diff --git a/unittest/eigen_ref.cpp b/unittest/eigen_ref.cpp index 1e58cfee4c7760169a605a79f3547b4a43369081..267f4a00666aed7082c38b1ebf334efae66f2113 100644 --- a/unittest/eigen_ref.cpp +++ b/unittest/eigen_ref.cpp @@ -37,6 +37,14 @@ void fill(Eigen::Ref<MatType> mat, const typename MatType::Scalar & value) mat.fill(value); } +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; +} + BOOST_PYTHON_MODULE(eigen_ref) { namespace bp = boost::python; @@ -56,4 +64,6 @@ BOOST_PYTHON_MODULE(eigen_ref) bp::def("fillVec3", fill<Vector3d>); bp::def("fillVec", fill<VectorXd>); bp::def("fill", fill<MatrixXd>); + + bp::def("asRef", asRef<MatrixXd>); } diff --git a/unittest/python/test_eigen_ref.py b/unittest/python/test_eigen_ref.py index fe8cd29e386162e52b5292681d6611f228532524..76721a3f2bb6080b0e7f3a9df1a0f8965f3a33d1 100644 --- a/unittest/python/test_eigen_ref.py +++ b/unittest/python/test_eigen_ref.py @@ -8,6 +8,16 @@ def test(mat): printMatrix(mat) assert np.array_equal(mat,np.full(mat.shape,1.)) + A_ref = asRef(mat.shape[0],mat.shape[1]) + A_ref.fill(1.) + A_ref2 = asRef(mat.shape[0],mat.shape[1]) + + assert np.array_equal(A_ref,A_ref2) + + A_ref2.fill(0) + assert np.array_equal(A_ref,A_ref2) + + rows = 10 cols = 30