-
Is there documentation about providing a class binding for custom c++ ndarray types with their own pointer to shared data, ndims, shape, etc. into the new nb::ndarray<...> functionality? With pybind11 we created a
with a and a lamba to return the Is there a way to provide python with the nb::ndarray information in a similar manner, while still keeping the original c++ type of the class instance? (For context I am trying to create bindings for Kokkos views to be passed back and forth between python and c++ functions expecting Kokkos views as inputs). |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
I've been working this all day and of course the second I post I find a solution. One can define the |
Beta Was this translation helpful? Give feedback.
-
yes you are correct, this actually turned out to be suitable for us as the pybind11 version already wrapped with np.array() so it was an easy solution. I do not think what I was originally looking for is possible, as it would require the treatment of the same object as a np.array type on the python side, but when passed to a bound c++ function, it needs to be a Kokkos::view type. So keeping two separate python variables, one of np.array(view) and one of view is a decent trade-off. |
Beta Was this translation helpful? Give feedback.
I've been working this all day and of course the second I post I find a solution. One can define the
__array__
method and return an nb::ndarray<> using the data from the c++ class like ndims, etc. So it won't outright return an np.ndarray, but you can then wrap the objects with np.array(view) and it will find everything it needs. Though I would be interested to hear if there are better ways of doing thing.