Skip to content

Commit f15dab9

Browse files
committed
test: test to-python for Eigen::Ref
1 parent 115ed93 commit f15dab9

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

unittest/eigen_ref.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@ void fill(Eigen::Ref<MatType> mat, const typename MatType::Scalar & value)
3737
mat.fill(value);
3838
}
3939

40+
template<typename MatType>
41+
Eigen::Ref<MatType> asRef(const int rows, const int cols)
42+
{
43+
static MatType mat(rows,cols);
44+
std::cout << "mat:\n" << mat << std::endl;
45+
return mat;
46+
}
47+
4048
BOOST_PYTHON_MODULE(eigen_ref)
4149
{
4250
namespace bp = boost::python;
@@ -56,4 +64,6 @@ BOOST_PYTHON_MODULE(eigen_ref)
5664
bp::def("fillVec3", fill<Vector3d>);
5765
bp::def("fillVec", fill<VectorXd>);
5866
bp::def("fill", fill<MatrixXd>);
67+
68+
bp::def("asRef", asRef<MatrixXd>);
5969
}

unittest/python/test_eigen_ref.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,16 @@ def test(mat):
88
printMatrix(mat)
99
assert np.array_equal(mat,np.full(mat.shape,1.))
1010

11+
A_ref = asRef(mat.shape[0],mat.shape[1])
12+
A_ref.fill(1.)
13+
A_ref2 = asRef(mat.shape[0],mat.shape[1])
14+
15+
assert np.array_equal(A_ref,A_ref2)
16+
17+
A_ref2.fill(0)
18+
assert np.array_equal(A_ref,A_ref2)
19+
20+
1121
rows = 10
1222
cols = 30
1323

0 commit comments

Comments
 (0)