g2o
Toggle main menu visibility
Loading...
Searching...
No Matches
g2o
core
sparse_block_matrix_diagonal.h
Go to the documentation of this file.
1
// g2o - General Graph Optimization
2
// Copyright (C) 2011 R. Kuemmerle, G. Grisetti, W. Burgard
3
// All rights reserved.
4
//
5
// Redistribution and use in source and binary forms, with or without
6
// modification, are permitted provided that the following conditions are
7
// met:
8
//
9
// * Redistributions of source code must retain the above copyright notice,
10
// this list of conditions and the following disclaimer.
11
// * Redistributions in binary form must reproduce the above copyright
12
// notice, this list of conditions and the following disclaimer in the
13
// documentation and/or other materials provided with the distribution.
14
//
15
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
16
// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17
// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
18
// PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19
// HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
21
// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
22
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
23
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
24
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
27
#ifndef G2O_SPARSE_BLOCK_MATRIX_DIAGONAL_H
28
#define G2O_SPARSE_BLOCK_MATRIX_DIAGONAL_H
29
30
#include <Eigen/Core>
31
#include <vector>
32
33
#include "g2o/config.h"
34
#include "
matrix_operations.h
"
35
36
namespace
g2o
{
37
45
template
<
class
MatrixType>
46
class
SparseBlockMatrixDiagonal
{
47
public
:
49
typedef
MatrixType
SparseMatrixBlock
;
50
52
int
cols
()
const
{
return
_blockIndices
.size() ?
_blockIndices
.back() : 0; }
54
int
rows
()
const
{
return
_blockIndices
.size() ?
_blockIndices
.back() : 0; }
55
56
using
DiagonalVector
= std::vector<MatrixType>;
57
58
SparseBlockMatrixDiagonal
(
const
std::vector<int>&
blockIndices
)
59
:
_blockIndices
(
blockIndices
) {}
60
62
inline
int
dimOfBlock
(
int
r)
const
{
63
return
r ?
_blockIndices
[r] -
_blockIndices
[r - 1] :
_blockIndices
[0];
64
}
65
67
inline
int
baseOfBlock
(
int
r)
const
{
return
r ?
_blockIndices
[r - 1] : 0; }
68
70
const
DiagonalVector
&
diagonal
()
const
{
return
_diagonal
; }
71
DiagonalVector
&
diagonal
() {
return
_diagonal
; }
72
74
const
std::vector<int>&
blockIndices
()
const
{
return
_blockIndices
; }
75
76
void
multiply
(
double
*& dest,
const
double
* src)
const
{
77
int
destSize =
cols
();
78
if
(!dest) {
79
dest =
new
double
[destSize];
80
memset(dest, 0, destSize *
sizeof
(
double
));
81
}
82
83
// map the memory by Eigen
84
Eigen::Map<VectorX> destVec(dest, destSize);
85
Eigen::Map<const VectorX> srcVec(src,
rows
());
86
87
#ifdef G2O_OPENMP
88
#pragma omp parallel for default(shared) schedule(dynamic, 10)
89
#endif
90
for
(
int
i = 0; i < static_cast<int>(
_diagonal
.size()); ++i) {
91
int
destOffset =
baseOfBlock
(i);
92
int
srcOffset = destOffset;
93
const
SparseMatrixBlock
& A =
_diagonal
[i];
94
// destVec += *A.transpose() * srcVec (according to the sub-vector parts)
95
internal::template axpy<SparseMatrixBlock>(A, srcVec, srcOffset, destVec,
96
destOffset);
97
}
98
}
99
100
protected
:
101
const
std::vector<int>&
_blockIndices
;
103
DiagonalVector
_diagonal
;
104
};
105
106
}
// namespace g2o
107
108
#endif
g2o::SparseBlockMatrixDiagonal::dimOfBlock
int dimOfBlock(int r) const
how many rows/cols does the block at block-row / block-column r has?
Definition
sparse_block_matrix_diagonal.h:62
g2o::SparseBlockMatrixDiagonal::_diagonal
DiagonalVector _diagonal
Definition
sparse_block_matrix_diagonal.h:103
g2o::SparseBlockMatrixDiagonal::SparseBlockMatrixDiagonal
SparseBlockMatrixDiagonal(const std::vector< int > &blockIndices)
Definition
sparse_block_matrix_diagonal.h:58
g2o::SparseBlockMatrixDiagonal::_blockIndices
const std::vector< int > & _blockIndices
Definition
sparse_block_matrix_diagonal.h:101
g2o::SparseBlockMatrixDiagonal::diagonal
DiagonalVector & diagonal()
Definition
sparse_block_matrix_diagonal.h:71
g2o::SparseBlockMatrixDiagonal::baseOfBlock
int baseOfBlock(int r) const
where does the row /col at block-row / block-column r starts?
Definition
sparse_block_matrix_diagonal.h:67
g2o::SparseBlockMatrixDiagonal::blockIndices
const std::vector< int > & blockIndices() const
indices of the row blocks
Definition
sparse_block_matrix_diagonal.h:74
g2o::SparseBlockMatrixDiagonal::cols
int cols() const
columns of the matrix
Definition
sparse_block_matrix_diagonal.h:52
g2o::SparseBlockMatrixDiagonal::DiagonalVector
std::vector< MatrixType > DiagonalVector
Definition
sparse_block_matrix_diagonal.h:56
g2o::SparseBlockMatrixDiagonal::SparseMatrixBlock
MatrixType SparseMatrixBlock
this is the type of the elementary block, it is an Eigen::Matrix.
Definition
sparse_block_matrix_diagonal.h:49
g2o::SparseBlockMatrixDiagonal::diagonal
const DiagonalVector & diagonal() const
the block matrices per block-column
Definition
sparse_block_matrix_diagonal.h:70
g2o::SparseBlockMatrixDiagonal::multiply
void multiply(double *&dest, const double *src) const
Definition
sparse_block_matrix_diagonal.h:76
g2o::SparseBlockMatrixDiagonal::rows
int rows() const
rows of the matrix
Definition
sparse_block_matrix_diagonal.h:54
matrix_operations.h
g2o
Definition
dl_wrapper.cpp:55
Generated on
for g2o by
1.17.0