Skip to content

Commit d38bad5

Browse files
committed
Improve some error messages
1 parent 7699755 commit d38bad5

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

array_api_compat/torch/_aliases.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,9 @@ def sort(x: array, /, *, axis: int = -1, descending: bool = False, stable: bool
172172

173173
def _normalize_axes(axis, ndim):
174174
axes = []
175+
if ndim == 0 and axis:
176+
# Better error message in this case
177+
raise IndexError(f"Dimension out of range: {axis[0]}")
175178
lower, upper = -ndim, ndim - 1
176179
for a in axis:
177180
if a < lower or a > upper:
@@ -180,12 +183,11 @@ def _normalize_axes(axis, ndim):
180183
if a < 0:
181184
a = a + ndim
182185
if a in axes:
183-
# Match torch error message but use IndexError instead of RuntimeError
184-
raise IndexError(f"dim {a} appears multiple times in the list of dims")
186+
# Use IndexError instead of RuntimeError, and "axis" instead of "dim"
187+
raise IndexError(f"Axis {a} appears multiple times in the list of axes")
185188
axes.append(a)
186189
return sorted(axes)
187190

188-
189191
def _apply_keepdims(x, ndim, keepdims):
190192
if keepdims:
191193
return x[(None,)*ndim]

0 commit comments

Comments
 (0)