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

Virtual base class for sparse matrix types. More...

#include <gsmatrix.h>

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

Public Member Functions

 TGenericSparseMatrix ()
 Create a sparse matrix of size 0 x 0.
 
 TGenericSparseMatrix (int rows, int cols, int nv=0, const MT *data=0)
 Create a sparse matrix of logical size rows x cols. More...
 
 TGenericSparseMatrix (int rows, int cols, int nv, MT *data, CopyMode cmode=DEEP_COPY)
 
 TGenericSparseMatrix (const TGenericSparseMatrix< MT > &m)
 Constructs a matrix as a copy of 'm'.
 
virtual ~TGenericSparseMatrix ()
 Destructor.
 
virtual void New (int nrows, int ncols)
 Reset the matrix dimensions. More...
 
virtual MT Get (int r, int c) const =0
 Retrieve a matrix element. More...
 
virtual bool Exists (int r, int c) const =0
 Checks allocation of a matrix element. More...
 
virtual void Unlink ()
 
void Initialise (int nv, const MT *data)
 
void Initialise (int nv, MT *data, CopyMode cmode)
 
void Zero ()
 
int nVal () const
 
MT & Val (int i)
 
MT * ValPtr ()
 
const MT * ValPtr () const
 
virtual MT & operator() (int r, int c)=0
 
virtual void Add (int r, int c, const MT &val)
 
virtual int Get_index (int r, int c) const =0
 
virtual MT GetNext (int &r, int &c) const =0
 
TGenericSparseMatrixoperator*= (const MT &sc)
 
TVector< MT > operator* (const TVector< MT > &x) const
 
virtual void Ax (const TVector< MT > &x, TVector< MT > &b) const =0
 
virtual void Ax (const TVector< MT > &x, TVector< MT > &b, int i1, int i2) const =0
 
virtual void ATx (const TVector< MT > &x, TVector< MT > &b) const =0
 
TVector< MT > ATx (const TVector< MT > &x) const
 
double FillFraction () const
 
virtual void Display (std::ostream &os) const
 
virtual void PrintFillinGraph (const char *fname, int maxdim=600, bool binary=true, bool antialias=true)
 
virtual void ExportRCV (std::ostream &os)
 Write sparse matrix to ASCII output stream. More...
 
- Public Member Functions inherited from TMatrix< MT >
 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...
 
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
 
TVector< MT > operator* (const TVector< MT > &x) 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
 

Static Public Member Functions

static void GlobalSelectIterativeSolver (IterativeMethod method)
 
static void GlobalSelectIterativeSolver_complex (IterativeMethod method)
 
static IterativeMethod GetGlobalIterativeSolver ()
 
static IterativeMethod GetGlobalIterativeSolver_complex ()
 

Protected Member Functions

void Append (MT v=0)
 

Protected Attributes

MT * val
 
int nbuf
 
int nval
 
- Protected Attributes inherited from TMatrix< MT >
int rows
 
int cols
 

Friends

int QRFactorize (TGenericSparseMatrix< MT > &A, TVector< MT > &c, TVector< MT > &d)
 
void RSolve (const TGenericSparseMatrix< MT > &A, const TVector< MT > &d, TVector< MT > &b)
 
void QRSolve (const TGenericSparseMatrix< MT > &A, const TVector< MT > &c, const TVector< MT > &d, const TVector< MT > &b, TVector< MT > &x)
 
int IterativeSolve (const TGenericSparseMatrix< MT > &A, const TVector< MT > &b, TVector< MT > &x, double &tol, TPreconditioner< MT > *precon, int maxit)
 
void IterativeSolve (const TGenericSparseMatrix< MT > &A, const TVector< MT > *b, TVector< MT > *x, int nrhs, double tol, int maxit, TPreconditioner< MT > *precon, IterativeSolverResult *res)
 
int CG (const TGenericSparseMatrix< MT > &A, const TVector< MT > &b, TVector< MT > &x, double &tol, TPreconditioner< MT > *precon, int maxit)
 
int BiCG (const TGenericSparseMatrix< MT > &A, const TVector< MT > &b, TVector< MT > &x, double &tol, TPreconditioner< MT > *precon, int maxit)
 
int ComplexBiCGSolve (const TGenericSparseMatrix< MT > &Are, const TGenericSparseMatrix< MT > &Aim, const TVector< MT > &bre, const TVector< MT > &bim, TVector< MT > &xre, TVector< MT > &xim, double &tol, int maxit)
 
int GaussSeidel (const TGenericSparseMatrix< MT > &A, const TVector< MT > &b, TVector< MT > &x, double &tol, int maxit)
 

Additional Inherited Members

- Public Types inherited from TMatrix< MT >
enum  RC { ROW, COL }
 

Detailed Description

template<class MT>
class TGenericSparseMatrix< MT >

Virtual base class for sparse matrix types.

The following template types are instantiated by default:

Constructor & Destructor Documentation

template<class MT >
TGenericSparseMatrix< MT >::TGenericSparseMatrix ( int  rows,
int  cols,
int  nv = 0,
const MT *  data = 0 
)

Create a sparse matrix of logical size rows x cols.

Parameters
rowsnumber of rows (>= 0)
colsnumber of columns (>= 0)
nvnumber of nonzero entries (0 <= nv <= rows.cols)
datadata array of size >= nv
cmodeif set to SHALLOW_COPY, the provided data array is used directly instead of copied to a local buffer. The buffer must remain valid during the lifetime of the matrix.
Note
If nv>0 and data=0, all allocated elements are initialised to zero.

Member Function Documentation

template<class MT>
virtual bool TGenericSparseMatrix< MT >::Exists ( int  r,
int  c 
) const
pure virtual

Checks allocation of a matrix element.

Parameters
rrow index (>= 0)
ccolumn index (>= 0)
Returns
true if memory space is allocated for the element, false if not.

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

template<class MT>
virtual void TGenericSparseMatrix< MT >::ExportRCV ( std::ostream &  os)
inlinevirtual

Write sparse matrix to ASCII output stream.

This writes the nonzero elements of the matrix in a row-column-value format

<r_i> <c_i> <val_i>

containing integer row and column index, and one (double) or two (complex) floating point values, all white-space separated.

Note
The row and column indices are 1-based.
This format can be read into MATLAB by using the 'load' command and converted into a MATLAB sparse matrix by using the 'spconvert' command.

Reimplemented in TCompRowMatrix< MT >, TCompRowMatrix< double >, TCompRowMatrix< int >, TCompRowMatrix< T >, and TCompRowMatrix< std::complex< float > >.

template<class MT>
virtual MT TGenericSparseMatrix< 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()

Implements TMatrix< MT >.

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

template<class MT >
void TGenericSparseMatrix< MT >::New ( int  nrows,
int  ncols 
)
virtual

Reset the matrix dimensions.

Parameters
nrowsnumber of matrix rows
ncolsnumber of matrix columns
Note
This method unlinks the matrix from its current data block by calling Unlink(), then resets its logical dimensions by calling TMatrix::New().
To allocate a new data block for the matrix after New(), use Initialise().
See Also
Unlink, Initialise, TMatrix::New

Reimplemented from TMatrix< MT >.

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

References TMatrix< MT >::New().


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