Currently the best way to work 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 problem is that there is no way to tell numba what to feat doube(double), so the code above breaks into nopython=True:
TypingError: Failed at nopython (nopython frontend)
Untyped global name 'f'
It looks like there was a FunctionType in previous versions, but was deleted / renamed: http://numba.pydata.org/numba-doc/0.8/types.html#functions
On this page, they mention something like numba.addressof (), which seems useful but dates back to 4 years.
source
share