提交 5a0e9943 authored 作者: James Bergstra's avatar James Bergstra

corrections to DebugMode test of checks_isfinite

上级 ba49f1ec
...@@ -544,35 +544,20 @@ class Test_check_isfinite(unittest.TestCase): ...@@ -544,35 +544,20 @@ class Test_check_isfinite(unittest.TestCase):
theano.tensor.TensorType.filter_checks_isfinite = self.old_val theano.tensor.TensorType.filter_checks_isfinite = self.old_val
def test_check_isfinite(self): def test_check_isfinite(self):
x = theano.tensor.dvector() x = theano.tensor.vector()
f = theano.function([x], (x+2) * 5, mode='DEBUG_MODE') f = theano.function([x], (x+2) * 5, mode='DEBUG_MODE')
g = theano.function([x], theano.tensor.log(x), mode='DEBUG_MODE')
# this should work # this should work
f(numpy.log([3, 4, 5])) f(numpy.log([3, 4, 5]))
# this should raise InvalidValueError # passing an invalid value as an input should trigger ValueError
try: self.failUnlessRaises(ValueError, f, numpy.log([3, -4, 5]))
# insert a NaN self.failUnlessRaises(ValueError, f, numpy.asarray([0, 1.0, 0])/0)
f(numpy.log([3, -4, 5])) self.failUnlessRaises(ValueError, f, numpy.asarray([1.0, 1.0, 1.0])/0)
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 # generating an invalid value internally should trigger InvalidValueError
try: self.failUnlessRaises(debugmode.InvalidValueError, g, [3,-4,5])
# insert several Inf
f(numpy.asarray([1.0, 1.0, 1.0])/0)
assert False
except debugmode.InvalidValueError:
pass
# this should disable the exception # this should disable the exception
theano.tensor.TensorType.filter_checks_isfinite = False theano.tensor.TensorType.filter_checks_isfinite = False
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论