|
So-Bogus
A c++ sparse block matrix library aimed at Second Order cone problems
|
Mapped Sparse Block Matrix. More...
#include <MappedSparseBlockMatrix.hpp>
Public Types | |
|
typedef SparseBlockMatrixBase < MappedSparseBlockMatrix > | Base |
| typedef Base::Index | Index |
| typedef Base::BlockPtr | BlockPtr |
|
typedef BlockMatrixTraits < MappedSparseBlockMatrix < BlockT, Flags, Index_ > > | Traits |
| typedef Traits::MajorIndexType | MajorIndexType |
| typedef Base::BlockType | BlockType |
| typedef Base::Scalar | Scalar |
|
typedef MajorIndexType::InnerIterator | InnerIterator |
|
typedef SparseBlockIndex < false, Index, BlockPtr > | UncompressedIndexType |
|
typedef SparseBlockIndex< true, Index, BlockPtr > | CompressedIndexType |
| typedef UncompressedIndexType | MinorIndexType |
| typedef CompressedIndexType | TransposeIndexType |
|
typedef TypeSwapIf < Traits::is_col_major, MajorIndexType, MinorIndexType > ::First | RowIndexType |
|
typedef TypeSwapIf < Traits::is_col_major, MajorIndexType, MinorIndexType > ::Second | ColIndexType |
|
typedef MutableImpl< BlockType, true >::Type | CopyResultType |
|
typedef Base::ConstTransposeReturnType | ConstTransposeReturnType |
|
typedef BlockTraits< BlockType > ::TransposeStorageType | TransposeBlockType |
|
typedef ResizableSequenceContainer < TransposeBlockType >::Type | TransposeArrayType |
| enum | CompileTimeProperties { RowsPerBlock = Traits::RowsPerBlock, ColsPerBlock = Traits::ColsPerBlock, has_row_major_blocks = BlockTraits< BlockType >::is_row_major, has_square_or_dynamic_blocks = ColsPerBlock == RowsPerBlock, has_fixed_rows_blocks = ((int) RowsPerBlock != internal::DYNAMIC ), has_fixed_cols_blocks = ((int) ColsPerBlock != internal::DYNAMIC ), has_fixed_size_blocks = has_fixed_cols_blocks && has_fixed_rows_blocks } |
| Compile-time block properties. | |
| typedef Traits::BlocksArrayType | BlocksArrayType |
| enum | { is_transposed = Traits::is_transposed } |
| enum | { RowsAtCompileTime = internal::DYNAMIC, ColsAtCompileTime = internal::DYNAMIC, is_self_transpose = Traits::is_symmetric } |
| typedef Traits::TransposeObjectType | TransposeObjectType |
| typedef Traits::PlainObjectType | PlainObjectType |
Public Member Functions | |
| template<typename Derived > | |
| MappedSparseBlockMatrix (const SparseBlockMatrixBase< Derived > &source) | |
| void | mapTo (std::size_t numberOfNonZeros, const BlockT *dataPtr, const Index *outerIndexPtr, const Index *innerIndexPtr) |
| template<typename Derived > | |
| void | mapTo (const SparseBlockMatrixBase< Derived > &source) |
| BlockType & | block (Index row, Index col) |
| const BlockType & | block (Index row, Index col) const |
| Index | rows () const |
| Returns the total number of rows of the matrix ( expanding blocks ) | |
| Index | cols () const |
| Returns the total number of columns of the matrix ( expanding blocks ) | |
| const Traits::BlocksArrayType & | blocks () const |
| Access to blocks data. | |
| const BlockType * | data () const |
| Access to blocks data as a raw pointer. | |
| BlockType * | data () |
| Access to blocks data as a raw pointer. | |
| BlockType & | diagonal (const Index row) |
| const BlockType & | diagonal (const Index row) const |
| template<typename Func > | |
| void | eachBlockOfRow (const Index row, Func func) const |
| Iterates over each block of a given row. Calls func( col, block ) | |
| template<typename Func > | |
| void | eachBlockOfCol (const Index col, Func func) const |
| Iterates over each block of a given col. Calls func( row, block ) | |
| template<bool DoTranspose, typename RhsT , typename ResT > | |
| void | rowMultiply (const Index row, const RhsT &rhs, ResT &res) const |
| Multiplication with a single row. | |
| template<bool DoTranspose, typename RhsT , typename ResT > | |
| void | colMultiply (const Index col, const RhsT &rhs, ResT &res) const |
| Multiplication with a single column. | |
| const Derived & | derived () const |
| Returns a const reference to the implementation. | |
| Derived & | derived () |
| Returns a reference to the implementation. | |
| Index | rowOffset (Index row) const |
| Returns an array containing the first index of a given row. | |
| Index | colOffset (Index col) const |
| Returns an array containing the first index of a given columns. | |
Setting and accessing the matrix structure | |
| void | setRows (const Index nBlocks, const unsigned *rowsPerBlock) |
| Defines the row structure of the matrix. More... | |
| void | setRows (const std::vector< unsigned > &rowsPerBlock) |
| Same, using a std::vector. | |
| void | setRows (const Index nBlocks, const Index rowsPerBlock) |
Same, setting each block to have exactly rowsPerBlock. | |
| void | setRows (const Index nBlocks) |
| Same, deducing the (constant) number of rows per block from the BlockType. | |
| void | setCols (const Index nBlocks, const unsigned *colsPerBlock) |
| Defines the column structure of the matrix. More... | |
| void | setCols (const std::vector< unsigned > &colsPerBlock) |
| Same, using a std::vector. | |
| void | setCols (const Index nBlocks, const Index colsPerBlock) |
Same, setting each block to have exactly rowsPerBlock. | |
| void | setCols (const Index nBlocks) |
| Same, deducing the (constant) number of rows per block from the BlockType. | |
| Index | rowsOfBlocks () const |
| Index | colsOfBlocks () const |
| Index | blockRows (Index row) const |
| Index | blockCols (Index col) const |
Inserting and accessing blocks | |
| void | reserve (std::size_t nBlocks) |
Reserve enouch memory to accomodate nBlocks. | |
| BlockType & | insertBack (Index row, Index col) |
| Inserts a block at the end of the matrix, and returns a reference to it. More... | |
| BlockType & | insertBackAndResize (Index row, Index col) |
| Convenience method that insertBack() a block and immediately resize it according to the dimensions given to setRows() and setCols() | |
| BlockType & | insert (Index row, Index col) |
| Insert a block anywhere in the matrix, and returns a reference to it. More... | |
| BlockType & | insertAndResize (Index row, Index col) |
| Convenience method that insert() a block and immediately resize it according to the dimensions given to setRows() and setCols() | |
| BlockType & | insertByOuterInner (Index outer, Index inner) |
| Insert a block, specifying directily the outer and inner indices instead of row and column. More... | |
| void | finalize () |
| void | clear () |
| Clears the matrix. | |
| MappedSparseBlockMatrix < BlockT, Flags, Index_ > & | setZero () |
|
MappedSparseBlockMatrix < BlockT, Flags, Index_ > & | setIdentity () |
| Calls set_identity() on each diagonal block, discard off-diagonal blocks. | |
|
MappedSparseBlockMatrix < BlockT, Flags, Index_ > & | setBlocksToZero () |
| Sets all allocated blocks to zero. Does not update index. | |
| std::size_t | nBlocks () const |
| Returns the number of (non-zero) blocks of the matrix. | |
| std::size_t | size () const |
| bool | empty () const |
| Returns whether the matrix is empty. | |
| const BlockType & | block (BlockPtr ptr) const |
| BlockType & | block (BlockPtr ptr) |
| BlockPtr | blockPtr (Index row, Index col) const |
| Return a BlockPtr to the block a (row, col) or InvalidBlockPtr if it does not exist. | |
| BlockPtr | diagonalBlockPtr (Index row) const |
| Return a BlockPtr to the block a (row, row) or InvalidBlockPtr if it does not exist. | |
| void | eachBlockOf (const Index outer, Func func) const |
| Iterates over each block of a given row or col. Calls func( inner, block ) | |
Accessing and manipulating indexes | |
| bool | computeMinorIndex () |
| Computes the minor index of the matrix. More... | |
| void | cacheTranspose () |
| Computes and caches the tranpose of the matrix. More... | |
| bool | transposeCached () const |
| Returns whether the transpose has been cached. | |
| InnerIterator | innerIterator (Index outer) const |
| Returns an InnerIterator to efficiently browse matrix. More... | |
| const MajorIndexType & | majorIndex () const |
| const MinorIndexType & | minorIndex () const |
| const TransposeIndexType & | transposeIndex () const |
| const ColIndexType & | colMajorIndex () const |
| const RowIndexType & | rowMajorIndex () const |
Unsafe API | |
| MajorIndexType & | majorIndex () |
| Direct access to major index. More... | |
| void | prealloc (std::size_t nBlocks) |
Resizes m_blocks. | |
| const TransposeArrayType & | transposeBlocks () const |
| Returns the blocks that have been created by cacheTranspose() | |
| const TransposeBlockType * | transposeData () const |
| Returns the blocks that have been created by cacheTranspose(), as a raw pointer. | |
| const Index * | rowOffsets () const |
| Returns an array containing the first index of each row. | |
| const Index * | colOffsets () const |
| Returns an array containing the first index of each column. | |
| const Lock & | lock () const |
| Reference to matrix private mutex. | |
Assignment and cloning operations | |
|
MappedSparseBlockMatrix < BlockT, Flags, Index_ > & | assign (const SparseBlockMatrixBase< OtherDerived > &source, const Scalar scale=1) |
| Performs ( *this = scale * source ) or ( *this = scale * source.transpose() ) | |
| void | cloneDimensions (const BlockMatrixBase< OtherDerived > &source) |
Clones the dimensions ( number of rows/cols blocks and rows/cols per block ) of source. | |
| void | cloneStructure (const SparseBlockMatrixBase< OtherDerived > &source) |
Clones the dimensions and the indexes of source. | |
| void | cloneIndex (const MajorIndexType &index) |
Linear algebra | |
| ConstTransposeReturnType | transpose () const |
| void | multiply (const RhsT &rhs, ResT &res, Scalar alpha=1, Scalar beta=0) const |
| void | splitRowMultiply (const Index row, const RhsT &rhs, ResT &res) const |
| void | rowMultiplyPrecompose (const Index row, const RhsT &rhs, ResT &res, const PreOp &op) const |
| void | colMultiplyPostcompose (const Index row, const RhsT &rhs, ResT &res, const PostOp &op) const |
| void | setFromProduct (const Product< LhsT, RhsT > &prod) |
|
MappedSparseBlockMatrix < BlockT, Flags, Index_ > & | scale (Scalar alpha) |
| Performs *this *= alpha. | |
|
MappedSparseBlockMatrix < BlockT, Flags, Index_ > & | add (const SparseBlockMatrixBase< OtherDerived > &rhs, Scalar alpha=1) |
| Performs *this += alpha * rhs (SAXPY) | |
|
MappedSparseBlockMatrix < BlockT, Flags, Index_ > & | operator*= (Scalar alpha) |
| Coeff-wise multiplication with a scalar. | |
|
MappedSparseBlockMatrix < BlockT, Flags, Index_ > & | operator/= (Scalar alpha) |
| Coeff-wise division with a scalar. | |
|
Scaling < MappedSparseBlockMatrix < BlockT, Flags, Index_ > > | operator- () const |
| Unary minus. | |
|
MappedSparseBlockMatrix < BlockT, Flags, Index_ > & | operator+= (const BlockObjectBase< OtherDerived > &source) |
| Adds another SparseBlockMatrixBase to this one. | |
|
MappedSparseBlockMatrix < BlockT, Flags, Index_ > & | operator-= (const BlockObjectBase< OtherDerived > &source) |
| Substracts another SparseBlockMatrixBase from this one. | |
I/O | |
| void | serialize (Archive &ar, const unsigned int file_version) |
Miscellaneous operations | |
| MappedSparseBlockMatrix < BlockT, Flags, Index_ > & | prune (const Scalar precision=0) |
Removes all blocks for which is_zero( block, precision ) is true. More... | |
| MappedSparseBlockMatrix < BlockT, Flags, Index_ > & | applyPermutation (const std::size_t *indices) |
| Sets *this = P * (*this) * P.transpose(). More... | |
Dimension-cloning construction methods | |
| CopyResultType | Zero () const |
| CopyResultType | Identity () const |
Static Public Attributes | |
| static const BlockPtr | InvalidBlockPtr |
| Return value of blockPtr( Index, Index ) for non-existing block. | |
Protected Types | |
| enum | |
|
typedef SparseBlockMatrixFinalizer < Traits::is_symmetric > | Finalizer |
Protected Member Functions | |
| void | computeMinorIndex (MinorIndexType &cmIndex) const |
| ColIndexType & | colMajorIndex () |
| RowIndexType & | rowMajorIndex () |
| TransposeBlockType * | transposeData () |
| BlockType & | allocateBlock (BlockPtr &ptr) |
Pushes a block at the back of m_blocks. | |
| const MinorIndexType & | getOrComputeMinorIndex (MinorIndexType &tempIndex) const |
| void | setInnerOffets (IndexT &index, const Index nBlocks, const unsigned *blockSizes) const |
Protected Attributes | |
| TransposeArrayType | m_transposeBlocks |
| MajorIndexType | m_majorIndex |
| MinorIndexType | m_minorIndex |
| TransposeIndexType | m_transposeIndex |
| Lock | m_lock |
| Index | m_rows |
| Index | m_cols |
| BlocksArrayType | m_blocks |
Mapped Sparse Block Matrix.
Allows bogus to operate on an external, immutable matrix using a compressed index ( ala MKL BSR – Block Sparse Row ) Only const (or caching) operations are available.
To obtain a valid MappedSparseBlockMatrix from a set of raw pointers, two operations are necessary 1 Set the size of each row and column of blocks using the setRows()/setCols() or cloneDimensions() methods 2 Map the block data and index using the mapTo() method
| BlockT | the type of the blocks of the matrix. Can be scalar, Eigen dense of sparse matrices, or basically anything provided a few functions are specialized |
| Flags | a combination of the values defined in bogus::flags |
| The | integer type used for indexing |
|
inherited |
Sets *this = P * (*this) * P.transpose().
P is build such that its non-zeros blocks are P( i, indices[i] ) = Id. This means that after a call to this this function, the block that was originally at (indices[i],indices[j]) will end up at (i, j).
|
inherited |
|
inherited |
|
inherited |
Computes and caches the tranpose of the matrix.
This will speed up some operations, especially splitRowMultiply() on symmetric matrices ( At a cost of doubling the memory storage, obviously )
|
inherited |
Clone an external index and allocate corresponding blocks. Rows and Cols dimensions should be set beforhand
|
inherited |
Computes the minor index of the matrix.
That is, the column major index for row-major matrices, and vice versa. This may speed up some operations, such as matrix/matrix multiplication under some circumstances.
|
inherited |
|
inherited |
|
inherited |
Finalizes the matrix.
|
inherited |
Returns an InnerIterator to efficiently browse matrix.
The iterator supports the pre-increment and casting-to-bool operations ot check fot its validity. The column (resp row.) can be accessed through the inner() method, and the block index through the ptr() method.
| outer | Index of the row (resp. column) of a row-major (resp. column-major) matrix on which to iterate |
|
inherited |
Insert a block anywhere in the matrix, and returns a reference to it.
|
inherited |
Inserts a block at the end of the matrix, and returns a reference to it.
|
inherited |
Insert a block, specifying directily the outer and inner indices instead of row and column.
| Ordered | If true, then we assume that the insertion is sequential and in stricly increasing order ( as defined in insertBack() ) |
|
inherited |
Direct access to major index.
Could be used in conjunction with prealloc() to devise a custom way of building the index. Dragons, etc.
| void bogus::MappedSparseBlockMatrix< BlockT, Flags, Index_ >::mapTo | ( | std::size_t | numberOfNonZeros, |
| const BlockT * | dataPtr, | ||
| const Index * | outerIndexPtr, | ||
| const Index * | innerIndexPtr | ||
| ) |
| numberOfNonZeros | Total number of blocks |
| dataPtr | Pointer to an array containing the blocks data |
| outerIndexPtr | A.k.a rowsIndex, pntrb, pntre-1 from BSR format |
| innerIndexPtr | A.k.a columns from BSR format |
|
inherited |
Removes all blocks for which is_zero( block, precision ) is true.
This function compacts the blocks and rebuild the index, which can be slow
|
inherited |
Defines the column structure of the matrix.
| nBlocks | the number of columns of blocks |
| colsPerBlock | array containing the number of columns of each block |
|
inherited |
Defines the row structure of the matrix.
| nBlocks | the number of rows of blocks |
| rowsPerBlock | array containing the number of row of each block |
|
inherited |