提交 2c6adccc authored 作者: Pascal Lamblin's avatar Pascal Lamblin 提交者: GitHub

Merge pull request #6178 from abergeron/fix_buildbot2

Repair tests that fail with compute_test_value.
...@@ -39,7 +39,7 @@ class OpDecoratorTests(utt.InferShapeTester): ...@@ -39,7 +39,7 @@ class OpDecoratorTests(utt.InferShapeTester):
x = dmatrix('x') x = dmatrix('x')
x.tag.test_value = np.zeros((2, 2)) x.tag.test_value = np.zeros((2, 2))
y = dvector('y') y = dvector('y')
y.tag.test_value = [0, 0] y.tag.test_value = [0, 0, 0, 0]
@as_op([dmatrix, dvector], dvector) @as_op([dmatrix, dvector], dvector)
def cumprod_plus(x, y): def cumprod_plus(x, y):
...@@ -55,7 +55,7 @@ class OpDecoratorTests(utt.InferShapeTester): ...@@ -55,7 +55,7 @@ class OpDecoratorTests(utt.InferShapeTester):
x = dmatrix('x') x = dmatrix('x')
x.tag.test_value = np.zeros((2, 2)) x.tag.test_value = np.zeros((2, 2))
y = dvector('y') y = dvector('y')
y.tag.test_value = [0, 0] y.tag.test_value = [0, 0, 0, 0]
def infer_shape(node, shapes): def infer_shape(node, shapes):
x, y = shapes x, y = shapes
......
...@@ -12,6 +12,8 @@ from theano.gof import destroyhandler ...@@ -12,6 +12,8 @@ from theano.gof import destroyhandler
from theano.gof.fg import FunctionGraph, InconsistencyError from theano.gof.fg import FunctionGraph, InconsistencyError
from theano.gof.toolbox import ReplaceValidate from theano.gof.toolbox import ReplaceValidate
from theano.configparser import change_flags
from copy import copy from copy import copy
...@@ -429,6 +431,7 @@ def test_value_repl(): ...@@ -429,6 +431,7 @@ def test_value_repl():
consistent(g) consistent(g)
@change_flags(compute_test_value='off')
def test_value_repl_2(): def test_value_repl_2():
x, y, z = inputs() x, y, z = inputs()
sy = sigmoid(y) sy = sigmoid(y)
......
...@@ -15,6 +15,8 @@ from theano.sandbox.rng_mrg import MRG_RandomStreams ...@@ -15,6 +15,8 @@ from theano.sandbox.rng_mrg import MRG_RandomStreams
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
# TODO: test MRG_RandomStreams # TODO: test MRG_RandomStreams
# Partly done in test_consistency_randomstreams # Partly done in test_consistency_randomstreams
...@@ -666,9 +668,10 @@ def test_overflow_cpu(): ...@@ -666,9 +668,10 @@ def test_overflow_cpu():
# run with THEANO_FLAGS=mode=FAST_RUN,device=cpu,floatX=float32 # run with THEANO_FLAGS=mode=FAST_RUN,device=cpu,floatX=float32
rng = MRG_RandomStreams(np.random.randint(1234)) rng = MRG_RandomStreams(np.random.randint(1234))
fct = rng.uniform fct = rng.uniform
# should raise error as the size overflows with change_flags(compute_test_value='off'):
sizes = [(2**31, ), (2**32, ), (2**15, 2**16,), (2, 2**15, 2**15)] # should raise error as the size overflows
rng_mrg_overflow(sizes, fct, config.mode, should_raise_error=True) sizes = [(2**31, ), (2**32, ), (2**15, 2**16,), (2, 2**15, 2**15)]
rng_mrg_overflow(sizes, fct, config.mode, should_raise_error=True)
# should not raise error # should not raise error
sizes = [(2**5, ), (2**5, 2**5), (2**5, 2**5, 2**5)] sizes = [(2**5, ), (2**5, 2**5), (2**5, 2**5, 2**5)]
rng_mrg_overflow(sizes, fct, config.mode, should_raise_error=False) rng_mrg_overflow(sizes, fct, config.mode, should_raise_error=False)
......
...@@ -5862,53 +5862,6 @@ class Dot(Op): ...@@ -5862,53 +5862,6 @@ class Dot(Op):
if eval_points[0] is None and eval_points[1] is None: if eval_points[0] is None and eval_points[1] is None:
return [None] return [None]
debugger_available = config.compute_test_value != 'off'
if debugger_available:
try:
iv0 = gof.op.get_test_value(inputs[0])
except AttributeError:
gof.op.missing_test_message(
'first input passed to Dot.R_op has no test value')
debugger_available = False
try:
iv1 = gof.op.get_test_value(inputs[1])
except AttributeError:
gof.op.missing_test_message(
'second input passed to Dot.R_op has no test value')
debugger_available = False
if eval_points[0]:
try:
ev0 = gof.op.get_test_value(eval_points[0])
except AttributeError:
gof.op.missing_test_message(
'first eval point passed to Dot.R_op '
'has no test value')
debugger_available = False
if eval_points[1]:
try:
ev1 = gof.op.get_test_value(eval_points[1])
except AttributeError:
gof.op.missing_test_message(
'second eval point passed to Dot.R_op '
'has no test value')
debugger_available = False
if debugger_available:
input_values = [iv0, iv1]
eval_point_values = [ev0, ev1]
for i in xrange(2):
if eval_point_values[i] is not None and \
input_values[i].shape != eval_point_values[i].shape:
raise ValueError(
'input ' + str(i) + ' and eval_point ' + str(i) +
' to Dot.R_op should have the same shape, but '
'their shapes are %s and %s, respectively' % (
str(input_values[i].shape),
str(eval_point_values[i].shape)))
if eval_points[0]: if eval_points[0]:
t1 = self(eval_points[0], inputs[1]) t1 = self(eval_points[0], inputs[1])
if eval_points[1]: if eval_points[1]:
......
...@@ -2300,8 +2300,8 @@ class AbstractConv_gradInputs(BaseAbstractConv): ...@@ -2300,8 +2300,8 @@ class AbstractConv_gradInputs(BaseAbstractConv):
mshp0 = mat.shape[0] // self.num_groups mshp0 = mat.shape[0] // self.num_groups
mshp1 = mat.shape[1] * self.num_groups mshp1 = mat.shape[1] * self.num_groups
mat = mat.reshape((self.num_groups, mshp0) + mat.shape[1:]) mat = mat.reshape((self.num_groups, mshp0) + mat.shape[1:])
mat = mat.transpose((1, 0, 2, 3, 4)) mat = mat.transpose((1, 0, 2) + tuple(range(3, 3 + self.convdim)))
mat = mat.reshape((mshp0, mshp1) + mat.shape[-2:]) mat = mat.reshape((mshp0, mshp1) + mat.shape[-self.convdim:])
return mat return mat
kern = correct_for_groups(kern) kern = correct_for_groups(kern)
kern = kern.transpose(axes_order) kern = kern.transpose(axes_order)
......
...@@ -130,7 +130,7 @@ class TestConv3D(utt.InferShapeTester): ...@@ -130,7 +130,7 @@ class TestConv3D(utt.InferShapeTester):
self.rb.name = 'rb' self.rb.name = 'rb'
self.V = shared(N.ndarray(shape=(1, 1, 1, 1, 1), dtype=floatX)) self.V = shared(N.ndarray(shape=(1, 1, 1, 1, 1), dtype=floatX))
self.V.name = 'V' self.V.name = 'V'
self.d = shared(N.ndarray(shape=(3, ), dtype=int)) self.d = shared(N.ones(shape=(3, ), dtype=int))
self.d.name = 'd' self.d.name = 'd'
self.H = conv3D(self.V, self.W, self.b, self.d) self.H = conv3D(self.V, self.W, self.b, self.d)
......
...@@ -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 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论