CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 
8 #ifndef VMATRIX_H_
9 #define VMATRIX_H_
10 
11 #include<iostream>
12 #include<iomanip>
13 #include<vector>
14 #include<cstring>
15 #include<math.h>
16 
18 namespace gbl {
19 
21 class VVector {
22 public:
23  VVector(const unsigned int nRows = 0);
24  VVector(const VVector &aVector);
25  virtual ~VVector();
26  void resize(const unsigned int nRows);
27  VVector getVec(unsigned int len, unsigned int start = 0) const;
28  void putVec(const VVector &aVector, unsigned int start = 0);
29  inline double &operator()(unsigned int i);
30  inline double operator()(unsigned int i) const;
31  unsigned int getNumRows() const;
32  void print() const;
33  VVector operator-(const VVector &aVector) const;
34  VVector &operator=(const VVector &aVector);
35 private:
36  unsigned int numRows;
37  std::vector<double> theVec;
38 };
39 
41 class VMatrix {
42 public:
43  VMatrix(const unsigned int nRows = 0, const unsigned int nCols = 0);
44  VMatrix(const VMatrix &aMatrix);
45  virtual ~VMatrix();
46  void resize(const unsigned int nRows, const unsigned int nCols);
47  VMatrix transpose() const;
48  inline double &operator()(unsigned int i, unsigned int j);
49  inline double operator()(unsigned int i, unsigned int j) const;
50  unsigned int getNumRows() const;
51  unsigned int getNumCols() const;
52  void print() const;
53  VVector operator*(const VVector &aVector) const;
54  VMatrix operator*(const VMatrix &aMatrix) const;
55  VMatrix operator+(const VMatrix &aMatrix) const;
56  VMatrix &operator=(const VMatrix &aMatrix);
57 private:
58  unsigned int numRows;
59  unsigned int numCols;
60  std::vector<double> theVec;
61 };
62 
64 class VSymMatrix {
65 public:
66  VSymMatrix(const unsigned int nRows = 0);
67  virtual ~VSymMatrix();
68  void resize(const unsigned int nRows);
69  unsigned int invert();
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  void print() const;
74  VSymMatrix operator-(const VMatrix &aMatrix) const;
75  VVector operator*(const VVector &aVector) const;
76  VMatrix operator*(const VMatrix &aMatrix) const;
77 private:
78  unsigned int numRows;
79  std::vector<double> theVec;
80 };
81 
83 inline double &VMatrix::operator()(unsigned int iRow, unsigned int iCol) {
84  return theVec[numCols * iRow + iCol];
85 }
86 
88 inline double VMatrix::operator()(unsigned int iRow, unsigned int iCol) const {
89  return theVec[numCols * iRow + iCol];
90 }
91 
93 inline double &VVector::operator()(unsigned int iRow) {
94  return theVec[iRow];
95 }
96 
98 inline double VVector::operator()(unsigned int iRow) const {
99  return theVec[iRow];
100 }
101 
103 inline double &VSymMatrix::operator()(unsigned int iRow, unsigned int iCol) {
104  return theVec[(iRow * iRow + iRow) / 2 + iCol]; // assuming iCol <= iRow
105 }
106 
108 inline double VSymMatrix::operator()(unsigned int iRow,
109  unsigned int iCol) const {
110  return theVec[(iRow * iRow + iRow) / 2 + iCol]; // assuming iCol <= iRow
111 }
112 }
113 #endif /* VMATRIX_H_ */
VVector getVec(unsigned int len, unsigned int start=0) const
Get part of vector.
Definition: VMatrix.cc:251
int i
Definition: DBlmapReader.cc:9
void print() const
Print matrix.
Definition: VMatrix.cc:167
tuple start
Check for commandline option errors.
Definition: dqm_diff.py:58
unsigned int getNumRows() const
Get number of rows.
Definition: VMatrix.cc:57
double & operator()(unsigned int i, unsigned int j)
access element (i,j)
Definition: VMatrix.h:83
VVector operator*(const VVector &aVector) const
Multiplication Matrix*Vector.
Definition: VMatrix.cc:86
Simple Matrix based on std::vector&lt;double&gt;
Definition: VMatrix.h:41
VVector(const unsigned int nRows=0)
Definition: VMatrix.cc:224
VVector operator*(const VVector &aVector) const
Multiplication SymMatrix*Vector.
Definition: VMatrix.cc:194
unsigned int invert()
Matrix inversion.
Definition: VMatrix.cc:326
void print() const
Print vector.
Definition: VMatrix.cc:276
void putVec(const VVector &aVector, unsigned int start=0)
Put part of vector.
Definition: VMatrix.cc:262
void resize(const unsigned int nRows, const unsigned int nCols)
Resize Matrix.
Definition: VMatrix.cc:33
unsigned int numCols
Number of columns.
Definition: VMatrix.h:59
VVector operator-(const VVector &aVector) const
Subtraction Vector-Vector.
Definition: VMatrix.cc:290
unsigned int getNumRows() const
Get number of rows.
Definition: VMatrix.cc:271
void resize(const unsigned int nRows)
Resize symmetric matrix.
Definition: VMatrix.cc:153
virtual ~VMatrix()
Definition: VMatrix.cc:25
double & operator()(unsigned int i, unsigned int j)
access element (i,j) assuming i&gt;=j
Definition: VMatrix.h:103
VMatrix transpose() const
Get transposed matrix.
Definition: VMatrix.cc:43
VSymMatrix(const unsigned int nRows=0)
Definition: VMatrix.cc:142
void resize(const unsigned int nRows)
Resize vector.
Definition: VMatrix.cc:240
unsigned int numRows
Number of rows.
Definition: VMatrix.h:58
int j
Definition: DBlmapReader.cc:9
Simple symmetric Matrix based on std::vector&lt;double&gt;
Definition: VMatrix.h:64
double & operator()(unsigned int i)
access element (i)
Definition: VMatrix.h:93
VMatrix & operator=(const VMatrix &aMatrix)
Assignment Matrix=Matrix.
Definition: VMatrix.cc:126
unsigned int numRows
Number of rows.
Definition: VMatrix.h:78
VVector & operator=(const VVector &aVector)
Assignment Vector=Vector.
Definition: VMatrix.cc:299
void print() const
Print matrix.
Definition: VMatrix.cc:70
std::vector< double > theVec
Data (symmetric storage)
Definition: VMatrix.h:79
unsigned int getNumCols() const
Get number of columns.
Definition: VMatrix.cc:65
Simple Vector based on std::vector&lt;double&gt;
Definition: VMatrix.h:21
unsigned int getNumRows() const
Get number of rows (= number of colums).
Definition: VMatrix.cc:162
std::vector< double > theVec
Data.
Definition: VMatrix.h:60
std::vector< double > theVec
Data.
Definition: VMatrix.h:37
VMatrix(const unsigned int nRows=0, const unsigned int nCols=0)
Definition: VMatrix.cc:15
virtual ~VVector()
Definition: VMatrix.cc:233
unsigned int numRows
Number of rows.
Definition: VMatrix.h:36
virtual ~VSymMatrix()
Definition: VMatrix.cc:146
VMatrix operator+(const VMatrix &aMatrix) const
Addition Matrix+Matrix.
Definition: VMatrix.cc:115
VSymMatrix operator-(const VMatrix &aMatrix) const
Subtraction SymMatrix-(sym)Matrix.
Definition: VMatrix.cc:183