Main MRPT website
>
C++ reference for MRPT 1.9.9
test.cpp
Go to the documentation of this file.
1
/* +------------------------------------------------------------------------+
2
| Mobile Robot Programming Toolkit (MRPT) |
3
| http://www.mrpt.org/ |
4
| |
5
| Copyright (c) 2005-2018, Individual contributors, see AUTHORS file |
6
| See: http://www.mrpt.org/Authors - All rights reserved. |
7
| Released under BSD License. See details in http://www.mrpt.org/License |
8
+------------------------------------------------------------------------+ */
9
10
#include <
mrpt/math/CSparseMatrix.h
>
11
#include <
mrpt/random/RandomGenerators.h
>
12
#include <iostream>
13
14
using namespace
mrpt
;
15
using namespace
mrpt::math
;
16
using namespace
std;
17
18
void
ExampleCSparse
()
19
{
20
// Initialize a 10x10 sparse matrix:
21
CSparseMatrix
SM(10, 10);
22
23
// With 2 dense blocks of 6x6 and 4x4:
24
const
auto
COV1 =
mrpt::random::getRandomGenerator
()
25
.
drawDefinitePositiveMatrix
<
CMatrixDouble
>(6, 0.2);
26
const
auto
COV2 =
mrpt::random::getRandomGenerator
()
27
.
drawDefinitePositiveMatrix
<
CMatrixDouble
>(4, 0.2);
28
SM.insert_submatrix(0, 0, COV1);
29
SM.insert_submatrix(6, 6, COV2);
30
31
// Get as a dense matrix just for displaying to console:
32
CMatrixDouble
M;
33
SM.get_dense(M);
34
cout <<
"M (as dense):\n"
<< M;
35
36
cout <<
"Saving to sparse_demo1.txt...\n"
;
37
SM.saveToTextFile_sparse(
"sparse_demo1.txt"
);
38
39
// Compress from the triplet to the column-compressed form:
40
cout <<
"Compressing as CCS...\n"
;
41
SM.compressFromTriplet();
42
43
cout <<
"Saving to sparse_demo2.txt...\n"
;
44
SM.saveToTextFile_sparse(
"sparse_demo2.txt"
);
45
46
// Compute the Cholesky decomposition:
47
CSparseMatrix::CholeskyDecomp
Chol(SM);
48
49
// And display the L factor:
50
const
CMatrixDouble
L = Chol.get_L();
51
cout <<
"L:\n"
<< L << endl;
52
}
53
54
int
main
(
int
argc,
char
** argv)
55
{
56
try
57
{
58
ExampleCSparse
();
59
return
0;
60
}
61
catch
(exception& e)
62
{
63
cout <<
"MRPT exception caught: "
<< e.what() << endl;
64
return
-1;
65
}
66
catch
(...)
67
{
68
printf(
"Another exception!!"
);
69
return
-1;
70
}
71
}
mrpt
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Definition:
CKalmanFilterCapable.h:30
mrpt::random::CRandomGenerator::drawDefinitePositiveMatrix
MATRIX drawDefinitePositiveMatrix(const size_t dim, const double std_scale=1.0, const double diagonal_epsilon=1e-8)
Generates a random definite-positive matrix of the given size, using the formula C = v*v^t + epsilon*...
Definition:
RandomGenerators.h:188
mrpt::math::CMatrixTemplateNumeric< double >
main
int main()
Definition:
vision_stereo_rectify/test.cpp:78
ExampleCSparse
void ExampleCSparse()
Definition:
vision_stereo_rectify/test.cpp:18
CSparseMatrix.h
RandomGenerators.h
mrpt::random::getRandomGenerator
CRandomGenerator & getRandomGenerator()
A static instance of a CRandomGenerator class, for use in single-thread applications.
Definition:
RandomGenerator.cpp:19
mrpt::math
This base provides a set of functions for maths stuff.
Definition:
math/include/mrpt/math/bits_math.h:13
mrpt::math::CSparseMatrix::CholeskyDecomp
Auxiliary class to hold the results of a Cholesky factorization of a sparse matrix.
Definition:
CSparseMatrix.h:440
mrpt::math::CSparseMatrix
A sparse matrix structure, wrapping T.
Definition:
CSparseMatrix.h:97
Page generated by
Doxygen 1.8.17
for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at miƩ 12 jul 2023 10:03:34 CEST