BUG: RBFInterpolator is much slower than Rbf for vector data
See original GitHub issueDescribe your issue.
Hi,
In the past ve been using the old RBF interpolator (Rbf) to interpolate between vectors and since it didn’t support the interpolation of vectors, but only scalars, I’ve had to manually extract the matrix of distances from the Rbf object (see code below). Since the new RBFInterpolator now supports interpolation of vectors, I gave it a try and noticed that it is almost a factor of 10 slower in my application and testcase below ( 29.7 s vs 3.9s). While this is technically not a bug, but this is very surprising.
I see that the time is being spent mostly here https://github.com/scipy/scipy/blob/15df2084b0757ace4b0d206ba84a10fbcbfd8aab/scipy/interpolate/_rbfinterp_pythran.py#L175 inside hte pythran evaluation function. I can’t immediately see anything obvious there that could be responsible for the regression though.
I also checked that if I set OMP_NUM_THREADS to 1, the performance difference is reduced but stays factor of 3.5 (10s vs 35s) (so the issue is not due to lack of parallelization of the pythran code)
Thanks
Reproducing Code Example
import numpy as np
import scipy.interpolate
import time
rstate = np.random.default_rng(44)
# initial point distribution
npt = 6000
xs, ys = rstate.normal(size=(2, npt))
# my data vectors are 4000dimensional
nx = 4000
xgrid = np.arange(nx)
data = (xgrid[None, :] * xs[:, None]**2 + ys[:, None]**2)
# number of points
neval = 1000
xnew, ynew = rstate.normal(size=(2, neval))
t1 = time.time()
# use the old interface on 1d data to get coefficients to apply for the
# to the 4000d data vectors
RR = scipy.interpolate.Rbf(xs, ys, data[:, 0])
coeffs = scipy.linalg.solve(RR.A, data)
r = RR._call_norm(np.array([xnew, ynew]), RR.xi)
pred0 = np.dot(RR._function(r), coeffs)
# use the new interface
t2 = time.time()
RR = scipy.interpolate.RBFInterpolator(np.array([xs, ys]).T, data)
pred1 = RR(np.array([xnew, ynew]).T)
t3 = time.time()
print(t2 - t1, t3 - t2)
Error message
None
SciPy/NumPy/Python version information
1.7.3 1.21.4 sys.version_info(major=3, minor=8, micro=10, releaselevel=‘final’, serial=0)
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (7 by maintainers)
@treverhines can you have a look at this issue?
I was planning to submit the PR based on what I have (i.e np.dot outside pythran). Personally I’d prefer not to delve into blas/lapack linking/building stuff/dependencies on pythran version, so if you think that np.dot has to be inside, I’ll let you do it.