gtsam
3rdparty
Eigen
test
qtvector.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) 2008 Gael Guennebaud <gael.guennebaud@inria.fr>
5
// Copyright (C) 2008 Benoit Jacob <jacob.benoit.1@gmail.com>
6
//
7
// This Source Code Form is subject to the terms of the Mozilla
8
// Public License v. 2.0. If a copy of the MPL was not distributed
9
// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
10
11
#define EIGEN_WORK_AROUND_QT_BUG_CALLING_WRONG_OPERATOR_NEW_FIXED_IN_QT_4_5
12
13
#include "
main.h
"
14
#include <QtCore/QVector>
15
#include <Eigen/Geometry>
16
#include <Eigen/QtAlignedMalloc>
17
18
template
<
typename
MatrixType>
19
void
check_qtvector_matrix
(
const
MatrixType
&
m
)
20
{
21
Index
rows
=
m
.rows();
22
Index
cols
=
m
.cols();
23
MatrixType
x
= MatrixType::Random(
rows
,
cols
),
y
= MatrixType::Random(
rows
,
cols
);
24
QVector<MatrixType>
v
(10,
MatrixType
(
rows
,
cols
)),
w
(20,
y
);
25
for
(
int
i
= 0;
i
< 20;
i
++)
26
{
27
VERIFY_IS_APPROX
(
w
[
i
],
y
);
28
}
29
v
[5] =
x
;
30
w
[6] =
v
[5];
31
VERIFY_IS_APPROX
(
w
[6],
v
[5]);
32
v
=
w
;
33
for
(
int
i
= 0;
i
< 20;
i
++)
34
{
35
VERIFY_IS_APPROX
(
w
[
i
],
v
[
i
]);
36
}
37
38
v
.resize(21);
39
v
[20] =
x
;
40
VERIFY_IS_APPROX
(
v
[20],
x
);
41
v
.fill(
y
,22);
42
VERIFY_IS_APPROX
(
v
[21],
y
);
43
v
.push_back(
x
);
44
VERIFY_IS_APPROX
(
v
[22],
x
);
45
VERIFY
((
size_t
)&(
v
[22]) == (
size_t
)&(
v
[21]) +
sizeof
(
MatrixType
));
46
47
// do a lot of push_back such that the vector gets internally resized
48
// (with memory reallocation)
49
MatrixType
*
ref
= &
w
[0];
50
for
(
int
i
=0;
i
<30 || ((
ref
==&
w
[0]) &&
i
<300); ++
i
)
51
v
.push_back(
w
[
i
%
w
.size()]);
52
for
(
int
i
=23;
i
<
v
.size(); ++
i
)
53
{
54
VERIFY
(
v
[
i
]==
w
[(
i
-23)%
w
.size()]);
55
}
56
}
57
58
template
<
typename
TransformType>
59
void
check_qtvector_transform
(
const
TransformType&)
60
{
61
typedef
typename
TransformType::MatrixType
MatrixType
;
62
TransformType
x
(MatrixType::Random()),
y
(MatrixType::Random());
63
QVector<TransformType>
v
(10),
w
(20,
y
);
64
v
[5] =
x
;
65
w
[6] =
v
[5];
66
VERIFY_IS_APPROX
(
w
[6],
v
[5]);
67
v
=
w
;
68
for
(
int
i
= 0;
i
< 20;
i
++)
69
{
70
VERIFY_IS_APPROX
(
w
[
i
],
v
[
i
]);
71
}
72
73
v
.resize(21);
74
v
[20] =
x
;
75
VERIFY_IS_APPROX
(
v
[20],
x
);
76
v
.fill(
y
,22);
77
VERIFY_IS_APPROX
(
v
[21],
y
);
78
v
.push_back(
x
);
79
VERIFY_IS_APPROX
(
v
[22],
x
);
80
VERIFY
((
size_t
)&(
v
[22]) == (
size_t
)&(
v
[21]) +
sizeof
(TransformType));
81
82
// do a lot of push_back such that the vector gets internally resized
83
// (with memory reallocation)
84
TransformType*
ref
= &
w
[0];
85
for
(
int
i
=0;
i
<30 || ((
ref
==&
w
[0]) &&
i
<300); ++
i
)
86
v
.push_back(
w
[
i
%
w
.size()]);
87
for
(
unsigned
int
i
=23;
int
(
i
)<
v
.size(); ++
i
)
88
{
89
VERIFY
(
v
[
i
].
matrix
()==
w
[(
i
-23)%
w
.size()].matrix());
90
}
91
}
92
93
template
<
typename
QuaternionType>
94
void
check_qtvector_quaternion
(
const
QuaternionType&)
95
{
96
typedef
typename
QuaternionType::Coefficients Coefficients;
97
QuaternionType
x
(Coefficients::Random()),
y
(Coefficients::Random());
98
QVector<QuaternionType>
v
(10),
w
(20,
y
);
99
v
[5] =
x
;
100
w
[6] =
v
[5];
101
VERIFY_IS_APPROX
(
w
[6],
v
[5]);
102
v
=
w
;
103
for
(
int
i
= 0;
i
< 20;
i
++)
104
{
105
VERIFY_IS_APPROX
(
w
[
i
],
v
[
i
]);
106
}
107
108
v
.resize(21);
109
v
[20] =
x
;
110
VERIFY_IS_APPROX
(
v
[20],
x
);
111
v
.fill(
y
,22);
112
VERIFY_IS_APPROX
(
v
[21],
y
);
113
v
.push_back(
x
);
114
VERIFY_IS_APPROX
(
v
[22],
x
);
115
VERIFY
((
size_t
)&(
v
[22]) == (
size_t
)&(
v
[21]) +
sizeof
(QuaternionType));
116
117
// do a lot of push_back such that the vector gets internally resized
118
// (with memory reallocation)
119
QuaternionType*
ref
= &
w
[0];
120
for
(
int
i
=0;
i
<30 || ((
ref
==&
w
[0]) &&
i
<300); ++
i
)
121
v
.push_back(
w
[
i
%
w
.size()]);
122
for
(
unsigned
int
i
=23;
int
(
i
)<
v
.size(); ++
i
)
123
{
124
VERIFY
(
v
[
i
].coeffs()==
w
[(
i
-23)%
w
.size()].coeffs());
125
}
126
}
127
128
EIGEN_DECLARE_TEST
(qtvector)
129
{
130
// some non vectorizable fixed sizes
131
CALL_SUBTEST
(
check_qtvector_matrix
(Vector2f()));
132
CALL_SUBTEST
(
check_qtvector_matrix
(Matrix3f()));
133
CALL_SUBTEST
(
check_qtvector_matrix
(Matrix3d()));
134
135
// some vectorizable fixed sizes
136
CALL_SUBTEST
(
check_qtvector_matrix
(Matrix2f()));
137
CALL_SUBTEST
(
check_qtvector_matrix
(Vector4f()));
138
CALL_SUBTEST
(
check_qtvector_matrix
(Matrix4f()));
139
CALL_SUBTEST
(
check_qtvector_matrix
(Matrix4d()));
140
141
// some dynamic sizes
142
CALL_SUBTEST
(
check_qtvector_matrix
(MatrixXd(1,1)));
143
CALL_SUBTEST
(
check_qtvector_matrix
(VectorXd(20)));
144
CALL_SUBTEST
(
check_qtvector_matrix
(RowVectorXf(20)));
145
CALL_SUBTEST
(
check_qtvector_matrix
(MatrixXcf(10,10)));
146
147
// some Transform
148
CALL_SUBTEST
(
check_qtvector_transform
(
Affine2f
()));
149
CALL_SUBTEST
(
check_qtvector_transform
(
Affine3f
()));
150
CALL_SUBTEST
(
check_qtvector_transform
(
Affine3d
()));
151
//CALL_SUBTEST(check_qtvector_transform(Transform4d()));
152
153
// some Quaternion
154
CALL_SUBTEST
(
check_qtvector_quaternion
(
Quaternionf
()));
155
CALL_SUBTEST
(
check_qtvector_quaternion
(
Quaternionf
()));
156
}
w
RowVector3d w
Definition:
Matrix_resize_int.cpp:3
gtsam.examples.DogLegOptimizerExample.int
int
Definition:
DogLegOptimizerExample.py:111
check_qtvector_matrix
void check_qtvector_matrix(const MatrixType &m)
Definition:
qtvector.cpp:19
Eigen::Affine2f
Transform< float, 2, Affine > Affine2f
Definition:
Transform.h:704
MatrixType
MatrixXf MatrixType
Definition:
benchmark-blocking-sizes.cpp:52
check_qtvector_quaternion
void check_qtvector_quaternion(const QuaternionType &)
Definition:
qtvector.cpp:94
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
rows
int rows
Definition:
Tutorial_commainit_02.cpp:1
Eigen::Affine3f
Transform< float, 3, Affine > Affine3f
Definition:
Transform.h:706
Eigen::Quaternionf
Quaternion< float > Quaternionf
Definition:
3rdparty/Eigen/Eigen/src/Geometry/Quaternion.h:363
m
Matrix3f m
Definition:
AngleAxis_mimic_euler.cpp:1
check_qtvector_transform
void check_qtvector_transform(const TransformType &)
Definition:
qtvector.cpp:59
y
Scalar * y
Definition:
level1_cplx_impl.h:124
matrix
Map< Matrix< T, Dynamic, Dynamic, ColMajor >, 0, OuterStride<> > matrix(T *data, int rows, int cols, int stride)
Definition:
gtsam/3rdparty/Eigen/blas/common.h:110
VERIFY_IS_APPROX
#define VERIFY_IS_APPROX(a, b)
Definition:
integer_types.cpp:15
EIGEN_DECLARE_TEST
EIGEN_DECLARE_TEST(qtvector)
Definition:
qtvector.cpp:128
main.h
ref
Reference counting helper.
Definition:
object.h:67
v
Array< int, Dynamic, 1 > v
Definition:
Array_initializer_list_vector_cxx11.cpp:1
cols
int cols
Definition:
Tutorial_commainit_02.cpp:1
Eigen::Affine3d
Transform< double, 3, Affine > Affine3d
Definition:
Transform.h:710
i
int i
Definition:
BiCGSTAB_step_by_step.cpp:9
CALL_SUBTEST
#define CALL_SUBTEST(FUNC)
Definition:
main.h:399
VERIFY
#define VERIFY(a)
Definition:
main.h:380
Eigen::Index
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition:
Meta.h:74
gtsam
Author(s):
autogenerated on Sun Dec 22 2024 04:13:02