def test_eval_U_grid1(self): log = logging.getLogger('TestCPsf.test_eval_U_grid1') enz = CPsf(8) r_sp = float(abs(normal(size=1, ))[0]) ph_sp = float(normal(size=1, )[0]) f_sp = float(normal(size=1, )[0]) enz.make_pol_grid([r_sp], [ph_sp], [f_sp]) beta = normal(size=enz.czern.nk) + 1j * normal(size=enz.czern.nk) a = enz.eval_grid(beta, 0, 0, 0) b = enz.U(beta, r_sp, ph_sp, f_sp) log.debug('r = {:e}, ph = {:e}, f = {:e}'.format(r_sp, ph_sp, f_sp)) log.debug('a {:s} {}'.format(str(type(a)), a)) log.debug('b {:s} {}'.format(str(type(b)), b)) log.debug('{}'.format(abs(a - b))) self.assertTrue(abs(a - b) < self.max_enorm)
def test_eval_U_grid2(self): log = logging.getLogger('TestCPsf.test_eval_U_grid2') enz = CPsf(8) L, K, P = 50, 70, 3 A = L * K * P r_sp = np.linspace(.01, 2, L) ph_sp = [2 * math.pi * i / L for i in range(K)] f_sp = [normal(size=1, ) for i in range(P)] t1 = time() enz.make_pol_grid(r_sp, ph_sp, f_sp) t2 = time() log.debug('make_pol_grid {:.6f}'.format(t2 - t1)) self.assertTrue(enz.Ugrid.size == A * enz.czern.nk) beta = normal(size=enz.czern.nk) + 1j * normal(size=enz.czern.nk) T1 = np.zeros((L, K, P), order='F', dtype=np.complex) self.assertTrue(r_sp.size == L) self.assertTrue(len(ph_sp) == K) self.assertTrue(len(f_sp) == P) self.assertTrue(T1.size == L * K * P) log.debug(r_sp.size) t1 = time() for i, r in enumerate(r_sp): for j, ph in enumerate(ph_sp): for k, f in enumerate(f_sp): T1[i, j, k] = enz.U(beta, r, ph, f) t2 = time() log.debug('scalar {:.6f}'.format(t2 - t1)) t1 = time() T2 = np.dot(enz.Ugrid, beta) t2 = time() log.debug('vect {:.6f}'.format(t2 - t1)) log.debug(enz.Ugrid.flags) self.assertTrue(norm(T1.ravel() - T2.ravel()) < self.max_enorm)