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

Update other tests, which used implicit downcasting.

上级 0d2c1831
...@@ -203,49 +203,52 @@ class Test_SharedVariable(unittest.TestCase): ...@@ -203,49 +203,52 @@ class Test_SharedVariable(unittest.TestCase):
# should keep the same bit width / precision as the original value used to create the # should keep the same bit width / precision as the original value used to create the
# shared variable. # shared variable.
# #
# Since downcasting of a value now raises an Exception,
def f(var, val): var.value = val def f(var, val): var.value = val
b = shared(numpy.int64(7)) b = shared(numpy.int64(7), allow_downcast=True)
assert b.type == theano.tensor.lscalar assert b.type == theano.tensor.lscalar
f(b,8.23) f(b,8.23)
assert b.value==8 assert b.value==8
b = shared(numpy.int32(7)) b = shared(numpy.int32(7), allow_downcast=True)
assert b.type == theano.tensor.iscalar assert b.type == theano.tensor.iscalar
f(b,8.23) f(b,8.23)
assert b.value==8 assert b.value==8
b = shared(numpy.int16(7)) b = shared(numpy.int16(7), allow_downcast=True)
assert b.type == theano.tensor.wscalar assert b.type == theano.tensor.wscalar
f(b,8.23) f(b,8.23)
assert b.value==8 assert b.value==8
b = shared(numpy.int8(7)) b = shared(numpy.int8(7), allow_downcast=True)
assert b.type == theano.tensor.bscalar assert b.type == theano.tensor.bscalar
f(b,8.23) f(b,8.23)
assert b.value==8 assert b.value==8
b = shared(numpy.float64(7.234)) b = shared(numpy.float64(7.234), allow_downcast=True)
assert b.type == theano.tensor.dscalar assert b.type == theano.tensor.dscalar
f(b,8) f(b,8)
assert b.value==8 assert b.value==8
b = shared(numpy.float32(7.234)) b = shared(numpy.float32(7.234), allow_downcast=True)
assert b.type == theano.tensor.fscalar assert b.type == theano.tensor.fscalar
f(b,8) f(b,8)
assert b.value==8 assert b.value==8
b = shared(numpy.float(7.234)) b = shared(numpy.float(7.234), allow_downcast=True)
assert b.type == theano.tensor.dscalar assert b.type == theano.tensor.dscalar
f(b,8) f(b,8)
assert b.value==8 assert b.value==8
b = shared(7.234) b = shared(7.234, allow_downcast=True)
assert b.type == theano.tensor.dscalar assert b.type == theano.tensor.dscalar
f(b,8) f(b,8)
assert b.value==8 assert b.value==8
c = shared(numpy.zeros((5,5), dtype='float32')) c = shared(numpy.zeros((5,5), dtype='float32'), allow_downcast=True)
self.failUnlessRaises(TypeError, f, b, numpy.random.rand(5,5)) self.failUnlessRaises(TypeError, f, b, numpy.random.rand(5,5))
...@@ -253,32 +256,32 @@ class Test_SharedVariable(unittest.TestCase): ...@@ -253,32 +256,32 @@ class Test_SharedVariable(unittest.TestCase):
def test_tensor_floatX(self): def test_tensor_floatX(self):
def f(var, val): var.value = val def f(var, val): var.value = val
b = shared(numpy.int64([7])) b = shared(numpy.int64([7]), allow_downcast=True)
assert b.type == theano.tensor.lvector assert b.type == theano.tensor.lvector
f(b,[8.23]) f(b,[8.23])
assert b.value == 8 assert b.value == 8
b = shared(numpy.int32([7])) b = shared(numpy.int32([7]), allow_downcast=True)
assert b.type == theano.tensor.ivector assert b.type == theano.tensor.ivector
f(b,[8.23]) f(b,[8.23])
assert b.value == 8 assert b.value == 8
b = shared(numpy.int16([7])) b = shared(numpy.int16([7]), allow_downcast=True)
assert b.type == theano.tensor.wvector assert b.type == theano.tensor.wvector
f(b,[8.23]) f(b,[8.23])
assert b.value == 8 assert b.value == 8
b = shared(numpy.int8([7])) b = shared(numpy.int8([7]), allow_downcast=True)
assert b.type == theano.tensor.bvector assert b.type == theano.tensor.bvector
f(b,[8.23]) f(b,[8.23])
assert b.value == 8 assert b.value == 8
b = shared(numpy.float64([7.234])) b = shared(numpy.float64([7.234]), allow_downcast=True)
assert b.type == theano.tensor.dvector assert b.type == theano.tensor.dvector
f(b,[8]) f(b,[8])
assert b.value == 8 assert b.value == 8
b = shared(numpy.float32([7.234])) b = shared(numpy.float32([7.234]), allow_downcast=True)
assert b.type == theano.tensor.fvector assert b.type == theano.tensor.fvector
f(b,[8]) f(b,[8])
assert b.value == 8 assert b.value == 8
...@@ -293,12 +296,12 @@ class Test_SharedVariable(unittest.TestCase): ...@@ -293,12 +296,12 @@ class Test_SharedVariable(unittest.TestCase):
# assert b.type == theano.tensor.dvector # assert b.type == theano.tensor.dvector
# f(b,[8]) # f(b,[8])
b = shared(numpy.asarray([7.234],dtype=theano.config.floatX)) b = shared(numpy.asarray([7.234],dtype=theano.config.floatX), allow_downcast=True)
assert b.dtype == theano.config.floatX assert b.dtype == theano.config.floatX
f(b,[8]) f(b,[8])
assert b.value == 8 assert b.value == 8
c = shared(numpy.zeros((5,5), dtype='float32')) c = shared(numpy.zeros((5,5), dtype='float32'), allow_downcast=True)
self.failUnlessRaises(TypeError, f, b, numpy.random.rand(5,5)) self.failUnlessRaises(TypeError, f, b, numpy.random.rand(5,5))
......
...@@ -206,7 +206,7 @@ def test_elemwise_empty(): ...@@ -206,7 +206,7 @@ def test_elemwise_empty():
f2 = pfunc([b], [], updates=[(a, a+b)], mode=mode_without_gpu) f2 = pfunc([b], [], updates=[(a, a+b)], mode=mode_without_gpu)
a0 = a.value * 1.0 a0 = a.value * 1.0
f(numpy.ones((0,0))) f(numpy.ones((0,0), dtype='float32'))
assert numpy.all(a0 + 1.0 == a.value) assert numpy.all(a0 + 1.0 == a.value)
...@@ -225,7 +225,7 @@ def test_elemwise0(): ...@@ -225,7 +225,7 @@ def test_elemwise0():
print 'BEFORE ADD', a.value print 'BEFORE ADD', a.value
for i, node in enumerate(f.maker.env.toposort()): for i, node in enumerate(f.maker.env.toposort()):
print i, node print i, node
f(numpy.ones((4,4))) f(numpy.ones((4,4), dtype='float32'))
print 'AFTER ADD', a.value print 'AFTER ADD', a.value
assert numpy.all(a0 + 1.0 == a.value) assert numpy.all(a0 + 1.0 == a.value)
...@@ -796,7 +796,7 @@ def test_duplicate_arg_elemwise(): ...@@ -796,7 +796,7 @@ def test_duplicate_arg_elemwise():
f = theano.function([A],B, mode = mode_with_gpu) f = theano.function([A],B, mode = mode_with_gpu)
Aval = numpy.random.RandomState([1,2,3]).randn(5,5) Aval = numpy.random.RandomState([1,2,3]).randn(5,5).astype('float32')
Bval = Aval + Aval Bval = Aval + Aval
assert numpy.allclose(Bval,f(Aval)) assert numpy.allclose(Bval,f(Aval))
......
...@@ -42,7 +42,8 @@ def test_GpuCrossentropySoftmaxArgmax1HotWithBias(): ...@@ -42,7 +42,8 @@ def test_GpuCrossentropySoftmaxArgmax1HotWithBias():
dot_result = T.fmatrix('dot_result') dot_result = T.fmatrix('dot_result')
xx = numpy.asarray(numpy.random.rand(batch_size,n_in),dtype=numpy.float32) xx = numpy.asarray(numpy.random.rand(batch_size,n_in),dtype=numpy.float32)
yy = numpy.ones((batch_size,),dtype='float32') #?????yy = numpy.ones((batch_size,),dtype='float32')
yy = numpy.ones((batch_size,),dtype='int32')
b_values = numpy.zeros((n_out,),dtype='float32') b_values = numpy.zeros((n_out,),dtype='float32')
W_values = numpy.asarray(numpy.random.rand(n_in,n_out),dtype='float32') W_values = numpy.asarray(numpy.random.rand(n_in,n_out),dtype='float32')
...@@ -82,7 +83,7 @@ def test_GpuCrossentropySoftmax1HotWithBiasDx(): ...@@ -82,7 +83,7 @@ def test_GpuCrossentropySoftmax1HotWithBiasDx():
batch_size = 4097 batch_size = 4097
n_out = 1250 n_out = 1250
softmax_output_value = numpy.random.rand(batch_size, n_out) softmax_output_value = numpy.random.rand(batch_size, n_out).astype('float32')
softmax_output = T.fmatrix() softmax_output = T.fmatrix()
softmax_output /= softmax_output.sum(axis=1).reshape(softmax_output.shape[1],1) softmax_output /= softmax_output.sum(axis=1).reshape(softmax_output.shape[1],1)
......
...@@ -73,7 +73,7 @@ def test_softmax(): ...@@ -73,7 +73,7 @@ def test_softmax():
f = theano.function([x],tensor.nnet.nnet.Softmax()(x), mode=mode_with_gpu) f = theano.function([x],tensor.nnet.nnet.Softmax()(x), mode=mode_with_gpu)
f2 = theano.function([x],tensor.nnet.nnet.Softmax()(x), mode=mode_without_gpu) f2 = theano.function([x],tensor.nnet.nnet.Softmax()(x), mode=mode_without_gpu)
assert isinstance(f.maker.env.toposort()[1].op,cuda.nnet.GpuSoftmax) assert isinstance(f.maker.env.toposort()[1].op,cuda.nnet.GpuSoftmax)
xv=numpy.random.rand(7,8) xv=numpy.random.rand(7,8).astype('float32')
assert numpy.allclose(f(xv),f2(xv)) assert numpy.allclose(f(xv),f2(xv))
...@@ -84,8 +84,8 @@ def test_softmax_with_bias(): ...@@ -84,8 +84,8 @@ def test_softmax_with_bias():
f = theano.function([x,b],tensor.nnet.nnet.SoftmaxWithBias()(x,b), mode=mode_with_gpu) f = theano.function([x,b],tensor.nnet.nnet.SoftmaxWithBias()(x,b), mode=mode_with_gpu)
f2 = theano.function([x,b],tensor.nnet.nnet.SoftmaxWithBias()(x,b), mode=mode_without_gpu) f2 = theano.function([x,b],tensor.nnet.nnet.SoftmaxWithBias()(x,b), mode=mode_without_gpu)
assert isinstance(f.maker.env.toposort()[2].op,cuda.nnet.GpuSoftmaxWithBias) assert isinstance(f.maker.env.toposort()[2].op,cuda.nnet.GpuSoftmaxWithBias)
xv=numpy.random.rand(7,8) xv=numpy.random.rand(7,8).astype('float32')
bv=numpy.random.rand(8) bv=numpy.random.rand(8).astype('float32')
assert numpy.allclose(f(xv,bv),f2(xv,bv)) assert numpy.allclose(f(xv,bv),f2(xv,bv))
def test_opt_gpujoin_onlyajoin(): def test_opt_gpujoin_onlyajoin():
...@@ -153,7 +153,7 @@ def test_print_op(): ...@@ -153,7 +153,7 @@ def test_print_op():
assert isinstance(topo[1].op, theano.printing.Print) assert isinstance(topo[1].op, theano.printing.Print)
assert isinstance(topo[2].op, cuda.GpuElemwise) assert isinstance(topo[2].op, cuda.GpuElemwise)
assert topo[3].op == cuda.host_from_gpu assert topo[3].op == cuda.host_from_gpu
f(numpy.random.random((5,5))) f(numpy.random.random((5,5)).astype('float32'))
def test_elemwise_fusion(): def test_elemwise_fusion():
""" Test the the GpuElemwise fusion work correctly""" """ Test the the GpuElemwise fusion work correctly"""
......
...@@ -1654,48 +1654,48 @@ class test_comparison(unittest.TestCase): ...@@ -1654,48 +1654,48 @@ class test_comparison(unittest.TestCase):
def test_gt(self): def test_gt(self):
x, y = fvector(), fvector() x, y = fvector(), fvector()
fn = inplace_func([x,y], x > y) fn = inplace_func([x,y], x > y)
l = numpy.asarray([0.,-1.,1.]) l = numpy.asarray([0.,-1.,1.], dtype='float32')
r = numpy.asarray([0.,1.,-1.]) r = numpy.asarray([0.,1.,-1.], dtype='float32')
v = fn(l, r) v = fn(l, r)
self.failUnless(numpy.all(v == (l > r)), (v, (l>r))) self.failUnless(numpy.all(v == (l > r)), (v, (l>r)))
def test_lt(self): def test_lt(self):
x, y = fvector(), fvector() x, y = fvector(), fvector()
fn = inplace_func([x,y], x < y) fn = inplace_func([x,y], x < y)
l = numpy.asarray([0.,-1.,1.]) l = numpy.asarray([0.,-1.,1.], dtype='float32')
r = numpy.asarray([0.,1.,-1.]) r = numpy.asarray([0.,1.,-1.], dtype='float32')
v = fn(l, r) v = fn(l, r)
self.failUnless(numpy.all(v == (l < r)), (v, (l<r))) self.failUnless(numpy.all(v == (l < r)), (v, (l<r)))
def test_le(self): def test_le(self):
x, y = fvector(), fvector() x, y = fvector(), fvector()
fn = inplace_func([x,y], x <= y) fn = inplace_func([x,y], x <= y)
l = numpy.asarray([0.,-1.,1.]) l = numpy.asarray([0.,-1.,1.], dtype='float32')
r = numpy.asarray([0.,1.,-1.]) r = numpy.asarray([0.,1.,-1.], dtype='float32')
v = fn(l, r) v = fn(l, r)
self.failUnless(numpy.all(v == (l <= r)), (v, (l<=r))) self.failUnless(numpy.all(v == (l <= r)), (v, (l<=r)))
def test_ge(self): def test_ge(self):
x, y = fvector(), fvector() x, y = fvector(), fvector()
fn = inplace_func([x,y], x >= y) fn = inplace_func([x,y], x >= y)
l = numpy.asarray([0.,-1.,1.]) l = numpy.asarray([0.,-1.,1.], dtype='float32')
r = numpy.asarray([0.,1.,-1.]) r = numpy.asarray([0.,1.,-1.], dtype='float32')
v = fn(l, r) v = fn(l, r)
self.failUnless(numpy.all(v == (l >= r)), (v, (l>=r))) self.failUnless(numpy.all(v == (l >= r)), (v, (l>=r)))
def test_eq(self): def test_eq(self):
x, y = fvector(), fvector() x, y = fvector(), fvector()
fn = inplace_func([x,y], eq(x,y)) fn = inplace_func([x,y], eq(x,y))
l = numpy.asarray([0.,-1.,1.]) l = numpy.asarray([0.,-1.,1.], dtype='float32')
r = numpy.asarray([0.,1.,-1.]) r = numpy.asarray([0.,1.,-1.], dtype='float32')
v = fn(l, r) v = fn(l, r)
self.failUnless(numpy.all(v == (l == r)), (v, (l==r))) self.failUnless(numpy.all(v == (l == r)), (v, (l==r)))
def test_neq(self): def test_neq(self):
x, y = fvector(), fvector() x, y = fvector(), fvector()
fn = inplace_func([x,y], neq(x, y)) fn = inplace_func([x,y], neq(x, y))
l = numpy.asarray([0.,-1.,1.]) l = numpy.asarray([0.,-1.,1.], dtype='float32')
r = numpy.asarray([0.,1.,-1.]) r = numpy.asarray([0.,1.,-1.], dtype='float32')
v = fn(l, r) v = fn(l, r)
self.failUnless(numpy.all(v == (l != r)), (v, (l!=r))) self.failUnless(numpy.all(v == (l != r)), (v, (l!=r)))
...@@ -2607,30 +2607,32 @@ class TestARange(unittest.TestCase): ...@@ -2607,30 +2607,32 @@ class TestARange(unittest.TestCase):
assert numpy.all(f(0,0,1) == numpy.arange(0,0,1)) assert numpy.all(f(0,0,1) == numpy.arange(0,0,1))
def test_float32(self): def test_float32(self):
"""Test arange constructor, on integer outputs""" """Test arange constructor, on float32 outputs"""
start, stop, step = fscalars('start', 'stop', 'step') start, stop, step = fscalars('start', 'stop', 'step')
out = arange(start, stop, step) out = arange(start, stop, step)
f = function([start, stop, step], out) f = function([start, stop, step], out)
assert out.dtype == start.type.dtype assert out.dtype == start.type.dtype
assert numpy.all(f(0,5,1) == numpy.arange(0,5,1, dtype=start.type.dtype)) arg_vals = [ (0,5,1), (2,11,4), (-5,1.1,1.2), (1.3,2,-2.1), (10,2,2) ]
assert numpy.all(f(2,11,4) == numpy.arange(2,11,4, dtype=start.type.dtype)) for arg_v in arg_vals:
assert numpy.all(f(-5,1.1,1.2) == numpy.arange(-5,1.1,1.2, dtype=start.type.dtype)) start_v, stop_v, step_v = arg_v
assert numpy.all(f(1.3,2,-2.1) == numpy.arange(1.3,2,-2.1, dtype=start.type.dtype)) start_v_, stop_v_, step_v_ = numpy.asarray(arg_v, dtype=start.type.dtype)
assert numpy.all(f(10,2,2) == numpy.arange(10,2,2, dtype=start.type.dtype)) assert numpy.all(f(start_v_, stop_v_, step_v_) == \
numpy.arange(start_v, stop_v, step_v, dtype=start.type.dtype))
def test_float64(self): def test_float64(self):
"""Test arange constructor, on integer outputs""" """Test arange constructor, on float64 outputs"""
start, stop, step = dscalars('start', 'stop', 'step') start, stop, step = dscalars('start', 'stop', 'step')
out = arange(start, stop, step) out = arange(start, stop, step)
f = function([start, stop, step], out) f = function([start, stop, step], out)
assert out.dtype == start.type.dtype assert out.dtype == start.type.dtype
assert numpy.all(f(0,5,1) == numpy.arange(0,5,1, dtype=start.type.dtype)) arg_vals = [ (0,5,1), (2,11,4), (-5,1.1,1.2), (1.3,2,-2.1), (10,2,2) ]
assert numpy.all(f(2,11,4) == numpy.arange(2,11,4, dtype=start.type.dtype)) for arg_v in arg_vals:
assert numpy.all(f(-5,1.1,1.2) == numpy.arange(-5,1.1,1.2, dtype=start.type.dtype)) start_v, stop_v, step_v = arg_v
assert numpy.all(f(1.3,2,-2.1) == numpy.arange(1.3,2,-2.1, dtype=start.type.dtype)) start_v_, stop_v_, step_v_ = numpy.asarray(arg_v, dtype=start.type.dtype)
assert numpy.all(f(10,2,2) == numpy.arange(10,2,2, dtype=start.type.dtype)) assert numpy.all(f(start_v_, stop_v_, step_v_) == \
numpy.arange(start_v, stop_v, step_v, dtype=start.type.dtype))
def test_default_step(self): def test_default_step(self):
"""Test that arange constructor uses the correct default step""" """Test that arange constructor uses the correct default step"""
...@@ -2669,9 +2671,10 @@ class TestARange(unittest.TestCase): ...@@ -2669,9 +2671,10 @@ class TestARange(unittest.TestCase):
ff = function([fstop], fout) ff = function([fstop], fout)
assert fout.dtype == fstop.type.dtype assert fout.dtype == fstop.type.dtype
assert numpy.all(ff(0.2) == numpy.arange(0.2)) fstop_values = [0.2, -0.7, 8.5]
assert numpy.all(ff(-0.7) == numpy.arange(-0.7)) for fstop_v in fstop_values:
assert numpy.all(ff(8.5) == numpy.arange(8.5)) fstop_v32 = numpy.float32(fstop_v)
assert numpy.all(ff(fstop_v32) == numpy.arange(fstop_v))
def test_upcast(self): def test_upcast(self):
"""Test that arange compute output type adequately""" """Test that arange compute output type adequately"""
...@@ -2756,7 +2759,7 @@ class TestInversePermutation(unittest.TestCase): ...@@ -2756,7 +2759,7 @@ class TestInversePermutation(unittest.TestCase):
# Generate a random permutation # Generate a random permutation
rng = numpy.random.RandomState(utt.fetch_seed()) rng = numpy.random.RandomState(utt.fetch_seed())
p_val = rng.permutation(10) p_val = rng.permutation(10).astype('int32')
inv_val = f_inverse(p_val) inv_val = f_inverse(p_val)
# Check that the inverse of the inverse is the original permutation # Check that the inverse of the inverse is the original permutation
...@@ -2774,7 +2777,8 @@ class TestInversePermutation(unittest.TestCase): ...@@ -2774,7 +2777,8 @@ class TestInversePermutation(unittest.TestCase):
rng = numpy.random.RandomState(utt.fetch_seed()) rng = numpy.random.RandomState(utt.fetch_seed())
# Generate 10 random permutations # Generate 10 random permutations
p_val = numpy.asarray([rng.permutation(10) for i in range(7)]) p_val = numpy.asarray([rng.permutation(10) for i in range(7)],
dtype='int32')
inv_val = f_inverse(p_val) inv_val = f_inverse(p_val)
# Check that the inverse of the inverse is the original permutation list # Check that the inverse of the inverse is the original permutation list
...@@ -2799,7 +2803,7 @@ class TestPermuteRowElements(unittest.TestCase): ...@@ -2799,7 +2803,7 @@ class TestPermuteRowElements(unittest.TestCase):
rng = numpy.random.RandomState(utt.fetch_seed()) rng = numpy.random.RandomState(utt.fetch_seed())
input_val = rng.uniform(size=(5,)) input_val = rng.uniform(size=(5,))
p_val = rng.permutation(5) p_val = rng.permutation(5).astype('int32')
out_val = permute(input_val, p_val) out_val = permute(input_val, p_val)
# Should be equivalent to advanced indexing # Should be equivalent to advanced indexing
...@@ -2821,7 +2825,7 @@ class TestPermuteRowElements(unittest.TestCase): ...@@ -2821,7 +2825,7 @@ class TestPermuteRowElements(unittest.TestCase):
rng = numpy.random.RandomState(utt.fetch_seed()) rng = numpy.random.RandomState(utt.fetch_seed())
input_val = rng.uniform(size=(3,5)) input_val = rng.uniform(size=(3,5))
p_val = rng.permutation(5) p_val = rng.permutation(5).astype('int32')
out_val = permute(input_val, p_val) out_val = permute(input_val, p_val)
# The same permutation should be applied to every row of the input matrix. # The same permutation should be applied to every row of the input matrix.
...@@ -2843,7 +2847,8 @@ class TestPermuteRowElements(unittest.TestCase): ...@@ -2843,7 +2847,8 @@ class TestPermuteRowElements(unittest.TestCase):
rng = numpy.random.RandomState(utt.fetch_seed()) rng = numpy.random.RandomState(utt.fetch_seed())
input_val = rng.uniform(size=(3,5)) input_val = rng.uniform(size=(3,5))
p_val = numpy.asarray([rng.permutation(5) for i in range(3)]) p_val = numpy.asarray([rng.permutation(5) for i in range(3)],
dtype='int32')
out_val = permute(input_val, p_val) out_val = permute(input_val, p_val)
# Each row of p contains a permutation to apply to the corresponding # Each row of p contains a permutation to apply to the corresponding
...@@ -2867,7 +2872,7 @@ class TestPermuteRowElements(unittest.TestCase): ...@@ -2867,7 +2872,7 @@ class TestPermuteRowElements(unittest.TestCase):
rng = numpy.random.RandomState(utt.fetch_seed()) rng = numpy.random.RandomState(utt.fetch_seed())
input_val = rng.uniform(size=(5,)) input_val = rng.uniform(size=(5,))
p_val = numpy.asarray([rng.permutation(5) for i in range(3)]) p_val = numpy.asarray([rng.permutation(5) for i in range(3)], dtype='int32')
out_val = permute(input_val, p_val) out_val = permute(input_val, p_val)
# Each row of p contains a permutation to apply to the input vector # Each row of p contains a permutation to apply to the input vector
...@@ -2892,7 +2897,8 @@ class TestPermuteRowElements(unittest.TestCase): ...@@ -2892,7 +2897,8 @@ class TestPermuteRowElements(unittest.TestCase):
rng = numpy.random.RandomState(utt.fetch_seed()) rng = numpy.random.RandomState(utt.fetch_seed())
input_val = rng.uniform(size=(4,1,5)) input_val = rng.uniform(size=(4,1,5))
p_val = numpy.asarray([rng.permutation(5) for i in range(3)]) p_val = numpy.asarray([rng.permutation(5) for i in range(3)],
dtype='int32')
out_val = permute(input_val, p_val) out_val = permute(input_val, p_val)
# Each row of p contains a permutation to apply to each row # Each row of p contains a permutation to apply to each row
...@@ -3039,7 +3045,7 @@ class test_tensordot(unittest.TestCase): ...@@ -3039,7 +3045,7 @@ class test_tensordot(unittest.TestCase):
amat = fmatrix() amat = fmatrix()
bmat = dmatrix()#we let at float64 to test mix of float32 and float64. bmat = dmatrix()#we let at float64 to test mix of float32 and float64.
axes = 1 axes = 1
aval = self.rand(4,5) aval = self.rand(4,5).astype('float32')
bval = numpy.random.rand(5,3) bval = numpy.random.rand(5,3)
c = tensordot(amat, bmat, axes) c = tensordot(amat, bmat, axes)
f3 = inplace_func([amat,bmat],c) f3 = inplace_func([amat,bmat],c)
......
...@@ -23,7 +23,7 @@ class TestRealImag(unittest.TestCase): ...@@ -23,7 +23,7 @@ class TestRealImag(unittest.TestCase):
x= imatrix() x= imatrix()
xval = numpy.asarray(rng.randn(3,3)*100, dtype='int') xval = numpy.asarray(rng.randn(3,3)*100, dtype='int32')
numpy.all( 0 == theano.function([x], imag(x))(xval)) numpy.all( 0 == theano.function([x], imag(x))(xval))
numpy.all( xval == theano.function([x], real(x))(xval)) numpy.all( xval == theano.function([x], real(x))(xval))
......
...@@ -12,7 +12,7 @@ def test_no_reuse(): ...@@ -12,7 +12,7 @@ def test_no_reuse():
f = theano.function([x, y], x + y) f = theano.function([x, y], x + y)
#provide both inputs in the first call #provide both inputs in the first call
f(numpy.ones(10), numpy.ones(10)) f(numpy.ones(10, dtype='int64'), numpy.ones(10, dtype='int64'))
try: try:
f(numpy.ones(10)) f(numpy.ones(10))
......
...@@ -10,7 +10,7 @@ def test_bug_2009_06_02_trac_387(): ...@@ -10,7 +10,7 @@ def test_bug_2009_06_02_trac_387():
#f = theano.function([y], tensor.join(0,tensor.shape_padleft(y[0] / 2,1))) #f = theano.function([y], tensor.join(0,tensor.shape_padleft(y[0] / 2,1)))
f = theano.function([y], tensor.int_div(tensor.DimShuffle(y[0].broadcastable, ['x'])(y[0]), 2)) f = theano.function([y], tensor.int_div(tensor.DimShuffle(y[0].broadcastable, ['x'])(y[0]), 2))
sys.stdout.flush() sys.stdout.flush()
print f(numpy.ones(1) * 3) print f(numpy.ones(1, dtype='int64') * 3)
#z = tensor.lscalar('z') #z = tensor.lscalar('z')
#f = theano.function([z], tensor.DimShuffle([], ['x'])(z) / 2) #f = theano.function([z], tensor.DimShuffle([], ['x'])(z) / 2)
......
...@@ -2094,6 +2094,6 @@ def test_local_mul_to_neg(): ...@@ -2094,6 +2094,6 @@ def test_local_mul_to_neg():
a = T.imatrix() a = T.imatrix()
f1 = theano.function([a], -1*a) f1 = theano.function([a], -1*a)
f2 = theano.function([a], -1.0*a) f2 = theano.function([a], -1.0*a)
aval = numpy.random.randint(0,10,(2,2)) aval = numpy.random.randint(0,10,(2,2)).astype('int32')
assert f1(aval).dtype == a.dtype assert f1(aval).dtype == a.dtype
assert f2(aval).dtype == 'float64' assert f2(aval).dtype == 'float64'
...@@ -581,8 +581,8 @@ class T_RandomStreams(unittest.TestCase): ...@@ -581,8 +581,8 @@ class T_RandomStreams(unittest.TestCase):
made = m.make() made = m.make()
made.random.initialize() made.random.initialize()
low_val = [.1, .2, .3] low_val = [100, 200, 300]
high_val = [1.1, 2.2, 3.3] high_val = [110, 220, 330]
seed_gen = numpy.random.RandomState(utt.fetch_seed()) seed_gen = numpy.random.RandomState(utt.fetch_seed())
numpy_rng = numpy.random.RandomState(int(seed_gen.randint(2**30))) numpy_rng = numpy.random.RandomState(int(seed_gen.randint(2**30)))
......
...@@ -665,8 +665,8 @@ class T_random_function(unittest.TestCase): ...@@ -665,8 +665,8 @@ class T_random_function(unittest.TestCase):
assert out.ndim == 1 assert out.ndim == 1
f = compile.function([rng_R, low, high], [post_r, out], accept_inplace=True) f = compile.function([rng_R, low, high], [post_r, out], accept_inplace=True)
low_val = [.1, .2, .3] low_val = [100, 200, 300]
high_val = [1.1, 2.2, 3.3] high_val = [110, 220, 330]
rng = numpy.random.RandomState(utt.fetch_seed()) rng = numpy.random.RandomState(utt.fetch_seed())
numpy_rng = numpy.random.RandomState(utt.fetch_seed()) numpy_rng = numpy.random.RandomState(utt.fetch_seed())
......
...@@ -527,8 +527,8 @@ class T_SharedRandomStreams(unittest.TestCase): ...@@ -527,8 +527,8 @@ class T_SharedRandomStreams(unittest.TestCase):
assert out.ndim == 1 assert out.ndim == 1
f = function([low, high], out) f = function([low, high], out)
low_val = [.1, .2, .3] low_val = [100, 200, 300]
high_val = [1.1, 2.2, 3.3] high_val = [110, 220, 330]
seed_gen = numpy.random.RandomState(utt.fetch_seed()) seed_gen = numpy.random.RandomState(utt.fetch_seed())
numpy_rng = numpy.random.RandomState(int(seed_gen.randint(2**30))) numpy_rng = numpy.random.RandomState(int(seed_gen.randint(2**30)))
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论