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 
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_ */
Definition: start.py:1
VVector getVec(unsigned int len, unsigned int start=0) const
Get part of vector.
Definition: VMatrix.cc:251
int i
Definition: DBlmapReader.cc:9
def transpose(a)
Definition: geometryDiff.py:37
double & operator()(unsigned int i, unsigned int j)
access element (i,j)
Definition: VMatrix.h:83
Simple Matrix based on std::vector<double>
Definition: VMatrix.h:41
MatrixMeschach operator+(const MatrixMeschach &mat1, const MatrixMeschach &mat2)
VVector(const unsigned int nRows=0)
Definition: VMatrix.cc:224
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
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
double & operator()(unsigned int i, unsigned int j)
access element (i,j) assuming i>=j
Definition: VMatrix.h:103
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
Namespace for the general broken lines package.
Simple symmetric Matrix based on std::vector<double>
Definition: VMatrix.h:64
double & operator()(unsigned int i)
access element (i)
Definition: VMatrix.h:93
unsigned int numRows
Number of rows.
Definition: VMatrix.h:78
VVector & operator=(const VVector &aVector)
Assignment Vector=Vector.
Definition: VMatrix.cc:299
std::vector< double > theVec
Data (symmetric storage)
Definition: VMatrix.h:79
Simple Vector based on std::vector<double>
Definition: VMatrix.h:21
MatrixMeschach operator*(const MatrixMeschach &mat1, const MatrixMeschach &mat2)
std::vector< double > theVec
Data.
Definition: VMatrix.h:60
std::vector< double > theVec
Data.
Definition: VMatrix.h:37
virtual ~VVector()
Definition: VMatrix.cc:233
unsigned int numRows
Number of rows.
Definition: VMatrix.h:36