question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

BUG: RBFInterpolator is much slower than Rbf for vector data

See original GitHub issue

Describe 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:closed
  • Created 2 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
tupuicommented, Dec 3, 2021

@treverhines can you have a look at this issue?

0reactions
segasaicommented, Dec 8, 2021

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

RBF interpolation MemoryError: Unable to allocate 97.8 GiB ...
I have the following df of size (162019,3) for which I want to perform RBF interpolation. x , y columns are coordinates of...
Read more >
How can I speed up my compiled RBF interpolating function?
I have a function that acts like the Interpolation on sparse n-dimensional data using a simple implementation of RBF interpolation method. I want...
Read more >
scipy.interpolate.RBFInterpolator — SciPy v1.9.3 Manual
The interpolant perfectly fits the data when this is set to 0. ... An RBF is a scalar valued function in N-dimensional space...
Read more >
A divergence‐free spatial interpolator for large sparse velocity ...
A significant advantage of the “greedy fit” RBF interpolator ... For S-RBFs applied to velocity data, F is the M long vector of...
Read more >
Comparing Machine Learning and Interpolation Methods for ...
to interpolation techniques on seismic data in low dimensions with ... idea of RBF is to write our approximation as a linear combination...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found