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