mirror of
https://gitlab.com/libeigen/eigen.git
synced 2026-04-10 11:34:33 +08:00
Clang-format tests, examples, libraries, benchmarks, etc.
This commit is contained in:
committed by
Rasmus Munk Larsen
parent
3252ecc7a4
commit
46e9cdb7fe
@@ -9,38 +9,37 @@
|
||||
|
||||
#include "main.h"
|
||||
|
||||
#define VERIFY_THROWS_BADALLOC(a) { \
|
||||
bool threw = false; \
|
||||
try { \
|
||||
a; \
|
||||
} \
|
||||
catch (std::bad_alloc&) { threw = true; } \
|
||||
VERIFY(threw && "should have thrown bad_alloc: " #a); \
|
||||
#define VERIFY_THROWS_BADALLOC(a) \
|
||||
{ \
|
||||
bool threw = false; \
|
||||
try { \
|
||||
a; \
|
||||
} catch (std::bad_alloc&) { \
|
||||
threw = true; \
|
||||
} \
|
||||
VERIFY(threw && "should have thrown bad_alloc: " #a); \
|
||||
}
|
||||
|
||||
template<typename MatrixType>
|
||||
void triggerMatrixBadAlloc(Index rows, Index cols)
|
||||
{
|
||||
VERIFY_THROWS_BADALLOC( MatrixType m(rows, cols) );
|
||||
VERIFY_THROWS_BADALLOC( MatrixType m; m.resize(rows, cols) );
|
||||
VERIFY_THROWS_BADALLOC( MatrixType m; m.conservativeResize(rows, cols) );
|
||||
template <typename MatrixType>
|
||||
void triggerMatrixBadAlloc(Index rows, Index cols) {
|
||||
VERIFY_THROWS_BADALLOC(MatrixType m(rows, cols));
|
||||
VERIFY_THROWS_BADALLOC(MatrixType m; m.resize(rows, cols));
|
||||
VERIFY_THROWS_BADALLOC(MatrixType m; m.conservativeResize(rows, cols));
|
||||
}
|
||||
|
||||
template<typename VectorType>
|
||||
void triggerVectorBadAlloc(Index size)
|
||||
{
|
||||
VERIFY_THROWS_BADALLOC( VectorType v(size) );
|
||||
VERIFY_THROWS_BADALLOC( VectorType v; v.resize(size) );
|
||||
VERIFY_THROWS_BADALLOC( VectorType v; v.conservativeResize(size) );
|
||||
template <typename VectorType>
|
||||
void triggerVectorBadAlloc(Index size) {
|
||||
VERIFY_THROWS_BADALLOC(VectorType v(size));
|
||||
VERIFY_THROWS_BADALLOC(VectorType v; v.resize(size));
|
||||
VERIFY_THROWS_BADALLOC(VectorType v; v.conservativeResize(size));
|
||||
}
|
||||
|
||||
EIGEN_DECLARE_TEST(sizeoverflow)
|
||||
{
|
||||
// there are 2 levels of overflow checking. first in PlainObjectBase.h we check for overflow in rows*cols computations.
|
||||
// this is tested in tests of the form times_itself_gives_0 * times_itself_gives_0
|
||||
// Then in Memory.h we check for overflow in size * sizeof(T) computations.
|
||||
// this is tested in tests of the form times_4_gives_0 * sizeof(float)
|
||||
|
||||
EIGEN_DECLARE_TEST(sizeoverflow) {
|
||||
// there are 2 levels of overflow checking. first in PlainObjectBase.h we check for overflow in rows*cols
|
||||
// computations. this is tested in tests of the form times_itself_gives_0 * times_itself_gives_0 Then in Memory.h we
|
||||
// check for overflow in size * sizeof(T) computations. this is tested in tests of the form times_4_gives_0 *
|
||||
// sizeof(float)
|
||||
|
||||
size_t times_itself_gives_0 = size_t(1) << (8 * sizeof(Index) / 2);
|
||||
VERIFY(times_itself_gives_0 * times_itself_gives_0 == 0);
|
||||
|
||||
@@ -57,8 +56,8 @@ EIGEN_DECLARE_TEST(sizeoverflow)
|
||||
triggerMatrixBadAlloc<MatrixXd>(times_itself_gives_0, times_itself_gives_0);
|
||||
triggerMatrixBadAlloc<MatrixXd>(times_itself_gives_0 / 8, times_itself_gives_0);
|
||||
triggerMatrixBadAlloc<MatrixXd>(times_8_gives_0, 1);
|
||||
|
||||
|
||||
triggerVectorBadAlloc<VectorXf>(times_4_gives_0);
|
||||
|
||||
|
||||
triggerVectorBadAlloc<VectorXd>(times_8_gives_0);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user