Example #1
0
def test_passes_for_even():
    a = np.empty((3, 4, 5)).astype('D')
    try:
        fft1(a, axis=1)
        assert True, 'passed'
    except:
        assert False, 'did not attempt to transform even dimension'
Example #2
0
def test_passes_for_even():
    a = np.empty((3,4,5)).astype('D')
    try:
        fft1(a, axis=1)
        assert True, 'passed'
    except:
        assert False, 'did not attempt to transform even dimension'
Example #3
0
def test_twice_odd_length():
    # functions with dimension lengths such that N_i/2 is odd need
    # special treatment in the output modulation
    a = np.random.randn(30).astype('D')
    A_ref = reference_fftn(a, shift=True)
    A_test = fft1(a, shift=True)
    assert np.allclose(A_ref, A_test), 'twice-odd length FT fails'
Example #4
0
def test_twice_odd_length():
    # functions with dimension lengths such that N_i/2 is odd need
    # special treatment in the output modulation
    a = np.random.randn(30).astype('D')
    A_ref = reference_fftn(a, shift=True)
    A_test = fft1(a, shift=True)
    assert np.allclose(A_ref, A_test), 'twice-odd length FT fails'
Example #5
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!'
Example #6
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!'
Example #7
0
def test_fails_for_odd_1():
    a = np.empty((3, 4, 5)).astype('D')
    fft1(a)
Example #8
0
def test_fails_for_odd_1():
    a = np.empty((3,4,5)).astype('D')
    fft1(a)