Tweak array_view to be more like pybind11#27066
Conversation
|
I think this is likely okay in the places it is used, as all of these should be scalar or 1D array only, but they would differ here if handed a 2D array. |
|
I've only added an explicit check in one place, but I think I've checked the other places that It looks like that change did change the exception type, but since that function could raise either, it should be alright, and I'll change the test to match. |
879a3c6 to
916ace4
Compare
This matches the name from pybind11, and will make it easier to reuse templated code with either.
The other dimensions have already been confirmed to be non-zero, so size() == shape(0) in these cases.
This currently checks if any dimension is 0, and returns the first dimension or 0. However, `pybind11::array_t.size()` returns the product of the shapes, so we want to be explicit when we need the former. I also checked the remaining `size` calls, and those will be fine with either interpretation, so I did not change them.
916ace4 to
343fa13
Compare
PR summary
This will generally make it easier to port to pybind11, as then the templated code can stay the same whether using the old
numpy::array_viewor the newpybind11::array_t.PR checklist