Thanks @luk-f-a for the reply. I wrote a simple example:
import numba
@numba.njit()
def f1(x, y):
return x + y
@numba.njit()
def f2(x, y):
return x + y
f1(1., 2.)
f2(1., 2.)
f_list = numba.typed.List()
f_list.append(f1)
f_list.append(f2)
@numba.jitclass([('funcs', numba.typeof(f_list))])
class Handler:
def __init__(self, funcs):
self.funcs = funcs
Handler(f_list)
which fails in the seccond append:
Traceback (most recent call last):
...
numba.core.errors.TypingError: Failed in nopython mode pipeline (step: nopython frontend)
- Resolution failure for literal arguments:
No implementation of function Function(<function impl_append at 0x7fe3c8da6550>) found for signature:
>>> impl_append(ListType[type(CPUDispatcher(<function f1 at 0x7fe3c8c143a0>))], type(CPUDispatcher(<function f2 at 0x7fe3c8de1430>)))
There are 2 candidate implementations:
- Of which 2 did not match due to:
Overload in function 'impl_append': File: numba/typed/listobject.py: Line 589.
With argument(s): '(ListType[type(CPUDispatcher(<function f1 at 0x7fe3c8c143a0>))], type(CPUDispatcher(<function f2 at 0x7fe3c8de1430>)))':
Rejected as the implementation raised a specific error:
LoweringError: Failed in nopython mode pipeline (step: nopython mode backend)
Cannot cast type(CPUDispatcher(<function f2 at 0x7fe3c8de1430>)) to type(CPUDispatcher(<function f1 at 0x7fe3c8c143a0>)): %".21" = load i8*, i8** %"item"
File "../../../../../anaconda3/envs/sci38/lib/python3.8/site-packages/numba/typed/listobject.py", line 597:
def impl(l, item):
casteditem = _cast(item, itemty)
^
During: lowering "$8call_function.3 = call $2load_global.0(item, $6load_deref.2, func=$2load_global.0, args=[Var(item, listobject.py:597), Var($6load_deref.2, listobject.py:597)], kws=(), vararg=None)" at /Users/grecco/anaconda3/envs/sci38/lib/python3.8/site-packages/numba/typed/listobject.py (597)
raised from /Users/grecco/anaconda3/envs/sci38/lib/python3.8/site-packages/numba/core/utils.py:81
- Resolution failure for non-literal arguments:
None
During: resolving callee type: BoundFunction((<class 'numba.core.types.containers.ListType'>, 'append') for ListType[type(CPUDispatcher(<function f1 at 0x7fe3c8c143a0>))])
During: typing of call at /Users/grecco/anaconda3/envs/sci38/lib/python3.8/site-packages/numba/typed/typedlist.py (66)
File "../../../../../anaconda3/envs/sci38/lib/python3.8/site-packages/numba/typed/typedlist.py", line 66:
def _append(l, item):
l.append(item)
^
Python: 3.8.2
Numba: 0.51.2