Verified Commit 594096ca authored by Justin Carpentier's avatar Justin Carpentier
Browse files

test/eigen: update test for returning reference

parent a6a94177
......@@ -20,6 +20,7 @@ struct Base
}
Matrix & ref() { return mat; }
const Matrix & const_ref() { return mat; }
Matrix copy() { return mat; }
protected:
......@@ -27,18 +28,30 @@ protected:
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)
{
using namespace Eigen;
namespace bp = boost::python;
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;
bp::class_<Base<RowMatrixType> >("Matrix",bp::init<DenseIndex,DenseIndex>())
.def("show",&Base<RowMatrixType>::show)
.def("ref",&Base<RowMatrixType>::ref, bp::return_internal_reference<>())
.def("copy",&Base<RowMatrixType>::copy);
expose_matrix_class<VectorType>("Vector");
expose_matrix_class<MatrixType>("Matrix");
expose_matrix_class<RowMatrixType>("RowMatrix");
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment