Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
cc54c4ef
提交
cc54c4ef
authored
11月 03, 2011
作者:
James Bergstra
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
pep8 MakeTester in the test suite
上级
1451d214
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
73 行增加
和
41 行删除
+73
-41
test_basic.py
theano/tensor/tests/test_basic.py
+73
-41
没有找到文件。
theano/tensor/tests/test_basic.py
浏览文件 @
cc54c4ef
...
...
@@ -194,23 +194,26 @@ def makeTester(name, op, expected, checks={}, good={}, bad_build={},
node
=
safe_make_node
(
self
.
op
,
*
inputrs
)
except
Exception
:
type
,
exc_value
,
traceback
=
sys
.
exc_info
()
err_msg
=
"Test
%
s::
%
s: Error occurred while making a node with inputs
%
s"
\
%
(
self
.
op
,
testname
,
inputs
)
err_msg
=
(
"Test
%
s::
%
s: Error occurred while"
" making a node with inputs
%
s"
)
%
(
self
.
op
,
testname
,
inputs
)
exc_value
.
args
=
exc_value
.
args
+
(
err_msg
,
)
raise
type
,
exc_value
,
traceback
raise
type
(
exc_value
,
traceback
)
try
:
f
=
inplace_func
(
inputrs
,
node
.
outputs
,
mode
=
mode
)
except
Exception
:
type
,
exc_value
,
traceback
=
sys
.
exc_info
()
err_msg
=
"Test
%
s::
%
s: Error occurred while trying to make a Function"
\
%
(
self
.
op
,
testname
)
err_msg
=
(
"Test
%
s::
%
s: Error occurred while"
" trying to make a Function"
)
%
(
self
.
op
,
testname
)
exc_value
.
args
=
exc_value
.
args
+
(
err_msg
,
)
raise
type
,
exc_value
,
traceback
if
isinstance
(
self
.
expected
,
dict
)
and
testname
in
self
.
expected
:
raise
type
(
exc_value
,
traceback
)
if
(
isinstance
(
self
.
expected
,
dict
)
and
testname
in
self
.
expected
):
expecteds
=
self
.
expected
[
testname
]
#with numpy version, when we print a number and read it back, we don't get exactly the same result
#So we accept rounding error in that case.
# with numpy version, when we print a number and read it
# back, we don't get exactly the same result #So we accept
# rounding error in that case.
eps
=
5e-9
else
:
expecteds
=
self
.
expected
(
*
inputs
)
...
...
@@ -224,27 +227,38 @@ def makeTester(name, op, expected, checks={}, good={}, bad_build={},
variables
=
f
(
*
inputs
)
except
Exception
:
type
,
exc_value
,
traceback
=
sys
.
exc_info
()
err_msg
=
"Test
%
s::
%
s: Error occurred while calling the Function on the inputs
%
s"
\
%
(
self
.
op
,
testname
,
inputs
)
err_msg
=
(
"Test
%
s::
%
s: Error occurred while calling"
" the Function on the inputs
%
s"
)
%
(
self
.
op
,
testname
,
inputs
)
exc_value
.
args
=
exc_value
.
args
+
(
err_msg
,
)
raise
type
,
exc_value
,
traceback
raise
type
(
exc_value
,
traceback
)
if
not
isinstance
(
expecteds
,
(
list
,
tuple
)):
expecteds
=
(
expecteds
,
)
for
i
,
(
variable
,
expected
)
in
enumerate
(
izip
(
variables
,
expecteds
)):
if
variable
.
dtype
!=
expected
.
dtype
or
variable
.
shape
!=
expected
.
shape
or
\
numpy
.
any
(
numpy
.
abs
(
variable
-
expected
)
>
eps
):
self
.
fail
(
"Test
%
s::
%
s: Output
%
s gave the wrong value. With inputs
%
s, expected
%
s, got
%
s. numpy.allclose return
%
s
%
s"
%
(
self
.
op
,
testname
,
i
,
inputs
,
expected
,
variable
,
numpy
.
allclose
(
variable
,
expected
,
atol
=
eps
),
numpy
.
allclose
(
variable
,
expected
)))
for
i
,
(
variable
,
expected
)
in
enumerate
(
izip
(
variables
,
expecteds
)):
if
(
variable
.
dtype
!=
expected
.
dtype
or
variable
.
shape
!=
expected
.
shape
or
numpy
.
any
(
abs
(
variable
-
expected
)
>
eps
):
self
.
fail
((
"Test
%
s::
%
s: Output
%
s gave the wrong"
" value. With inputs
%
s, expected
%
s, got
%
s."
" numpy.allclose return
%
s
%
s"
)
%
(
self
.
op
,
testname
,
i
,
inputs
,
expected
,
variable
,
numpy
.
allclose
(
variable
,
expected
,
atol
=
eps
),
numpy
.
allclose
(
variable
,
expected
)))
for
description
,
check
in
self
.
checks
.
items
():
if
not
check
(
inputs
,
variables
):
self
.
fail
(
"Test
%
s::
%
s: Failed check:
%
s (inputs were
%
s, outputs were
%
s)"
%
(
self
.
op
,
testname
,
description
,
inputs
,
variables
))
self
.
fail
((
"Test
%
s::
%
s: Failed check:
%
s (inputs"
" were
%
s, outputs were
%
s)"
)
%
(
self
.
op
,
testname
,
description
,
inputs
,
variables
))
def
test_bad_build
(
self
):
if
skip
:
...
...
@@ -252,8 +266,10 @@ def makeTester(name, op, expected, checks={}, good={}, bad_build={},
for
testname
,
inputs
in
self
.
bad_build
.
items
():
inputs
=
[
copy
(
input
)
for
input
in
inputs
]
inputrs
=
[
value
(
input
)
for
input
in
inputs
]
self
.
assertRaises
(
Exception
,
safe_make_node
,
self
.
op
,
*
inputrs
)
# The old error string was ("Test %s::%s: %s was successfully instantiated on the following bad inputs: %s"
self
.
assertRaises
(
Exception
,
safe_make_node
,
self
.
op
,
*
inputrs
)
# The old error string was ("Test %s::%s: %s was successfully
# instantiated on the following bad inputs: %s"
# % (self.op, testname, node, inputs))
def
test_bad_runtime
(
self
):
...
...
@@ -266,23 +282,25 @@ def makeTester(name, op, expected, checks={}, good={}, bad_build={},
node
=
safe_make_node
(
self
.
op
,
*
inputrs
)
except
Exception
:
type
,
exc_value
,
traceback
=
sys
.
exc_info
()
err_msg
=
"Test
%
s::
%
s: Error occurred while trying to make a node with inputs
%
s"
\
%
(
self
.
op
,
testname
,
inputs
)
err_msg
=
(
"Test
%
s::
%
s: Error occurred while trying"
" to make a node with inputs
%
s"
)
%
(
self
.
op
,
testname
,
inputs
)
exc_value
.
args
=
exc_value
.
args
+
(
err_msg
,
)
raise
type
,
exc_value
,
traceback
raise
type
(
exc_value
,
traceback
)
try
:
f
=
inplace_func
(
inputrs
,
node
.
outputs
,
mode
=
mode
)
except
Exception
:
type
,
exc_value
,
traceback
=
sys
.
exc_info
()
err_msg
=
"Test
%
s::
%
s: Error occurred while trying to make a Function"
\
%
(
self
.
op
,
testname
)
err_msg
=
(
"Test
%
s::
%
s: Error occurred while trying"
" to make a Function"
)
%
(
self
.
op
,
testname
)
exc_value
.
args
=
exc_value
.
args
+
(
err_msg
,
)
raise
type
,
exc_value
,
traceback
raise
type
(
exc_value
,
traceback
)
# Add tester return a ValueError. Should we catch only this one?
# TODO: test that only this one is raised and catch only this one
# or the subset that get raised.
# Add tester return a ValueError. Should we catch only this
# one?
# TODO: test that only this one is raised and catch only this
# one or the subset that get raised.
self
.
assertRaises
(
Exception
,
f
,
*
inputs
)
def
test_grad
(
self
):
...
...
@@ -296,13 +314,16 @@ def makeTester(name, op, expected, checks={}, good={}, bad_build={},
inputs
=
[
copy
(
input
)
for
input
in
inputs
]
inputrs
=
[
value
(
input
)
for
input
in
inputs
]
try
:
utt
.
verify_grad
(
self
.
op
,
inputs
,
mode
=
self
.
mode
,
rel_tol
=
_grad_rtol
)
utt
.
verify_grad
(
self
.
op
,
inputs
,
mode
=
self
.
mode
,
rel_tol
=
_grad_rtol
)
except
Exception
:
type
,
exc_value
,
traceback
=
sys
.
exc_info
()
err_msg
=
"Test
%
s::
%
s: Error occurred while computing the gradient on the following inputs:
%
s"
\
%
(
self
.
op
,
testname
,
inputs
)
err_msg
=
(
"Test
%
s::
%
s: Error occurred while"
" computing the gradient on the following"
" inputs:
%
s"
)
%
(
self
.
op
,
testname
,
inputs
)
exc_value
.
args
=
exc_value
.
args
+
(
err_msg
,
)
raise
type
,
exc_value
,
traceback
raise
type
(
exc_value
,
traceback
)
finally
:
config
.
warn
.
sum_div_dimshuffle_bug
=
backup
...
...
@@ -310,9 +331,19 @@ def makeTester(name, op, expected, checks={}, good={}, bad_build={},
return
Checker
rand
=
lambda
*
shape
:
2
*
numpy
.
asarray
(
numpy
.
random
.
rand
(
*
shape
),
dtype
=
config
.
floatX
)
-
1
randint
=
lambda
*
shape
:
numpy
.
random
.
random_integers
(
-
5
,
5
,
shape
)
randcomplex
=
lambda
*
shape
:
numpy
.
complex128
(
2
*
numpy
.
asarray
(
numpy
.
random
.
rand
(
*
shape
),
dtype
=
config
.
floatX
)
-
1
)
def
rand
(
*
shape
):
r
=
numpy
.
asarray
(
numpy
.
random
.
rand
(
*
shape
),
dtype
=
config
.
floatX
)
return
r
*
2
-
1
def
randint
(
*
shape
):
return
numpy
.
random
.
random_integers
(
-
5
,
5
,
shape
)
# XXX: this so-called complex random array as all-zero imaginary parts
def
randcomplex
(
*
shape
):
r
=
numpy
.
asarray
(
numpy
.
random
.
rand
(
*
shape
),
dtype
=
config
.
floatX
)
return
numpy
.
complex128
(
2
*
r
-
1
)
def
randint_nonzero
(
*
shape
):
...
...
@@ -371,7 +402,8 @@ def makeBroadcastTester(op, expected, checks={}, name=None, **kwargs):
def
inplace_check
(
inputs
,
outputs
):
# this used to be inputs[0] is output[0]
# I changed it so that it was easier to satisfy by the DebugMode
# I changed it so that it was easier to satisfy by the
# DebugMode
return
numpy
.
all
(
inputs
[
0
]
==
outputs
[
0
])
checks
=
dict
(
checks
,
inplace_check
=
inplace_check
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论