Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion python/src/indexing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -913,7 +913,7 @@ mlx_compute_slice_update_args(
upd_ax--;
} else if (is_index_scalar(pyidx)) {
int st = safe_to_int32(pyidx);
st = (st < 0) ? st + src.shape(i) : st;
st = (st < 0) ? st + src.shape(ax) : st;
starts[ax] = st;
stops[ax] = st + 1;
if (upd_ax >= 0) {
Expand Down
7 changes: 7 additions & 0 deletions python/tests/test_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -1348,6 +1348,13 @@ def test_setitem(self):
a[0:1] = mx.array([1])
self.assertEqual(a.tolist(), [1, 4, 4])

# Regression test: a negative integer index after a None
# (newaxis) used to be normalized against the wrong axis size,
# silently writing nothing instead of updating the last row.
b = mx.zeros((3, 4))
b[None, -1] = 9
self.assertEqual(b.tolist(), [[0, 0, 0, 0], [0, 0, 0, 0], [9, 9, 9, 9]])

with self.assertRaises(ValueError):
a[0:1] = mx.array([2, 3])

Expand Down
Loading