Esempio n. 1
0
 def check_definition(self):
     x = [1, 2, 3, 4, 1, 2, 3, 4]
     x1 = [1, 2 + 3j, 4 + 1j, 2 + 3j, 4, 2 - 3j, 4 - 1j, 2 - 3j]
     y = irfft(x)
     y1 = direct_irdft(x)
     assert_array_almost_equal(y, y1)
     assert_array_almost_equal(y, ifft(x1))
     x = [1, 2, 3, 4, 1, 2, 3, 4, 5]
     x1 = [1, 2 + 3j, 4 + 1j, 2 + 3j, 4 + 5j, 4 - 5j, 2 - 3j, 4 - 1j, 2 - 3j]
     y = irfft(x)
     y1 = direct_irdft(x)
     assert_array_almost_equal(y, y1)
     assert_array_almost_equal(y, ifft(x1))
Esempio n. 2
0
    def bench_random(self, level=5):
        from numpy.fft import irfft as numpy_irfft

        print
        print "Inverse Fast Fourier Transform (real data)"
        print "=================================="
        print " size |  scipy  |  numpy  "
        print "----------------------------------"
        for size, repeat in [
            (100, 7000),
            (1000, 2000),
            (256, 10000),
            (512, 10000),
            (1024, 1000),
            (2048, 1000),
            (2048 * 2, 500),
            (2048 * 4, 500),
        ]:
            print "%5s" % size,
            sys.stdout.flush()

            x = random([size]).astype(double)
            x1 = zeros(size / 2 + 1, dtype=cdouble)
            x1[0] = x[0]
            for i in range(1, size / 2):
                x1[i] = x[2 * i - 1] + 1j * x[2 * i]
            if not size % 2:
                x1[-1] = x[-1]
            y = irfft(x)

            print "|%8.2f" % self.measure("irfft(x)", repeat),
            sys.stdout.flush()

            assert_array_almost_equal(numpy_irfft(x1, size), y)
            print "|%8.2f" % self.measure("numpy_irfft(x1,size)", repeat),
            sys.stdout.flush()

            print " (secs for %s calls)" % (repeat)

        sys.stdout.flush()
Esempio n. 3
0
 def check_random_real(self):
     for size in [1, 51, 111, 100, 200, 64, 128, 256, 1024]:
         x = random([size]).astype(double)
         assert_array_almost_equal(irfft(rfft(x)), x)
         assert_array_almost_equal(rfft(irfft(x)), x)