@@ -20,25 +20,38 @@ struct Base
2020 }
2121
2222 Matrix & ref () { return mat; }
23+ const Matrix & const_ref () { return mat; }
2324 Matrix copy () { return mat; }
2425
2526protected:
2627
2728 Matrix mat;
2829};
2930
31+ template <typename MatrixType>
32+ void expose_matrix_class (const std::string & name)
33+ {
34+ using namespace Eigen ;
35+ namespace bp = boost::python;
36+
37+ bp::class_<Base<MatrixType> >(name.c_str (),bp::init<DenseIndex,DenseIndex>())
38+ .def (" show" ,&Base<MatrixType>::show)
39+ .def (" ref" ,&Base<MatrixType>::ref, bp::return_internal_reference<>())
40+ .def (" const_ref" ,&Base<MatrixType>::const_ref, bp::return_internal_reference<>())
41+ .def (" copy" ,&Base<MatrixType>::copy);
42+ }
3043
3144BOOST_PYTHON_MODULE (return_by_ref)
3245{
3346 using namespace Eigen ;
34- namespace bp = boost::python;
3547 eigenpy::enableEigenPy ();
3648
37-
49+ typedef Eigen::Matrix<double ,Eigen::Dynamic,1 > VectorType;
50+ typedef Eigen::Matrix<double ,Eigen::Dynamic,Eigen::Dynamic> MatrixType;
3851 typedef Eigen::Matrix<double ,Eigen::Dynamic,Eigen::Dynamic,Eigen::RowMajor> RowMatrixType;
39- bp::class_<Base<RowMatrixType> >( " Matrix " ,bp::init<DenseIndex,DenseIndex>())
40- . def ( " show " ,&Base<RowMatrixType>::show)
41- . def ( " ref " ,&Base<RowMatrixType>::ref, bp::return_internal_reference<>())
42- . def ( " copy " ,&Base <RowMatrixType>::copy );
52+
53+ expose_matrix_class<VectorType>( " Vector " );
54+ expose_matrix_class<MatrixType>( " Matrix " );
55+ expose_matrix_class <RowMatrixType>( " RowMatrix " );
4356}
4457
0 commit comments