Skip to content
Snippets Groups Projects
Verified Commit 594096ca authored by Justin Carpentier's avatar Justin Carpentier
Browse files

test/eigen: update test for returning reference

parent a6a94177
No related branches found
No related tags found
No related merge requests found
...@@ -20,6 +20,7 @@ struct Base ...@@ -20,6 +20,7 @@ struct Base
} }
Matrix & ref() { return mat; } Matrix & ref() { return mat; }
const Matrix & const_ref() { return mat; }
Matrix copy() { return mat; } Matrix copy() { return mat; }
protected: protected:
...@@ -27,18 +28,30 @@ protected: ...@@ -27,18 +28,30 @@ protected:
Matrix mat; Matrix mat;
}; };
template<typename MatrixType>
void expose_matrix_class(const std::string & name)
{
using namespace Eigen;
namespace bp = boost::python;
bp::class_<Base<MatrixType> >(name.c_str(),bp::init<DenseIndex,DenseIndex>())
.def("show",&Base<MatrixType>::show)
.def("ref",&Base<MatrixType>::ref, bp::return_internal_reference<>())
.def("const_ref",&Base<MatrixType>::const_ref, bp::return_internal_reference<>())
.def("copy",&Base<MatrixType>::copy);
}
BOOST_PYTHON_MODULE(return_by_ref) BOOST_PYTHON_MODULE(return_by_ref)
{ {
using namespace Eigen; using namespace Eigen;
namespace bp = boost::python;
eigenpy::enableEigenPy(); eigenpy::enableEigenPy();
typedef Eigen::Matrix<double,Eigen::Dynamic,1> VectorType;
typedef Eigen::Matrix<double,Eigen::Dynamic,Eigen::Dynamic> MatrixType;
typedef Eigen::Matrix<double,Eigen::Dynamic,Eigen::Dynamic,Eigen::RowMajor> RowMatrixType; typedef Eigen::Matrix<double,Eigen::Dynamic,Eigen::Dynamic,Eigen::RowMajor> RowMatrixType;
bp::class_<Base<RowMatrixType> >("Matrix",bp::init<DenseIndex,DenseIndex>())
.def("show",&Base<RowMatrixType>::show) expose_matrix_class<VectorType>("Vector");
.def("ref",&Base<RowMatrixType>::ref, bp::return_internal_reference<>()) expose_matrix_class<MatrixType>("Matrix");
.def("copy",&Base<RowMatrixType>::copy); expose_matrix_class<RowMatrixType>("RowMatrix");
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment