diff --git a/unittest/eigen_ref.cpp b/unittest/eigen_ref.cpp index 2813e00bf60bec8dabfbd008f8cd538a13262ba4..66249edbfb11cfd20dc93be976adffa1850bc1bb 100644 --- a/unittest/eigen_ref.cpp +++ b/unittest/eigen_ref.cpp @@ -58,8 +58,9 @@ void fill(Eigen::Ref<MatType> mat, const typename MatType::Scalar& value) { mat.fill(value); } +/// Get ref to a static matrix of size ( @p rows, @p cols ) template <typename MatType> -Eigen::Ref<MatType> asRef(const int rows, const int cols) { +Eigen::Ref<MatType> getRefToStatic(const int rows, const int cols) { static MatType mat(rows, cols); std::cout << "create ref to matrix of size (" << rows << "," << cols << ")\n"; return mat; @@ -113,10 +114,8 @@ BOOST_PYTHON_MODULE(eigen_ref) { bp::def("fillVec", fill<VectorXd>); bp::def("fill", fill<MatrixXd>); - bp::def<Eigen::Ref<MatrixXd> (*)(const int, const int)>("asRef", - asRef<MatrixXd>); - bp::def<Eigen::Ref<MatrixXd> (*)(Eigen::Ref<MatrixXd>)>("asRef", - asRef<MatrixXd>); + bp::def("getRefToStatic", getRefToStatic<MatrixXd>); + bp::def("asRef", asRef<MatrixXd>); bp::def("asConstRef", asConstRef<MatrixXd>); bp::def("getBlock", &getBlock<MatrixXd>); diff --git a/unittest/python/test_eigen_ref.py b/unittest/python/test_eigen_ref.py index 0ed65834589105aaa3e9c61b411e9af1093f87b5..fe43e501fd28abc13c7a4fab257f7ea7ccab1faa 100644 --- a/unittest/python/test_eigen_ref.py +++ b/unittest/python/test_eigen_ref.py @@ -1,6 +1,7 @@ import numpy as np from eigen_ref import ( printMatrix, + getRefToStatic, asRef, asConstRef, fill, @@ -30,11 +31,11 @@ def test_create_ref_to_static(mat): # create ref to static: print() print("[asRef(int, int)]") - A_ref = asRef(mat.shape[0], mat.shape[1]) + A_ref = getRefToStatic(mat.shape[0], mat.shape[1]) A_ref.fill(1.0) A_ref[0, 1] = -1.0 print("make second reference:") - A_ref2 = asRef(mat.shape[0], mat.shape[1]) + A_ref2 = getRefToStatic(mat.shape[0], mat.shape[1]) print(A_ref2) assert np.array_equal(A_ref, A_ref2)