Skip to content

Constructing ndarray by moving from a std::unique_ptr #993

Closed Answered by hpkfft
agtumulak asked this question in Q&A
Discussion options

You must be logged in to vote

I would follow the example in https://nanobind.readthedocs.io/en/latest/ndarray.html#data-ownership
Maybe, there's no reason to use a unique_ptr, since you're always using .get() anyway to pass the raw pointer to functions?
Though, maybe you want safety if cuda_sample throws an exception?

The nb::ndarray constructor in your example above is only given the raw pointer, so neither it nor the subsequent .cast() can use std::move to affect the unique_ptr itself.

If you need to use unique_ptr for some reason (e.g., exception considerations, other functions calls not shown in your minimal example above), then you can use samples_ptr.release() in the nb::ndarray constructor so that the unique_pt…

Replies: 2 comments 2 replies

Comment options

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

@hpkfft
Comment options

Answer selected by agtumulak
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
3 participants