Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
834f0b6a
提交
834f0b6a
authored
2月 12, 2009
作者:
James Bergstra
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
reasons are being passed around during optimization... with an ugly hack to env.execute_callback
上级
52dff24f
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
24 行增加
和
17 行删除
+24
-17
env.py
theano/gof/env.py
+12
-6
opt.py
theano/gof/opt.py
+4
-4
toolbox.py
theano/gof/toolbox.py
+6
-6
opt.py
theano/tensor/opt.py
+2
-1
没有找到文件。
theano/gof/env.py
浏览文件 @
834f0b6a
...
...
@@ -297,10 +297,7 @@ class Env(utils.object2):
self
.
__import_r__
([
new_r
])
self
.
__add_clients__
(
new_r
,
[(
node
,
i
)])
prune
=
self
.
__remove_clients__
(
r
,
[(
node
,
i
)],
False
)
if
reason
is
None
:
self
.
execute_callbacks
(
'on_change_input'
,
node
,
i
,
r
,
new_r
)
else
:
self
.
execute_callbacks
(
'on_change_input_with_reason'
,
node
,
i
,
r
,
new_r
,
reason
)
self
.
execute_callbacks
(
'on_change_input'
,
node
,
i
,
r
,
new_r
,
reason
=
reason
)
if
prune
:
self
.
__prune_r__
([
r
])
...
...
@@ -367,7 +364,7 @@ class Env(utils.object2):
### callback utils ###
def
execute_callbacks
(
self
,
name
,
*
args
):
def
execute_callbacks
(
self
,
name
,
*
args
,
**
kwargs
):
"""WRITEME
Calls
getattr(feature, name)(*args)
...
...
@@ -378,7 +375,16 @@ class Env(utils.object2):
fn
=
getattr
(
feature
,
name
)
except
AttributeError
:
continue
fn
(
self
,
*
args
)
#####HORRIBLE OPTIONAL ARGUMENT HACK
try
:
fn
(
self
,
*
args
,
**
kwargs
)
except
TypeError
,
e
:
if
str
(
e
)
==
"on_change_input() got an unexpected keyword argument 'reason'"
and
len
(
kwargs
)
==
1
:
fn
(
self
,
*
args
)
else
:
raise
def
collect_callbacks
(
self
,
name
,
*
args
):
"""WRITEME
...
...
theano/gof/opt.py
浏览文件 @
834f0b6a
...
...
@@ -189,7 +189,7 @@ class MergeOptimizer(Optimizer):
# we adopt convention to keep the last name
if
c
.
name
:
other_c
.
name
=
c
.
name
env
.
replace_validate
(
c
,
other_c
)
env
.
replace_validate
(
c
,
other_c
,
reason
=
'Constant Merge'
)
else
:
#this is a new constant
const_sig
[
c
]
=
sig
...
...
@@ -219,7 +219,7 @@ class MergeOptimizer(Optimizer):
if
output
.
name
and
not
new_output
.
name
:
new_output
.
name
=
output
.
name
try
:
env
.
replace_all_validate
(
pairs
)
env
.
replace_all_validate
(
pairs
,
reason
=
'Merge (exptime)'
)
except
InconsistencyError
,
e
:
success
=
False
if
not
success
:
...
...
@@ -266,7 +266,7 @@ class MergeOptimizer(Optimizer):
if
node_output
.
name
:
cand_output
.
name
=
node_output
.
name
try
:
env
.
replace_all_validate
(
pairs
)
env
.
replace_all_validate
(
pairs
,
reason
=
"Merge"
)
except
InconsistencyError
,
e
:
success
=
False
...
...
@@ -714,7 +714,7 @@ class NavigatorOptimizer(Optimizer):
return
False
repl_pairs
=
zip
(
node
.
outputs
,
replacements
)
try
:
env
.
replace_all_validate
(
repl_pairs
)
env
.
replace_all_validate
(
repl_pairs
,
reason
=
lopt
)
return
True
except
Exception
,
e
:
# This means the replacements were rejected by the env.
...
...
theano/gof/toolbox.py
浏览文件 @
834f0b6a
...
...
@@ -36,11 +36,11 @@ class History:
del
env
.
revert
del
self
.
history
[
env
]
def
on_change_input
(
self
,
env
,
node
,
i
,
r
,
new_r
):
def
on_change_input
(
self
,
env
,
node
,
i
,
r
,
new_r
,
reason
=
None
):
if
self
.
history
[
env
]
is
None
:
return
h
=
self
.
history
[
env
]
h
.
append
(
lambda
:
env
.
change_input
(
node
,
i
,
r
))
h
.
append
(
lambda
:
env
.
change_input
(
node
,
i
,
r
,
reason
=
(
"Revert"
,
reason
)
))
def
revert
(
self
,
env
,
checkpoint
):
"""
...
...
@@ -92,14 +92,14 @@ class ReplaceValidate(History, Validator):
del
env
.
replace_validate
del
env
.
replace_all_validate
def
replace_validate
(
self
,
env
,
r
,
new_r
):
self
.
replace_all_validate
(
env
,
[(
r
,
new_r
)])
def
replace_validate
(
self
,
env
,
r
,
new_r
,
reason
=
None
):
self
.
replace_all_validate
(
env
,
[(
r
,
new_r
)]
,
reason
=
reason
)
def
replace_all_validate
(
self
,
env
,
replacements
):
def
replace_all_validate
(
self
,
env
,
replacements
,
reason
=
None
):
chk
=
env
.
checkpoint
()
for
r
,
new_r
in
replacements
:
try
:
env
.
replace
(
r
,
new_r
)
env
.
replace
(
r
,
new_r
,
reason
=
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
...
...
theano/tensor/opt.py
浏览文件 @
834f0b6a
...
...
@@ -64,7 +64,8 @@ def insert_inplace_optimizer(env):
*
[
inplace_pattern
.
get
(
i
,
None
)
\
for
i
in
xrange
(
len
(
node
.
outputs
))])),
inplace_pattern
)
.
make_node
(
*
node
.
inputs
)
env
.
replace_all_validate
(
zip
(
node
.
outputs
,
new
.
outputs
))
env
.
replace_all_validate
(
zip
(
node
.
outputs
,
new
.
outputs
),
reason
=
"insert_inplace_optimizer"
)
except
(
ValueError
,
TypeError
,
InconsistencyError
),
e
:
continue
candidate_inputs
.
remove
(
candidate_input
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论