Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
6757ec46
提交
6757ec46
authored
4月 15, 2015
作者:
Frederic
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Speed up io_toposort()
上级
ea2b1686
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
66 行增加
和
30 行删除
+66
-30
graph.py
theano/gof/graph.py
+66
-30
没有找到文件。
theano/gof/graph.py
浏览文件 @
6757ec46
...
@@ -716,7 +716,8 @@ def clone_get_equiv(inputs, outputs,
...
@@ -716,7 +716,8 @@ def clone_get_equiv(inputs, outputs,
return
memo
return
memo
def
general_toposort
(
r_out
,
deps
,
debug_print
=
False
):
def
general_toposort
(
r_out
,
deps
,
debug_print
=
False
,
_deps
=
None
,
deps_cache
=
None
):
"""WRITEME
"""WRITEME
:note:
:note:
...
@@ -727,22 +728,29 @@ def general_toposort(r_out, deps, debug_print=False):
...
@@ -727,22 +728,29 @@ def general_toposort(r_out, deps, debug_print=False):
:note:
:note:
The order of the return value list is determined by the order of nodes returned by the deps() function.
The order of the return value list is determined by the order of nodes returned by the deps() function.
"""
deps_cache
=
{}
def
_deps
(
io
):
:note: deps should be provided or can be None and the caller
if
io
not
in
deps_cache
:
provide _deps and deps_cache. The second option remove a
d
=
deps
(
io
)
Python function call, so is faster.
if
d
:
if
not
isinstance
(
d
,
(
list
,
OrderedSet
)):
"""
raise
TypeError
(
"Non-deterministic collections here make"
if
_deps
is
None
:
deps_cache
=
{}
def
_deps
(
io
):
if
io
not
in
deps_cache
:
d
=
deps
(
io
)
if
d
:
if
not
isinstance
(
d
,
(
list
,
OrderedSet
)):
raise
TypeError
(
"Non-deterministic collections here make"
" toposort non-deterministic."
)
" toposort non-deterministic."
)
deps_cache
[
io
]
=
list
(
d
)
deps_cache
[
io
]
=
list
(
d
)
else
:
deps_cache
[
io
]
=
d
return
d
else
:
else
:
deps_cache
[
io
]
=
d
return
deps_cache
[
io
]
return
d
else
:
return
deps_cache
[
io
]
assert
isinstance
(
r_out
,
(
tuple
,
list
,
deque
))
assert
isinstance
(
r_out
,
(
tuple
,
list
,
deque
))
...
@@ -786,26 +794,54 @@ def io_toposort(inputs, outputs, orderings=None):
...
@@ -786,26 +794,54 @@ def io_toposort(inputs, outputs, orderings=None):
order. no sets allowed!
order. no sets allowed!
"""
"""
if
orderings
is
None
:
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
(
inputs
)
iset
=
set
(
inputs
)
def
deps
(
obj
):
# We build 2 functions as a speed up
rval
=
[]
deps_cache
=
{}
if
obj
not
in
iset
:
if
isinstance
(
obj
,
Variable
):
deps
=
None
if
obj
.
owner
:
_deps
=
None
rval
=
[
obj
.
owner
]
if
not
orderings
:
# can be None or empty dict
elif
isinstance
(
obj
,
Apply
):
# Specialized function that is faster when no ordering.
rval
=
list
(
obj
.
inputs
)
# Also include the cache in the function itself for speed up.
rval
.
extend
(
orderings
.
get
(
obj
,
[]))
def
_deps
(
obj
):
else
:
if
obj
in
deps_cache
:
assert
not
orderings
.
get
(
obj
,
[])
return
deps_cache
[
io
]
return
rval
rval
=
[]
if
obj
not
in
iset
:
if
isinstance
(
obj
,
Variable
):
if
obj
.
owner
:
rval
=
[
obj
.
owner
]
elif
isinstance
(
obj
,
Apply
):
rval
=
list
(
obj
.
inputs
)
if
rval
:
if
not
isinstance
(
rval
,
(
list
,
OrderedSet
)):
raise
TypeError
(
"Non-deterministic collections here make"
" toposort non-deterministic."
)
deps_cache
[
obj
]
=
list
(
rval
)
else
:
deps_cache
[
obj
]
=
rval
else
:
deps_cache
[
obj
]
=
rval
return
rval
else
:
def
deps
(
obj
):
rval
=
[]
if
obj
not
in
iset
:
if
isinstance
(
obj
,
Variable
):
if
obj
.
owner
:
rval
=
[
obj
.
owner
]
elif
isinstance
(
obj
,
Apply
):
rval
=
list
(
obj
.
inputs
)
rval
.
extend
(
orderings
.
get
(
obj
,
[]))
else
:
assert
not
orderings
.
get
(
obj
,
[])
return
rval
topo
=
general_toposort
(
outputs
,
deps
)
topo
=
general_toposort
(
outputs
,
deps
=
deps
,
_deps
=
_deps
,
deps_cache
=
deps_cache
)
return
[
o
for
o
in
topo
if
isinstance
(
o
,
Apply
)]
return
[
o
for
o
in
topo
if
isinstance
(
o
,
Apply
)]
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论