Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
VMatrix.h
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file VMatrix.h
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_ */