Created from my comment here: #4388 (comment)
Describe the bug
bytes(array) dumps the wrong memory on any view that is not row-contiguous it returns neighboring parent memory, not the array's values.
To Reproduce
x = mx.arange(10, dtype=mx.int32)
mx.eval(x)
y = x[::2]
mx.eval(y)
got = list(bytes(y))
exp = list(np.array(y.tolist(), dtype=np.int32).tobytes())
print("slice ", y.tolist())
print("bytes mlx ", got)
print("bytes want ", exp)
Output:
slice [0, 2, 4, 6, 8]
bytes mlx [0, 0, 0, 0, 1, 0, 0, 0, 2, 0, 0, 0, 3, 0, 0, 0, 4, 0, 0, 0]
bytes want [0, 0, 0, 0, 2, 0, 0, 0, 4, 0, 0, 0, 6, 0, 0, 0, 8, 0, 0, 0]
Any view( slice / transpose / broadcast ) which is not packed will produce wrong output.
Created from my comment here: #4388 (comment)
Describe the bug
bytes(array) dumps the wrong memory on any view that is not row-contiguous it returns neighboring parent memory, not the array's values.
To Reproduce
Output:
Any view( slice / transpose / broadcast ) which is not packed will produce wrong output.