From the pybind information, you can extract the dimension information.
For instance, this is what I do inside Audio ToolKit with m
the current Python module you want to build:
py::class_<MyClass>(m,"name")
.def("set_pointer", [](MyClass& instance, const py::array_t<DataType>& array)
{
gsl::index channels = 1;
gsl::index size = array.shape(0);
if(array.ndim() == 2)
{
channels = array.shape(0);
size = array.shape(1);
}
// Call using array.data() and possibly add more dimension information, this is specific to my use case
instance.set_pointer(array.data(), channels, size);
});
From this, you can create the Eigen::Map
call instead to create an Eigen-like matrix that you can use in your templated code.
Basically, pybind11 allows you to create a lambda where you can create your wrapper for your use case. The same works for return, you can get the Eigen class, create a pybind array that you populate with the Eigen data.
Eigen has the Tensor class that you can use as well.