mirror of
https://gitlab.com/libeigen/eigen.git
synced 2026-04-10 11:34:33 +08:00
Remove random retry loops in tests (batch 2: indices and integer types)
libeigen/eigen!2261 Co-authored-by: Rasmus Munk Larsen <rmlarsen@gmail.com>
This commit is contained in:
@@ -26,24 +26,13 @@ void signed_integer_type_tests(const MatrixType& m) {
|
||||
|
||||
MatrixType m1(rows, cols), m2 = MatrixType::Random(rows, cols), mzero = MatrixType::Zero(rows, cols);
|
||||
|
||||
{
|
||||
int guard = 0;
|
||||
do {
|
||||
m1 = MatrixType::Random(rows, cols);
|
||||
} while ((m1 == mzero || m1 == m2) && (++guard) < 100);
|
||||
VERIFY(guard < 100);
|
||||
}
|
||||
m1 = MatrixType::Random(rows, cols);
|
||||
if (m1 == mzero || m1 == m2) m1(0, 0) = m2(0, 0) + Scalar(1);
|
||||
|
||||
// check linear structure
|
||||
|
||||
Scalar s1;
|
||||
{
|
||||
int guard = 0;
|
||||
do {
|
||||
s1 = internal::random<Scalar>();
|
||||
} while (s1 == 0 && (++guard) < 100);
|
||||
VERIFY(guard < 100);
|
||||
}
|
||||
Scalar s1 = internal::random<Scalar>();
|
||||
if (s1 == 0) s1 = Scalar(1);
|
||||
|
||||
VERIFY_IS_EQUAL(-(-m1), m1);
|
||||
VERIFY_IS_EQUAL(-m2 + m1 + m2, m1);
|
||||
@@ -71,36 +60,26 @@ 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);
|
||||
|
||||
{
|
||||
int guard = 0;
|
||||
do {
|
||||
m1 = MatrixType::Random(rows, cols);
|
||||
} while ((m1 == mzero || m1 == m2) && (++guard) < 100);
|
||||
VERIFY(guard < 100);
|
||||
}
|
||||
m1 = MatrixType::Random(rows, cols);
|
||||
if (m1 == mzero || m1 == m2) m1(0, 0) = m2(0, 0) + Scalar(1);
|
||||
|
||||
{
|
||||
int guard = 0;
|
||||
do {
|
||||
v1 = VectorType::Random(rows);
|
||||
} while ((v1 == vzero || v1 == v2) && (++guard) < 100);
|
||||
VERIFY(guard < 100);
|
||||
}
|
||||
v1 = VectorType::Random(rows);
|
||||
if (v1 == vzero || v1 == v2) v1(0) = v2(0) + Scalar(1);
|
||||
|
||||
VERIFY_IS_APPROX(v1, v1);
|
||||
VERIFY_IS_EQUAL(v1, v1);
|
||||
VERIFY_IS_NOT_APPROX(v1, 2 * v1);
|
||||
VERIFY_IS_APPROX(vzero, v1 - v1);
|
||||
VERIFY_IS_APPROX(m1, m1);
|
||||
VERIFY_IS_EQUAL(vzero, v1 - v1);
|
||||
VERIFY_IS_EQUAL(m1, m1);
|
||||
VERIFY_IS_NOT_APPROX(m1, 2 * m1);
|
||||
VERIFY_IS_APPROX(mzero, m1 - m1);
|
||||
VERIFY_IS_EQUAL(mzero, m1 - m1);
|
||||
|
||||
VERIFY_IS_APPROX(m3 = m1, m1);
|
||||
VERIFY_IS_EQUAL(m3 = m1, m1);
|
||||
MatrixType m4;
|
||||
VERIFY_IS_APPROX(m4 = m1, m1);
|
||||
VERIFY_IS_EQUAL(m4 = m1, m1);
|
||||
|
||||
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());
|
||||
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());
|
||||
|
||||
// check == / != operators
|
||||
VERIFY(m1 == m1);
|
||||
@@ -113,10 +92,8 @@ void integer_type_tests(const MatrixType& m) {
|
||||
|
||||
// check linear structure
|
||||
|
||||
Scalar s1;
|
||||
do {
|
||||
s1 = internal::random<Scalar>();
|
||||
} while (s1 == 0);
|
||||
Scalar s1 = internal::random<Scalar>();
|
||||
if (s1 == 0) s1 = Scalar(1);
|
||||
|
||||
VERIFY_IS_EQUAL(m1 + m1, 2 * m1);
|
||||
VERIFY_IS_EQUAL(m1 + m2 - m1, m2);
|
||||
@@ -134,10 +111,10 @@ void integer_type_tests(const MatrixType& m) {
|
||||
|
||||
// check matrix product.
|
||||
|
||||
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));
|
||||
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));
|
||||
}
|
||||
|
||||
template <int>
|
||||
|
||||
Reference in New Issue
Block a user