Пример #1
0
def test_twice_odd_length2():
    # functions with dimension lengths such that N_i/2 is odd need
    # special treatment in the output modulation
    a = np.random.randn(30, 40).astype('D')
    A_ref = reference_fftn(a, axes=(0, 1), shift=True)
    A_test = fft2(a, shift=True)
    assert np.allclose(A_ref, A_test), 'twice-odd length FT fails in 2D'
Пример #2
0
def test_twice_odd_length2():
    # functions with dimension lengths such that N_i/2 is odd need
    # special treatment in the output modulation
    a = np.random.randn(30,40).astype('D')
    A_ref = reference_fftn(a, axes=(0,1), shift=True)
    A_test = fft2(a, shift=True)
    assert np.allclose(A_ref, A_test), 'twice-odd length FT fails in 2D'
Пример #3
0
def bench_fft2_time():
    from numpy.fft import fftn as numpy_fftn
    from scipy.fftpack import fftn as scipy_fftn
    print
    print '    2D Double Precision Fast Fourier Transform'
    print '==================================================='
    print '          |   complex input    '
    print '---------------------------------------------------'
    print '   size   |  fftw  |  numpy  |  scipy  |'
    print '---------------------------------------------------'
    for size, repeat in [
        ((100, 100), 100),
        ((1000, 100), 7),
        ((256, 256), 10),
        ((512, 512), 3),
    ]:
        print '%9s' % ('%sx%s' % size),
        sys.stdout.flush()
        x = random(repeat, *size).astype('D') + \
            random(repeat, *size).astype('D')*1j
        tr0 = time.time()
        y = fft2(x, shift=False)
        trf = time.time()
        print '|%8.2f' % (trf - tr0),
        sys.stdout.flush()

        tn0 = time.time()
        ny = numpy_fftn(x, axes=(-2, -1))
        tnf = time.time()
        ##         assert_array_almost_equal(ny,y)
        print '|%8.2f' % (tnf - tn0),
        sys.stdout.flush()

        ts0 = time.time()
        sy = scipy_fftn(x, axes=(-2, -1))
        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 '    2D Double Precision Fast Fourier Transform'
    print '==================================================='
    print '          |   complex input shifted   '
    print '---------------------------------------------------'
    print '   size   |  fftw  |  numpy  |  scipy  |'
    print '---------------------------------------------------'
    for size, repeat in [
        ((100, 100), 100),
        ((1000, 100), 7),
        ((256, 256), 10),
        ((512, 512), 3),
    ]:
        chk = checkerboard(*size).astype('d')
        print '%9s' % ('%sx%s' % size),
        sys.stdout.flush()
        x = random(repeat, *size).astype('D') + \
            random(repeat, *size).astype('D')*1j
        tr0 = time.time()
        y = fft2(x, shift=True)
        trf = time.time()
        print '|%8.2f' % (trf - tr0),
        sys.stdout.flush()

        tn0 = time.time()
        ny = numpy_fftn(x, axes=(-2, -1))
        tnf = time.time()
        ##         assert_array_almost_equal(ny,y)
        print '|%8.2f' % (tnf - tn0),
        sys.stdout.flush()

        ts0 = time.time()
        sy = scipy_fftn(x, axes=(-2, -1))
        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 '    2D Single Precision Fast Fourier Transform'
    print '==================================================='
    print '          |   complex input    '
    print '---------------------------------------------------'
    print '   size   |  fftw  |  numpy  |  scipy*  |'
    print '---------------------------------------------------'
    for size, repeat in [
        ((100, 100), 100),
        ((1000, 100), 7),
        ((256, 256), 10),
        ((512, 512), 3),
    ]:
        print '%9s' % ('%sx%s' % size),
        sys.stdout.flush()
        x = random(repeat, *size).astype('F') + \
            random(repeat, *size).astype('F')*1j
        tr0 = time.time()
        y = fft2(x, shift=False)
        trf = time.time()
        print '|%8.2f' % (trf - tr0),
        sys.stdout.flush()

        tn0 = time.time()
        ny = numpy_fftn(x, axes=(-2, -1))
        tnf = time.time()
        ##         assert_array_almost_equal(ny,y, decimal=2)
        print '|%8.2f' % (tnf - tn0),
        sys.stdout.flush()

        ts0 = time.time()
        sy = scipy_fftn(x.astype('D'), axes=(-2, -1)).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 '    2D Single Precision Fast Fourier Transform'
    print '==================================================='
    print '          |   complex input shifted   '
    print '---------------------------------------------------'
    print '   size   |  fftw  |  numpy  |  scipy*  |'
    print '---------------------------------------------------'
    for size, repeat in [
        ((100, 100), 100),
        ((1000, 100), 7),
        ((256, 256), 10),
        ((512, 512), 3),
    ]:
        chk = checkerboard(*size).astype('f')
        print '%9s' % ('%sx%s' % size),
        sys.stdout.flush()
        x = random(repeat, *size).astype('F') + \
            random(repeat, *size).astype('F')*1j
        tr0 = time.time()
        y = fft2(x, shift=True)
        trf = time.time()
        print '|%8.2f' % (trf - tr0),
        sys.stdout.flush()

        tn0 = time.time()
        ny = chk * numpy_fftn(chk * x, axes=(-2, -1))
        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_fftn(
            (chk * x).astype('D'), axes=(-2, -1)).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, 'asdf'
Пример #4
0
def bench_fft2_time():
    from numpy.fft import fftn as numpy_fftn
    from scipy.fftpack import fftn as scipy_fftn
    print
    print '    2D Double Precision Fast Fourier Transform'
    print '==================================================='
    print '          |   complex input    '
    print '---------------------------------------------------'
    print '   size   |  fftw  |  numpy  |  scipy  |'
    print '---------------------------------------------------'
    for size,repeat in [((100,100),100),((1000,100),7),
                        ((256,256),10),
                        ((512,512),3),
                        ]:
        print '%9s' % ('%sx%s'%size),
        sys.stdout.flush()
        x = random(repeat, *size).astype('D') + \
            random(repeat, *size).astype('D')*1j
        tr0 = time.time()
        y = fft2(x, shift=False)
        trf = time.time()
        print '|%8.2f' % (trf-tr0),
        sys.stdout.flush()

        tn0 = time.time()
        ny = numpy_fftn(x, axes=(-2,-1))
        tnf = time.time()
##         assert_array_almost_equal(ny,y)
        print '|%8.2f' % (tnf-tn0),
        sys.stdout.flush()

        ts0 = time.time()
        sy = scipy_fftn(x, axes=(-2,-1))
        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 '    2D Double Precision Fast Fourier Transform'
    print '==================================================='
    print '          |   complex input shifted   '
    print '---------------------------------------------------'
    print '   size   |  fftw  |  numpy  |  scipy  |'
    print '---------------------------------------------------'
    for size,repeat in [((100,100),100),((1000,100),7),
                        ((256,256),10),
                        ((512,512),3),
                        ]:
        chk = checkerboard(*size).astype('d')
        print '%9s' % ('%sx%s'%size),
        sys.stdout.flush()
        x = random(repeat, *size).astype('D') + \
            random(repeat, *size).astype('D')*1j
        tr0 = time.time()
        y = fft2(x, shift=True)
        trf = time.time()
        print '|%8.2f' % (trf-tr0),
        sys.stdout.flush()

        tn0 = time.time()
        ny = numpy_fftn(x, axes=(-2,-1))
        tnf = time.time()
##         assert_array_almost_equal(ny,y)
        print '|%8.2f' % (tnf-tn0),
        sys.stdout.flush()

        ts0 = time.time()
        sy = scipy_fftn(x, axes=(-2,-1))
        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 '    2D Single Precision Fast Fourier Transform'
    print '==================================================='
    print '          |   complex input    '
    print '---------------------------------------------------'
    print '   size   |  fftw  |  numpy  |  scipy*  |'
    print '---------------------------------------------------'
    for size,repeat in [((100,100),100),((1000,100),7),
                        ((256,256),10),
                        ((512,512),3),
                        ]:
        print '%9s' % ('%sx%s'%size),
        sys.stdout.flush()
        x = random(repeat, *size).astype('F') + \
            random(repeat, *size).astype('F')*1j
        tr0 = time.time()
        y = fft2(x, shift=False)
        trf = time.time()
        print '|%8.2f' % (trf-tr0),
        sys.stdout.flush()

        tn0 = time.time()
        ny = numpy_fftn(x, axes=(-2,-1))
        tnf = time.time()
##         assert_array_almost_equal(ny,y, decimal=2)
        print '|%8.2f' % (tnf-tn0),
        sys.stdout.flush()

        ts0 = time.time()
        sy = scipy_fftn(x.astype('D'), axes=(-2,-1)).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 '    2D Single Precision Fast Fourier Transform'
    print '==================================================='
    print '          |   complex input shifted   '
    print '---------------------------------------------------'
    print '   size   |  fftw  |  numpy  |  scipy*  |'
    print '---------------------------------------------------'
    for size,repeat in [((100,100),100),((1000,100),7),
                        ((256,256),10),
                        ((512,512),3),
                        ]:
        chk = checkerboard(*size).astype('f')
        print '%9s' % ('%sx%s'%size),
        sys.stdout.flush()
        x = random(repeat, *size).astype('F') + \
            random(repeat, *size).astype('F')*1j
        tr0 = time.time()
        y = fft2(x, shift=True)
        trf = time.time()
        print '|%8.2f' % (trf-tr0),
        sys.stdout.flush()

        tn0 = time.time()
        ny = chk*numpy_fftn(chk*x, axes=(-2,-1))
        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_fftn((chk*x).astype('D'), axes=(-2,-1)).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, 'asdf'
Пример #5
0
def test_fails_for_odd_1():
    a = np.empty((3, 4, 5)).astype('D')
    fft2(a, axes=(0, 1))
Пример #6
0
def test_fails_for_odd_1():
    a = np.empty((3,4,5)).astype('D')
    fft2(a, axes=(0,1))