mlx icon indicating copy to clipboard operation
mlx copied to clipboard

[BUG] Slice does not write through, unlike numpy

Open hlovatt opened this issue 10 months ago • 0 comments

Describe the bug A slice in NumPy writes through to underlying array, MLX doesn't. MLX behaves like Python, not NumPy.

To Reproduce

import mlx.core as mx
a = mx.array([1, 2, 3])
b = a[1:]
b[0] = 0
a, b

(array([1, 2, 3], dtype=int32), array([0, 3], dtype=int32))

Note how 0 is not written through b into a.

Expected behavior In NumPy:

import numpy as np
e = np.array([1, 2, 3])
f = e[1:]
f[0] = 0
e, f

(array([1, 0, 3]), array([0, 3]))

Note how 0 is written through f into e.

Desktop (please complete the following information):

  • MacOS 15.5
  • MLX 0.25.2

Additional context Only tested inside Jupyter!

hlovatt avatar May 20 '25 07:05 hlovatt