Repository navigation
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #213 +/- ##
==========================================
+ Coverage 98.35% 98.36% +0.01%
==========================================
Files 8 8
Lines 1699 1711 +12
==========================================
+ Hits 1671 1683 +12
Misses 28 28
🚀 New features to boost your workflow:
|
This was referenced Nov 23, 2026
Merged
Compute the Hermite basis weights once per query and broadcast them over the trailing axes of f, instead of forming every cubic's coefficients with a 4x4 matmul per query and trailing element. Index f with scalars for a scalar query, so XLA slices rather than gathers. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Scaling the zero weights of derivatives above the third by dxi**4 gave 0 * inf = nan where that factor overflows. Scale each derivative branch by its own power of dxi, and clamp a negative derivative to 0 as before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Summing the Hermite terms elementwise in half precision rounded every term, where the old matmul ran at full precision. Cast the result back to the dtype of f. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Cast the result to the dtype of f and fx rather than of f alone, compute the weights in at least the precision of f and fx, and take f1 - f0 first so the value weights cancel exactly. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The Hermite basis now returns the weights as polynomials in t together with a single scale (1, dxi, dxi**2 or 6*dxi**3), applied once after the weighted sum. This keeps the rounding of f32 and bf16 derivatives close to the 4x4 matmul it replaces, and the zero branch uses scale 1 so tiny cells never form 0*inf. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
nstarman
force-pushed
the
perf/interp1d-hermite-basis
branch
from
November 24, 2026 14:05
dafa11e to
db98927
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Speeds up cubic
interp1d(and soInterpolator1D), most of all for many trailing axes.Two changes, both in the cubic branch:
f. Before, the coefficients of every cubic were formed with a 4×4 matmul per query and per trailing element, then contracted with[1, t, t², t³].fwith scalars.jnp.atleast_1dmade it a length-1 gather, and a dynamic slice costs about half as much on CPU.The weights are computed in at least float32 and at least the precision of
fandfx. The sum is taken in that precision too.f1 - f0is formed first so the value weights cancel exactly, and thedxi**derivativefactor is applied once to the sum. The result has the dtype off,fxandx, as before.float64 results match
mainto round-off. In float32 and bfloat16 the errors are comparable tomain's and often lower, most of all for float32 derivatives 1 and 2, sincef1 - f0cancels any constant part offexactly. Single datasets can still come out several times worse than onmain.The table shows what I measured: random, sine and offset data with and without
fx, 5 to 15 seeds each, against the same rounded inputs interpolated in float64. The ratio ismain's max error over this PR's max error, so above 1 means this PR is more accurate.The results match
CubicHermiteSplineto 1e-12 for derivatives 0–3, for real and complexf, inside and outside the knots, and for scalar and array queries. Higher derivatives are exactly zero, even on cells small enough that1/dx**4overflows. On the test data, bfloat16 and float16 derivatives 0–2 stay within 3% of the largest value of the same inputs interpolated in float64. That bound is empirical. Complexfxwith realf, and float32 knots with float64 values, keep their dtype and precision. These are the new tests.Timings on CPU, single-threaded XLA, jax 0.8.0, float64, 128 knots,
fof shape(128, 25),fxgiven,extrap=True. "Scalar" is one query per step inside alax.scan.even_spacing=Trued/dxq, scalar queryeven_spacing=TrueThe other methods,
interp2d/interp3dandPPolyare unchanged. The 2D and 3D kernels form their coefficients the same way, so they could get the same treatment in a follow-up.🤖 Generated with Claude Code