Skip to content
Discussion options

You must be logged in to vote

Most of the time reshape doesn't copy data and just edits the metadata of an array to edit its shape.

For instance when you create a flat array of 100 elements and the reshape it to 2x5x10 there is no need to copy because the elements are still flat so we only need to edit the shape and strides.

However, if we transpose the array above to 5x2x10 and then reshape to 10x10 then we have to copy because the first axis would not be flat.

I use flat here to mean contiguous in memory. In general a user need not care about the contiguity of an MLX array. It may seldom make sense for some optimization in which case you can also use mx.contiguous without the need to reshape.

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by louisamand
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants