I have an existing pybind11::array_t
, and need to do a copy-construction. Is there a function inside pybind11
that allows me to do a deep copy of an array_t
?
I know that I could create a new array_t
, size it properly, and then copy the original data into it, but was wondering if there exists already a method to do this that hides these passages.
the default copy constructor does a deep copy, people are actually trying to avoid this :)
To use the copy constructor, you can go through the buffer
using py_arr = pybind11::array_t<double>;
py_arr a;
// do stuff with a, fill it and everything...
auto buffer = a.request();
py_arr b = py_arr(buffer);
std::cout << b.data() << " " << a.data() << std::endl; // this won't return the same address twice
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With