CMS 3D CMS Logo

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_ */
Definition: start.py:1
VVector getVec(unsigned int len, unsigned int start=0) const
Get part of vector.
Definition: VMatrix.cc:273
def transpose(a)
Definition: geometryDiff.py:37
double & operator()(unsigned int i, unsigned int j)
access element (i,j)
Definition: VMatrix.h:105
Simple Matrix based on std::vector<double>
Definition: VMatrix.h:63
MatrixMeschach operator+(const MatrixMeschach &mat1, const MatrixMeschach &mat2)
VVector(const unsigned int nRows=0)
Definition: VMatrix.cc:246
void print() const
Print vector.
Definition: VMatrix.cc:298
void putVec(const VVector &aVector, unsigned int start=0)
Put part of vector.
Definition: VMatrix.cc:284
unsigned int numCols
Number of columns.
Definition: VMatrix.h:81
VVector operator-(const VVector &aVector) const
Subtraction Vector-Vector.
Definition: VMatrix.cc:312
unsigned int getNumRows() const
Get number of rows.
Definition: VMatrix.cc:293
double & operator()(unsigned int i, unsigned int j)
access element (i,j) assuming i>=j
Definition: VMatrix.h:125
void resize(const unsigned int nRows)
Resize vector.
Definition: VMatrix.cc:262
unsigned int numRows
Number of rows.
Definition: VMatrix.h:80
Namespace for the general broken lines package.
Simple symmetric Matrix based on std::vector<double>
Definition: VMatrix.h:86
double & operator()(unsigned int i)
access element (i)
Definition: VMatrix.h:115
unsigned int numRows
Number of rows.
Definition: VMatrix.h:100
VVector & operator=(const VVector &aVector)
Assignment Vector=Vector.
Definition: VMatrix.cc:321
std::vector< double > theVec
Data (symmetric storage)
Definition: VMatrix.h:101
Simple Vector based on std::vector<double>
Definition: VMatrix.h:43
MatrixMeschach operator*(const MatrixMeschach &mat1, const MatrixMeschach &mat2)
std::vector< double > theVec
Data.
Definition: VMatrix.h:82
std::vector< double > theVec
Data.
Definition: VMatrix.h:59
virtual ~VVector()
Definition: VMatrix.cc:255
unsigned int numRows
Number of rows.
Definition: VMatrix.h:58