Skip to content

wrapping existing c++ ndarray classes without def_buffer function #182

Answered by kaschau
kaschau asked this question in Q&A
Discussion options

You must be logged in to vote

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.

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@wjakob
Comment options

Answer selected by wjakob
Comment options

You must be logged in to vote
0 replies
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