Belle II Software  release-08-01-10
VMatrix.h
Go to the documentation of this file.
1 /*
2  * VMatrix.h
3  *
4  * Created on: Feb 15, 2012
5  * Author: kleinwrt
6  */
7 
30 #ifndef VMATRIX_H_
31 #define VMATRIX_H_
32 
33 #include<iostream>
34 #include<iomanip>
35 #include<vector>
36 #include<cstring>
37 #include<math.h>
38 
40 namespace gbl {
41 
43 class VVector {
44 public:
45  VVector(const unsigned int nRows = 0);
46  VVector(const VVector &aVector);
47  virtual ~VVector();
48  void resize(const unsigned int nRows);
49  VVector getVec(unsigned int len, unsigned int start = 0) const;
50  void putVec(const VVector &aVector, unsigned int start = 0);
51  inline double &operator()(unsigned int i);
52  inline double operator()(unsigned int i) const;
53  unsigned int getNumRows() const;
54  void print() const;
55  VVector operator-(const VVector &aVector) const;
56  VVector &operator=(const VVector &aVector);
57 private:
58  unsigned int numRows;
59  std::vector<double> theVec;
60 };
61 
63 class VMatrix {
64 public:
65  VMatrix(const unsigned int nRows = 0, const unsigned int nCols = 0);
66  VMatrix(const VMatrix &aMatrix);
67  virtual ~VMatrix();
68  void resize(const unsigned int nRows, const unsigned int nCols);
69  VMatrix transpose() const;
70  inline double &operator()(unsigned int i, unsigned int j);
71  inline double operator()(unsigned int i, unsigned int j) const;
72  unsigned int getNumRows() const;
73  unsigned int getNumCols() const;
74  void print() const;
75  VVector operator*(const VVector &aVector) const;
76  VMatrix operator*(const VMatrix &aMatrix) const;
77  VMatrix operator+(const VMatrix &aMatrix) const;
78  VMatrix &operator=(const VMatrix &aMatrix);
79 private:
80  unsigned int numRows;
81  unsigned int numCols;
82  std::vector<double> theVec;
83 };
84 
86 class VSymMatrix {
87 public:
88  VSymMatrix(const unsigned int nRows = 0);
89  virtual ~VSymMatrix();
90  void resize(const unsigned int nRows);
91  unsigned int invert();
92  inline double &operator()(unsigned int i, unsigned int j);
93  inline double operator()(unsigned int i, unsigned int j) const;
94  unsigned int getNumRows() const;
95  void print() const;
96  VSymMatrix operator-(const VMatrix &aMatrix) const;
97  VVector operator*(const VVector &aVector) const;
98  VMatrix operator*(const VMatrix &aMatrix) const;
99 private:
100  unsigned int numRows;
101  std::vector<double> theVec;
102 };
103 
105 inline double &VMatrix::operator()(unsigned int iRow, unsigned int iCol) {
106  return theVec[numCols * iRow + iCol];
107 }
108 
110 inline double VMatrix::operator()(unsigned int iRow, unsigned int iCol) const {
111  return theVec[numCols * iRow + iCol];
112 }
113 
115 inline double &VVector::operator()(unsigned int iRow) {
116  return theVec[iRow];
117 }
118 
120 inline double VVector::operator()(unsigned int iRow) const {
121  return theVec[iRow];
122 }
123 
125 inline double &VSymMatrix::operator()(unsigned int iRow, unsigned int iCol) {
126  return theVec[(iRow * iRow + iRow) / 2 + iCol]; // assuming iCol <= iRow
127 }
128 
130 inline double VSymMatrix::operator()(unsigned int iRow,
131  unsigned int iCol) const {
132  return theVec[(iRow * iRow + iRow) / 2 + iCol]; // assuming iCol <= iRow
133 }
134 }
135 #endif /* VMATRIX_H_ */
Simple Matrix based on std::vector<double>
Definition: VMatrix.h:63
void resize(const unsigned int nRows, const unsigned int nCols)
Resize Matrix.
Definition: VMatrix.cc:55
double & operator()(unsigned int i, unsigned int j)
access element (i,j)
Definition: VMatrix.h:105
unsigned int numRows
Number of rows.
Definition: VMatrix.h:80
VMatrix transpose() const
Get transposed matrix.
Definition: VMatrix.cc:65
VMatrix operator+(const VMatrix &aMatrix) const
Addition Matrix+Matrix.
Definition: VMatrix.cc:137
unsigned int numCols
Number of columns.
Definition: VMatrix.h:81
VMatrix & operator=(const VMatrix &aMatrix)
Assignment Matrix=Matrix.
Definition: VMatrix.cc:148
void print() const
Print matrix.
Definition: VMatrix.cc:92
unsigned int getNumRows() const
Get number of rows.
Definition: VMatrix.cc:79
std::vector< double > theVec
Data.
Definition: VMatrix.h:82
VVector operator*(const VVector &aVector) const
Multiplication Matrix*Vector.
Definition: VMatrix.cc:108
unsigned int getNumCols() const
Get number of columns.
Definition: VMatrix.cc:87
Simple symmetric Matrix based on std::vector<double>
Definition: VMatrix.h:86
void resize(const unsigned int nRows)
Resize symmetric matrix.
Definition: VMatrix.cc:175
double & operator()(unsigned int i, unsigned int j)
access element (i,j) assuming i>=j
Definition: VMatrix.h:125
unsigned int numRows
Number of rows.
Definition: VMatrix.h:100
VSymMatrix operator-(const VMatrix &aMatrix) const
Subtraction SymMatrix-(sym)Matrix.
Definition: VMatrix.cc:205
unsigned int invert()
Matrix inversion.
Definition: VMatrix.cc:348
void print() const
Print matrix.
Definition: VMatrix.cc:189
unsigned int getNumRows() const
Get number of rows (= number of colums).
Definition: VMatrix.cc:184
std::vector< double > theVec
Data (symmetric storage)
Definition: VMatrix.h:101
VVector operator*(const VVector &aVector) const
Multiplication SymMatrix*Vector.
Definition: VMatrix.cc:216
Simple Vector based on std::vector<double>
Definition: VMatrix.h:43
double & operator()(unsigned int i)
access element (i)
Definition: VMatrix.h:115
void putVec(const VVector &aVector, unsigned int start=0)
Put part of vector.
Definition: VMatrix.cc:284
void resize(const unsigned int nRows)
Resize vector.
Definition: VMatrix.cc:262
unsigned int numRows
Number of rows.
Definition: VMatrix.h:58
VVector operator-(const VVector &aVector) const
Subtraction Vector-Vector.
Definition: VMatrix.cc:312
VVector & operator=(const VVector &aVector)
Assignment Vector=Vector.
Definition: VMatrix.cc:321
VVector getVec(unsigned int len, unsigned int start=0) const
Get part of vector.
Definition: VMatrix.cc:273
void print() const
Print vector.
Definition: VMatrix.cc:298
unsigned int getNumRows() const
Get number of rows.
Definition: VMatrix.cc:293
std::vector< double > theVec
Data.
Definition: VMatrix.h:59
Namespace for the general broken lines package.