gtsam
3rdparty
Eigen
test
bandmatrix.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) 2008-2009 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
#include "
main.h
"
11
12
template
<
typename
MatrixType>
void
bandmatrix
(
const
MatrixType
& _m)
13
{
14
typedef
typename
MatrixType::Scalar
Scalar
;
15
typedef
typename
NumTraits<Scalar>::Real
RealScalar
;
16
typedef
Matrix<Scalar,Dynamic,Dynamic>
DenseMatrixType;
17
18
Index
rows
= _m.rows();
19
Index
cols
= _m.cols();
20
Index
supers = _m.supers();
21
Index
subs = _m.subs();
22
23
MatrixType
m
(
rows
,
cols
,supers,subs);
24
25
DenseMatrixType dm1(
rows
,
cols
);
26
dm1.setZero();
27
28
m
.diagonal().setConstant(123);
29
dm1.diagonal().setConstant(123);
30
for
(
int
i
=1;
i
<=
m
.supers();++
i
)
31
{
32
m
.diagonal(
i
).setConstant(
static_cast<
RealScalar
>
(
i
));
33
dm1.diagonal(
i
).setConstant(
static_cast<
RealScalar
>
(
i
));
34
}
35
for
(
int
i
=1;
i
<=
m
.subs();++
i
)
36
{
37
m
.diagonal(-
i
).setConstant(-
static_cast<
RealScalar
>
(
i
));
38
dm1.diagonal(-
i
).setConstant(-
static_cast<
RealScalar
>
(
i
));
39
}
40
//std::cerr << m.m_data << "\n\n" << m.toDense() << "\n\n" << dm1 << "\n\n\n\n";
41
VERIFY_IS_APPROX
(dm1,
m
.toDenseMatrix());
42
43
for
(
int
i
=0;
i
<
cols
; ++
i
)
44
{
45
m
.col(
i
).setConstant(
static_cast<
RealScalar
>
(
i
+1));
46
dm1.col(
i
).setConstant(
static_cast<
RealScalar
>
(
i
+1));
47
}
48
Index
d
= (
std::min
)(
rows
,
cols
);
49
Index
a
= std::max<Index>(0,
cols
-
d
-supers);
50
Index
b
= std::max<Index>(0,
rows
-
d
-subs);
51
if
(
a
>0) dm1.block(0,
d
+supers,
rows
,
a
).setZero();
52
dm1.block(0,supers+1,
cols
-supers-1-
a
,
cols
-supers-1-
a
).template triangularView<Upper>().setZero();
53
dm1.block(subs+1,0,
rows
-subs-1-
b
,
rows
-subs-1-
b
).template
triangularView<Lower>
().setZero();
54
if
(
b
>0) dm1.block(
d
+subs,0,
b
,
cols
).setZero();
55
//std::cerr << m.m_data << "\n\n" << m.toDense() << "\n\n" << dm1 << "\n\n";
56
VERIFY_IS_APPROX
(dm1,
m
.toDenseMatrix());
57
58
}
59
60
using
Eigen::internal::BandMatrix
;
61
62
EIGEN_DECLARE_TEST
(
bandmatrix
)
63
{
64
for
(
int
i
= 0;
i
< 10*
g_repeat
;
i
++) {
65
Index
rows
= internal::random<Index>(1,10);
66
Index
cols
= internal::random<Index>(1,10);
67
Index
sups = internal::random<Index>(0,
cols
-1);
68
Index
subs = internal::random<Index>(0,
rows
-1);
69
CALL_SUBTEST
(
bandmatrix
(
BandMatrix<float>
(
rows
,
cols
,sups,subs)) );
70
}
71
}
Eigen::internal::BandMatrix
Represents a rectangular matrix with a banded storage.
Definition:
BandMatrix.h:199
d
static const double d[K][N]
Definition:
igam.h:11
MatrixType
MatrixXf MatrixType
Definition:
benchmark-blocking-sizes.cpp:52
b
Scalar * b
Definition:
benchVecAdd.cpp:17
EIGEN_DECLARE_TEST
EIGEN_DECLARE_TEST(bandmatrix)
Definition:
bandmatrix.cpp:62
rows
int rows
Definition:
Tutorial_commainit_02.cpp:1
bandmatrix
void bandmatrix(const MatrixType &_m)
Definition:
bandmatrix.cpp:12
Eigen::g_repeat
static int g_repeat
Definition:
main.h:169
m
Matrix3f m
Definition:
AngleAxis_mimic_euler.cpp:1
VERIFY_IS_APPROX
#define VERIFY_IS_APPROX(a, b)
Definition:
integer_types.cpp:15
RealScalar
NumTraits< Scalar >::Real RealScalar
Definition:
bench_gemm.cpp:47
a
ArrayXXi a
Definition:
Array_initializer_list_23_cxx11.cpp:1
main.h
min
#define min(a, b)
Definition:
datatypes.h:19
Eigen::Matrix< Scalar, Dynamic, Dynamic >
cols
int cols
Definition:
Tutorial_commainit_02.cpp:1
triangularView< Lower >
A triangularView< Lower >().adjoint().solveInPlace(B)
Eigen::NumTraits
Holds information about the various numeric (i.e. scalar) types allowed by Eigen.
Definition:
NumTraits.h:232
i
int i
Definition:
BiCGSTAB_step_by_step.cpp:9
Scalar
SCALAR Scalar
Definition:
bench_gemm.cpp:46
CALL_SUBTEST
#define CALL_SUBTEST(FUNC)
Definition:
main.h:399
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 Fri Nov 1 2024 03:31:58