I am trying to expose an Eigen tensor to python using pybind11. I can compile everything with no issue and can successfully import it to python. However, the data cannot be conv
That C++ code does not compile and that python code can not possibly have run as posted, but after fixing those and making the logical changes, the conclusion is still that pybind11 does not support TensorMap from "unsupported/Eigen/CXX11/Tensor" as that class does not provide the same interface as other Eigen mapping classes.
I would have expected a specialization of the mapper caster to work automatically, but doing so explicitly:
template<>
struct py::detail::type_caster>, void>
: py::detail::eigen_map_caster>> {};
fails the instantiation of pybind11::detail::EigenProps, b/c TensorMap does not provide its dimensions with cols/rows/stride. Thus, SFINAE prevents automatic generation of the caster.
Is there no other option than to use headers from a directory named "unsupported"? If not, your best bet is to copy the TensorMap's contents to a numpy array and to return that in a customization of getDataUsingMapping
: there are several examples of how to do that on SO, with and without copying. (Specialization of EigenProps would not work unless you're willing to flatten the tensor, but you could use it as an example to write a new generic type caster for TensorMap.)