Beispiel #1
0
    def test_even(self):
        print('\nChecking Tensors with even grid points...')

        for dim, n, fft_form in itertools.product([2, 3], [4, 5], fft_forms):
            msg = 'Tensors with: dim={}, n={}, fft_form={}'.format(
                dim, n, fft_form)

            N = dim * (n, )
            M = tuple(2 * np.array(N))

            u = Tensor(name='test',
                       shape=(),
                       N=N,
                       Fourier=False,
                       fft_form=fft_form)
            u.randomize()
            Fu = u.fourier(copy=True)
            FuM = Fu.project(M)
            uM = FuM.fourier()

            if n % 2 == 0:
                self.assertGreaterEqual(u.norm(), FuM.norm(), msg=msg)
                self.assertGreaterEqual(u.norm(componentwise=True),
                                        FuM.norm(componentwise=True),
                                        msg=msg)
                self.assertGreaterEqual(u.norm(), uM.norm(), msg=msg)
                self.assertGreaterEqual(u.norm(componentwise=True),
                                        uM.norm(componentwise=True),
                                        msg=msg)
            else:
                self.assertAlmostEqual(u.norm(), FuM.norm(), msg=msg)
                self.assertAlmostEqual(u.norm(componentwise=True),
                                       FuM.norm(componentwise=True),
                                       msg=msg)
                self.assertAlmostEqual(u.norm(), uM.norm(), msg=msg)
                self.assertAlmostEqual(u.norm(componentwise=True),
                                       uM.norm(componentwise=True),
                                       msg=msg)

            self.assertAlmostEqual(0, u.mean() - FuM.mean(), msg=msg)
            self.assertAlmostEqual(u.mean(), uM.mean(), msg=msg)

            # testing that that interpolation on double grid have exactly the same values
            slc = tuple(u.order * [
                slice(None),
            ] + [slice(0, M[i], 2) for i in range(dim)])
            self.assertAlmostEqual(0,
                                   np.linalg.norm(u.val - uM.val[slc]),
                                   msg=msg)
        print('...ok')
Beispiel #2
0
    def test_even(self):
        print('\nChecking Tensors with even grid points...')

        for dim, n, fft_form in itertools.product([2,3], [4,5], fft_forms):
            msg='Tensors with: dim={}, n={}, fft_form={}'.format(dim, n, fft_form)

            N=dim*(n,)
            M=tuple(2*np.array(N))

            u=Tensor(name='test', shape=(), N=N, Fourier=False, fft_form=fft_form)
            u.randomize()
            Fu=u.fourier(copy=True)
            FuM=Fu.project(M)
            uM=FuM.fourier()

            if n%2 == 0:
                self.assertGreaterEqual(u.norm(), FuM.norm(), msg=msg)
                self.assertGreaterEqual(u.norm(componentwise=True), FuM.norm(componentwise=True),
                                       msg=msg)
                self.assertGreaterEqual(u.norm(), uM.norm(), msg=msg)
                self.assertGreaterEqual(u.norm(componentwise=True), uM.norm(componentwise=True),
                                        msg=msg)
            else:
                self.assertAlmostEqual(u.norm(), FuM.norm(), msg=msg)
                self.assertAlmostEqual(u.norm(componentwise=True), FuM.norm(componentwise=True),
                                       msg=msg)
                self.assertAlmostEqual(u.norm(), uM.norm(), msg=msg)
                self.assertAlmostEqual(u.norm(componentwise=True), uM.norm(componentwise=True),
                                        msg=msg)

            self.assertAlmostEqual(0, u.mean()-FuM.mean(), msg=msg)
            self.assertAlmostEqual(u.mean(), uM.mean(), msg=msg)

            # testing that that interpolation on double grid have exactly the same values
            slc=tuple(u.order*[slice(None),]+[slice(0,M[i],2) for i in range(dim)])
            self.assertAlmostEqual(0, np.linalg.norm(u.val-uM.val[slc]), msg=msg)
        print('...ok')
Beispiel #3
0
with representation in Fourier domain (with Fourier coefficients);
FxN = FN*xN = FN(xN) =""")
FxN = FN*xN # Fourier coefficients of xN
print(FxN)

print("""
The forward and inverse DFT are mutually inverse operations that can
be observed by calculation of variable 'xN2':
xN2 = FiN(FxN) = FiN(FN(xN)) =""")
xN2 = FiN(FxN) # values of trigonometric polynomial at grid points
print(xN2)
print("and its comparison with initial trigonometric polynomial 'xN2'")
print("(xN == xN2) = ")
print(xN == xN2)

print("""
The norm of trigonometric polynomial calculated from Fourier
coefficients corresponds to L^2 norm and is the same like for values at grid
points, which is a consequence of Parseval's identity:
xN.norm() = np.linalg.norm(xN.val)/np.prod(xN.N)**0.5 =
= (np.sum(xN.val*xN.val)/np.prod(xN.N))**0.5 = """)
print(xN.norm())
print("""FxN.norm() = np.linalg.norm(FxN.val) =
= np.sum(FxN.val*np.conj(FxN.val)).real**0.5 =""")
print(FxN.norm())

print("""
The trigonometric polynomials can be also multiplied. The standard
multiplication with '*' operations corresponds to scalar product
leading to a square of norm, i.e.
FxN.norm() = xN.norm() = (xN*xN)**0.5 = (FxN*FxN)**0.5 =""")
Beispiel #4
0
with representation in Fourier domain (with Fourier coefficients);
FxN = FN*xN = FN(xN) =""")
FxN = FN * xN  # Fourier coefficients of xN
print(FxN)

print("""
The forward and inverse DFT are mutually inverse operations that can
be observed by calculation of variable 'xN2':
xN2 = FiN(FxN) = FiN(FN(xN)) =""")
xN2 = FiN(FxN)  # values of trigonometric polynomial at grid points
print(xN2)
print("and its comparison with initial trigonometric polynomial 'xN2'")
print("(xN == xN2) = ")
print(xN == xN2)

print("""
The norm of trigonometric polynomial calculated from Fourier
coefficients corresponds to L^2 norm and is the same like for values at grid
points, which is a consequence of Parseval's identity:
xN.norm() = np.linalg.norm(xN.val)/np.prod(xN.N)**0.5 =
= (np.sum(xN.val*xN.val)/np.prod(xN.N))**0.5 = """)
print(xN.norm())
print("""FxN.norm() = np.linalg.norm(FxN.val) =
= np.sum(FxN.val*np.conj(FxN.val)).real**0.5 =""")
print(FxN.norm())

print("""
The trigonometric polynomials can be also multiplied. The standard
multiplication with '*' operations corresponds to scalar product
leading to a square of norm, i.e.
FxN.norm() = xN.norm() = (xN*xN)**0.5 = (FxN*FxN)**0.5 =""")