mathnet-numerics
mathnet-numerics copied to clipboard
Added segment index caching for more efficient interpolation of large…
I added a cache to linear, cubic, and quadratic spline interpolators to prevent unnecessary binary searches.
Very simply, it won't redo a binary search if the last returned index is valid for the current query.
Thanks for proposing this change! It does indeed likely improve performance on typical use cases.
Unfortunately it does seem like this could break in multi-threaded use cases though, i.e. when the resulting interpolation is used concurrently from multiple threads.
Gotcha. I can change the caches to ThreadLocal caches if that would help.
Also, I have n-degree lagrange and hermite polynomial interpolators that implement IInterpolation if you're interested. The algorithms were borrowed from JPL's SPICE toolkit.
@cdrnet Added thread-local caches. In my testing this substantially improves performance, especially when abscissa are sparse and queries are dense.
In other news, I'm not rightfully sure why those checks would have failed.