Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
bbda20ee
提交
bbda20ee
authored
6月 03, 2015
作者:
Frédéric Bastien
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #2996 from lamblin/scan_test_values
Scan test values
上级
2846a3aa
f210d812
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
38 行增加
和
4 行删除
+38
-4
scan_utils.py
theano/scan_module/scan_utils.py
+15
-3
test_scan.py
theano/scan_module/tests/test_scan.py
+23
-1
没有找到文件。
theano/scan_module/scan_utils.py
浏览文件 @
bbda20ee
...
@@ -64,6 +64,16 @@ def safe_new(x, tag='', dtype=None):
...
@@ -64,6 +64,16 @@ def safe_new(x, tag='', dtype=None):
else
:
else
:
nw_x
=
x
.
type
()
nw_x
=
x
.
type
()
nw_x
.
name
=
nw_name
nw_x
.
name
=
nw_name
if
theano
.
config
.
compute_test_value
!=
'off'
:
# Copy test value, cast it if necessary
try
:
x_test_value
=
gof
.
op
.
get_test_value
(
x
)
except
AttributeError
:
# There is no test value
pass
else
:
# This clause is executed if no exception was raised
nw_x
.
tag
.
test_value
=
nw_x
.
type
.
filter
(
x_test_value
)
return
nw_x
return
nw_x
else
:
else
:
try
:
try
:
...
@@ -73,11 +83,13 @@ def safe_new(x, tag='', dtype=None):
...
@@ -73,11 +83,13 @@ def safe_new(x, tag='', dtype=None):
# want to avoid the convoluted logic that checks for cuda
# want to avoid the convoluted logic that checks for cuda
# ndarrays
# ndarrays
pass
pass
# Cast x if needed. If x has a test value, this will also cast it.
if
dtype
and
x
.
dtype
!=
dtype
:
x
=
x
.
astype
(
dtype
)
nw_x
=
x
.
type
()
nw_x
=
x
.
type
()
if
dtype
and
nw_x
.
dtype
!=
dtype
:
nw_x
=
nw_x
.
astype
(
dtype
)
.
type
()
nw_x
.
name
=
nw_name
nw_x
.
name
=
nw_name
# Preserve test values so that the 'compute_test_value' option can be used.
# 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
# The test value is deep-copied to ensure there can be no interactions
# between test values, due to inplace operations for instance. This may
# between test values, due to inplace operations for instance. This may
...
...
theano/scan_module/tests/test_scan.py
浏览文件 @
bbda20ee
...
@@ -4983,12 +4983,34 @@ def test_compute_test_value_grad():
...
@@ -4983,12 +4983,34 @@ def test_compute_test_value_grad():
)
)
loss
=
result_mi
[
-
1
]
loss
=
result_mi
[
-
1
]
grad
=
tensor
.
grad
(
loss
,
W_flat
)
tensor
.
grad
(
loss
,
W_flat
)
finally
:
finally
:
theano
.
config
.
compute_test_value
=
old_compute_test_val
theano
.
config
.
compute_test_value
=
old_compute_test_val
theano
.
config
.
exception_verbosity
=
old_exception_verbosity
theano
.
config
.
exception_verbosity
=
old_exception_verbosity
def
test_compute_test_value_grad_cast
():
# Test for test values when variables have to be casted
# Reported by Daniel Renshaw at
# https://groups.google.com/d/topic/theano-users/o4jK9xDe5WI/discussion
backup
=
theano
.
config
.
compute_test_value
theano
.
config
.
compute_test_value
=
'raise'
try
:
h
=
tensor
.
matrix
(
'h'
)
h
.
tag
.
test_value
=
numpy
.
array
([[
1
,
2
,
3
,
4
],
[
5
,
6
,
7
,
8
]],
dtype
=
numpy
.
float64
)
w
=
theano
.
shared
(
numpy
.
random
.
randn
(
4
,
3
)
.
astype
(
'float64'
),
name
=
'w'
)
outputs
,
_
=
theano
.
scan
(
lambda
i
,
h
,
w
:
(
theano
.
dot
(
h
[
i
],
w
),
i
),
outputs_info
=
[
None
,
0L
],
non_sequences
=
[
h
,
w
],
n_steps
=
3
)
theano
.
grad
(
outputs
[
0
]
.
sum
(),
w
)
finally
:
theano
.
config
.
compute_test_value
=
backup
def
test_constant_folding_n_steps
():
def
test_constant_folding_n_steps
():
# The following code used to crash at revision 2060b8f, in the constant
# The following code used to crash at revision 2060b8f, in the constant
# folding optimization step.
# folding optimization step.
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论