Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
bbd941f1
提交
bbd941f1
authored
4月 01, 2009
作者:
James Bergstra
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
added check for NaN and Inf, fixed bug in DebugMode _Linker so that functions…
added check for NaN and Inf, fixed bug in DebugMode _Linker so that functions can be reused after raising an error
上级
c0de4b06
全部展开
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
89 行增加
和
20 行删除
+89
-20
debugmode.txt
doc/topics/debugmode.txt
+22
-20
debugmode.py
theano/compile/debugmode.py
+0
-0
test_debugmode.py
theano/compile/tests/test_debugmode.py
+60
-0
basic.py
theano/tensor/basic.py
+7
-0
没有找到文件。
doc/topics/debugmode.txt
浏览文件 @
bbd941f1
...
...
@@ -39,9 +39,26 @@ Some kinds of errors can only be detected for certain input value combinations.
In the example above, there is no way to guarantee that a future call to say,
``f(-1)`` won't cause a problem. DebugMode is not a silver bullet.
If you instantiate DebugMode using the constructor ``compile.DebugMode``
rather than the keyword ``DEBUG_MODE`` you can configure its behaviour via
constructor arguments. See :api:`DebugMode` for details.
The keyword version of DebugMode (which you get by using ``mode='DEBUG_MODE``)
is quite strict, and can raise several different Exception types.
There following are DebugMode exceptions you might encounter:
DebugModeError
--------------
This is a generic error. All the other exceptions inherit from this one.
This error is typically not raised directly.
However, you can use ``except DebugModeError: ...`` to catch any of the more
specific types of Exception.
For detailed documentation see :api:`DebugModeError`.
BadCLinkerOutput
----------------
...
...
@@ -105,18 +122,6 @@ whereby we debug in DEBUG_MODE and then run the full-size jobs in FAST_RUN.
For detailed documentation see :api:`StochasticOrder`.
FloatError
----------
This happens when invalid floating-point values such as NaN and Inf are
introduced into the computations. It indicates which Op created the first
NaN.
Currently this exception is never raised because the check is not being
performed, but the plan is that it will be. (see ticket #320)
For detailed documentation see :api:`FloatError`.
InvalidValueError
-----------------
...
...
@@ -126,14 +131,11 @@ an output that is invalid with respect to the type of the corresponding output
variable. Like if it returned a complex-valued ndarray for a ``dscalar``
Type.
For detailed documentation see :api:`InvalidValueError`.
DebugModeError
--------------
This can also be triggered when floating-point values such as NaN and Inf are
introduced into the computations. It indicates which Op created the first
NaN. These floating-point values can be allowed by passing the
``check_isfinite=False`` argument to DebugMode.
This is a generic error, pretty unhelpful. You'll generally have to look at the
stack trace and then in the code to figure out why DebugMode is complaining.
For detailed documentation see :api:`InvalidValueError`.
For detailed documentation see :api:`DebugModeError`.
theano/compile/debugmode.py
浏览文件 @
bbd941f1
差异被折叠。
点击展开。
theano/compile/tests/test_debugmode.py
浏览文件 @
bbd941f1
...
...
@@ -531,3 +531,63 @@ class Test_ViewMap(unittest.TestCase):
# input, but guarantees correctness.
#custom_op.view_map = {0:[0], 1:[1]}
#f([1,2,3,4],[5,6,7,8])
class
Test_check_isfinite
(
unittest
.
TestCase
):
def
setUp
(
self
):
print
'Up'
self
.
old_val
=
theano
.
tensor
.
TensorType
.
filter_checks_isfinite
def
tearDown
(
self
):
print
'Down'
theano
.
tensor
.
TensorType
.
filter_checks_isfinite
=
self
.
old_val
def
test_check_isfinite
(
self
):
x
=
theano
.
tensor
.
dvector
()
f
=
theano
.
function
([
x
],
(
x
+
2
)
*
5
,
mode
=
'DEBUG_MODE'
)
# this should work
f
(
numpy
.
log
([
3
,
4
,
5
]))
# this should raise InvalidValueError
try
:
# insert a NaN
f
(
numpy
.
log
([
3
,
-
4
,
5
]))
assert
False
except
debugmode
.
InvalidValueError
:
pass
# this should raise InvalidValueError
try
:
# insert an Nan and Inf
f
(
numpy
.
asarray
([
0
,
1.0
,
0
])
/
0
)
assert
False
except
debugmode
.
InvalidValueError
:
pass
# this should raise InvalidValueError
try
:
# insert several Inf
f
(
numpy
.
asarray
([
1.0
,
1.0
,
1.0
])
/
0
)
assert
False
except
debugmode
.
InvalidValueError
:
pass
# this should disable the exception
theano
.
tensor
.
TensorType
.
filter_checks_isfinite
=
False
# insert several Inf
f
(
numpy
.
asarray
([
1.0
,
1.0
,
1.0
])
/
0
)
def
test_check_isfinite_disabled
(
self
):
x
=
theano
.
tensor
.
dvector
()
f
=
theano
.
function
([
x
],
(
x
+
2
)
*
5
,
mode
=
debugmode
.
DebugMode
(
check_isfinite
=
False
))
# the DestroyMap checker should be triggered by Nan != Nan
try
:
f
(
numpy
.
log
([
3
,
-
4
,
5
]))
assert
False
except
debugmode
.
BadDestroyMap
:
pass
#inf should go through
f
(
numpy
.
asarray
([
1.0
,
1.0
,
1.0
])
/
0
)
theano/tensor/basic.py
浏览文件 @
bbd941f1
...
...
@@ -164,6 +164,11 @@ def value(x, name=None, ndim=None):
class
TensorType
(
Type
):
"""Symbolic `Type` representing a numpy.ndarray value."""
filter_checks_isfinite
=
False
"""
When this is True, strict filtering rejects data containing NaN or Inf entries. (Used in `DebugMode`)
"""
def
__init__
(
self
,
dtype
,
broadcastable
,
name
=
None
):
"""Initialize self.dtype and self.broadcastable.
...
...
@@ -199,6 +204,8 @@ class TensorType(Type):
raise
TypeError
(
"
%
s expected a ndarray object with dtype =
%
s (got
%
s)."
%
(
self
,
self
.
dtype
,
data
.
dtype
))
if
not
data
.
ndim
==
self
.
ndim
:
raise
TypeError
(
"
%
s expected a ndarray object with
%
s dimensions (got
%
s)."
%
(
self
,
self
.
ndim
,
data
.
ndim
))
if
self
.
filter_checks_isfinite
and
(
not
numpy
.
all
(
numpy
.
isfinite
(
data
))):
raise
TypeError
(
"non-finite elements not allowed"
)
return
data
else
:
data
=
numpy
.
asarray
(
data
,
dtype
=
self
.
dtype
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论