Skip to content

Commit 6664e6d

Browse files
committed
ENH: allow ndim>1 indexing arrays
1 parent 36a370a commit 6664e6d

File tree

2 files changed

+7
-13
lines changed

2 files changed

+7
-13
lines changed

array_api_strict/_array_object.py

+3-8
Original file line numberDiff line numberDiff line change
@@ -498,14 +498,9 @@ def _validate_index(self, key, op="getitem"):
498498
"Array API when the array is the sole index."
499499
)
500500
if not get_array_api_strict_flags()['boolean_indexing']:
501-
raise RuntimeError("The boolean_indexing flag has been disabled for array-api-strict")
502-
503-
elif i.dtype in _integer_dtypes and i.ndim > 1:
504-
raise IndexError(
505-
f"Single-axes index {i} is a multi-dimensional "
506-
"integer array, but advanced integer indexing is only "
507-
"specified in the Array API for 1D index arrays."
508-
)
501+
raise RuntimeError(
502+
"The boolean_indexing flag has been disabled for array-api-strict"
503+
)
509504
elif isinstance(i, tuple):
510505
raise IndexError(
511506
f"Single-axes index {i} is a tuple, but nested tuple "

array_api_strict/tests/test_array_object.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,6 @@ def test_validate_index():
7070
assert_raises(IndexError, lambda: a[[True, True, True]])
7171
assert_raises(IndexError, lambda: a[(True, True, True),])
7272

73-
# Integer array indices are not allowed (except for 0-D or 1D)
74-
idx = asarray([[0, 1]]) # idx.ndim == 2
75-
assert_raises(IndexError, lambda: a[idx, 0])
76-
assert_raises(IndexError, lambda: a[0, idx])
77-
7873
# Mixing 1D integer array indices with slices, ellipsis or booleans is not allowed
7974
idx = asarray([0, 1])
8075
assert_raises(IndexError, lambda: a[..., idx])
@@ -138,6 +133,10 @@ def test_indexing_arrays():
138133
with assert_raises(IndexError):
139134
a[idx, idx] = 42
140135

136+
# smoke test indexing with ndim > 1 arrays
137+
idx = idx[..., None]
138+
a[idx, idx]
139+
141140

142141
def test_promoted_scalar_inherits_device():
143142
device1 = Device("device1")

0 commit comments

Comments
 (0)