提交 2d51062f authored 作者: Benjamin Scellier's avatar Benjamin Scellier 提交者: Nicolas Ballas

file theano/gof/tests/test_compute_test_value.py

上级 99ff11d1
...@@ -4,7 +4,7 @@ import sys ...@@ -4,7 +4,7 @@ import sys
import traceback import traceback
import warnings import warnings
import numpy import numpy as np
from nose.plugins.skip import SkipTest from nose.plugins.skip import SkipTest
import unittest import unittest
...@@ -44,9 +44,9 @@ class TestComputeTestValue(unittest.TestCase): ...@@ -44,9 +44,9 @@ class TestComputeTestValue(unittest.TestCase):
theano.config.compute_test_value = 'raise' theano.config.compute_test_value = 'raise'
x = T.matrix('x') x = T.matrix('x')
x.tag.test_value = numpy.random.rand(3, 4).astype(config.floatX) x.tag.test_value = np.random.rand(3, 4).astype(config.floatX)
y = T.matrix('y') y = T.matrix('y')
y.tag.test_value = numpy.random.rand(4, 5).astype(config.floatX) y.tag.test_value = np.random.rand(4, 5).astype(config.floatX)
# should work # should work
z = T.dot(x, y) z = T.dot(x, y)
...@@ -56,7 +56,7 @@ class TestComputeTestValue(unittest.TestCase): ...@@ -56,7 +56,7 @@ class TestComputeTestValue(unittest.TestCase):
z.tag.test_value) z.tag.test_value)
# this test should fail # this test should fail
y.tag.test_value = numpy.random.rand(6, 5).astype(config.floatX) y.tag.test_value = np.random.rand(6, 5).astype(config.floatX)
self.assertRaises(ValueError, T.dot, x, y) self.assertRaises(ValueError, T.dot, x, y)
finally: finally:
theano.config.compute_test_value = orig_compute_test_value theano.config.compute_test_value = orig_compute_test_value
...@@ -66,7 +66,7 @@ class TestComputeTestValue(unittest.TestCase): ...@@ -66,7 +66,7 @@ class TestComputeTestValue(unittest.TestCase):
try: try:
x = T.matrix('x') x = T.matrix('x')
y = T.matrix('y') y = T.matrix('y')
y.tag.test_value = numpy.random.rand(4, 5).astype(config.floatX) y.tag.test_value = np.random.rand(4, 5).astype(config.floatX)
# should skip computation of test value # should skip computation of test value
theano.config.compute_test_value = 'off' theano.config.compute_test_value = 'off'
...@@ -96,11 +96,11 @@ class TestComputeTestValue(unittest.TestCase): ...@@ -96,11 +96,11 @@ class TestComputeTestValue(unittest.TestCase):
theano.config.compute_test_value = 'raise' theano.config.compute_test_value = 'raise'
x = T.matrix('x') x = T.matrix('x')
x.tag.test_value = numpy.random.rand(3, 4).astype(config.floatX) x.tag.test_value = np.random.rand(3, 4).astype(config.floatX)
y = T.matrix('y') y = T.matrix('y')
y.tag.test_value = numpy.random.rand(4, 5).astype(config.floatX) y.tag.test_value = np.random.rand(4, 5).astype(config.floatX)
z = theano.shared(numpy.random.rand(5, 6).astype(config.floatX)) z = theano.shared(np.random.rand(5, 6).astype(config.floatX))
# should work # should work
out = T.dot(T.dot(x, y), z) out = T.dot(T.dot(x, y), z)
...@@ -114,7 +114,7 @@ class TestComputeTestValue(unittest.TestCase): ...@@ -114,7 +114,7 @@ class TestComputeTestValue(unittest.TestCase):
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).astype(config.floatX)) z.set_value(np.random.rand(7, 6).astype(config.floatX))
self.assertRaises(ValueError, f, x, y, z) self.assertRaises(ValueError, f, x, y, z)
finally: finally:
theano.config.compute_test_value = orig_compute_test_value theano.config.compute_test_value = orig_compute_test_value
...@@ -125,8 +125,8 @@ class TestComputeTestValue(unittest.TestCase): ...@@ -125,8 +125,8 @@ class TestComputeTestValue(unittest.TestCase):
theano.config.compute_test_value = 'raise' theano.config.compute_test_value = 'raise'
x = T.matrix('x') x = T.matrix('x')
x.tag.test_value = numpy.random.rand(3, 4).astype(config.floatX) x.tag.test_value = np.random.rand(3, 4).astype(config.floatX)
y = theano.shared(numpy.random.rand(4, 6).astype(config.floatX), y = theano.shared(np.random.rand(4, 6).astype(config.floatX),
'y') 'y')
# should work # should work
...@@ -136,7 +136,7 @@ class TestComputeTestValue(unittest.TestCase): ...@@ -136,7 +136,7 @@ class TestComputeTestValue(unittest.TestCase):
assert _allclose(f(x.tag.test_value), z.tag.test_value) assert _allclose(f(x.tag.test_value), z.tag.test_value)
# this test should fail # this test should fail
y.set_value(numpy.random.rand(5, 6).astype(config.floatX)) y.set_value(np.random.rand(5, 6).astype(config.floatX))
self.assertRaises(ValueError, T.dot, x, y) self.assertRaises(ValueError, T.dot, x, y)
finally: finally:
theano.config.compute_test_value = orig_compute_test_value theano.config.compute_test_value = orig_compute_test_value
...@@ -146,8 +146,8 @@ class TestComputeTestValue(unittest.TestCase): ...@@ -146,8 +146,8 @@ class TestComputeTestValue(unittest.TestCase):
try: try:
theano.config.compute_test_value = 'raise' theano.config.compute_test_value = 'raise'
x = numpy.random.rand(2, 3).astype(config.floatX) x = np.random.rand(2, 3).astype(config.floatX)
y = theano.shared(numpy.random.rand(3, 6).astype(config.floatX), y = theano.shared(np.random.rand(3, 6).astype(config.floatX),
'y') 'y')
# should work # should work
...@@ -157,7 +157,7 @@ class TestComputeTestValue(unittest.TestCase): ...@@ -157,7 +157,7 @@ class TestComputeTestValue(unittest.TestCase):
assert _allclose(f(), z.tag.test_value) assert _allclose(f(), z.tag.test_value)
# this test should fail # this test should fail
x = numpy.random.rand(2, 4).astype(config.floatX) x = np.random.rand(2, 4).astype(config.floatX)
self.assertRaises(ValueError, T.dot, x, y) self.assertRaises(ValueError, T.dot, x, y)
finally: finally:
theano.config.compute_test_value = orig_compute_test_value theano.config.compute_test_value = orig_compute_test_value
...@@ -167,7 +167,7 @@ class TestComputeTestValue(unittest.TestCase): ...@@ -167,7 +167,7 @@ class TestComputeTestValue(unittest.TestCase):
try: try:
theano.config.compute_test_value = 'raise' theano.config.compute_test_value = 'raise'
x = theano.shared(numpy.random.rand(0, 6).astype(config.floatX), x = theano.shared(np.random.rand(0, 6).astype(config.floatX),
'x') 'x')
# should work # should work
...@@ -184,8 +184,8 @@ class TestComputeTestValue(unittest.TestCase): ...@@ -184,8 +184,8 @@ class TestComputeTestValue(unittest.TestCase):
try: try:
theano.config.compute_test_value = 'raise' theano.config.compute_test_value = 'raise'
x = T.constant(numpy.random.rand(2, 3), dtype=config.floatX) x = T.constant(np.random.rand(2, 3), dtype=config.floatX)
y = theano.shared(numpy.random.rand(3, 6).astype(config.floatX), y = theano.shared(np.random.rand(3, 6).astype(config.floatX),
'y') 'y')
# should work # should work
...@@ -195,7 +195,7 @@ class TestComputeTestValue(unittest.TestCase): ...@@ -195,7 +195,7 @@ class TestComputeTestValue(unittest.TestCase):
assert _allclose(f(), z.tag.test_value) assert _allclose(f(), z.tag.test_value)
# this test should fail # this test should fail
x = T.constant(numpy.random.rand(2, 4), dtype=config.floatX) x = T.constant(np.random.rand(2, 4), dtype=config.floatX)
self.assertRaises(ValueError, T.dot, x, y) self.assertRaises(ValueError, T.dot, x, y)
finally: finally:
theano.config.compute_test_value = orig_compute_test_value theano.config.compute_test_value = orig_compute_test_value
...@@ -207,9 +207,9 @@ class TestComputeTestValue(unittest.TestCase): ...@@ -207,9 +207,9 @@ class TestComputeTestValue(unittest.TestCase):
x = T.fmatrix('x') x = T.fmatrix('x')
# Incorrect dtype (float64) for test_value # Incorrect dtype (float64) for test_value
x.tag.test_value = numpy.random.rand(3, 4) x.tag.test_value = np.random.rand(3, 4)
y = T.dmatrix('y') y = T.dmatrix('y')
y.tag.test_value = numpy.random.rand(4, 5) y.tag.test_value = np.random.rand(4, 5)
self.assertRaises(TypeError, T.dot, x, y) self.assertRaises(TypeError, T.dot, x, y)
finally: finally:
...@@ -222,9 +222,9 @@ class TestComputeTestValue(unittest.TestCase): ...@@ -222,9 +222,9 @@ class TestComputeTestValue(unittest.TestCase):
try: try:
config.compute_test_value = "raise" config.compute_test_value = "raise"
x = T.matrix() x = T.matrix()
x.tag.test_value = numpy.zeros((2, 3), dtype=config.floatX) x.tag.test_value = np.zeros((2, 3), dtype=config.floatX)
y = T.matrix() y = T.matrix()
y.tag.test_value = numpy.zeros((2, 2), dtype=config.floatX) y.tag.test_value = np.zeros((2, 2), dtype=config.floatX)
self.assertRaises(ValueError, x.__mul__, y) self.assertRaises(ValueError, x.__mul__, y)
finally: finally:
theano.config.compute_test_value = orig_compute_test_value theano.config.compute_test_value = orig_compute_test_value
...@@ -240,7 +240,7 @@ class TestComputeTestValue(unittest.TestCase): ...@@ -240,7 +240,7 @@ class TestComputeTestValue(unittest.TestCase):
k = T.iscalar("k") k = T.iscalar("k")
A = T.vector("A") A = T.vector("A")
k.tag.test_value = 3 k.tag.test_value = 3
A.tag.test_value = numpy.random.rand(5).astype(config.floatX) A.tag.test_value = np.random.rand(5).astype(config.floatX)
def fx(prior_result, A): def fx(prior_result, A):
return prior_result * A return prior_result * A
...@@ -267,7 +267,7 @@ class TestComputeTestValue(unittest.TestCase): ...@@ -267,7 +267,7 @@ class TestComputeTestValue(unittest.TestCase):
k = T.iscalar("k") k = T.iscalar("k")
A = T.matrix("A") A = T.matrix("A")
k.tag.test_value = 3 k.tag.test_value = 3
A.tag.test_value = numpy.random.rand(5, 3).astype(config.floatX) A.tag.test_value = np.random.rand(5, 3).astype(config.floatX)
def fx(prior_result, A): def fx(prior_result, A):
return T.dot(prior_result, A) return T.dot(prior_result, A)
...@@ -304,7 +304,7 @@ class TestComputeTestValue(unittest.TestCase): ...@@ -304,7 +304,7 @@ class TestComputeTestValue(unittest.TestCase):
k = T.iscalar("k") k = T.iscalar("k")
A = T.matrix("A") A = T.matrix("A")
k.tag.test_value = 3 k.tag.test_value = 3
A.tag.test_value = numpy.random.rand(5, 3).astype(config.floatX) A.tag.test_value = np.random.rand(5, 3).astype(config.floatX)
def fx(prior_result, A): def fx(prior_result, A):
return T.dot(prior_result, A) return T.dot(prior_result, A)
...@@ -400,7 +400,7 @@ class TestComputeTestValue(unittest.TestCase): ...@@ -400,7 +400,7 @@ class TestComputeTestValue(unittest.TestCase):
try: try:
theano.config.compute_test_value = 'raise' theano.config.compute_test_value = 'raise'
init_Mu1 = theano.shared( init_Mu1 = theano.shared(
numpy.zeros((5,), dtype=config.floatX)).dimshuffle('x', 0) np.zeros((5,), dtype=config.floatX)).dimshuffle('x', 0)
theano.function([], outputs=[init_Mu1]) theano.function([], outputs=[init_Mu1])
finally: finally:
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论