From 5a75d3ee5c3562d7574dd61cf2d79d83631aeead Mon Sep 17 00:00:00 2001 From: Antonio Sanchez Date: Tue, 30 Sep 2025 14:28:00 -0700 Subject: [PATCH] Update `geo_homogeneous` test, add eval() to PermutationMatrix. It's the test that's broken, not the functionality. The problem is returning an expression involving `Random()`. Every time the original expression was evaluated, it generated a new random vector, triggering different results in the comparison. Explicitly valuating the random vector first before calling `.homogenous()` fixes this. Also added an `eval()` method to `PermutationMatrix` for consistency with `DenseBase`. Otherwise, you would need to call different functions on different expressions to express the same thing. --- Eigen/src/Core/PermutationMatrix.h | 3 +++ test/geo_homogeneous.cpp | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Eigen/src/Core/PermutationMatrix.h b/Eigen/src/Core/PermutationMatrix.h index eb8e79782..771335451 100644 --- a/Eigen/src/Core/PermutationMatrix.h +++ b/Eigen/src/Core/PermutationMatrix.h @@ -109,6 +109,9 @@ class PermutationBase : public EigenBase { */ DenseMatrixType toDenseMatrix() const { return derived(); } + /** \returns the plain matrix representation of the permutation. */ + DenseMatrixType eval() const { return toDenseMatrix(); } + /** const version of indices(). */ const IndicesType& indices() const { return derived().indices(); } /** \returns a reference to the stored array representing the permutation. */ diff --git a/test/geo_homogeneous.cpp b/test/geo_homogeneous.cpp index 21be26d25..1b515d73c 100644 --- a/test/geo_homogeneous.cpp +++ b/test/geo_homogeneous.cpp @@ -127,8 +127,8 @@ void homogeneous(void) { { const Eigen::PermutationMatrix P{Eigen::Vector::EqualSpaced(0, 1)}; - const auto right = Eigen::Vector::Random().homogeneous(); - const auto left = Eigen::RowVector::Random().homogeneous(); + const auto right = Eigen::Vector::Random().eval().homogeneous(); + const auto left = Eigen::RowVector::Random().eval().homogeneous(); VERIFY_IS_APPROX(P * right, P * right.eval()); VERIFY_IS_APPROX(left * P, left.eval() * P); -- GitLab