Beispiel #1
0
	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)
Beispiel #2
0
	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)
Beispiel #3
0
	def testHighOrderBack(self):

		# Psi^2 or ^3 has infinite numbers of harmonics, but we still can count on
		# certain precision of restored function.
		eps = 0.1

		print "\nChecking that F^-1[F[Psi^l]] ~ Psi^l:"
		for order in (2, 3):
			for N in (5, 6, 7, 40, 60):
				f = TestFunction(self.env, N, order, coefficients=[1] + [0] * N)
				p = createFHTPlan(self.env, N, order)

				C = p.execute(f.data)
				f_back = p.execute(C, inverse=True)
				d = f.test(f_back)

				if N == 40 or N == 60:
					print "N = {N}, order = {l}, diff = {d}".format(N=N, l=order, d=d)
				else:
					self.assert_(d < eps)
Beispiel #4
0
	def testOrder1(self):

		eps = 1e-11

		print "\nChecking that harmonic decomposition gives right coefficients:"

		for N in (1, 3, 5, 40, 60):
			f = TestFunction(self.env, N, 1)
			plan = createFHTPlan(self.env, (N,), 1)

			C = plan.execute(f.data)
			d_fw = f.test_coeffs(C)

			if not (N == 40 or N == 60):
				self.assert_(d_fw < eps)

			f_back = plan.execute(C, inverse=True)
			d_back = f.test(f_back)

			if N == 40 or N == 60:
				print "N = {N}, diff forward = {d_fw}, diff back = {d_back}".format(
					N=N, d_fw=d_fw, d_back=d_back)
			else:
				self.assert_(d_back < eps)