def testBatch(self): eps = 1e-14 N = (2, 3, 4) coeffs = numpy.arange(N[0] * N[1] * N[2] * 2).reshape(2, N[0] * N[1] * N[2]) fa = TestFunction(N, 1, coefficients=coeffs[0, :]) fb = TestFunction(N, 1, coefficients=coeffs[1, :]) p = FHT3D(N, 1) f2 = numpy.concatenate([fa(p.grid_x, p.grid_y, p.grid_z), fb(p.grid_x, p.grid_y, p.grid_z)]) C = p.execute(f2, batch=2) self.assert_(C.shape == tuple([2] + list(N))) self.assert_(diff(C, coeffs.reshape(C.shape)) < eps) f_back = p.execute(C, batch=2, inverse=True) self.assert_(f_back.shape == (2, len(p.grid_z), len(p.grid_y), len(p.grid_x))) self.assert_(diff(f_back, f2.reshape(f_back.shape)) < eps)
def testBatch(self): eps = 1e-14 N = 5 coeffs = numpy.arange(N * 2).reshape(2, N) fa = TestFunction(self.env, N, 1, coefficients=coeffs[0, :]) fb = TestFunction(self.env, N, 1, coefficients=coeffs[1, :]) p = createFHTPlan(self.env, N, 1) f2 = self.env.toDevice(numpy.concatenate( [self.env.fromDevice(fa.data), self.env.fromDevice(fb.data)])) C = p.execute(f2, batch=2) self.assert_(C.shape == coeffs.shape) self.assert_(diff(self.env.fromDevice(C), coeffs) < eps) f_back = p.execute(C, batch=2, inverse=True) self.assert_(f_back.shape == (2, len(p.grid_x))) self.assert_(diff(self.env.fromDevice(f_back), self.env.fromDevice(f2).reshape(f_back.shape)) < eps)
def testHighOrderForward(self): eps = 1e-10 for order in (2, 3): for N in ((1, 1, 1), (2, 3, 4), (5, 6, 7)): for i in xrange(3): f = TestFunction(N, order) big_N = tuple(x + 1 for x in N) p1 = FHT3D(N, order) p2 = FHT3D(big_N, order) C1 = p1.execute(f(p1.grid_x, p1.grid_y, p1.grid_z)) C2 = p2.execute(f(p2.grid_x, p2.grid_y, p2.grid_z)) # check that decomposition with N + 1 modes has the same 0 .. N modes self.assert_(diff(C1, C2[0,:-1,:-1,:-1]) < eps)
def testHighOrderForward(self): eps = 1e-11 print "\nChecking that with increased number of modes previous terms do not change" for order in (2, 3): print "Order: " + str(order) for N in (20, 40, 60): f1 = TestFunction(self.env, N, order) f2 = TestFunction(self.env, N + 1, order) p1 = createFHTPlan(self.env, N, order) p2 = createFHTPlan(self.env, N + 1, order) C1 = p1.execute(f1.data) C2 = p2.execute(f2.data) d = diff(self.env.fromDevice(C1).reshape(N), self.env.fromDevice(C2).reshape(N + 1)[:-1]) print "N = {N}, diff = {d}".format(N=N, d=d)
def test_coeffs(self, C): return diff(self.env.fromDevice(C).reshape(self.coefficients.shape), self.coefficients)
def test(self, results): return diff(self.env.fromDevice(self.data), self.env.fromDevice(results).reshape(self.data.shape))