Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
f8ce40ae
提交
f8ce40ae
authored
10月 07, 2020
作者:
Brandon T. Willard
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Relocate str_diagnostic function from tests to theano.compile.debugmode
上级
f683d1ac
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
67 行增加
和
70 行删除
+67
-70
unittest_tools.py
tests/unittest_tools.py
+1
-66
debugmode.py
theano/compile/debugmode.py
+66
-4
没有找到文件。
tests/unittest_tools.py
浏览文件 @
f8ce40ae
...
@@ -12,9 +12,9 @@ from functools import wraps
...
@@ -12,9 +12,9 @@ from functools import wraps
from
copy
import
copy
,
deepcopy
from
copy
import
copy
,
deepcopy
from
six
import
integer_types
from
six
import
integer_types
from
six.moves
import
StringIO
from
theano
import
config
from
theano
import
config
from
theano.compile.debugmode
import
str_diagnostic
_logger
=
logging
.
getLogger
(
"tests.unittest_tools"
)
_logger
=
logging
.
getLogger
(
"tests.unittest_tools"
)
...
@@ -282,71 +282,6 @@ class InferShapeTester:
...
@@ -282,71 +282,6 @@ class InferShapeTester:
assert
np
.
all
(
out
.
shape
==
shape
),
(
out
.
shape
,
shape
)
assert
np
.
all
(
out
.
shape
==
shape
),
(
out
.
shape
,
shape
)
def
str_diagnostic
(
expected
,
value
,
rtol
,
atol
):
"""Return a pretty multiline string representating the cause
of the exception"""
sio
=
StringIO
()
try
:
ssio
=
StringIO
()
print
(
" : shape, dtype, strides, min, max, n_inf, n_nan:"
,
file
=
ssio
)
print
(
" Expected :"
,
end
=
" "
,
file
=
ssio
)
print
(
expected
.
shape
,
end
=
" "
,
file
=
ssio
)
print
(
expected
.
dtype
,
end
=
" "
,
file
=
ssio
)
print
(
expected
.
strides
,
end
=
" "
,
file
=
ssio
)
print
(
expected
.
min
(),
end
=
" "
,
file
=
ssio
)
print
(
expected
.
max
(),
end
=
" "
,
file
=
ssio
)
print
(
np
.
isinf
(
expected
)
.
sum
(),
end
=
" "
,
file
=
ssio
)
print
(
np
.
isnan
(
expected
)
.
sum
(),
end
=
" "
,
file
=
ssio
)
# only if all succeeds to we add anything to sio
print
(
ssio
.
getvalue
(),
file
=
sio
)
except
Exception
:
pass
try
:
ssio
=
StringIO
()
print
(
" Value :"
,
end
=
" "
,
file
=
ssio
)
print
(
value
.
shape
,
end
=
" "
,
file
=
ssio
)
print
(
value
.
dtype
,
end
=
" "
,
file
=
ssio
)
print
(
value
.
strides
,
end
=
" "
,
file
=
ssio
)
print
(
value
.
min
(),
end
=
" "
,
file
=
ssio
)
print
(
value
.
max
(),
end
=
" "
,
file
=
ssio
)
print
(
np
.
isinf
(
value
)
.
sum
(),
end
=
" "
,
file
=
ssio
)
print
(
np
.
isnan
(
value
)
.
sum
(),
end
=
" "
,
file
=
ssio
)
# only if all succeeds to we add anything to sio
print
(
ssio
.
getvalue
(),
file
=
sio
)
except
Exception
:
pass
print
(
" expected :"
,
expected
,
file
=
sio
)
print
(
" value :"
,
value
,
file
=
sio
)
try
:
ov
=
np
.
asarray
(
expected
)
nv
=
np
.
asarray
(
value
)
ssio
=
StringIO
()
absdiff
=
np
.
absolute
(
nv
-
ov
)
print
(
" Max Abs Diff: "
,
np
.
max
(
absdiff
),
file
=
ssio
)
print
(
" Mean Abs Diff: "
,
np
.
mean
(
absdiff
),
file
=
ssio
)
print
(
" Median Abs Diff: "
,
np
.
median
(
absdiff
),
file
=
ssio
)
print
(
" Std Abs Diff: "
,
np
.
std
(
absdiff
),
file
=
ssio
)
reldiff
=
np
.
absolute
(
nv
-
ov
)
/
np
.
absolute
(
ov
)
print
(
" Max Rel Diff: "
,
np
.
max
(
reldiff
),
file
=
ssio
)
print
(
" Mean Rel Diff: "
,
np
.
mean
(
reldiff
),
file
=
ssio
)
print
(
" Median Rel Diff: "
,
np
.
median
(
reldiff
),
file
=
ssio
)
print
(
" Std Rel Diff: "
,
np
.
std
(
reldiff
),
file
=
ssio
)
# only if all succeeds to we add anything to sio
print
(
ssio
.
getvalue
(),
file
=
sio
)
except
Exception
:
pass
atol_
,
rtol_
=
T
.
basic
.
_get_atol_rtol
(
expected
,
value
)
if
rtol
is
not
None
:
rtol_
=
rtol
if
atol
is
not
None
:
atol_
=
atol
print
(
" rtol, atol:"
,
rtol_
,
atol_
,
file
=
sio
)
return
sio
.
getvalue
()
class
WrongValue
(
Exception
):
class
WrongValue
(
Exception
):
def
__init__
(
self
,
expected_val
,
val
,
rtol
,
atol
):
def
__init__
(
self
,
expected_val
,
val
,
rtol
,
atol
):
Exception
.
__init__
(
self
)
# to be compatible with python2.4
Exception
.
__init__
(
self
)
# to be compatible with python2.4
...
...
theano/compile/debugmode.py
浏览文件 @
f8ce40ae
...
@@ -157,10 +157,7 @@ class BadThunkOutput(DebugModeError):
...
@@ -157,10 +157,7 @@ class BadThunkOutput(DebugModeError):
print
(
" thunk1 :"
,
self
.
thunk1
,
file
=
sio
)
print
(
" thunk1 :"
,
self
.
thunk1
,
file
=
sio
)
print
(
" thunk2 :"
,
self
.
thunk2
,
file
=
sio
)
print
(
" thunk2 :"
,
self
.
thunk2
,
file
=
sio
)
# Don't import it at the top of the file to prevent circular import.
print
(
str_diagnostic
(
self
.
val1
,
self
.
val2
,
None
,
None
),
file
=
sio
)
import
tests.unittest_tools
as
utt
print
(
utt
.
str_diagnostic
(
self
.
val1
,
self
.
val2
,
None
,
None
),
file
=
sio
)
ret
=
sio
.
getvalue
()
ret
=
sio
.
getvalue
()
return
ret
return
ret
...
@@ -382,6 +379,71 @@ class InvalidValueError(DebugModeError):
...
@@ -382,6 +379,71 @@ class InvalidValueError(DebugModeError):
########################
########################
def
str_diagnostic
(
expected
,
value
,
rtol
,
atol
):
"""Return a pretty multiline string representating the cause
of the exception"""
sio
=
StringIO
()
try
:
ssio
=
StringIO
()
print
(
" : shape, dtype, strides, min, max, n_inf, n_nan:"
,
file
=
ssio
)
print
(
" Expected :"
,
end
=
" "
,
file
=
ssio
)
print
(
expected
.
shape
,
end
=
" "
,
file
=
ssio
)
print
(
expected
.
dtype
,
end
=
" "
,
file
=
ssio
)
print
(
expected
.
strides
,
end
=
" "
,
file
=
ssio
)
print
(
expected
.
min
(),
end
=
" "
,
file
=
ssio
)
print
(
expected
.
max
(),
end
=
" "
,
file
=
ssio
)
print
(
np
.
isinf
(
expected
)
.
sum
(),
end
=
" "
,
file
=
ssio
)
print
(
np
.
isnan
(
expected
)
.
sum
(),
end
=
" "
,
file
=
ssio
)
# only if all succeeds to we add anything to sio
print
(
ssio
.
getvalue
(),
file
=
sio
)
except
Exception
:
pass
try
:
ssio
=
StringIO
()
print
(
" Value :"
,
end
=
" "
,
file
=
ssio
)
print
(
value
.
shape
,
end
=
" "
,
file
=
ssio
)
print
(
value
.
dtype
,
end
=
" "
,
file
=
ssio
)
print
(
value
.
strides
,
end
=
" "
,
file
=
ssio
)
print
(
value
.
min
(),
end
=
" "
,
file
=
ssio
)
print
(
value
.
max
(),
end
=
" "
,
file
=
ssio
)
print
(
np
.
isinf
(
value
)
.
sum
(),
end
=
" "
,
file
=
ssio
)
print
(
np
.
isnan
(
value
)
.
sum
(),
end
=
" "
,
file
=
ssio
)
# only if all succeeds to we add anything to sio
print
(
ssio
.
getvalue
(),
file
=
sio
)
except
Exception
:
pass
print
(
" expected :"
,
expected
,
file
=
sio
)
print
(
" value :"
,
value
,
file
=
sio
)
try
:
ov
=
np
.
asarray
(
expected
)
nv
=
np
.
asarray
(
value
)
ssio
=
StringIO
()
absdiff
=
np
.
absolute
(
nv
-
ov
)
print
(
" Max Abs Diff: "
,
np
.
max
(
absdiff
),
file
=
ssio
)
print
(
" Mean Abs Diff: "
,
np
.
mean
(
absdiff
),
file
=
ssio
)
print
(
" Median Abs Diff: "
,
np
.
median
(
absdiff
),
file
=
ssio
)
print
(
" Std Abs Diff: "
,
np
.
std
(
absdiff
),
file
=
ssio
)
reldiff
=
np
.
absolute
(
nv
-
ov
)
/
np
.
absolute
(
ov
)
print
(
" Max Rel Diff: "
,
np
.
max
(
reldiff
),
file
=
ssio
)
print
(
" Mean Rel Diff: "
,
np
.
mean
(
reldiff
),
file
=
ssio
)
print
(
" Median Rel Diff: "
,
np
.
median
(
reldiff
),
file
=
ssio
)
print
(
" Std Rel Diff: "
,
np
.
std
(
reldiff
),
file
=
ssio
)
# only if all succeeds to we add anything to sio
print
(
ssio
.
getvalue
(),
file
=
sio
)
except
Exception
:
pass
atol_
,
rtol_
=
theano
.
tensor
.
basic
.
_get_atol_rtol
(
expected
,
value
)
if
rtol
is
not
None
:
rtol_
=
rtol
if
atol
is
not
None
:
atol_
=
atol
print
(
" rtol, atol:"
,
rtol_
,
atol_
,
file
=
sio
)
return
sio
.
getvalue
()
def
char_from_number
(
number
):
def
char_from_number
(
number
):
"""
"""
Converts number to string by rendering it in base 26 using
Converts number to string by rendering it in base 26 using
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论