Skip to content

Commit 67de584

Browse files
Merge f9b1af5 into be5c3f0
2 parents be5c3f0 + f9b1af5 commit 67de584

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

dpnp/dpnp_iface_mathematical.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -627,7 +627,7 @@ def around(x, /, decimals=0, out=None):
627627
)
628628

629629

630-
def clip(a, a_min, a_max, *, out=None, order="K", **kwargs):
630+
def clip(a, /, a_min=None, a_max=None, *, out=None, order="K", **kwargs):
631631
"""
632632
Clip (limit) the values in an array.
633633
@@ -639,8 +639,10 @@ def clip(a, a_min, a_max, *, out=None, order="K", **kwargs):
639639
Array containing elements to clip.
640640
a_min, a_max : {dpnp.ndarray, usm_ndarray, None}
641641
Minimum and maximum value. If ``None``, clipping is not performed on
642-
the corresponding edge. Only one of `a_min` and `a_max` may be
643-
``None``. Both are broadcast against `a`.
642+
the corresponding edge. If both ``a_min`` and ``a_max`` are ``None``,
643+
the elements of the returned array stay the same.
644+
Both are broadcast against `a`.
645+
Default : ``None``.
644646
out : {None, dpnp.ndarray, usm_ndarray}, optional
645647
The results will be placed in this array. It may be the input array
646648
for in-place clipping. `out` must be of the right shape to hold the
@@ -687,9 +689,6 @@ def clip(a, a_min, a_max, *, out=None, order="K", **kwargs):
687689
if kwargs:
688690
raise NotImplementedError(f"kwargs={kwargs} is currently not supported")
689691

690-
if a_min is None and a_max is None:
691-
raise ValueError("One of max or min must be given")
692-
693692
if order is None:
694693
order = "K"
695694

tests/third_party/cupy/math_tests/test_misc.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,13 @@ def test_clip_max_none(self, xp, dtype):
126126
a = testing.shaped_arange((2, 3, 4), xp, dtype)
127127
return a.clip(3, None)
128128

129+
# numpy>=2.0 does not raise ValueError with a_min=None, a_max=None
130+
@testing.with_requires("numpy>=2.0")
129131
@testing.for_all_dtypes(no_bool=True, no_complex=True)
130132
def test_clip_min_max_none(self, dtype):
131133
for xp in (numpy, cupy):
132134
a = testing.shaped_arange((2, 3, 4), xp, dtype)
133-
with pytest.raises(ValueError):
134-
a.clip(None, None)
135+
return a.clip(None, None)
135136

136137
@testing.for_all_dtypes(no_complex=True)
137138
@testing.numpy_cupy_array_equal()
@@ -155,8 +156,15 @@ def test_external_clip3(self, xp, dtype):
155156
def test_external_clip4(self, dtype):
156157
for xp in (numpy, cupy):
157158
a = testing.shaped_arange((2, 3, 4), xp, dtype)
158-
with pytest.raises(TypeError):
159-
xp.clip(a, 3)
159+
# dpnp.clip() has default a_min, a_max variables as None
160+
# while numpy.clip() uses np._NoValue(numpy>=2.0)
161+
# or required arguments (numpy<2.0) for a_min, a_max
162+
# and raises TypeError if passing a_min only
163+
if xp is numpy:
164+
with pytest.raises(TypeError):
165+
xp.clip(a, 3)
166+
else:
167+
return xp.clip(a, 3)
160168

161169
@testing.for_all_dtypes(no_complex=True)
162170
@testing.numpy_cupy_array_equal()

0 commit comments

Comments
 (0)