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 个修改的文件
包含
35 行增加
和
20 行删除
+35
-20
toolbox.py
theano/gof/toolbox.py
+35
-20
没有找到文件。
theano/gof/toolbox.py
浏览文件 @
55470b76
...
...
@@ -10,7 +10,7 @@ class AlreadyThere(Exception):
class
Bookkeeper
:
def
on_attach
(
self
,
env
):
for
node
in
graph
.
io_toposort
(
env
.
inputs
,
env
.
outputs
):
self
.
on_import
(
env
,
node
)
...
...
@@ -18,7 +18,7 @@ class Bookkeeper:
def
on_detach
(
self
,
env
):
for
node
in
graph
.
io_toposort
(
env
.
inputs
,
env
.
outputs
):
self
.
on_prune
(
env
,
node
)
class
History
:
...
...
@@ -27,7 +27,8 @@ class History:
def
on_attach
(
self
,
env
):
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
]
=
[]
env
.
checkpoint
=
lambda
:
len
(
self
.
history
[
env
])
env
.
revert
=
partial
(
self
.
revert
,
env
)
...
...
@@ -41,8 +42,9 @@ class History:
if
self
.
history
[
env
]
is
None
:
return
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
):
"""
Reverts the graph to whatever it was at the provided
...
...
@@ -61,8 +63,10 @@ class Validator:
def
on_attach
(
self
,
env
):
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'
)
def
consistent
():
try
:
env
.
validate
()
...
...
@@ -81,9 +85,10 @@ class ReplaceValidate(History, Validator):
def
on_attach
(
self
,
env
):
History
.
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
):
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_all_validate
=
partial
(
self
.
replace_all_validate
,
env
)
...
...
@@ -101,10 +106,16 @@ class ReplaceValidate(History, Validator):
for
r
,
new_r
in
replacements
:
try
:
env
.
replace
(
r
,
new_r
,
reason
=
reason
)
print
reason
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
):
print
>>
sys
.
stderr
,
"<<!! BUG IN ENV.REPLACE OR A LISTENER !!>>"
,
type
(
e
),
e
,
reason
env
.
revert
(
chk
)
# this might fail if the error is in a listener: (env.replace kinda needs better internal error handling)
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
)):
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
try
:
env
.
validate
()
...
...
@@ -117,19 +128,21 @@ class NodeFinder(dict, Bookkeeper):
def
__init__
(
self
):
self
.
env
=
None
def
on_attach
(
self
,
env
):
if
self
.
env
is
not
None
:
raise
Exception
(
"A NodeFinder instance can only serve one Env."
)
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
env
.
get_nodes
=
partial
(
self
.
query
,
env
)
Bookkeeper
.
on_attach
(
self
,
env
)
def
on_detach
(
self
,
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
del
env
.
get_nodes
Bookkeeper
.
on_detach
(
self
,
env
)
...
...
@@ -137,7 +150,7 @@ class NodeFinder(dict, Bookkeeper):
def
on_import
(
self
,
env
,
node
):
try
:
self
.
setdefault
(
node
.
op
,
[])
.
append
(
node
)
except
TypeError
:
#
node.op is unhashable
except
TypeError
:
#
node.op is unhashable
return
except
Exception
,
e
:
print
>>
sys
.
stderr
,
'OFFENDING node'
,
type
(
node
),
type
(
node
.
op
)
...
...
@@ -150,7 +163,7 @@ class NodeFinder(dict, Bookkeeper):
def
on_prune
(
self
,
env
,
node
):
try
:
nodes
=
self
[
node
.
op
]
except
TypeError
:
#
node.op is unhashable
except
TypeError
:
#
node.op is unhashable
return
nodes
.
remove
(
node
)
if
not
nodes
:
...
...
@@ -160,16 +173,17 @@ class NodeFinder(dict, Bookkeeper):
try
:
all
=
self
.
get
(
op
,
[])
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
)
return
all
class
PrintListener
(
object
):
def
__init__
(
self
,
active
=
True
):
def
__init__
(
self
,
active
=
True
):
self
.
active
=
active
def
on_attach
(
self
,
env
):
if
self
.
active
:
print
"-- attaching to: "
,
env
...
...
@@ -188,7 +202,8 @@ class PrintListener(object):
def
on_change_input
(
self
,
env
,
node
,
i
,
r
,
new_r
,
reason
=
None
):
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
:
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论