From be7538ed65739237c55a12b36c6b0b243452660d Mon Sep 17 00:00:00 2001 From: Rasmus Munk Larsen <4643818-rmlarsen1@users.noreply.gitlab.com> Date: Sun, 8 Mar 2026 10:44:57 -0700 Subject: [PATCH] Remove random retry loops in tests (batch 1: simple scalar cases) libeigen/eigen!2260 Co-authored-by: Rasmus Munk Larsen --- test/basicstuff.cpp | 4 ++-- test/linearstructure.cpp | 2 +- test/nullary.cpp | 5 +---- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/test/basicstuff.cpp b/test/basicstuff.cpp index 455cbfddb..882d4a9c0 100644 --- a/test/basicstuff.cpp +++ b/test/basicstuff.cpp @@ -38,8 +38,8 @@ void basicStuff(const MatrixType& m) { VectorType v1 = VectorType::Random(rows), vzero = VectorType::Zero(rows); SquareMatrixType sm1 = SquareMatrixType::Random(rows, rows), sm2(rows, rows); - Scalar x = 0; - while (x == Scalar(0)) x = internal::random(); + Scalar x = internal::random(); + if (x == Scalar(0)) x = Scalar(1); Index r = internal::random(0, rows - 1), c = internal::random(0, cols - 1); diff --git a/test/linearstructure.cpp b/test/linearstructure.cpp index e5684a52f..80cf4c331 100644 --- a/test/linearstructure.cpp +++ b/test/linearstructure.cpp @@ -31,7 +31,7 @@ void linearStructure(const MatrixType& m) { MatrixType m1 = MatrixType::Random(rows, cols), m2 = MatrixType::Random(rows, cols), m3(rows, cols); Scalar s1 = internal::random(); - while (abs(s1) < RealScalar(1e-3)) s1 = internal::random(); + if (s1 == Scalar(0)) s1 = Scalar(1); Index r = internal::random(0, rows - 1), c = internal::random(0, cols - 1); diff --git a/test/nullary.cpp b/test/nullary.cpp index c2bbe3f4f..71cf9cbea 100644 --- a/test/nullary.cpp +++ b/test/nullary.cpp @@ -209,10 +209,7 @@ void testMatrixType(const MatrixType& m) { typedef typename MatrixType::Scalar Scalar; typedef typename MatrixType::RealScalar RealScalar; - Scalar s1; - do { - s1 = internal::random(); - } while (abs(s1) < RealScalar(1e-5) && (!NumTraits::IsInteger)); + Scalar s1 = internal::random(); MatrixType A; A.setIdentity(rows, cols);