提交 40274190 authored 作者: Pascal Lamblin's avatar Pascal Lamblin

Put back the initial value of compute_test_value at the end of tests

上级 6f2690dd
...@@ -8,91 +8,115 @@ from theano import tensor as T ...@@ -8,91 +8,115 @@ from theano import tensor as T
class TestComputeTestValue(unittest.TestCase): class TestComputeTestValue(unittest.TestCase):
def test_variable_only(self): def test_variable_only(self):
theano.config.compute_test_value = True orig_compute_test_value = theano.config.compute_test_value
try:
theano.config.compute_test_value = True
x = T.matrix('x') x = T.matrix('x')
x.tag.test_value = numpy.random.rand(3,4) x.tag.test_value = numpy.random.rand(3,4)
y = T.matrix('y') y = T.matrix('y')
y.tag.test_value = numpy.random.rand(4,5) y.tag.test_value = numpy.random.rand(4,5)
# should work
z = T.dot(x,y)
# this test should fail # should work
y.tag.test_value = numpy.random.rand(6,5) z = T.dot(x,y)
self.assertRaises(ValueError, T.dot, x, y)
def test_compute_flag(self): # this test should fail
y.tag.test_value = numpy.random.rand(6,5)
self.assertRaises(ValueError, T.dot, x, y)
finally:
theano.config.compute_test_value = orig_compute_test_value
x = T.matrix('x')
y = T.matrix('y')
y.tag.test_value = numpy.random.rand(4,5)
# should skip computation of test value
theano.config.compute_test_value = False
z = T.dot(x,y)
# should fail one or another when flag is set def test_compute_flag(self):
theano.config.compute_test_value = 'warn' orig_compute_test_value = theano.config.compute_test_value
self.assertRaises(Warning, T.dot, x, y) try:
theano.config.compute_test_value = 'err' x = T.matrix('x')
self.assertRaises(ValueError, T.dot, x, y) y = T.matrix('y')
y.tag.test_value = numpy.random.rand(4,5)
# should skip computation of test value
theano.config.compute_test_value = False
z = T.dot(x,y)
# should fail one or another when flag is set
theano.config.compute_test_value = 'warn'
self.assertRaises(Warning, T.dot, x, y)
theano.config.compute_test_value = 'err'
self.assertRaises(ValueError, T.dot, x, y)
finally:
theano.config.compute_test_value = orig_compute_test_value
def test_string_var(self): def test_string_var(self):
theano.config.compute_test_value = True orig_compute_test_value = theano.config.compute_test_value
try:
theano.config.compute_test_value = True
x = T.matrix('x')
x.tag.test_value = numpy.random.rand(3,4)
y = T.matrix('y')
y.tag.test_value = numpy.random.rand(4,5)
x = T.matrix('x') z = theano.shared(numpy.random.rand(5,6))
x.tag.test_value = numpy.random.rand(3,4)
y = T.matrix('y')
y.tag.test_value = numpy.random.rand(4,5)
z = theano.shared(numpy.random.rand(5,6))
# should work # should work
out = T.dot(T.dot(x,y), z) out = T.dot(T.dot(x,y), z)
def f(x,y,z): def f(x,y,z):
return T.dot(T.dot(x,y),z) return T.dot(T.dot(x,y),z)
# this test should fail # this test should fail
z.set_value(numpy.random.rand(7,6)) z.set_value(numpy.random.rand(7,6))
self.assertRaises(ValueError, f, x, y, z) self.assertRaises(ValueError, f, x, y, z)
finally:
theano.config.compute_test_value = orig_compute_test_value
def test_shared(self): def test_shared(self):
theano.config.compute_test_value = True orig_compute_test_value = theano.config.compute_test_value
try:
theano.config.compute_test_value = True
x = T.matrix('x') x = T.matrix('x')
x.tag.test_value = numpy.random.rand(3,4) x.tag.test_value = numpy.random.rand(3,4)
y = theano.shared(numpy.random.rand(4,6), 'y') y = theano.shared(numpy.random.rand(4,6), 'y')
# should work
z = T.dot(x,y)
# this test should fail # should work
y.set_value(numpy.random.rand(5,6)) z = T.dot(x,y)
self.assertRaises(ValueError, T.dot, x, y)
# this test should fail
y.set_value(numpy.random.rand(5,6))
self.assertRaises(ValueError, T.dot, x, y)
finally:
theano.config.compute_test_value = orig_compute_test_value
def test_ndarray(self): def test_ndarray(self):
theano.config.compute_test_value = True orig_compute_test_value = theano.config.compute_test_value
try:
theano.config.compute_test_value = True
x = numpy.random.rand(2,3)
y = theano.shared(numpy.random.rand(3,6), 'y')
x = numpy.random.rand(2,3) # should work
y = theano.shared(numpy.random.rand(3,6), 'y') z = T.dot(x,y)
# should work
z = T.dot(x,y)
# this test should fail # this test should fail
x = numpy.random.rand(2,4) x = numpy.random.rand(2,4)
self.assertRaises(ValueError, T.dot, x, y) self.assertRaises(ValueError, T.dot, x, y)
finally:
theano.config.compute_test_value = orig_compute_test_value
def test_constant(self): def test_constant(self):
theano.config.compute_test_value = True orig_compute_test_value = theano.config.compute_test_value
try:
theano.config.compute_test_value = True
x = T.constant(numpy.random.rand(2,3))
y = theano.shared(numpy.random.rand(3,6), 'y')
x = T.constant(numpy.random.rand(2,3)) # should work
y = theano.shared(numpy.random.rand(3,6), 'y') z = T.dot(x,y)
# should work
z = T.dot(x,y)
# this test should fail # this test should fail
x = T.constant(numpy.random.rand(2,4)) x = T.constant(numpy.random.rand(2,4))
self.assertRaises(ValueError, T.dot, x, y) self.assertRaises(ValueError, T.dot, x, y)
finally:
theano.config.compute_test_value = orig_compute_test_value
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论