提交 0dbb97c6 authored 作者: Arnaud Bergeron's avatar Arnaud Bergeron

Fix the elemwise tests to respect floatX.

上级 c9b28cc2
......@@ -166,10 +166,12 @@ class test_Broadcast(unittest.TestCase):
linkers = [gof.PerformLinker, gof.CLinker]
def rand_val(self, shp):
return numpy.asarray(numpy.random.rand(*shp), dtype='float32')
return numpy.asarray(numpy.random.rand(*shp),
dtype=theano.config.floatX)
def rand_cval(self, shp):
return numpy.asarray(numpy.random.rand(*shp), dtype='float32')
return numpy.asarray(numpy.random.rand(*shp),
dtype=theano.config.floatX)
def setUp(self):
unittest_tools.seed_rng()
......@@ -189,8 +191,10 @@ class test_Broadcast(unittest.TestCase):
((2, 3, 4, 5), (1, 3, 1, 5)),
((2, 3, 4, 5), (1, 1, 1, 1)),
((), ())]:
x = type('float32', [(entry == 1) for entry in xsh])('x')
y = type('float32', [(entry == 1) for entry in ysh])('y')
x = type(theano.config.floatX,
[(entry == 1) for entry in xsh])('x')
y = type(theano.config.floatX,
[(entry == 1) for entry in ysh])('y')
e = op(scalar.add)(x, y)
f = copy(linker).accept(FunctionGraph([x, y], [e])).make_function()
xv = rand_val(xsh)
......@@ -202,8 +206,10 @@ class test_Broadcast(unittest.TestCase):
# test Elemwise.infer_shape
# the Shape op don't implement c_code!
if isinstance(linker, gof.PerformLinker):
x = type('float32', [(entry == 1) for entry in xsh])('x')
y = type('float32', [(entry == 1) for entry in ysh])('y')
x = type(theano.config.floatX,
[(entry == 1) for entry in xsh])('x')
y = type(theano.config.floatX,
[(entry == 1) for entry in ysh])('y')
e = op(scalar.add)(x, y)
f = copy(linker).accept(FunctionGraph(
[x, y], [e.shape])).make_function()
......@@ -218,8 +224,10 @@ class test_Broadcast(unittest.TestCase):
((2, 3, 4, 5), (1, 3, 1, 5)),
((2, 3, 4, 5), (1, 1, 1, 1)),
((), ())]:
x = type('float32', [(entry == 1) for entry in xsh])('x')
y = type('float32', [(entry == 1) for entry in ysh])('y')
x = type(theano.config.floatX,
[(entry == 1) for entry in xsh])('x')
y = type(theano.config.floatX,
[(entry == 1) for entry in ysh])('y')
e = op(scalar.Add(scalar.transfer_type(0)), {0: 0})(x, y)
f = copy(linker).accept(FunctionGraph([x, y], [e])).make_function()
xv = rand_val(xsh)
......@@ -232,8 +240,10 @@ class test_Broadcast(unittest.TestCase):
# test Elemwise.infer_shape
# the Shape op don't implement c_code!
if isinstance(linker, gof.PerformLinker):
x = type('float32', [(entry == 1) for entry in xsh])('x')
y = type('float32', [(entry == 1) for entry in ysh])('y')
x = type(theano.config.floatX,
[(entry == 1) for entry in xsh])('x')
y = type(theano.config.floatX,
[(entry == 1) for entry in ysh])('y')
e = op(scalar.Add(scalar.transfer_type(0)), {0: 0})(x, y)
f = copy(linker).accept(FunctionGraph(
[x, y], [e.shape])).make_function()
......@@ -270,8 +280,8 @@ class test_Broadcast(unittest.TestCase):
for linker, op, t, rval in zip(self.linkers, [self.op, self.cop],
[self.type, self.ctype],
[self.rand_val, self.rand_cval]):
x = t('float32', [0, 0])('x')
y = t('float32', [1, 1])('y')
x = t(theano.config.floatX, [0, 0])('x')
y = t(theano.config.floatX, [1, 1])('y')
e = op(scalar.Second(scalar.transfer_type(0)), {0: 0})(x, y)
f = linker().accept(FunctionGraph([x, y], [e])).make_function()
xv = rval((5, 5))
......@@ -297,8 +307,8 @@ class test_Broadcast(unittest.TestCase):
for linker, op, t, rval in zip(self.linkers, [self.op, self.cop],
[self.type, self.ctype],
[self.rand_val, self.rand_cval]):
x = t('float32', [0, 0, 0, 0, 0])('x')
y = t('float32', [0, 0, 0, 0, 0])('y')
x = t(theano.config.floatX, [0, 0, 0, 0, 0])('x')
y = t(theano.config.floatX, [0, 0, 0, 0, 0])('y')
e = op(scalar.add)(x, y)
f = linker().accept(FunctionGraph([x, y], [e])).make_function()
xv = rval((2, 2, 2, 2, 2))
......@@ -312,7 +322,7 @@ class test_Broadcast(unittest.TestCase):
for linker, op, t, rval in zip(self.linkers, [self.op, self.cop],
[self.type, self.ctype],
[self.rand_val, self.rand_cval]):
x = t('float32', [0, 0])('x')
x = t(theano.config.floatX, [0, 0])('x')
e = op(scalar.add)(x, x)
f = linker().accept(FunctionGraph([x], [e])).make_function()
xv = rval((2, 2))
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论