提交 e331b68f authored 作者: Benjamin Scellier's avatar Benjamin Scellier

file theano/compile/tests/test_debugmode.py

上级 f8d377f3
...@@ -2,7 +2,7 @@ from __future__ import absolute_import, print_function, division ...@@ -2,7 +2,7 @@ from __future__ import absolute_import, print_function, division
from nose.plugins.skip import SkipTest from nose.plugins.skip import SkipTest
import unittest import unittest
import numpy import numpy as np
from theano import config from theano import config
from theano import gof from theano import gof
...@@ -316,7 +316,7 @@ def test_just_c_code(): ...@@ -316,7 +316,7 @@ def test_just_c_code():
x = theano.tensor.dvector() x = theano.tensor.dvector()
f = theano.function([x], wb2(x), f = theano.function([x], wb2(x),
mode=debugmode.DebugMode(check_py_code=False)) mode=debugmode.DebugMode(check_py_code=False))
assert numpy.all(f([1, 2]) == [2, 4]) assert np.all(f([1, 2]) == [2, 4])
def test_baddestroymap(): def test_baddestroymap():
...@@ -349,7 +349,7 @@ def test_baddestroymap_c(): ...@@ -349,7 +349,7 @@ def test_baddestroymap_c():
f = theano.function([x], wb2i(x), f = theano.function([x], wb2i(x),
mode=debugmode.DebugMode(check_py_code=False)) mode=debugmode.DebugMode(check_py_code=False))
try: try:
assert numpy.all(f([1, 2]) == [2, 4]) assert np.all(f([1, 2]) == [2, 4])
assert False # failed to raise error assert False # failed to raise error
except debugmode.BadDestroyMap: except debugmode.BadDestroyMap:
pass pass
...@@ -445,8 +445,8 @@ class Test_ViewMap(unittest.TestCase): ...@@ -445,8 +445,8 @@ class Test_ViewMap(unittest.TestCase):
r0, r1 = f([1, 2, 3, 4], [5, 6, 7, 8]) r0, r1 = f([1, 2, 3, 4], [5, 6, 7, 8])
assert numpy.all(r0 == [1, 2, 3, 4]) assert np.all(r0 == [1, 2, 3, 4])
assert numpy.all(r1 == [2, 3, 4]) assert np.all(r1 == [2, 3, 4])
def test_aliased_outputs_ok_output(self): def test_aliased_outputs_ok_output(self):
# here aliased outputs is ok because they are both outputs of the # here aliased outputs is ok because they are both outputs of the
...@@ -470,8 +470,8 @@ class Test_ViewMap(unittest.TestCase): ...@@ -470,8 +470,8 @@ class Test_ViewMap(unittest.TestCase):
r0, r1 = f([1, 2, 3, 4], [5, 6, 7, 8]) r0, r1 = f([1, 2, 3, 4], [5, 6, 7, 8])
assert numpy.all(r0 == [2, 4, 6, 8]) assert np.all(r0 == [2, 4, 6, 8])
assert numpy.all(r1 == [4, 6, 8]) assert np.all(r1 == [4, 6, 8])
def test_aliased_outputs_ok_shadow(self): def test_aliased_outputs_ok_shadow(self):
# here the alias between outputs is ok because one of them is not used # here the alias between outputs is ok because one of them is not used
...@@ -496,7 +496,7 @@ class Test_ViewMap(unittest.TestCase): ...@@ -496,7 +496,7 @@ class Test_ViewMap(unittest.TestCase):
r0 = f([1, 2, 3, 4], [5, 6, 7, 8]) r0 = f([1, 2, 3, 4], [5, 6, 7, 8])
assert numpy.all(r0 == [2, 4, 6, 8]) assert np.all(r0 == [2, 4, 6, 8])
def test_aliased_outputs_bad(self): def test_aliased_outputs_bad(self):
# here the alias between outputs is not ok because destroying one # here the alias between outputs is not ok because destroying one
...@@ -555,30 +555,30 @@ class Test_check_isfinite(unittest.TestCase): ...@@ -555,30 +555,30 @@ class Test_check_isfinite(unittest.TestCase):
g = theano.function([x], theano.tensor.log(x), 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]).astype(config.floatX)) f(np.log([3, 4, 5]).astype(config.floatX))
# if TensorType.filter_checks_isfinite were true, these would raise # if TensorType.filter_checks_isfinite were true, these would raise
# ValueError # ValueError
# if not, DebugMode will check internally, and raise InvalidValueError # if not, DebugMode will check internally, and raise InvalidValueError
# passing an invalid value as an input should trigger ValueError # passing an invalid value as an input should trigger ValueError
self.assertRaises(debugmode.InvalidValueError, f, self.assertRaises(debugmode.InvalidValueError, f,
numpy.log([3, -4, 5]).astype(config.floatX)) np.log([3, -4, 5]).astype(config.floatX))
self.assertRaises(debugmode.InvalidValueError, f, self.assertRaises(debugmode.InvalidValueError, f,
(numpy.asarray([0, 1.0, 0]) / 0).astype(config.floatX)) (np.asarray([0, 1.0, 0]) / 0).astype(config.floatX))
self.assertRaises(debugmode.InvalidValueError, f, self.assertRaises(debugmode.InvalidValueError, f,
(numpy.asarray([1.0, 1.0, 1.0]) / 0).astype(config.floatX)) (np.asarray([1.0, 1.0, 1.0]) / 0).astype(config.floatX))
# generating an invalid value internally should trigger # generating an invalid value internally should trigger
# InvalidValueError # InvalidValueError
self.assertRaises(debugmode.InvalidValueError, g, self.assertRaises(debugmode.InvalidValueError, g,
numpy.asarray([3, -4, 5], dtype=config.floatX)) np.asarray([3, -4, 5], dtype=config.floatX))
# this should disable the exception # this should disable the exception
theano.tensor.TensorType.filter_checks_isfinite = False theano.tensor.TensorType.filter_checks_isfinite = False
theano.compile.mode.predefined_modes[ theano.compile.mode.predefined_modes[
'DEBUG_MODE'].check_isfinite = False 'DEBUG_MODE'].check_isfinite = False
# insert several Inf # insert several Inf
f(numpy.asarray(numpy.asarray([1.0, 1.0, 1.0]) / 0, f(np.asarray(np.asarray([1.0, 1.0, 1.0]) / 0,
dtype=config.floatX)) dtype=config.floatX))
def test_check_isfinite_disabled(self): def test_check_isfinite_disabled(self):
...@@ -587,10 +587,10 @@ class Test_check_isfinite(unittest.TestCase): ...@@ -587,10 +587,10 @@ class Test_check_isfinite(unittest.TestCase):
mode=debugmode.DebugMode(check_isfinite=False)) mode=debugmode.DebugMode(check_isfinite=False))
# nan should go through # nan should go through
f(numpy.log([3, -4, 5])) f(np.log([3, -4, 5]))
# inf should go through # inf should go through
infs = numpy.asarray([1.0, 1., 1.]) / 0 infs = np.asarray([1.0, 1., 1.]) / 0
# print infs # print infs
f(infs) f(infs)
return return
...@@ -721,14 +721,14 @@ class VecAsRowAndCol(gof.Op): ...@@ -721,14 +721,14 @@ class VecAsRowAndCol(gof.Op):
class Test_preallocated_output(unittest.TestCase): class Test_preallocated_output(unittest.TestCase):
def setUp(self): def setUp(self):
self.rng = numpy.random.RandomState(seed=utt.fetch_seed()) self.rng = np.random.RandomState(seed=utt.fetch_seed())
def test_f_contiguous(self): def test_f_contiguous(self):
a = theano.tensor.fmatrix('a') a = theano.tensor.fmatrix('a')
b = theano.tensor.fmatrix('b') b = theano.tensor.fmatrix('b')
z = BrokenCImplementationAdd()(a, b) z = BrokenCImplementationAdd()(a, b)
# In this test, we do not want z to be an output of the graph. # In this test, we do not want z to be an output of the graph.
out = theano.tensor.dot(z, numpy.eye(7)) out = theano.tensor.dot(z, np.eye(7))
a_val = self.rng.randn(7, 7).astype('float32') a_val = self.rng.randn(7, 7).astype('float32')
b_val = self.rng.randn(7, 7).astype('float32') b_val = self.rng.randn(7, 7).astype('float32')
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论