gtsam
3rdparty
Eigen
test
selfadjoint.cpp
Go to the documentation of this file.
1
// This file is triangularView of Eigen, a lightweight C++ template library
2
// for linear algebra.
3
//
4
// Copyright (C) 2010 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
#define TEST_CHECK_STATIC_ASSERTIONS
11
#include "
main.h
"
12
13
// This file tests the basic selfadjointView API,
14
// the related products and decompositions are tested in specific files.
15
16
template
<
typename
MatrixType>
void
selfadjoint
(
const
MatrixType
&
m
)
17
{
18
typedef
typename
MatrixType::Scalar
Scalar
;
19
20
Index
rows
=
m
.rows();
21
Index
cols
=
m
.cols();
22
23
MatrixType
m1
= MatrixType::Random(
rows
,
cols
),
24
m2
= MatrixType::Random(
rows
,
cols
),
25
m3
(
rows
,
cols
),
26
m4(
rows
,
cols
);
27
28
m1
.diagonal() =
m1
.diagonal().real().template cast<Scalar>();
29
30
// check selfadjoint to dense
31
m3
=
m1
.template selfadjointView<Upper>();
32
VERIFY_IS_APPROX
(
MatrixType
(
m3
.template triangularView<Upper>()),
MatrixType
(
m1
.template triangularView<Upper>()));
33
VERIFY_IS_APPROX
(
m3
,
m3
.adjoint());
34
35
m3
=
m1
.template selfadjointView<Lower>();
36
VERIFY_IS_APPROX
(
MatrixType
(
m3
.template
triangularView<Lower>
()),
MatrixType
(
m1
.template
triangularView<Lower>
()));
37
VERIFY_IS_APPROX
(
m3
,
m3
.adjoint());
38
39
m3
=
m1
.template selfadjointView<Upper>();
40
m4 =
m2
;
41
m4 +=
m1
.template selfadjointView<Upper>();
42
VERIFY_IS_APPROX
(m4,
m2
+
m3
);
43
44
m3
=
m1
.template selfadjointView<Lower>();
45
m4 =
m2
;
46
m4 -=
m1
.template selfadjointView<Lower>();
47
VERIFY_IS_APPROX
(m4,
m2
-
m3
);
48
49
VERIFY_RAISES_STATIC_ASSERT
(
m2
.template selfadjointView<StrictlyUpper>());
50
VERIFY_RAISES_STATIC_ASSERT
(
m2
.template selfadjointView<UnitLower>());
51
}
52
53
void
bug_159
()
54
{
55
Matrix3d
m
= Matrix3d::Random().selfadjointView<
Lower
>();
56
EIGEN_UNUSED_VARIABLE
(
m
)
57
}
58
59
EIGEN_DECLARE_TEST
(
selfadjoint
)
60
{
61
for
(
int
i
= 0;
i
<
g_repeat
;
i
++)
62
{
63
int
s
= internal::random<int>(1,
EIGEN_TEST_MAX_SIZE
);
64
65
CALL_SUBTEST_1
(
selfadjoint
(
Matrix<float, 1, 1>
()) );
66
CALL_SUBTEST_2
(
selfadjoint
(
Matrix<float, 2, 2>
()) );
67
CALL_SUBTEST_3
(
selfadjoint
(Matrix3cf()) );
68
CALL_SUBTEST_4
(
selfadjoint
(MatrixXcd(
s
,
s
)) );
69
CALL_SUBTEST_5
(
selfadjoint
(
Matrix<float,Dynamic,Dynamic,RowMajor>
(
s
,
s
)) );
70
71
TEST_SET_BUT_UNUSED_VARIABLE
(
s
)
72
}
73
74
CALL_SUBTEST_1
(
bug_159
() );
75
}
bug_159
void bug_159()
Definition:
selfadjoint.cpp:53
s
RealScalar s
Definition:
level1_cplx_impl.h:126
MatrixType
MatrixXf MatrixType
Definition:
benchmark-blocking-sizes.cpp:52
selfadjoint
void selfadjoint(const MatrixType &m)
Definition:
selfadjoint.cpp:16
m1
Matrix3d m1
Definition:
IOFormat.cpp:2
rows
int rows
Definition:
Tutorial_commainit_02.cpp:1
CALL_SUBTEST_4
#define CALL_SUBTEST_4(FUNC)
Definition:
split_test_helper.h:22
m2
MatrixType m2(n_dims)
CALL_SUBTEST_3
#define CALL_SUBTEST_3(FUNC)
Definition:
split_test_helper.h:16
CALL_SUBTEST_1
#define CALL_SUBTEST_1(FUNC)
Definition:
split_test_helper.h:4
EIGEN_UNUSED_VARIABLE
#define EIGEN_UNUSED_VARIABLE(var)
Definition:
Macros.h:1076
EIGEN_DECLARE_TEST
EIGEN_DECLARE_TEST(selfadjoint)
Definition:
selfadjoint.cpp:59
CALL_SUBTEST_5
#define CALL_SUBTEST_5(FUNC)
Definition:
split_test_helper.h:28
Eigen::g_repeat
static int g_repeat
Definition:
main.h:169
m
Matrix3f m
Definition:
AngleAxis_mimic_euler.cpp:1
VERIFY_RAISES_STATIC_ASSERT
#define VERIFY_RAISES_STATIC_ASSERT(a)
Definition:
main.h:344
Eigen::Lower
@ Lower
Definition:
Constants.h:209
CALL_SUBTEST_2
#define CALL_SUBTEST_2(FUNC)
Definition:
split_test_helper.h:10
VERIFY_IS_APPROX
#define VERIFY_IS_APPROX(a, b)
Definition:
integer_types.cpp:15
m3
static const DiscreteKey m3(M(3), 2)
main.h
EIGEN_TEST_MAX_SIZE
#define EIGEN_TEST_MAX_SIZE
Definition:
boostmultiprec.cpp:16
Eigen::Matrix
The matrix class, also used for vectors and row-vectors.
Definition:
3rdparty/Eigen/Eigen/src/Core/Matrix.h:178
cols
int cols
Definition:
Tutorial_commainit_02.cpp:1
triangularView< Lower >
A triangularView< Lower >().adjoint().solveInPlace(B)
i
int i
Definition:
BiCGSTAB_step_by_step.cpp:9
TEST_SET_BUT_UNUSED_VARIABLE
#define TEST_SET_BUT_UNUSED_VARIABLE(X)
Definition:
main.h:121
Scalar
SCALAR Scalar
Definition:
bench_gemm.cpp:46
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 Sat Nov 16 2024 04:04:03