If I try to compile a function containing an array of conditions with a numba jit compiler, it will take a very long time. The program looks essentially like
from numba import jit
import numpy as np
@jit(nopython=True)
def foo(a, b):
valid = [
(a - 1 >= 0) and (b - 1 >= 0),
(a - 1 >= 0) and (b - 1 >= 0),
(a - 1 >= 0) and (b - 1 >= 0),
(a - 1 >= 0) and (b - 1 >= 0),
(a - 1 >= 0) and (b - 1 >= 0),
(a - 1 >= 0) and (b - 1 >= 0),
(a - 1 >= 0) and (b - 1 >= 0),
(a - 1 >= 0) and (b - 1 >= 0),
(a - 1 >= 0) and (b - 1 >= 0),
(a - 1 >= 0) and (b - 1 >= 0),
(a - 1 >= 0) and (b - 1 >= 0),
(a - 1 >= 0) and (b - 1 >= 0),
(a - 1 >= 0) and (b - 1 >= 0),
(a - 1 >= 0) and (b - 1 >= 0),
(a - 1 >= 0) and (b - 1 >= 0),
(a - 1 >= 0) and (b - 1 >= 0),
(a - 1 >= 0) and (b - 1 >= 0),
(a - 1 >= 0) and (b - 1 >= 0),
(a - 1 >= 0) and (b - 1 >= 0),
(a - 1 >= 0) and (b - 1 >= 0),
(a - 1 >= 0) and (b - 1 >= 0),
(a - 1 >= 0) and (b - 1 >= 0),
(a - 1 >= 0) and (b - 1 >= 0)
]
foo(1, 1)
where I ruled out everything that won't change compile time significantly. The problem arises if I use more than 20 elements.
| elements | time |
-------------------
| 21 | 2.7s |
| 22 | 5.1s |
| 23 | 10s |
| ... | ... |
-------------------
Despite this, the function works well. Does anyone know why it takes so long to compile such a function with numba? Creating arrays in the same way with combinations of integers or floats does not cause problems.
source
share