LinearAlgebra.h
Go to the documentation of this file.
1 #ifndef _FdEnergyDepositFinderKG_LinearAlgebra_h_
2 #define _FdEnergyDepositFinderKG_LinearAlgebra_h_
3 
4 #include <utl/AugerException.h>
5 #include <vector>
6 
7 
8 namespace FdEnergyDepositFinderKG {
9 
18  class DiagonalMatrix;
19  class LowerTriangularMatrix;
20  class ColumnVector;
21 
22 
23  class ColumnVector {
24  public:
26  ColumnVector(const int n) : fElements(n) { }
27 
29  ColumnVector(const int n, const double x)
30  : fElements(n, x) { }
31 
34 
36  const double& operator()(const int row) const
37  { return fElements[row]; }
39  double& operator()(const int row) { return fElements[row]; }
40 
42  void Clear() { fElements.clear(); }
44  void Zero();
45 
47  void SetSize(const int n) { fElements.resize(n); }
48  unsigned int GetSize() const { return fElements.size(); }
49 
50  ColumnVector operator+(const ColumnVector& rhs) const;
51 
52  private:
53  std::vector<double> fElements;
54 
55  friend class LowerTriangularMatrix;
56  friend class DiagonalMatrix;
57  };
58 
59 
61  public:
63  LowerTriangularMatrix(const int n) : fElements(n*(n+1)/2) { }
64 
66  LowerTriangularMatrix(const int n, const double x)
67  : fElements(n*(n+1)/2, x) { }
68 
71 
72  // Note: for proper access asserts, we'd have to make this non-inlined...
74  const double& operator()(const int row, const int col) const
75  { return fElements[(row*(row+1))/2 + col]; }
77  double& operator()(const int row, const int col)
78  { return fElements[(row*(row+1))/2 + col]; }
79 
81  void Clear() { fElements.clear(); }
83  void Zero();
84 
87  void SetSize(const int n) { fElements.resize(n*(n+1)/2); }
88  unsigned int GetSize() const;
89 
92 
94  void Print() const;
95 
98  ColumnVector operator*(const ColumnVector& rhs) const;
99 
100  private:
101  std::vector<double> fElements;
102 
103  friend class DiagonalMatrix;
104  };
105 
106 
108  public:
110  DiagonalMatrix(const int n) : fElements(n) { }
111 
113  DiagonalMatrix(const int n, const double x)
114  : fElements(n, x) { }
115 
118 
120  const double& operator()(const int row, const int col) const;
122  double& operator()(const int row, const int col);
123 
125  const double& operator()(const int iDiagonal) const
126  { return fElements[iDiagonal]; }
128  double& operator()(const int iDiagonal)
129  { return fElements[iDiagonal]; }
130 
132  void Clear() { fElements.clear(); }
134  void Zero();
135 
138  void SetSize(const int n) { fElements.resize(n); }
139  unsigned int GetSize() const { return fElements.size(); }
140 
142  void Print() const;
143 
144  DiagonalMatrix operator+(const DiagonalMatrix& rhs) const;
145  ColumnVector operator*(const ColumnVector& rhs) const;
146 
147  DiagonalMatrix GetInverse() const;
148 
149  private:
150  std::vector<double> fElements;
151 
152  friend class LowerTriangularMatrix;
153  };
154 
155 
157  public:
158  SingularMatrixException(const std::string& message = std::string())
159  : AugerException(message) { }
160 
162  virtual std::string GetExceptionName() const
163  { return "Singular Matrix Exception"; }
164  };
165 
166 }
167 
168 
169 #endif
void Clear()
Free the vector (requiring another SetSize(n) call for reuse)
Definition: LinearAlgebra.h:42
const double & operator()(const int row, const int col) const
Read-only access to a matrix element.
ColumnVector()
Empty row vector (needs SetSize() later)
Definition: LinearAlgebra.h:33
const double & operator()(const int row, const int col) const
Read-only access to a matrix element.
Definition: LinearAlgebra.h:74
void Zero()
Set all elements to 0.
Base class for all exceptions used in the auger offline code.
DiagonalMatrix(const int n)
(n*n) diagonal matrix
void SetSize(const int n)
Set the size of the vector. Does NOT initialize elements to 0.
Definition: LinearAlgebra.h:47
ColumnVector operator*(const ColumnVector &rhs) const
DiagonalMatrix(const int n, const double x)
(n*n) diagonal matrix, elements intialized to x
LowerTriangularMatrix(const int n)
(n*n) lower triangular matrix
Definition: LinearAlgebra.h:63
LowerTriangularMatrix operator+(const LowerTriangularMatrix &rhs) const
LowerTriangularMatrix()
Empty matrix (needs SetSize() later)
Definition: LinearAlgebra.h:70
ColumnVector(const int n, const double x)
Row vector with n elements, intializing to x.
Definition: LinearAlgebra.h:29
ColumnVector operator+(const ColumnVector &rhs) const
void Clear()
Free the matrix (requiring another SetSize(n) call for reuse)
Definition: LinearAlgebra.h:81
double & operator()(const int row, const int col)
Read/write access to a matrix element.
Definition: LinearAlgebra.h:77
void Zero()
Set all elements to 0.
LowerTriangularMatrix GetInverse() const
Get the inverse of the matrix.
void Print() const
Dump ASCII representation to STDOUT (for debugging)
ColumnVector operator*(const ColumnVector &rhs) const
const double & operator()(const int iDiagonal) const
Read-only access to a diagonal matrix element.
double & operator()(const int row)
Read/write access to a vector element.
Definition: LinearAlgebra.h:39
LowerTriangularMatrix(const int n, const double x)
(n*n) lower triangular matrix, elements intialized to x
Definition: LinearAlgebra.h:66
DiagonalMatrix operator+(const DiagonalMatrix &rhs) const
double & operator()(const int iDiagonal)
Read/write access to a diagonal matrix element.
void Print() const
Dump ASCII representation to STDOUT (for debugging)
DiagonalMatrix()
Empty matrix (needs SetSize() later)
const double & operator()(const int row) const
Read-only access to a vector element.
Definition: LinearAlgebra.h:36
ColumnVector(const int n)
Row vector with n elements.
Definition: LinearAlgebra.h:26
void Clear()
Free the matrix (requiring another SetSize(n) call for reuse)

, generated on Tue Sep 26 2023.