MathTL
 All Classes Functions Variables Typedefs Enumerations
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes
MathTL::SparseMatrix< C > Class Template Reference

#include <sparse_matrix.h>

Inheritance diagram for MathTL::SparseMatrix< C >:
MathTL::MatrixBlock< C >

List of all members.

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_

Detailed Description

template<class C>
class MathTL::SparseMatrix< C >

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


Member Typedef Documentation

template<class C>
typedef Vector<C>::size_type MathTL::SparseMatrix< C >::size_type

type of indexes and size type (cf. STL containers)

Reimplemented from MathTL::MatrixBlock< C >.


Constructor & Destructor Documentation

template<class C >
MathTL::SparseMatrix< C >::SparseMatrix ( const size_type  n = 1) [explicit]

default constructor, yields zero square matrix

template<class C>
MathTL::SparseMatrix< C >::SparseMatrix ( const SparseMatrix< C > &  M)

copy constructor

template<class C>
MathTL::SparseMatrix< C >::SparseMatrix ( const size_type  row_dimension,
const size_type  column_dimension 
)

construct m*n rectangular zero matrix

template<class C >
MathTL::SparseMatrix< C >::~SparseMatrix ( )

destructor


Member Function Documentation

template<class C>
void MathTL::SparseMatrix< C >::add ( const C  s,
const SparseMatrix< C > &  M 
)

in place summation *this += s*M

template<class C >
template<class VECTOR >
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

template<class C >
template<class VECTOR >
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

template<class C >
const SparseMatrix< C >::size_type MathTL::SparseMatrix< C >::column_dimension ( ) const [inline, virtual]

column dimension

Implements MathTL::MatrixBlock< C >.

template<class 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)

template<class C>
void MathTL::SparseMatrix< C >::diagonal ( const size_type  n,
const C  diag 
)

yields an n-by-n diagonal matrix

template<class C >
bool MathTL::SparseMatrix< C >::empty ( ) const [inline]

return true if matrix is empty (cf. STL containers)

template<class C >
const SparseMatrix< C >::size_type MathTL::SparseMatrix< C >::entries_in_row ( const size_type  row) const [inline]

number of nonzero entries a given row

template<class C >
template<class MATRIX >
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

template<class C >
const C MathTL::SparseMatrix< C >::get_entry ( const size_type  row,
const size_type  column 
) const

read-only access to a single matrix entry

template<class C >
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

template<class C >
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

template<class C>
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)

template<class C >
void MathTL::SparseMatrix< C >::kill ( ) [protected]

deallocate all memory

template<class C >
void MathTL::SparseMatrix< C >::matlab_input ( const char *  file)

read from matlab sparse matrix format (in binary==1 format)

template<class C >
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

template<class C>
SparseMatrix< C > & MathTL::SparseMatrix< C >::operator= ( const SparseMatrix< C > &  M)

assignment from another sparse matrix

template<class C >
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 >.

template<class C >
void MathTL::SparseMatrix< C >::resize ( const size_type  rows,
const size_type  columns 
)

resize matrix and initialize with zero

template<class C >
const SparseMatrix< C >::size_type MathTL::SparseMatrix< C >::row_dimension ( ) const [inline, virtual]

row dimension

Implements MathTL::MatrixBlock< C >.

template<class C>
void MathTL::SparseMatrix< C >::scale ( const C  s)

in place scaling *this *= s

template<class C >
template<class MATRIX >
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

template<class C>
void MathTL::SparseMatrix< C >::set_entry ( const size_type  row,
const size_type  column,
const C  value 
)

write access to a matrix entry

template<class C>
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)

template<class C >
const SparseMatrix< C >::size_type MathTL::SparseMatrix< C >::size ( ) const

size as an STL-compatible container for matrix entries, number of nonzero entries


Member Data Documentation

template<class C>
size_type MathTL::SparseMatrix< C >::coldim_ [protected]

column dimension

template<class C>
C** MathTL::SparseMatrix< C >::entries_ [protected]

storage for the matrix entries, entries_[r] contains the elements in row r

template<class C>
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

template<class C>
size_type MathTL::SparseMatrix< C >::rowdim_ [protected]

row dimension


The documentation for this class was generated from the following files:
 All Classes Functions Variables Typedefs Enumerations