gtsam
3rdparty
Eigen
unsupported
test
cxx11_maxsizevector.cpp
Go to the documentation of this file.
1
#include "
main.h
"
2
3
#include <exception>
// std::exception
4
5
#include <unsupported/Eigen/CXX11/Tensor>
6
7
struct
Foo
8
{
9
static
Index
object_count
;
10
static
Index
object_limit
;
11
EIGEN_ALIGN_TO_BOUNDARY
(128)
int
dummy
;
12
13
Foo
(
int
x
=0) : dummy(
x
)
14
{
15
#ifdef EIGEN_EXCEPTIONS
16
// TODO: Is this the correct way to handle this?
17
if
(
Foo::object_count
>
Foo::object_limit
) { std::cout <<
"\nThrow!\n"
;
throw
Foo::Fail
(); }
18
#endif
19
std::cout <<
'+'
;
20
++
Foo::object_count
;
21
eigen_assert
((
internal::UIntPtr
(
this
) & (127)) == 0);
22
}
23
Foo
(
const
Foo
&)
24
{
25
std::cout <<
'c'
;
26
++
Foo::object_count
;
27
eigen_assert
((
internal::UIntPtr
(
this
) & (127)) == 0);
28
}
29
30
~Foo
()
31
{
32
std::cout <<
'~'
;
33
--
Foo::object_count
;
34
}
35
36
class
Fail
:
public
std::exception {};
37
};
38
39
Index
Foo::object_count
= 0;
40
Index
Foo::object_limit
= 0;
41
42
43
44
EIGEN_DECLARE_TEST
(cxx11_maxsizevector)
45
{
46
typedef
MaxSizeVector<Foo>
VectorX
;
47
Foo::object_count
= 0;
48
for
(
int
r = 0; r <
g_repeat
; r++) {
49
Index
rows
= internal::random<Index>(3,30);
50
Foo::object_limit
= internal::random<Index>(0, rows - 2);
51
std::cout <<
"object_limit = "
<< Foo::object_limit << std::endl;
52
bool
exception_raised =
false
;
53
#ifdef EIGEN_EXCEPTIONS
54
try
55
{
56
#endif
57
std::cout <<
"\nVectorX m("
<< rows <<
");\n"
;
58
VectorX vect(rows);
59
for
(
int
i
=0;
i
<
rows
; ++
i
)
60
vect.push_back(
Foo
());
61
#ifdef EIGEN_EXCEPTIONS
62
VERIFY
(
false
);
// not reached if exceptions are enabled
63
}
64
catch
(
const
Foo::Fail
&) { exception_raised =
true
; }
65
VERIFY
(exception_raised);
66
#endif
67
VERIFY_IS_EQUAL
(
Index
(0),
Foo::object_count
);
68
69
{
70
Foo::object_limit = rows+1;
71
VectorX vect2(rows,
Foo
());
72
VERIFY_IS_EQUAL
(
Foo::object_count
, rows);
73
}
74
VERIFY_IS_EQUAL
(
Index
(0),
Foo::object_count
);
75
std::cout <<
'\n'
;
76
}
77
}
Foo::Fail
Definition:
ctorleak.cpp:27
VectorX
Matrix< Scalar, Dynamic, 1 > VectorX
Definition:
sparse_lu.cpp:41
Foo::Foo
Foo()
Definition:
ctorleak.cpp:11
Foo::Foo
Foo(const Foo &)
Definition:
cxx11_maxsizevector.cpp:23
Foo::object_limit
static Index object_limit
Definition:
ctorleak.cpp:8
Foo::object_count
static Index object_count
Definition:
ctorleak.cpp:7
Eigen::internal::UIntPtr
std::size_t UIntPtr
Definition:
Meta.h:92
main.h
VERIFY_IS_EQUAL
#define VERIFY_IS_EQUAL(a, b)
Definition:
main.h:386
Eigen::g_repeat
static int g_repeat
Definition:
main.h:169
Eigen::Index
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition:
Meta.h:74
eigen_assert
#define eigen_assert(x)
Definition:
Macros.h:1037
Foo::~Foo
~Foo()
Definition:
cxx11_maxsizevector.cpp:30
Foo::EIGEN_ALIGN_TO_BOUNDARY
EIGEN_ALIGN_TO_BOUNDARY(128) int dummy
VERIFY
#define VERIFY(a)
Definition:
main.h:380
Foo
Definition:
jacobisvd.cpp:77
Foo::dummy
int dummy
Definition:
ctorleak.cpp:9
rows
int rows
Definition:
Tutorial_commainit_02.cpp:1
Eigen::MaxSizeVector
The MaxSizeVector class.
Definition:
MaxSizeVector.h:31
x
set noclip points set clip one set noclip two set bar set border lt lw set xdata set ydata set zdata set x2data set y2data set boxwidth set dummy x
Definition:
gnuplot_common_settings.hh:12
EIGEN_DECLARE_TEST
EIGEN_DECLARE_TEST(cxx11_maxsizevector)
Definition:
cxx11_maxsizevector.cpp:44
i
int i
Definition:
BiCGSTAB_step_by_step.cpp:9
gtsam.examples.DogLegOptimizerExample.int
int
Definition:
DogLegOptimizerExample.py:111
gtsam
Author(s):
autogenerated on Tue Jul 4 2023 02:34:06