Verified Commit f15dab93 authored by Justin Carpentier's avatar Justin Carpentier
Browse files

test: test to-python for Eigen::Ref

parent 115ed938
Pipeline #10829 passed with stage
in 16 minutes and 24 seconds
......@@ -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>);
}
......@@ -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
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment