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

Dense matrix class. More...

#include <dnsmatrix.h>

Inheritance diagram for TDenseMatrix< MT >:
TMatrix< MT >

Public Member Functions

 TDenseMatrix ()
 Create a dense matrix of size 0 x 0.
 
 TDenseMatrix (int r, int c)
 Create a dense matrix of size r x c. More...
 
 TDenseMatrix (int n)
 Create a dense square matrix of size n x n. More...
 
 TDenseMatrix (const TDenseMatrix< MT > &m)
 Create a dense matrix as a copy of another dense matrix. More...
 
 TDenseMatrix (const TDenseMatrix< MT > &m, int i0, int j0, int i1, int j1)
 Construct a matrix by copying a sub-block of another matrix. More...
 
 TDenseMatrix (int r, int c, MT *values)
 Create a dense r x c matrix with a list of values. More...
 
 TDenseMatrix (int r, int c, const char *valstr)
 Create a dense r x c matrix with a string of values. More...
 
 TDenseMatrix (const TSymMatrix< MT > &A)
 Create a dense square matrix from a symmetric matrix. More...
 
 TDenseMatrix (const TCompRowMatrix< MT > &A)
 Create a dense matrix from a compressed row matrix. More...
 
 ~TDenseMatrix ()
 Destructor. De-allocates the matrix.
 
MatrixStorage StorageType () const
 Matrix storage class. More...
 
void New (int r, int c)
 Resize and reset the matrix. More...
 
void Zero ()
 
void Zero (int n)
 
void Zero (int r, int c)
 
void Identity ()
 
void Identity (int n)
 
void Identity (int r, int c)
 
MT Get (int r, int c) const
 Retrieve a matrix element. More...
 
void Set (int r, int c, MT v)
 
MT operator() (int r, int c) const
 
MT & operator() (int r, int c)
 
MT * ValPtr ()
 
TVector< MT > Row (int r) const
 Returns a vector containing a copy of row `r'. More...
 
TVector< MT > Col (int c) const
 Returns a vector containing a copy of column 'c'. More...
 
int SparseRow (int r, idxtype *ci, MT *rv) const
 Returns a row of the matrix in sparse format. More...
 
void SetRow (int r, const TVector< MT > &rval)
 Substitute a row of the matrix. More...
 
void ColScale (const TVector< MT > &scale)
 
void RowScale (const TVector< MT > &scale)
 
TVector< MT > RowSum () const
 Returns a vector of row sums. More...
 
TVector< MT > RowSumSq () const
 Returns a vector of sum of squares for each row. More...
 
TVector< MT > ColSum () const
 Returns a vector of column sums. More...
 
TVector< MT > ColSumSq () const
 Returns a vector of sum of squares for each column. More...
 
void Ax (const TVector< MT > &x, TVector< MT > &b) const
 
void ATx (const TVector< MT > &x, TVector< MT > &b) const
 
void AB (const TDenseMatrix< MT > &A, const TDenseMatrix< MT > &B)
 
MT colmult (int c1, int c2)
 
TDenseMatrix< MT > & operator= (const TDenseMatrix< MT > &m)
 
TDenseMatrix< MT > & operator= (MT v)
 
TDenseMatrix< MT > operator+ (const TDenseMatrix< MT > &m) const
 
TDenseMatrix< MT > operator- (const TDenseMatrix< MT > &m) const
 
TDenseMatrix< MT > operator* (const TDenseMatrix< MT > &m) const
 
TVector< MT > operator* (const TVector< MT > &x) const
 
TDenseMatrix< MT > operator* (const MT &mt) const
 
TDenseMatrix< MT > operator/ (const MT &mt) const
 
TDenseMatrix< MT > & operator*= (const MT &mt)
 
TDenseMatrix< MT > & operator/= (const MT &mt)
 
MT * data_buffer ()
 
const MT * data_buffer () const
 
- 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...
 
MT operator() (int r, int c) const
 Matrix element access (read only) 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...
 
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
 

Protected Attributes

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

Friends

TDenseMatrix< MT > transpose (const TDenseMatrix< MT > &A)
 
TDenseMatrix< MT > cath (const TDenseMatrix< MT > &A, const TDenseMatrix< MT > &B)
 Concatenate two matrices horizontally. More...
 
TDenseMatrix< MT > catv (const TDenseMatrix< MT > &A, const TDenseMatrix< MT > &B)
 Concatenate two matrices vertically. More...
 
TSymMatrix< MT > ATA (const TDenseMatrix< MT > &A)
 
TSymMatrix< MT > AAT (const TDenseMatrix< MT > &A)
 
TDenseMatrix< MT > kron (const TDenseMatrix< MT > &A, const TDenseMatrix< MT > &B)
 
MT det (const TDenseMatrix< MT > &A, TDenseMatrix< MT > *Ai)
 
TDenseMatrix< MT > inverse (const TDenseMatrix< MT > &A)
 
int QRFactorize (TDenseMatrix< MT > &A, TVector< MT > &c, TVector< MT > &d)
 
void RSolve (const TDenseMatrix< MT > &A, const TVector< MT > &d, TVector< MT > &b)
 
void QRSolve (const TDenseMatrix< MT > &A, const TVector< MT > &c, const TVector< MT > &d, const TVector< MT > &b, TVector< MT > &x)
 
void LUFactorize (TDenseMatrix< MT > &a, IVector &indx, double &d)
 
void LUSolve (const TDenseMatrix< MT > &a, const IVector &indx, TVector< MT > &b)
 
std::istream & operator>> (std::istream &is, TDenseMatrix< MT > &m)
 
std::ostream & operator<< (std::ostream &os, const TDenseMatrix< MT > &m)
 

Additional Inherited Members

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

Detailed Description

template<class MT>
class TDenseMatrix< MT >

Dense matrix class.

A fully populated matrix type that stores its elements in row order. Supports all operations inherited from the matrix base class interface, such as row and column norms, row and column scaling, matrix x vector operations, and various direct and iterative linear solvers.

Constructor & Destructor Documentation

template<class MT>
TDenseMatrix< MT >::TDenseMatrix ( int  r,
int  c 
)
inline

Create a dense matrix of size r x c.

Parameters
rnumber of rows (>= 0)
cnumber of columns (>= 0)
Note
All elements are initialised to zero.
template<class MT>
TDenseMatrix< MT >::TDenseMatrix ( int  n)
inline

Create a dense square matrix of size n x n.

Parameters
nnumber of rows and columns (>= 0)
Note
All elements are initialised to zero.
template<class MT>
TDenseMatrix< MT >::TDenseMatrix ( const TDenseMatrix< MT > &  m)
inline

Create a dense matrix as a copy of another dense matrix.

Parameters
msource matrix
template<class MT>
TDenseMatrix< MT >::TDenseMatrix ( const TDenseMatrix< MT > &  m,
int  i0,
int  j0,
int  i1,
int  j1 
)

Construct a matrix by copying a sub-block of another matrix.

Parameters
msource matrix
i0low row index of sub-block
j0low column index of sub-block
i1high row index+1 of sub-block
j1high column index+1 of sub-block
Note
This constructor creates a dense matrix of dimensions i1-i0 x j1-j0 by copying a block of matrix m.
0 <= i0 <= i1 <= m.nRows() and 0 <= j0 <= j1 <= m.nCols() is required.
This is not a reference constructor: the new matrix does not share its data block with the source matrix.
template<class MT>
TDenseMatrix< MT >::TDenseMatrix ( int  r,
int  c,
MT *  values 
)
inline

Create a dense r x c matrix with a list of values.

Parameters
rnumber of rows (>= 0)
cnumber of columns (>= 0)
valuesarray of matrix values
Note
The entries in the array are applied in row-order: values[0] -> m(0,0), values[1] -> m(0,1), ...
The length of the array must be at least r*c
The values are deep-copied, so the array can be deallocated by the caller after use.
template<class MT>
TDenseMatrix< MT >::TDenseMatrix ( int  r,
int  c,
const char *  valstr 
)

Create a dense r x c matrix with a string of values.

Parameters
rnumber of rows (>= 0)
cnumber of columns (>= 0)
valstrASCII string of values
Note
The entries in the string must be in a format recognisable by the stream-in operator (>>). They must be separated by whitespace.
The entries in the array are applied in row-order.
template<class MT>
TDenseMatrix< MT >::TDenseMatrix ( const TSymMatrix< MT > &  A)

Create a dense square matrix from a symmetric matrix.

Parameters
Asymmetric source matrix
Note
The matrix requires more storage space in dense format than in symmetric format, because both the upper and lower triangles are represented explicitly.
template<class MT>
TDenseMatrix< MT >::TDenseMatrix ( const TCompRowMatrix< MT > &  A)

Create a dense matrix from a compressed row matrix.

Parameters
Acompressed row source matrix

Member Function Documentation

template<class MT>
TVector<MT> TDenseMatrix< MT >::Col ( int  c) const
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

Implements TMatrix< MT >.

template<class MT>
TVector<MT> TDenseMatrix< MT >::ColSum ( ) const

Returns a vector of column sums.

Returns
Column sum vector.
Note
The size of the returned vector equals the number of columns of the matrix. Each entry j contains the sum of elements of column j.
See Also
RowSum, RowSumSq, ColSumSq
template<class MT>
TVector<MT> TDenseMatrix< MT >::ColSumSq ( ) const

Returns a vector of sum of squares for each column.

Returns
Vector of sum of squares.
Note
The size of the returned vector equals the number of columns of the matrix. Each entry j contains the sum of the squares of elements of column j.
See Also
ColSum, RowSum, RowSumSq
template<class MT>
MT TDenseMatrix< MT >::Get ( int  r,
int  c 
) const
inlinevirtual

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 >.

template<class MT>
void TDenseMatrix< MT >::New ( int  nrows,
int  ncols 
)
inlinevirtual

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 from TMatrix< MT >.

template<class MT>
TVector<MT> TDenseMatrix< MT >::Row ( int  r) const
inlinevirtual

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

Implements TMatrix< MT >.

template<class MT>
TVector<MT> TDenseMatrix< MT >::RowSum ( ) const

Returns a vector of row sums.

Returns
Row sum vector.
Note
The size of the returned vector equals the number of rows of the matrix. Each entry i contains the sum of elements of row i.
See Also
RowSumSq, ColSum, ColSumSq
template<class MT>
TVector<MT> TDenseMatrix< MT >::RowSumSq ( ) const

Returns a vector of sum of squares for each row.

Returns
Vector of sum of squares.
Note
The size of the returned vector equals the number of rows of the matrix. Each entry i contains the sum of the squares of elements of row i.
See Also
RowSum, ColSum, ColSumSq
template<class MT>
void TDenseMatrix< MT >::SetRow ( int  r,
const TVector< MT > &  row 
)
virtual

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 from TMatrix< MT >.

template<class MT>
int TDenseMatrix< MT >::SparseRow ( int  r,
idxtype *  colidx,
MT *  val 
) const
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

Implements TMatrix< MT >.

template<class MT>
MatrixStorage TDenseMatrix< MT >::StorageType ( ) const
inlinevirtual

Matrix storage class.

Returns
storage class identifier

Implements TMatrix< MT >.

Friends And Related Function Documentation

template<class MT>
TDenseMatrix<MT> cath ( const TDenseMatrix< MT > &  A,
const TDenseMatrix< MT > &  B 
)
friend

Concatenate two matrices horizontally.

Parameters
Afirst matrix argument
Bsecond matrix argument
Returns
Result of concatenation [A B]
Note
A and B must have the same number of rows.
This method has the functionality of the MATLAB construct C = (A,B)
template<class MT>
TDenseMatrix<MT> catv ( const TDenseMatrix< MT > &  A,
const TDenseMatrix< MT > &  B 
)
friend

Concatenate two matrices vertically.

Parameters
Afirst matrix argument
Bsecond matrix argument
Returns
Result of concatenation

\[ C = \left[ \begin{array}{c} A\\B \end{array} \right] \]

Note
A and B must have the same number of columns
This method has the functionality of the MATLAB construct C = (A;B)

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