Search code examples
c++eigen3pybind11

How to Use Eigen with Pybind11


Issue description

I have a simple function as such

void test2(Eigen::Matrix4f& mat){
    std::cout << mat << std::endl;
}

In my Python code, I do this

pylc.test2(np.ones((4,4), dtype=np.float32))

But it crashes with

TypeError: test2(): incompatible function arguments. The following argument types are supported:
    1. (arg0: Eigen::Matrix<float, 4, 4, 0, 4, 4>) -> None

Invoked with: array([[1., 1., 1., 1.],
       [1., 1., 1., 1.],
       [1., 1., 1., 1.],
       [1., 1., 1., 1.]], dtype=float32)

What did I do wrong


Solution

  • include <pybind11/eigen.h>

    i forgot to put this..