Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
8c4e330d
提交
8c4e330d
authored
7月 10, 2015
作者:
Iban Harlouchet
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
flake8 of theano/gof/destroyhandler.py
上级
b129fb77
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
33 行增加
和
32 行删除
+33
-32
destroyhandler.py
theano/gof/destroyhandler.py
+33
-31
test_flake8.py
theano/tests/test_flake8.py
+0
-1
没有找到文件。
theano/gof/destroyhandler.py
浏览文件 @
8c4e330d
...
@@ -46,7 +46,6 @@ def _contains_cycle(fgraph, orderings):
...
@@ -46,7 +46,6 @@ def _contains_cycle(fgraph, orderings):
"""
"""
# These are lists of Variable instances
# These are lists of Variable instances
inputs
=
fgraph
.
inputs
outputs
=
fgraph
.
outputs
outputs
=
fgraph
.
outputs
# this is hard-coded reimplementation of functions from graph.py
# this is hard-coded reimplementation of functions from graph.py
...
@@ -65,8 +64,6 @@ def _contains_cycle(fgraph, orderings):
...
@@ -65,8 +64,6 @@ def _contains_cycle(fgraph, orderings):
# (defaultdict runs faster than dict in the case where the key
# (defaultdict runs faster than dict in the case where the key
# is not in the dictionary, at least in CPython)
# is not in the dictionary, at least in CPython)
iset
=
set
(
inputs
)
# IG: I tried converting parent_counts to use an id for the key,
# IG: I tried converting parent_counts to use an id for the key,
# so that the dict would do reference counting on its keys.
# so that the dict would do reference counting on its keys.
# This caused a slowdown.
# This caused a slowdown.
...
@@ -236,9 +233,9 @@ def fast_inplace_check(inputs):
...
@@ -236,9 +233,9 @@ def fast_inplace_check(inputs):
protected_inputs
.
extend
(
fgraph
.
outputs
)
protected_inputs
.
extend
(
fgraph
.
outputs
)
inputs
=
[
i
for
i
in
inputs
if
inputs
=
[
i
for
i
in
inputs
if
not
isinstance
(
i
,
graph
.
Constant
)
not
isinstance
(
i
,
graph
.
Constant
)
and
and
not
fgraph
.
destroyers
(
i
)
not
fgraph
.
destroyers
(
i
)
and
and
i
not
in
protected_inputs
]
i
not
in
protected_inputs
]
return
inputs
return
inputs
if
0
:
if
0
:
...
@@ -293,7 +290,7 @@ if 0:
...
@@ -293,7 +290,7 @@ if 0:
TODO: WRITEME: what does this do besides the checks?
TODO: WRITEME: what does this do besides the checks?
"""
"""
#
###### Do the checking ##########
#
#
Do the checking
#
already_there
=
False
already_there
=
False
if
self
.
fgraph
not
in
[
None
,
fgraph
]:
if
self
.
fgraph
not
in
[
None
,
fgraph
]:
raise
Exception
(
"A DestroyHandler instance can only serve"
raise
Exception
(
"A DestroyHandler instance can only serve"
...
@@ -309,7 +306,7 @@ if 0:
...
@@ -309,7 +306,7 @@ if 0:
"DestroyHandler feature is already present or in"
"DestroyHandler feature is already present or in"
" conflict with another plugin."
)
" conflict with another plugin."
)
#
###### end of checking ###########
#
#
end of checking
#
def
get_destroyers_of
(
r
):
def
get_destroyers_of
(
r
):
droot
,
impact
,
root_destroyer
=
self
.
refresh_droot_impact
()
droot
,
impact
,
root_destroyer
=
self
.
refresh_droot_impact
()
...
@@ -362,8 +359,8 @@ if 0:
...
@@ -362,8 +359,8 @@ if 0:
"Multiple destroyers of
%
s"
%
input_root
)
"Multiple destroyers of
%
s"
%
input_root
)
droot
[
input_root
]
=
input_root
droot
[
input_root
]
=
input_root
root_destroyer
[
input_root
]
=
app
root_destroyer
[
input_root
]
=
app
#input_impact = set([input_root])
#
input_impact = set([input_root])
#add_impact(input_root, self.view_o, input_impact)
#
add_impact(input_root, self.view_o, input_impact)
input_impact
=
get_impact
(
input_root
,
self
.
view_o
)
input_impact
=
get_impact
(
input_root
,
self
.
view_o
)
for
v
in
input_impact
:
for
v
in
input_impact
:
assert
v
not
in
droot
assert
v
not
in
droot
...
@@ -390,7 +387,7 @@ if 0:
...
@@ -390,7 +387,7 @@ if 0:
def
on_import
(
self
,
fgraph
,
app
,
reason
):
def
on_import
(
self
,
fgraph
,
app
,
reason
):
"""Add Apply instance to set which must be computed"""
"""Add Apply instance to set which must be computed"""
#if app in self.debug_all_apps: raise ProtocolError("double import")
#
if app in self.debug_all_apps: raise ProtocolError("double import")
# self.debug_all_apps.add(app)
# self.debug_all_apps.add(app)
# print 'DH IMPORT', app, id(app), id(self), len(self.debug_all_apps)
# print 'DH IMPORT', app, id(app), id(self), len(self.debug_all_apps)
...
@@ -421,7 +418,7 @@ if 0:
...
@@ -421,7 +418,7 @@ if 0:
def
on_prune
(
self
,
fgraph
,
app
,
reason
):
def
on_prune
(
self
,
fgraph
,
app
,
reason
):
"""Remove Apply instance from set which must be computed"""
"""Remove Apply instance from set which must be computed"""
#if app not in self.debug_all_apps: raise ProtocolError("prune without import")
#
if app not in self.debug_all_apps: raise ProtocolError("prune without import")
# self.debug_all_apps.remove(app)
# self.debug_all_apps.remove(app)
# UPDATE self.clients
# UPDATE self.clients
...
@@ -458,7 +455,7 @@ if 0:
...
@@ -458,7 +455,7 @@ if 0:
# considered 'outputs' of the graph.
# considered 'outputs' of the graph.
pass
pass
else
:
else
:
#if app not in self.debug_all_apps: raise ProtocolError("change without import")
#
if app not in self.debug_all_apps: raise ProtocolError("change without import")
# UPDATE self.clients
# UPDATE self.clients
self
.
clients
[
old_r
][
app
]
-=
1
self
.
clients
[
old_r
][
app
]
-=
1
...
@@ -529,9 +526,10 @@ if 0:
...
@@ -529,9 +526,10 @@ if 0:
droot
,
impact
,
__ignore
=
self
.
refresh_droot_impact
()
droot
,
impact
,
__ignore
=
self
.
refresh_droot_impact
()
# check for destruction of constants
# check for destruction of constants
illegal_destroy
=
[
r
for
r
in
droot
if
illegal_destroy
=
[
getattr
(
r
.
tag
,
'indestructible'
,
False
)
or
r
for
r
in
droot
if
isinstance
(
r
,
graph
.
Constant
)]
getattr
(
r
.
tag
,
'indestructible'
,
False
)
or
isinstance
(
r
,
graph
.
Constant
)]
if
illegal_destroy
:
if
illegal_destroy
:
# print 'destroying illegally'
# print 'destroying illegally'
raise
InconsistencyError
(
raise
InconsistencyError
(
...
@@ -603,7 +601,7 @@ if 0:
...
@@ -603,7 +601,7 @@ if 0:
if
input
in
root_impact
\
if
input
in
root_impact
\
and
(
i
not
in
tolerated
or
input
is
not
destroyed_variable
):
and
(
i
not
in
tolerated
or
input
is
not
destroyed_variable
):
raise
InconsistencyError
(
"Input aliasing:
%
s (
%
i,
%
i)"
raise
InconsistencyError
(
"Input aliasing:
%
s (
%
i,
%
i)"
%
(
app
,
destroyed_idx
,
i
))
%
(
app
,
destroyed_idx
,
i
))
# add the rule: app must be preceded by all other Apply instances that
# add the rule: app must be preceded by all other Apply instances that
# depend on destroyed_input
# depend on destroyed_input
...
@@ -621,7 +619,7 @@ if 0:
...
@@ -621,7 +619,7 @@ if 0:
return
rval
return
rval
class
DestroyHandler
(
toolbox
.
Bookkeeper
):
class
DestroyHandler
(
toolbox
.
Bookkeeper
):
# noqa
"""
"""
The DestroyHandler class detects when a graph is impossible to evaluate
The DestroyHandler class detects when a graph is impossible to evaluate
because of aliasing and destructive operations.
because of aliasing and destructive operations.
...
@@ -702,7 +700,7 @@ class DestroyHandler(toolbox.Bookkeeper):
...
@@ -702,7 +700,7 @@ class DestroyHandler(toolbox.Bookkeeper):
TODO: WRITEME: what does this do besides the checks?
TODO: WRITEME: what does this do besides the checks?
"""
"""
#
###### Do the checking ##########
#
#
Do the checking
#
already_there
=
False
already_there
=
False
if
self
.
fgraph
is
fgraph
:
if
self
.
fgraph
is
fgraph
:
already_there
=
True
already_there
=
True
...
@@ -720,7 +718,7 @@ class DestroyHandler(toolbox.Bookkeeper):
...
@@ -720,7 +718,7 @@ class DestroyHandler(toolbox.Bookkeeper):
"DestroyHandler feature is already present"
"DestroyHandler feature is already present"
" or in conflict with another plugin."
)
" or in conflict with another plugin."
)
#
###### Annotate the FunctionGraph ###########
#
#
Annotate the FunctionGraph
#
self
.
unpickle
(
fgraph
)
self
.
unpickle
(
fgraph
)
fgraph
.
destroy_handler
=
self
fgraph
.
destroy_handler
=
self
...
@@ -945,12 +943,13 @@ class DestroyHandler(toolbox.Bookkeeper):
...
@@ -945,12 +943,13 @@ class DestroyHandler(toolbox.Bookkeeper):
droot
,
impact
,
__ignore
=
self
.
refresh_droot_impact
()
droot
,
impact
,
__ignore
=
self
.
refresh_droot_impact
()
# check for destruction of constants
# check for destruction of constants
illegal_destroy
=
[
r
for
r
in
droot
if
\
illegal_destroy
=
[
r
for
r
in
droot
if
getattr
(
r
.
tag
,
'indestructible'
,
False
)
or
\
getattr
(
r
.
tag
,
'indestructible'
,
False
)
or
isinstance
(
r
,
graph
.
Constant
)]
isinstance
(
r
,
graph
.
Constant
)]
if
illegal_destroy
:
if
illegal_destroy
:
raise
InconsistencyError
(
"Attempting to destroy indestructible variables:
%
s"
%
raise
InconsistencyError
(
illegal_destroy
)
"Attempting to destroy indestructible variables:
%
s"
%
illegal_destroy
)
# add destroyed variable clients as computational dependencies
# add destroyed variable clients as computational dependencies
for
app
in
self
.
destroyers
:
for
app
in
self
.
destroyers
:
...
@@ -995,24 +994,27 @@ class DestroyHandler(toolbox.Bookkeeper):
...
@@ -995,24 +994,27 @@ class DestroyHandler(toolbox.Bookkeeper):
# CHECK FOR INPUT ALIASING
# CHECK FOR INPUT ALIASING
# OPT: pre-compute this on import
# OPT: pre-compute this on import
tolerate_same
=
getattr
(
app
.
op
,
'destroyhandler_tolerate_same'
,
[])
tolerate_same
=
getattr
(
app
.
op
,
'destroyhandler_tolerate_same'
,
[])
assert
isinstance
(
tolerate_same
,
list
)
assert
isinstance
(
tolerate_same
,
list
)
tolerated
=
OrderedSet
(
idx1
for
idx0
,
idx1
in
tolerate_same
tolerated
=
OrderedSet
(
idx1
for
idx0
,
idx1
in
tolerate_same
if
idx0
==
destroyed_idx
)
if
idx0
==
destroyed_idx
)
tolerated
.
add
(
destroyed_idx
)
tolerated
.
add
(
destroyed_idx
)
tolerate_aliased
=
getattr
(
app
.
op
,
'destroyhandler_tolerate_aliased'
,
[])
tolerate_aliased
=
getattr
(
app
.
op
,
'destroyhandler_tolerate_aliased'
,
[])
assert
isinstance
(
tolerate_aliased
,
list
)
assert
isinstance
(
tolerate_aliased
,
list
)
ignored
=
OrderedSet
(
idx1
for
idx0
,
idx1
in
tolerate_aliased
ignored
=
OrderedSet
(
idx1
for
idx0
,
idx1
in
tolerate_aliased
if
idx0
==
destroyed_idx
)
if
idx0
==
destroyed_idx
)
# print 'tolerated', tolerated
# print 'tolerated', tolerated
# print 'ignored', ignored
# print 'ignored', ignored
for
i
,
input
in
enumerate
(
app
.
inputs
):
for
i
,
input
in
enumerate
(
app
.
inputs
):
if
i
in
ignored
:
if
i
in
ignored
:
continue
continue
if
input
in
root_impact
\
if
input
in
root_impact
\
and
(
i
not
in
tolerated
or
input
is
not
destroyed_variable
):
and
(
i
not
in
tolerated
or
input
is
not
destroyed_variable
):
raise
InconsistencyError
(
"Input aliasing:
%
s (
%
i,
%
i)"
raise
InconsistencyError
(
"Input aliasing:
%
s (
%
i,
%
i)"
%
(
app
,
destroyed_idx
,
i
))
%
(
app
,
destroyed_idx
,
i
))
# add the rule: app must be preceded by all other Apply instances that
# add the rule: app must be preceded by all other Apply instances that
# depend on destroyed_input
# depend on destroyed_input
...
...
theano/tests/test_flake8.py
浏览文件 @
8c4e330d
...
@@ -240,7 +240,6 @@ whitelist_flake8 = [
...
@@ -240,7 +240,6 @@ whitelist_flake8 = [
"sparse/sandbox/sp2.py"
,
"sparse/sandbox/sp2.py"
,
"sparse/sandbox/truedot.py"
,
"sparse/sandbox/truedot.py"
,
"sparse/sandbox/sp.py"
,
"sparse/sandbox/sp.py"
,
"gof/destroyhandler.py"
,
"gof/unify.py"
,
"gof/unify.py"
,
"gof/graph.py"
,
"gof/graph.py"
,
"gof/__init__.py"
,
"gof/__init__.py"
,
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论