Skip to content

Commit f267a43

Browse files
committed
slight formatting and comments
1 parent ce6709a commit f267a43

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

src/array_api_compat/numpy/_aliases.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ def clip(
122122
x: Input array.
123123
min: Minimum bound. If None, no lower bound is applied.
124124
max: Maximum bound. If None, no upper bound is applied.
125+
**kwargs: Additional keyword arguments passed to ``np.clip``.
125126
out: Optional output array to store the result, has to have dtype of x
126127
"""
127128
# out is a possible *kwarg for numpy.clip, but not in the array API spec. We handle it here to
@@ -156,24 +157,25 @@ def _bound_shape(a: object) -> tuple[int, ...]:
156157
# this covers integer arrays for float and integer bounds
157158
# Also handle cases where the min/max are arrays/lists (replace values below min with iinfo.min and above max with iinfo.max)
158159
if np.issubdtype(dtype, np.integer):
160+
159161
if np.issubdtype(type(min), np.integer) and min <= np.iinfo(dtype).min:
160162
min = None
161163
elif np.issubdtype(type(min), np.floating) and min < np.iinfo(dtype).min:
162164
min = np.iinfo(dtype).min
163165
elif isinstance(min, (list, tuple, Array)):
164166
min[min < np.iinfo(dtype).min] = np.iinfo(dtype).min
167+
165168
if np.issubdtype(type(max), np.integer) and max >= np.iinfo(dtype).max:
166169
max = None
167-
168170
elif np.issubdtype(type(max), np.floating) and max > np.iinfo(dtype).max:
169171
max = np.iinfo(dtype).max
170-
171172
elif isinstance(max, (list, tuple, Array)):
172173
max[max > np.iinfo(dtype).max] = np.iinfo(dtype).max
173174

174175
# In the case of downcasting floats numpy replaces out of bounds with inf
175176
# This automatically handles those cases
176-
177+
178+
# Early return for simple cases
177179
if min is None and max is None:
178180
if out is None:
179181
return x.copy()[()]

0 commit comments

Comments
 (0)