Revert "Remove random retry loops in tests (batch 2: indices and integer types)"

This reverts merge request !2261
This commit is contained in:
Rasmus Munk Larsen
2026-03-09 20:01:53 -07:00
parent 54458cb39d
commit 42b6c43cfe
6 changed files with 95 additions and 66 deletions

View File

@@ -26,13 +26,24 @@ void signed_integer_type_tests(const MatrixType& m) {
MatrixType m1(rows, cols), m2 = MatrixType::Random(rows, cols), mzero = MatrixType::Zero(rows, cols);
m1 = MatrixType::Random(rows, cols);
if (m1 == mzero || m1 == m2) m1(0, 0) = m2(0, 0) + Scalar(1);
{
int guard = 0;
do {
m1 = MatrixType::Random(rows, cols);
} while ((m1 == mzero || m1 == m2) && (++guard) < 100);
VERIFY(guard < 100);
}
// check linear structure
Scalar s1 = internal::random<Scalar>();
if (s1 == 0) s1 = Scalar(1);
Scalar s1;
{
int guard = 0;
do {
s1 = internal::random<Scalar>();
} while (s1 == 0 && (++guard) < 100);
VERIFY(guard < 100);
}
VERIFY_IS_EQUAL(-(-m1), m1);
VERIFY_IS_EQUAL(-m2 + m1 + m2, m1);
@@ -60,26 +71,36 @@ void integer_type_tests(const MatrixType& m) {
SquareMatrixType identity = SquareMatrixType::Identity(rows, rows), square = SquareMatrixType::Random(rows, rows);
VectorType v1(rows), v2 = VectorType::Random(rows), vzero = VectorType::Zero(rows);
m1 = MatrixType::Random(rows, cols);
if (m1 == mzero || m1 == m2) m1(0, 0) = m2(0, 0) + Scalar(1);
{
int guard = 0;
do {
m1 = MatrixType::Random(rows, cols);
} while ((m1 == mzero || m1 == m2) && (++guard) < 100);
VERIFY(guard < 100);
}
v1 = VectorType::Random(rows);
if (v1 == vzero || v1 == v2) v1(0) = v2(0) + Scalar(1);
{
int guard = 0;
do {
v1 = VectorType::Random(rows);
} while ((v1 == vzero || v1 == v2) && (++guard) < 100);
VERIFY(guard < 100);
}
VERIFY_IS_EQUAL(v1, v1);
VERIFY_IS_APPROX(v1, v1);
VERIFY_IS_NOT_APPROX(v1, 2 * v1);
VERIFY_IS_EQUAL(vzero, v1 - v1);
VERIFY_IS_EQUAL(m1, m1);
VERIFY_IS_APPROX(vzero, v1 - v1);
VERIFY_IS_APPROX(m1, m1);
VERIFY_IS_NOT_APPROX(m1, 2 * m1);
VERIFY_IS_EQUAL(mzero, m1 - m1);
VERIFY_IS_APPROX(mzero, m1 - m1);
VERIFY_IS_EQUAL(m3 = m1, m1);
VERIFY_IS_APPROX(m3 = m1, m1);
MatrixType m4;
VERIFY_IS_EQUAL(m4 = m1, m1);
VERIFY_IS_APPROX(m4 = m1, m1);
m3.real() = m1.real();
VERIFY_IS_EQUAL(static_cast<const MatrixType&>(m3).real(), static_cast<const MatrixType&>(m1).real());
VERIFY_IS_EQUAL(static_cast<const MatrixType&>(m3).real(), m1.real());
VERIFY_IS_APPROX(static_cast<const MatrixType&>(m3).real(), static_cast<const MatrixType&>(m1).real());
VERIFY_IS_APPROX(static_cast<const MatrixType&>(m3).real(), m1.real());
// check == / != operators
VERIFY(m1 == m1);
@@ -92,8 +113,10 @@ void integer_type_tests(const MatrixType& m) {
// check linear structure
Scalar s1 = internal::random<Scalar>();
if (s1 == 0) s1 = Scalar(1);
Scalar s1;
do {
s1 = internal::random<Scalar>();
} while (s1 == 0);
VERIFY_IS_EQUAL(m1 + m1, 2 * m1);
VERIFY_IS_EQUAL(m1 + m2 - m1, m2);
@@ -111,10 +134,10 @@ void integer_type_tests(const MatrixType& m) {
// check matrix product.
VERIFY_IS_EQUAL(identity * m1, m1);
VERIFY_IS_EQUAL(square * (m1 + m2), square * m1 + square * m2);
VERIFY_IS_EQUAL((m1 + m2).transpose() * square, m1.transpose() * square + m2.transpose() * square);
VERIFY_IS_EQUAL((m1 * m2.transpose()) * m1, m1 * (m2.transpose() * m1));
VERIFY_IS_APPROX(identity * m1, m1);
VERIFY_IS_APPROX(square * (m1 + m2), square * m1 + square * m2);
VERIFY_IS_APPROX((m1 + m2).transpose() * square, m1.transpose() * square + m2.transpose() * square);
VERIFY_IS_APPROX((m1 * m2.transpose()) * m1, m1 * (m2.transpose() * m1));
}
template <int>