gtsam
3rdparty
Eigen
test
real_qz.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) 2012 Alexey Korepanov <kaikaikai@yandex.ru>
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 EIGEN_RUNTIME_NO_MALLOC
11
#include "
main.h
"
12
#include <limits>
13
#include <Eigen/Eigenvalues>
14
15
template
<
typename
MatrixType>
void
real_qz
(
const
MatrixType
&
m
)
16
{
17
/* this test covers the following files:
18
RealQZ.h
19
*/
20
using
std::abs
;
21
typedef
typename
MatrixType::Scalar
Scalar
;
22
23
Index
dim =
m
.cols();
24
25
MatrixType
A
= MatrixType::Random(dim,dim),
26
B
= MatrixType::Random(dim,dim);
27
28
29
// Regression test for bug 985: Randomly set rows or columns to zero
30
Index
k=internal::random<Index>(0, dim-1);
31
switch
(internal::random<int>(0,10)) {
32
case
0:
33
A
.row(k).setZero();
break
;
34
case
1:
35
A
.col(k).setZero();
break
;
36
case
2:
37
B
.row(k).setZero();
break
;
38
case
3:
39
B
.col(k).setZero();
break
;
40
default
:
41
break
;
42
}
43
44
RealQZ<MatrixType>
qz
(dim);
45
// TODO enable full-prealocation of required memory, this probably requires an in-place mode for HessenbergDecomposition
46
//Eigen::internal::set_is_malloc_allowed(false);
47
qz
.compute(
A
,
B
);
48
//Eigen::internal::set_is_malloc_allowed(true);
49
50
VERIFY_IS_EQUAL
(
qz
.info(),
Success
);
51
// check for zeros
52
bool
all_zeros =
true
;
53
for
(
Index
i
=0;
i
<
A
.cols();
i
++)
54
for
(
Index
j
=0;
j
<
i
;
j
++) {
55
if
(
abs
(
qz
.matrixT()(
i
,
j
))!=
Scalar
(0.0))
56
{
57
std::cerr <<
"Error: T("
<<
i
<<
","
<<
j
<<
") = "
<<
qz
.matrixT()(
i
,
j
) << std::endl;
58
all_zeros =
false
;
59
}
60
if
(
j
<
i
-1 &&
abs
(
qz
.matrixS()(
i
,
j
))!=
Scalar
(0.0))
61
{
62
std::cerr <<
"Error: S("
<<
i
<<
","
<<
j
<<
") = "
<<
qz
.matrixS()(
i
,
j
) << std::endl;
63
all_zeros =
false
;
64
}
65
if
(
j
==
i
-1 &&
j
>0 &&
abs
(
qz
.matrixS()(
i
,
j
))!=
Scalar
(0.0) &&
abs
(
qz
.matrixS()(
i
-1,
j
-1))!=
Scalar
(0.0))
66
{
67
std::cerr <<
"Error: S("
<<
i
<<
","
<<
j
<<
") = "
<<
qz
.matrixS()(
i
,
j
) <<
" && S("
<<
i
-1 <<
","
<<
j
-1 <<
") = "
<<
qz
.matrixS()(
i
-1,
j
-1) << std::endl;
68
all_zeros =
false
;
69
}
70
}
71
VERIFY_IS_EQUAL
(all_zeros,
true
);
72
VERIFY_IS_APPROX
(
qz
.matrixQ()*
qz
.matrixS()*
qz
.matrixZ(),
A
);
73
VERIFY_IS_APPROX
(
qz
.matrixQ()*
qz
.matrixT()*
qz
.matrixZ(),
B
);
74
VERIFY_IS_APPROX
(
qz
.matrixQ()*
qz
.matrixQ().adjoint(), MatrixType::Identity(dim,dim));
75
VERIFY_IS_APPROX
(
qz
.matrixZ()*
qz
.matrixZ().adjoint(), MatrixType::Identity(dim,dim));
76
}
77
78
EIGEN_DECLARE_TEST
(
real_qz
)
79
{
80
int
s
= 0;
81
for
(
int
i
= 0;
i
<
g_repeat
;
i
++) {
82
CALL_SUBTEST_1
(
real_qz
(Matrix4f()) );
83
s
= internal::random<int>(1,
EIGEN_TEST_MAX_SIZE
/4);
84
CALL_SUBTEST_2
(
real_qz
(MatrixXd(
s
,
s
)) );
85
86
// some trivial but implementation-wise tricky cases
87
CALL_SUBTEST_2
(
real_qz
(MatrixXd(1,1)) );
88
CALL_SUBTEST_2
(
real_qz
(MatrixXd(2,2)) );
89
CALL_SUBTEST_3
(
real_qz
(
Matrix<double,1,1>
()) );
90
CALL_SUBTEST_4
(
real_qz
(Matrix2d()) );
91
}
92
93
TEST_SET_BUT_UNUSED_VARIABLE
(
s
)
94
}
B
Matrix< SCALARB, Dynamic, Dynamic, opt_B > B
Definition:
bench_gemm.cpp:49
s
RealScalar s
Definition:
level1_cplx_impl.h:126
MatrixType
MatrixXf MatrixType
Definition:
benchmark-blocking-sizes.cpp:52
Eigen::RealQZ< MatrixType >
VERIFY_IS_EQUAL
#define VERIFY_IS_EQUAL(a, b)
Definition:
main.h:386
Eigen::Success
@ Success
Definition:
Constants.h:442
A
Matrix< SCALARA, Dynamic, Dynamic, opt_A > A
Definition:
bench_gemm.cpp:48
CALL_SUBTEST_4
#define CALL_SUBTEST_4(FUNC)
Definition:
split_test_helper.h:22
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
j
std::ptrdiff_t j
Definition:
tut_arithmetic_redux_minmax.cpp:2
Eigen::g_repeat
static int g_repeat
Definition:
main.h:169
m
Matrix3f m
Definition:
AngleAxis_mimic_euler.cpp:1
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
qz
RealQZ< MatrixXf > qz(4)
main.h
EIGEN_TEST_MAX_SIZE
#define EIGEN_TEST_MAX_SIZE
Definition:
boostmultiprec.cpp:16
EIGEN_DECLARE_TEST
EIGEN_DECLARE_TEST(real_qz)
Definition:
real_qz.cpp:78
Eigen::Matrix
The matrix class, also used for vectors and row-vectors.
Definition:
3rdparty/Eigen/Eigen/src/Core/Matrix.h:178
abs
#define abs(x)
Definition:
datatypes.h:17
i
int i
Definition:
BiCGSTAB_step_by_step.cpp:9
real_qz
void real_qz(const MatrixType &m)
Definition:
real_qz.cpp:15
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 Sun Dec 22 2024 04:13:03