コード例 #1
0
    def bench_random(self):
        from numpy.fft import fftn as numpy_fftn
        print()
        print('    Multi-dimensional Fast Fourier Transform')
        print('===================================================')
        print('          |    real input     |   complex input    ')
        print('---------------------------------------------------')
        print('   size   |  scipy  |  numpy  |  scipy  |  numpy ')
        print('---------------------------------------------------')
        for size,repeat in [((100,100),100),((1000,100),7),
                            ((256,256),10),
                            ((512,512),3),
                            ]:
            print('%9s' % ('%sx%s'%size), end=' ')
            sys.stdout.flush()

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

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

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

        sys.stdout.flush()
コード例 #2
0
ファイル: test_basic.py プロジェクト: mbentz80/jzigbeercp
    def bench_random(self, level=5):
        from numpy.fft import fftn as numpy_fftn

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

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

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

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

        sys.stdout.flush()
コード例 #3
0
ファイル: fft_bench.py プロジェクト: christandiono/nutmeg-py
    def bench_fft2_time(self):
        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   |  recon  |  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(cdouble) + \
                random(repeat, *size).astype(cdouble)*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   |  recon  |  numpy  |  scipy  |'
        print '---------------------------------------------------'
        for size,repeat in [((100,100),100),((1000,100),7),
                            ((256,256),10),
                            ((512,512),3),
                            ]:
            chk = checkerboard(*size).astype(double)
            print '%9s' % ('%sx%s'%size),
            sys.stdout.flush()
            x = random(repeat, *size).astype(cdouble) + \
                random(repeat, *size).astype(cdouble)*1j
            tr0 = time.time()
            y = fft2(x, shift=True)
            trf = time.time()
            print '|%8.2f' % (trf-tr0),
            sys.stdout.flush()


        print
        print '    2D Single Precision Fast Fourier Transform'
        print '==================================================='
        print '          |   complex input    '
        print '---------------------------------------------------'
        print '   size   |  recon  |  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(csingle) + \
                random(repeat, *size).astype(csingle)*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(cdouble), axes=(-2,-1)).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 '    2D Single Precision Fast Fourier Transform'
        print '==================================================='
        print '          |   complex input shifted   '
        print '---------------------------------------------------'
        print '   size   |  recon  |  numpy  |  scipy*  |'
        print '---------------------------------------------------'
        for size,repeat in [((100,100),100),((1000,100),7),
                            ((256,256),10),
                            ((512,512),3),
                            ]:
            chk = checkerboard(*size).astype(single)
            print '%9s' % ('%sx%s'%size),
            sys.stdout.flush()
            x = random(repeat, *size).astype(csingle) + \
                random(repeat, *size).astype(csingle)*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(cdouble), axes=(-2,-1)).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()
コード例 #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'