def test_3d_decimate_active(self): shape = self.shape3D known_data = np.random.normal(size=shape).astype(np.float32).view( np.complex64) idata = bf.ndarray(known_data, space='cuda') odata = bf.empty((idata.shape[0] // 2, idata.shape[1], idata.shape[2]), dtype=idata.dtype, space='cuda') coeffs = self.coeffs * 1.0 coeffs.shape += (1, ) coeffs = np.repeat(coeffs, idata.shape[1] * idata.shape[2], axis=1) coeffs.shape = (coeffs.shape[0], idata.shape[1], idata.shape[2]) coeffs = bf.ndarray(coeffs, space='cuda') fir = Fir() fir.init(coeffs, 2) fir.execute(idata, odata) fir.execute(idata, odata) odata = odata.copy('system') for i in range(known_data.shape[1]): for j in range(known_data.shape[2]): zf = lfiltic(self.coeffs, 1.0, 0.0) known_result, zf = lfilter(self.coeffs, 1.0, known_data[:, i, j], zi=zf) known_result, zf = lfilter(self.coeffs, 1.0, known_data[:, i, j], zi=zf) known_result = known_result[0::2] compare(odata[:, i, j], known_result)
def test_explicit_indexing(self): shape = (55, 66, 77) a = np.random.randint(65536, size=shape).astype(np.int32) a = bf.asarray(a, space='cuda') b = bf.empty((a.shape[2], a.shape[0], a.shape[1]), a.dtype, 'cuda') bf.map("b(i,j,k) = a(j,k,i)", b.shape, 'i', 'j', 'k', a=a, b=b) a = a.copy('system') b = b.copy('system') np.testing.assert_equal(b, a.transpose([2, 0, 1]))
def test_custom_shape(self): shape = (55, 66, 77) a = np.random.randint(65536, size=shape).astype(np.int32) a = bf.asarray(a, space='cuda') b = bf.empty((a.shape[0], a.shape[2]), a.dtype, 'cuda') j = 11 bf.map("b(i,k) = a(i,j,k)", b.shape, 'i', 'k', a=a, b=b, j=j) a = a.copy('system') b = b.copy('system') np.testing.assert_equal(b, a[:, j, :])
def test_explicit_indexing(self): shape = (55,66,77) a = np.random.randint(65536, size=shape).astype(np.int32) a = bf.asarray(a, space='cuda') b = bf.empty((a.shape[2],a.shape[0], a.shape[1]), a.dtype, 'cuda') for _ in xrange(3): bf.map("b(i,j,k) = a(j,k,i)", shape=b.shape, axis_names=('i','j','k'), data={'a': a, 'b': b}, block_shape=(64,4), block_axes=('i','k')) a = a.copy('system') b = b.copy('system') np.testing.assert_equal(b, a.transpose([2,0,1]))
def test_broadcast(self): n = 89 a = np.arange(n).astype(np.float32) a = bf.asarray(a, space='cuda') b = a[:, None] c = bf.empty((a.shape[0], b.shape[0]), a.dtype, 'cuda') # TODO: Need way to compute broadcast shape bf.map("c = a*b", a=a, b=b, c=c) a = a.copy('system') b = b.copy('system') c = c.copy('system') np.testing.assert_equal(c, a * b)
def test_custom_shape(self): shape = (55,66,77) a = np.random.randint(65536, size=shape).astype(np.int32) a = bf.asarray(a, space='cuda') b = bf.empty((a.shape[0],a.shape[2]), a.dtype, 'cuda') j = 11 for _ in xrange(3): bf.map("b(i,k) = a(i,j,k)", shape=b.shape, axis_names=('i','k'), data={'a': a, 'b': b, 'j': j}) a = a.copy('system') b = b.copy('system') np.testing.assert_equal(b, a[:,j,:])