gh-58338: Support multi-dimensional slicing in memoryview#153661
Open
serhiy-storchaka wants to merge 1 commit into
Open
gh-58338: Support multi-dimensional slicing in memoryview#153661serhiy-storchaka wants to merge 1 commit into
serhiy-storchaka wants to merge 1 commit into
Conversation
Slicing a multi-dimensional memoryview, or indexing it with a combination of integers, slices and an ellipsis, now returns a sub-view instead of raising NotImplementedError. Each integer drops the corresponding dimension, a slice keeps it, and the ellipsis expands to full slices over the remaining dimensions. Such sub-views also support slice assignment, with the same shape and format matching rules as one-dimensional assignment. Buffers with suboffsets (indirect, PIL-style) are not yet handled on the sub-view paths and still raise NotImplementedError.
Documentation build overview
|
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.
Slicing a multi-dimensional
memoryview, or indexing it with a combination of integers, slices and an ellipsis, now returns a sub-view instead of raisingNotImplementedError. Each integer drops the corresponding dimension, a slice keeps it, and the ellipsis expands to full slices over the remaining dimensions. An empty tuple or a bare ellipsis selects the whole view.Such sub-views also support slice assignment, with the same shape and format matching rules as one-dimensional assignment (the right-hand side must be a bytes-like object of the matching shape; a one-dimensional sub-view accepts any matching bytes-like object).
Buffers with suboffsets (indirect, PIL-style) are not yet handled on the sub-view paths and still raise
NotImplementedError; a full index (which follows the suboffsets) and a leading-dimension slice continue to work.