Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
5731ba11
提交
5731ba11
authored
9月 14, 2012
作者:
Ian Goodfellow
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Big speedup! Got rid of set of visited nodes altogether
上级
cc8b5e2d
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
31 行增加
和
21 行删除
+31
-21
destroyhandler.py
theano/gof/destroyhandler.py
+31
-21
没有找到文件。
theano/gof/destroyhandler.py
浏览文件 @
5731ba11
...
...
@@ -100,45 +100,55 @@ def _contains_cycle(fgraph, orderings):
# get_parents worked better.
# IG: I tried tagging each variable and node with a visited flag
# to avoid needing to do a
node_to_pare
nts lookup to tell if a
# to avoid needing to do a
parent_cou
nts lookup to tell if a
# node was visited. This requires wrapping everything in a
# try-finally and setting all the flags to false in the finally.
# It resulted in a net slowdown, whether I used iteration
# on
node_to_pare
nts or rval_list. (rval_list was a list
# whose contents were the same as
node_to_pare
nts.keys())
# on
parent_cou
nts or rval_list. (rval_list was a list
# whose contents were the same as
parent_cou
nts.keys())
# IG: I tried converting
node_to_pare
nts to use an id for the key,
# IG: I tried converting
parent_cou
nts to use an id for the key,
# so that the dict would do reference counting on its keys.
#
For some reason this caused a slowdown--not sure if dict is
#
slow for int keys, or if call to id function is expensive.
#
DWF tried implementing this as cython, including the deque
#
class when compiling cython, and only got a 10% speedup
.
#
dict mapping an Apply or Variable instance to its parents
#
(including parents imposed by orderings)
node_to_pare
nts
=
{}
#
the inverse mapping
#
This caused a slowdown.
#
Separate benchmark tests showed that calling id is about
# half as expensive as a dictionary access, and that the
#
dictionary also runs slower when storing ids than when
#
storing objects
.
# dict mapping an Apply or Variable instance to the number
#
of its parents (including parents imposed by orderings)
#
that haven't been visited yet
parent_cou
nts
=
{}
#
dict mapping an Apply or Variable instance to its children
node_to_children
=
{}
lifo_queue
=
deque
(
outputs
)
fifo_queue
=
deque
()
# visitable: A container holding all Variable and Apply instances
# that can currently be visited according to the graph topology
# (ie, whose parents have already been visited)
# TODO: visitable is a fifo_queue. could this run faster if we
# implement it as a stack rather than a deque?
# TODO: visitable need not be a fifo_queue, any kind of container
# that we can throw things into and take things out of quickly will
# work. is there another kind of container that could run faster?
# we don't care about the traversal order here as much as we do
# in io_toposort because we aren't trying to generate an ordering
# on the nodes
visitable
=
deque
()
# Do a DFS through the graph, following the edges backwards from
# the outputs to the inputs. Build the node_to_parents and
# node_to_children dictionaries. Put the roots of the graph
# into fifo_queue
# TODO: does the order of the roots in the fifo_queue matter?
# into visitable
while
lifo_queue
:
# using pop rather than pop_left makes this queue LIFO
# using a LIFO queue makes the search DFS
node
=
lifo_queue
.
pop
()
if
node
not
in
node_to_pare
nts
:
if
node
not
in
parent_cou
nts
:
if
node
in
iset
:
# Inputs to the graph must not have any dependencies
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论