Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
3a7cb5a5
提交
3a7cb5a5
authored
7月 23, 2015
作者:
Ziye Fan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Make following methods in destroyhandler.py inline:
- getroot - add_impact - get_impact
上级
2ddaca06
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
43 行增加
和
87 行删除
+43
-87
destroyhandler.py
theano/gof/destroyhandler.py
+43
-87
没有找到文件。
theano/gof/destroyhandler.py
浏览文件 @
3a7cb5a5
...
@@ -13,6 +13,7 @@ from theano.compat import OrderedDict
...
@@ -13,6 +13,7 @@ from theano.compat import OrderedDict
from
theano.misc.ordered_set
import
OrderedSet
from
theano.misc.ordered_set
import
OrderedSet
from
.fg
import
InconsistencyError
from
.fg
import
InconsistencyError
from
six.moves.queue
import
Queue
class
ProtocolError
(
Exception
):
class
ProtocolError
(
Exception
):
...
@@ -178,45 +179,51 @@ def _contains_cycle(fgraph, orderings):
...
@@ -178,45 +179,51 @@ def _contains_cycle(fgraph, orderings):
return
visited
!=
len
(
parent_counts
)
return
visited
!=
len
(
parent_counts
)
def
getroot
(
r
,
view_i
):
def
_build_droot_impact
(
destroy_handler
):
"""
droot
=
{}
# destroyed view + nonview variables -> foundation
TODO: what is view_i ? based on add_impact's docstring, IG is guessing
impact
=
{}
# destroyed nonview variable -> it + all views of it
it might be a dictionary mapping variables to views, but what is
root_destroyer
=
{}
# root -> destroyer apply
a view? In these old docstrings I'm not sure if "view" always
means "view variable" or if it also sometimes means "viewing
pattern."
For views: Return non-view variable which is ultimatly viewed by r.
For non-views: return self.
"""
try
:
return
getroot
(
view_i
[
r
],
view_i
)
except
KeyError
:
return
r
for
app
in
destroy_handler
.
destroyers
:
for
output_idx
,
input_idx_list
in
app
.
op
.
destroy_map
.
items
():
if
len
(
input_idx_list
)
!=
1
:
raise
NotImplementedError
()
input_idx
=
input_idx_list
[
0
]
input
=
app
.
inputs
[
input_idx
]
def
add_impact
(
r
,
view_o
,
impact
):
# Find non-view variable which is ultimatly viewed by input.
"""
view_i
=
destroy_handler
.
view_i
In opposition to getroot, which finds the variable that is viewed *by* r, this function
_r
=
input
returns all the variables that are views of r.
while
_r
is
not
None
:
r
=
_r
_r
=
view_i
.
get
(
r
)
input_root
=
r
:param impact: is a set of variables that are views of r
if
input_root
in
droot
:
:param droot: a dictionary mapping views -> r
raise
InconsistencyError
(
"Multiple destroyers of
%
s"
%
input_root
)
droot
[
input_root
]
=
input_root
root_destroyer
[
input_root
]
=
app
TODO: this docstring is hideously wrong, the function doesn't return anything.
# The code here add all the variables that are views of r into
has droot been renamed to view_o?
# an OrderedSet input_impact
does it add things to the impact argument instead of returning them?
input_impact
=
OrderedSet
()
IG thinks so, based on reading the code. It looks like get_impact
queue
=
Queue
()
does what this docstring said this function does.
queue
.
put
(
input_root
)
"""
while
not
queue
.
empty
():
for
v
in
view_o
.
get
(
r
,
[]):
v
=
queue
.
get
()
impact
.
add
(
v
)
for
n
in
destroy_handler
.
view_o
.
get
(
v
,
[]):
add_impact
(
v
,
view_o
,
impact
)
input_impact
.
add
(
n
)
queue
.
put
(
n
)
for
v
in
input_impact
:
assert
v
not
in
droot
droot
[
v
]
=
input_root
impact
[
input_root
]
=
input_impact
impact
[
input_root
]
.
add
(
input_root
)
def
get_impact
(
root
,
view_o
):
return
droot
,
impact
,
root_destroyer
impact
=
OrderedSet
()
add_impact
(
root
,
view_o
,
impact
)
return
impact
def
fast_inplace_check
(
inputs
):
def
fast_inplace_check
(
inputs
):
...
@@ -338,39 +345,10 @@ if 0:
...
@@ -338,39 +345,10 @@ if 0:
def
refresh_droot_impact
(
self
):
def
refresh_droot_impact
(
self
):
if
self
.
stale_droot
:
if
self
.
stale_droot
:
self
.
droot
,
self
.
impact
,
self
.
root_destroyer
=
self
.
_build_droot_impact
(
)
self
.
droot
,
self
.
impact
,
self
.
root_destroyer
=
_build_droot_impact
(
self
)
self
.
stale_droot
=
False
self
.
stale_droot
=
False
return
self
.
droot
,
self
.
impact
,
self
.
root_destroyer
return
self
.
droot
,
self
.
impact
,
self
.
root_destroyer
def
_build_droot_impact
(
self
):
droot
=
{}
# destroyed view + nonview variables -> foundation
impact
=
{}
# destroyed nonview variable -> it + all views of it
root_destroyer
=
{}
# root -> destroyer apply
for
app
in
self
.
destroyers
:
for
output_idx
,
input_idx_list
in
iteritems
(
app
.
op
.
destroy_map
):
if
len
(
input_idx_list
)
!=
1
:
raise
NotImplementedError
()
input_idx
=
input_idx_list
[
0
]
input
=
app
.
inputs
[
input_idx
]
input_root
=
getroot
(
input
,
self
.
view_i
)
if
input_root
in
droot
:
raise
InconsistencyError
(
"Multiple destroyers of
%
s"
%
input_root
)
droot
[
input_root
]
=
input_root
root_destroyer
[
input_root
]
=
app
# input_impact = set([input_root])
# add_impact(input_root, self.view_o, input_impact)
input_impact
=
get_impact
(
input_root
,
self
.
view_o
)
for
v
in
input_impact
:
assert
v
not
in
droot
droot
[
v
]
=
input_root
impact
[
input_root
]
=
input_impact
impact
[
input_root
]
.
add
(
input_root
)
return
droot
,
impact
,
root_destroyer
def
on_detach
(
self
,
fgraph
):
def
on_detach
(
self
,
fgraph
):
if
fgraph
is
not
self
.
fgraph
:
if
fgraph
is
not
self
.
fgraph
:
raise
Exception
(
"detaching wrong fgraph"
,
fgraph
)
raise
Exception
(
"detaching wrong fgraph"
,
fgraph
)
...
@@ -750,30 +728,8 @@ class DestroyHandler(toolbox.Bookkeeper): # noqa
...
@@ -750,30 +728,8 @@ class DestroyHandler(toolbox.Bookkeeper): # noqa
(see docstrings for these properties above)
(see docstrings for these properties above)
"""
"""
if
self
.
stale_droot
:
if
self
.
stale_droot
:
droot
=
OrderedDict
()
# destroyed view + nonview variables -> foundation
self
.
droot
,
self
.
impact
,
self
.
root_destroyer
=
\
impact
=
OrderedDict
()
# destroyed nonview variable -> it + all views of it
_build_droot_impact
(
self
)
root_destroyer
=
OrderedDict
()
# root -> destroyer apply
for
app
in
self
.
destroyers
:
for
output_idx
,
input_idx_list
in
iteritems
(
app
.
op
.
destroy_map
):
if
len
(
input_idx_list
)
!=
1
:
raise
NotImplementedError
()
input_idx
=
input_idx_list
[
0
]
input
=
app
.
inputs
[
input_idx
]
input_root
=
getroot
(
input
,
self
.
view_i
)
if
input_root
in
droot
:
raise
InconsistencyError
(
"Multiple destroyers of
%
s"
%
input_root
)
droot
[
input_root
]
=
input_root
root_destroyer
[
input_root
]
=
app
input_impact
=
get_impact
(
input_root
,
self
.
view_o
)
for
v
in
input_impact
:
assert
v
not
in
droot
droot
[
v
]
=
input_root
impact
[
input_root
]
=
input_impact
impact
[
input_root
]
.
add
(
input_root
)
self
.
droot
,
self
.
impact
,
self
.
root_destroyer
=
droot
,
impact
,
root_destroyer
self
.
stale_droot
=
False
self
.
stale_droot
=
False
return
self
.
droot
,
self
.
impact
,
self
.
root_destroyer
return
self
.
droot
,
self
.
impact
,
self
.
root_destroyer
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论