Add checks after using pybind ensure() - #32267
Merged
Merged
Conversation
iccir
commented
Aug 30, 2026
| // Ensure input array is contiguous, regardless of dtype | ||
| input_array = py::array::ensure(input_array, py::array::c_style); | ||
| if (!input_array) { | ||
| throw std::invalid_argument("Input array could not be made C-contiguous"); |
Contributor
Author
There was a problem hiding this comment.
Note that this is likely unnecessary. I couldn't figure out a way to make this ensure() return a null. That said, throwing an exception is better than crashing.
QuLogic
reviewed
Aug 31, 2026
QuLogic
approved these changes
Sep 1, 2026
ksunden
approved these changes
Sep 4, 2026
QuLogic
pushed a commit
that referenced
this pull request
Sep 5, 2026
QuLogic
added a commit
that referenced
this pull request
Sep 5, 2026
…267-on-v3.11.x Backport PR #32267 on branch v3.11.x (Add checks after using pybind ensure())
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.
PR summary
Checks that the result of calling
ensure()call is non-null.Closes #32261
AI Disclosure
I used AI as a search engine to find pybind11 documentation.
PR quality check