Closed akapelrud closed 1 year ago
It was as simple as adding the xt::import_numpy();
call to the embedding scope.
#define FORCE_IMPORT_ARRAY
#include <xtensor-python/pyarray.hpp>
#include <pybind11/embed.h>
namespace py = pybind11;
void someprocedure() {
py::scoped_interpreter guard{};
xt::import_numpy();
py::module_ test = py::module_::import("test"); // import local python module
py::object result = test.attr("generate_data")(); // call function from python module
// this now works as expected:
xt::pyarray<double> array0(result);
return 0;
}
All of the examples show extending python with C++ but how can I translate from a numpy
ndarray
to axt::pyarray
when embedding python using pybind11?Given:
test.py
:and the C++ source: