首页 > 解决方案 > 如何在 Pybind11 中使用 Eigen

问题描述

问题描述

我有一个简单的功能

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

在我的 Python 代码中,我这样做了

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

但它崩溃了

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)

我做错什么了

标签: c++eigen3pybind11

解决方案


include <pybind11/eigen.h>

我忘了放这个。。


推荐阅读