xtensor-stack / xtensor-python

Python bindings for xtensor
BSD 3-Clause "New" or "Revised" License
346 stars 58 forks source link

How to convert xt::pyarray to xt::xarray? #294

Closed Roy-Kid closed 1 year ago

Roy-Kid commented 1 year ago

I have written a c++ lib and the function signature is, let's say xt::xarray<double> func(xt::xarray<double>& m). And now I need to write a python wrapper for this lib. So I try to write something like this:

PYBIND_MODULE(cpp_kernel, m) {
xt::import_numpy();
m.def("func", [](xt::pyarray<double>& m){  /* convert xt::pyarray to xt::array*/ } , "python wrapper")
}

It seems that both implicit conversion and xt::adapt fails. How can I implement this ? Thanks in advance!

Roy-Kid commented 1 year ago

Hi everyone,

I've found the related doc https://xtensor-python.readthedocs.io/en/latest/examples.html#fall-back-cast

It works for me!

Sorry to bother you