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()
b_out = CopyBlock(b_fft, space='system', core=3) b_write = BinaryFileWriteBlock(b_out, core=4) # Run pipeline pipeline = bfp.get_default_pipeline() print(pipeline.dot_graph()) pipeline.run() # Check the output files match the input files for filename in filenames: try: print(filename) # Load the input data, do a windowed FFT indata = np.fromfile(filename, dtype='complex64') indata = scipy_fft(indata.reshape(n_window, window_len), axis=1) # Load the output data and reshape into windowed FFTs outdata = np.fromfile('%s.out' % filename, dtype='complex64') outdata = outdata.reshape(n_window, window_len) assert np.allclose(indata, outdata, atol=0.1) print(" Input data and output data match.") except AssertionError: print(" Error: input and output data do not match.") for ii in range(len(indata)): print("Window %02i match: %s" % (ii, np.allclose(indata[ii], outdata[ii], atol=0.1))) print(indata[0, 0:10]) print(outdata[0, 0:10]) print(np.max(indata - outdata))
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!'