template<class T>
class gnsstk::SparseMatrix< T >
Class SparseMatrix. This class is designed to present an interface nearly identical to class Matrix, but more efficiently handle sparse matrices, in which most of the elements are zero. The class stores only non-zero elements; using a map of SparseVectors, with key = row index. it also stores a nominal dimension - number of rows and columns. The class uses a proxy class, SMatProxy, to access elements; this allows rvalues and lvalues to be treated separately. Notes on speed. The most expensive parts are the Proxy::operator(), then find() and lower_bound(). Never use the Proxy stuff within the class, always use iterators and assign values to the maps directly. Never assign zeros to the maps. See timing and test results in the test program smtest.cpp Matrix multiply is orders of magnitude faster. Transpose() is much faster than the Matrix version, which is something of a surprise. Most time consuming is looping over columns; this is expected since the design stores by row. The trick is to re-write the algorithm in terms of the transpose of the column-loop matrix, and then apply a transpose(), which is cheap, either before starting (when col-loop matrix is input) or after returning (output). Then the loops become loops over rows. NB. never store zeros in the map, particularly when you are creating the matrix and using it at the same time, as in inverseLT().
Definition at line 53 of file SparseMatrix.hpp.
|
void | clear () |
| clear - set all data to 0 (i.e. remove all data); leave dimensions alone More...
|
|
SparseVector< T > | colCopy (const unsigned int j) const |
| return col j of this SparseMatrix as a SparseVector More...
|
|
unsigned int | cols () const |
| get number of columns - of the real Matrix, not the data array More...
|
|
unsigned int | datasize () const |
| datasize - number of non-zero data More...
|
|
double | density () const |
| density - ratio of number of non-zero element to size() More...
|
|
SparseVector< T > | diagCopy () const |
| return diagonal of this SparseMatrix as a SparseVector More...
|
|
std::string | dump (const int p=3, bool dosci=false) const |
| Dump only non-zero values, with indexes (i,value) More...
|
|
void | flatten (std::vector< unsigned int > &rows, std::vector< unsigned int > &cols, std::vector< T > &values) const |
| Convert to "dump-able" form : 3 parallel vectors; rows, cols, values. More...
|
|
bool | isEmpty () const |
| is this SM empty? NB may have to call zeroize() to get a yes. More...
|
|
bool | isFilled (const unsigned int i, const unsigned int j) |
| true if the element (i,j) is non-zero More...
|
|
| operator Matrix< T > () const |
| cast to Matrix or implicit conversion to Matrix<T> More...
|
|
SMatProxy< T > | operator() (unsigned int i, unsigned int j) |
| operator() for non-const, but SMatProxy does all the work More...
|
|
const SMatProxy< T > | operator() (unsigned int i, unsigned int j) const |
| operator() for const, but SMatProxy does all the work More...
|
|
SparseMatrix< T > & | operator*= (const T &value) |
| Multiply all elements by a scalar T constant. More...
|
|
SparseMatrix< T > & | operator+= (const Matrix< T > &SM) |
| Matrix addition: SparseMatrix += Matrix. More...
|
|
SparseMatrix< T > & | operator+= (const SparseMatrix< T > &SM) |
| Matrix addition: SparseMatrix += SparseMatrix. More...
|
|
SparseMatrix< T > | operator- () const |
|
SparseMatrix< T > & | operator-= (const Matrix< T > &SM) |
| Matrix subtraction: SparseMatrix -= Matrix. More...
|
|
SparseMatrix< T > & | operator-= (const SparseMatrix< T > &SM) |
| Minimum element - return 0 if empty. More...
|
|
SparseMatrix< T > & | operator/= (const T &value) |
|
void | resize (const unsigned int newrows, const unsigned int newcols) |
| resize - only changes len and removes elements if necessary More...
|
|
SparseVector< T > | rowCopy (const unsigned int i) const |
| return row i of this SparseMatrix as a SparseVector More...
|
|
unsigned int | rows () const |
| get number of rows - of the real Matrix, not the data array More...
|
|
unsigned int | size () const |
| size of matrix = rows()*cols() More...
|
|
| SparseMatrix () |
| empty constructor More...
|
|
| SparseMatrix (const Matrix< T > &M) |
| constructor from regular Matrix<T> More...
|
|
| SparseMatrix (const SparseMatrix< T > &SM, const unsigned int &rind, const unsigned int &cind, const unsigned int &rnum, const unsigned int &cnum) |
|
| SparseMatrix (unsigned int r, unsigned int c) |
| constructor with dimensions More...
|
|
void | swapCols (const unsigned int ii, const unsigned int jj) |
| swap columns of this SparseMatrix More...
|
|
void | swapRows (const unsigned int &ii, const unsigned int &jj) |
| swap rows of this SparseMatrix More...
|
|
void | zeroize (const T tol=static_cast< T >(SparseVector< T >::zeroTolerance)) |
| zeroize - remove elements that are less than tolerance in abs value More...
|
|
|
SparseMatrix< T > | identSparse (const unsigned int dim) |
|
SparseMatrix< T > | inverse (const SparseMatrix< T > &A) |
|
SparseMatrix< T > | inverseLT (const SparseMatrix< T > <, T *ptrSmall, T *ptrBig) |
| Compute inverse of lower-triangular SparseMatrix. More...
|
|
SparseMatrix< T > | inverseViaCholesky (const SparseMatrix< T > &A) |
|
SparseMatrix< T > | lowerCholesky (const SparseMatrix< T > &A) |
|
SparseMatrix< T > | matrixTimesTranspose (const SparseMatrix< T > &M) |
|
T | max (const SparseMatrix< T > &SM) |
| Maximum element - return 0 if empty. More...
|
|
T | maxabs (const SparseMatrix< T > &SM) |
| Maximum absolute value - return 0 if empty. More...
|
|
T | min (const SparseMatrix< T > &SM) |
| Maximum element - return 0 if empty. More...
|
|
T | minabs (const SparseMatrix< T > &SM) |
| Minimum absolute value - return 0 if empty. More...
|
|
std::ostream & | operator (std::ostream &os, const SparseMatrix< T > &S) |
|
SparseMatrix< T > | operator* (const Matrix< T > &L, const SparseMatrix< T > &R) |
| Matrix multiply: SparseMatrix = Matrix * SparseMatrix. More...
|
|
SparseVector< T > | operator* (const Matrix< T > &L, const SparseVector< T > &V) |
| Matrix,Vector multiply: SparseVector = Matrix * SparseVector. More...
|
|
SparseMatrix< T > | operator* (const SparseMatrix< T > &L, const Matrix< T > &R) |
| Matrix multiply: SparseMatrix = SparseMatrix * Matrix. More...
|
|
SparseMatrix< T > | operator* (const SparseMatrix< T > &L, const SparseMatrix< T > &R) |
| Matrix multiply: SparseMatrix = SparseMatrix * SparseMatrix. More...
|
|
SparseMatrix< T > | operator* (const SparseMatrix< T > &L, const SparseMatrix< T > &R) |
| Matrix multiply: SparseMatrix = SparseMatrix * SparseMatrix. More...
|
|
SparseVector< T > | operator* (const SparseMatrix< T > &L, const SparseVector< T > &V) |
| Matrix,Vector multiply: SparseVector = SparseMatrix * SparseVector. More...
|
|
SparseVector< T > | operator* (const SparseMatrix< T > &L, const Vector< T > &V) |
| Matrix,Vector multiply: SparseVector = SparseMatrix * Vector. More...
|
|
SparseVector< T > | operator* (const SparseVector< T > &V, const Matrix< T > &R) |
| Vector,Matrix multiply: SparseVector = SparseVector * Matrix. More...
|
|
SparseVector< T > | operator* (const SparseVector< T > &V, const SparseMatrix< T > &R) |
| Vector,Matrix multiply: SparseVector = SparseVector * SparseMatrix. More...
|
|
SparseVector< T > | operator* (const Vector< T > &V, const SparseMatrix< T > &R) |
| Vector,Matrix multiply: SparseVector = Vector * SparseMatrix. More...
|
|
SparseMatrix< T > | operator+ (const Matrix< T > &L, const SparseMatrix< T > &R) |
|
SparseMatrix< T > | operator+ (const SparseMatrix< T > &L, const Matrix< T > &R) |
| Matrix addition: SparseMatrix = SparseMatrix + Matrix : copy, += M. More...
|
|
SparseMatrix< T > | operator+ (const SparseMatrix< T > &L, const SparseMatrix< T > &R) |
| Matrix addition: SparseMatrix = SparseMatrix + SparseMatrix : copy, += SM. More...
|
|
SparseMatrix< T > | operator- (const Matrix< T > &L, const SparseMatrix< T > &R) |
| Matrix subtraction: SparseMatrix = Matrix - SparseMatrix. More...
|
|
SparseMatrix< T > | operator- (const SparseMatrix< T > &L, const Matrix< T > &R) |
| Matrix subtraction: SparseMatrix = SparseMatrix - Matrix. More...
|
|
SparseMatrix< T > | operator- (const SparseMatrix< T > &L, const SparseMatrix< T > &R) |
| Matrix subtraction: SparseMatrix = SparseMatrix - SparseMatrix. More...
|
|
SparseMatrix< T > | operator|| (const SparseMatrix< T > &L, const SparseMatrix< T > &R) |
|
SparseMatrix< T > | operator|| (const SparseMatrix< T > &L, const Vector< T > &V) |
| Concatenation SparseMatrix || Vector TD the rest of them... More...
|
|
class | SMatProxy< T > |
| Proxy needs access to rowsMap. More...
|
|
SparseMatrix< T > | SparseHouseholder (const SparseMatrix< T > &A) |
| Householder transformation of a matrix. More...
|
|
void | SrifMU (Matrix< T > &R, Vector< T > &Z, SparseMatrix< T > &A, const unsigned int M) |
|
void | SrifMU (Matrix< T > &R, Vector< T > &Z, SparseMatrix< T > &P, Vector< T > &D, const unsigned int M) |
|
Vector< T > | transformDiag (const SparseMatrix< T > &P, const Matrix< T > &C) |
| Compute diagonal of P*C*P^T, ie diagonal of transform of square Matrix C. More...
|
|
SparseMatrix< T > | transpose (const SparseMatrix< T > &M) |
| transpose More...
|
|
SparseMatrix< T > | transposeTimesMatrix (const SparseMatrix< T > &M) |
|
SparseMatrix< T > | upperCholesky (const SparseMatrix< T > &A) |
|