diff --git a/CHANGELOG.md b/CHANGELOG.md index 752240a4734..a7fa2f1ee74 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -67,6 +67,7 @@ This release is compatible with NumPy 2.5. * Fixed `dpnp.tensor.acosh` and `dpnp.tensor.acos` returning infinity for complex numbers with large negative real parts [#2928](https://github.com/IntelPython/dpnp/pull/2928) * Fixed `__array_namespace_info__().devices()` and `.default_device()` to return Python array API compatible device objects [#2979](https://github.com/IntelPython/dpnp/pull/2979) * Fixed `dpnp.interp` with an empty input array `x` to return an empty array with the correct dtype [#2985](https://github.com/IntelPython/dpnp/pull/2985) +* Fixed `dpnp.interp` returning `nan` when querying at an exact knot point whose adjacent `fp` value is `inf` [#2986](https://github.com/IntelPython/dpnp/pull/2986) ### Security diff --git a/dpnp/backend/kernels/elementwise_functions/interpolate.hpp b/dpnp/backend/kernels/elementwise_functions/interpolate.hpp index c85dafea24b..704820ad3c1 100644 --- a/dpnp/backend/kernels/elementwise_functions/interpolate.hpp +++ b/dpnp/backend/kernels/elementwise_functions/interpolate.hpp @@ -88,6 +88,9 @@ class InterpolateFunctor else if (x_idx >= static_cast(xp_size - 1)) { out[id] = right_val; } + else if (x_val == xp[x_idx]) { + out[id] = fp[x_idx]; + } else { TValue slope = (fp[x_idx + 1] - fp[x_idx]) / (xp[x_idx + 1] - xp[x_idx]); diff --git a/dpnp/tests/third_party/cupy/math_tests/test_misc.py b/dpnp/tests/third_party/cupy/math_tests/test_misc.py index 930930d18f4..f478e0fbf4d 100644 --- a/dpnp/tests/third_party/cupy/math_tests/test_misc.py +++ b/dpnp/tests/third_party/cupy/math_tests/test_misc.py @@ -626,6 +626,18 @@ def test_interp_inf_to_nan(self, xp, dtype_y, dtype_x): fy = xp.asarray([0, 10], dtype=dtype_y) return xp.interp(x, fx, fy) + @testing.for_float_dtypes(name="dtype_x") + @testing.for_dtypes("efdFD", name="dtype_y") + @testing.numpy_cupy_allclose(atol=1e-5, type_check=has_support_aspect64()) + def test_interp_inf_fy_at_knot(self, xp, dtype_y, dtype_x): + # Regression test: querying at an exact knot point should return the + # knot value, not nan, even when the adjacent fy value is inf. + # See https://github.com/cupy/cupy/issues/9823 + x = xp.asarray([2.0], dtype=dtype_x) + fx = xp.asarray([1.0, 2.0, 3.0, 4.0], dtype=dtype_x) + fy = xp.asarray([1.0, 2.0, xp.inf, 4.0], dtype=dtype_y) + return xp.interp(x, fx, fy) + @testing.for_all_dtypes(name="dtype_2", no_bool=True, no_complex=True) @testing.for_all_dtypes(name="dtype_1", no_bool=True, no_complex=True) @testing.numpy_cupy_array_equal(type_check=has_support_aspect64())