Repository navigation
Conversation
Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: Claude <noreply@anthropic.com>
|
Some background on why this works and why scipy doesn't do it already: Why solving one dimension at a time is exact. On a regular grid, the values are interpolated at every combination of grid points. So the collocation matrix of the n-D spline is the Kronecker product of the 1-D collocation matrices, What scipy does instead. Downsides. None that I can see for
This could be fixed in scipy too, which would help other |
🏎️ New personal best! Some benchmarks got better.
🚀 better · 🐌 worse · 💥 now failing · 🩹 fixed · 🤷 not comparable Comparing |
spsolve on the 100x30x10 test grid takes minutes for quintic and timed out on CI; gcrotmk with rtol=1e-12 is accurate to ~1e-13 in under a second. Co-authored-by: Claude <noreply@anthropic.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
scipy-stubs types the RegularGridInterpolator solver as returning an array and solver_args as a tuple, but scipy calls iterative solvers as x, info = solver(A, b, **solver_args). Pass them via a dict[str, Any]. Co-authored-by: Claude <noreply@anthropic.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
I opened an upstream issue for that. Maybe it's better to fix this at the source instead of ugly custom builds here. Thoughts? |
dcherian
left a comment
There was a problem hiding this comment.
On the whole, I think this is worth it. We maintain vendored functions for efficiency and backcompat already. It would definitely be good to upstream. In the meantime, we could stick these functions in scipy_compat.py for example, following current code conventions.
I'll leave it to your judgement.
If you'd like to merge, please add some property tests comparing the output to scipy for random inputs. Another property could be the interp of a 1D vector shoul dmatch the interp of that vector broadcasted out to nD.
|
It seems that scipy is very interested in getting this patch. I might work on that, so maybe this PR is not necessary. I don't think we really need a compatiblity layer in that case. If you want it faster, update your scipy. |
|
Great. As an aside, I loved that thread. Great example of how LLMs can help out OSS! |
Multidimensional
interpwithmethod="cubic"/"quintic"usedscipy.interpolate.interpn, which builds the collocation matrix of the whole grid and solves it with an iterative sparse solver (gcrotmk,atol=1e-6). That is slow, needs a lot of memory and is only accurate to ~1e-6 (~1e-5 for quintic).Solve for the tensor-product spline coefficients one dimension after the other with
make_interp_splineand evaluate them withNdBSpline. This is exact and keeps theinterpnsemantics (bounds_error,fill_value, NaN destinations, any destination layout).Single point in a
(288, 71, 73)array (the example from xarray interp with method="cubic" fails for time/lon/lat interpolation #11342): 6.5 s / 1.8 GB → 0.45 s / 67 MB.Tests compare against scipy with a direct solver;
test_interpolate_nduses that reference for spline methods too, because quinticinterpnexceeds the defaultrtol.New asv benchmarks
InterpolationSplineND/InterpolationSplineNDDask(time for a point, a grid and pointwise destinations, plus peak memory).Compatible with Fix interp performance regression for vectorized interpolation #11681 (merges cleanly, only the interpolator passed to
apply_ufuncchanges).Closes xarray interp with method="cubic" fails for time/lon/lat interpolation #11342
Tests added
User visible changes (including notable bug fixes) are documented in
whats-new.rstAI Disclosure
🤖 Generated with Claude Code