title: Why numba can't compile this for loop?
body: <p>I try to compute the 1-dimensional discrete cosine transformation (Type 2), I am trying to improve my performance with numba.
  I have the following code:</p>
  
  <pre><code>import numpy as np
  import math
  import numba
  
  @numba.jit()
  def epsilon(N:int, i: int) -&gt; float:
      if i == 0 or i == N:
          return math.sqrt(2)/2
      return 1.0
  
  @numba.jit()
  def dct2(a):
      n = len(a)
      y = np.empty([2*n])
      y[:len(a)] = a
      y[n:] = np.flip(a)
      fft = np.fft.fft(y)
      erg = np.empty([n])
      factor = 1/math.sqrt(2*n)
      for i in range(0,n):
          erg[i] = factor*epsilon(n,i)*(math.cos(-i*2*math.pi/(4*n))*fft[i].real - math.sin(-i*2*math.pi/(4*n))*fft[i].imag)
      return erg
  </code></pre>
  
  <p>I think it can't compile the for loop, but I don't know why. From what I understand from the numba Documentation, the loop should be able to be lifted.</p>
  
  <p>I got the following warnings:</p>
  
  <pre><code>In definition 0:
      All templates rejected with literals.
  In definition 1:
      All templates rejected without literals.
  This error is usually caused by passing an argument of a type that is unsupported by the named function.
  [1] During: resolving callee type: Function(&lt;built-in function empty&gt;)
  [2] During: typing of call at src/algos.py (32)
  
  
  File "src/algos.py", line 32:
  def dct2(a):
      &lt;source elided&gt;
      n = len(a)
      y = np.empty([2*n])
   ^
  
    @numba.jit()
  src/algos.py:29: NumbaWarning: Function "dct2" failed type inference: cannot determine Numba type of &lt;class 'numba.dispatcher.LiftedLoop'&gt;
  
  File "src/algos.py", line 39:
  def dct2(a):
      &lt;source elided&gt;
      factor = 1/math.sqrt(2*n)
      for i in range(0,n):
   ^
  
    @numba.jit()
  src/algos.py:29: NumbaWarning: Function "dct2" was compiled in object mode without forceobj=True, but has lifted loops.
    @numba.jit()
  src/algos.py:29: NumbaWarning: Function "dct2" failed type inference: Invalid use of Function(&lt;built-in function empty&gt;) with argument(s) of type(s): (list(int64))
   * parameterized
  </code></pre>
  
  <p>Does anyone know why the loop fails and how I might fix it?</p>