gtsam
3rdparty
Eigen
test
exceptions.cpp
Go to the documentation of this file.
1
// This file is part of Eigen, a lightweight C++ template library
2
// for linear algebra.
3
//
4
// Copyright (C) 2011 Gael Guennebaud <gael.guennebaud@inria.fr>
5
//
6
// This Source Code Form is subject to the terms of the Mozilla
7
// Public License v. 2.0. If a copy of the MPL was not distributed
8
// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
9
10
11
// Various sanity tests with exceptions and non trivially copyable scalar type.
12
// - no memory leak when a custom scalar type trow an exceptions
13
// - todo: complete the list of tests!
14
15
#define EIGEN_STACK_ALLOCATION_LIMIT 100000000
16
17
#include "
main.h
"
18
#include "
AnnoyingScalar.h
"
19
20
#define CHECK_MEMLEAK(OP) { \
21
AnnoyingScalar::countdown = 100; \
22
int before = AnnoyingScalar::instances; \
23
bool exception_thrown = false; \
24
try { OP; } \
25
catch (my_exception) { \
26
exception_thrown = true; \
27
VERIFY(AnnoyingScalar::instances==before && "memory leak detected in " && EIGEN_MAKESTRING(OP)); \
28
} \
29
VERIFY( (AnnoyingScalar::dont_throw) || (exception_thrown && " no exception thrown in " && EIGEN_MAKESTRING(OP)) ); \
30
}
31
32
EIGEN_DECLARE_TEST
(exceptions)
33
{
34
typedef
Eigen::Matrix<AnnoyingScalar,Dynamic,1>
VectorType
;
35
typedef
Eigen::Matrix<AnnoyingScalar,Dynamic,Dynamic>
MatrixType
;
36
37
{
38
AnnoyingScalar::dont_throw
=
false
;
39
int
n
= 50;
40
VectorType
v0
(
n
),
v1
(
n
);
41
MatrixType
m0
(
n
,
n
),
m1
(
n
,
n
),
m2
(
n
,
n
);
42
v0
.setOnes();
v1
.setOnes();
43
m0
.setOnes();
m1
.setOnes();
m2
.setOnes();
44
CHECK_MEMLEAK
(
v0
=
m0
*
m1
*
v1
);
45
CHECK_MEMLEAK
(
m2
=
m0
*
m1
*
m2
);
46
CHECK_MEMLEAK
((
v0
+
v1
).
dot
(
v0
+
v1
));
47
}
48
VERIFY
(
AnnoyingScalar::instances
==0 &&
"global memory leak detected in "
&&
EIGEN_MAKESTRING
(
OP
));
49
}
AnnoyingScalar::dont_throw
static bool dont_throw
Definition:
AnnoyingScalar.h:98
v0
static const double v0
Definition:
testCal3DFisheye.cpp:31
MatrixType
MatrixXf MatrixType
Definition:
benchmark-blocking-sizes.cpp:52
AnnoyingScalar.h
CHECK_MEMLEAK
#define CHECK_MEMLEAK(OP)
Definition:
exceptions.cpp:20
m1
Matrix3d m1
Definition:
IOFormat.cpp:2
m0
static const DiscreteKey m0(M(0), 2)
dot
Scalar EIGEN_BLAS_FUNC() dot(int *n, RealScalar *px, int *incx, RealScalar *py, int *incy)
Definition:
level1_real_impl.h:49
n
int n
Definition:
BiCGSTAB_simple.cpp:1
EIGEN_DECLARE_TEST
EIGEN_DECLARE_TEST(exceptions)
Definition:
exceptions.cpp:32
m2
MatrixType m2(n_dims)
EIGEN_MAKESTRING
#define EIGEN_MAKESTRING(a)
Definition:
Macros.h:908
AnnoyingScalar::instances
static int instances
Definition:
AnnoyingScalar.h:95
main.h
OP
#define OP(X)
Definition:
gtsam/3rdparty/Eigen/blas/common.h:47
Eigen::Matrix
The matrix class, also used for vectors and row-vectors.
Definition:
3rdparty/Eigen/Eigen/src/Core/Matrix.h:178
VectorType
Definition:
FFTW.cpp:65
v1
Vector v1
Definition:
testSerializationBase.cpp:38
VERIFY
#define VERIFY(a)
Definition:
main.h:380
gtsam
Author(s):
autogenerated on Fri Nov 1 2024 03:32:30