Skip to content
Snippets Groups Projects
Commit bf7840fe authored by Wilson Jallet's avatar Wilson Jallet :clapper:
Browse files

unittest/eigen_ref: rename asRef overload to "getRefToStatic"

& update its docstring
parent b3b2aafb
No related branches found
No related tags found
No related merge requests found
......@@ -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>);
......
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)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment