g2o
Loading...
Searching...
No Matches
g2o::SparseBlockMatrix< MatrixType > Class Template Reference

Sparse matrix which uses blocks. More...

#include <sparse_block_matrix.h>

Public Types

typedef MatrixType SparseMatrixBlock
 this is the type of the elementary block, it is an Eigen::Matrix.
typedef std::map< int, SparseMatrixBlock * > IntBlockMap

Public Member Functions

int cols () const
 columns of the matrix
int rows () const
 rows of the matrix
 SparseBlockMatrix (const int *rbi, const int *cbi, int rb, int cb, bool hasStorage=true)
 SparseBlockMatrix ()
 ~SparseBlockMatrix ()
void clear (bool dealloc=false)
SparseMatrixBlock * block (int r, int c, bool alloc=false)
const SparseMatrixBlock * block (int r, int c) const
 returns the block at location r,c
int rowsOfBlock (int r) const
 how many rows does the block at block-row r has?
int colsOfBlock (int c) const
 how many cols does the block at block-col c has?
int rowBaseOfBlock (int r) const
 where does the row at block-row r starts?
int colBaseOfBlock (int c) const
 where does the col at block-col r starts?
size_t nonZeros () const
 number of non-zero elements
size_t nonZeroBlocks () const
 number of allocated blocks
SparseBlockMatrix * clone () const
 deep copy of a sparse-block-matrix;
SparseBlockMatrix * slice (int rmin, int rmax, int cmin, int cmax, bool alloc=true) const
template<class MatrixTransposedType>
bool transpose (SparseBlockMatrix< MatrixTransposedType > &dest) const
template<class MatrixTransposedType>
std::unique_ptr< SparseBlockMatrix< MatrixTransposedType > > transposed () const
bool add (SparseBlockMatrix< MatrixType > &dest) const
 adds the current matrix to the destination
std::unique_ptr< SparseBlockMatrix< MatrixType > > added () const
template<class MatrixResultType, class MatrixFactorType>
bool multiply (SparseBlockMatrix< MatrixResultType > *&dest, const SparseBlockMatrix< MatrixFactorType > *M) const
 dest = (*this) * M
void multiply (double *&dest, const double *src) const
 dest = (*this) * src
void multiplySymmetricUpperTriangle (double *&dest, const double *src) const
void rightMultiply (double *&dest, const double *src) const
 dest = M * (*this)
void scale (double a)
 *this *= a
bool symmPermutation (SparseBlockMatrix< MatrixType > *&dest, const int *pinv, bool onlyUpper=false) const
int fillCCS (int *Cp, int *Ci, double *Cx, bool upperTriangle=false) const
int fillCCS (double *Cx, bool upperTriangle=false) const
void fillBlockStructure (MatrixStructure &ms) const
 exports the non zero blocks in the structure matrix ms
void fillBlockStructure (int *Cp, int *Ci) const
 exports the non zero blocks into a column compressed structure
const std::vector< IntBlockMap > & blockCols () const
 the block matrices per block-column
std::vector< IntBlockMap > & blockCols ()
const std::vector< int > & rowBlockIndices () const
 indices of the row blocks
std::vector< int > & rowBlockIndices ()
const std::vector< int > & colBlockIndices () const
 indices of the column blocks
std::vector< int > & colBlockIndices ()
bool writeOctave (const char *filename, bool upperTriangle=true) const
int fillSparseBlockMatrixCCS (SparseBlockMatrixCCS< MatrixType > &blockCCS) const
int fillSparseBlockMatrixCCSTransposed (SparseBlockMatrixCCS< MatrixType > &blockCCS) const
void takePatternFromHash (SparseBlockMatrixHashMap< MatrixType > &hashMatrix)

Protected Attributes

std::vector< int > _rowBlockIndices
std::vector< int > _colBlockIndices
std::vector< IntBlockMap > _blockCols
bool _hasStorage

Private Member Functions

template<class MatrixTransposedType>
void transpose_internal (SparseBlockMatrix< MatrixTransposedType > &dest) const
void add_internal (SparseBlockMatrix< MatrixType > &dest) const

Detailed Description

template<class MatrixType = MatrixX>
class g2o::SparseBlockMatrix< MatrixType >

Sparse matrix which uses blocks.

Template class that specifies a sparse block matrix. A block matrix is a sparse matrix made of dense blocks. These blocks cannot have a random pattern, but follow a (variable) grid structure. This structure is specified by a partition of the rows and the columns of the matrix. The blocks are represented by the Eigen::Matrix structure, thus they can be statically or dynamically allocated. For efficiency reasons it is convenient to allocate them statically, when possible. A static block matrix has all blocks of the same size, and the size of the block is specified by the template argument. If this is not the case, and you have different block sizes than you have to use a dynamic-block matrix (default template argument).

Definition at line 64 of file sparse_block_matrix.h.

Member Typedef Documentation

◆ IntBlockMap

template<class MatrixType = MatrixX>
typedef std::map<int, SparseMatrixBlock*> g2o::SparseBlockMatrix< MatrixType >::IntBlockMap

Definition at line 78 of file sparse_block_matrix.h.

◆ SparseMatrixBlock

template<class MatrixType = MatrixX>
typedef MatrixType g2o::SparseBlockMatrix< MatrixType >::SparseMatrixBlock

this is the type of the elementary block, it is an Eigen::Matrix.

Definition at line 67 of file sparse_block_matrix.h.

Constructor & Destructor Documentation

◆ SparseBlockMatrix() [1/2]

template<class MatrixType>
g2o::SparseBlockMatrix< MatrixType >::SparseBlockMatrix ( const int * rbi,
const int * cbi,
int rb,
int cb,
bool hasStorage = true )

constructs a sparse block matrix having a specific layout

Parameters
rbiarray of int containing the row layout of the blocks. the component i of the array should contain the index of the first row of the block i+1.
cbiarray of int containing the column layout of the blocks. the component i of the array should contain the index of the first col of the block i+1.
rbnumber of row blocks
cbnumber of col blocks
hasStorageset it to true if the matrix "owns" the blocks, thus it deletes it on destruction. if false the matrix is only a "view" over an existing structure.

Definition at line 32 of file sparse_block_matrix.hpp.

References _blockCols, _colBlockIndices, _hasStorage, and _rowBlockIndices.

Referenced by add(), add_internal(), block(), block(), clear(), clone(), fillCCS(), fillCCS(), multiply(), multiplySymmetricUpperTriangle(), nonZeros(), rightMultiply(), scale(), slice(), symmPermutation(), takePatternFromHash(), transpose(), transpose_internal(), and writeOctave().

◆ SparseBlockMatrix() [2/2]

template<class MatrixType>
g2o::SparseBlockMatrix< MatrixType >::SparseBlockMatrix ( )

Definition at line 41 of file sparse_block_matrix.hpp.

References _blockCols, and _hasStorage.

◆ ~SparseBlockMatrix()

template<class MatrixType>
g2o::SparseBlockMatrix< MatrixType >::~SparseBlockMatrix ( )

Definition at line 64 of file sparse_block_matrix.hpp.

References _hasStorage, and clear().

Member Function Documentation

◆ add()

template<class MatrixType>
bool g2o::SparseBlockMatrix< MatrixType >::add ( SparseBlockMatrix< MatrixType > & dest) const

adds the current matrix to the destination

Definition at line 184 of file sparse_block_matrix.hpp.

References _colBlockIndices, _hasStorage, _rowBlockIndices, and SparseBlockMatrix().

◆ add_internal()

template<class MatrixType>
void g2o::SparseBlockMatrix< MatrixType >::add_internal ( SparseBlockMatrix< MatrixType > & dest) const
private

Definition at line 169 of file sparse_block_matrix.hpp.

References _blockCols, and SparseBlockMatrix().

◆ added()

template<class MatrixType>
std::unique_ptr< SparseBlockMatrix< MatrixType > > g2o::SparseBlockMatrix< MatrixType >::added ( ) const

Definition at line 202 of file sparse_block_matrix.hpp.

References _colBlockIndices, and _rowBlockIndices.

◆ block() [1/2]

template<class MatrixType>
const SparseBlockMatrix< MatrixType >::SparseMatrixBlock * g2o::SparseBlockMatrix< MatrixType >::block ( int r,
int c ) const

returns the block at location r,c

Definition at line 97 of file sparse_block_matrix.hpp.

References SparseBlockMatrix().

◆ block() [2/2]

template<class MatrixType>
SparseBlockMatrix< MatrixType >::SparseMatrixBlock * g2o::SparseBlockMatrix< MatrixType >::block ( int r,
int c,
bool alloc = false )

◆ blockCols() [1/2]

template<class MatrixType = MatrixX>
std::vector< IntBlockMap > & g2o::SparseBlockMatrix< MatrixType >::blockCols ( )
inline

Definition at line 212 of file sparse_block_matrix.h.

◆ blockCols() [2/2]

template<class MatrixType = MatrixX>
const std::vector< IntBlockMap > & g2o::SparseBlockMatrix< MatrixType >::blockCols ( ) const
inline

◆ clear()

template<class MatrixType>
void g2o::SparseBlockMatrix< MatrixType >::clear ( bool dealloc = false)

this zeroes all the blocks. If dealloc=true the blocks are removed from memory

Definition at line 45 of file sparse_block_matrix.hpp.

References _blockCols, _hasStorage, and SparseBlockMatrix().

Referenced by symmPermutation(), and ~SparseBlockMatrix().

◆ clone()

template<class MatrixType>
SparseBlockMatrix< MatrixType > * g2o::SparseBlockMatrix< MatrixType >::clone ( ) const

deep copy of a sparse-block-matrix;

Definition at line 105 of file sparse_block_matrix.hpp.

References SparseBlockMatrix().

◆ colBaseOfBlock()

◆ colBlockIndices() [1/2]

template<class MatrixType = MatrixX>
std::vector< int > & g2o::SparseBlockMatrix< MatrixType >::colBlockIndices ( )
inline

Definition at line 220 of file sparse_block_matrix.h.

◆ colBlockIndices() [2/2]

template<class MatrixType = MatrixX>
const std::vector< int > & g2o::SparseBlockMatrix< MatrixType >::colBlockIndices ( ) const
inline

◆ cols()

◆ colsOfBlock()

◆ fillBlockStructure() [1/2]

template<class MatrixType>
void g2o::SparseBlockMatrix< MatrixType >::fillBlockStructure ( int * Cp,
int * Ci ) const

exports the non zero blocks into a column compressed structure

Definition at line 582 of file sparse_block_matrix.hpp.

References _blockCols, and nonZeroBlocks().

◆ fillBlockStructure() [2/2]

◆ fillCCS() [1/2]

template<class MatrixType>
int g2o::SparseBlockMatrix< MatrixType >::fillCCS ( double * Cx,
bool upperTriangle = false ) const

fill the CCS arrays of a matrix, arrays have to be allocated beforehand. This function only writes the values and assumes that column and row structures have already been written.

Definition at line 516 of file sparse_block_matrix.hpp.

References _blockCols, _colBlockIndices, _rowBlockIndices, colsOfBlock(), rows(), and SparseBlockMatrix().

◆ fillCCS() [2/2]

template<class MatrixType>
int g2o::SparseBlockMatrix< MatrixType >::fillCCS ( int * Cp,
int * Ci,
double * Cx,
bool upperTriangle = false ) const

fill the CCS arrays of a matrix, arrays have to be allocated beforehand

Definition at line 542 of file sparse_block_matrix.hpp.

References _blockCols, _colBlockIndices, _rowBlockIndices, colsOfBlock(), rows(), and SparseBlockMatrix().

Referenced by g2o::SparseOptimizerIncremental::computeCholeskyUpdate(), and g2o::LinearSolverCholmodOnline< MatrixType >::fillCholmodExt().

◆ fillSparseBlockMatrixCCS()

template<class MatrixType>
int g2o::SparseBlockMatrix< MatrixType >::fillSparseBlockMatrixCCS ( SparseBlockMatrixCCS< MatrixType > & blockCCS) const

copy into CCS structure

Returns
number of processed blocks, -1 on error

Definition at line 646 of file sparse_block_matrix.hpp.

References blockCols(), and g2o::SparseBlockMatrixCCS< MatrixType >::blockCols().

Referenced by g2o::LinearSolverCCS< MatrixType >::initMatrixStructure().

◆ fillSparseBlockMatrixCCSTransposed()

template<class MatrixType>
int g2o::SparseBlockMatrix< MatrixType >::fillSparseBlockMatrixCCSTransposed ( SparseBlockMatrixCCS< MatrixType > & blockCCS) const

copy as transposed into a CCS structure

Returns
number of processed blocks, -1 on error

Definition at line 667 of file sparse_block_matrix.hpp.

References _rowBlockIndices, blockCols(), and g2o::SparseBlockMatrixCCS< MatrixType >::blockCols().

◆ multiply() [1/2]

template<class MatrixType>
void g2o::SparseBlockMatrix< MatrixType >::multiply ( double *& dest,
const double * src ) const

dest = (*this) * src

Definition at line 255 of file sparse_block_matrix.hpp.

References _rowBlockIndices.

◆ multiply() [2/2]

template<class MatrixType>
template<class MatrixResultType, class MatrixFactorType>
bool g2o::SparseBlockMatrix< MatrixType >::multiply ( SparseBlockMatrix< MatrixResultType > *& dest,
const SparseBlockMatrix< MatrixFactorType > * M ) const

dest = (*this) * M

Definition at line 212 of file sparse_block_matrix.hpp.

References _blockCols, _colBlockIndices, _hasStorage, _rowBlockIndices, and SparseBlockMatrix().

◆ multiplySymmetricUpperTriangle()

template<class MatrixType>
void g2o::SparseBlockMatrix< MatrixType >::multiplySymmetricUpperTriangle ( double *& dest,
const double * src ) const

compute dest = (*this) * src However, assuming that this is a symmetric matrix where only the upper triangle is stored

Definition at line 285 of file sparse_block_matrix.hpp.

References _blockCols, _rowBlockIndices, colBaseOfBlock(), cols(), rowBaseOfBlock(), rows(), and SparseBlockMatrix().

◆ nonZeroBlocks()

template<class MatrixType>
size_t g2o::SparseBlockMatrix< MatrixType >::nonZeroBlocks ( ) const

◆ nonZeros()

◆ rightMultiply()

template<class MatrixType>
void g2o::SparseBlockMatrix< MatrixType >::rightMultiply ( double *& dest,
const double * src ) const

dest = M * (*this)

Definition at line 320 of file sparse_block_matrix.hpp.

References _blockCols, colBaseOfBlock(), cols(), rowBaseOfBlock(), rows(), and SparseBlockMatrix().

◆ rowBaseOfBlock()

template<class MatrixType = MatrixX>
int g2o::SparseBlockMatrix< MatrixType >::rowBaseOfBlock ( int r) const
inline

◆ rowBlockIndices() [1/2]

template<class MatrixType = MatrixX>
std::vector< int > & g2o::SparseBlockMatrix< MatrixType >::rowBlockIndices ( )
inline

Definition at line 216 of file sparse_block_matrix.h.

◆ rowBlockIndices() [2/2]

◆ rows()

◆ rowsOfBlock()

template<class MatrixType = MatrixX>
int g2o::SparseBlockMatrix< MatrixType >::rowsOfBlock ( int r) const
inline

how many rows does the block at block-row r has?

Definition at line 112 of file sparse_block_matrix.h.

Referenced by g2o::LinearSolver< PoseMatrixType >::allocateBlocks(), block(), slice(), and g2o::LinearSolverDense< MatrixType >::solve().

◆ scale()

template<class MatrixType>
void g2o::SparseBlockMatrix< MatrixType >::scale ( double a)

*this *= a

Definition at line 353 of file sparse_block_matrix.hpp.

References _blockCols, and SparseBlockMatrix().

◆ slice()

template<class MatrixType>
SparseBlockMatrix< MatrixType > * g2o::SparseBlockMatrix< MatrixType >::slice ( int rmin,
int rmax,
int cmin,
int cmax,
bool alloc = true ) const

returns a view or a copy of the block matrix

Parameters
rminstarting block row
rmaxending block row
cminstarting block col
cmaxending block col
allocif true it makes a deep copy, if false it creates a view.

Definition at line 365 of file sparse_block_matrix.hpp.

References _blockCols, _hasStorage, colsOfBlock(), rowsOfBlock(), and SparseBlockMatrix().

◆ symmPermutation()

template<class MatrixType>
bool g2o::SparseBlockMatrix< MatrixType >::symmPermutation ( SparseBlockMatrix< MatrixType > *& dest,
const int * pinv,
bool onlyUpper = false ) const

writes in dest a block permutaton specified by pinv.

Parameters
pinvarray such that new_block[i] = old_block[pinv[i]]

Definition at line 453 of file sparse_block_matrix.hpp.

References _blockCols, _colBlockIndices, _rowBlockIndices, block(), clear(), cols(), rows(), SparseBlockMatrix(), and transpose().

◆ takePatternFromHash()

template<class MatrixType>
void g2o::SparseBlockMatrix< MatrixType >::takePatternFromHash ( SparseBlockMatrixHashMap< MatrixType > & hashMatrix)

take over the memory and matrix pattern from a hash matrix. The structure of the hash matrix will be cleared.

Definition at line 687 of file sparse_block_matrix.hpp.

References blockCols(), g2o::SparseBlockMatrixHashMap< MatrixType >::blockCols(), and SparseBlockMatrix().

◆ transpose()

template<class MatrixType>
template<class MatrixTransposedType>
bool g2o::SparseBlockMatrix< MatrixType >::transpose ( SparseBlockMatrix< MatrixTransposedType > & dest) const

transposes a block matrix, The transposed type should match the argument false on failure

Definition at line 141 of file sparse_block_matrix.hpp.

References _colBlockIndices, _hasStorage, _rowBlockIndices, and SparseBlockMatrix().

Referenced by g2o::LinearSolverDense< MatrixType >::solve(), and symmPermutation().

◆ transpose_internal()

template<class MatrixType>
template<class MatrixTransposedType>
void g2o::SparseBlockMatrix< MatrixType >::transpose_internal ( SparseBlockMatrix< MatrixTransposedType > & dest) const
private

Definition at line 125 of file sparse_block_matrix.hpp.

References _blockCols, block(), and SparseBlockMatrix().

◆ transposed()

template<class MatrixType>
template<class MatrixTransposedType>
std::unique_ptr< SparseBlockMatrix< MatrixTransposedType > > g2o::SparseBlockMatrix< MatrixType >::transposed ( ) const

Definition at line 160 of file sparse_block_matrix.hpp.

◆ writeOctave()

template<class MatrixType>
bool g2o::SparseBlockMatrix< MatrixType >::writeOctave ( const char * filename,
bool upperTriangle = true ) const

write the content of this matrix to a stream loadable by Octave

Parameters
upperTriangledoes this matrix store only the upper triangular blocks

Definition at line 600 of file sparse_block_matrix.hpp.

References _blockCols, g2o::TripletEntry::c, colBaseOfBlock(), cols(), g2o::TripletEntry::r, rowBaseOfBlock(), rows(), SparseBlockMatrix(), and g2o::TripletEntry::x.

Referenced by g2o::LinearSolverEigen< MatrixType >::computeCholesky().

Member Data Documentation

◆ _blockCols

template<class MatrixType = MatrixX>
std::vector<IntBlockMap> g2o::SparseBlockMatrix< MatrixType >::_blockCols
protected

array of maps of blocks. The index of the array represent a block column of the matrix and the block column is stored as a map row_block -> matrix_block_ptr.

Definition at line 257 of file sparse_block_matrix.h.

Referenced by add_internal(), block(), clear(), fillBlockStructure(), fillCCS(), fillCCS(), multiply(), multiplySymmetricUpperTriangle(), nonZeroBlocks(), nonZeros(), rightMultiply(), scale(), slice(), SparseBlockMatrix(), SparseBlockMatrix(), symmPermutation(), transpose_internal(), and writeOctave().

◆ _colBlockIndices

template<class MatrixType = MatrixX>
std::vector<int> g2o::SparseBlockMatrix< MatrixType >::_colBlockIndices
protected

vector of the indices of the blocks along the cols

Definition at line 253 of file sparse_block_matrix.h.

Referenced by add(), added(), fillBlockStructure(), fillCCS(), fillCCS(), multiply(), SparseBlockMatrix(), symmPermutation(), and transpose().

◆ _hasStorage

template<class MatrixType = MatrixX>
bool g2o::SparseBlockMatrix< MatrixType >::_hasStorage
protected

◆ _rowBlockIndices

template<class MatrixType = MatrixX>
std::vector<int> g2o::SparseBlockMatrix< MatrixType >::_rowBlockIndices
protected

The documentation for this class was generated from the following files: