Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
f1f123b8
提交
f1f123b8
authored
3月 07, 2012
作者:
Razvan Pascanu
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #510 from delallea/test_value_scan_fix
Test value scan fix
上级
fce0a1e8
264cb8f6
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
38 行增加
和
5 行删除
+38
-5
scan_utils.py
theano/scan_module/scan_utils.py
+15
-5
test_scan.py
theano/scan_module/tests/test_scan.py
+23
-0
没有找到文件。
theano/scan_module/scan_utils.py
浏览文件 @
f1f123b8
...
...
@@ -36,7 +36,7 @@ _logger = logging.getLogger('theano.scan_utils')
def
safe_new
(
x
,
tag
=
''
):
"""
Internal function that constructs a new variable from x with the same
type, but with a different name (
old name + tag). This function is used
type, but with a different name (old name + tag). This function is used
by gradient, or the R-op to construct new variables for the inputs of
the inner graph such that there is no interference between the original
graph and the newly constructed graph.
...
...
@@ -58,12 +58,22 @@ def safe_new(x, tag=''):
try
:
x
=
tensor
.
as_tensor_variable
(
x
)
except
TypeError
:
# This could happen
d
for example for random states, and I really
# This could happen for example for random states, and I really
# want to avoid the convoluted logic that checks for cuda
# ndarrays
pass
nw_x
=
x
.
type
()
nw_x
.
name
=
nw_name
# Preserve test values so that the 'compute_test_value' option can be used.
# The test value is deep-copied to ensure there can be no interactions
# between test values, due to inplace operations for instance. This may
# not be the most efficient memory-wise, though.
if
theano
.
config
.
compute_test_value
!=
'off'
:
try
:
nw_x
.
tag
.
test_value
=
copy
.
deepcopy
(
gof
.
op
.
get_test_value
(
x
))
except
AttributeError
:
# This means `x` has no test value.
pass
return
nw_x
...
...
@@ -212,9 +222,9 @@ def get_updates_and_outputs(ls):
'The return value of your scan lambda expression may only be '
'made of lists, tuples, or dictionaries containing Theano '
'variables (or `theano.scan_module.until` objects for '
'conditions). In particular if you need to use constant
values,
'
'
you can use `tensor.constant` to turn them into Thean
o '
'variables.'
)
'conditions). In particular if you need to use constant '
'
values, you can use `tensor.constant` to turn them int
o '
'
Theano
variables.'
)
if
is_outputs
(
ls
):
return
None
,
_list
(
ls
),
{}
...
...
theano/scan_module/tests/test_scan.py
浏览文件 @
f1f123b8
...
...
@@ -3310,3 +3310,26 @@ if __name__ == '__main__':
print 37
scan_tst.test_save_mem_store_steps()
#'''
def
test_compute_test_value
():
"""
Verify that test values can be used with scan.
"""
backup
=
theano
.
config
.
compute_test_value
theano
.
config
.
compute_test_value
=
'raise'
try
:
x
=
tensor
.
vector
()
xv
=
numpy
.
ones
(
3
,
dtype
=
theano
.
config
.
floatX
)
x
.
tag
.
test_value
=
xv
y
=
theano
.
shared
(
numpy
.
arange
(
3
,
dtype
=
theano
.
config
.
floatX
))
z
,
_
=
theano
.
scan
(
fn
=
lambda
u
,
v
:
u
+
v
,
sequences
=
[
x
,
y
])
assert
not
_
# The gradient computation used to crash before 6af465e.
g
=
tensor
.
grad
(
z
.
sum
(),
x
)
#f = theano.function([x], g)
#print f(xv)
finally
:
theano
.
config
.
compute_test_value
=
backup
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论