Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
77c55988
提交
77c55988
authored
9月 12, 2008
作者:
James Bergstra
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
cleaning Apply docstrings
上级
aac0c7bb
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
48 行增加
和
25 行删除
+48
-25
graph.py
gof/graph.py
+48
-25
没有找到文件。
gof/graph.py
浏览文件 @
77c55988
...
@@ -8,19 +8,26 @@ import utils
...
@@ -8,19 +8,26 @@ import utils
class
Apply
(
utils
.
object2
):
class
Apply
(
utils
.
object2
):
"""
"""
Represents the application of an Op on input Results, producing output
Represents the application of an Op on input Results, producing output
Results. These should be instantiated by an Op's make_node function.
Results.
This class should be instantiated by an Op's make_node function.
"""
"""
#__slots__ = ['op', 'inputs', 'outputs']
def
__init__
(
self
,
op
,
inputs
,
outputs
):
def
__init__
(
self
,
op
,
inputs
,
outputs
):
"""
"""
Sets self.op, self.inputs, self.outputs to the respective parameter
Initialize self.{op, inputs, outputs}
in the arguments list.
@param op: initialize self.op
@param inputs: initialize self.inputs
@param outputs: initialize self.outputs
@type op: Op instance
@type inputs: list of Result instances
@type outputs: list of Result instances
The owner field of each output in the outputs list will be set to
@note: The owner field of each output in the outputs list will be set to self.
self.
Note: it is illegal for an output element to have an owner that is
@note: If an output element has an owner that is neither None nor self, then a
not None, unless it already points to self
.
ValueError exception will be raised
.
"""
"""
self
.
op
=
op
self
.
op
=
op
self
.
inputs
=
[]
self
.
inputs
=
[]
...
@@ -44,12 +51,17 @@ class Apply(utils.object2):
...
@@ -44,12 +51,17 @@ class Apply(utils.object2):
self
.
outputs
.
append
(
output
)
self
.
outputs
.
append
(
output
)
else
:
else
:
raise
TypeError
(
"The 'outputs' argument to Apply must contain Result instances with no owner, not
%
s"
%
output
)
raise
TypeError
(
"The 'outputs' argument to Apply must contain Result instances with no owner, not
%
s"
%
output
)
def
default_output
(
self
):
def
default_output
(
self
):
"""Returns the default output for this node.
@rtype: Result instance
@return: an element of self.outputs, typically self.outputs[0].
@note: may raise AttributeError self.op.default_output is out of range, or if there are
multiple outputs and self.op.default_output does not exist.
"""
"""
Returns the default output for this node. If there is only one
output, it will be returned. Else, it will consult the value of
node.op.default_output to decide which output to return.
"""
do
=
getattr
(
self
.
op
,
'default_output'
,
None
)
do
=
getattr
(
self
.
op
,
'default_output'
,
None
)
if
do
is
None
:
if
do
is
None
:
if
len
(
self
.
outputs
)
==
1
:
if
len
(
self
.
outputs
)
==
1
:
...
@@ -59,32 +71,42 @@ class Apply(utils.object2):
...
@@ -59,32 +71,42 @@ class Apply(utils.object2):
elif
do
<
0
or
do
>=
len
(
self
.
outputs
):
elif
do
<
0
or
do
>=
len
(
self
.
outputs
):
raise
AttributeError
(
"
%
s.default_output is out of range."
%
self
.
op
)
raise
AttributeError
(
"
%
s.default_output is out of range."
%
self
.
op
)
return
self
.
outputs
[
do
]
return
self
.
outputs
[
do
]
out
=
property
(
default_output
,
out
=
property
(
default_output
,
doc
=
"same as self.default_output()"
)
doc
=
"alias for self.default_output()"
)
def
__str__
(
self
):
def
__str__
(
self
):
return
op_as_string
(
self
.
inputs
,
self
)
return
op_as_string
(
self
.
inputs
,
self
)
def
__repr__
(
self
):
def
__repr__
(
self
):
return
str
(
self
)
return
str
(
self
)
def
__asapply__
(
self
):
def
__asapply__
(
self
):
return
self
return
self
def
clone
(
self
):
def
clone
(
self
):
# cp = copy(self)
"""Duplicate this Apply instance with inputs = self.inputs.
# cp.outputs = [output.clone() for output in self.outputs]
# for output in cp.outputs:
@return: a new Apply instance (or subclass instance) with new outputs.
# output.owner = cp
# return cp
@note: tags are copied from self to the returned instance.
"""
cp
=
self
.
__class__
(
self
.
op
,
self
.
inputs
,
[
output
.
clone
()
for
output
in
self
.
outputs
])
cp
=
self
.
__class__
(
self
.
op
,
self
.
inputs
,
[
output
.
clone
()
for
output
in
self
.
outputs
])
cp
.
tag
=
copy
(
self
.
tag
)
cp
.
tag
=
copy
(
self
.
tag
)
return
cp
return
cp
def
clone_with_new_inputs
(
self
,
inputs
,
strict
=
True
):
def
clone_with_new_inputs
(
self
,
inputs
,
strict
=
True
):
"""
"""Duplicate this Apply instance in a new graph.
Returns an Apply node with the same op but different inputs. Unless
strict is False, the type fields of all the inputs must be
@param inputs: list of Result instances to use as inputs.
equal to the current ones.
@type strict: Bool
@param strict: If True, the type fields of all the inputs must be equal to the current
ones, and returned outputs are guaranteed to have the same types as self.outputs.
If False, then there's no guarantee that the clone's outputs will have the same types
as self.outputs, and cloning may not even be possible (it depends on the Op).
If strict is True, the outputs of the clone will have the same type as
@returns: an Apply instance with the same op but different outputs.
the outputs of self. Else, it depends on the types of the new inputs
and the behavior of the op wrt that.
"""
"""
# if check_type:
# if check_type:
# for curr, new in zip(self.inputs, inputs):
# for curr, new in zip(self.inputs, inputs):
...
@@ -108,6 +130,7 @@ class Apply(utils.object2):
...
@@ -108,6 +130,7 @@ class Apply(utils.object2):
new_node
.
inputs
=
inputs
new_node
.
inputs
=
inputs
return
new_node
return
new_node
#convenience properties
nin
=
property
(
lambda
self
:
len
(
self
.
inputs
),
doc
=
'same as len(self.inputs)'
)
nin
=
property
(
lambda
self
:
len
(
self
.
inputs
),
doc
=
'same as len(self.inputs)'
)
nout
=
property
(
lambda
self
:
len
(
self
.
outputs
),
doc
=
'same as len(self.outputs)'
)
nout
=
property
(
lambda
self
:
len
(
self
.
outputs
),
doc
=
'same as len(self.outputs)'
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论