Skip to content

How to bind numpy arrays in-place when given as STL vectors? #145

Closed Answered by wjakob
tienviitta asked this question in Q&A
Discussion options

You must be logged in to vote

You cannot just reference-cast the nb::ndarray to a std::vector<uint8_t>. They are different types and have an incompatible layout. Use a static_cast if you feel unsure. This would have resulted in an error message in this case.

std::vector can never be used as a view of some other pre-existing data, since it wants to own the underlying storage.

I suggest that you review the nanobind documentation, including how to iterate over the contents of an ndarray. You will likely have to update the interface of your bit2byte functions. Another option is to not use an ndarray but use bind_vector.h to expose this type. Again, please refer to the documentation for detail.

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@tienviitta
Comment options

@tienviitta
Comment options

Answer selected by wjakob
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants