eigen_ref.cpp 1.59 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
/*
 * Copyright 2014-2019, CNRS
 * Copyright 2018-2020, INRIA
 */

#include "eigenpy/eigenpy.hpp"
#include <iostream>

using namespace Eigen;
using namespace eigenpy;

template<typename MatType>
13
void printMatrix(const Eigen::Ref<const MatType> mat)
14
15
16
17
18
19
20
21
{
  if(MatType::IsVectorAtCompileTime)
    std::cout << "isVector" << std::endl;
  std::cout << "size: cols " << mat.cols() << " rows " << mat.rows() << std::endl;
  std::cout << mat << std::endl;
}

template<typename VecType>
22
void printVector(const Eigen::Ref<const VecType> & vec)
23
24
25
26
27
28
29
30
31
{
  EIGEN_STATIC_ASSERT_VECTOR_ONLY(VecType);
  printMatrix(vec);
}

template<typename MatType>
void setOnes(Eigen::Ref<MatType> mat)
{
  mat.setOnes();
32
33
34
35
36
37
}

template<typename MatType>
void fill(Eigen::Ref<MatType> mat, const typename MatType::Scalar & value)
{
  mat.fill(value);
38
39
}

40
41
42
43
44
45
46
47
template<typename MatType>
Eigen::Ref<MatType> asRef(const int rows, const int cols)
{
  static MatType mat(rows,cols);
  std::cout << "mat:\n" << mat << std::endl;
  return mat;
}

48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
BOOST_PYTHON_MODULE(eigen_ref)
{
  namespace bp = boost::python;
  eigenpy::enableEigenPy();
  
  bp::def("printMatrix", printMatrix<Vector3d>);
  bp::def("printMatrix", printMatrix<VectorXd>);
  bp::def("printMatrix", printMatrix<MatrixXd>);
  
  bp::def("printVector", printVector<VectorXd>);
  bp::def("printRowVector", printVector<RowVectorXd>);

  bp::def("setOnes", setOnes<Vector3d>);
  bp::def("setOnes", setOnes<VectorXd>);
  bp::def("setOnes", setOnes<MatrixXd>);
63
64
65
66
  
  bp::def("fillVec3", fill<Vector3d>);
  bp::def("fillVec", fill<VectorXd>);
  bp::def("fill", fill<MatrixXd>);
67
68
  
  bp::def("asRef", asRef<MatrixXd>);
69
}