Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
f7687b37
提交
f7687b37
authored
10月 31, 2014
作者:
Iulian Vlad Serban
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fixed #2071: Moving test_record.py from Pylearn2 to Theano.
上级
7fb90052
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
163 行增加
和
0 行删除
+163
-0
test_record.py
theano/tests/test_record.py
+163
-0
没有找到文件。
theano/tests/test_record.py
0 → 100644
浏览文件 @
f7687b37
from
theano.tests.record
import
*
from
theano
import
function
from
theano.tensor
import
iscalar
import
cStringIO
def
test_record_good
():
"""
Tests that when we record a sequence of events, then
repeat it exactly, the Record class:
1) Records it correctly
2) Does not raise any errors
"""
# Record a sequence of events
output
=
cStringIO
.
StringIO
()
recorder
=
Record
(
file_object
=
output
,
replay
=
False
)
num_lines
=
10
for
i
in
xrange
(
num_lines
):
recorder
.
handle_line
(
str
(
i
)
+
'
\n
'
)
# Make sure they were recorded correctly
output_value
=
output
.
getvalue
()
assert
output_value
==
''
.
join
(
str
(
i
)
+
'
\n
'
for
i
in
xrange
(
num_lines
))
# Make sure that the playback functionality doesn't raise any errors
# when we repeat them
output
=
cStringIO
.
StringIO
(
output_value
)
playback_checker
=
Record
(
file_object
=
output
,
replay
=
True
)
for
i
in
xrange
(
num_lines
):
playback_checker
.
handle_line
(
str
(
i
)
+
'
\n
'
)
def
test_record_bad
():
"""
Tests that when we record a sequence of events, then
do something different on playback, the Record class catches it.
"""
# Record a sequence of events
output
=
cStringIO
.
StringIO
()
recorder
=
Record
(
file_object
=
output
,
replay
=
False
)
num_lines
=
10
for
i
in
xrange
(
num_lines
):
recorder
.
handle_line
(
str
(
i
)
+
'
\n
'
)
# Make sure that the playback functionality doesn't raise any errors
# when we repeat some of them
output_value
=
output
.
getvalue
()
output
=
cStringIO
.
StringIO
(
output_value
)
playback_checker
=
Record
(
file_object
=
output
,
replay
=
True
)
for
i
in
xrange
(
num_lines
//
2
):
playback_checker
.
handle_line
(
str
(
i
)
+
'
\n
'
)
# Make sure it raises an error when we deviate from the recorded sequence
try
:
playback_checker
.
handle_line
(
'0
\n
'
)
except
MismatchError
:
return
raise
AssertionError
(
"Failed to detect mismatch between recorded sequence "
" and repetition of it."
)
def
test_record_mode_good
():
"""
Like test_record_good, but some events are recorded by the
theano RecordMode. We don't attempt to check the
exact string value of the record in this case.
"""
# Record a sequence of events
output
=
cStringIO
.
StringIO
()
recorder
=
Record
(
file_object
=
output
,
replay
=
False
)
record_mode
=
RecordMode
(
recorder
)
i
=
iscalar
()
f
=
function
([
i
],
i
,
mode
=
record_mode
,
name
=
'f'
)
num_lines
=
10
for
i
in
xrange
(
num_lines
):
recorder
.
handle_line
(
str
(
i
)
+
'
\n
'
)
f
(
i
)
# Make sure that the playback functionality doesn't raise any errors
# when we repeat them
output_value
=
output
.
getvalue
()
output
=
cStringIO
.
StringIO
(
output_value
)
playback_checker
=
Record
(
file_object
=
output
,
replay
=
True
)
playback_mode
=
RecordMode
(
playback_checker
)
i
=
iscalar
()
f
=
function
([
i
],
i
,
mode
=
playback_mode
,
name
=
'f'
)
for
i
in
xrange
(
num_lines
):
playback_checker
.
handle_line
(
str
(
i
)
+
'
\n
'
)
f
(
i
)
def
test_record_mode_bad
():
"""
Like test_record_bad, but some events are recorded by the
theano RecordMode, as is the event that triggers the mismatch
error.
"""
# Record a sequence of events
output
=
cStringIO
.
StringIO
()
recorder
=
Record
(
file_object
=
output
,
replay
=
False
)
record_mode
=
RecordMode
(
recorder
)
i
=
iscalar
()
f
=
function
([
i
],
i
,
mode
=
record_mode
,
name
=
'f'
)
num_lines
=
10
for
i
in
xrange
(
num_lines
):
recorder
.
handle_line
(
str
(
i
)
+
'
\n
'
)
f
(
i
)
# Make sure that the playback functionality doesn't raise any errors
# when we repeat them
output_value
=
output
.
getvalue
()
output
=
cStringIO
.
StringIO
(
output_value
)
playback_checker
=
Record
(
file_object
=
output
,
replay
=
True
)
playback_mode
=
RecordMode
(
playback_checker
)
i
=
iscalar
()
f
=
function
([
i
],
i
,
mode
=
playback_mode
,
name
=
'f'
)
for
i
in
xrange
(
num_lines
//
2
):
playback_checker
.
handle_line
(
str
(
i
)
+
'
\n
'
)
f
(
i
)
# Make sure a wrong event causes a MismatchError
try
:
f
(
0
)
except
MismatchError
:
return
raise
AssertionError
(
"Failed to detect a mismatch."
)
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论