Replies: 1 comment 10 replies
-
For historical context: Initially, nanobind would make a DLPack capsule and then convert that into an nd-array of choice (NumPy, PyTorch, etc.). However, the NumPy <-> DLpack interface was found to be insufficient since non-brand-new numpy versions didn't support it, so I added an extra indirect path via an Can you explain the problem you are experiencing with the return value policies? It may be helpful to see an actual example. |
Beta Was this translation helpful? Give feedback.
-
Given an ndarray_handle and numpy as framework, ndarray_wrap creates a new nb_ndarray instance (that shares the data of the ndarray_handle), and calls numpy.array(nb_ndarray), which makes NumPy request a buffer from the nb_ndarray, again sharing the data. All reference counting seems fine, and no copying of data is involved if e.g. none is passed as return value policy.
With the defaults passed by nb::cast (copy/move), the data IS copied, however. What is the reason for that, given that ndarray_handle et al. have all means to share data? Why does ndarray_wrap consider a return value policy at all? This seems to contradict the documentation saying "A return value policy is unnecessary when the type itself clarifies ownership...".
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions