-
Notifications
You must be signed in to change notification settings - Fork 15
Open
Description
Hello,
I've tried the following test code, which does 2d interpolation, and fast_interp is slower than scipy by three orders of magnitude. Is there something obvious I am doing wrong?
import fast_interp
import numpy as np
import time
import scipy.interpolate as interpolate
nx = 50
ny = 37
xv, xh = np.linspace(0, 1, nx, endpoint=True, retstep=True)
yv, yh = np.linspace(0, 2*np.pi, ny, endpoint=False, retstep=True)
x, y = np.meshgrid(xv, yv, indexing='ij')
test_function = lambda x, y: np.exp(x)*np.exp(np.sin(y))
f = test_function(x, y)
n = 128**2
test_x = np.random.rand(n)
test_y = np.random.rand(n)
t0 = time.time()
interpolater = fast_interp.interp2d([0,0], [1,2*np.pi], [xh,yh], f, k=1, p=[False,False], e=[0,0])
fe = interpolater(test_x, test_y)
t1 = time.time()
print(t1-t0)
cpdf = interpolate.RegularGridInterpolator((xv,yv),f,method="linear",fill_value=0.,bounds_error=False)((test_x,test_y))
t2 = time.time()
print(t2-t1)
I get t1-t0 = 2.1 s (fast_interp) and t2-t1 = 0.008 s (scipy).
Metadata
Metadata
Assignees
Labels
No labels