@@ -110,7 +110,6 @@ def clip(
110110 / ,
111111 min : float | Array | None = None ,
112112 max : float | Array | None = None ,
113- out : Array | None = None ,
114113 ** kwargs ,
115114) -> Array :
116115 """Array API compatible clip implementation for NumPy.
@@ -125,6 +124,13 @@ def clip(
125124 max: Maximum bound. If None, no upper bound is applied.
126125 out: Optional output array to store the result, has to have dtype of x
127126 """
127+ # out is a possible *kwarg for numpy.clip, but not in the array API spec. We handle it here to
128+ # avoid having to add it to the array API spec, which would be a breaking change
129+ # check if out in kwargs, if so pop it and use it as the out parameter
130+ if "out" in kwargs :
131+ out = kwargs .pop ("out" )
132+ else :
133+ out = None
128134
129135 def _bound_shape (a : object ) -> tuple [int , ...]:
130136 if a is None or np .isscalar (a ):
@@ -134,7 +140,9 @@ def _bound_shape(a: object) -> tuple[int, ...]:
134140 dtype = x .dtype
135141 out_dtype = out .dtype if out is not None else dtype
136142 if out_dtype != dtype :
137- raise ValueError (f"Output array has dtype { out_dtype } , but input array has dtype { dtype } " )
143+ raise ValueError (
144+ f"Output array has dtype { out_dtype } , but input array has dtype { dtype } "
145+ )
138146 min_shape = _bound_shape (min )
139147 max_shape = _bound_shape (max )
140148
0 commit comments