-
Notifications
You must be signed in to change notification settings - Fork 208
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
Draft: force buffer protocol in tensor creation for numpy
to avoid read/write constraints with dlpack
.
#56
Conversation
@wjakob I've added an |
I can confirm that |
There is now a Both issues are solved, but I wonder if there is a way of combining the readonly/writeable flags. I could not see how to do it as they really serve in different places. For clarity, maybe they should be |
0f898e2
to
94bbb89
Compare
Based on the table below, we only need buffer protocal for 2 cases: python readonly to C++ readonly, and C++ readwrite to python readwrite.
It will be great to use the same flag for both cases. Having both |
Sorry, I don't understand the table -- it looks misleading. Currently nanobind throws an exception if you send it a RO buffer from python. So neither RO -> RO or RO -> RW from python -> C++ work. Any readonly flag in C++ (at least for numpy arrays) is simply a warning to the programmer, unless we force the array to be const. Perhaps that is an option, but my c++ templating skills are already stretched! Maybe @wjakob has some suggestions? |
Sorry, I should clarify the table is a summary of the data transfer technologies that (I think) can be used for transferring data under different read/write permissions. (and by python, I meant numpy array.) It is not what nanobind does currently. In any case, I agree with you that we should combine |
Sorry for taking a long time to respond -- generally this seems like a reasonable set of changes, though it does seem somewhat specific to NumPy. A similar readonly flag is on the horizon for DLPack (data-apis/array-api#191), so whatever this turns into will have to generalize into passing all kinds of read-only tensors made using different frameworks. A code style comment: in nanobind, opening braces are generally merged with the previous line -- the PR deviates from this convention. |
Hi @wjakob. Thanks for the comments. I'll have a look at the DLPack changes, to try and see how they would fit. |
1c17434
to
a2b8b20
Compare
42ce5e7
to
0106656
Compare
c41d953
to
f935f93
Compare
14dc172
to
16b77b1
Compare
d5b6905
to
9af019b
Compare
4280c39
to
50e761a
Compare
ec3373c
to
b5ed696
Compare
I will close this PR, I don't think it is relevant anymore with recent changes to nanobind. I am happy to reopen it if you disagree. |
This PR overcomes two current limitations with tensors in nanobind when using numpy (it does not affect torch or jax).
write=False
is set #42.