I have a C ++ function calculating a large tensor that I would like to return Python as a NumPy array through pybind11 .
From the pybind11 documentation, it seems advisable to use STL unique_ptr . In the following example, the commented version works, while the given one compiles, but does not execute at runtime ("Cannot convert the return value of the function to Python type!").
Why is the smartpointer version not working? What is the canonical way to create and return a NumPy array?
PS: Due to the structure of the program and the size of the array, it is advisable not to copy the memory, but to create an array from the specified pointer. Memory ownership should be done by Python.
typedef typename py::array_t<double, py::array::c_style | py::array::forcecast> py_cdarray_t;
c ++ python arrays numpy pybind11
mrupp
source share