Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
768eb415
提交
768eb415
authored
5月 08, 2008
作者:
Olivier Breuleux
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
doc in graph.py
上级
14090d83
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
42 行增加
和
6 行删除
+42
-6
graph.py
gof/graph.py
+42
-6
没有找到文件。
gof/graph.py
浏览文件 @
768eb415
...
@@ -7,10 +7,21 @@ import utils
...
@@ -7,10 +7,21 @@ import utils
class
Apply
(
utils
.
object2
):
class
Apply
(
utils
.
object2
):
"""
"""
Note: it is illegal for an output element to have an owner != self
Represents the application of an Op on input Results, producing output
Results. These should be instantiated by an Op's make_node function.
"""
"""
#__slots__ = ['op', 'inputs', 'outputs']
#__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
in the arguments list.
The owner field of each output in the outputs list will be set to
self.
Note: it is illegal for an output element to have an owner that is
not None, unless it already points to self.
"""
self
.
op
=
op
self
.
op
=
op
self
.
inputs
=
[]
self
.
inputs
=
[]
...
@@ -34,8 +45,9 @@ class Apply(utils.object2):
...
@@ -34,8 +45,9 @@ class Apply(utils.object2):
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, typically self.outputs[0].
Returns the default output for this node. If there is only one
Depends on the value of node.op.default_output
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
:
...
@@ -47,7 +59,7 @@ class Apply(utils.object2):
...
@@ -47,7 +59,7 @@ class Apply(utils.object2):
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
=
"
Shortcut to the as self.outputs[0] if this Op's has_default_output field is True.
"
)
doc
=
"
same as 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
):
...
@@ -57,6 +69,14 @@ class Apply(utils.object2):
...
@@ -57,6 +69,14 @@ class Apply(utils.object2):
def
clone
(
self
):
def
clone
(
self
):
return
self
.
__class__
(
self
.
op
,
self
.
inputs
,
[
output
.
clone
()
for
output
in
self
.
outputs
])
return
self
.
__class__
(
self
.
op
,
self
.
inputs
,
[
output
.
clone
()
for
output
in
self
.
outputs
])
def
clone_with_new_inputs
(
self
,
inputs
,
check_type
=
True
):
def
clone_with_new_inputs
(
self
,
inputs
,
check_type
=
True
):
"""
Returns an Apply node with the same op but different inputs. Unless
check_type is False, the type fields of all the inputs must be
equal to the current ones.
The outputs of the clone will have the same type as the outputs of
self.
"""
if
check_type
:
if
check_type
:
for
curr
,
new
in
zip
(
self
.
inputs
,
inputs
):
for
curr
,
new
in
zip
(
self
.
inputs
,
inputs
):
if
not
curr
.
type
==
new
.
type
:
if
not
curr
.
type
==
new
.
type
:
...
@@ -65,11 +85,15 @@ class Apply(utils.object2):
...
@@ -65,11 +85,15 @@ class Apply(utils.object2):
new_node
.
inputs
=
inputs
new_node
.
inputs
=
inputs
return
new_node
return
new_node
nin
=
property
(
lambda
self
:
len
(
self
.
inputs
))
nin
=
property
(
lambda
self
:
len
(
self
.
inputs
)
,
doc
=
'same as len(self.inputs)'
)
nout
=
property
(
lambda
self
:
len
(
self
.
outputs
))
nout
=
property
(
lambda
self
:
len
(
self
.
outputs
)
,
doc
=
'same as len(self.outputs)'
)
class
Result
(
utils
.
object2
):
class
Result
(
utils
.
object2
):
"""
Represents the result of some computation (pointed to by its owner field),
or an input to the graph (if owner is None)
"""
#__slots__ = ['type', 'owner', 'index', 'name']
#__slots__ = ['type', 'owner', 'index', 'name']
def
__init__
(
self
,
type
,
owner
=
None
,
index
=
None
,
name
=
None
):
def
__init__
(
self
,
type
,
owner
=
None
,
index
=
None
,
name
=
None
):
self
.
type
=
type
self
.
type
=
type
...
@@ -99,6 +123,12 @@ class Result(utils.object2):
...
@@ -99,6 +123,12 @@ class Result(utils.object2):
return
self
.
__class__
(
self
.
type
,
None
,
None
,
self
.
name
)
return
self
.
__class__
(
self
.
type
,
None
,
None
,
self
.
name
)
class
Value
(
Result
):
class
Value
(
Result
):
"""
Result with a data field. The data field is filtered by what is
provided in the constructor for the Value's type field.
Its owner field is always None.
"""
#__slots__ = ['data']
#__slots__ = ['data']
def
__init__
(
self
,
type
,
data
,
name
=
None
):
def
__init__
(
self
,
type
,
data
,
name
=
None
):
Result
.
__init__
(
self
,
type
,
None
,
None
,
name
)
Result
.
__init__
(
self
,
type
,
None
,
None
,
name
)
...
@@ -115,6 +145,9 @@ class Value(Result):
...
@@ -115,6 +145,9 @@ class Value(Result):
owner
=
property
(
lambda
self
:
None
,
__set_owner
)
owner
=
property
(
lambda
self
:
None
,
__set_owner
)
class
Constant
(
Value
):
class
Constant
(
Value
):
"""
Same as Value, but the data it contains cannot be modified.
"""
#__slots__ = ['data']
#__slots__ = ['data']
def
__init__
(
self
,
type
,
data
,
name
=
None
):
def
__init__
(
self
,
type
,
data
,
name
=
None
):
Value
.
__init__
(
self
,
type
,
data
,
name
)
Value
.
__init__
(
self
,
type
,
data
,
name
)
...
@@ -128,6 +161,9 @@ class Constant(Value):
...
@@ -128,6 +161,9 @@ class Constant(Value):
return
self
.
name
return
self
.
name
return
str
(
self
.
data
)
#+ "::" + str(self.type)
return
str
(
self
.
data
)
#+ "::" + str(self.type)
def
stack_search
(
start
,
expand
,
mode
=
'bfs'
,
build_inv
=
False
):
def
stack_search
(
start
,
expand
,
mode
=
'bfs'
,
build_inv
=
False
):
"""Search through L{Result}s, either breadth- or depth-first
"""Search through L{Result}s, either breadth- or depth-first
@type start: deque
@type start: deque
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论