title: How to make discrete Fourier transform (FFT) in numba.njit?
body: <p>Hello fellow programmers</p>
  
  <p>I am trying to make a <code>discrete Fourier transform</code> in this <code>minimal working example</code> with the <code>numba.njit</code> decorator:</p>
  
  <pre><code>import numba
  import numpy as np
  import scipy
  import scipy.fftpack
  
  @numba.njit
  def main():
      wave = [[[0.09254795,  0.10001078,  0.10744892, 0.07755555,  0.08506225, 0.09254795],
            [0.09907245,  0.10706145,  0.11502401,  0.08302302,  0.09105898, 0.09907245],
            [0.09565098,  0.10336405,  0.11105158,  0.08015589,  0.08791429, 0.09565098],
            [0.00181467,  0.001961,    0.00210684,  0.0015207,   0.00166789, 0.00181467]],
           [[-0.45816267, - 0.46058367, - 0.46289091, - 0.45298182, - 0.45562851, -0.45816267],
            [-0.49046506, - 0.49305676, - 0.49552669, - 0.48491893, - 0.48775223, -0.49046506],
            [-0.47352483, - 0.47602701, - 0.47841162, - 0.46817027, - 0.4709057, -0.47352483],
            [-0.00898358, - 0.00903105, - 0.00907629, - 0.008882, - 0.00893389, -0.00898358]],
           [[0.36561472,  0.36057289,  0.355442,  0.37542627,  0.37056626, 0.36561472],
            [0.39139261,  0.38599531,  0.38050268,  0.40189591,  0.39669325, 0.39139261],
            [0.37787385,  0.37266296,  0.36736003,  0.38801438,  0.38299141, 0.37787385],
            [0.00716892,  0.00707006,  0.00696945,  0.0073613,  0.00726601, 0.00716892]]]
  
      new_fft = scipy.fftpack.fft(wave)
  
  
  if __name__ == '__main__':
      main()
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>C:\Users\Artur\Anaconda\python.exe C:/Users/Artur/Desktop/RL_framework/help_functions/test2.py
  Traceback (most recent call last):
    File "C:/Users/Artur/Desktop/RL_framework/help_functions/test2.py", line 25, in &lt;module&gt;
      main()
    File "C:\Users\Artur\Anaconda\lib\site-packages\numba\core\dispatcher.py", line 401, in _compile_for_args
      error_rewrite(e, 'typing')
    File "C:\Users\Artur\Anaconda\lib\site-packages\numba\core\dispatcher.py", line 344, in error_rewrite
      reraise(type(e), e, None)
    File "C:\Users\Artur\Anaconda\lib\site-packages\numba\core\utils.py", line 80, in reraise
      raise value.with_traceback(tb)
  numba.core.errors.TypingError: Failed in nopython mode pipeline (step: nopython frontend)
  Unknown attribute 'fft' of type Module(&lt;module 'scipy.fftpack' from 'C:\\Users\\Artur\\Anaconda\\lib\\site-packages\\scipy\\fftpack\\__init__.py'&gt;)
  
  File "test2.py", line 21:
  def main():
      &lt;source elided&gt;
  
      new_fft = scipy.fftpack.fft(wave)
      ^
  
  [1] During: typing of get attribute at C:/Users/Artur/Desktop/RL_framework/help_functions/test2.py (21)
  
  File "test2.py", line 21:
  def main():
      &lt;source elided&gt;
  
      new_fft = scipy.fftpack.fft(wave)
      ^
  
  
  Process finished with exit code 1
  </code></pre>
  
  <p>Unfortunately <code>scipy.fftpack.fft</code> seems to be a legacy function that is not supported by <code>numba</code>. So I searched for alternatives. I found two:</p>
  
  <p>1.
  <code>scipy.fft(wave)</code> which is the updated version of the above mentioned legacy function. It produces this error output:</p>
  
  <pre><code>C:\Users\Artur\Anaconda\python.exe C:/Users/Artur/Desktop/RL_framework/help_functions/test2.py
  Traceback (most recent call last):
    File "C:/Users/Artur/Desktop/RL_framework/help_functions/test2.py", line 25, in &lt;module&gt;
      main()
    File "C:\Users\Artur\Anaconda\lib\site-packages\numba\core\dispatcher.py", line 401, in _compile_for_args
      error_rewrite(e, 'typing')
    File "C:\Users\Artur\Anaconda\lib\site-packages\numba\core\dispatcher.py", line 344, in error_rewrite
      reraise(type(e), e, None)
    File "C:\Users\Artur\Anaconda\lib\site-packages\numba\core\utils.py", line 80, in reraise
      raise value.with_traceback(tb)
  numba.core.errors.TypingError: Failed in nopython mode pipeline (step: nopython frontend)
  Invalid use of Module(&lt;module 'scipy.fft' from 'C:\\Users\\Artur\\Anaconda\\lib\\site-packages\\scipy\\fft\\__init__.py'&gt;) with parameters (list(list(list(float64))))
  No type info available for Module(&lt;module 'scipy.fft' from 'C:\\Users\\Artur\\Anaconda\\lib\\site-packages\\scipy\\fft\\__init__.py'&gt;) as a callable.
  [1] During: resolving callee type: Module(&lt;module 'scipy.fft' from 'C:\\Users\\Artur\\Anaconda\\lib\\site-packages\\scipy\\fft\\__init__.py'&gt;)
  [2] During: typing of call at C:/Users/Artur/Desktop/RL_framework/help_functions/test2.py (21)
  
  
  File "test2.py", line 21:
  def main():
      &lt;source elided&gt;
  
      new_fft = scipy.fft(wave)
      ^
  
  
  Process finished with exit code 1
  </code></pre>
  
  <p>2.
  <code>np.fft.fft(wave)</code> which seems to be supported but also produces an error:</p>
  
  <pre><code>C:\Users\Artur\Anaconda\python.exe C:/Users/Artur/Desktop/RL_framework/help_functions/test2.py
  Traceback (most recent call last):
    File "C:/Users/Artur/Desktop/RL_framework/help_functions/test2.py", line 25, in &lt;module&gt;
      main()
    File "C:\Users\Artur\Anaconda\lib\site-packages\numba\core\dispatcher.py", line 401, in _compile_for_args
      error_rewrite(e, 'typing')
    File "C:\Users\Artur\Anaconda\lib\site-packages\numba\core\dispatcher.py", line 344, in error_rewrite
      reraise(type(e), e, None)
    File "C:\Users\Artur\Anaconda\lib\site-packages\numba\core\utils.py", line 80, in reraise
      raise value.with_traceback(tb)
  numba.core.errors.TypingError: Failed in nopython mode pipeline (step: nopython frontend)
  Unknown attribute 'fft' of type Module(&lt;module 'numpy.fft' from 'C:\\Users\\Artur\\Anaconda\\lib\\site-packages\\numpy\\fft\\__init__.py'&gt;)
  
  File "test2.py", line 21:
  def main():
      &lt;source elided&gt;
  
      new_fft = np.fft.fft(wave)
      ^
  
  [1] During: typing of get attribute at C:/Users/Artur/Desktop/RL_framework/help_functions/test2.py (21)
  
  File "test2.py", line 21:
  def main():
      &lt;source elided&gt;
  
      new_fft = np.fft.fft(wave)
      ^
  
  
  Process finished with exit code 1
  </code></pre>
  
  <p>Do you know a <code>fft</code> function, that works with the <code>numba.njit</code> decorator?</p>