Toast++  1.0.2 (r.539)
Forward and inverse modelling in optical tomography
dgmatrix.h
1 // -*-C++-*-
2 // ==========================================================================
3 // Module mathlib
4 // File dgmatrix.h
5 // Declaration of template class TDiagMatrix ('template diagonal matrix')
6 //
7 // The following typedefs for specific template types have been defined
8 // for convenience:
9 // RDiagMatrix = TDiagMatrix<double> ('real')
10 // FDiagMatrix = TDiagMatrix<float> ('float')
11 // CDiagMatrix = TDiagMatrix<complex> ('complex')
12 // IDiagMatrix = TDiagMatrix<int> ('integer')
13 // DiagMatrix = TDiagMatrix<double> for backward compatibility
14 //
15 // Inheritance:
16 // ------------
17 // TGenericSparseMatrix ----> TDiagMatrix
18 // ==========================================================================
19 
20 #ifndef __DGMATRIX_H
21 #define __DGMATRIX_H
22 
23 #include "gsmatrix.h"
24 #include "dnsmatrix.h"
25 
26 // ==========================================================================
27 // class TDiagMatrix
28 // ==========================================================================
43 template<class MT> class TDiagMatrix: public TGenericSparseMatrix<MT> {
44 public:
48  TDiagMatrix ();
49 
56  TDiagMatrix (int r, int c, const MT v = (MT)0);
57 
62  TDiagMatrix (const TDiagMatrix<MT> &mat);
63 
67  virtual ~TDiagMatrix ();
68 
74 
81  void New (int nrows, int ncols);
82 
90  virtual MT Get (int r, int c) const
91  { return (r == c) ? this->val[r] : (MT)0; }
92 
100  TVector<MT> Row (int r) const;
101 
109  TVector<MT> Col (int c) const;
110 
123  int SparseRow (int r, idxtype *colidx, MT *val) const;
124 
130  void ColScale (const TVector<MT> &scale);
131 
137  void RowScale (const TVector<MT> &scale);
138 
146 
154  TDiagMatrix &operator= (const MT &v);
155 
161  void Copy (const TDiagMatrix<MT> &mat);
162 
168  operator TDenseMatrix<MT> ();
169 
178  MT &operator() (int r, int c);
179 
186  TDiagMatrix operator+ (const TDiagMatrix &mat) const;
187 
194  TDiagMatrix operator- (const TDiagMatrix &mat) const;
195 
202  bool Exists (int r, int c) const;
203 
210  int Get_index (int r, int c) const;
211 
227  MT GetNext (int &r, int &c) const;
228 
236  void Ax (const TVector<MT> &x, TVector<MT> &b) const;
237 
247  void Ax (const TVector<MT> &x, TVector<MT> &b, int r1, int r2) const;
248 
256  void ATx (const TVector<MT> &x, TVector<MT> &b) const;
257 };
258 
259 // ==========================================================================
260 // typedefs for specific instances of `TDiagMatrix'
261 // ==========================================================================
262 typedef TDiagMatrix<double> RDiagMatrix; // 'real'
263 typedef TDiagMatrix<float> FDiagMatrix; // 'float'
264 typedef TDiagMatrix<std::complex<double> > CDiagMatrix; // 'complex'
265 typedef TDiagMatrix<int> IDiagMatrix; // 'integer'
266 typedef TDiagMatrix<double> DiagMatrix; // for backward compatibility
267 // ==========================================================================
268 
269 #endif // !__DGMATRIX_H
TVector< MT > Row(int r) const
Returns a vector containing a copy of row 'r'.
Virtual base class for sparse matrix types.
Definition: gsmatrix.h:47
MT & operator()(int r, int c)
Element access.
void ATx(const TVector< MT > &x, TVector< MT > &b) const
Transpose matrix-vector multiplication.
void New(int nrows, int ncols)
Resizes and resets the matrix.
void Copy(const TDiagMatrix< MT > &mat)
Matrix copy operation.
TDiagMatrix & operator=(const TDiagMatrix< MT > &mat)
Matrix assignment.
void RowScale(const TVector< MT > &scale)
Scales the matrix rows.
TVector< MT > Col(int c) const
Returns a vector containing a copy of column 'c'.
MatrixStorage
Definition: matrix.h:20
virtual MT Get(int r, int c) const
Retrieves a matrix element.
Definition: dgmatrix.h:90
Diagonal matrix class.
Definition: crmatrix.h:39
TDiagMatrix operator-(const TDiagMatrix &mat) const
Matrix subtraction.
virtual ~TDiagMatrix()
Matrix destructor.
int Get_index(int r, int c) const
Returns data array index for an element.
MatrixStorage StorageType() const
Returns the matrix storage type.
Definition: dgmatrix.h:73
void ColScale(const TVector< MT > &scale)
Scales the matrix columns.
TDiagMatrix()
Creates a diagonal matrix of dimension 0 x 0.
void Ax(const TVector< MT > &x, TVector< MT > &b) const
Matrix-vector multiplication.
Dense matrix class.
Definition: crmatrix.h:38
TDiagMatrix operator+(const TDiagMatrix &mat) const
Matrix addition.
bool Exists(int r, int c) const
Checks allocation of a matrix element.
MT GetNext(int &r, int &c) const
Element iterator.
store diagonal matrix as vector
Definition: matrix.h:23
int SparseRow(int r, idxtype *colidx, MT *val) const
Returns a row of the matrix in sparse format.