Skip to content

Commit

Permalink
Reuse alternate index syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
crusaderky committed Dec 18, 2024
1 parent c9d45af commit d0bbc88
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/array_api_extra/_funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -672,8 +672,7 @@ def __getitem__(self, idx: Index, /) -> "at": # numpydoc ignore=PR01,RT01
if self._idx is not _undef:
msg = "Index has already been set"
raise ValueError(msg)
self._idx = idx
return self
return at(self._x, idx)

def _update_common(
self,
Expand Down
5 changes: 5 additions & 0 deletions tests/test_at.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,11 @@ def test_alternate_index_syntax():
a = np.asarray([1, 2, 3])
assert_array_equal(at(a, 0).set(4), [4, 2, 3])
assert_array_equal(at(a)[0].set(4), [4, 2, 3])

a_at = at(a)
assert_array_equal(a_at[0].add(1), [2, 2, 3])
assert_array_equal(a_at[1].add(2), [1, 4, 3])

with pytest.raises(ValueError, match="Index"):
at(a).set(4)
with pytest.raises(ValueError, match="Index"):
Expand Down

0 comments on commit d0bbc88

Please sign in to comment.