All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Groups Pages
Eigen::BlockSparseMatrix< _Scalar, _BlockAtCompileTime, _Options, _StorageIndex > Class Template Reference

Detailed Description

template<typename _Scalar, int _BlockAtCompileTime = Dynamic, int _Options = ColMajor, typename _StorageIndex = int>
class Eigen::BlockSparseMatrix< _Scalar, _BlockAtCompileTime, _Options, _StorageIndex >

A versatile sparse matrix representation where each element is a block.

This class provides routines to manipulate block sparse matrices stored in a BSR-like representation. There are two main types :

  1. All blocks have the same number of rows and columns, called block size in the following. In this case, if this block size is known at compile time, it can be given as a template parameter like
    * BlockSparseMatrix<Scalar, 3, ColMajor> bmat(b_rows, b_cols);
    *
    Here, bmat is a b_rows x b_cols block sparse matrix where each coefficient is a 3x3 dense matrix. If the block size is fixed but will be given at runtime,
    * BlockSparseMatrix<Scalar, Dynamic, ColMajor> bmat(b_rows, b_cols);
    * bmat.setBlockSize(block_size);
    *
  2. The second case is for variable-block sparse matrices. Here each block has its own dimensions. The only restriction is that all the blocks in a row (resp. a column) should have the same number of rows (resp. of columns). It is thus required in this case to describe the layout of the matrix by calling setBlockLayout(rowBlocks, colBlocks).

In any of the previous case, the matrix can be filled by calling setFromTriplets(). A regular sparse matrix can be converted to a block sparse matrix and vice versa. It is obviously required to describe the block layout beforehand by calling either setBlockSize() for fixed-size blocks or setBlockLayout for variable-size blocks.

Template Parameters
_ScalarThe Scalar type
_BlockAtCompileTimeThe block layout option. It takes the following values Dynamic : block size known at runtime a numeric number : fixed-size block known at compile time

Inherits SparseMatrixBase< BlockSparseMatrix< _Scalar, _BlockAtCompileTime, _Options, _StorageIndex > >.

Public Member Functions

Index blockCols () const
 
Index blockColsIndex (Index bj) const
 
Index blockPtr (Index id) const
 
Index blockRows () const
 
Index blockRowsIndex (Index bi) const
 
 BlockSparseMatrix (Index brow, Index bcol)
 Construct and resize.
 
 BlockSparseMatrix (const BlockSparseMatrix &other)
 Copy-constructor.
 
template<typename MatrixType >
 BlockSparseMatrix (const MatrixType &spmat)
 Constructor from a sparse matrix.
 
Map< const BlockScalar > coeff (Index brow, Index bcol) const
 
Ref< BlockScalar > coeffRef (Index brow, Index bcol)
 
Index cols () const
 
Index innerToBlock (Index inner) const
 
bool isCompressed () const
 for compatibility purposes with the SparseMatrix class
 
Index nonZeros () const
 
Index nonZerosBlocks () const
 
template<typename MatrixType >
BlockSparseMatrixoperator= (const MatrixType &spmat)
 Assignment from a sparse matrix with the same storage order. More...
 
Index outerToBlock (Index outer) const
 
void reserve (const Index nonzerosblocks)
 Allocate the internal array of pointers to blocks and their inner indices. More...
 
void resize (Index brow, Index bcol)
 Set the number of rows and columns blocks.
 
Index rows () const
 
void setBlockLayout (const VectorXi &rowBlocks, const VectorXi &colBlocks)
 Set the row and column block layouts,. More...
 
void setBlockSize (Index blockSize)
 set the block size at runtime for fixed-size block layout More...
 
template<typename MatrixType >
void setBlockStructure (const MatrixType &blockPattern)
 Set the nonzero block pattern of the matrix. More...
 
template<typename InputIterator >
void setFromTriplets (const InputIterator &begin, const InputIterator &end)
 Fill values in a matrix from a triplet list. More...
 

Member Function Documentation

template<typename _Scalar , int _BlockAtCompileTime = Dynamic, int _Options = ColMajor, typename _StorageIndex = int>
Index Eigen::BlockSparseMatrix< _Scalar, _BlockAtCompileTime, _Options, _StorageIndex >::blockCols ( ) const
inline
Returns
the number of columns grouped by blocks
template<typename _Scalar , int _BlockAtCompileTime = Dynamic, int _Options = ColMajor, typename _StorageIndex = int>
Index Eigen::BlockSparseMatrix< _Scalar, _BlockAtCompileTime, _Options, _StorageIndex >::blockColsIndex ( Index  bj) const
inline
Returns
the starting index of the bj col block
template<typename _Scalar , int _BlockAtCompileTime = Dynamic, int _Options = ColMajor, typename _StorageIndex = int>
Index Eigen::BlockSparseMatrix< _Scalar, _BlockAtCompileTime, _Options, _StorageIndex >::blockPtr ( Index  id) const
inline
Returns
the starting position of the block <id> in the array of values
template<typename _Scalar , int _BlockAtCompileTime = Dynamic, int _Options = ColMajor, typename _StorageIndex = int>
Index Eigen::BlockSparseMatrix< _Scalar, _BlockAtCompileTime, _Options, _StorageIndex >::blockRows ( ) const
inline
Returns
the number of rows grouped by blocks
template<typename _Scalar , int _BlockAtCompileTime = Dynamic, int _Options = ColMajor, typename _StorageIndex = int>
Index Eigen::BlockSparseMatrix< _Scalar, _BlockAtCompileTime, _Options, _StorageIndex >::blockRowsIndex ( Index  bi) const
inline
Returns
the starting index of the bi row block
template<typename _Scalar , int _BlockAtCompileTime = Dynamic, int _Options = ColMajor, typename _StorageIndex = int>
Map<const BlockScalar> Eigen::BlockSparseMatrix< _Scalar, _BlockAtCompileTime, _Options, _StorageIndex >::coeff ( Index  brow,
Index  bcol 
) const
inline
Returns
the value of the (i,j) block as an Eigen Dense Matrix
template<typename _Scalar , int _BlockAtCompileTime = Dynamic, int _Options = ColMajor, typename _StorageIndex = int>
Ref<BlockScalar> Eigen::BlockSparseMatrix< _Scalar, _BlockAtCompileTime, _Options, _StorageIndex >::coeffRef ( Index  brow,
Index  bcol 
)
inline
Returns
a reference to the (i,j) block as an Eigen Dense Matrix
template<typename _Scalar , int _BlockAtCompileTime = Dynamic, int _Options = ColMajor, typename _StorageIndex = int>
Index Eigen::BlockSparseMatrix< _Scalar, _BlockAtCompileTime, _Options, _StorageIndex >::cols ( ) const
inline
Returns
the number of cols
template<typename _Scalar , int _BlockAtCompileTime = Dynamic, int _Options = ColMajor, typename _StorageIndex = int>
Index Eigen::BlockSparseMatrix< _Scalar, _BlockAtCompileTime, _Options, _StorageIndex >::innerToBlock ( Index  inner) const
inline
Returns
the block index where inner belongs to
template<typename _Scalar , int _BlockAtCompileTime = Dynamic, int _Options = ColMajor, typename _StorageIndex = int>
Index Eigen::BlockSparseMatrix< _Scalar, _BlockAtCompileTime, _Options, _StorageIndex >::nonZeros ( ) const
inline
Returns
the total number of nonzero elements, including eventual explicit zeros in blocks
template<typename _Scalar , int _BlockAtCompileTime = Dynamic, int _Options = ColMajor, typename _StorageIndex = int>
Index Eigen::BlockSparseMatrix< _Scalar, _BlockAtCompileTime, _Options, _StorageIndex >::nonZerosBlocks ( ) const
inline
Returns
the number of nonzero blocks
template<typename _Scalar , int _BlockAtCompileTime = Dynamic, int _Options = ColMajor, typename _StorageIndex = int>
template<typename MatrixType >
BlockSparseMatrix& Eigen::BlockSparseMatrix< _Scalar, _BlockAtCompileTime, _Options, _StorageIndex >::operator= ( const MatrixType &  spmat)
inline

Assignment from a sparse matrix with the same storage order.

Convert from a sparse matrix to block sparse matrix.

Warning
Before calling this function, tt is necessary to call either setBlockLayout() (matrices with variable-size blocks) or setBlockSize() (for fixed-size blocks).
template<typename _Scalar , int _BlockAtCompileTime = Dynamic, int _Options = ColMajor, typename _StorageIndex = int>
Index Eigen::BlockSparseMatrix< _Scalar, _BlockAtCompileTime, _Options, _StorageIndex >::outerToBlock ( Index  outer) const
inline
Returns
the block index where outer belongs to
template<typename _Scalar , int _BlockAtCompileTime = Dynamic, int _Options = ColMajor, typename _StorageIndex = int>
void Eigen::BlockSparseMatrix< _Scalar, _BlockAtCompileTime, _Options, _StorageIndex >::reserve ( const Index  nonzerosblocks)
inline

Allocate the internal array of pointers to blocks and their inner indices.

Note
For fixed-size blocks, call setBlockSize() to set the block. And For variable-size blocks, call setBlockLayout() before using this function
Parameters
nonzerosblocksNumber of nonzero blocks. The total number of nonzeros is is computed in setBlockLayout() for variable-size blocks
See Also
setBlockSize()
template<typename _Scalar , int _BlockAtCompileTime = Dynamic, int _Options = ColMajor, typename _StorageIndex = int>
Index Eigen::BlockSparseMatrix< _Scalar, _BlockAtCompileTime, _Options, _StorageIndex >::rows ( ) const
inline
Returns
the number of rows
template<typename _Scalar , int _BlockAtCompileTime = Dynamic, int _Options = ColMajor, typename _StorageIndex = int>
void Eigen::BlockSparseMatrix< _Scalar, _BlockAtCompileTime, _Options, _StorageIndex >::setBlockLayout ( const VectorXi &  rowBlocks,
const VectorXi &  colBlocks 
)
inline

Set the row and column block layouts,.

This function set the size of each row and column block. So this function should be used only for blocks with variable size.

Parameters
rowBlocks: Number of rows per row block
colBlocks: Number of columns per column block
See Also
resize(), setBlockSize()
template<typename _Scalar , int _BlockAtCompileTime = Dynamic, int _Options = ColMajor, typename _StorageIndex = int>
void Eigen::BlockSparseMatrix< _Scalar, _BlockAtCompileTime, _Options, _StorageIndex >::setBlockSize ( Index  blockSize)
inline

set the block size at runtime for fixed-size block layout

Call this only for fixed-size blocks

template<typename _Scalar , int _BlockAtCompileTime = Dynamic, int _Options = ColMajor, typename _StorageIndex = int>
template<typename MatrixType >
void Eigen::BlockSparseMatrix< _Scalar, _BlockAtCompileTime, _Options, _StorageIndex >::setBlockStructure ( const MatrixType &  blockPattern)
inline

Set the nonzero block pattern of the matrix.

Given a sparse matrix describing the nonzero block pattern, this function prepares the internal pointers for values. After calling this function, any nonzero block (bi, bj) can be set with a simple call to coeffRef(bi,bj).

Warning
Before calling this function, tt is necessary to call either setBlockLayout() (matrices with variable-size blocks) or setBlockSize() (for fixed-size blocks).
Parameters
blockPatternSparse matrix of boolean elements describing the block structure
See Also
setBlockLayout()
setBlockSize()
template<typename _Scalar , int _BlockAtCompileTime = Dynamic, int _Options = ColMajor, typename _StorageIndex = int>
template<typename InputIterator >
void Eigen::BlockSparseMatrix< _Scalar, _BlockAtCompileTime, _Options, _StorageIndex >::setFromTriplets ( const InputIterator &  begin,
const InputIterator &  end 
)
inline

Fill values in a matrix from a triplet list.

Each triplet item has a block stored in an Eigen dense matrix. The InputIterator class should provide the functions row(), col() and value()

Note
For fixed-size blocks, call setBlockSize() before this function.

FIXME Do not accept duplicates


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