Toast++  1.0.2 (r.539)
Forward and inverse modelling in optical tomography
Public Types | Public Member Functions | Protected Attributes | Friends | List of all members
TMatrix< MT > Class Template Referenceabstract

Virtual base class for all matrix types (dense and sparse) More...

#include <matrix.h>

Inheritance diagram for TMatrix< MT >:
TDenseMatrix< MT > TDenseMatrixMPI< MT > TGenericSparseMatrix< MT > TSymMatrix< MT > TCompRowMatrix< MT > TCompRowMatrix< double > TCompRowMatrix< int > TCompRowMatrix< std::complex< float > > TCompRowMatrix< T > TCompRowMatrixMPI< MT > TCoordMatrix< MT > TDiagMatrix< MT > TSymCompRowMatrix< MT >

Public Types

enum  RC { ROW, COL }
 

Public Member Functions

 TMatrix ()
 Create a matrix of size 0 x 0.
 
 TMatrix (int nrows, int ncols)
 Create a matrix of logical size nrows x ncols. More...
 
 TMatrix (const TMatrix< MT > &m)
 Create a matrix as a copy of another matrix. More...
 
virtual ~TMatrix ()
 Destroy the matrix. More...
 
int Dim (RC rc) const
 Return a matrix dimension. More...
 
int nRows () const
 Return number of rows of the matrix. More...
 
int nCols () const
 Return number of columns of the matrix. More...
 
bool isSparse () const
 Return sparse storage flag. More...
 
bool isFull () const
 Return dense storage flag. More...
 
virtual MatrixStorage StorageType () const =0
 Matrix storage class. More...
 
virtual void New (int nrows, int ncols)
 Resize and reset the matrix. More...
 
virtual MT Get (int r, int c) const =0
 Retrieve a matrix element. More...
 
MT operator() (int r, int c) const
 Matrix element access (read only) More...
 
virtual TVector< MT > Row (int r) const =0
 Returns a vector containing a copy of row `r'. More...
 
virtual void SetRow (int r, const TVector< MT > &row)
 Substitute a row of the matrix. More...
 
virtual int SparseRow (int r, idxtype *colidx, MT *val) const =0
 Returns a row of the matrix in sparse format. More...
 
virtual TVector< MT > Col (int c) const =0
 Returns a vector containing a copy of column 'c'. More...
 
virtual TVector< MT > Diag () const
 Returns the matrix diagonal as a vector. More...
 
virtual TVector< MT > ColNorm () const
 Returns vector of column norms. More...
 
virtual void ColScale (const TVector< MT > &scale)=0
 
virtual void RowScale (const TVector< MT > &scale)=0
 
virtual void Unlink ()=0
 
virtual void Ax (const TVector< MT > &x, TVector< MT > &b) const
 
TVector< MT > operator* (const TVector< MT > &x) const
 
virtual void ATx (const TVector< MT > &x, TVector< MT > &b) const
 
TVector< MT > ATx (const TVector< MT > &x) const
 
virtual void Transpone ()
 
virtual MT RowMult (int r, MT *x) const
 
void Export (std::ostream &os) const
 Write matrix to ASCII stream. More...
 
void Print (std::ostream &os=std::cout, int n=80) const
 
void PrintNzeroGraph (char *fname)
 
virtual int pcg (const TVector< MT > &b, TVector< MT > &x, double &tol, TPreconditioner< MT > *precon=0, int maxit=0) const
 
virtual void pcg (const TVector< MT > *b, TVector< MT > *x, int nrhs, double tol, int maxit=0, TPreconditioner< MT > *precon=0, IterativeSolverResult *res=0) const
 
virtual int bicgstab (const TVector< MT > &b, TVector< MT > &x, double &tol, TPreconditioner< MT > *precon=0, int maxit=0) const
 
virtual void bicgstab (const TVector< MT > *b, TVector< MT > *x, int nrhs, double tol, int maxit=0, TPreconditioner< MT > *precon=0, IterativeSolverResult *res=0) const
 
template<>
int pcg (const FVector &b, FVector &x, double &tol, TPreconditioner< float > *precon, int maxit) const
 
template<>
void pcg (const FVector *b, FVector *x, int nrhs, double tol, int maxit, TPreconditioner< float > *precon, IterativeSolverResult *res) const
 
template<>
int bicgstab (const FVector &b, FVector &x, double &tol, TPreconditioner< float > *precon, int maxit) const
 
template<>
void bicgstab (const FVector *b, FVector *x, int nrhs, double tol, int maxit, TPreconditioner< float > *precon, IterativeSolverResult *res) const
 

Protected Attributes

int rows
 
int cols
 

Friends

TSymMatrix< MT > ATA (const TMatrix< MT > &A)
 Return transp(*this) * *this as a symmetric matrix.
 
TSymMatrix< MT > AAT (const TMatrix< MT > &A)
 
TVector< MT > ATA_diag (const TMatrix< MT > &A)
 
int PCG (const TMatrix< MT > &A, const TVector< MT > &b, TVector< MT > &x, double &tol, TPreconditioner< MT > *precon, int maxit)
 
void PCG (const TMatrix< MT > &A, const TVector< MT > *b, TVector< MT > *x, int nrhs, double tol, int maxit, TPreconditioner< MT > *precon, IterativeSolverResult *res)
 
int BiCGSTAB (const TMatrix< MT > &A, const TVector< MT > &b, TVector< MT > &x, double &tol, TPreconditioner< MT > *precon, int maxit)
 
void BiCGSTAB (const TMatrix< MT > &A, const TVector< MT > *b, TVector< MT > *x, int nrhs, double tol, int maxit, TPreconditioner< MT > *precon, IterativeSolverResult *res)
 
std::ostream & operator<< (std::ostream &os, const TMatrix< MT > &mat)
 

Detailed Description

template<class MT>
class TMatrix< MT >

Virtual base class for all matrix types (dense and sparse)

The following template types have been instantiated:

Constructor & Destructor Documentation

template<class MT>
TMatrix< MT >::TMatrix ( int  nrows,
int  ncols 
)
inline

Create a matrix of logical size nrows x ncols.

Parameters
nrowsnumber of rows
ncolsnumber of columns
Remarks
This constructor does not allocate memory for data storage. Storage details are left to derived classes.
template<class MT>
TMatrix< MT >::TMatrix ( const TMatrix< MT > &  m)

Create a matrix as a copy of another matrix.

Parameters
mmatrix to be copied
template<class MT>
virtual TMatrix< MT >::~TMatrix ( )
inlinevirtual

Destroy the matrix.

Remarks
Derived classes deallocate their data blocks here.

Member Function Documentation

template<class MT>
virtual TVector<MT> TMatrix< MT >::Col ( int  c) const
pure virtual

Returns a vector containing a copy of column 'c'.

Parameters
ccolumn index (>= 0)
Returns
vector containing column c
Note
Sparse matrix types expand to a dense column, with missing entries filled with zeros, so this can be used as a "scatter" operation.
See Also
Row

Implemented in TCompRowMatrix< MT >, TCompRowMatrix< double >, TCompRowMatrix< int >, TCompRowMatrix< T >, TCompRowMatrix< std::complex< float > >, TDenseMatrix< MT >, TDenseMatrix< double >, TCompRowMatrixMPI< MT >, TSymMatrix< MT >, TSymMatrix< double >, TDiagMatrix< MT >, TCoordMatrix< MT >, TDenseMatrixMPI< MT >, and TSymCompRowMatrix< MT >.

template<class MT >
TVector< MT > TMatrix< MT >::ColNorm ( ) const
virtual

Returns vector of column norms.

Returns
column L2-norm vector of dimension 'cols'
Note
Returns vector c with

\[ c_j = \sqrt{\sum_i M_{ij}^2} \]

Uses the Col() method to retrieve column vectors. Derived classes which do not have an efficient Col() implementation should overload this method.
template<class MT >
TVector< MT > TMatrix< MT >::Diag ( ) const
virtual

Returns the matrix diagonal as a vector.

Returns
vector containing diagonal elements
Note
The length of the returned vector is min(rows,cols)
The base class implementation uses the Get() method to retrieve the matrix elements. Derived matrix classes should overwrite this method to improve performance.
template<class MT>
int TMatrix< MT >::Dim ( RC  rc) const
inline

Return a matrix dimension.

Parameters
rcROW or COL
Returns
size of the specified dimension
See Also
nRows(), nCols()
template<class MT >
void TMatrix< MT >::Export ( std::ostream &  os) const

Write matrix to ASCII stream.

Outputs the matrix in a generic format, with elements separated by whitespace, and rows separated by line feeds.

Parameters
osoutput stream
template<class MT>
virtual MT TMatrix< MT >::Get ( int  r,
int  c 
) const
pure virtual

Retrieve a matrix element.

Parameters
rmatrix row (0 <= r < nRows())
cmatrix column (0 <= c < nCols())
Returns
matrix element (*this)r,c
Note
This is a read operation and returns the element value. For writing operations, use Put() or operator().
See Also
operator()

Implemented in TCompRowMatrix< MT >, TCompRowMatrix< double >, TCompRowMatrix< int >, TCompRowMatrix< T >, TCompRowMatrix< std::complex< float > >, TDenseMatrix< MT >, TDenseMatrix< double >, TGenericSparseMatrix< MT >, TCompRowMatrixMPI< MT >, TSymMatrix< MT >, TSymMatrix< double >, TCoordMatrix< MT >, TDiagMatrix< MT >, TDenseMatrixMPI< MT >, and TSymCompRowMatrix< MT >.

Referenced by TMatrix< double >::operator()().

template<class MT>
bool TMatrix< MT >::isFull ( ) const
inline

Return dense storage flag.

Returns
true for dense, false for sparse matrix classes
template<class MT>
bool TMatrix< MT >::isSparse ( ) const
inline

Return sparse storage flag.

Returns
true for sparse, false for dense matrix classes
template<class MT>
int TMatrix< MT >::nCols ( ) const
inline

Return number of columns of the matrix.

Returns
number of columns
See Also
nRows(), Dim()
template<class MT >
void TMatrix< MT >::New ( int  nrows,
int  ncols 
)
virtual

Resize and reset the matrix.

Resets the logical size of the matrix to nrows x ncols. Derived classes reallocate the data block and any index arrays, and reset the matrix elements to zero.

Parameters
nrowsnew number of matrix rows
ncolsnew number of matrix columns

Reimplemented in TCompRowMatrix< MT >, TCompRowMatrix< double >, TCompRowMatrix< int >, TCompRowMatrix< T >, TCompRowMatrix< std::complex< float > >, TDenseMatrix< MT >, TDenseMatrix< double >, TGenericSparseMatrix< MT >, TCoordMatrix< MT >, TDiagMatrix< MT >, TSymMatrix< MT >, TSymMatrix< double >, TDenseMatrixMPI< MT >, and TSymCompRowMatrix< MT >.

Referenced by TGenericSparseMatrix< MT >::New().

template<class MT>
int TMatrix< MT >::nRows ( ) const
inline

Return number of rows of the matrix.

Returns
number of rows
See Also
nCols(), Dim()
template<class MT>
MT TMatrix< MT >::operator() ( int  r,
int  c 
) const
inline

Matrix element access (read only)

Parameters
rrow index (0 <= r < nRows())
ccolumn index (0 <= c < nCols())
Returns
matrix element (r,c)
See Also
Get
template<class MT>
virtual TVector<MT> TMatrix< MT >::Row ( int  r) const
pure virtual

Returns a vector containing a copy of row `r'.

Parameters
rrow index (>= 0)
Returns
vector containing row r
Note
Sparse matrix types expand to a dense row, with missing entries filled with zeros, so this can be used as a "scatter" operation.
See Also
SparseRow, SetRow

Implemented in TCompRowMatrix< MT >, TCompRowMatrix< double >, TCompRowMatrix< int >, TCompRowMatrix< T >, TCompRowMatrix< std::complex< float > >, TDenseMatrix< MT >, TDenseMatrix< double >, TSymMatrix< MT >, TSymMatrix< double >, TCompRowMatrixMPI< MT >, TCoordMatrix< MT >, TDiagMatrix< MT >, TDenseMatrixMPI< MT >, and TSymCompRowMatrix< MT >.

template<class MT>
virtual void TMatrix< MT >::SetRow ( int  r,
const TVector< MT > &  row 
)
inlinevirtual

Substitute a row of the matrix.

Replaces row r by 'row'.

Parameters
rrow index (>= 0)
rowvector containing new row values
Note
For sparse matrix types, this function compresses the row vector by stripping zero entries, so this can be used as a "gather" operation.
See Also
Row, SparseRow

Reimplemented in TCompRowMatrix< MT >, TDenseMatrix< MT >, TDenseMatrix< double >, and TDenseMatrixMPI< MT >.

template<class MT>
virtual int TMatrix< MT >::SparseRow ( int  r,
idxtype *  colidx,
MT *  val 
) const
pure virtual

Returns a row of the matrix in sparse format.

Returns a list of column indices and values for all allocated entries of row r. This is only really useful for sparse matrix types. For dense matrices this simply returns the complete row, with indices 0, 1, 2, ... n-1

Parameters
rrow index (>= 0)
colidxpointer to array of column indices
valpointer to array of element values
Returns
Actual number of allocated matrix entries in the row.
Note
The arrays must be allocated by the caller and be of sufficient size.
See Also
Row, SetRow

Implemented in TCompRowMatrix< MT >, TDenseMatrix< MT >, TDenseMatrix< double >, TCompRowMatrixMPI< MT >, TSymMatrix< MT >, TSymMatrix< double >, TDiagMatrix< MT >, TCoordMatrix< MT >, TDenseMatrixMPI< MT >, and TSymCompRowMatrix< MT >.

template<class MT>
virtual MatrixStorage TMatrix< MT >::StorageType ( ) const
pure virtual

The documentation for this class was generated from the following file: