What is currently the best way of dealing with higher order functions in numba?
I implemented the secant method:
def secant_method_curried (f):
def inner (x_minus1, x_0, consecutive_tolerance):
x_new = x_0
x_old = x_minus1
x_oldest = None
while abs(x_new - x_old) > consecutive_tolerance:
x_oldest = x_old
x_old = x_new
x_new = x_old - f(x_old)*((x_old-x_oldest)/(f(x_old)-f(x_oldest)))
return x_new
return numba.jit(nopython=False)(inner)
The issue is that there's no way to tell numba that f
is doube(double)
, so the above code breaks with nopython=True
:
TypingError: Failed at nopython (nopython frontend)
Untyped global name 'f'
It seems like there was a FunctionType in previous versions, but got removed/renamed: http://numba.pydata.org/numba-doc/0.8/types.html#functions
On this page, they mention something called numba.addressof(), which seems kind of helpful, but again dates back 4 years.