Skip to content

[BUG]: bytes(array) dumps the wrong memory when the array is not packed #4445

Closed

Description

@simeetnayan81

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.

Activity

  1. axiom-of-choice commented on Sep 1, 2026

    @axiom-of-choice
    Contributor

    Reproduced and fixed in #4449.

  2. simeetnayan81 commented on Sep 1, 2026

    @simeetnayan81
    Author

    Thanks @axiom-of-choice for raising the PR but I was waiting for a maintainer to confirm this before making any code changes. Thanks anyway. I'll review it.

  3. aaishwarymishra commented on Sep 2, 2026

    @aaishwarymishra
    Contributor

    I did reproduce the bug, I might have missed it my bad :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions