FEDRA emulsion software from the OPERA Collaboration
VtMatrix.hh
Go to the documentation of this file.
1 #ifndef __VTMATRIX_HH
2 #define __VTMATRIX_HH
3 // *****************************************************************************
4 //
5 // source:
6 //
7 // type: source code
8 //
9 // created: 21. Aug 2000
10 //
11 // author: Thorsten Glebe
12 // HERA-B Collaboration
13 // Max-Planck-Institut fuer Kernphysik
14 // Saupfercheckweg 1
15 // 69117 Heidelberg
16 // Germany
17 // E-mail: T.Glebe@mpi-hd.mpg.de
18 //
19 // Description: Matrix base class
20 //
21 // changes:
22 // 21 Aug 2000 (TG) creation
23 // 11 Sep 2000 (TG) added documentation
24 // 10 Okt 2000 (TG) added copy() member function
25 // 11 Okt 2000 (TG) added clear() member function
26 // 17 Okt 2000 (TG) declared some members virtual
27 // 23 Okt 2000 (TG) added place_at(VtVector,...)
28 // 27 Okt 2000 (TG) made print() virtual
29 // 04 Sep 2001 (TG) added array()
30 //
31 // *****************************************************************************
32 
33 #include <iosfwd>
34 #include <assert.h>
35 
36 #ifdef WIN32
37 # include "Rtypes.h"
38 #endif
39 
40 namespace MATRIX {
41  class VtVector;
42  class VtNegMatrix;
43 
46  //============================================================================
47  // Class VtMatrix: simple Matrix class
48  //============================================================================
49  class VtMatrix {
50  public:
53  VtMatrix(const unsigned int row, const unsigned int col);
55  VtMatrix(const VtMatrix& rhs);
57  virtual ~VtMatrix();
58 
61  inline unsigned int nrow() const { return m_nrow; }
63  inline unsigned int ncol() const { return m_ncol; }
65  inline int size() const { return m_size; }
66 
67  // helper class to implement m[i][j]
68  class VtMatrix_row {
69  public:
70  inline VtMatrix_row(VtMatrix& a, int row):
71  r_a(a), r_r(row) {}
72  double& operator[](int col) {
73  return r_a.operator()(r_r,col);
74  // return *(r_a.m + r_r*r_a.ncol() + col);
75  }
76  private:
78  int r_r;
79  }; // VtMatrix_row
80 
81  // const version
83  public:
84  inline VtMatrix_row_const(const VtMatrix& a, int row):
85  r_a(a), r_r(row) {}
86  const double operator[](int col) const {
87  return r_a.operator()(r_r,col);
88  // return *(r_a.m + r_r*r_a.ncol() + col);
89  }
90  private:
91  const VtMatrix& r_a;
92  int r_r;
93  }; // VtMatrix_row_const
94 
95  inline VtMatrix_row operator[](int row) {
96  return VtMatrix_row(*this, row);
97  }
98  inline VtMatrix_row_const operator[](int row) const {
99  return VtMatrix_row_const(*this, row);
100  }
101 
102  virtual double operator()(unsigned int row, unsigned int col) const;
103  virtual double& operator()(const unsigned int row, const unsigned int col);
104 
105  inline double get(unsigned int row, unsigned int col) const {
106  return *(m + row*m_ncol + col);
107  }
108 
109  inline double& get(unsigned int row, unsigned int col) {
110  return *(m + row*m_ncol + col);
111  }
112 
115  void VtT(void);
117  const VtMatrix T(void) const;
119  virtual void place_at(const VtMatrix& rhs,
120  const unsigned int row,
121  const unsigned int col);
123  virtual void place_at(const VtVector& rhs,
124  const unsigned int row,
125  const unsigned int col);
127  void copy(const VtMatrix& rhs);
129  void clear(void);
130 
132  const VtMatrix& operator= (const VtMatrix& rhs);
134  const VtMatrix& operator= (const VtNegMatrix& rhs);
136  virtual const VtMatrix& operator+=(const double rhs);
138  virtual const VtMatrix& operator-=(const double rhs);
140  virtual const VtMatrix& operator*=(const double rhs);
142  virtual const VtMatrix& operator/=(const double rhs);
144  const VtMatrix& operator+=(const VtMatrix& rhs);
146  const VtMatrix& operator-=(const VtMatrix& rhs);
147 
149  const VtMatrix operator+ (const VtMatrix& rhs) const;
151  const VtMatrix operator+ (const VtNegMatrix& rhs) const;
153  const VtMatrix operator- (const VtMatrix& rhs) const;
155  const VtMatrix operator- (const VtNegMatrix& rhs) const;
157  const VtNegMatrix operator- (void) const;
159  const VtMatrix operator* (const VtMatrix& rhs) const;
161  const VtVector operator* (const VtVector& rhs) const;
162  // not needed: const VtMatrix operator* (const VtNegMatrix& rhs) const;
163 
166  inline double* array() const { return m; }
168  virtual void print(std::ostream& os) const;
169 
170  protected:
171  double* m; // pointer to matrix array
172  double* work; // workspace for CERNLIB routines
173  unsigned int m_nrow; // no of rows
174  unsigned int m_ncol; // no of col
175 
176  private:
177  friend class VtMatrix_row;
178  friend class VtMatrix_row_const;
179  int m_size; // size of matrix array
180 
181 #ifdef WIN32
182  ClassDef(VtMatrix,0)
183 #endif
184  }; // class VtMatrix
185 
186  //==============================================================================
187  // operator <<
188  //==============================================================================
189  inline std::ostream& operator<< ( std::ostream& os, const VtMatrix& t ) {
190  t.print(os);
191  return os;
192  }
193 
194 } // namespace MATRIX
195 #endif
void a()
Definition: check_aligned.C:59
TTree * t
Definition: check_shower.C:4
Definition: VtMatrix.hh:82
const VtMatrix & r_a
Definition: VtMatrix.hh:91
VtMatrix_row_const(const VtMatrix &a, int row)
Definition: VtMatrix.hh:84
const double operator[](int col) const
Definition: VtMatrix.hh:86
int r_r
Definition: VtMatrix.hh:92
Definition: VtMatrix.hh:68
VtMatrix & r_a
Definition: VtMatrix.hh:77
VtMatrix_row(VtMatrix &a, int row)
Definition: VtMatrix.hh:70
int r_r
Definition: VtMatrix.hh:78
double & operator[](int col)
Definition: VtMatrix.hh:72
Definition: VtMatrix.hh:49
const VtNegMatrix operator-(void) const
$-\textbf{A}$
Definition: VtMatrix.C:271
VtMatrix_row_const operator[](int row) const
Definition: VtMatrix.hh:98
virtual void print(std::ostream &os) const
Definition: VtMatrix.C:358
void clear(void)
set matrix elements to 0
Definition: VtMatrix.C:394
double * m
Definition: VtMatrix.hh:171
virtual void place_at(const VtMatrix &rhs, const unsigned int row, const unsigned int col)
copy a smaller matrix at a certain place
Definition: VtMatrix.C:65
double & get(unsigned int row, unsigned int col)
Definition: VtMatrix.hh:109
void copy(const VtMatrix &rhs)
to be used if matrix dimensions are not equal
Definition: VtMatrix.C:379
const VtMatrix & operator=(const VtMatrix &rhs)
$\textbf{A} = \textbf{B}$
Definition: VtMatrix.C:120
double get(unsigned int row, unsigned int col) const
Definition: VtMatrix.hh:105
void VtT(void)
transform into transpose matrix
Definition: VtMatrix.C:330
int m_size
Definition: VtMatrix.hh:179
VtMatrix_row operator[](int row)
Definition: VtMatrix.hh:95
VtMatrix(const unsigned int row, const unsigned int col)
Definition: VtMatrix.C:38
virtual const VtMatrix & operator+=(const double rhs)
$\textbf{A} = (a_{\mu\nu} + \alpha)$
Definition: VtMatrix.C:158
unsigned int ncol() const
no of columns $m$
Definition: VtMatrix.hh:63
unsigned int m_nrow
Definition: VtMatrix.hh:173
int size() const
$m\times n$
Definition: VtMatrix.hh:65
double * array() const
return pointer to internal array
Definition: VtMatrix.hh:166
const VtMatrix operator+(const VtMatrix &rhs) const
$\textbf{A} + \textbf{B}$
Definition: VtMatrix.C:216
unsigned int m_ncol
Definition: VtMatrix.hh:174
double * work
Definition: VtMatrix.hh:172
unsigned int nrow() const
no of rows $n$
Definition: VtMatrix.hh:61
const VtMatrix T(void) const
return transpose
Definition: VtMatrix.C:349
virtual const VtMatrix & operator-=(const double rhs)
$\textbf{A} = (a_{\mu\nu} - \alpha)$
Definition: VtMatrix.C:179
virtual const VtMatrix & operator*=(const double rhs)
$\textbf{A} = (a_{\mu\nu} \cdot\alpha)$
Definition: VtMatrix.C:200
friend class VtMatrix_row
Definition: VtMatrix.hh:177
virtual ~VtMatrix()
Definition: VtMatrix.C:56
virtual double operator()(unsigned int row, unsigned int col) const
Definition: VtMatrix.C:109
const VtMatrix operator*(const VtMatrix &rhs) const
$\textbf{A}\cdot\textbf{B} = \sum_{\nu=1}^n a_{\mu\nu}b_{\nu\lambda}$
Definition: VtMatrix.C:283
virtual const VtMatrix & operator/=(const double rhs)
$\textbf{A} = (a_{\mu\nu} / \alpha)$
Definition: VtMatrix.C:208
friend class VtMatrix_row_const
Definition: VtMatrix.hh:178
Definition: VtNegMatrix.hh:44
Definition: VtVector.hh:45
Definition: CMatrix.C:43
std::ostream & operator<<(std::ostream &os, const VtMatrix &t)
Definition: VtMatrix.hh:189