Skip to content

Commit 9872bfb

Browse files
committed
test: add library for eigen_ref
1 parent 60c9687 commit 9872bfb

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

unittest/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ ADD_LIB_UNIT_TEST(geometry "eigen3")
3434
ADD_LIB_UNIT_TEST(complex "eigen3")
3535
ADD_LIB_UNIT_TEST(return_by_ref "eigen3")
3636
IF(NOT ${EIGEN3_VERSION} VERSION_LESS "3.2.0")
37+
ADD_LIB_UNIT_TEST(eigen_ref "eigen3")
3738
ADD_LIB_UNIT_TEST(eigenpy_ref "eigen3")
3839
ENDIF()
3940

unittest/eigen_ref.cpp

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Copyright 2014-2019, CNRS
3+
* Copyright 2018-2020, INRIA
4+
*/
5+
6+
#include "eigenpy/eigenpy.hpp"
7+
#include <iostream>
8+
9+
using namespace Eigen;
10+
using namespace eigenpy;
11+
12+
template<typename MatType>
13+
void printMatrix(const Eigen::Ref<MatType> & mat)
14+
{
15+
if(MatType::IsVectorAtCompileTime)
16+
std::cout << "isVector" << std::endl;
17+
std::cout << "size: cols " << mat.cols() << " rows " << mat.rows() << std::endl;
18+
std::cout << mat << std::endl;
19+
}
20+
21+
template<typename VecType>
22+
void printVector(const Eigen::Ref<VecType> & vec)
23+
{
24+
EIGEN_STATIC_ASSERT_VECTOR_ONLY(VecType);
25+
printMatrix(vec);
26+
}
27+
28+
template<typename MatType>
29+
void setOnes(Eigen::Ref<MatType> mat)
30+
{
31+
printMatrix(mat);
32+
mat.setOnes();
33+
printMatrix(mat);
34+
}
35+
36+
BOOST_PYTHON_MODULE(eigen_ref)
37+
{
38+
namespace bp = boost::python;
39+
eigenpy::enableEigenPy();
40+
41+
bp::def("printMatrix", printMatrix<Vector3d>);
42+
bp::def("printMatrix", printMatrix<VectorXd>);
43+
bp::def("printMatrix", printMatrix<MatrixXd>);
44+
45+
bp::def("printVector", printVector<VectorXd>);
46+
bp::def("printRowVector", printVector<RowVectorXd>);
47+
48+
bp::def("setOnes", setOnes<Vector3d>);
49+
bp::def("setOnes", setOnes<VectorXd>);
50+
bp::def("setOnes", setOnes<MatrixXd>);
51+
}

0 commit comments

Comments
 (0)