Fix a collection of random failures encountered when testing with Bazel.

This commit is contained in:
Antonio Sánchez 2025-06-26 16:58:24 +00:00 committed by Rasmus Munk Larsen
parent 0bce653efc
commit a395ee162d
12 changed files with 52 additions and 23 deletions

View File

@ -31,6 +31,15 @@ namespace internal {
#define EIGEN_GPU_HAS_FP16_ARITHMETIC 1
#endif
// We need to distinguish clang as the CUDA compiler from clang as the host compiler,
// invoked by NVCC (e.g. on MacOS). The former needs to see both host and device implementation
// of the functions, while the latter can only deal with one of them.
#if defined(EIGEN_CUDA_ARCH) || defined(EIGEN_HIPCC) || (defined(EIGEN_CUDACC) && EIGEN_COMP_CLANG && !EIGEN_COMP_NVCC)
#define EIGEN_HAS_GPU_DEVICE_FUNCTIONS 1
#else
#define EIGEN_HAS_GPU_DEVICE_FUNCTIONS 0
#endif
// Make sure this is only available when targeting a GPU: we don't want to
// introduce conflicts between these packet_traits definitions and the ones
// we'll use on the host side (SSE, AVX, ...)
@ -74,7 +83,10 @@ struct packet_traits<float> : default_packet_traits {
HasGammaSampleDerAlpha = 1,
HasIGammac = 1,
HasBetaInc = 1,
HasBlend = 0
HasBlend = 0,
HasFloor = 1,
HasCmp = EIGEN_HAS_GPU_DEVICE_FUNCTIONS
};
};
@ -143,10 +155,7 @@ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double2 pset1<double2>(const double& from)
return make_double2(from, from);
}
// We need to distinguish clang as the CUDA compiler from clang as the host compiler,
// invoked by NVCC (e.g. on MacOS). The former needs to see both host and device implementation
// of the functions, while the latter can only deal with one of them.
#if defined(EIGEN_CUDA_ARCH) || defined(EIGEN_HIPCC) || (defined(EIGEN_CUDACC) && EIGEN_COMP_CLANG && !EIGEN_COMP_NVCC)
#if EIGEN_HAS_GPU_DEVICE_FUNCTIONS
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float bitwise_and(const float& a, const float& b) {
return __int_as_float(__float_as_int(a) & __float_as_int(b));
@ -259,8 +268,7 @@ template <>
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double2 pcmp_le<double2>(const double2& a, const double2& b) {
return make_double2(le_mask(a.x, b.x), le_mask(a.y, b.y));
}
#endif // defined(EIGEN_CUDA_ARCH) || defined(EIGEN_HIPCC) || (defined(EIGEN_CUDACC) && EIGEN_COMP_CLANG &&
// !EIGEN_COMP_NVCC)
#endif // EIGEN_HAS_GPU_DEVICE_FUNCTIONS
template <>
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float4 plset<float4>(const float& a) {

View File

@ -274,6 +274,10 @@ struct simpl_chol_helper {
}
};
// Symbol is ODR-used, so we need a definition.
template <typename Scalar, typename StorageIndex>
constexpr StorageIndex simpl_chol_helper<Scalar, StorageIndex>::kEmpty;
} // namespace internal
template <typename Derived>

View File

@ -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

View File

@ -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))));

View File

@ -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);

View File

@ -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

View File

@ -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;

View File

@ -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);

View File

@ -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) {

View File

@ -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);

View File

@ -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));

View File

@ -45,7 +45,7 @@
#include <thread>
#if defined(EIGEN_USE_THREADS) || defined(EIGEN_USE_SYCL)
#include "ThreadPool"
#include "../../../Eigen/ThreadPool"
#endif
#ifdef EIGEN_USE_GPU