def bench_random(self): from numpy.fft import ifft as numpy_ifft print() print(' Inverse 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 = ifft(x) else: y = direct_idft(x) assert_array_almost_equal(ifft(x),y) print('|%8.2f' % measure('ifft(x)',repeat), end=' ') sys.stdout.flush() assert_array_almost_equal(numpy_ifft(x),y) print('|%8.2f' % measure('numpy_ifft(x)',repeat), end=' ') sys.stdout.flush() print(' (secs for %s calls)' % (repeat)) sys.stdout.flush()
def test_djbfft(self): from numpy.fft import ifft as numpy_ifft for i in range(2,14): n = 2**i x = range(n) x1 = zeros((n,),dtype=cdouble) x1[0] = x[0] for k in range(1, int(n/2)): x1[k] = x[2*k-1]+1j*x[2*k] x1[n-k] = x[2*k-1]-1j*x[2*k] x1[n/2] = x[-1] y1 = numpy_ifft(x1) y = fftpack.drfft(x,direction=-1) assert_array_almost_equal(y,y1)
def test_djbfft(self): from numpy.fft import ifft as numpy_ifft for i in range(2,14): n = 2**i x = list(range(n)) x1 = zeros((n,),dtype=cdouble) x1[0] = x[0] for k in range(1, n//2): x1[k] = x[2*k-1]+1j*x[2*k] x1[n-k] = x[2*k-1]-1j*x[2*k] x1[n//2] = x[-1] y1 = numpy_ifft(x1) y = fftpack.drfft(x,direction=-1) assert_array_almost_equal(y,y1)
def calculate_fft_numpy(a, b): x = to_decimal_table(a, 2 * check_which_2pow(max(a, b))) y = to_decimal_table(b, 2 * check_which_2pow(max(a, b))) dft_x = numpy_fft(x) dft_y = numpy_fft(y) freq = [] for i in range(0, len(dft_x)): temp = complex(dft_x[i] * dft_y[i]) freq.append(temp) z = [int(round(elem.real)) for elem in numpy_ifft(freq)] return to_decimal(z, 10) return output
def bench_random(self, level=5): from numpy.fft import ifft as numpy_ifft print print " Inverse 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 = ifft(x) else: y = direct_idft(x) assert_array_almost_equal(ifft(x), y) print "|%8.2f" % self.measure("ifft(x)", repeat), sys.stdout.flush() assert_array_almost_equal(numpy_ifft(x), y) print "|%8.2f" % self.measure("numpy_ifft(x)", repeat), sys.stdout.flush() print " (secs for %s calls)" % (repeat) sys.stdout.flush()
def bench_ifft1_time(self): from numpy.fft import ifft as numpy_ifft from scipy.fftpack import ifft as scipy_ifft print print ' 1D Double Precision (I)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 = ifft1(x, shift=False) trf = time.time() print '|%8.2f' % (trf-tr0), sys.stdout.flush() tn0 = time.time() ny = numpy_ifft(x) tnf = time.time() assert_array_almost_equal(ny,y) print '|%8.2f' % (tnf-tn0), sys.stdout.flush() ts0 = time.time() sy = scipy_ifft(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 (I)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 = ifft1(x, shift=True) trf = time.time() print '|%8.2f' % (trf-tr0), sys.stdout.flush() tn0 = time.time() ny = chk*numpy_ifft(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_ifft(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 (I)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 = ifft1(x, shift=False) trf = time.time() print '|%8.2f' % (trf-tr0), sys.stdout.flush() tn0 = time.time() ny = numpy_ifft(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_ifft(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 (I)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 = ifft1(x, shift=True) trf = time.time() print '|%8.2f' % (trf-tr0), sys.stdout.flush() tn0 = time.time() ny = chk*numpy_ifft(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_ifft((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()
def bench_ifft1_time(): from numpy.fft import ifft as numpy_ifft from scipy.fftpack import ifft as scipy_ifft print print ' 1D Double Precision (I)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 = ifft1(x, shift=False) trf = time.time() print '|%8.2f' % (trf - tr0), sys.stdout.flush() tn0 = time.time() ny = numpy_ifft(x) tnf = time.time() ## assert_array_almost_equal(ny,y) print '|%8.2f' % (tnf - tn0), sys.stdout.flush() ts0 = time.time() sy = scipy_ifft(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 (I)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 = ifft1(x, shift=True) trf = time.time() print '|%8.2f' % (trf - tr0), sys.stdout.flush() tn0 = time.time() ny = chk * numpy_ifft(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_ifft(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 (I)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 = ifft1(x, shift=False) trf = time.time() print '|%8.2f' % (trf - tr0), sys.stdout.flush() tn0 = time.time() ny = numpy_ifft(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_ifft(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 (I)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 = ifft1(x, shift=True) trf = time.time() print '|%8.2f' % (trf - tr0), sys.stdout.flush() tn0 = time.time() ny = chk * numpy_ifft(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_ifft((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, 'asdf'