(this is not a question about the persistent cache, which has been answered here)
Please consider this simplified example:
import numba as nb
t0 = 0.
y0 = 1.
@nb.njit
def f(t, y):
return -y
@nb.njit
def g(t, y):
return -y
f(t0, y0)
g(t0, y0)
print(f.nopython_signatures)
print(g.nopython_signatures)
yields:
[(float64, array(float64, 1d, C)) -> array(float64, 1d, C)]
[(float64, array(float64, 1d, C)) -> array(float64, 1d, C)]
So both functions have the same signature. I was expecting that the signature of a function that take either f
or g
does not depend on being f
or g
. But:
@nb.njit
def step(rhs, t, y):
return rhs(t+1, 2*y)
step(f, t0, y0)
step(g, t0, y0)
print(step.nopython_signatures)
yields two different signatures:
[
(type(CPUDispatcher(<function f at 0x7fb92e3271f0>)), float64, array(float64, 1d, C)) -> array(float64, 1d, C),
(type(CPUDispatcher(<function g at 0x7fb92fbf90d0>)), float64, array(float64, 1d, C)) -> array(float64, 1d, C)
]
Possible inlining is the only reason that I can think of this behaviour. Is this the reason?
This means that step
is recompiled every time with the associated impact on execution time. Is there a way to avoid this behaviour?