return_by_ref.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2020 INRIA
3  */
4 
5 #include "eigenpy/eigenpy.hpp"
6 #include <iostream>
7 
8 template<typename Matrix>
9 struct Base
10 {
11  Base(const Eigen::DenseIndex rows,
12  const Eigen::DenseIndex cols)
13  : mat(rows,cols)
14  {}
15 
16  void show()
17  {
18  std::cout << mat << std::endl;
19  }
20 
21  Matrix & ref() { return mat; }
22  const Matrix & const_ref() { return mat; }
23  Matrix copy() { return mat; }
24 
25 protected:
26 
27  Matrix mat;
28 };
29 
30 template<typename MatrixType>
31 void expose_matrix_class(const std::string & name)
32 {
33  using namespace Eigen;
34  namespace bp = boost::python;
35 
36  bp::class_<Base<MatrixType> >(name.c_str(),bp::init<DenseIndex,DenseIndex>())
37  .def("show",&Base<MatrixType>::show)
38  .def("ref",&Base<MatrixType>::ref, bp::return_internal_reference<>())
39  .def("const_ref",&Base<MatrixType>::const_ref, bp::return_internal_reference<>())
40  .def("copy",&Base<MatrixType>::copy);
41 }
42 
43 BOOST_PYTHON_MODULE(return_by_ref)
44 {
45  using namespace Eigen;
47 
48  typedef Eigen::Matrix<double,Eigen::Dynamic,1> VectorType;
49  typedef Eigen::Matrix<double,Eigen::Dynamic,Eigen::Dynamic> MatrixType;
50  typedef Eigen::Matrix<double,Eigen::Dynamic,Eigen::Dynamic,Eigen::RowMajor> RowMatrixType;
51 
52  expose_matrix_class<VectorType>("Vector");
53  expose_matrix_class<MatrixType>("Matrix");
54  expose_matrix_class<RowMatrixType>("RowMatrix");
55 }
56 
Matrix & ref()
Base(const Eigen::DenseIndex rows, const Eigen::DenseIndex cols)
Matrix mat
Definition: complex.cpp:7
void EIGENPY_DLLAPI enableEigenPy()
Definition: eigenpy.cpp:29
void expose_matrix_class(const std::string &name)
BOOST_PYTHON_MODULE(return_by_ref)
const Matrix & const_ref()
Matrix copy()
void show()


eigenpy
Author(s): Justin Carpentier, Nicolas Mansard
autogenerated on Sat Apr 17 2021 02:37:59