问题描述
我正在使用 pybind11 为我的 C++ 代码创建 python 绑定。在 C++ 中,我有一些类通过 Eigen::SparseMatrix<double>
共享一个 std::shared_ptr<>
。
矩阵本身被加载并分配给python中的不同对象
matrix = scipy.io.mmread("C.mtx")
o1 = O1()
o2 = O2()
o1.matrix = matrix
o2.matrix = matrix
创建绑定时,我尝试接收 std::shared_ptr<Eigen::SparseMatrix<double>>
,但 pybind11 无法编译
void VNCS::Sim2D::py::projection(pybind11::module &m)
{
::py::class_<VNCS::Sim2D::Projection,sofa::core::sptr<VNCS::Sim2D::Projection>>(m,"Projection")
.def(pybind11::init<>())
.def_property(
"clusterMatrix",[](const VNCS::Sim2D::Projection &projection) { return projection.clusterMatrix(); },[](VNCS::Sim2D::Projection &projection,std::shared_ptr<Eigen::SparseMatrix<VNCS::Sim2D::Kernel::Real>> m) {
projection.setClusterMatrix(m);
});
}
出现以下错误
error: static assertion Failed: Holder classes are only supported for custom types
能够在 C++ 类之间共享矩阵并从 python 分配它的最佳方法是什么?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)