[Numpy-discussion] Choosing between NumPy and SciPy functions

Sturla Molden sturla.molden at gmail.com
Tue Oct 28 07:40:26 EDT 2014


Pierre Barbier de Reuille <pierre at barbierdereuille.net> wrote:

> I would add one element to the discussion: for some (odd) reasons, SciPy is
> lacking the functions `rfftn` and `irfftn`, functions using half the memory
> space compared to their non-real equivalent `fftn` and `ifftn`. 

In both NumPy and SciPy the N-dimensional FFTs are implemented in Python.
It is just a Python loop over all the axes, calling fft or rfft on each
axis.

> However, I
> haven't (yet) seriously tested `scipy.fftpack.fftn` vs. `np.fft.rfftn` to
> check if there is a serious performance gain (beside memory usage).

Real-value FFT is implemented with complex-value FFT. You save half the
memory, but not quite half the computation. Apart from that, the FFT in
SciPy is written in Fortran and the FFT in NumPy is written in C, but they
are algorithmically similar. I don't see any good reason why the Fortran
code in SciPy should be faster than the C code in NumPy. It used to be the
case that Fortran was "faster than C", everything else being equal, but
with modern C compilers and CPUs with deep pipelines and branch prediction
this is rarely the case. So I would expect the NumPy rfftn to be slightly
faster than SciPy fftn, but keep in mind that both have a huge Python
overhead.

Sturla




More information about the NumPy-Discussion mailing list