NDEVR
API Documentation
sparse_block_matrix_diagonal.h
1#pragma once
2#include "Base/Headers/Buffer.hpp"
3#include <Eigen/Core>
4#include <Eigen/StdVector>
5
6#include "matrix_operations.h"
7
8namespace NDEVR {
9
17 template <class MatrixType>
18 class SparseBlockMatrixDiagonal
19 {
20 public:
22 typedef MatrixType SparseMatrixBlock;
23
25 int cols() const {return _blockIndices && (*_blockIndices).size() ? (*_blockIndices).last() : 0;}
27 int rows() const {return _blockIndices && (*_blockIndices).size() ? (*_blockIndices).last() : 0;}
28
29 typedef Buffer<MatrixType> DiagonalVector;
30
32 {}
33 SparseBlockMatrixDiagonal(const Buffer<int>& blockIndices) :
35 {}
36
38 inline int dimOfBlock(int r) const { return r ? (*_blockIndices)[r] - (*_blockIndices)[r-1] : (*_blockIndices)[0] ; }
39
41 inline int baseOfBlock(int r) const { return r ? (*_blockIndices)[r-1] : 0 ; }
42
44 const DiagonalVector& diagonal() const { return _diagonal;}
45 DiagonalVector& diagonal() { return _diagonal;}
46
48 const Buffer<int>& blockIndices() const { return (*_blockIndices);}
49
50 void multiply(g_type*& dest, const g_type* src) const
51 {
52 int destSize=cols();
53 if (! dest) {
54 dest=new g_type[destSize];
55 memset(dest,0, destSize*sizeof(g_type));
56 }
57
58 // map the memory by Eigen
59 Eigen::Map<Eigen::VectorX<g_type>> destVec(dest, destSize);
60 Eigen::Map<const Eigen::VectorX<g_type>> srcVec(src, rows());
61
62# ifdef G2O_OPENMP
63# pragma omp parallel for default (shared) schedule(dynamic, 10)
64# endif
65 for (int i=0; i < static_cast<int>(_diagonal.size()); ++i){
66 int destOffset = baseOfBlock(i);
67 int srcOffset = destOffset;
68 const SparseMatrixBlock& A = _diagonal[i];
69 // destVec += *A.transpose() * srcVec (according to the sub-vector parts)
70 internal::axpy(A, srcVec, srcOffset, destVec, destOffset);
71 }
72 }
73
74 protected:
75 const Buffer<int>* _blockIndices = nullptr;
76 DiagonalVector _diagonal;
77 };
78
79}
The equivelent of std::vector but with a bit more control.
Definition Buffer.hpp:58
Sparse matrix which uses blocks on the diagonal.
int rows() const
rows of the matrix
int cols() const
columns of the matrix
const DiagonalVector & diagonal() const
the block matrices per block-column
int baseOfBlock(int r) const
where does the row /col at block-row / block-column r starts?
const Buffer< int > * _blockIndices
vector of the indices of the blocks along the diagonal
const Buffer< int > & blockIndices() const
indices of the row blocks
MatrixType SparseMatrixBlock
this is the type of the elementary block, it is an Eigen::Matrix.
int dimOfBlock(int r) const
how many rows/cols does the block at block-row / block-column r has?
Internal helper functions for block-wise matrix-vector products (axpy and atxpy).
The primary namespace for the NDEVR SDK.