Skip to content

Commit fbdd634

Browse files
Merge pull request #1759 from IntelPython/fix-gh-1744-clip-out-of-bounds-scalars
Fix gh 1744 clip out of bounds scalars
2 parents 9403f76 + 635dc84 commit fbdd634

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

dpctl/tensor/_clip.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,11 @@ def clip(x, /, min=None, max=None, out=None, order="K"):
404404
)
405405
if order not in ["K", "C", "F", "A"]:
406406
order = "K"
407+
if x.dtype.kind in "iu":
408+
if isinstance(min, int) and min <= dpt.iinfo(x.dtype).min:
409+
min = None
410+
if isinstance(max, int) and max >= dpt.iinfo(x.dtype).max:
411+
max = None
407412
if min is None and max is None:
408413
exec_q = x.sycl_queue
409414
orig_out = out

dpctl/tests/test_tensor_clip.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -767,3 +767,11 @@ def test_clip_readonly_out():
767767

768768
with pytest.raises(ValueError):
769769
dpt.clip(x, out=r)
770+
771+
772+
def test_clip_gh_1744():
773+
get_queue_or_skip()
774+
x = dpt.asarray([0, 255], dtype=dpt.uint8)
775+
y = dpt.clip(x, -300, 300)
776+
777+
assert dpt.all(x == y)

0 commit comments

Comments
 (0)