Python pybind11中的命名默认参数 我使用PybDun11在转换lambda“SHIM”中封装C++类方法(我必须这样做是因为原因)。方法的一个参数是C++中的默认值。p> A类 { void meow(Eigen::Matrix4f optMat=Eigen::Matrix4f::Identity()); };
在pybind代码中,我希望保留此可选参数:Python pybind11中的命名默认参数 我使用PybDun11在转换lambda“SHIM”中封装C++类方法(我必须这样做是因为原因)。方法的一个参数是C++中的默认值。p> A类 { void meow(Eigen::Matrix4f optMat=Eigen::Matrix4f::Identity()); };,python,c++,pybind11,default-arguments,Python,C++,Pybind11,Default Arguments,在pybind代码中,我希望保留此可选参数: py::class_m(A) .def(py::init()) .def(“喵喵”, [](A&self,Eigen::Matrix4f optMat=Eigen::Matrix4f::Identity()) { 返回self.meow(optMat); }); 如何在生成的Python代码中使optMat成为可选的命名参数 只需将它们添加到lambda之后: py::class_<A>(m, "A") .def(py::ini
py::class_m(A)
.def(py::init())
.def(“喵喵”,
[](A&self,Eigen::Matrix4f optMat=Eigen::Matrix4f::Identity())
{
返回self.meow(optMat);
});
如何在生成的Python代码中使
optMat
成为可选的命名参数 只需将它们添加到lambda之后:
py::class_<A>(m, "A")
.def(py::init<>())
.def("meow",
[](A& self, Eigen::Matrix4f optMat) {
return self.meow(optMat);
},
py::arg("optMat") = Eigen::Matrix4f::Identity());
py::class_m(A)
.def(py::init())
.def(“喵喵”,
[](A&self,Eigen::Matrix4f optMat){
返回self.meow(optMat);
},
py::arg(“optMat”)=Eigen::Matrix4f::Identity();
是的,我看过文档,不清楚如何将它们应用到lambda,因为lambda参数不是实例化(对于py:arg
对象),而是类型声明。