When attempting to compile a function with variable positional arguments and different signatures simultaneously, a “RuntimeError: compilation disabled” error occurs. The problem appears to be related to the use of a variable-sized tuple (args) in the function, making Numba’s type inference and compilation system unable to handle the varying argument types.
Can somebody explain this behavior?
The error does not appear if I call the functions with different signatures one by one.
Now Numba is able to compile the functions even with multiple different signatures.
Here is an example:
from numba import njit
import numba.types as nbt
@njit(['f8(f8)'])
def fn_A(a): # noqa
return a
@njit(['f8(f8,f8)'])
def fn_B(a, b): # noqa
return a+b
def func(fn, *args): # noqa
return fn(*args)
signature_A = nbt.f8(
nbt.FunctionType(nbt.f8(nbt.f8)),
nbt.Tuple((nbt.f8,)))
signature_B = nbt.f8(
nbt.FunctionType(nbt.f8(nbt.f8, nbt.f8)),
nbt.Tuple((nbt.f8, nbt.f8)))
signature_AB = [signature_A, signature_B]
print('Function pointer A:')
eager_func = njit(signature_A)(func)
print(eager_func(fn_A, 10.0))
print(eager_func.signatures)
print()
print('Function pointer B:')
eager_func = njit(signature_B)(func)
print(eager_func(fn_B, 10.0, 5.0))
print(eager_func.signatures)
print()
print('Function pointer A & B:')
eager_func = njit(signature_AB)(func)
print(eager_func(fn_A, 10.0))
print(eager_func(fn_B, 10.0, 5.0))
print(eager_func.signatures)
print()
# Function pointer A & B:
# 10.0
# 15.0
# [(FunctionType[float64(float64)], UniTuple(float64, 1)), (FunctionType[float64(float64, float64)], UniTuple(float64, 2))]