5

So here's what my code looks like:

@jit(nopython=True)
def sum_fn(arg1, arg2, ...argn):
    .....
    for i in xrange(len(arg2)): #For each bin
        l, p = fn1(arg1, arg2...argn) 
        res = res + fn2(arg1, arg2, arg3) 
    return res

@jit(nopython=True)
def fn1(a1, a2,...an):
    ....
    return r1, r2

def fn2(l_lk, l_pk, l_lvals):
        f_i = interp1d(l_lk, l_pk,kind='linear') #Scipy.interpolate.interp1d
        ftmp = fn3(f_i,l_lk,l_pk)
        return 10**ftmp(l_lvals)

It appears that calling fn2 gives an error because it isn't being imported into the numba compilation process, unlike fn1, which is jitted. Unfortunately, I cannot jit fn2 because it uses the scipy.interpolate.interp1d function which isn't recognized by Numba. How can I work around this?

1 Answer 1

4

You can't call a non-jitted function from within a function that is jitted with nopython=True. The former is by definition a python function. Your only real option is to write your own version of interp1d as a jitted function (again with nopython=True). Sometimes it is simple to strip out the functionality you need by looking at the source of the original scipy or numpy function. Unfortunately sometimes it's pretty difficult.

The following library might be helpful:

https://github.com/EconForge/interpolation.py

2
  • I did try writing a linear interpolator myself and then using numba on it. But at least on the trial data, the scipy interpolator worked significantly faster than the linear interpolator I wrote+numba. Can this be a possibility or does this mean I've written the interpolator code extremely inefficiently? Thanks for the library, I will take a look at it.
    – Neodymia
    Commented Jul 10, 2017 at 20:03
  • It's hard to say why your linear interpolation scheme is less efficient than the one in scipy without looking at it, but it should be possible to get something going that is pretty similar in performance I would guess.
    – JoshAdel
    Commented Jul 10, 2017 at 21:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.