In [1]:
import pyfftw
import scipy.fftpack as fftpack
import numpy as np
import numpy.fft as npfft
import timeit
In [2]:
nseg = 100
n_bins = 8192
rate1D = np.random.random_integers(0,10000,n_bins)
rate2D = np.random.random_integers(0,10000,(n_bins, nseg))
print "Shape of 1D array:", np.shape(rate1D)
print "Shape of 2D array:", np.shape(rate2D)
In [3]:
scipy_1Dfft = fftpack.fft(rate1D)
## Still only taking a FFT in one dimension, but over a 2D array
scipy_2Dfft = fftpack.fft(rate2D, axis=0)
In [4]:
numpy_1Dfft = npfft.fft(rate1D)
numpy_2Dfft = npfft.fft(rate2D, axis=0)
In [5]:
in1D_array = pyfftw.n_byte_align_empty(n_bins, 16, 'complex128')
out1D_array = pyfftw.n_byte_align_empty(n_bins, 16, 'complex128')
fft1D_object = pyfftw.FFTW(in1D_array, out1D_array, flags=('FFTW_MEASURE',))
ifft1D_object = pyfftw.FFTW(in1D_array, out1D_array, direction='FFTW_BACKWARD', flags=('FFTW_MEASURE',), normalise_idft=False)
in2D_array = pyfftw.n_byte_align_empty((n_bins,nseg), 16, 'complex128')
out2D_array = pyfftw.n_byte_align_empty((n_bins,nseg), 16, 'complex128')
fft2D_object = pyfftw.FFTW(in2D_array, out2D_array, flags=('FFTW_MEASURE',), threads=50, axes=(0,))
ifft2D_object = pyfftw.FFTW(in2D_array, out2D_array, direction='FFTW_BACKWARD', flags=('FFTW_MEASURE',), threads=50, axes=(0,), normalise_idft=False)
In [6]:
in1D_array[:] = rate1D + 0j
pyfftw_1Dfft = fft1D_object(in1D_array)
in2D_array[:] = rate2D + 0j
pyfftw_2Dfft = fft2D_object(in2D_array)
In [7]:
print np.allclose(scipy_1Dfft, pyfftw_1Dfft)
print np.allclose(numpy_1Dfft, pyfftw_1Dfft)
print np.allclose(scipy_1Dfft, numpy_1Dfft)
In [8]:
print np.allclose(scipy_2Dfft, pyfftw_2Dfft)
print np.allclose(numpy_2Dfft, pyfftw_2Dfft)
print np.allclose(scipy_2Dfft, numpy_2Dfft)
In [9]:
print "SciPy, FFT, 1D:"
%timeit fftpack.fft(rate1D)
print "pyFFTW, FFT, 1D:"
%timeit fft1D_object(in1D_array)
print "NumPy, FFT, 1D:"
%timeit npfft.fft(rate1D)
In [10]:
print "SciPy, FFT, 2D:"
%timeit fftpack.fft(rate2D, axis=0)
print "pyFFTW, FFT, 2D:"
%timeit fft2D_object(in2D_array)
print "NumPy, FFT, 2D:"
%timeit npfft.fft(rate2D, axis=0)
In [11]:
print "SciPy, iFFT, 1D:"
%timeit fftpack.ifft(scipy_1Dfft)
print "pyFFTW, iFFT, 1D:"
%timeit ifft1D_object(pyfftw_1Dfft)
print "NumPy, iFFT, 1D:"
%timeit npfft.ifft(numpy_1Dfft)
In [12]:
print "SciPy, iFFT, 2D:"
%timeit fftpack.ifft(scipy_2Dfft, axis=0)
print "pyFFTW, iFFT, 2D:"
%timeit ifft2D_object(pyfftw_2Dfft)
print "NumPy, iFFT, 2D:"
%timeit npfft.ifft(numpy_2Dfft, axis=0)
In [12]: