Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
8c381254
提交
8c381254
authored
7月 16, 2012
作者:
nouiz
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #764 from delallea/minor
PEP8 fixes
上级
cc4ce0d0
064ce7a0
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
40 行增加
和
32 行删除
+40
-32
graph.py
theano/gof/graph.py
+40
-32
没有找到文件。
theano/gof/graph.py
浏览文件 @
8c381254
...
...
@@ -71,9 +71,10 @@ class Apply(utils.object2):
self
.
inputs
=
[]
self
.
tag
=
utils
.
scratchpad
()
if
not
isinstance
(
inputs
,
(
list
,
tuple
)):
if
not
isinstance
(
inputs
,
(
list
,
tuple
)):
raise
TypeError
(
"The inputs of an Apply must be a list or tuple"
)
if
not
isinstance
(
outputs
,(
list
,
tuple
)):
if
not
isinstance
(
outputs
,
(
list
,
tuple
)):
raise
TypeError
(
"The output of an Apply must be a list or tuple"
)
## filter inputs to make sure each element is a Variable
...
...
@@ -120,27 +121,25 @@ class Apply(utils.object2):
raise
AttributeError
(
"
%
s.default_output is out of range."
%
self
.
op
)
return
self
.
outputs
[
do
]
def
env_getter
(
self
):
warnings
.
warn
(
"Apply.env is deprecated, it has been renamed 'fgraph'"
,
stacklevel
=
2
)
stacklevel
=
2
)
return
self
.
fgraph
def
env_setter
(
self
,
value
):
def
env_setter
(
self
,
value
):
warnings
.
warn
(
"Apply.env is deprecated, it has been renamed 'fgraph'"
,
stacklevel
=
2
)
stacklevel
=
2
)
self
.
fgraph
=
value
def
env_deleter
(
self
):
warnings
.
warn
(
"Apply.env is deprecated, it has been renamed 'fgraph'"
,
stacklevel
=
2
)
stacklevel
=
2
)
del
self
.
fgraph
env
=
property
(
env_getter
,
env_setter
,
env_deleter
)
out
=
property
(
default_output
,
doc
=
"alias for self.default_output()"
)
doc
=
"alias for self.default_output()"
)
"""Alias for self.default_output()"""
def
__str__
(
self
):
...
...
@@ -165,7 +164,7 @@ class Apply(utils.object2):
cp
.
tag
=
copy
(
self
.
tag
)
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.
:param inputs: list of Variable instances to use as inputs.
...
...
@@ -204,10 +203,10 @@ class Apply(utils.object2):
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)'
)
"""property: Number of 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)'
)
"""property: Number of outputs"""
...
...
@@ -289,7 +288,7 @@ class Variable(utils.object2):
"""
#__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
):
"""Initialize type, owner, index, name.
:type type: a Type instance
...
...
@@ -317,6 +316,7 @@ class Variable(utils.object2):
if
name
is
not
None
and
not
isinstance
(
name
,
basestring
):
raise
TypeError
(
"name must be a string"
,
name
)
self
.
name
=
name
def
__str__
(
self
):
"""WRITEME"""
if
self
.
name
is
not
None
:
...
...
@@ -329,8 +329,10 @@ class Variable(utils.object2):
return
str
(
self
.
owner
.
op
)
+
"."
+
str
(
self
.
index
)
else
:
return
"<
%
s>"
%
str
(
self
.
type
)
def
__repr__
(
self
):
return
str
(
self
)
def
clone
(
self
):
"""Return a new Variable like self.
...
...
@@ -345,39 +347,40 @@ class Variable(utils.object2):
cp
.
tag
=
copy
(
self
.
tag
)
return
cp
def
__lt__
(
self
,
other
):
def
__lt__
(
self
,
other
):
raise
NotImplementedError
(
'Subclasses of Variable must provide __lt__'
,
self
.
__class__
.
__name__
)
def
__le__
(
self
,
other
):
def
__le__
(
self
,
other
):
raise
NotImplementedError
(
'Subclasses of Variable must provide __le__'
,
self
.
__class__
.
__name__
)
def
__gt__
(
self
,
other
):
def
__gt__
(
self
,
other
):
raise
NotImplementedError
(
'Subclasses of Variable must provide __gt__'
,
self
.
__class__
.
__name__
)
def
__ge__
(
self
,
other
):
def
__ge__
(
self
,
other
):
raise
NotImplementedError
(
'Subclasses of Variable must provide __ge__'
,
self
.
__class__
.
__name__
)
def
env_getter
(
self
):
warnings
.
warn
(
"Variable.env is deprecated, it has been renamed 'fgraph'"
,
stacklevel
=
2
)
stacklevel
=
2
)
return
self
.
fgraph
def
env_setter
(
self
,
value
):
def
env_setter
(
self
,
value
):
warnings
.
warn
(
"Variable.env is deprecated, it has been renamed 'fgraph'"
,
stacklevel
=
2
)
stacklevel
=
2
)
self
.
fgraph
=
value
def
env_deleter
(
self
):
warnings
.
warn
(
"Variable.env is deprecated, it has been renamed 'fgraph'"
,
stacklevel
=
2
)
stacklevel
=
2
)
del
self
.
fgraph
env
=
property
(
env_getter
,
env_setter
,
env_deleter
)
class
Constant
(
Variable
):
"""
A :term:`Constant` is a `Variable` with a `value` field that cannot be changed at runtime.
...
...
@@ -385,7 +388,7 @@ class Constant(Variable):
Constant nodes make eligible numerous optimizations: constant inlining in C code, constant folding, etc.
"""
#__slots__ = ['data']
def
__init__
(
self
,
type
,
data
,
name
=
None
):
def
__init__
(
self
,
type
,
data
,
name
=
None
):
"""Initialize self.
:note:
...
...
@@ -439,7 +442,7 @@ class Constant(Variable):
# index is not defined, because the `owner` attribute must necessarily be None
def
stack_search
(
start
,
expand
,
mode
=
'bfs'
,
build_inv
=
False
):
def
stack_search
(
start
,
expand
,
mode
=
'bfs'
,
build_inv
=
False
):
"""Search through a graph, either breadth- or depth-first
:type start: deque
...
...
@@ -591,7 +594,7 @@ def orphans(i, o):
return
variables_and_orphans
(
i
,
o
)[
1
]
def
clone
(
i
,
o
,
copy_inputs
=
True
):
def
clone
(
i
,
o
,
copy_inputs
=
True
):
"""
Copies the subgraph contained between i and o.
...
...
@@ -670,7 +673,7 @@ def clone_get_equiv(inputs, outputs,
return
memo
def
general_toposort
(
r_out
,
deps
,
debug_print
=
False
):
def
general_toposort
(
r_out
,
deps
,
debug_print
=
False
):
"""WRITEME
:note:
...
...
@@ -683,6 +686,7 @@ def general_toposort(r_out, deps, debug_print = False):
The order of the return value list is determined by the order of nodes returned by the deps() function.
"""
deps_cache
=
{}
def
_deps
(
io
):
if
io
not
in
deps_cache
:
d
=
deps
(
io
)
...
...
@@ -696,7 +700,7 @@ def general_toposort(r_out, deps, debug_print = False):
assert
isinstance
(
r_out
,
(
tuple
,
list
,
deque
))
reachable
,
clients
=
stack_search
(
deque
(
r_out
),
_deps
,
'dfs'
,
True
)
reachable
,
clients
=
stack_search
(
deque
(
r_out
),
_deps
,
'dfs'
,
True
)
sources
=
deque
([
r
for
r
in
reachable
if
not
deps_cache
.
get
(
r
,
None
)])
rset
=
set
()
...
...
@@ -728,6 +732,7 @@ def io_toposort(i, o, orderings=None):
orderings
=
{}
#the inputs are used only here in the function that decides what 'predecessors' to explore
iset
=
set
(
i
)
def
deps
(
obj
):
rval
=
[]
if
obj
not
in
iset
:
...
...
@@ -740,6 +745,7 @@ def io_toposort(i, o, orderings=None):
else
:
assert
not
orderings
.
get
(
obj
,
[])
return
rval
topo
=
general_toposort
(
o
,
deps
)
return
[
o
for
o
in
topo
if
isinstance
(
o
,
Apply
)]
...
...
@@ -817,9 +823,11 @@ def is_same_graph(var1, var2, givens=None, debug=False):
all_vars
=
[
set
(
variables
(
v_i
,
v_o
))
for
v_i
,
v_o
in
((
inputs_var
[
0
],
[
var1
]),
(
inputs_var
[
1
],
[
var2
]))]
def
in_var
(
x
,
k
):
# Return True iff `x` is in computation graph of variable `vark`.
return
x
in
all_vars
[
k
-
1
]
for
to_replace
,
replace_by
in
givens
.
iteritems
():
# Map a substitution variable to the computational graphs it
# belongs to.
...
...
@@ -856,16 +864,16 @@ def is_same_graph(var1, var2, givens=None, debug=False):
def
op_as_string
(
i
,
op
,
leaf_formatter
=
default_leaf_formatter
,
node_formatter
=
default_node_formatter
):
leaf_formatter
=
default_leaf_formatter
,
node_formatter
=
default_node_formatter
):
"""WRITEME"""
strs
=
as_string
(
i
,
op
.
inputs
,
leaf_formatter
,
node_formatter
)
return
node_formatter
(
op
,
strs
)
def
as_string
(
i
,
o
,
leaf_formatter
=
default_leaf_formatter
,
node_formatter
=
default_node_formatter
):
leaf_formatter
=
default_leaf_formatter
,
node_formatter
=
default_node_formatter
):
"""WRITEME
:type i: list
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论