Time numpys fft vs fftw (linked through pyfftw).


In [2]:
%run ../common.ipynb


Populating the interactive namespace from numpy and matplotlib

In [3]:
image = imread('../MP.tiff')

In [4]:
fft2?

In [7]:
%time numpy_F = fft2(image)


CPU times: user 32.2 s, sys: 153 ms, total: 32.3 s
Wall time: 32.4 s

In [6]:
import pyfftw

In [18]:
pyfftw.interfaces.numpy_fft.fft2?

In [19]:
%time fftw_F = pyfftw.interfaces.numpy_fft.fft2(image)


CPU times: user 9.12 s, sys: 157 ms, total: 9.27 s
Wall time: 9.28 s

In [32]:
numpy.array_equal(numpy_F, fftw_F)


Out[32]:
False

In [22]:
numpy.allclose(numpy_F, fftw_F)


Out[22]:
True

In [26]:
imshow(log(abs(fftshift(numpy_F))))


Out[26]:
(<matplotlib.figure.Figure at 0x11e7888d0>,
 <matplotlib.axes._subplots.AxesSubplot at 0x1265f36d0>,
 <matplotlib.image.AxesImage at 0x12661a190>)

In [27]:
imshow(log(abs(fftshift(fftw_F))))


Out[27]:
(<matplotlib.figure.Figure at 0x114c1e590>,
 <matplotlib.axes._subplots.AxesSubplot at 0x126719c90>,
 <matplotlib.image.AxesImage at 0x1267a7b90>)

In [33]:
# enable cache - http://hgomersall.github.io/pyFFTW/sphinx/tutorial.html#caveat
pyfftw.interfaces.cache.enable()

In [35]:
# now in cache
%time fftw_F = pyfftw.interfaces.numpy_fft.fft2(image)


CPU times: user 671 ms, sys: 50.9 ms, total: 722 ms
Wall time: 720 ms

In [36]:
pyfftw.interfaces.cache.disable()

In [37]:
%time fftw_F = pyfftw.interfaces.numpy_fft.fft2(image)


CPU times: user 684 ms, sys: 33.3 ms, total: 717 ms
Wall time: 716 ms

In [38]:
pyfftw.interfaces.cache.enable()

In [50]:
%time F = pyfftw.interfaces.numpy_fft.fft2(pyfftw.n_byte_align(imread('../MP.tiff'), 16, dtype='uint8'))


CPU times: user 687 ms, sys: 95.4 ms, total: 783 ms
Wall time: 798 ms

In [44]:
F.shape


Out[44]:
(2111, 2198)

In [45]:
pyfftw.n_byte_align_empty?

In [46]:
pyfftw.n_byte_align?