question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support for np.fft.fft, np.fft.ifft etc.

See original GitHub issue

Feature request

It would be amazing if numba would support the FFT pack of numpy. Personally, I would be interested in

   np.fft.fft
   np.fft.ifft
   np.fft.rfft
   np.fft.irfft

Obviously, there are many applications in signal processing that could benefit from this.

Are there any plans for that?

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:31
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

8reactions
Sbozzolocommented, Sep 11, 2020

I stumbled upon this thread having the same problem everyone else has: I want to use fft’s routines in my numba functions. What I found is the following (maybe useful for others). If the fft is only a small part of the function, object mode can be used as a good workaround. A sketch of code would look like:

@njit
def myfunc(input)
     .....
     .....
     with objmode(out='complex128[:]'):
            out = np.fft.fft(in)
            # Maybe also out = np.fft.fftshift(out)
     .....
     # heavy computations
     return ...

In my specific case, this is still significantly faster than a pure implementation. Of course, it would be great to have first-class support for these functions.

1reaction
stuartarchibaldcommented, Jun 15, 2020

Thanks for the request. This would be great to have, the reason it hasn’t been done is that it would rely upon:

  1. Some package, e.g. SciPy providing a consistent means of access. Numba uses scipy.linalg.cython_blas and scipy.linalg.cython_lapack as a means of obtaining the addresses of BLAS and LAPACK functions so as to implement numpy.linalg.*, similar would be needed for FFT functions.
  2. There would need to be a “consistent” interface (or subset of an interface) for accessing and using the functions that do the FFT work (e.g. FFTW vs MKL FFT vs … something else). This would likely be more of a challenge to overcome than exposing a raw binding. From memory, the interfaces are quite involved and to get good performance require things like the caching of plans.
Read more comments on GitHub >

github_iconTop Results From Across the Web

Numba for numpy.fft.fft - Community Support
Hello, I am trying to use @jit for optimizing a function using numpy.fft.fft. Below is my code import numpy as np import math...
Read more >
numpy.fft.ifft — NumPy v1.24 Manual
This function computes the inverse of the one-dimensional n-point discrete Fourier transform computed by fft . In other words, ifft(fft(a)) == a to...
Read more >
How to make discrete Fourier transform (FFT) in numba.njit?
The numba documentation mentioned that np.fft.fft is not support. A solution is to use the objmode context ...
Read more >
numpy.fft.ifftn_NumPy中文网
numpy.fft.ifftn · s[0] refers to axis 0, · s[1] to axis 1, etc.). This corresponds to · n for ifft(x, n) . Along...
Read more >
Numpy fft phase - Casale Giacinta
Help numpy. fft import sys from scipy. size n_harm = 50 t = np. ... EXAMPLE: Use fft and ifft function from numpy...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found