Esempio n. 1
0
    def test_non_ndarray_with_dtype(self):
        x = np.array([1., 2., 3., 4., 5.])
        xs = _TestRFFTBase.MockSeries(x)

        expected = [1, 2, 3, 4, 5]
        rfft(xs)

        # Data should not have been overwritten
        assert_equal(x, expected)
        assert_equal(xs.data, expected)
Esempio n. 2
0
    def test_size_accuracy(self):
        # Sanity check for the accuracy for prime and non-prime sized inputs
        if self.rdt == np.float32:
            rtol = 1e-5
        elif self.rdt == np.float64:
            rtol = 1e-10

        for size in LARGE_COMPOSITE_SIZES + LARGE_PRIME_SIZES:
            np.random.seed(1234)
            x = np.random.rand(size).astype(self.rdt)
            y = irfft(rfft(x), len(x))
            _assert_close_in_norm(x, y, rtol, size, self.rdt)
            y = rfft(irfft(x, 2 * len(x) - 1))
            _assert_close_in_norm(x, y, rtol, size, self.rdt)
Esempio n. 3
0
 def test_random_real(self):
     for size in [1, 51, 111, 100, 200, 64, 128, 256, 1024]:
         x = random([size]).astype(self.rdt)
         y1 = irfft(rfft(x), n=size)
         y2 = rfft(irfft(x, n=(size * 2 - 1)))
         assert_equal(y1.dtype, self.rdt)
         assert_equal(y2.dtype, self.cdt)
         assert_array_almost_equal(y1,
                                   x,
                                   decimal=self.ndec,
                                   err_msg="size=%d" % size)
         assert_array_almost_equal(y2,
                                   x,
                                   decimal=self.ndec,
                                   err_msg="size=%d" % size)
Esempio n. 4
0
 def test_djbfft(self):
     for i in range(2, 14):
         n = 2**i
         x = np.arange(n)
         y1 = np.fft.rfft(x)
         y = rfft(x)
         assert_array_almost_equal(y, y1)
Esempio n. 5
0
 def test_definition(self):
     for t in [[1, 2, 3, 4, 1, 2, 3, 4], [1, 2, 3, 4, 1, 2, 3, 4, 5]]:
         x = np.array(t, dtype=self.rdt)
         y = rfft(x)
         y1 = direct_rdft(x)
         assert_array_almost_equal(y, y1)
         assert_equal(y.dtype, self.cdt)
Esempio n. 6
0
 def test_complex_input(self):
     x = np.zeros(10, dtype=self.cdt)
     with assert_raises(TypeError, match="x must be a real sequence"):
         rfft(x)
Esempio n. 7
0
def direct_rdftn(x):
    return fftn(rfft(x), axes=range(x.ndim - 1))