示例#1
0
 def _type_1_odd(self, eps=1e-10):
     p2 = nufft1d1(self.x, self.c, len(self.f) + 1, direct=True)
     p1 = nufft1d1(self.x, self.c, len(self.f) + 1, eps=eps)
     self.assertTrue(_error(p1, p2) < eps,
                     "Type 1: Discrepancy between direct and fft function")
     self.assertEqual(len(nufft1d1freqs(len(self.f) + 1)), len(p1),
                      "Wrong length of frequency array")
示例#2
0
    def test_type1_irdft(self):
        """Is the NUFFT type 1 IRDFT correct?"""

        # Trick to make it think it is seeing a full FFT
        f = np.concatenate((self.fr_numpy,
                            np.conj(self.fr_numpy[-2:0:-1])))

        c_dir = np.roll(nufft1d1(self.x,
                                 f,
                                 self.N,
                                 iflag=1,
                                 direct=True),
                        -int(self.N / 2),
                        0)
        c_nufft = np.roll(nufft1d1(self.x,
                                   f,
                                   self.N,
                                   iflag=1,
                                   direct=False),
                          -int(self.N / 2),
                          0)

        self.assertTrue(_error(self.cr_numpy, c_dir) < self.eps,
                        "NUFFT direct IRDFT (1) vs. NumPy IRFFT: error too large")
        self.assertTrue(_error(self.cr_numpy, c_nufft) < self.eps,
                        "NUFFT direct IRDFT (1) vs. NumPy IRFFT: error too large")
示例#3
0
 def _type_1_odd(self, eps=1e-10):
     p2 = nufft1d1(self.x, self.c, len(self.f) + 1, direct=True)
     p1 = nufft1d1(self.x, self.c, len(self.f) + 1, eps=eps)
     self.assertTrue(
         _error(p1, p2) < eps,
         "Type 1: Discrepancy between direct and fft function")
     self.assertEqual(len(nufft1d1freqs(len(self.f) + 1)), len(p1),
                      "Wrong length of frequency array")
示例#4
0
    def test_type1_rdft(self):
        """Is the NUFFT type 1 RDFT correct?"""
        f_dir1 = np.roll(
            nufft1d1(self.x, self.c, self.N, iflag=-1, direct=True),
            -int(self.N / 2), 0)[:int(self.N / 2) + 1] * self.N
        f_nufft1 = np.roll(
            nufft1d1(self.x, self.c, self.N, iflag=-1, direct=False),
            -int(self.N / 2), 0)[:int(self.N / 2) + 1] * self.N

        self.assertTrue(
            _error(self.fr_numpy, f_dir1) < self.eps,
            "NUFFT direct RDFT (1) vs. NumPy IRFFT: error too large")
        self.assertTrue(
            _error(self.fr_numpy, f_nufft1) < self.eps,
            "NUFFT RFFT (1) vs. NumPy IRFFT: error too large")
示例#5
0
    def test_type1_idft(self):
        """Is the NUFFT type 1 IDFT correct?"""
        c_dir = np.roll(
            nufft1d1(self.x, self.f_numpy, self.N, iflag=1, direct=True),
            -int(self.N / 2), 0)
        c_nufft = np.roll(
            nufft1d1(self.x, self.f_numpy, self.N, iflag=1, direct=False),
            -int(self.N / 2), 0)

        self.assertTrue(
            _error(self.c_numpy, c_dir) < self.eps,
            "NUFFT direct IDFT (1) vs. NumPy IFFT: error too large")
        self.assertTrue(
            _error(self.c_numpy, c_nufft) < self.eps,
            "NUFFT direct IDFT (1) vs. NumPy IFFT: error too large")
示例#6
0
    def test_type1_irdft(self):
        """Is the NUFFT type 1 IRDFT correct?"""

        # Trick to make it think it is seeing a full FFT
        f = np.concatenate((self.fr_numpy, np.conj(self.fr_numpy[-2:0:-1])))

        c_dir = np.roll(nufft1d1(self.x, f, self.N, iflag=1, direct=True),
                        -int(self.N / 2), 0)
        c_nufft = np.roll(nufft1d1(self.x, f, self.N, iflag=1, direct=False),
                          -int(self.N / 2), 0)

        self.assertTrue(
            _error(self.cr_numpy, c_dir) < self.eps,
            "NUFFT direct IRDFT (1) vs. NumPy IRFFT: error too large")
        self.assertTrue(
            _error(self.cr_numpy, c_nufft) < self.eps,
            "NUFFT direct IRDFT (1) vs. NumPy IRFFT: error too large")
示例#7
0
    def _type_1_and_3(self, eps=1e-10):

        f = nufft1d1freqs(len(self.f))
        p2 = nufft1d3(self.x, self.c, f, eps=eps)
        p1 = nufft1d1(self.x, self.c, len(f), eps=eps)
        self.assertTrue(_error(p1, p2) < eps,
                        "Type 1 and 3 and not close (even)")

        f = nufft1d1freqs(len(f) + 1)
        p2 = nufft1d3(self.x, self.c, f, eps=eps)
        p1 = nufft1d1(self.x, self.c, len(f), eps=eps)
        self.assertTrue(_error(p1, p2) < eps,
                        "Type 1 and 3 and not close (odd)")

        df = 0.5 * (f[1] - f[0])
        p1 = nufft1d1(self.x, self.c, len(f), eps=eps, df=df)
        f = nufft1d1freqs(len(f), df=df)
        p2 = nufft1d3(self.x, self.c, f, eps=eps)
        self.assertTrue(_error(p1, p2) < eps,
                        "Type 1 and 3 and not close (even)")
示例#8
0
    def _type_1_and_3(self, eps=1e-10):

        f = nufft1d1freqs(len(self.f))
        p2 = nufft1d3(self.x, self.c, f, eps=eps)
        p1 = nufft1d1(self.x, self.c, len(f), eps=eps)
        self.assertTrue(
            _error(p1, p2) < eps, "Type 1 and 3 and not close (even)")

        f = nufft1d1freqs(len(f) + 1)
        p2 = nufft1d3(self.x, self.c, f, eps=eps)
        p1 = nufft1d1(self.x, self.c, len(f), eps=eps)
        self.assertTrue(
            _error(p1, p2) < eps, "Type 1 and 3 and not close (odd)")

        df = 0.5 * (f[1] - f[0])
        p1 = nufft1d1(self.x, self.c, len(f), eps=eps, df=df)
        f = nufft1d1freqs(len(f), df=df)
        p2 = nufft1d3(self.x, self.c, f, eps=eps)
        self.assertTrue(
            _error(p1, p2) < eps, "Type 1 and 3 and not close (even)")
示例#9
0
    def test_type1_rdft(self):
        """Is the NUFFT type 1 RDFT correct?"""
        f_dir1 = np.roll(nufft1d1(self.x,
                                  self.c,
                                  self.N,
                                  iflag=-1,
                                  direct=True),
                         -int(self.N / 2),
                         0)[:int(self.N / 2) + 1] * self.N
        f_nufft1 = np.roll(nufft1d1(self.x,
                                    self.c,
                                    self.N,
                                    iflag=-1,
                                    direct=False),
                           -int(self.N / 2),
                           0)[:int(self.N / 2) + 1] * self.N

        self.assertTrue(_error(self.fr_numpy, f_dir1) < self.eps,
                        "NUFFT direct RDFT (1) vs. NumPy IRFFT: error too large")
        self.assertTrue(_error(self.fr_numpy, f_nufft1) < self.eps,
                        "NUFFT RFFT (1) vs. NumPy IRFFT: error too large")
示例#10
0
    def test_type1_idft(self):
        """Is the NUFFT type 1 IDFT correct?"""
        c_dir = np.roll(nufft1d1(self.x,
                                 self.f_numpy,
                                 self.N,
                                 iflag=1,
                                 direct=True),
                        -int(self.N / 2),
                        0)
        c_nufft = np.roll(nufft1d1(self.x,
                                   self.f_numpy,
                                   self.N,
                                   iflag=1,
                                   direct=False),
                          -int(self.N / 2),
                          0)

        self.assertTrue(_error(self.c_numpy, c_dir) < self.eps,
                        "NUFFT direct IDFT (1) vs. NumPy IFFT: error too large")
        self.assertTrue(_error(self.c_numpy, c_nufft) < self.eps,
                        "NUFFT direct IDFT (1) vs. NumPy IFFT: error too large")
示例#11
0
def test_all_equal_nufft1d1():
    xj = np.random.random_sample(NJ)
    cj = np.sin(xj).astype(dtype=np.complex128)

    fk1 = np.zeros((MS), dtype=np.complex128)

    ier = cff_nufft.lib.nufft1d1(NJ, numpy_pointer(np.copy(xj)),
                                 numpy_pointer(np.copy(cj)), IFLAG, EPS, MS,
                                 numpy_pointer(fk1))

    fk2 = f2p_nufft.nufft1d1(xj, cj, MS, df=1.0, eps=EPS, iflag=IFLAG)

    assert np.allclose(fk1, fk2)
示例#12
0
 def _type_1_2_roundtrip(self, eps=1e-10):
     x, c1, f = _get_data_roundtrip()
     p = nufft1d1(x, c1, len(f), iflag=-1, eps=eps)
     c2 = len(x) / len(f) * nufft1d2(x, p, iflag=1, direct=True)
     self.assertTrue(_error(c1, c2) < eps,
                     "Type 1 and 2: roundtrip error.")
示例#13
0
 def _type_1_2_roundtrip(self, eps=1e-10):
     x, c1, f = _get_data_roundtrip()
     p = nufft1d1(x, c1, len(f), iflag=-1, eps=eps)
     c2 = len(x) / len(f) * nufft1d2(x, p, iflag=1, direct=True)
     self.assertTrue(_error(c1, c2) < eps, "Type 1 and 2: roundtrip error.")