提交 1e141e5c authored 作者: Frederic's avatar Frederic 提交者: Marc-Alexandre Cote

Force float32 tests and use the mode for gpucumsum tests

上级 14713c9d
......@@ -23,7 +23,6 @@ from theano.tensor.extra_ops import cumsum
class TestGpuCumsum(theano.tensor.tests.test_extra_ops.TestCumsumOp):
mode = mode_with_gpu
op = GpuCumsum
dtypes = ['float32']
def setUp(self):
super(TestGpuCumsum, self).setUp()
......@@ -45,49 +44,49 @@ class TestGpuCumsum(theano.tensor.tests.test_extra_ops.TestCumsumOp):
self.max_grid_size1 = prop['maxGridSize1']
def test_Strides1D(self):
x = T.vector('x')
x = T.fvector('x')
# Stepped strides
f = theano.function([x], cumsum(x[::2]))
a = np.random.randint(10, size=(42,)).astype(config.floatX)
f = theano.function([x], cumsum(x[::2]), mode=self.mode)
a = np.random.randint(10, size=(42,)).astype("float32")
assert np.allclose(np.cumsum(a[::2]), f(a))
# Negative strides
f = theano.function([x], cumsum(x[::-1]))
a = np.random.randint(10, size=(42,)).astype(config.floatX)
f = theano.function([x], cumsum(x[::-1]), mode=self.mode)
a = np.random.randint(10, size=(42,)).astype("float32")
assert np.allclose(np.cumsum(a[::-1]), f(a))
def test_GpuCumsum1D(self):
block_max_size = self.max_threads_dim0 * 2
x = T.vector('x')
f = theano.function([x], cumsum(x))
x = T.fvector('x')
f = theano.function([x], cumsum(x), mode=self.mode)
# Extensive testing for the first 1k sizes
a = np.ones((int(1e3),), dtype=config.floatX)
a = np.ones((int(1e3),), dtype="float32")
for i in xrange(a.shape[0]):
assert np.allclose(np.cumsum(a[:i]), f(a[:i]))
# Use multiple GPU threadblocks
a = np.random.random((block_max_size+2,)).astype(config.floatX)
a = np.random.random((block_max_size+2,)).astype("float32")
assert np.allclose(np.cumsum(a), f(a))
# Use recursive cumsum
a = np.ones((block_max_size*(block_max_size+1)+2,),
dtype=config.floatX)
dtype="float32")
assert np.allclose(np.cumsum(a), f(a))
def test_GpuCumsum2D(self):
block_max_size = self.max_threads_dim0 * 2
x = T.fmatrix('x')
for axis in xrange(2):
x = T.matrix('x')
f = theano.function([x], cumsum(x, axis=axis))
f = theano.function([x], cumsum(x, axis=axis), mode=self.mode)
# Extensive testing for the first 1k sizes
a_shape = [11, 11]
a_shape[axis] = int(1e3)
a = np.ones(a_shape, dtype=config.floatX)
a = np.ones(a_shape, dtype="float32")
slices = [slice(None), slice(None)]
for i in xrange(a.shape[axis]):
slices[axis] = slice(i)
......@@ -98,17 +97,17 @@ class TestGpuCumsum(theano.tensor.tests.test_extra_ops.TestCumsumOp):
# Use multiple GPU threadblocks
a_shape = [11, 11]
a_shape[axis] = block_max_size+2
a = np.ones(a_shape, dtype=config.floatX)
a = np.ones(a_shape, dtype="float32")
assert np.allclose(np.cumsum(a, axis=axis), f(a))
# Use multiple GPU gridblocks
a_shape = [11, 11]
a_shape[1-axis] = self.max_grid_size1+1
a = np.ones(a_shape, dtype=config.floatX)
a = np.ones(a_shape, dtype="float32")
assert np.allclose(np.cumsum(a, axis=axis), f(a))
# Use recursive cumsum
a_shape = [11, 11]
a_shape[axis] = block_max_size*(block_max_size+1)+2
a = np.ones(a_shape, dtype=config.floatX)
a = np.ones(a_shape, dtype="float32")
assert np.allclose(np.cumsum(a, axis=axis), f(a))
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论