diff --git a/dpctl/tensor/_utility_functions.py b/dpctl/tensor/_utility_functions.py index 642b3fec0b..a324fe5483 100644 --- a/dpctl/tensor/_utility_functions.py +++ b/dpctl/tensor/_utility_functions.py @@ -453,7 +453,8 @@ def diff(x, /, *, axis=-1, n=1, prepend=None, append=None): x_nd = x.ndim axis = normalize_axis_index(operator.index(axis), x_nd) n = operator.index(n) - + if n < 0: + raise ValueError(f"`n` must be positive, got {n}") arr = _concat_diff_input(x, axis, prepend, append) if n == 0: return arr diff --git a/dpctl/tests/test_tensor_diff.py b/dpctl/tests/test_tensor_diff.py index ff2f104515..cb5c006f47 100644 --- a/dpctl/tests/test_tensor_diff.py +++ b/dpctl/tests/test_tensor_diff.py @@ -313,3 +313,17 @@ def test_diff_input_validation(): dpt.diff, bad_in, ) + + +def test_diff_positive_order(): + get_queue_or_skip() + + x = dpt.ones(1, dtype="i4") + n = -1 + assert_raises_regex( + ValueError, + ".*must be positive.*", + dpt.diff, + x, + n=n, + )