def bench_random(self):
        from numpy.fft import fft as numpy_fft
        print()
        print('                 Fast Fourier Transform')
        print('=================================================')
        print('      |    real input     |   complex input    ')
        print('-------------------------------------------------')
        print(' size |  scipy  |  numpy  |  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, end=' ')
            sys.stdout.flush()

            for x in [random([size]).astype(double),
                      random([size]).astype(cdouble)+random([size]).astype(cdouble)*1j
                      ]:
                if size > 500: y = fft(x)
                else: y = direct_dft(x)
                assert_array_almost_equal(fft(x),y)
                print('|%8.2f' % measure('fft(x)',repeat), end=' ')
                sys.stdout.flush()

                assert_array_almost_equal(numpy_fft(x),y)
                print('|%8.2f' % measure('numpy_fft(x)',repeat), end=' ')
                sys.stdout.flush()

            print(' (secs for %s calls)' % (repeat))
        sys.stdout.flush()
Esempio n. 2
0
 def test_djbfft(self):
     from numpy.fft import fft as numpy_fft
     for i in range(2,14):
         n = 2**i
         x = range(n)
         y2 = numpy_fft(x)
         y1 = zeros((n,),dtype=double)
         y1[0] = y2[0].real
         y1[-1] = y2[n/2].real
         for k in range(1, int(n/2)):
             y1[2*k-1] = y2[k].real
             y1[2*k] = y2[k].imag
         y = fftpack.drfft(x)
         assert_array_almost_equal(y,y1)
Esempio n. 3
0
 def test_djbfft(self):
     from numpy.fft import fft as numpy_fft
     for i in range(2, 14):
         n = 2**i
         x = range(n)
         y2 = numpy_fft(x)
         y1 = zeros((n, ), dtype=double)
         y1[0] = y2[0].real
         y1[-1] = y2[n / 2].real
         for k in range(1, int(n / 2)):
             y1[2 * k - 1] = y2[k].real
             y1[2 * k] = y2[k].imag
         y = fftpack.drfft(x)
         assert_array_almost_equal(y, y1)
Esempio n. 4
0
    def bench_random(self):
        from numpy.fft import fft as numpy_fft
        print()
        print('                 Fast Fourier Transform')
        print('=================================================')
        print('      |    real input     |   complex input    ')
        print('-------------------------------------------------')
        print(' size |  scipy  |  numpy  |  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, end=' ')
            sys.stdout.flush()

            for x in [
                    random([size]).astype(double),
                    random([size]).astype(cdouble) +
                    random([size]).astype(cdouble) * 1j
            ]:
                if size > 500:
                    y = fft(x)
                else:
                    y = direct_dft(x)
                assert_array_almost_equal(fft(x), y)
                print('|%8.2f' % measure('fft(x)', repeat), end=' ')
                sys.stdout.flush()

                assert_array_almost_equal(numpy_fft(x), y)
                print('|%8.2f' % measure('numpy_fft(x)', repeat), end=' ')
                sys.stdout.flush()

            print(' (secs for %s calls)' % (repeat))
        sys.stdout.flush()
Esempio n. 5
0
    def bench_random(self, level=5):
        from numpy.fft import fft as numpy_fft

        print
        print "                 Fast Fourier Transform"
        print "================================================="
        print "      |    real input     |   complex input    "
        print "-------------------------------------------------"
        print " size |  scipy  |  numpy  |  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()

            for x in [
                random([size]).astype(double),
                random([size]).astype(cdouble) + random([size]).astype(cdouble) * 1j,
            ]:
                if size > 500:
                    y = fft(x)
                else:
                    y = direct_dft(x)
                assert_array_almost_equal(fft(x), y)
                print "|%8.2f" % self.measure("fft(x)", repeat),
                sys.stdout.flush()

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

            print " (secs for %s calls)" % (repeat)
        sys.stdout.flush()
Esempio n. 6
0
    def bench_fft1_time(self):
        from numpy.fft import fft as numpy_fft
        from scipy.fftpack import fft as scipy_fft
        print
        print '   1D Double Precision Fast Fourier Transform'
        print '================================================='
        print '      |   complex input    '
        print '-------------------------------------------------'
        print ' size |  recon  |  numpy  |  scipy  |'
        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(repeat, size).astype(cdouble) + \
                random(repeat, size).astype(cdouble)*1j
            tr0 = time.time()
            y = fft1(x, shift=False)
            trf = time.time()
            print '|%8.2f' % (trf-tr0),
            sys.stdout.flush()
            tn0 = time.time()
            ny = numpy_fft(x)
            tnf = time.time()
            assert_array_almost_equal(ny,y)
            print '|%8.2f' % (tnf-tn0),
            sys.stdout.flush()
            ts0 = time.time()
            sy = scipy_fft(x)
            tsf = time.time()
            assert_array_almost_equal(sy,y)
            print '|%8.2f' % (tsf-ts0),
            sys.stdout.flush()

            print ' (secs for %s calls)' % (repeat)
        sys.stdout.flush()
        
        print
        print '   1D Double Precision Fast Fourier Transform'
        print '================================================='
        print '      |   complex input shifted   '
        print '-------------------------------------------------'
        print ' size |  recon  |  numpy  |  scipy  |'
        print '-------------------------------------------------'
        for size,repeat in [(100,7000),(1000,2000),
                            (256,10000),
                            (512,10000),
                            (1024,1000),
                            (2048,1000),
                            (2048*2,500),
                            (2048*4,500),
                            ]:
            chk = checkerline(size).astype(double)
            print '%5s' % size,
            sys.stdout.flush()

            x = random(repeat, size).astype(cdouble) + \
                random(repeat, size).astype(cdouble)*1j
            tr0 = time.time()
            y = fft1(x, shift=True)
            trf = time.time()
            print '|%8.2f' % (trf-tr0),
            sys.stdout.flush()
            tn0 = time.time()
            ny = chk*numpy_fft(chk*x)
            tnf = time.time()
            assert_array_almost_equal(ny,y)
            print '|%8.2f' % (tnf-tn0),
            sys.stdout.flush()
            ts0 = time.time()
            sy = chk*scipy_fft(chk*x)
            tsf = time.time()
            assert_array_almost_equal(sy,y)
            print '|%8.2f' % (tsf-ts0),
            sys.stdout.flush()

            print ' (secs for %s calls)' % (repeat)
        sys.stdout.flush()

        print
        print '   1D Single Precision Fast Fourier Transform'
        print '================================================='
        print '      |   complex input    '
        print '-------------------------------------------------'
        print ' size |  recon  |  numpy  |  scipy*  |'
        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(repeat, size).astype(csingle) + \
                random(repeat, size).astype(csingle)*1j
            tr0 = time.time()
            y = fft1(x, shift=False)
            trf = time.time()
            print '|%8.2f' % (trf-tr0),
            sys.stdout.flush()
            tn0 = time.time()
            ny = numpy_fft(x)
            tnf = time.time()
            assert_array_almost_equal(ny,y, decimal=2)
            print '|%8.2f' % (tnf-tn0),
            sys.stdout.flush()
            ts0 = time.time()
            sy = scipy_fft(x.astype(cdouble)).astype(csingle)
            tsf = time.time()
            assert_array_almost_equal(sy,y, decimal=2)
            print '|%8.2f' % (tsf-ts0),
            sys.stdout.flush()

            print ' (secs for %s calls)' % (repeat)
        print "(* casted float->FT{double}->float)"

        sys.stdout.flush()
        print
        print '   1D Single Precision Fast Fourier Transform'
        print '================================================='
        print '      |   complex input shifted   '
        print '-------------------------------------------------'
        print ' size |  recon  |  numpy  |  scipy*  |'
        print '-------------------------------------------------'
        for size,repeat in [(100,7000),(1000,2000),
                            (256,10000),
                            (512,10000),
                            (1024,1000),
                            (2048,1000),
                            (2048*2,500),
                            (2048*4,500),
                            ]:
            chk = checkerline(size).astype(single)
            print '%5s' % size,
            sys.stdout.flush()

            x = random(repeat, size).astype(csingle) + \
                random(repeat, size).astype(csingle)*1j
            tr0 = time.time()
            y = fft1(x, shift=True)
            trf = time.time()
            print '|%8.2f' % (trf-tr0),
            sys.stdout.flush()
            tn0 = time.time()
            ny = chk*numpy_fft(chk*x)
            tnf = time.time()
            assert_array_almost_equal(ny,y, decimal=2)
            print '|%8.2f' % (tnf-tn0),
            sys.stdout.flush()
            ts0 = time.time()
            sy = chk*(scipy_fft((chk*x).astype(cdouble))).astype(csingle)
            tsf = time.time()
            assert_array_almost_equal(sy,y, decimal=2)
            print '|%8.2f' % (tsf-ts0),
            sys.stdout.flush()

            print ' (secs for %s calls)' % (repeat)
        print "(* casted float->FT{double}->float)"
        sys.stdout.flush()
Esempio n. 7
0
def bench_fft1_time():
    from numpy.fft import fft as numpy_fft
    from scipy.fftpack import fft as scipy_fft
    print
    print '   1D Double Precision Fast Fourier Transform'
    print '================================================='
    print '      |   complex input    '
    print '-------------------------------------------------'
    print ' size |  fftw  |  numpy  |  scipy  |'
    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(repeat, size).astype('D') + \
            random(repeat, size).astype('D')*1j
        tr0 = time.time()
        y = fft1(x, shift=False)
        trf = time.time()
        print '|%8.2f' % (trf - tr0),
        sys.stdout.flush()
        tn0 = time.time()
        ny = numpy_fft(x)
        tnf = time.time()
        ##         assert_array_almost_equal(ny,y)
        print '|%8.2f' % (tnf - tn0),
        sys.stdout.flush()
        ts0 = time.time()
        sy = scipy_fft(x)
        tsf = time.time()
        ##         assert_array_almost_equal(sy,y)
        print '|%8.2f' % (tsf - ts0),
        sys.stdout.flush()

        print ' (secs for %s calls)' % (repeat)
    sys.stdout.flush()

    print
    print '   1D Double Precision Fast Fourier Transform'
    print '================================================='
    print '      |   complex input shifted   '
    print '-------------------------------------------------'
    print ' size |  fftw  |  numpy  |  scipy  |'
    print '-------------------------------------------------'
    for size, repeat in [
        (100, 7000),
        (1000, 2000),
        (256, 10000),
        (512, 10000),
        (1024, 1000),
        (2048, 1000),
        (2048 * 2, 500),
        (2048 * 4, 500),
    ]:
        chk = checkerline(size).astype('d')
        print '%5s' % size,
        sys.stdout.flush()

        x = random(repeat, size).astype('D') + \
            random(repeat, size).astype('D')*1j
        tr0 = time.time()
        y = fft1(x, shift=True)
        trf = time.time()
        print '|%8.2f' % (trf - tr0),
        sys.stdout.flush()
        tn0 = time.time()
        ny = chk * numpy_fft(chk * x)
        tnf = time.time()
        ##         assert_array_almost_equal(ny,y)
        print '|%8.2f' % (tnf - tn0),
        sys.stdout.flush()
        ts0 = time.time()
        sy = chk * scipy_fft(chk * x)
        tsf = time.time()
        ##         assert_array_almost_equal(sy,y)
        print '|%8.2f' % (tsf - ts0),
        sys.stdout.flush()

        print ' (secs for %s calls)' % (repeat)
    sys.stdout.flush()

    print
    print '   1D Single Precision Fast Fourier Transform'
    print '================================================='
    print '      |   complex input    '
    print '-------------------------------------------------'
    print ' size |  fftw  |  numpy  |  scipy*  |'
    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(repeat, size).astype('F') + \
            random(repeat, size).astype('F')*1j
        tr0 = time.time()
        y = fft1(x, shift=False)
        trf = time.time()
        print '|%8.2f' % (trf - tr0),
        sys.stdout.flush()
        tn0 = time.time()
        ny = numpy_fft(x)
        tnf = time.time()
        ##         assert_array_almost_equal(ny,y, decimal=2)
        print '|%8.2f' % (tnf - tn0),
        sys.stdout.flush()
        ts0 = time.time()
        sy = scipy_fft(x.astype('D')).astype('F')
        tsf = time.time()
        ##         assert_array_almost_equal(sy,y, decimal=2)
        print '|%8.2f' % (tsf - ts0),
        sys.stdout.flush()

        print ' (secs for %s calls)' % (repeat)
    print "(* casted float->FT{double}->float)"

    sys.stdout.flush()
    print
    print '   1D Single Precision Fast Fourier Transform'
    print '================================================='
    print '      |   complex input shifted   '
    print '-------------------------------------------------'
    print ' size |  fftw  |  numpy  |  scipy*  |'
    print '-------------------------------------------------'
    for size, repeat in [
        (100, 7000),
        (1000, 2000),
        (256, 10000),
        (512, 10000),
        (1024, 1000),
        (2048, 1000),
        (2048 * 2, 500),
        (2048 * 4, 500),
    ]:
        chk = checkerline(size).astype('f')
        print '%5s' % size,
        sys.stdout.flush()

        x = random(repeat, size).astype('F') + \
            random(repeat, size).astype('F')*1j
        tr0 = time.time()
        y = fft1(x, shift=True)
        trf = time.time()
        print '|%8.2f' % (trf - tr0),
        sys.stdout.flush()
        tn0 = time.time()
        ny = chk * numpy_fft(chk * x)
        tnf = time.time()
        ##         assert_array_almost_equal(ny,y, decimal=2)
        print '|%8.2f' % (tnf - tn0),
        sys.stdout.flush()
        ts0 = time.time()
        sy = chk * (scipy_fft((chk * x).astype('D'))).astype('F')
        tsf = time.time()
        ##         assert_array_almost_equal(sy,y, decimal=2)
        print '|%8.2f' % (tsf - ts0),
        sys.stdout.flush()

        print ' (secs for %s calls)' % (repeat)
    print "(* casted float->FT{double}->float)"
    sys.stdout.flush()
    assert True, 'WTF!'