提交 b461908b authored 作者: Arnaud Bergeron's avatar Arnaud Bergeron

Disable compute_test_value for test that expect errors.

上级 749a492d
...@@ -8,6 +8,7 @@ import theano.tensor as T ...@@ -8,6 +8,7 @@ import theano.tensor as T
from theano.tensor.nnet.neighbours import images2neibs, neibs2images, Images2Neibs from theano.tensor.nnet.neighbours import images2neibs, neibs2images, Images2Neibs
from theano.tests import unittest_tools from theano.tests import unittest_tools
from theano.configparser import change_flags
mode_without_gpu = theano.compile.mode.get_default_mode().excluding('gpu') mode_without_gpu = theano.compile.mode.get_default_mode().excluding('gpu')
...@@ -140,6 +141,7 @@ class T_Images2Neibs(unittest_tools.InferShapeTester): ...@@ -140,6 +141,7 @@ class T_Images2Neibs(unittest_tools.InferShapeTester):
# print g() # print g()
# assert numpy.allclose(images.get_value(borrow=True), g()) # assert numpy.allclose(images.get_value(borrow=True), g())
@change_flags(compute_test_value='off')
def test_neibs_bad_shape(self): def test_neibs_bad_shape(self):
shape = (2, 3, 10, 10) shape = (2, 3, 10, 10)
for dtype in self.dtypes: for dtype in self.dtypes:
...@@ -287,6 +289,7 @@ class T_Images2Neibs(unittest_tools.InferShapeTester): ...@@ -287,6 +289,7 @@ class T_Images2Neibs(unittest_tools.InferShapeTester):
f_full = theano.function([], x_using_full, mode=self.mode) f_full = theano.function([], x_using_full, mode=self.mode)
unittest_tools.assert_allclose(f_valid(), f_full()) unittest_tools.assert_allclose(f_valid(), f_full())
@change_flags(compute_test_value='off')
def test_neibs_bad_shape_wrap_centered(self): def test_neibs_bad_shape_wrap_centered(self):
shape = (2, 3, 10, 10) shape = (2, 3, 10, 10)
......
...@@ -57,7 +57,7 @@ from theano.tensor import ( ...@@ -57,7 +57,7 @@ from theano.tensor import (
from theano.tests import unittest_tools as utt from theano.tests import unittest_tools as utt
from theano.tests.unittest_tools import attr from theano.tests.unittest_tools import attr
from theano.configparser import change_flags
imported_scipy_special = False imported_scipy_special = False
mode_no_scipy = get_default_mode() mode_no_scipy = get_default_mode()
...@@ -443,6 +443,7 @@ def makeTester(name, op, expected, checks=None, good=None, bad_build=None, ...@@ -443,6 +443,7 @@ def makeTester(name, op, expected, checks=None, good=None, bad_build=None,
# instantiated on the following bad inputs: %s" # instantiated on the following bad inputs: %s"
# % (self.op, testname, node, inputs)) # % (self.op, testname, node, inputs))
@change_flags(compute_test_value='off')
def test_bad_runtime(self): def test_bad_runtime(self):
if skip: if skip:
raise SkipTest(skip) raise SkipTest(skip)
...@@ -4383,14 +4384,15 @@ class T_Join_and_Split(unittest.TestCase): ...@@ -4383,14 +4384,15 @@ class T_Join_and_Split(unittest.TestCase):
for node in topo: for node in topo:
assert not isinstance(node.op, type(self.join_op)) assert not isinstance(node.op, type(self.join_op))
# Test hide error with change_flags(compute_test_value='off'):
x1.set_value(get_mat(3, 4)) # Test hide error
x2.set_value(get_mat(3, 4)) x1.set_value(get_mat(3, 4))
x3.set_value(get_mat(2, 5)) x2.set_value(get_mat(3, 4))
if not self.hide_error: x3.set_value(get_mat(2, 5))
self.assertRaises(ValueError, f) if not self.hide_error:
else: self.assertRaises(ValueError, f)
f() else:
f()
def test_rebroadcast(self): def test_rebroadcast(self):
# Regression test for a crash that used to happen when rebroadcasting. # Regression test for a crash that used to happen when rebroadcasting.
...@@ -4432,6 +4434,7 @@ class T_Join_and_Split(unittest.TestCase): ...@@ -4432,6 +4434,7 @@ class T_Join_and_Split(unittest.TestCase):
assert np.allclose(o1, m.get_value(borrow=True)) assert np.allclose(o1, m.get_value(borrow=True))
assert np.allclose(o2, m.get_value(borrow=True)[4:]) assert np.allclose(o2, m.get_value(borrow=True)[4:])
@change_flags(compute_test_value='off')
def test_split_neg(self): def test_split_neg(self):
rng = np.random.RandomState(seed=utt.fetch_seed()) rng = np.random.RandomState(seed=utt.fetch_seed())
m = self.shared(rng.rand(4, 6).astype(self.floatX)) m = self.shared(rng.rand(4, 6).astype(self.floatX))
...@@ -7321,11 +7324,12 @@ class T_get_scalar_constant_value(unittest.TestCase): ...@@ -7321,11 +7324,12 @@ class T_get_scalar_constant_value(unittest.TestCase):
a = opt.Assert()(c, c > 1) a = opt.Assert()(c, c > 1)
assert get_scalar_constant_value(a) == 2 assert get_scalar_constant_value(a) == 2
# condition is always False with change_flags(compute_test_value='off'):
a = opt.Assert()(c, c > 2) # condition is always False
self.assertRaises( a = opt.Assert()(c, c > 2)
tensor.NotScalarConstantError, self.assertRaises(
get_scalar_constant_value, a) tensor.NotScalarConstantError,
get_scalar_constant_value, a)
# condition is not constant # condition is not constant
a = opt.Assert()(c, c > x) a = opt.Assert()(c, c > x)
......
...@@ -6,11 +6,14 @@ import subprocess ...@@ -6,11 +6,14 @@ import subprocess
import os import os
from theano.gof.sched import sort_schedule_fn from theano.gof.sched import sort_schedule_fn
from theano.configparser import change_flags
mpi_scheduler = sort_schedule_fn(*mpi_cmps) mpi_scheduler = sort_schedule_fn(*mpi_cmps)
mpi_linker = theano.OpWiseCLinker(schedule=mpi_scheduler) mpi_linker = theano.OpWiseCLinker(schedule=mpi_scheduler)
mpi_mode = theano.Mode(linker=mpi_linker) mpi_mode = theano.Mode(linker=mpi_linker)
@change_flags(compute_test_value='off')
def test_recv(): def test_recv():
x = recv((10, 10), 'float64', 0, 11) x = recv((10, 10), 'float64', 0, 11)
assert x.dtype == 'float64' assert x.dtype == 'float64'
...@@ -29,6 +32,7 @@ def test_send(): ...@@ -29,6 +32,7 @@ def test_send():
assert sendnode.op.tag == 11 assert sendnode.op.tag == 11
@change_flags(compute_test_value='off')
def test_can_make_function(): def test_can_make_function():
x = recv((5, 5), 'float32', 0, 11) x = recv((5, 5), 'float32', 0, 11)
y = x+1 y = x+1
...@@ -61,6 +65,7 @@ def test_mpi_send_wait_cmp(): ...@@ -61,6 +65,7 @@ def test_mpi_send_wait_cmp():
assert mpi_send_wait_cmp(waitnode, addnode) > 0 # wait happens last assert mpi_send_wait_cmp(waitnode, addnode) > 0 # wait happens last
@change_flags(compute_test_value='off')
def test_mpi_tag_ordering(): def test_mpi_tag_ordering():
x = recv((2, 2), 'float32', 1, 12) x = recv((2, 2), 'float32', 1, 12)
y = recv((2, 2), 'float32', 1, 11) y = recv((2, 2), 'float32', 1, 11)
......
...@@ -63,6 +63,7 @@ from theano.tensor.elemwise import DimShuffle ...@@ -63,6 +63,7 @@ from theano.tensor.elemwise import DimShuffle
from theano.tensor.type import values_eq_approx_remove_nan from theano.tensor.type import values_eq_approx_remove_nan
from theano.tests import unittest_tools as utt from theano.tests import unittest_tools as utt
from theano.gof.opt import check_stack_trace, out2in from theano.gof.opt import check_stack_trace, out2in
from theano.configparser import change_flags
from nose.plugins.attrib import attr from nose.plugins.attrib import attr
mode_opt = theano.config.mode mode_opt = theano.config.mode
...@@ -3685,6 +3686,7 @@ class Test_local_canonicalize_alloc(unittest.TestCase): ...@@ -3685,6 +3686,7 @@ class Test_local_canonicalize_alloc(unittest.TestCase):
def setUp(self): def setUp(self):
self.rng = np.random.RandomState(utt.fetch_seed()) self.rng = np.random.RandomState(utt.fetch_seed())
@change_flags(compute_test_value='off')
def test0(self): def test0(self):
x = shared(self.rng.randn(3, 7)) x = shared(self.rng.randn(3, 7))
a = tensor.alloc(x, 6, 7) a = tensor.alloc(x, 6, 7)
...@@ -5602,7 +5604,7 @@ class T_local_opt_alloc(unittest.TestCase): ...@@ -5602,7 +5604,7 @@ class T_local_opt_alloc(unittest.TestCase):
finally: finally:
theano.config.warn_float64 = orig theano.config.warn_float64 = orig
@theano.configparser.change_flags(on_opt_error='raise') @change_flags(on_opt_error='raise')
def test_sum_bool_upcast(self): def test_sum_bool_upcast(self):
s = theano.tensor.lscalar() s = theano.tensor.lscalar()
a = theano.tensor.alloc(np.asarray(True, dtype='bool'), s, s) a = theano.tensor.alloc(np.asarray(True, dtype='bool'), s, s)
......
...@@ -34,6 +34,7 @@ from theano.tensor.subtensor import (AdvancedIncSubtensor, ...@@ -34,6 +34,7 @@ from theano.tensor.subtensor import (AdvancedIncSubtensor,
from theano.tensor.tests.test_basic import inplace_func, rand, randint_ranged from theano.tensor.tests.test_basic import inplace_func, rand, randint_ranged
from theano.tests import unittest_tools as utt from theano.tests import unittest_tools as utt
from theano.tests.unittest_tools import attr from theano.tests.unittest_tools import attr
from theano.configparser import change_flags
if PY3: if PY3:
def L(i): def L(i):
...@@ -126,14 +127,10 @@ class T_subtensor(unittest.TestCase, utt.TestOptimizationMixin): ...@@ -126,14 +127,10 @@ class T_subtensor(unittest.TestCase, utt.TestOptimizationMixin):
return return
self.fail() self.fail()
@change_flags(compute_test_value='off')
def test1_err_bounds(self): def test1_err_bounds(self):
n = self.shared(np.ones(3, dtype=self.dtype)) n = self.shared(np.ones(3, dtype=self.dtype))
ctv_backup = config.compute_test_value t = n[7]
config.compute_test_value = 'off'
try:
t = n[7]
finally:
config.compute_test_value = ctv_backup
self.assertTrue(isinstance(t.owner.op, Subtensor)) self.assertTrue(isinstance(t.owner.op, Subtensor))
# Silence expected error messages # Silence expected error messages
_logger = logging.getLogger('theano.gof.opt') _logger = logging.getLogger('theano.gof.opt')
...@@ -223,26 +220,23 @@ class T_subtensor(unittest.TestCase, utt.TestOptimizationMixin): ...@@ -223,26 +220,23 @@ class T_subtensor(unittest.TestCase, utt.TestOptimizationMixin):
self.assertTrue(tval.shape == (2,)) self.assertTrue(tval.shape == (2,))
self.assertTrue((tval == [0.0, 2.0]).all()) self.assertTrue((tval == [0.0, 2.0]).all())
@change_flags(compute_test_value='off')
def test2_err_bounds0(self): def test2_err_bounds0(self):
n = self.shared(np.ones((2, 3), dtype=self.dtype) * 5) n = self.shared(np.ones((2, 3), dtype=self.dtype) * 5)
ctv_backup = config.compute_test_value for idx in [(0, 4), (0, -4)]:
config.compute_test_value = 'off' t = n[idx]
try: self.assertTrue(isinstance(t.owner.op, Subtensor))
for idx in [(0, 4), (0, -4)]: # Silence expected warnings
t = n[idx] _logger = logging.getLogger('theano.gof.opt')
self.assertTrue(isinstance(t.owner.op, Subtensor)) oldlevel = _logger.level
# Silence expected warnings _logger.setLevel(logging.CRITICAL)
_logger = logging.getLogger('theano.gof.opt') try:
oldlevel = _logger.level self.assertRaises(IndexError,
_logger.setLevel(logging.CRITICAL) self.eval_output_and_check, [t])
try: finally:
self.assertRaises(IndexError, _logger.setLevel(oldlevel)
self.eval_output_and_check, [t])
finally:
_logger.setLevel(oldlevel)
finally:
config.compute_test_value = ctv_backup
@change_flags(compute_test_value='off')
def test2_err_bounds1(self): def test2_err_bounds1(self):
n = self.shared((np.ones((2, 3), dtype=self.dtype) * 5)) n = self.shared((np.ones((2, 3), dtype=self.dtype) * 5))
t = n[4:5, 3] t = n[4:5, 3]
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论