Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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` with an empty input array `x` to return an empty array with the correct dtype [#2985](https://github.com/IntelPython/dpnp/pull/2985)

### Security

Expand Down
8 changes: 4 additions & 4 deletions dpnp/dpnp_iface_mathematical.py
Original file line number Diff line number Diff line change
Expand Up @@ -3011,7 +3011,7 @@ def interp(x, xp, fp, left=None, right=None, period=None):
raise ValueError("xp and fp must be 1D arrays")
if xp.size != fp.size:
raise ValueError("fp and xp are not of the same length")
if xp.size == 0:
if xp.size == 0 and x.size != 0:
raise ValueError("array of sample points is empty")

usm_type, exec_q = get_usm_allocations([x, xp, fp])
Expand Down Expand Up @@ -3059,9 +3059,9 @@ def interp(x, xp, fp, left=None, right=None, period=None):
right = _validate_interp_param(right, "right", exec_q, usm_type, fp.dtype)

usm_type, exec_q = get_usm_allocations([x, xp, fp, period, left, right])
output = dpnp.empty(
x.shape, dtype=out_dtype, sycl_queue=exec_q, usm_type=usm_type
)
output = dpnp.empty_like(x, dtype=out_dtype, usm_type=usm_type)
if x.size == 0:
return output

left_usm = left.get_array() if left is not None else None
right_usm = right.get_array() if right is not None else None
Expand Down
37 changes: 17 additions & 20 deletions dpnp/tests/test_mathematical.py
Original file line number Diff line number Diff line change
Expand Up @@ -1140,13 +1140,14 @@ def test_complex(self, xp):


class TestInterp:
@pytest.mark.parametrize(
"dtype_x", get_all_dtypes(no_complex=True, no_none=True)
)
@pytest.mark.parametrize(
"dtype_xp", get_all_dtypes(no_complex=True, no_none=True)
ALL_DTYPES = get_all_dtypes(no_float16=False, no_none=True)
ALL_DTYPES_NO_COMPLEX = get_all_dtypes(
no_float16=False, no_complex=True, no_none=True
)
@pytest.mark.parametrize("dtype_y", get_all_dtypes(no_none=True))

@pytest.mark.parametrize("dtype_x", ALL_DTYPES_NO_COMPLEX)
@pytest.mark.parametrize("dtype_xp", ALL_DTYPES_NO_COMPLEX)
@pytest.mark.parametrize("dtype_y", ALL_DTYPES)
def test_all_dtypes(self, dtype_x, dtype_xp, dtype_y):
x = numpy.linspace(0.1, 9.9, 20).astype(dtype_x)
xp = numpy.linspace(0.0, 10.0, 5).astype(dtype_xp)
Expand All @@ -1160,9 +1161,7 @@ def test_all_dtypes(self, dtype_x, dtype_xp, dtype_y):
result = dpnp.interp(ix, ixp, ifp)
assert_dtype_allclose(result, expected)

@pytest.mark.parametrize(
"dtype_x", get_all_dtypes(no_complex=True, no_none=True)
)
@pytest.mark.parametrize("dtype_x", ALL_DTYPES_NO_COMPLEX)
@pytest.mark.parametrize("dtype_y", get_complex_dtypes())
def test_complex_fp(self, dtype_x, dtype_y):
x = numpy.array([0.25, 0.75], dtype=dtype_x)
Expand All @@ -1177,9 +1176,7 @@ def test_complex_fp(self, dtype_x, dtype_y):
result = dpnp.interp(ix, ixp, ifp)
assert_dtype_allclose(result, expected)

@pytest.mark.parametrize(
"dtype", get_all_dtypes(no_complex=True, no_none=True)
)
@pytest.mark.parametrize("dtype", ALL_DTYPES_NO_COMPLEX)
@pytest.mark.parametrize(
"left, right", [[-40, 40], [dpnp.array(-40), dpnp.array(40)]]
)
Expand Down Expand Up @@ -1216,14 +1213,14 @@ def test_naninf(self, val):
result = dpnp.interp(ix, ixp, ifp)
assert_dtype_allclose(result, expected)

def test_empty_x(self):
x = numpy.array([])
xp = numpy.array([0, 1])
fp = numpy.array([10, 20])

ix = dpnp.array(x)
ixp = dpnp.array(xp)
ifp = dpnp.array(fp)
@testing.with_requires("numpy>=2.5")
@pytest.mark.parametrize(
"x, xp, fp",
[([], [], []), ([], [1, 2], [3, 4]), ([], [1, 2], [3 + 4j, 5 + 6j])],
)
def test_empty_x(self, x, xp, fp):
x, xp, fp = numpy.array(x), numpy.array(xp), numpy.array(fp)
ix, ixp, ifp = dpnp.array(x), dpnp.array(xp), dpnp.array(fp)

expected = numpy.interp(x, xp, fp)
result = dpnp.interp(ix, ixp, ifp)
Expand Down
Loading