Skip to content

Fix dpnp.interp returning nan at exact knot when fp contains inf#2986

Merged
antonwolfy merged 4 commits into
masterfrom
fix-interp-nan-at-knots
Jul 15, 2026
Merged

Fix dpnp.interp returning nan at exact knot when fp contains inf#2986
antonwolfy merged 4 commits into
masterfrom
fix-interp-nan-at-knots

Conversation

@antonwolfy

@antonwolfy antonwolfy commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

dpnp.interp returned NaN when a query point landed exactly on an interior knot of xp and the adjacent fp value was Inf. Interpolating at such a point should return the knot value directly.

The root cause is IEEE-754 arithmetic in the linear formula: when fp[x_idx+1] is inf, slope becomes Inf, and since x_val - xp[x_idx] == 0 at the knot, the result is inf * 0 = nan. The existing NaN-recovery fallback also yields nan in this case.

import dpnp as np

x = np.array([2.0])
xp = np.array([1.0, 2.0, 3.0, 4.0])
fp = np.array([1.0, 2.0, np.inf, 4.0])
np.interp(x, xp, fp)
# before: array([nan])
# after:  array([2.])   (matches numpy.interp)
  • Have you provided a meaningful PR description?
  • Have you added a test, reproducer or referred to an issue with a reproducer?
  • Have you tested your changes locally for CPU and GPU devices?
  • Have you made sure that new changes do not introduce compiler warnings?
  • Have you checked performance impact of proposed changes?
  • Have you added documentation for your changes, if necessary?
  • Have you added your changes to the changelog?

@antonwolfy antonwolfy added this to the 0.21.0 release milestone Jul 2, 2026
@antonwolfy antonwolfy self-assigned this Jul 2, 2026
@github-actions

github-actions Bot commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

View rendered docs @ https://intelpython.github.io/dpnp/index.html

@coveralls

coveralls commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator

Coverage Status

No base build to compare — fix-interp-nan-at-knots into master

@github-actions

github-actions Bot commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Array API standard conformance tests for dpnp=0.21.0dev3=py313h509198e_6 ran successfully.
Passed: 1373
Failed: 2
Skipped: 5

@antonwolfy antonwolfy marked this pull request as ready for review July 2, 2026 13:58

@vlad-perevezentsev vlad-perevezentsev 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.

LGTM
Thank you @antonwolfy

@antonwolfy antonwolfy merged commit b05c07a into master Jul 15, 2026
76 of 82 checks passed
@antonwolfy antonwolfy deleted the fix-interp-nan-at-knots branch July 15, 2026 12:36
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