Skip to content

Commit b77b9aa

Browse files
committed
[Test] Add unit test for Ref
1 parent 02e96c2 commit b77b9aa

File tree

2 files changed

+61
-1
lines changed

2 files changed

+61
-1
lines changed

unittest/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright (c) 2016 CNRS
2+
# Copyright (c) 2016-2018 CNRS
33
#
44
# This file is part of eigenpy
55
# eigenpy is free software: you can redistribute it
@@ -40,4 +40,5 @@ ADD_CUSTOM_TARGET(check COMMAND ${CMAKE_CTEST_COMMAND})
4040

4141
ADD_LIB_UNIT_TEST(matrix "eigen3")
4242
ADD_LIB_UNIT_TEST(geometry "eigen3")
43+
ADD_LIB_UNIT_TEST(ref "eigen3")
4344

unittest/ref.cpp

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* Copyright 2018, Justin Carpentier <[email protected]>, LAAS-CNRS
3+
*
4+
* This file is part of eigenpy.
5+
* eigenpy is free software: you can redistribute it and/or
6+
* modify it under the terms of the GNU Lesser General Public License
7+
* as published by the Free Software Foundation, either version 3 of
8+
* the License, or (at your option) any later version.
9+
* eigenpy is distributed in the hope that it will be
10+
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty
11+
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU Lesser General Public License for more details. You should
13+
* have received a copy of the GNU Lesser General Public License along
14+
* with eigenpy. If not, see <http://www.gnu.org/licenses/>.
15+
*/
16+
17+
#include "eigenpy/eigenpy.hpp"
18+
#include <iostream>
19+
20+
using namespace Eigen;
21+
using namespace eigenpy;
22+
23+
template<typename MatType>
24+
void printMatrix(const eigenpy::Ref<MatType> & mat)
25+
{
26+
if(MatType::IsVectorAtCompileTime)
27+
std::cout << "isVector" << std::endl;
28+
std::cout << "size: cols " << mat.cols() << " rows " << mat.rows() << std::endl;
29+
std::cout << mat << std::endl;
30+
}
31+
32+
template<typename MatType>
33+
void printVector(const eigenpy::Ref<MatType> & mat)
34+
{
35+
EIGEN_STATIC_ASSERT_VECTOR_ONLY(MatType);
36+
printMatrix(mat);
37+
}
38+
39+
template<typename MatType>
40+
void setOnes(eigenpy::Ref<MatType> mat)
41+
{
42+
mat.setOnes();
43+
}
44+
45+
BOOST_PYTHON_MODULE(ref)
46+
{
47+
namespace bp = boost::python;
48+
eigenpy::enableEigenPy();
49+
50+
bp::def("printMatrix", printMatrix<Vector3d>);
51+
bp::def("printMatrix", printMatrix<VectorXd>);
52+
bp::def("printMatrix", printMatrix<MatrixXd>);
53+
54+
bp::def("printVector", printVector<VectorXd>);
55+
56+
bp::def("setOnes", setOnes<Vector3d>);
57+
bp::def("setOnes", setOnes<VectorXd>);
58+
bp::def("setOnes", setOnes<MatrixXd>);
59+
}

0 commit comments

Comments
 (0)