diff --git a/CHANGELOG.md b/CHANGELOG.md index 70bf2a61a103..aea9237ad9ac 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -60,6 +60,7 @@ This release is compatible with NumPy 2.5. * Fixed `icx`/`icpx` warning during `conda build` by stripping the GCC-only `-fno-merge-constants` flag injected by conda-forge into `CFLAGS`/`CXXFLAGS` [#2978](https://github.com/IntelPython/dpnp/pull/2978) * Fixed `dpnp.asnumpy` and `dpnp.ndarray.asnumpy` ignoring the `order` keyword, which caused a non-contiguous source array to be returned with a non-contiguous layout even when `order="C"` was requested [#2980](https://github.com/IntelPython/dpnp/pull/2980) * 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 `dpnp.interp` returning `nan` when querying at an exact knot point whose adjacent `fp` value is `inf` [#2985](https://github.com/IntelPython/dpnp/pull/2985) ### Security diff --git a/dpnp/backend/kernels/elementwise_functions/interpolate.hpp b/dpnp/backend/kernels/elementwise_functions/interpolate.hpp index c85dafea24b0..704820ad3c1e 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 930930d18f47..f478e0fbf4d7 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())