I have a minimum example here for trying to create a jitclass with a typed (float64), empty list in the init:
import numba
from numba.experimental import jitclass
@jitclass([('l',numba.types.ListType(numba.types.float64))])
class test:
def __init__(self):
l = []
test()
This throws the errror:
TypingError: Failed in nopython mode pipeline (step: nopython frontend)
Failed in nopython mode pipeline (step: nopython frontend)
Cannot infer the type of variable 'l', have imprecise type: list(undefined)<iv=None>.
For Numba to be able to compile a list, the list must have a known and
precise type that can be inferred from the other variables. Whilst sometimes
the type of empty lists can be inferred, this is not always the case, see this
documentation for help:
https://numba.readthedocs.io/en/stable/user/troubleshoot.html#my-code-has-an-untyped-list-problem
File "../../../../tmp/ipykernel_18992/3659426322.py", line 8:
<source missing, REPL/exec in use?>
During: resolving callee type: jitclass.test#7f4e6fdbde70<l:ListType[float64]>
During: typing of call at <string> (3)
During: resolving callee type: jitclass.test#7f4e6fdbde70<l:ListType[float64]>
During: typing of call at <string> (3)
File "<string>", line 3:
<source missing, REPL/exec in use?>
In contrast, when I create a non-empty list instead it works:
@jitclass([('l',numba.types.ListType(numba.types.float64))])
class test:
def __init__(self):
l = [0.0]
test()
gives:
<numba.experimental.jitclass.boxing.test at 0x7f4e7081ab00>
How can I create an empty, typed list inside this class?
Thanks!