Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
8963a02f
提交
8963a02f
authored
11月 22, 2010
作者:
Frederic Bastien
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
white space fix.
上级
efcf58d0
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
26 行增加
和
28 行删除
+26
-28
graph.py
theano/gof/graph.py
+26
-28
没有找到文件。
theano/gof/graph.py
浏览文件 @
8963a02f
...
@@ -17,7 +17,7 @@ class Apply(utils.object2):
...
@@ -17,7 +17,7 @@ class Apply(utils.object2):
"""
"""
An :term:`Apply` instance is a node in an expression graph which represents the application
An :term:`Apply` instance is a node in an expression graph which represents the application
of an `Op` to some input `Variable` nodes, producing some output `Variable` nodes.
of an `Op` to some input `Variable` nodes, producing some output `Variable` nodes.
This class is typically instantiated by an Op's make_node() function, which is typically
This class is typically instantiated by an Op's make_node() function, which is typically
called by that Op's __call__() function.
called by that Op's __call__() function.
...
@@ -89,9 +89,9 @@ class Apply(utils.object2):
...
@@ -89,9 +89,9 @@ class Apply(utils.object2):
def
default_output
(
self
):
def
default_output
(
self
):
"""Returns the default output for this node.
"""Returns the default output for this node.
:rtype:
:rtype:
Variable instance
Variable instance
:return:
:return:
an element of self.outputs, typically self.outputs[0].
an element of self.outputs, typically self.outputs[0].
...
@@ -101,7 +101,7 @@ class Apply(utils.object2):
...
@@ -101,7 +101,7 @@ class Apply(utils.object2):
multiple outputs and self.op.default_output does not exist.
multiple outputs and self.op.default_output does not exist.
"""
"""
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
:
...
@@ -112,7 +112,7 @@ class Apply(utils.object2):
...
@@ -112,7 +112,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
=
"alias for self.default_output()"
)
doc
=
"alias for self.default_output()"
)
"""Alias for self.default_output()"""
"""Alias for self.default_output()"""
...
@@ -145,7 +145,7 @@ class Apply(utils.object2):
...
@@ -145,7 +145,7 @@ class Apply(utils.object2):
:type strict: Bool
:type strict: Bool
:param strict:
:param strict:
If True, the type fields of all the inputs must be equal to the current ones, and
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,
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
then there's no guarantee that the clone's outputs will have the same types as
...
@@ -203,7 +203,7 @@ class Variable(utils.object2):
...
@@ -203,7 +203,7 @@ class Variable(utils.object2):
the position of itself in the owner's output list (property: index).
the position of itself in the owner's output list (property: index).
- `Variable` (this base type) is typically the output of a symbolic computation,
- `Variable` (this base type) is typically the output of a symbolic computation,
- `Value` (a subclass) adds a default :literal:`value`, and requires that owner is None
- `Value` (a subclass) adds a default :literal:`value`, and requires that owner is None
- `Constant` (a subclass) which adds a default and un-replaceable :literal:`value`, and
- `Constant` (a subclass) which adds a default and un-replaceable :literal:`value`, and
...
@@ -248,7 +248,7 @@ class Variable(utils.object2):
...
@@ -248,7 +248,7 @@ class Variable(utils.object2):
"""Initialize type, owner, index, name.
"""Initialize type, owner, index, name.
:type type: a Type instance
:type type: a Type instance
:param type:
:param type:
the type governs the kind of data that can be associated with this variable
the type governs the kind of data that can be associated with this variable
:type owner: None or Apply instance
:type owner: None or Apply instance
...
@@ -299,14 +299,14 @@ class Variable(utils.object2):
...
@@ -299,14 +299,14 @@ class Variable(utils.object2):
cp
=
self
.
__class__
(
self
.
type
,
None
,
None
,
self
.
name
)
cp
=
self
.
__class__
(
self
.
type
,
None
,
None
,
self
.
name
)
cp
.
tag
=
copy
(
self
.
tag
)
cp
.
tag
=
copy
(
self
.
tag
)
return
cp
return
cp
def
__lt__
(
self
,
other
):
def
__lt__
(
self
,
other
):
raise
NotImplementedError
(
'Subclasses of Variable must implement __lt__'
)
raise
NotImplementedError
(
'Subclasses of Variable must implement __lt__'
)
def
__le__
(
self
,
other
):
def
__le__
(
self
,
other
):
raise
NotImplementedError
(
'Subclasses of Variable must implement __le__'
)
raise
NotImplementedError
(
'Subclasses of Variable must implement __le__'
)
def
__gt__
(
self
,
other
):
def
__gt__
(
self
,
other
):
raise
NotImplementedError
(
'Subclasses of Variable must implement __gt__'
,
self
.
__class__
.
__name__
)
raise
NotImplementedError
(
'Subclasses of Variable must implement __gt__'
,
self
.
__class__
.
__name__
)
def
__ge__
(
self
,
other
):
def
__ge__
(
self
,
other
):
raise
NotImplementedError
(
'Subclasses of Variable must implement __ge__'
)
raise
NotImplementedError
(
'Subclasses of Variable must implement __ge__'
)
class
Value
(
Variable
):
class
Value
(
Variable
):
...
@@ -324,7 +324,7 @@ class Value(Variable):
...
@@ -324,7 +324,7 @@ class Value(Variable):
def
__init__
(
self
,
type
,
data
,
name
=
None
):
def
__init__
(
self
,
type
,
data
,
name
=
None
):
"""Initialize self.
"""Initialize self.
:note:
:note:
The data field is filtered by what is provided in the constructor for the Value's
The data field is filtered by what is provided in the constructor for the Value's
type field.
type field.
...
@@ -353,7 +353,7 @@ class Value(Variable):
...
@@ -353,7 +353,7 @@ class Value(Variable):
if
value
is
not
None
:
if
value
is
not
None
:
raise
ValueError
(
"Value instances cannot have an owner."
)
raise
ValueError
(
"Value instances cannot have an owner."
)
owner
=
property
(
lambda
self
:
None
,
__set_owner
)
owner
=
property
(
lambda
self
:
None
,
__set_owner
)
value
=
property
(
lambda
self
:
self
.
data
,
value
=
property
(
lambda
self
:
self
.
data
,
doc
=
'read-only data access method'
)
doc
=
'read-only data access method'
)
# index is not defined, because the `owner` attribute must necessarily be None
# index is not defined, because the `owner` attribute must necessarily be None
...
@@ -394,15 +394,15 @@ def stack_search(start, expand, mode='bfs', build_inv = False):
...
@@ -394,15 +394,15 @@ def stack_search(start, expand, mode='bfs', build_inv = False):
:type start: deque
:type start: deque
:param start: search from these nodes
:param start: search from these nodes
:type expand: callable
:type expand: callable
:param expand:
:param expand:
when we get to a node, add expand(node) to the list of nodes to visit. This function
when we get to a node, add expand(node) to the list of nodes to visit. This function
should return a list, or None
should return a list, or None
:rtype: list of `Variable` or `Apply` instances (depends on `expend`)
:rtype: list of `Variable` or `Apply` instances (depends on `expend`)
:return: the list of nodes in order of traversal.
:return: the list of nodes in order of traversal.
:note:
:note:
a node will appear at most once in the return value, even if it appears multiple times
a node will appear at most once in the return value, even if it appears multiple times
in the start parameter.
in the start parameter.
:postcondition: every element of start is transferred to the returned list.
:postcondition: every element of start is transferred to the returned list.
:postcondition: start is empty.
:postcondition: start is empty.
...
@@ -440,7 +440,7 @@ def inputs(variable_list, blockers = None):
...
@@ -440,7 +440,7 @@ def inputs(variable_list, blockers = None):
:param variable_list:
:param variable_list:
output `Variable` instances from which to search backward through owners
output `Variable` instances from which to search backward through owners
:rtype: list of `Variable` instances
:rtype: list of `Variable` instances
:returns:
:returns:
input nodes with no owner, in the order found by a left-recursive depth-first search
input nodes with no owner, in the order found by a left-recursive depth-first search
started at the nodes in `variable_list`.
started at the nodes in `variable_list`.
...
@@ -548,7 +548,7 @@ def clone_get_equiv(i, o, copy_inputs_and_orphans = True):
...
@@ -548,7 +548,7 @@ def clone_get_equiv(i, o, copy_inputs_and_orphans = True):
:type o: list
:type o: list
:param o: output L{Variable}s
:param o: output L{Variable}s
:type copy_inputs_and_orphans: bool
:type copy_inputs_and_orphans: bool
:param copy_inputs_and_orphans:
:param copy_inputs_and_orphans:
if True, the inputs and the orphans will be replaced in the cloned graph by copies
if True, the inputs and the orphans will be replaced in the cloned graph by copies
available in the equiv dictionary returned by the function (copy_inputs_and_orphans
available in the equiv dictionary returned by the function (copy_inputs_and_orphans
defaults to True)
defaults to True)
...
@@ -592,10 +592,10 @@ def clone_get_equiv(i, o, copy_inputs_and_orphans = True):
...
@@ -592,10 +592,10 @@ def clone_get_equiv(i, o, copy_inputs_and_orphans = True):
def
general_toposort
(
r_out
,
deps
,
debug_print
=
False
):
def
general_toposort
(
r_out
,
deps
,
debug_print
=
False
):
"""WRITEME
"""WRITEME
:note:
:note:
deps(i) should behave like a pure function (no funny business with internal state)
deps(i) should behave like a pure function (no funny business with internal state)
:note:
:note:
deps(i) will be cached by this function (to be fast)
deps(i) will be cached by this function (to be fast)
:note:
:note:
...
@@ -645,10 +645,10 @@ def io_toposort(i, o, orderings = {}):
...
@@ -645,10 +645,10 @@ def io_toposort(i, o, orderings = {}):
"""
"""
#the inputs are used only here in the function that decides what 'predecessors' to explore
#the inputs are used only here in the function that decides what 'predecessors' to explore
iset
=
set
(
i
)
iset
=
set
(
i
)
def
deps
(
obj
):
def
deps
(
obj
):
rval
=
[]
rval
=
[]
if
obj
not
in
iset
:
if
obj
not
in
iset
:
if
isinstance
(
obj
,
Variable
):
if
isinstance
(
obj
,
Variable
):
if
obj
.
owner
:
if
obj
.
owner
:
rval
=
[
obj
.
owner
]
rval
=
[
obj
.
owner
]
if
isinstance
(
obj
,
Apply
):
if
isinstance
(
obj
,
Apply
):
...
@@ -685,7 +685,7 @@ def as_string(i, o,
...
@@ -685,7 +685,7 @@ def as_string(i, o,
:type leaf_formatter: function
:type leaf_formatter: function
:param leaf_formatter: takes a `Variable` and returns a string to describe it
:param leaf_formatter: takes a `Variable` and returns a string to describe it
:type node_formatter: function
:type node_formatter: function
:param node_formatter:
:param node_formatter:
takes an `Op` and the list of strings corresponding to its arguments and returns a
takes an `Op` and the list of strings corresponding to its arguments and returns a
string to describe it
string to describe it
...
@@ -701,7 +701,7 @@ def as_string(i, o,
...
@@ -701,7 +701,7 @@ def as_string(i, o,
i
=
set
(
i
)
i
=
set
(
i
)
orph
=
orphans
(
i
,
o
)
orph
=
orphans
(
i
,
o
)
multi
=
set
()
multi
=
set
()
seen
=
set
()
seen
=
set
()
for
output
in
o
:
for
output
in
o
:
...
@@ -771,5 +771,3 @@ def view_roots(r):
...
@@ -771,5 +771,3 @@ def view_roots(r):
return
[
r
]
return
[
r
]
else
:
else
:
return
[
r
]
return
[
r
]
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论