diff --git a/unittest/CMakeLists.txt b/unittest/CMakeLists.txt index 8524a1d62587be5d9d413913fc6911fb42f3ce70..8b0a15c8e797fe03b9f4e25cf95299208dd87603 100644 --- a/unittest/CMakeLists.txt +++ b/unittest/CMakeLists.txt @@ -1,5 +1,5 @@ # -# Copyright (c) 2016 CNRS +# Copyright (c) 2016-2018 CNRS # # This file is part of eigenpy # eigenpy is free software: you can redistribute it @@ -40,4 +40,5 @@ ADD_CUSTOM_TARGET(check COMMAND ${CMAKE_CTEST_COMMAND}) ADD_LIB_UNIT_TEST(matrix "eigen3") ADD_LIB_UNIT_TEST(geometry "eigen3") +ADD_LIB_UNIT_TEST(ref "eigen3") diff --git a/unittest/ref.cpp b/unittest/ref.cpp new file mode 100644 index 0000000000000000000000000000000000000000..0ca38fc059f7d987adbf1271d5a71b71afce1d0d --- /dev/null +++ b/unittest/ref.cpp @@ -0,0 +1,59 @@ +/* + * Copyright 2018, Justin Carpentier <jcarpent@laas.fr>, LAAS-CNRS + * + * This file is part of eigenpy. + * eigenpy is free software: you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation, either version 3 of + * the License, or (at your option) any later version. + * eigenpy is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. You should + * have received a copy of the GNU Lesser General Public License along + * with eigenpy. If not, see <http://www.gnu.org/licenses/>. + */ + +#include "eigenpy/eigenpy.hpp" +#include <iostream> + +using namespace Eigen; +using namespace eigenpy; + +template<typename MatType> +void printMatrix(const eigenpy::Ref<MatType> & mat) +{ + 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 MatType> +void printVector(const eigenpy::Ref<MatType> & mat) +{ + EIGEN_STATIC_ASSERT_VECTOR_ONLY(MatType); + printMatrix(mat); +} + +template<typename MatType> +void setOnes(eigenpy::Ref<MatType> mat) +{ + mat.setOnes(); +} + +BOOST_PYTHON_MODULE(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("setOnes", setOnes<Vector3d>); + bp::def("setOnes", setOnes<VectorXd>); + bp::def("setOnes", setOnes<MatrixXd>); +}