Skip to content

Prevent intermediate overflow in Akima spline weighted derivatives - #351

Open
JackieTien97 wants to merge 2 commits into
apache:masterfrom
JackieTien97:ty/akima-normalize-weights
Open

JackieTien97 wants to merge 2 commits into
apache:masterfrom
JackieTien97:ty/akima-normalize-weights

Conversation

@JackieTien97

@JackieTien97 JackieTien97 commented Nov 7, 2026 •

Copy link
Copy Markdown

Finite samples can produce NaN in Akima interpolation because the weighted slope products overflow before division. For example, with x = {0, 2, 4, 6, 8} and y = {0, 1e200, 0, 1e200, 0}, evaluating the interpolant at 3 returns NaN instead of approximately 5e199.

Preserve the existing calculation when the intermediate sums are finite and at least one weighted product is nonzero. Otherwise, normalize the two weights before forming the convex combination of slopes. Keeping the existing arithmetic for representable products preserves small contributions when the weights have very different magnitudes; unconditionally normalizing those weights can itself underflow a weight.

Add regression coverage for:

  • Large finite samples in both original and modified Akima interpolation.
  • Scale invariance at 1e200, -1e200, and 1e-200 in both modes.
  • Highly unbalanced weights: y = {1e-200, 0, 0, 1e200, 1e200} must retain the value -1.875e-201 at x = 3 in both modes.

Also add a release-note entry.

Validation:

  • The four new overflow/scale regressions fail on the unmodified base revision.
  • Full mvn clean verify passes: 3,828 tests reported, 33 skipped, no failures or errors.

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 87.21%. Comparing base (f554608) to head (c6ced52).
⚠️ Report is 412 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff              @@
##             master     #351      +/-   ##
============================================
+ Coverage     86.54%   87.21%   +0.67%     
+ Complexity     9787       91    -9696     
============================================
  Files           532      499      -33     
  Lines         35516    33535    -1981     
  Branches       6194     5853     -341     
============================================
- Hits          30738    29249    -1489     
+ Misses         3518     3160     -358     
+ Partials       1260     1126     -134     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@aherbert aherbert left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix. I would suggest also raising an exception if the differences overflow and there are regions in the interpolator that will not work.

final double weightedP = wP * differences[i - 1];
final double weightedM = wM * differences[i];
final double weightedSum = weightedP + weightedM;
final double weightSum = wP + wM;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that prior to this step the computation of the computation of the differences can also overflow. Feel free to investigate if that can be recovered. Otherwise I suggest raising an exception for an interpolator that will not work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants