Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
55470b76
提交
55470b76
authored
10月 27, 2011
作者:
Frederic
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
pep8 fix.
上级
60d6b2e5
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
29 行增加
和
14 行删除
+29
-14
toolbox.py
theano/gof/toolbox.py
+29
-14
没有找到文件。
theano/gof/toolbox.py
浏览文件 @
55470b76
...
@@ -27,7 +27,8 @@ class History:
...
@@ -27,7 +27,8 @@ class History:
def
on_attach
(
self
,
env
):
def
on_attach
(
self
,
env
):
if
hasattr
(
env
,
'checkpoint'
)
or
hasattr
(
env
,
'revert'
):
if
hasattr
(
env
,
'checkpoint'
)
or
hasattr
(
env
,
'revert'
):
raise
AlreadyThere
(
"History feature is already present or in conflict with another plugin."
)
raise
AlreadyThere
(
"History feature is already present or in"
" conflict with another plugin."
)
self
.
history
[
env
]
=
[]
self
.
history
[
env
]
=
[]
env
.
checkpoint
=
lambda
:
len
(
self
.
history
[
env
])
env
.
checkpoint
=
lambda
:
len
(
self
.
history
[
env
])
env
.
revert
=
partial
(
self
.
revert
,
env
)
env
.
revert
=
partial
(
self
.
revert
,
env
)
...
@@ -41,7 +42,8 @@ class History:
...
@@ -41,7 +42,8 @@ class History:
if
self
.
history
[
env
]
is
None
:
if
self
.
history
[
env
]
is
None
:
return
return
h
=
self
.
history
[
env
]
h
=
self
.
history
[
env
]
h
.
append
(
lambda
:
env
.
change_input
(
node
,
i
,
r
,
reason
=
(
"Revert"
,
reason
)))
h
.
append
(
lambda
:
env
.
change_input
(
node
,
i
,
r
,
reason
=
(
"Revert"
,
reason
)))
def
revert
(
self
,
env
,
checkpoint
):
def
revert
(
self
,
env
,
checkpoint
):
"""
"""
...
@@ -61,8 +63,10 @@ class Validator:
...
@@ -61,8 +63,10 @@ class Validator:
def
on_attach
(
self
,
env
):
def
on_attach
(
self
,
env
):
if
hasattr
(
env
,
'validate'
):
if
hasattr
(
env
,
'validate'
):
raise
AlreadyThere
(
"Validator feature is already present or in conflict with another plugin."
)
raise
AlreadyThere
(
"Validator feature is already present or in"
" conflict with another plugin."
)
env
.
validate
=
lambda
:
env
.
execute_callbacks
(
'validate'
)
env
.
validate
=
lambda
:
env
.
execute_callbacks
(
'validate'
)
def
consistent
():
def
consistent
():
try
:
try
:
env
.
validate
()
env
.
validate
()
...
@@ -83,7 +87,8 @@ class ReplaceValidate(History, Validator):
...
@@ -83,7 +87,8 @@ class ReplaceValidate(History, Validator):
Validator
.
on_attach
(
self
,
env
)
Validator
.
on_attach
(
self
,
env
)
for
attr
in
(
'replace_validate'
,
'replace_all_validate'
):
for
attr
in
(
'replace_validate'
,
'replace_all_validate'
):
if
hasattr
(
env
,
attr
):
if
hasattr
(
env
,
attr
):
raise
AlreadyThere
(
"ReplaceValidate feature is already present or in conflict with another plugin."
)
raise
AlreadyThere
(
"ReplaceValidate feature is already present"
" or in conflict with another plugin."
)
env
.
replace_validate
=
partial
(
self
.
replace_validate
,
env
)
env
.
replace_validate
=
partial
(
self
.
replace_validate
,
env
)
env
.
replace_all_validate
=
partial
(
self
.
replace_all_validate
,
env
)
env
.
replace_all_validate
=
partial
(
self
.
replace_all_validate
,
env
)
...
@@ -101,10 +106,16 @@ class ReplaceValidate(History, Validator):
...
@@ -101,10 +106,16 @@ class ReplaceValidate(History, Validator):
for
r
,
new_r
in
replacements
:
for
r
,
new_r
in
replacements
:
try
:
try
:
env
.
replace
(
r
,
new_r
,
reason
=
reason
)
env
.
replace
(
r
,
new_r
,
reason
=
reason
)
print
reason
except
Exception
,
e
:
except
Exception
,
e
:
if
'The type of the replacement must be the same'
not
in
str
(
e
)
and
'does not belong to this Env'
not
in
str
(
e
):
if
(
'The type of the replacement must be the same'
not
in
print
>>
sys
.
stderr
,
"<<!! BUG IN ENV.REPLACE OR A LISTENER !!>>"
,
type
(
e
),
e
,
reason
str
(
e
)
and
'does not belong to this Env'
not
in
str
(
e
)):
env
.
revert
(
chk
)
# this might fail if the error is in a listener: (env.replace kinda needs better internal error handling)
out
=
sys
.
stderr
print
>>
out
,
"<<!! BUG IN ENV.REPLACE OR A LISTENER !!>>"
,
print
>>
out
,
type
(
e
),
e
,
reason
# this might fail if the error is in a listener:
# (env.replace kinda needs better internal error handling)
env
.
revert
(
chk
)
raise
raise
try
:
try
:
env
.
validate
()
env
.
validate
()
...
@@ -122,14 +133,16 @@ class NodeFinder(dict, Bookkeeper):
...
@@ -122,14 +133,16 @@ class NodeFinder(dict, Bookkeeper):
if
self
.
env
is
not
None
:
if
self
.
env
is
not
None
:
raise
Exception
(
"A NodeFinder instance can only serve one Env."
)
raise
Exception
(
"A NodeFinder instance can only serve one Env."
)
if
hasattr
(
env
,
'get_nodes'
):
if
hasattr
(
env
,
'get_nodes'
):
raise
AlreadyThere
(
"NodeFinder is already present or in conflict with another plugin."
)
raise
AlreadyThere
(
"NodeFinder is already present or in conflict"
" with another plugin."
)
self
.
env
=
env
self
.
env
=
env
env
.
get_nodes
=
partial
(
self
.
query
,
env
)
env
.
get_nodes
=
partial
(
self
.
query
,
env
)
Bookkeeper
.
on_attach
(
self
,
env
)
Bookkeeper
.
on_attach
(
self
,
env
)
def
on_detach
(
self
,
env
):
def
on_detach
(
self
,
env
):
if
self
.
env
is
not
env
:
if
self
.
env
is
not
env
:
raise
Exception
(
"This NodeFinder instance was not attached to the provided env."
)
raise
Exception
(
"This NodeFinder instance was not attached to the"
" provided env."
)
self
.
env
=
None
self
.
env
=
None
del
env
.
get_nodes
del
env
.
get_nodes
Bookkeeper
.
on_detach
(
self
,
env
)
Bookkeeper
.
on_detach
(
self
,
env
)
...
@@ -137,7 +150,7 @@ class NodeFinder(dict, Bookkeeper):
...
@@ -137,7 +150,7 @@ class NodeFinder(dict, Bookkeeper):
def
on_import
(
self
,
env
,
node
):
def
on_import
(
self
,
env
,
node
):
try
:
try
:
self
.
setdefault
(
node
.
op
,
[])
.
append
(
node
)
self
.
setdefault
(
node
.
op
,
[])
.
append
(
node
)
except
TypeError
:
#
node.op is unhashable
except
TypeError
:
#
node.op is unhashable
return
return
except
Exception
,
e
:
except
Exception
,
e
:
print
>>
sys
.
stderr
,
'OFFENDING node'
,
type
(
node
),
type
(
node
.
op
)
print
>>
sys
.
stderr
,
'OFFENDING node'
,
type
(
node
),
type
(
node
.
op
)
...
@@ -150,7 +163,7 @@ class NodeFinder(dict, Bookkeeper):
...
@@ -150,7 +163,7 @@ class NodeFinder(dict, Bookkeeper):
def
on_prune
(
self
,
env
,
node
):
def
on_prune
(
self
,
env
,
node
):
try
:
try
:
nodes
=
self
[
node
.
op
]
nodes
=
self
[
node
.
op
]
except
TypeError
:
#
node.op is unhashable
except
TypeError
:
#
node.op is unhashable
return
return
nodes
.
remove
(
node
)
nodes
.
remove
(
node
)
if
not
nodes
:
if
not
nodes
:
...
@@ -160,14 +173,15 @@ class NodeFinder(dict, Bookkeeper):
...
@@ -160,14 +173,15 @@ class NodeFinder(dict, Bookkeeper):
try
:
try
:
all
=
self
.
get
(
op
,
[])
all
=
self
.
get
(
op
,
[])
except
TypeError
:
except
TypeError
:
raise
TypeError
(
"
%
s in unhashable and cannot be queried by the optimizer"
%
op
)
raise
TypeError
(
"
%
s in unhashable and cannot be queried by the"
" optimizer"
%
op
)
all
=
list
(
all
)
all
=
list
(
all
)
return
all
return
all
class
PrintListener
(
object
):
class
PrintListener
(
object
):
def
__init__
(
self
,
active
=
True
):
def
__init__
(
self
,
active
=
True
):
self
.
active
=
active
self
.
active
=
active
def
on_attach
(
self
,
env
):
def
on_attach
(
self
,
env
):
...
@@ -188,7 +202,8 @@ class PrintListener(object):
...
@@ -188,7 +202,8 @@ class PrintListener(object):
def
on_change_input
(
self
,
env
,
node
,
i
,
r
,
new_r
,
reason
=
None
):
def
on_change_input
(
self
,
env
,
node
,
i
,
r
,
new_r
,
reason
=
None
):
if
self
.
active
:
if
self
.
active
:
print
"-- changing (
%
s.inputs[
%
s]) from
%
s to
%
s"
%
(
node
,
i
,
r
,
new_r
)
print
"-- changing (
%
s.inputs[
%
s]) from
%
s to
%
s"
%
(
node
,
i
,
r
,
new_r
)
class
PreserveNames
:
class
PreserveNames
:
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论