mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-07-19 11:24:26 +08:00
Fix a collection of random failures encountered when testing with Bazel.
This commit is contained in:
parent
0bce653efc
commit
a395ee162d
@ -31,6 +31,15 @@ namespace internal {
|
|||||||
#define EIGEN_GPU_HAS_FP16_ARITHMETIC 1
|
#define EIGEN_GPU_HAS_FP16_ARITHMETIC 1
|
||||||
#endif
|
#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
|
// 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
|
// introduce conflicts between these packet_traits definitions and the ones
|
||||||
// we'll use on the host side (SSE, AVX, ...)
|
// we'll use on the host side (SSE, AVX, ...)
|
||||||
@ -74,7 +83,10 @@ struct packet_traits<float> : default_packet_traits {
|
|||||||
HasGammaSampleDerAlpha = 1,
|
HasGammaSampleDerAlpha = 1,
|
||||||
HasIGammac = 1,
|
HasIGammac = 1,
|
||||||
HasBetaInc = 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);
|
return make_double2(from, from);
|
||||||
}
|
}
|
||||||
|
|
||||||
// We need to distinguish ‘clang as the CUDA compiler’ from ‘clang as the host compiler,
|
#if EIGEN_HAS_GPU_DEVICE_FUNCTIONS
|
||||||
// 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)
|
|
||||||
|
|
||||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float bitwise_and(const float& a, const float& b) {
|
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));
|
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) {
|
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));
|
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 &&
|
#endif // EIGEN_HAS_GPU_DEVICE_FUNCTIONS
|
||||||
// !EIGEN_COMP_NVCC)
|
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float4 plset<float4>(const float& a) {
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float4 plset<float4>(const float& a) {
|
||||||
|
@ -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
|
} // namespace internal
|
||||||
|
|
||||||
template <typename Derived>
|
template <typename Derived>
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
#pragma GCC diagnostic ignored "-Wshadow"
|
#pragma GCC diagnostic ignored "-Wshadow"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef EIGEN_TEST_ANNOYING_SCALAR_DONT_THROW
|
#if defined(EIGEN_EXCEPTIONS) && !defined(EIGEN_TEST_ANNOYING_SCALAR_DONT_THROW)
|
||||||
struct my_exception {
|
struct my_exception {
|
||||||
my_exception() {}
|
my_exception() {}
|
||||||
~my_exception() {}
|
~my_exception() {}
|
||||||
@ -76,7 +76,7 @@ class AnnoyingScalar {
|
|||||||
}
|
}
|
||||||
|
|
||||||
AnnoyingScalar operator+(const AnnoyingScalar& other) const {
|
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--;
|
countdown--;
|
||||||
if (countdown <= 0 && !dont_throw) throw my_exception();
|
if (countdown <= 0 && !dont_throw) throw my_exception();
|
||||||
#endif
|
#endif
|
||||||
|
@ -1340,7 +1340,7 @@ EIGEN_DECLARE_TEST(array_cwise) {
|
|||||||
CALL_SUBTEST_3(array_generic(Array44d()));
|
CALL_SUBTEST_3(array_generic(Array44d()));
|
||||||
CALL_SUBTEST_4(array_generic(
|
CALL_SUBTEST_4(array_generic(
|
||||||
ArrayXXcf(internal::random<int>(1, EIGEN_TEST_MAX_SIZE), internal::random<int>(1, EIGEN_TEST_MAX_SIZE))));
|
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))));
|
ArrayXXf(internal::random<int>(1, EIGEN_TEST_MAX_SIZE), internal::random<int>(1, EIGEN_TEST_MAX_SIZE))));
|
||||||
CALL_SUBTEST_8(array_generic(
|
CALL_SUBTEST_8(array_generic(
|
||||||
ArrayXXi(internal::random<int>(1, EIGEN_TEST_MAX_SIZE), internal::random<int>(1, EIGEN_TEST_MAX_SIZE))));
|
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/.
|
// 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.
|
// 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!
|
// - todo: complete the list of tests!
|
||||||
|
|
||||||
#define EIGEN_STACK_ALLOCATION_LIMIT 100000000
|
#define EIGEN_STACK_ALLOCATION_LIMIT 100000000
|
||||||
@ -21,9 +21,8 @@
|
|||||||
AnnoyingScalar::countdown = 100; \
|
AnnoyingScalar::countdown = 100; \
|
||||||
int before = AnnoyingScalar::instances; \
|
int before = AnnoyingScalar::instances; \
|
||||||
bool exception_thrown = false; \
|
bool exception_thrown = false; \
|
||||||
try { \
|
EIGEN_TRY { OP; } \
|
||||||
OP; \
|
EIGEN_CATCH(my_exception) { \
|
||||||
} catch (my_exception) { \
|
|
||||||
exception_thrown = true; \
|
exception_thrown = true; \
|
||||||
VERIFY(AnnoyingScalar::instances == before && "memory leak detected in " && EIGEN_MAKESTRING(OP)); \
|
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;
|
typedef Eigen::Matrix<AnnoyingScalar, Dynamic, Dynamic> MatrixType;
|
||||||
|
|
||||||
{
|
{
|
||||||
|
#if defined(EIGEN_EXCEPTIONS) && !defined(EIGEN_TEST_ANNOYING_SCALAR_DONT_THROW)
|
||||||
AnnoyingScalar::dont_throw = false;
|
AnnoyingScalar::dont_throw = false;
|
||||||
|
#else
|
||||||
|
AnnoyingScalar::dont_throw = true;
|
||||||
|
#endif
|
||||||
int n = 50;
|
int n = 50;
|
||||||
VectorType v0(n), v1(n);
|
VectorType v0(n), v1(n);
|
||||||
MatrixType m0(n, n), m1(n, n), m2(n, 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)
|
#if !defined(EIGEN_TESTING_CONSTEXPR) && !defined(EIGEN_TESTING_PLAINOBJECT_CTOR)
|
||||||
#define EIGEN_INTERNAL_DEBUGGING
|
#define EIGEN_INTERNAL_DEBUGGING
|
||||||
#endif
|
#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,
|
inline void verify_impl(bool condition, const char* testname, const char* file, int line,
|
||||||
const char* condition_as_string) {
|
const char* condition_as_string) {
|
||||||
@ -935,3 +935,7 @@ int main(int argc, char* argv[]) {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "gpu_test_helper.h"
|
#include "gpu_test_helper.h"
|
||||||
|
|
||||||
|
#ifndef EIGEN_TEST_MAX_SIZE
|
||||||
|
#define EIGEN_TEST_MAX_SIZE 320
|
||||||
|
#endif
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
#include "main.h"
|
#include "main.h"
|
||||||
|
|
||||||
|
#ifdef EIGEN_EXCEPTIONS
|
||||||
#include <exception> // std::exception
|
#include <exception> // std::exception
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <Eigen/src/Core/util/MaxSizeVector.h>
|
#include <Eigen/src/Core/util/MaxSizeVector.h>
|
||||||
|
|
||||||
@ -31,28 +33,27 @@ struct Foo {
|
|||||||
std::cout << '~';
|
std::cout << '~';
|
||||||
--Foo::object_count;
|
--Foo::object_count;
|
||||||
}
|
}
|
||||||
|
#ifdef EIGEN_EXCEPTIONS
|
||||||
class Fail : public std::exception {};
|
class Fail : public std::exception {};
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
Index Foo::object_count = 0;
|
Index Foo::object_count = 0;
|
||||||
Index Foo::object_limit = 0;
|
Index Foo::object_limit = 0;
|
||||||
|
|
||||||
EIGEN_DECLARE_TEST(cxx11_maxsizevector) {
|
EIGEN_DECLARE_TEST(maxsizevector) {
|
||||||
typedef MaxSizeVector<Foo> VectorX;
|
typedef MaxSizeVector<Foo> VectorX;
|
||||||
Foo::object_count = 0;
|
Foo::object_count = 0;
|
||||||
for (int r = 0; r < g_repeat; r++) {
|
for (int r = 0; r < g_repeat; r++) {
|
||||||
Index rows = internal::random<Index>(3, 30);
|
Index rows = internal::random<Index>(3, 30);
|
||||||
Foo::object_limit = internal::random<Index>(0, rows - 2);
|
Foo::object_limit = internal::random<Index>(0, rows - 2);
|
||||||
std::cout << "object_limit = " << Foo::object_limit << std::endl;
|
std::cout << "object_limit = " << Foo::object_limit << std::endl;
|
||||||
bool exception_raised = false;
|
|
||||||
#ifdef EIGEN_EXCEPTIONS
|
#ifdef EIGEN_EXCEPTIONS
|
||||||
|
bool exception_raised = false;
|
||||||
try {
|
try {
|
||||||
#endif
|
|
||||||
std::cout << "\nVectorX m(" << rows << ");\n";
|
std::cout << "\nVectorX m(" << rows << ");\n";
|
||||||
VectorX vect(rows);
|
VectorX vect(rows);
|
||||||
for (int i = 0; i < rows; ++i) vect.push_back(Foo());
|
for (int i = 0; i < rows; ++i) vect.push_back(Foo());
|
||||||
#ifdef EIGEN_EXCEPTIONS
|
|
||||||
VERIFY(false); // not reached if exceptions are enabled
|
VERIFY(false); // not reached if exceptions are enabled
|
||||||
} catch (const Foo::Fail&) {
|
} catch (const Foo::Fail&) {
|
||||||
exception_raised = true;
|
exception_raised = true;
|
||||||
|
@ -182,8 +182,8 @@ EIGEN_DECLARE_TEST(redux) {
|
|||||||
CALL_SUBTEST_5(matrixRedux(ArrayXX<int64_t>(rows, cols)));
|
CALL_SUBTEST_5(matrixRedux(ArrayXX<int64_t>(rows, cols)));
|
||||||
CALL_SUBTEST_6(matrixRedux(MatrixXcf(rows, cols)));
|
CALL_SUBTEST_6(matrixRedux(MatrixXcf(rows, cols)));
|
||||||
CALL_SUBTEST_6(matrixRedux(ArrayXXcf(rows, cols)));
|
CALL_SUBTEST_6(matrixRedux(ArrayXXcf(rows, cols)));
|
||||||
CALL_SUBTEST_6(matrixRedux(MatrixXcd(rows, cols)));
|
CALL_SUBTEST_7(matrixRedux(MatrixXcd(rows, cols)));
|
||||||
CALL_SUBTEST_6(matrixRedux(ArrayXXcd(rows, cols)));
|
CALL_SUBTEST_7(matrixRedux(ArrayXXcd(rows, cols)));
|
||||||
}
|
}
|
||||||
for (int i = 0; i < g_repeat; i++) {
|
for (int i = 0; i < g_repeat; i++) {
|
||||||
int size = internal::random<int>(1, maxsize);
|
int size = internal::random<int>(1, maxsize);
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
|
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
|
|
||||||
|
#ifdef EIGEN_EXCEPTIONS
|
||||||
#define VERIFY_THROWS_BADALLOC(a) \
|
#define VERIFY_THROWS_BADALLOC(a) \
|
||||||
{ \
|
{ \
|
||||||
bool threw = false; \
|
bool threw = false; \
|
||||||
@ -19,6 +20,10 @@
|
|||||||
} \
|
} \
|
||||||
VERIFY(threw && "should have thrown bad_alloc: " #a); \
|
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>
|
template <typename MatrixType>
|
||||||
void triggerMatrixBadAlloc(Index rows, Index cols) {
|
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;
|
typedef Matrix<typename MatrixType::Scalar, RowsAtCompileTime, 1> RhsType;
|
||||||
RhsType rhs = RhsType::Zero(input.rows());
|
RhsType rhs = RhsType::Zero(input.rows());
|
||||||
|
EIGEN_UNUSED_VARIABLE(rhs); // Only used if asserts are enabled.
|
||||||
MatrixType m(input.rows(), input.cols());
|
MatrixType m(input.rows(), input.cols());
|
||||||
svd_fill_random(m);
|
svd_fill_random(m);
|
||||||
|
|
||||||
@ -410,6 +411,7 @@ void svd_verify_assert(const MatrixType& input = MatrixType()) {
|
|||||||
enum { RowsAtCompileTime = MatrixType::RowsAtCompileTime };
|
enum { RowsAtCompileTime = MatrixType::RowsAtCompileTime };
|
||||||
typedef Matrix<typename MatrixType::Scalar, RowsAtCompileTime, 1> RhsType;
|
typedef Matrix<typename MatrixType::Scalar, RowsAtCompileTime, 1> RhsType;
|
||||||
RhsType rhs = RhsType::Zero(input.rows());
|
RhsType rhs = RhsType::Zero(input.rows());
|
||||||
|
EIGEN_UNUSED_VARIABLE(rhs); // Only used if asserts are enabled.
|
||||||
MatrixType m(input.rows(), input.cols());
|
MatrixType m(input.rows(), input.cols());
|
||||||
svd_fill_random(m);
|
svd_fill_random(m);
|
||||||
|
|
||||||
|
@ -24,6 +24,8 @@ void zeroReduction(const MatrixType& m) {
|
|||||||
VERIFY_RAISES_ASSERT(m.minCoeff());
|
VERIFY_RAISES_ASSERT(m.minCoeff());
|
||||||
VERIFY_RAISES_ASSERT(m.maxCoeff());
|
VERIFY_RAISES_ASSERT(m.maxCoeff());
|
||||||
Index i, j;
|
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.minCoeff(&i, &j));
|
||||||
VERIFY_RAISES_ASSERT(m.maxCoeff(&i, &j));
|
VERIFY_RAISES_ASSERT(m.maxCoeff(&i, &j));
|
||||||
VERIFY_RAISES_ASSERT(m.reshaped().minCoeff(&i));
|
VERIFY_RAISES_ASSERT(m.reshaped().minCoeff(&i));
|
||||||
|
@ -45,7 +45,7 @@
|
|||||||
#include <thread>
|
#include <thread>
|
||||||
|
|
||||||
#if defined(EIGEN_USE_THREADS) || defined(EIGEN_USE_SYCL)
|
#if defined(EIGEN_USE_THREADS) || defined(EIGEN_USE_SYCL)
|
||||||
#include "ThreadPool"
|
#include "../../../Eigen/ThreadPool"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef EIGEN_USE_GPU
|
#ifdef EIGEN_USE_GPU
|
||||||
|
Loading…
x
Reference in New Issue
Block a user