def test_infer_shape(self): for ndim in range(4): x = T.TensorType(config.floatX, [False] * ndim)() shp = (numpy.arange(ndim) + 1) * 5 a = np.random.random(shp).astype(config.floatX) for axis in self._possible_axis(ndim): for dtype in tensor.discrete_dtypes: r_var = T.scalar(dtype=dtype) r = numpy.asarray(3, dtype=dtype) if dtype in self.numpy_unsupported_dtypes: self.assertRaises(TypeError, repeat, x, r_var) else: self._compile_and_check( [x, r_var], [RepeatOp(axis=axis)(x, r_var)], [a, r], self.op_class) r_var = T.vector(dtype=dtype) if axis is None: r = np.random.random_integers( 5, size=a.size).astype(dtype) elif a.size > 0: r = np.random.random_integers( 5, size=a.shape[axis]).astype(dtype) else: r = np.random.random_integers( 5, size=(10, )).astype(dtype) self._compile_and_check( [x, r_var], [RepeatOp(axis=axis)(x, r_var)], [a, r], self.op_class)
def test_broadcastable(self): x = T.TensorType(config.floatX, [False, True, False])() r = RepeatOp(axis=1)(x, 2) self.assertEqual(r.broadcastable, (False, False, False)) r = RepeatOp(axis=1)(x, 1) self.assertEqual(r.broadcastable, (False, True, False)) r = RepeatOp(axis=0)(x, 2) self.assertEqual(r.broadcastable, (False, True, False))
def test_broadcastable(self): x = T.TensorType(config.floatX, [False, True, False])() r = RepeatOp(axis=1)(x, 2) assert r.broadcastable == (False, False, False) r = RepeatOp(axis=1)(x, 1) assert r.broadcastable == (False, True, False) r = RepeatOp(axis=0)(x, 2) assert r.broadcastable == (False, True, False)
def setup_method(self): super().setup_method() self.op_class = RepeatOp self.op = RepeatOp() # uint64 always fails # int64 and uint32 also fail if python int are 32-bit if LOCAL_BITWIDTH == 64: self.numpy_unsupported_dtypes = ("uint64",) if LOCAL_BITWIDTH == 32: self.numpy_unsupported_dtypes = ("uint32", "int64", "uint64")
def setUp(self): super(TestRepeatOp, self).setUp() self.op_class = RepeatOp self.op = RepeatOp() # uint64 always fails # int64 and uint32 also fail if python int are 32-bit ptr_bitwidth = theano.gof.local_bitwidth() if ptr_bitwidth == 64: self.numpy_unsupported_dtypes = ('uint64', ) if ptr_bitwidth == 32: self.numpy_unsupported_dtypes = ('uint32', 'int64', 'uint64')
def setup_method(self): super().setup_method() self.op_class = RepeatOp self.op = RepeatOp() # uint64 always fails # int64 and uint32 also fail if python int are 32-bit ptr_bitwidth = theano.configdefaults.local_bitwidth() if ptr_bitwidth == 64: self.numpy_unsupported_dtypes = ("uint64", ) if ptr_bitwidth == 32: self.numpy_unsupported_dtypes = ("uint32", "int64", "uint64")
def test_infer_shape(self): for ndim in [1, 3]: x = T.TensorType(config.floatX, [False] * ndim)() shp = (np.arange(ndim) + 1) * 3 a = np.random.random(shp).astype(config.floatX) for axis in self._possible_axis(ndim): for dtype in ["int8", "uint8", "uint64"]: r_var = T.scalar(dtype=dtype) r = np.asarray(3, dtype=dtype) if dtype in self.numpy_unsupported_dtypes: r_var = T.vector(dtype=dtype) with pytest.raises(TypeError): repeat(x, r_var) else: self._compile_and_check( [x, r_var], [RepeatOp(axis=axis)(x, r_var)], [a, r], self.op_class, ) r_var = T.vector(dtype=dtype) if axis is None: r = np.random.randint(1, 6, size=a.size).astype(dtype) elif a.size > 0: r = np.random.randint( 1, 6, size=a.shape[axis]).astype(dtype) else: r = np.random.randint(1, 6, size=(10, )).astype(dtype) self._compile_and_check( [x, r_var], [RepeatOp(axis=axis)(x, r_var)], [a, r], self.op_class, )
def test_grad(self): for ndim in range(3): a = np.random.random((10, ) * ndim).astype(config.floatX) for axis in self._possible_axis(ndim): utt.verify_grad(lambda x: RepeatOp(axis=axis)(x, 3), [a])