Skip to content
Snippets Groups Projects
Verified Commit 9e606508 authored by Justin Carpentier's avatar Justin Carpentier
Browse files

test: add test for Eigen::Ref

parent 1fe6a61c
No related branches found
No related tags found
No related merge requests found
......@@ -42,6 +42,7 @@ ADD_PYTHON_UNIT_TEST("py-matrix" "unittest/python/test_matrix.py" "unittest")
ADD_PYTHON_UNIT_TEST("py-geometry" "unittest/python/test_geometry.py" "unittest")
ADD_PYTHON_UNIT_TEST("py-complex" "unittest/python/test_complex.py" "unittest")
ADD_PYTHON_UNIT_TEST("py-return-by-ref" "unittest/python/test_return_by_ref.py" "unittest")
ADD_PYTHON_UNIT_TEST("py-eigen-ref" "unittest/python/test_eigen_ref.py" "unittest")
ADD_PYTHON_UNIT_TEST("py-switch" "unittest/python/test_switch.py" "python/eigenpy")
SET_TESTS_PROPERTIES("py-switch" PROPERTIES DEPENDS ${PYWRAP})
......
......@@ -10,7 +10,7 @@ using namespace Eigen;
using namespace eigenpy;
template<typename MatType>
void printMatrix(const Eigen::Ref<MatType> & mat)
void printMatrix(const Eigen::Ref<const MatType> mat)
{
if(MatType::IsVectorAtCompileTime)
std::cout << "isVector" << std::endl;
......@@ -19,7 +19,7 @@ void printMatrix(const Eigen::Ref<MatType> & mat)
}
template<typename VecType>
void printVector(const Eigen::Ref<VecType> & vec)
void printVector(const Eigen::Ref<const VecType> & vec)
{
EIGEN_STATIC_ASSERT_VECTOR_ONLY(VecType);
printMatrix(vec);
......@@ -28,9 +28,13 @@ void printVector(const Eigen::Ref<VecType> & vec)
template<typename MatType>
void setOnes(Eigen::Ref<MatType> mat)
{
printMatrix(mat);
mat.setOnes();
printMatrix(mat);
}
template<typename MatType>
void fill(Eigen::Ref<MatType> mat, const typename MatType::Scalar & value)
{
mat.fill(value);
}
BOOST_PYTHON_MODULE(eigen_ref)
......@@ -48,4 +52,8 @@ BOOST_PYTHON_MODULE(eigen_ref)
bp::def("setOnes", setOnes<Vector3d>);
bp::def("setOnes", setOnes<VectorXd>);
bp::def("setOnes", setOnes<MatrixXd>);
bp::def("fillVec3", fill<Vector3d>);
bp::def("fillVec", fill<VectorXd>);
bp::def("fill", fill<MatrixXd>);
}
import numpy as np
from eigen_ref import *
def test(mat):
printMatrix(mat)
fill(mat,1.)
printMatrix(mat)
assert np.array_equal(mat,np.full(mat.shape,1.))
rows = 10
cols = 30
mat = np.array(np.zeros((rows,cols)))
test(mat)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment