Skip to content

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

Open
antonwolfy wants to merge 3 commits into
masterfrom
fix-interp-nan-at-knots
Open

Fix dpnp.interp returning nan at exact knot when fp contains inf#2986
antonwolfy wants to merge 3 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/pull/2986/index.html

@coveralls

Copy link
Copy Markdown
Collaborator

Coverage Status

coverage: 78.11%. remained the same — 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.0dev2=py313h509198e_13 ran successfully.
Passed: 1372
Failed: 3
Skipped: 5

@antonwolfy antonwolfy marked this pull request as ready for review July 2, 2026 13:58
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.

2 participants