So-Bogus
A c++ sparse block matrix library aimed at Second Order cone problems
|
Base class for SparseBlockMatrix. More...
#include <SparseBlockMatrixBase.hpp>
Classes | |
struct | MutableImpl |
struct | MutableImpl< OtherBlockType, false, false > |
struct | MutableImpl< OtherBlockType, false, true > |
struct | MutableImpl< OtherBlockType, true, true > |
Public Types | |
typedef BlockMatrixBase< Derived > | Base |
typedef BlockMatrixTraits < Derived > | Traits |
typedef Traits::BlockPtr | BlockPtr |
typedef Base::Index | Index |
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 | |
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() | |
template<bool Ordered> | |
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. | |
Derived & | setZero () |
Derived & | setIdentity () |
Calls set_identity() on each diagonal block, discard off-diagonal blocks. | |
Derived & | 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. | |
template<bool ColWise, typename Func > | |
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 |
Assignment and cloning operations | |
template<bool Transpose, typename OtherDerived > | |
Derived & | assign (const SparseBlockMatrixBase< OtherDerived > &source, const Scalar scale=1) |
Performs ( *this = scale * source ) or ( *this = scale * source.transpose() ) | |
template<typename OtherDerived > | |
Derived & | operator= (const BlockObjectBase< OtherDerived > &source) |
Derived & | operator= (const SparseBlockMatrixBase &source) |
template<typename LhsT , typename RhsT > | |
Derived & | operator= (const Product< LhsT, RhsT > &prod) |
template<typename LhsT , typename RhsT > | |
Derived & | operator= (const Addition< LhsT, RhsT > &add) |
template<typename Expression > | |
Derived & | operator= (const NarySum< Expression > &sum) |
template<typename OtherDerived > | |
Derived & | operator= (const Scaling< OtherDerived > &scaling) |
template<typename OtherDerived > | |
void | cloneDimensions (const BlockMatrixBase< OtherDerived > &source) |
Clones the dimensions ( number of rows/cols blocks and rows/cols per block ) of source . | |
template<typename OtherDerived > | |
void | cloneStructure (const SparseBlockMatrixBase< OtherDerived > &source) |
Clones the dimensions and the indexes of source . | |
void | cloneIndex (const MajorIndexType &index) |
Linear algebra | |
ConstTransposeReturnType | transpose () const |
template<bool Transpose, typename RhsT , typename ResT > | |
void | multiply (const RhsT &rhs, ResT &res, Scalar alpha=1, Scalar beta=0) const |
template<typename RhsT , typename ResT > | |
void | splitRowMultiply (const Index row, const RhsT &rhs, ResT &res) const |
template<bool DoTranspose, typename RhsT , typename ResT , typename PreOp > | |
void | rowMultiplyPrecompose (const Index row, const RhsT &rhs, ResT &res, const PreOp &op) const |
template<bool DoTranspose, typename RhsT , typename ResT , typename PostOp > | |
void | colMultiplyPostcompose (const Index row, const RhsT &rhs, ResT &res, const PostOp &op) const |
template<bool ColWise, typename LhsT , typename RhsT > | |
void | setFromProduct (const Product< LhsT, RhsT > &prod) |
Derived & | scale (Scalar alpha) |
Performs *this *= alpha. | |
template<bool Transpose, typename OtherDerived > | |
Derived & | add (const SparseBlockMatrixBase< OtherDerived > &rhs, Scalar alpha=1) |
Performs *this += alpha * rhs (SAXPY) | |
Derived & | operator*= (Scalar alpha) |
Coeff-wise multiplication with a scalar. | |
Derived & | operator/= (Scalar alpha) |
Coeff-wise division with a scalar. | |
Scaling< Derived > | operator- () const |
Unary minus. | |
template<typename OtherDerived > | |
Derived & | operator+= (const BlockObjectBase< OtherDerived > &source) |
Adds another SparseBlockMatrixBase to this one. | |
template<typename OtherDerived > | |
Derived & | operator-= (const BlockObjectBase< OtherDerived > &source) |
Substracts another SparseBlockMatrixBase from this one. | |
I/O | |
template<typename Archive > | |
void | serialize (Archive &ar, const unsigned int file_version) |
Miscellaneous operations | |
Derived & | prune (const Scalar precision=0) |
Removes all blocks for which is_zero ( block , precision ) is true . More... | |
Derived & | applyPermutation (const std::size_t *indices) |
Sets *this = P * (*this) * P.transpose(). More... | |
Dimension-cloning construction methods | |
CopyResultType | Zero () const |
CopyResultType | Identity () 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. | |
Static Public Attributes | |
static const BlockPtr | InvalidBlockPtr |
Return value of blockPtr( Index, Index ) for non-existing block. | |
Protected Types | |
enum | { is_bsr_compatible } |
typedef SparseBlockMatrixFinalizer < Traits::is_symmetric > | Finalizer |
Protected Member Functions | |
template<bool EnforceThreadSafety> | |
BlockType & | allocateBlock (BlockPtr &ptr) |
Pushes a block at the back of m_blocks . | |
void | computeMinorIndex (MinorIndexType &cmIndex) const |
const MinorIndexType & | getOrComputeMinorIndex (MinorIndexType &tempIndex) const |
ColIndexType & | colMajorIndex () |
RowIndexType & | rowMajorIndex () |
template<typename IndexT > | |
void | setInnerOffets (IndexT &index, const Index nBlocks, const unsigned *blockSizes) const |
TransposeBlockType * | transposeData () |
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 |
Friends | |
struct | SparseBlockIndexGetter< Derived, true > |
struct | SparseBlockIndexGetter< Derived, false > |
Base class for SparseBlockMatrix.
Most of the useful functions are defined and implemented here, but instantiation should be done throught derived classes such as SparseBlockMatrix
struct bogus::SparseBlockMatrixBase::MutableImpl |
Class Members | ||
---|---|---|
typedef SparseBlockMatrix < OtherBlockType, flags &~UNCOMPRESSED > |
Type |
struct bogus::SparseBlockMatrixBase::MutableImpl< OtherBlockType, false, false > |
Class Members | ||
---|---|---|
typedef SparseBlockMatrix < OtherBlockType, flags &~UNCOMPRESSED &~SYMMETRIC > |
Type |
struct bogus::SparseBlockMatrixBase::MutableImpl< OtherBlockType, false, true > |
Class Members | ||
---|---|---|
typedef SparseBlockMatrix < OtherBlockType,(flags &~UNCOMPRESSED &~SYMMETRIC &~COL_MAJOR)|((~flags)&COL_MAJOR) > |
Type |
struct bogus::SparseBlockMatrixBase::MutableImpl< OtherBlockType, true, true > |
Class Members | ||
---|---|---|
typedef SparseBlockMatrix < OtherBlockType,(flags &~UNCOMPRESSED &~COL_MAJOR)|((~flags)&COL_MAJOR) > |
Type |
Derived& bogus::SparseBlockMatrixBase< Derived >::applyPermutation | ( | const std::size_t * | indices | ) |
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 |
void bogus::SparseBlockMatrixBase< Derived >::cacheTranspose | ( | ) |
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 )
void bogus::SparseBlockMatrixBase< Derived >::cloneIndex | ( | const MajorIndexType & | index | ) |
Clone an external index and allocate corresponding blocks. Rows and Cols dimensions should be set beforhand
bool bogus::SparseBlockMatrixBase< Derived >::computeMinorIndex | ( | ) |
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 |
void bogus::SparseBlockMatrixBase< Derived >::finalize | ( | ) |
Finalizes the matrix.
InnerIterator bogus::SparseBlockMatrixBase< Derived >::innerIterator | ( | Index | outer | ) | const |
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 |
BlockType& bogus::SparseBlockMatrixBase< Derived >::insert | ( | Index | row, |
Index | col | ||
) |
Insert a block anywhere in the matrix, and returns a reference to it.
BlockType& bogus::SparseBlockMatrixBase< Derived >::insertBack | ( | Index | row, |
Index | col | ||
) |
Inserts a block at the end of the matrix, and returns a reference to it.
BlockType& bogus::SparseBlockMatrixBase< Derived >::insertByOuterInner | ( | Index | outer, |
Index | inner | ||
) |
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() ) |
MajorIndexType& bogus::SparseBlockMatrixBase< Derived >::majorIndex | ( | ) |
Direct access to major index.
Could be used in conjunction with prealloc() to devise a custom way of building the index. Dragons, etc.
Derived& bogus::SparseBlockMatrixBase< Derived >::prune | ( | const Scalar | precision = 0 | ) |
Removes all blocks for which is_zero
( block
, precision
) is true
.
This function compacts the blocks and rebuild the index, which can be slow
void bogus::SparseBlockMatrixBase< Derived >::setCols | ( | const Index | nBlocks, |
const unsigned * | colsPerBlock | ||
) |
Defines the column structure of the matrix.
nBlocks | the number of columns of blocks |
colsPerBlock | array containing the number of columns of each block |
void bogus::SparseBlockMatrixBase< Derived >::setRows | ( | const Index | nBlocks, |
const unsigned * | rowsPerBlock | ||
) |
Defines the row structure of the matrix.
nBlocks | the number of rows of blocks |
rowsPerBlock | array containing the number of row of each block |
Derived& bogus::SparseBlockMatrixBase< Derived >::setZero | ( | ) |