NDEVR
API Documentation
sparse_block_matrix.h
1#pragma once
2#include "DLLInfo.h"
3#include "Base/Headers/Buffer.hpp"
4#include "Base/Headers/Dictionary.h"
5#include <Eigen/Core>
6
7#include "sparse_block_matrix_ccs.h"
8#include "matrix_structure.h"
9#include "matrix_operations.h"
10#include <map>
11namespace NDEVR
12{
13 using namespace Eigen;
30 template <class MatrixType = MatrixX<g_type>>
32
33 public:
35 typedef MatrixType SparseMatrixBlock;
36
38 inline int cols() const { return _colBlockIndices.size() ? _colBlockIndices.last() : 0; }
40 inline int rows() const { return _rowBlockIndices.size() ? _rowBlockIndices.last() : 0; }
41
42 typedef std::map<int, SparseMatrixBlock> IntBlockMap;
43
55 SparseBlockMatrix(const int* rbi, const int* cbi, int rb, int cb, bool hasStorage = true);
56
58
60
61
63 void clear(bool dealloc = false);
64
66 SparseMatrixBlock* block(int r, int c, bool alloc = false);
68 const SparseMatrixBlock* block(int r, int c) const;
69
71 inline int rowsOfBlock(int r) const { return r ? _rowBlockIndices[r] - _rowBlockIndices[r - 1] : _rowBlockIndices[0]; }
72
74 inline int colsOfBlock(int c) const { return c ? _colBlockIndices[c] - _colBlockIndices[c - 1] : _colBlockIndices[0]; }
75
77 inline int rowBaseOfBlock(int r) const { return r ? _rowBlockIndices[r - 1] : 0; }
78
80 inline int colBaseOfBlock(int c) const { return c ? _colBlockIndices[c - 1] : 0; }
81
86
87
96 SparseBlockMatrix* slice(int rmin, int rmax, int cmin, int cmax, bool alloc = true) const;
97
99 template <class MatrixTransposedType>
101
104
106 template <class MatrixResultType, class MatrixFactorType>
108
110 void multiply(g_type*& dest, const g_type* src) const;
111
116 void multiplySymmetricUpperTriangle(g_type*& dest, const g_type* src) const;
117
119 void rightMultiply(g_type*& dest, const g_type* src) const;
120
122 void scale(g_type a);
123
128 bool symmPermutation(SparseBlockMatrix<MatrixType>*& dest, const int* pinv, bool onlyUpper = false) const;
129
133 int fillCCS(int* Cp, int* Ci, g_type* Cx, bool upperTriangle = false) const;
134
139 int fillCCS(g_type* Cx, bool upperTriangle = false) const;
140
143
145 const Buffer<IntBlockMap>& blockCols() const { return _blockCols; }
147
151
155
161
167
173
174 protected:
179 Buffer <IntBlockMap> _blockCols;
181 public:
182 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
183 };
184}
185#include "sparse_block_matrix.hpp"
The equivelent of std::vector but with a bit more control.
Definition Buffer.hpp:58
representing the structure of a matrix in column compressed structure (only the upper triangular part...
Sparse matrix which uses blocks.
Sparse matrix which uses blocks based on hash structures.
const Buffer< int > & rowBlockIndices() const
indices of the row blocks
void multiply(g_type *&dest, const g_type *src) const
dest = (*this) * src
void scale(g_type a)
*this *= a
int cols() const
columns of the matrix
int fillSparseBlockMatrixCCS(SparseBlockMatrixCCS< MatrixType > &blockCCS) const
copy into CCS structure
bool symmPermutation(SparseBlockMatrix< MatrixType > *&dest, const int *pinv, bool onlyUpper=false) const
writes in dest a block permutaton specified by pinv.
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
SparseBlockMatrix * slice(int rmin, int rmax, int cmin, int cmax, bool alloc=true) const
returns a view or a copy of the block matrix
const Buffer< IntBlockMap > & blockCols() const
the block matrices per block-column
int rows() const
rows of the matrix
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 t...
bool add(SparseBlockMatrix< MatrixType > &dest) const
adds the current matrix to the destination
int fillCCS(g_type *Cx, bool upperTriangle=false) const
fill the CCS arrays of a matrix, arrays have to be allocated beforehand.
SparseMatrixBlock * block(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
uint04 nonZeroBlocks() const
number of allocated blocks
void fillBlockStructure(MatrixStructure &ms) const
exports the non zero blocks in the structure matrix ms
bool multiply(SparseBlockMatrix< MatrixResultType > *&dest, const SparseBlockMatrix< MatrixFactorType > *M) const
dest = (*this) * M
void rightMultiply(g_type *&dest, const g_type *src) const
dest = M * (*this)
const Buffer< int > & colBlockIndices() const
indices of the column blocks
void takePatternFromHash(SparseBlockMatrixHashMap< MatrixType > &hashMatrix)
take over the memory and matrix pattern from a hash matrix.
uint04 nonZeros() const
number of non-zero elements
int rowsOfBlock(int r) const
how many rows does the block at block-row r has?
int fillSparseBlockMatrixCCSTransposed(SparseBlockMatrixCCS< MatrixType > &blockCCS) const
copy as transposed into a CCS structure
bool transpose(SparseBlockMatrix< MatrixTransposedType > *&dest) const
transposes a block matrix, The transposed type should match the argument false on failure
SparseBlockMatrix(const int *rbi, const int *cbi, int rb, int cb, bool hasStorage=true)
constructs a sparse block matrix having a specific layout
int rowBaseOfBlock(int r) const
where does the row at block-row r starts?
const SparseMatrixBlock * block(int r, int c) const
returns the block at location r,c
void clear(bool dealloc=false)
this zeroes all the blocks. If dealloc=true the blocks are removed from memory
int colsOfBlock(int c) const
how many cols does the block at block-col c has?
int colBaseOfBlock(int c) const
where does the col at block-col r starts?
Internal helper functions for block-wise matrix-vector products (axpy and atxpy).
The primary namespace for the NDEVR SDK.
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...