g2o
Loading...
Searching...
No Matches
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
36namespace g2o {
37
45template <class MatrixType>
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
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; }
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;
104};
105
106} // namespace g2o
107
108#endif
Sparse matrix which uses blocks on the diagonal.
int dimOfBlock(int r) const
how many rows/cols does the block at block-row / block-column r has?
SparseBlockMatrixDiagonal(const std::vector< int > &blockIndices)
int baseOfBlock(int r) const
where does the row /col at block-row / block-column r starts?
const std::vector< int > & blockIndices() const
indices of the row blocks
int cols() const
columns of the matrix
MatrixType SparseMatrixBlock
this is the type of the elementary block, it is an Eigen::Matrix.
const DiagonalVector & diagonal() const
the block matrices per block-column
void multiply(double *&dest, const double *src) const