-
Notifications
You must be signed in to change notification settings - Fork 217
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
[BUG]: ndarray<> fails on read-only buffer object #206
Comments
nanobind currently doesn't have the concept of a read-only tensor and so refusing this unsafe cast seems reasonable. I might consider adding a special I think that pybind11 simply did not perform checks on whether an array is read only (and shouldn't be written to) requiring the user to do the right thing, which is of course also a solution though arguably not the best one. |
At least one other user would definitely appreciate that! :-) edit: |
Yes, a special annotation fixed my problem and make semantics clear. Looking forward to this feature! |
Ah, okay. The C++ accessors on the I'm not seeing any modification to the For numpy and buffer protocol users, though, it looks great to me! Thanks! |
DLPack supports a read-only flag as of dmlc/dlpack#113. But the details of the Python interface aren't worked out, and in any case nobody is using this new versioned flavor of DLPack yet. I plan to update nanobind once there are some implementations of the interface to test against..
nanobind generally ignores constness in function parameters and return values. Ignoring the read-only flag in the DLPack interface seems to me in line with this overall behavior. PR #217 implements a limited form of const tracking for nd-arrays because we need this flag to be able to fully interface with NumPy (which is far more strict). |
Problem description
when accessing numpy array with
ndarray<>
, nanobind fails when binding on a read-only object.seems that
nanobind/src/nb_ndarray.cpp
Line 165 in a965f5b
PyBUF_RECORDS
requires write permission. errorsValueError: buffer source array is read-only
Reproducible example code
The text was updated successfully, but these errors were encountered: