Verified Commit b0082164 authored by Justin Carpentier's avatar Justin Carpentier
Browse files

test: start implementing test for return by reference context

parent defe0330
......@@ -32,6 +32,7 @@ ENDMACRO(ADD_LIB_UNIT_TEST)
ADD_LIB_UNIT_TEST(matrix "eigen3")
ADD_LIB_UNIT_TEST(geometry "eigen3")
ADD_LIB_UNIT_TEST(complex "eigen3")
ADD_LIB_UNIT_TEST(return_by_ref "eigen3")
IF(NOT ${EIGEN3_VERSION} VERSION_LESS "3.2.0")
ADD_LIB_UNIT_TEST(ref "eigen3")
ENDIF()
......
/*
* Copyright 2014-2019, CNRS
* Copyright 2018-2020, INRIA
*/
#include "eigenpy/eigenpy.hpp"
#include <iostream>
template<typename Matrix>
struct Base
{
Base(const Eigen::DenseIndex rows,
const Eigen::DenseIndex cols)
: mat(rows,cols)
{}
void show()
{
std::cout << mat << std::endl;
}
Matrix & ref() { return mat; }
Matrix copy() { return mat; }
protected:
Matrix mat;
};
BOOST_PYTHON_MODULE(return_by_ref)
{
using namespace Eigen;
namespace bp = boost::python;
eigenpy::enableEigenPy();
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);
}
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