EconForge / interpolation.py

BSD 2-Clause "Simplified" License
123 stars 35 forks source link

eval_linear raises numba error on master #78

Closed thomasaarholt closed 3 years ago

thomasaarholt commented 3 years ago

Hiya!

First off - thanks for writing this! It's blazing fast - interpolating 17161 points on a regular 2d grid with equally many pixels takes 229ms with scipy and 4.29ms with interpolation! That's a 53x speedup!

The issue below is just in case you are unaware - I have instead installed the current conda version and numba=0.49 and things are working fine.

With the latest master, eval_linear is raising a large error when called as in the readme example here on github. It hints at the out argument not being present, but when included it includes an equally long error that is harder for me to take apart. I would have pasted the entire error here, but I accidentally wiped it after installing the older version. I suggest you just run the following (from Readme.md) and see:

import numpy as np

from interpolation.splines import UCGrid, CGrid, nodes

# we interpolate function
f = lambda x,y: np.sin(np.sqrt(x**2+y**2+0.00001))/np.sqrt(x**2+y**2+0.00001)

# uniform cartesian grid
grid = UCGrid((-1.0, 1.0, 10), (-1.0, 1.0, 10))

# get grid points
gp = nodes(grid)   # 100x2 matrix

# compute values on grid points
values = f(gp[:,0], gp[:,1]).reshape((10,10))

from interpolation.splines import eval_linear
# interpolate at one point
point = np.array([0.1,0.45]) # 1d array
val = eval_linear(grid, values, point)  # float

# interpolate at many points:
points = np.random.random((10000,2))
eval_linear(grid, values, points) # 10000 vector

# output can be preallocated
out = np.zeros(10000)
eval_linear(grid, values, points, out) # 10000 vector
albop commented 3 years ago

Strange, I just ran the code you pasted with latest numba and with numba 0.49, but there is no error.

Can you give your platform, the numba version and paste the error message ?

thomasaarholt commented 3 years ago

Intriguing! I just tried with a fresh conda environment, and now it works fine! I must have done something odd, but I'm not sure what - the code was definitely complaining the the out parameters wasn't set. Regardless, closing this - will reopen if it happens again!