diff --git a/array_api_strict/_elementwise_functions.py b/array_api_strict/_elementwise_functions.py index 6c87b3f..10c854e 100644 --- a/array_api_strict/_elementwise_functions.py +++ b/array_api_strict/_elementwise_functions.py @@ -257,7 +257,7 @@ def clip( raise TypeError("Only real numeric dtypes are allowed in clip") if min is max is None: - return x + return Array._new(x._array.copy(), device=x.device) for argname, arg in ("min", min), ("max", max): if isinstance(arg, Array): diff --git a/array_api_strict/tests/test_elementwise_functions.py b/array_api_strict/tests/test_elementwise_functions.py index e8a6d32..050f2bc 100644 --- a/array_api_strict/tests/test_elementwise_functions.py +++ b/array_api_strict/tests/test_elementwise_functions.py @@ -312,3 +312,12 @@ def _array_vals(): with pytest.raises(TypeError): func(s, s) + + +def test_clip_none(): + # regression test: clip(x) is a copy of x, not a view + x = asarray([1, 2, 3]) + y = array_api_strict.clip(x) + + y[1] = 42 + assert x[1] == 2