-
Notifications
You must be signed in to change notification settings - Fork 212
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]: Cannot resolve numpy array as tensor input if flag write=False
is set
#42
Comments
I think I have the same problem. I'm converting code from pybind11, and I pass in a numpy array which is constructed from a buffer: buf = fstream.read(RAW_CHUNK_SIZE)
arr = np.frombuffer(buf, dtype=np.int8) Passing |
I spent a bit of time futzing around trying to debug this. If I change this line: Line 152 in 8555cf8
to this: if (PyObject_GetBuffer(o, view.get(), PyBUF_RECORDS_RO)) { Then my code works. But I have no idea about the further implications of this. There is a lot to take in! @chrisrichardson Does this work for you? |
It appears the readonly problem is not just with nanobind. import numpy as np
w = np.array([[2.0,2.0]])
w.setflags(write=False)
w.__dlpack__() gives
Some discussion here: numpy/numpy#20742 So is the issue that dlpack doesn't support readonly buffers? |
Relevant when working with mikedh/trimesh, as the vertex and normal arrays have write=False by default |
I will close this issue, the current |
Problem description
If we have a function which takes a const reference, it should be possible to do something like this:
m.def("get_dim", [](const nb::tensor<const double>& x){ return x.ndim(); });
and send in an unwriteable numpy array:
But this doesn't seem to work at the moment:
Removing the
write=False
, it works fine, but sometimes we have an unwriteable array from somewhere else...Reproducible example code
No response
The text was updated successfully, but these errors were encountered: