std_vector.cpp
Go to the documentation of this file.
1 #include <ostream>
5 
6 #include "eigenpy/eigenpy.hpp"
8 #include "eigenpy/std-vector.hpp"
9 
10 template <typename MatType>
12  const std::vector<MatType, Eigen::aligned_allocator<MatType> > &Ms) {
13  const std::size_t n = Ms.size();
14  for (std::size_t i = 0; i < n; i++) {
15  std::cout << "el[" << i << "] =\n" << Ms[i] << '\n';
16  }
17 }
18 
19 template <typename MatType>
20 std::vector<MatType, Eigen::aligned_allocator<MatType> > copy(
21  const std::vector<MatType, Eigen::aligned_allocator<MatType> > &Ms) {
22  std::vector<MatType, Eigen::aligned_allocator<MatType> > out = Ms;
23  return out;
24 }
25 
26 template <typename MatType>
27 void setZero(std::vector<MatType, Eigen::aligned_allocator<MatType> > &Ms) {
28  for (std::size_t i = 0; i < Ms.size(); i++) {
29  Ms[i].setZero();
30  }
31 }
32 
34  bool operator==(const CustomTestStruct &) const { return true; }
35 };
36 
37 BOOST_PYTHON_MODULE(std_vector) {
38  namespace bp = boost::python;
39  using namespace eigenpy;
40 
41  enableEigenPy();
42 
43  bp::def("printVectorOfMatrix", printVectorOfMatrix<Eigen::VectorXd>);
44  bp::def("printVectorOfMatrix", printVectorOfMatrix<Eigen::MatrixXd>);
45 
46  bp::def("copyStdVector", copy<Eigen::MatrixXd>);
47  bp::def("copyStdVector", copy<Eigen::VectorXd>);
48 
49  exposeStdVectorEigenSpecificType<Eigen::Matrix3d>("Mat3d");
50  bp::def("printVectorOf3x3", printVectorOfMatrix<Eigen::Matrix3d>);
51  bp::def("copyStdVec_3x3", copy<Eigen::Matrix3d>, bp::args("mats"));
52 
53  typedef Eigen::Ref<Eigen::MatrixXd> RefXd;
55  bp::def("setZero", setZero<Eigen::MatrixXd>, "Sets the coeffs to 0.");
56 
57  // Test matrix modification
58  // Mat2d don't have tolist, reserve, mutable __getitem__ and from list
59  // conversion
60  // exposeStdVectorEigenSpecificType must add those methods to StdVec_Mat2d
61  bp::class_<std::vector<Eigen::Matrix2d> >("StdVec_Mat2d")
62  .def(boost::python::vector_indexing_suite<
63  std::vector<Eigen::Matrix2d> >());
64  exposeStdVectorEigenSpecificType<Eigen::Matrix2d>("Mat2d");
65 
66  // Test API regression:
67  // Exposing a `std::vector` with documentation doesn't clash with
68  // exposing a `std::vector` with a visitor
70  "StdVec_CustomTestStruct", "some documentation");
71 }
boost::python
Definition: alignment.hpp:49
eigenpy::StdVectorPythonVisitor
Expose an std::vector from a type given as template argument.
Definition: std-vector.hpp:424
eigenpy::enableEigenPy
void EIGENPY_DLLAPI enableEigenPy()
Definition: eigenpy.cpp:43
eigen-from-python.hpp
CustomTestStruct::operator==
bool operator==(const CustomTestStruct &) const
Definition: std_vector.cpp:34
printVectorOfMatrix
void printVectorOfMatrix(const std::vector< MatType, Eigen::aligned_allocator< MatType > > &Ms)
Definition: std_vector.cpp:11
eigenpy
Definition: alignment.hpp:14
CustomTestStruct
Definition: std_vector.cpp:33
eigenpy::expose
void expose()
Call the expose function of a given type T.
Definition: expose.hpp:23
eigenpy.hpp
setZero
void setZero(std::vector< MatType, Eigen::aligned_allocator< MatType > > &Ms)
Definition: std_vector.cpp:27
copy
std::vector< MatType, Eigen::aligned_allocator< MatType > > copy(const std::vector< MatType, Eigen::aligned_allocator< MatType > > &Ms)
Definition: std_vector.cpp:20
std-vector.hpp
BOOST_PYTHON_MODULE
BOOST_PYTHON_MODULE(std_vector)
Definition: std_vector.cpp:37


eigenpy
Author(s): Justin Carpentier, Nicolas Mansard
autogenerated on Sat Nov 2 2024 02:14:45