gh-78959: Add order parameter to memoryview.cast()#153663
Open
serhiy-storchaka wants to merge 1 commit into
Open
gh-78959: Add order parameter to memoryview.cast()#153663serhiy-storchaka wants to merge 1 commit into
serhiy-storchaka wants to merge 1 commit into
Conversation
memoryview.cast() now accepts a keyword-only order parameter. With order='F' it returns a zero-copy Fortran-contiguous (column-major) view of a flat buffer, mirroring the order argument of memoryview.tobytes(). Only 'C' (the default) and 'F' are accepted; the buffer is not copied.
Documentation build overview
|
This was referenced Jul 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
memoryview.cast()now accepts a keyword-only order parameter. With a multidimensional shape,order='F'returns a zero-copy Fortran-contiguous (column-major) view of a flat buffer, whileorder='C'(the default) keeps the current C-contiguous behavior. This mirrors the order argument ofmemoryview.tobytes()and makes it possible to interface with column-major libraries from pure Python without copying.Only
'C'and'F'are accepted; anything else raisesValueError, and non-single-character values raiseTypeError. Unlikememoryview.tobytes(),Noneis not accepted, since the default already means'C'.