#include <sparse_matrix.h>
Public Types | |
| typedef Vector< C >::size_type | size_type |
Public Member Functions | |
| SparseMatrix (const size_type n=1) | |
| SparseMatrix (const SparseMatrix< C > &M) | |
| SparseMatrix (const size_type row_dimension, const size_type column_dimension) | |
| ~SparseMatrix () | |
| MatrixBlock< C > * | clone () const |
| clone the sparse matrix (requirement from MatrixBlock) | |
| MatrixBlock< C > * | clone_transposed () const |
| transpose the sparse matrix (requirement from MatrixBlock) | |
| const size_type | row_dimension () const |
| const size_type | column_dimension () const |
| const size_type | size () const |
| bool | empty () const |
| void | resize (const size_type rows, const size_type columns) |
| const size_type | entries_in_row (const size_type row) const |
| const size_type | get_nth_index (const size_type row, const size_type n) const |
| const C | get_nth_entry (const size_type row, const size_type n) const |
| const C | get_entry (const size_type row, const size_type column) const |
| template<class MATRIX > | |
| void | get_block (const size_type firstrow, const size_type firstcolumn, const size_type rows, const size_type columns, MATRIX &M) const |
| void | get_row (const size_type row, InfiniteVector< C, size_type > &v, const size_type offset=0) const |
| void | set_entry (const size_type row, const size_type column, const C value) |
| void | set_row (const size_type row, const std::list< size_type > &indices, const std::list< C > &entries) |
| template<class MATRIX > | |
| void | set_block (const size_type firstrow, const size_type firstcolumn, const MATRIX &M, const bool reflect=false, const double factor=1.0) |
| SparseMatrix< C > & | operator= (const SparseMatrix< C > &M) |
| void | scale (const C s) |
| void | add (const C s, const SparseMatrix< C > &M) |
| void | diagonal (const size_type n, const C diag) |
| template<class VECTOR > | |
| void | apply (const VECTOR &x, VECTOR &Mx) const |
| void | apply (const Vector< C > &x, Vector< C > &Mx) const |
| special version for Vector<C> (requirement from MatrixBlock) | |
| template<class VECTOR > | |
| void | apply_transposed (const VECTOR &x, VECTOR &Mtx) const |
| void | apply_transposed (const Vector< C > &x, Vector< C > &Mtx) const |
| special version for Vector<C> (requirement from MatrixBlock) | |
| void | compress (const double eta=1e-16) |
| void | print (std::ostream &os, const unsigned int tabwidth=8, const unsigned int precision=3) const |
| void | matlab_output (const char *file, const char *Matrixname, const int binary, const int rowend=-1, const int columnend=-1) const |
| void | matlab_output (const char *file, const char *Matrixname, const int binary, const int rowstart, const int rowend, const int columnstart, const int columnend) const |
| void | matlab_input (const char *file) |
Protected Member Functions | |
| void | kill () |
Protected Attributes | |
| C ** | entries_ |
| size_type ** | indices_ |
| size_type | rowdim_ |
| size_type | coldim_ |
This class models finite, sparsely populated matrices M = (m_{i,j})_{0<=i<m, 0<=j<n} with entries from an arbitrary (scalar) class C, designed for numerical computations. The internal representation is CRS (compressed row storage), see [N].
Reference: [N] http://www.netlib.org/linalg/html_templates/node91.html
| typedef Vector<C>::size_type MathTL::SparseMatrix< C >::size_type |
type of indexes and size type (cf. STL containers)
Reimplemented from MathTL::MatrixBlock< C >.
| MathTL::SparseMatrix< C >::SparseMatrix | ( | const size_type | n = 1 | ) | [explicit] |
default constructor, yields zero square matrix
| MathTL::SparseMatrix< C >::SparseMatrix | ( | const SparseMatrix< C > & | M | ) |
copy constructor
| MathTL::SparseMatrix< C >::SparseMatrix | ( | const size_type | row_dimension, |
| const size_type | column_dimension | ||
| ) |
construct m*n rectangular zero matrix
| MathTL::SparseMatrix< C >::~SparseMatrix | ( | ) |
destructor
| void MathTL::SparseMatrix< C >::add | ( | const C | s, |
| const SparseMatrix< C > & | M | ||
| ) |
in place summation *this += s*M
| void MathTL::SparseMatrix< C >::apply | ( | const VECTOR & | x, |
| VECTOR & | Mx | ||
| ) | const |
matrix-vector multiplication Mx = (*this) * x; we assume that the vector Mx has the correct size and is not identical to x
| void MathTL::SparseMatrix< C >::apply_transposed | ( | const VECTOR & | x, |
| VECTOR & | Mtx | ||
| ) | const |
transposed matrix-vector multiplication Mtx = (*this)^T * x; we assume that the vector Mtx has the correct size and is not identical to x
| const SparseMatrix< C >::size_type MathTL::SparseMatrix< C >::column_dimension | ( | ) | const [inline, virtual] |
column dimension
Implements MathTL::MatrixBlock< C >.
| void MathTL::SparseMatrix< C >::compress | ( | const double | eta = 1e-16 | ) |
set all values with modulus below a threshold to zero (fabs<C> should exist)
| void MathTL::SparseMatrix< C >::diagonal | ( | const size_type | n, |
| const C | diag | ||
| ) |
yields an n-by-n diagonal matrix
| bool MathTL::SparseMatrix< C >::empty | ( | ) | const [inline] |
return true if matrix is empty (cf. STL containers)
| const SparseMatrix< C >::size_type MathTL::SparseMatrix< C >::entries_in_row | ( | const size_type | row | ) | const [inline] |
number of nonzero entries a given row
| void MathTL::SparseMatrix< C >::get_block | ( | const size_type | firstrow, |
| const size_type | firstcolumn, | ||
| const size_type | rows, | ||
| const size_type | columns, | ||
| MATRIX & | M | ||
| ) | const |
read access to a subblock
| const C MathTL::SparseMatrix< C >::get_entry | ( | const size_type | row, |
| const size_type | column | ||
| ) | const |
read-only access to a single matrix entry
| const C MathTL::SparseMatrix< C >::get_nth_entry | ( | const size_type | row, |
| const size_type | n | ||
| ) | const [inline] |
read access to the n-th nontrivial element in a given row
| const SparseMatrix< C >::size_type MathTL::SparseMatrix< C >::get_nth_index | ( | const size_type | row, |
| const size_type | n | ||
| ) | const [inline] |
read access to the column index of the n-th nontrivial element in a given row
| void MathTL::SparseMatrix< C >::get_row | ( | const size_type | row, |
| InfiniteVector< C, size_type > & | v, | ||
| const size_type | offset = 0 |
||
| ) | const |
read access to an entire row; offset leads to a shift of v (with respect to the original column indices)
| void MathTL::SparseMatrix< C >::kill | ( | ) | [protected] |
deallocate all memory
| void MathTL::SparseMatrix< C >::matlab_input | ( | const char * | file | ) |
read from matlab sparse matrix format (in binary==1 format)
| void MathTL::SparseMatrix< C >::matlab_output | ( | const char * | file, |
| const char * | Matrixname, | ||
| const int | binary, | ||
| const int | rowend = -1, |
||
| const int | columnend = -1 |
||
| ) | const |
write matlab sparse matrix format row/column numbering starts at 0, thus the highest possible value is row/column_dimension()-1
row/columnstart = number of first row/column to be saved row/columnend = number of last row/column to be saved caution: size of original matrix is not stored, so storing a mxn matrix and then loading it will result in a mxn matrix, NOT in a kxl matrix where only a mxn part is filled
| SparseMatrix< C > & MathTL::SparseMatrix< C >::operator= | ( | const SparseMatrix< C > & | M | ) |
assignment from another sparse matrix
| void MathTL::SparseMatrix< C >::print | ( | std::ostream & | os, |
| const unsigned int | tabwidth = 8, |
||
| const unsigned int | precision = 3 |
||
| ) | const [virtual] |
stream output with user-defined tabwidth and precision (cf. deal.II)
Implements MathTL::MatrixBlock< C >.
| void MathTL::SparseMatrix< C >::resize | ( | const size_type | rows, |
| const size_type | columns | ||
| ) |
resize matrix and initialize with zero
| const SparseMatrix< C >::size_type MathTL::SparseMatrix< C >::row_dimension | ( | ) | const [inline, virtual] |
row dimension
Implements MathTL::MatrixBlock< C >.
| void MathTL::SparseMatrix< C >::scale | ( | const C | s | ) |
in place scaling *this *= s
| void MathTL::SparseMatrix< C >::set_block | ( | const size_type | firstrow, |
| const size_type | firstcolumn, | ||
| const MATRIX & | M, | ||
| const bool | reflect = false, |
||
| const double | factor = 1.0 |
||
| ) |
write access to a subblock; if the "reflect" flag is set, rows and columns of the block are reflected before writing
| void MathTL::SparseMatrix< C >::set_entry | ( | const size_type | row, |
| const size_type | column, | ||
| const C | value | ||
| ) |
write access to a matrix entry
| void MathTL::SparseMatrix< C >::set_row | ( | const size_type | row, |
| const std::list< size_type > & | indices, | ||
| const std::list< C > & | entries | ||
| ) |
write access to a complete row (this std::list version is especially suitable for situations where the nonzero pattern is not a priorily known)
| const SparseMatrix< C >::size_type MathTL::SparseMatrix< C >::size | ( | ) | const |
size as an STL-compatible container for matrix entries, number of nonzero entries
size_type MathTL::SparseMatrix< C >::coldim_ [protected] |
column dimension
C** MathTL::SparseMatrix< C >::entries_ [protected] |
storage for the matrix entries, entries_[r] contains the elements in row r
size_type** MathTL::SparseMatrix< C >::indices_ [protected] |
storage for the indices of nontrivial entries, indices_[r] contains the nonzero indices in row r, where indices_[r][0] is the number of indices k indices_[r][1],...,indices_[r][k] are the indices themselves
size_type MathTL::SparseMatrix< C >::rowdim_ [protected] |
row dimension
1.7.6.1