mirror of
https://gitlab.com/libeigen/eigen.git
synced 2026-04-10 11:34:33 +08:00
Fix a collection of random failures encountered when testing with Bazel.
This commit is contained in:
committed by
Rasmus Munk Larsen
parent
0bce653efc
commit
a395ee162d
@@ -16,7 +16,7 @@
|
||||
#pragma GCC diagnostic ignored "-Wshadow"
|
||||
#endif
|
||||
|
||||
#ifndef EIGEN_TEST_ANNOYING_SCALAR_DONT_THROW
|
||||
#if defined(EIGEN_EXCEPTIONS) && !defined(EIGEN_TEST_ANNOYING_SCALAR_DONT_THROW)
|
||||
struct my_exception {
|
||||
my_exception() {}
|
||||
~my_exception() {}
|
||||
@@ -76,7 +76,7 @@ class AnnoyingScalar {
|
||||
}
|
||||
|
||||
AnnoyingScalar operator+(const AnnoyingScalar& other) const {
|
||||
#ifndef EIGEN_TEST_ANNOYING_SCALAR_DONT_THROW
|
||||
#if defined(EIGEN_EXCEPTIONS) && !defined(EIGEN_TEST_ANNOYING_SCALAR_DONT_THROW)
|
||||
countdown--;
|
||||
if (countdown <= 0 && !dont_throw) throw my_exception();
|
||||
#endif
|
||||
|
||||
@@ -1340,7 +1340,7 @@ EIGEN_DECLARE_TEST(array_cwise) {
|
||||
CALL_SUBTEST_3(array_generic(Array44d()));
|
||||
CALL_SUBTEST_4(array_generic(
|
||||
ArrayXXcf(internal::random<int>(1, EIGEN_TEST_MAX_SIZE), internal::random<int>(1, EIGEN_TEST_MAX_SIZE))));
|
||||
CALL_SUBTEST_7(array_generic(
|
||||
CALL_SUBTEST_5(array_generic(
|
||||
ArrayXXf(internal::random<int>(1, EIGEN_TEST_MAX_SIZE), internal::random<int>(1, EIGEN_TEST_MAX_SIZE))));
|
||||
CALL_SUBTEST_8(array_generic(
|
||||
ArrayXXi(internal::random<int>(1, EIGEN_TEST_MAX_SIZE), internal::random<int>(1, EIGEN_TEST_MAX_SIZE))));
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
// Various sanity tests with exceptions and non trivially copyable scalar type.
|
||||
// - no memory leak when a custom scalar type trow an exceptions
|
||||
// - no memory leak when a custom scalar type throw an exceptions
|
||||
// - todo: complete the list of tests!
|
||||
|
||||
#define EIGEN_STACK_ALLOCATION_LIMIT 100000000
|
||||
@@ -21,9 +21,8 @@
|
||||
AnnoyingScalar::countdown = 100; \
|
||||
int before = AnnoyingScalar::instances; \
|
||||
bool exception_thrown = false; \
|
||||
try { \
|
||||
OP; \
|
||||
} catch (my_exception) { \
|
||||
EIGEN_TRY { OP; } \
|
||||
EIGEN_CATCH(my_exception) { \
|
||||
exception_thrown = true; \
|
||||
VERIFY(AnnoyingScalar::instances == before && "memory leak detected in " && EIGEN_MAKESTRING(OP)); \
|
||||
} \
|
||||
@@ -35,7 +34,11 @@ EIGEN_DECLARE_TEST(exceptions) {
|
||||
typedef Eigen::Matrix<AnnoyingScalar, Dynamic, Dynamic> MatrixType;
|
||||
|
||||
{
|
||||
#if defined(EIGEN_EXCEPTIONS) && !defined(EIGEN_TEST_ANNOYING_SCALAR_DONT_THROW)
|
||||
AnnoyingScalar::dont_throw = false;
|
||||
#else
|
||||
AnnoyingScalar::dont_throw = true;
|
||||
#endif
|
||||
int n = 50;
|
||||
VectorType v0(n), v1(n);
|
||||
MatrixType m0(n, n), m1(n, n), m2(n, n);
|
||||
|
||||
@@ -343,7 +343,7 @@ static std::vector<std::string> eigen_assert_list;
|
||||
#if !defined(EIGEN_TESTING_CONSTEXPR) && !defined(EIGEN_TESTING_PLAINOBJECT_CTOR)
|
||||
#define EIGEN_INTERNAL_DEBUGGING
|
||||
#endif
|
||||
#include <Eigen/QR> // required for createRandomPIMatrixOfRank and generateRandomMatrixSvs
|
||||
#include <Eigen/Core>
|
||||
|
||||
inline void verify_impl(bool condition, const char* testname, const char* file, int line,
|
||||
const char* condition_as_string) {
|
||||
@@ -935,3 +935,7 @@ int main(int argc, char* argv[]) {
|
||||
#endif
|
||||
|
||||
#include "gpu_test_helper.h"
|
||||
|
||||
#ifndef EIGEN_TEST_MAX_SIZE
|
||||
#define EIGEN_TEST_MAX_SIZE 320
|
||||
#endif
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
#include "main.h"
|
||||
|
||||
#ifdef EIGEN_EXCEPTIONS
|
||||
#include <exception> // std::exception
|
||||
#endif
|
||||
|
||||
#include <Eigen/src/Core/util/MaxSizeVector.h>
|
||||
|
||||
@@ -31,28 +33,27 @@ struct Foo {
|
||||
std::cout << '~';
|
||||
--Foo::object_count;
|
||||
}
|
||||
|
||||
#ifdef EIGEN_EXCEPTIONS
|
||||
class Fail : public std::exception {};
|
||||
#endif
|
||||
};
|
||||
|
||||
Index Foo::object_count = 0;
|
||||
Index Foo::object_limit = 0;
|
||||
|
||||
EIGEN_DECLARE_TEST(cxx11_maxsizevector) {
|
||||
EIGEN_DECLARE_TEST(maxsizevector) {
|
||||
typedef MaxSizeVector<Foo> VectorX;
|
||||
Foo::object_count = 0;
|
||||
for (int r = 0; r < g_repeat; r++) {
|
||||
Index rows = internal::random<Index>(3, 30);
|
||||
Foo::object_limit = internal::random<Index>(0, rows - 2);
|
||||
std::cout << "object_limit = " << Foo::object_limit << std::endl;
|
||||
bool exception_raised = false;
|
||||
#ifdef EIGEN_EXCEPTIONS
|
||||
bool exception_raised = false;
|
||||
try {
|
||||
#endif
|
||||
std::cout << "\nVectorX m(" << rows << ");\n";
|
||||
VectorX vect(rows);
|
||||
for (int i = 0; i < rows; ++i) vect.push_back(Foo());
|
||||
#ifdef EIGEN_EXCEPTIONS
|
||||
VERIFY(false); // not reached if exceptions are enabled
|
||||
} catch (const Foo::Fail&) {
|
||||
exception_raised = true;
|
||||
|
||||
@@ -182,8 +182,8 @@ EIGEN_DECLARE_TEST(redux) {
|
||||
CALL_SUBTEST_5(matrixRedux(ArrayXX<int64_t>(rows, cols)));
|
||||
CALL_SUBTEST_6(matrixRedux(MatrixXcf(rows, cols)));
|
||||
CALL_SUBTEST_6(matrixRedux(ArrayXXcf(rows, cols)));
|
||||
CALL_SUBTEST_6(matrixRedux(MatrixXcd(rows, cols)));
|
||||
CALL_SUBTEST_6(matrixRedux(ArrayXXcd(rows, cols)));
|
||||
CALL_SUBTEST_7(matrixRedux(MatrixXcd(rows, cols)));
|
||||
CALL_SUBTEST_7(matrixRedux(ArrayXXcd(rows, cols)));
|
||||
}
|
||||
for (int i = 0; i < g_repeat; i++) {
|
||||
int size = internal::random<int>(1, maxsize);
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
|
||||
#include "main.h"
|
||||
|
||||
#ifdef EIGEN_EXCEPTIONS
|
||||
#define VERIFY_THROWS_BADALLOC(a) \
|
||||
{ \
|
||||
bool threw = false; \
|
||||
@@ -19,6 +20,10 @@
|
||||
} \
|
||||
VERIFY(threw && "should have thrown bad_alloc: " #a); \
|
||||
}
|
||||
#else
|
||||
// No way to catch a bad alloc - program terminates.
|
||||
#define VERIFY_THROWS_BADALLOC(a)
|
||||
#endif
|
||||
|
||||
template <typename MatrixType>
|
||||
void triggerMatrixBadAlloc(Index rows, Index cols) {
|
||||
|
||||
@@ -381,6 +381,7 @@ void svd_verify_assert_full_only(const MatrixType& input = MatrixType()) {
|
||||
|
||||
typedef Matrix<typename MatrixType::Scalar, RowsAtCompileTime, 1> RhsType;
|
||||
RhsType rhs = RhsType::Zero(input.rows());
|
||||
EIGEN_UNUSED_VARIABLE(rhs); // Only used if asserts are enabled.
|
||||
MatrixType m(input.rows(), input.cols());
|
||||
svd_fill_random(m);
|
||||
|
||||
@@ -410,6 +411,7 @@ void svd_verify_assert(const MatrixType& input = MatrixType()) {
|
||||
enum { RowsAtCompileTime = MatrixType::RowsAtCompileTime };
|
||||
typedef Matrix<typename MatrixType::Scalar, RowsAtCompileTime, 1> RhsType;
|
||||
RhsType rhs = RhsType::Zero(input.rows());
|
||||
EIGEN_UNUSED_VARIABLE(rhs); // Only used if asserts are enabled.
|
||||
MatrixType m(input.rows(), input.cols());
|
||||
svd_fill_random(m);
|
||||
|
||||
|
||||
@@ -24,6 +24,8 @@ void zeroReduction(const MatrixType& m) {
|
||||
VERIFY_RAISES_ASSERT(m.minCoeff());
|
||||
VERIFY_RAISES_ASSERT(m.maxCoeff());
|
||||
Index i, j;
|
||||
EIGEN_UNUSED_VARIABLE(i); // Only used if exceptions are enabled.
|
||||
EIGEN_UNUSED_VARIABLE(j);
|
||||
VERIFY_RAISES_ASSERT(m.minCoeff(&i, &j));
|
||||
VERIFY_RAISES_ASSERT(m.maxCoeff(&i, &j));
|
||||
VERIFY_RAISES_ASSERT(m.reshaped().minCoeff(&i));
|
||||
|
||||
Reference in New Issue
Block a user