gtsam
3rdparty
Eigen
test
incomplete_cholesky.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) 2015-2016 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
// #define EIGEN_DONT_VECTORIZE
10
// #define EIGEN_MAX_ALIGN_BYTES 0
11
#include "
sparse_solver.h
"
12
#include <Eigen/IterativeLinearSolvers>
13
#include <unsupported/Eigen/IterativeSolvers>
14
15
template
<
typename
T,
typename
I_>
void
test_incomplete_cholesky_T
()
16
{
17
typedef
SparseMatrix<T,0,I_>
SparseMatrixType;
18
ConjugateGradient<SparseMatrixType, Lower, IncompleteCholesky<T, Lower, AMDOrdering<I_>
> > cg_illt_lower_amd;
19
ConjugateGradient<SparseMatrixType, Lower, IncompleteCholesky<T, Lower, NaturalOrdering<I_>
> > cg_illt_lower_nat;
20
ConjugateGradient<SparseMatrixType, Upper, IncompleteCholesky<T, Upper, AMDOrdering<I_>
> > cg_illt_upper_amd;
21
ConjugateGradient<SparseMatrixType, Upper, IncompleteCholesky<T, Upper, NaturalOrdering<I_>
> > cg_illt_upper_nat;
22
ConjugateGradient<SparseMatrixType, Upper|Lower, IncompleteCholesky<T, Lower, AMDOrdering<I_>
> > cg_illt_uplo_amd;
23
24
25
CALL_SUBTEST
(
check_sparse_spd_solving
(cg_illt_lower_amd) );
26
CALL_SUBTEST
(
check_sparse_spd_solving
(cg_illt_lower_nat) );
27
CALL_SUBTEST
(
check_sparse_spd_solving
(cg_illt_upper_amd) );
28
CALL_SUBTEST
(
check_sparse_spd_solving
(cg_illt_upper_nat) );
29
CALL_SUBTEST
(
check_sparse_spd_solving
(cg_illt_uplo_amd) );
30
}
31
32
template
<
int
>
33
void
bug1150
()
34
{
35
// regression for bug 1150
36
for
(
int
N
= 1;
N
<20; ++
N
)
37
{
38
Eigen::MatrixXd
b
(
N
,
N
);
39
b
.setOnes();
40
41
Eigen::SparseMatrix<double>
m
(
N
,
N
);
42
m
.reserve(Eigen::VectorXi::Constant(
N
,4));
43
for
(
int
i
= 0;
i
<
N
; ++
i
)
44
{
45
m
.insert(
i
,
i
) = 1;
46
m
.coeffRef(
i
,
i
/ 2 ) = 2;
47
m
.coeffRef(
i
,
i
/ 3 ) = 2;
48
m
.coeffRef(
i
,
i
/ 4 ) = 2;
49
}
50
51
Eigen::SparseMatrix<double>
A
;
52
A
=
m
*
m
.transpose();
53
54
Eigen::ConjugateGradient<Eigen::SparseMatrix<double>
,
55
Eigen::Lower
|
Eigen::Upper
,
56
Eigen::IncompleteCholesky<double>
>
solver
(
A
);
57
VERIFY
(
solver
.preconditioner().info() ==
Eigen::Success
);
58
VERIFY
(
solver
.info() ==
Eigen::Success
);
59
}
60
}
61
62
EIGEN_DECLARE_TEST
(incomplete_cholesky)
63
{
64
CALL_SUBTEST_1
(( test_incomplete_cholesky_T<double,int>() ));
65
CALL_SUBTEST_2
((
test_incomplete_cholesky_T
<std::complex<double>,
int
>() ));
66
CALL_SUBTEST_3
(( test_incomplete_cholesky_T<double,long int>() ));
67
68
CALL_SUBTEST_1
(( bug1150<0>() ));
69
}
test_incomplete_cholesky_T
void test_incomplete_cholesky_T()
Definition:
incomplete_cholesky.cpp:15
bug1150
void bug1150()
Definition:
incomplete_cholesky.cpp:33
Eigen::SparseMatrix
A versatible sparse matrix representation.
Definition:
SparseMatrix.h:96
b
Scalar * b
Definition:
benchVecAdd.cpp:17
Eigen::Upper
@ Upper
Definition:
Constants.h:211
Eigen::Success
@ Success
Definition:
Constants.h:442
Eigen::IncompleteCholesky
Modified Incomplete Cholesky with dual threshold.
Definition:
IncompleteCholesky.h:45
solver
BiCGSTAB< SparseMatrix< double > > solver
Definition:
BiCGSTAB_simple.cpp:5
A
Matrix< SCALARA, Dynamic, Dynamic, opt_A > A
Definition:
bench_gemm.cpp:48
EIGEN_DECLARE_TEST
EIGEN_DECLARE_TEST(incomplete_cholesky)
Definition:
incomplete_cholesky.cpp:62
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::ConjugateGradient
A conjugate gradient solver for sparse (or dense) self-adjoint problems.
Definition:
ConjugateGradient.h:97
m
Matrix3f m
Definition:
AngleAxis_mimic_euler.cpp:1
Eigen::Lower
@ Lower
Definition:
Constants.h:209
CALL_SUBTEST_2
#define CALL_SUBTEST_2(FUNC)
Definition:
split_test_helper.h:10
check_sparse_spd_solving
void check_sparse_spd_solving(Solver &solver, int maxSize=(std::min)(300, EIGEN_TEST_MAX_SIZE), int maxRealWorldSize=100000)
Definition:
sparse_solver.h:404
sparse_solver.h
N
#define N
Definition:
igam.h:9
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
gtsam
Author(s):
autogenerated on Sat Nov 16 2024 04:02:27