NDEVR
API Documentation
SparseBlockMatrix< MatrixType >

Sparse matrix which uses blocks. More...

Inheritance diagram for SparseBlockMatrix< MatrixType >:
[legend]
Collaboration diagram for SparseBlockMatrix< MatrixType >:
[legend]

Public Types

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

Public Member Functions

 SparseBlockMatrix (const int *rbi, const int *cbi, int rb, int cb, bool hasStorage=true)
 constructs a sparse block matrix having a specific layout
bool add (SparseBlockMatrix< MatrixType > &dest) const
 adds the current matrix to the destination
const SparseMatrixBlockblock (int r, int c) const
 returns the block at location r,c
SparseMatrixBlockblock (int r, int c, bool alloc=false)
 returns the block at location r,c. if alloc=true he block is created if it does not exist
const Buffer< IntBlockMap > & blockCols () const
 the block matrices per block-column
void clear (bool dealloc=false)
 this zeroes all the blocks. If dealloc=true the blocks are removed from memory
int colBaseOfBlock (int c) const
 where does the col at block-col r starts?
const Buffer< int > & colBlockIndices () const
 indices of the column blocks
int cols () const
 columns of the matrix
int colsOfBlock (int c) const
 how many cols does the block at block-col c has?
void fillBlockStructure (MatrixStructure &ms) const
 exports the non zero blocks in the structure matrix ms
int fillCCS (g_type *Cx, bool upperTriangle=false) const
 fill the CCS arrays of a matrix, arrays have to be allocated beforehand.
int fillCCS (int *Cp, int *Ci, g_type *Cx, bool upperTriangle=false) const
 fill the CCS arrays of a matrix, arrays have to be allocated beforehand
int fillSparseBlockMatrixCCS (SparseBlockMatrixCCS< MatrixType > &blockCCS) const
 copy into CCS structure
int fillSparseBlockMatrixCCSTransposed (SparseBlockMatrixCCS< MatrixType > &blockCCS) const
 copy as transposed into a CCS structure
void multiply (g_type *&dest, const g_type *src) const
 dest = (*this) * src
template<class MatrixResultType, class MatrixFactorType>
bool multiply (SparseBlockMatrix< MatrixResultType > *&dest, const SparseBlockMatrix< MatrixFactorType > *M) const
 dest = (*this) * M
void multiplySymmetricUpperTriangle (g_type *&dest, const g_type *src) const
 compute dest = (*this) * src However, assuming that this is a symmetric matrix where only the upper triangle is stored
uint04 nonZeroBlocks () const
 number of allocated blocks
uint04 nonZeros () const
 number of non-zero elements
void rightMultiply (g_type *&dest, const g_type *src) const
 dest = M * (*this)
int rowBaseOfBlock (int r) const
 where does the row at block-row r starts?
const Buffer< int > & rowBlockIndices () const
 indices of the row blocks
int rows () const
 rows of the matrix
int rowsOfBlock (int r) const
 how many rows does the block at block-row r has?
void scale (g_type a)
 *this *= a
SparseBlockMatrixslice (int rmin, int rmax, int cmin, int cmax, bool alloc=true) const
 returns a view or a copy of the block matrix
bool symmPermutation (SparseBlockMatrix< MatrixType > *&dest, const int *pinv, bool onlyUpper=false) const
 writes in dest a block permutaton specified by pinv.
void takePatternFromHash (SparseBlockMatrixHashMap< MatrixType > &hashMatrix)
 take over the memory and matrix pattern from a hash matrix.
template<class MatrixTransposedType>
bool transpose (SparseBlockMatrix< MatrixTransposedType > *&dest) const
 transposes a block matrix, The transposed type should match the argument false on failure

Protected Attributes

Buffer< IntBlockMap > _blockCols
 array of maps of blocks.
Buffer< int > _colBlockIndices
 vector of the indices of the blocks along the cols
bool _hasStorage
 Whether this matrix owns its block storage (true) or is a view (false).
Buffer< int > _rowBlockIndices
 vector of the indices of the blocks along the rows.

Detailed Description

template<class MatrixType = MatrixX<g_type>>
class 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 31 of file sparse_block_matrix.h.

Constructor & Destructor Documentation

◆ SparseBlockMatrix()

template<class MatrixType>
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.
rbiarray 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 30 of file sparse_block_matrix.hpp.

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

Referenced by add(), multiply(), slice(), symmPermutation(), and transpose().

Member Function Documentation

◆ fillCCS()

template<class MatrixType>
int SparseBlockMatrix< MatrixType >::fillCCS ( g_type * 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 452 of file sparse_block_matrix.hpp.

References _blockCols, _colBlockIndices, _rowBlockIndices, cast(), and colsOfBlock().

◆ fillSparseBlockMatrixCCS()

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

copy into CCS structure

Returns
number of processed blocks, -1 on error

Definition at line 535 of file sparse_block_matrix.hpp.

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

◆ fillSparseBlockMatrixCCSTransposed()

template<class MatrixType>
int 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 556 of file sparse_block_matrix.hpp.

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

◆ slice()

template<class MatrixType>
SparseBlockMatrix< MatrixType > * 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 304 of file sparse_block_matrix.hpp.

References SparseBlockMatrix(), _blockCols, _hasStorage, colsOfBlock(), Buffer< t_type, t_memory_manager >::insert(), and rowsOfBlock().

◆ symmPermutation()

template<class MatrixType>
bool 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 385 of file sparse_block_matrix.hpp.

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

◆ takePatternFromHash()

template<class MatrixType>
void 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 575 of file sparse_block_matrix.hpp.

References Buffer< t_type, t_memory_manager >::add(), blockCols(), and SparseBlockMatrixHashMap< MatrixType >::columns().

Member Data Documentation

◆ _blockCols

template<class MatrixType = MatrixX<g_type>>
Buffer<IntBlockMap> 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 179 of file sparse_block_matrix.h.

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


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