-
Notifications
You must be signed in to change notification settings - Fork 2.2k
view for numpy arrays #987
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Npyreshape
for more information, see https://pre-commit.ci
* Comment: matching style in file (///), responsibility sentence, consistent punctuation. * Replacing `unsigned char` with `uint8_t` for max consistency. * Removing `1` from `array_view1` because there is only one.
I also ran a quick manual leak check to ensure that the It was simply temporarily adding |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@henryiii, @Skylion007: Looking for a 2nd set of eyes / approval.
include/pybind11/numpy.h
Outdated
array view(const std::string& dtype) { | ||
auto& api = detail::npy_api::get(); | ||
auto new_view = reinterpret_steal<array>(api.PyArray_View_( | ||
m_ptr, dtype::from_args(pybind11::str(dtype)).release().ptr(), NULL)); | ||
if (!new_view) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
personally prefer leaving braces in,
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Me too, but I think our clang-format config will take them out, that's why I removed them. Let me double check ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry it turns out I was wrong (I'm still really confused why I got to believe so strongly that clang-format takes them out).
They are back now. While I was at it, I applied clang-format-diff, except to line 202 in numpy.h, to not make it outstanding there.
(I really hope we'll get to finish establishing pre-commit clang-format sometime soon...)
All green, merging! Thanks again @ncullen93 and @Skylion007! |
this function is useful when you have numpy array buffers that need to be reinterpreted as different memory types.
For example, I often get a numpy array buffer from an ITK image that is e.g. size 256x256x4 as uint8 and it needs to be "viewed" as 256x256 float... it'd be nice to do this directly with pybind11.
From numpy:
Not sure if you like the std:string arg input or would rather have py::dtype or something..
Suggested changelog entry:
* Added ``view`` to view arrays with a different datatype.