GeneralBrokenLines V03-01-03
using EIGEN
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
40namespace gbl {
41
43class VVector {
44public:
45 VVector(const unsigned int nRows = 0);
46 VVector(const VVector &aVector);
47 virtual ~VVector();
48 void resize(const unsigned int nRows);
49 void setZero();
50 VVector getVec(unsigned int len, unsigned int start = 0) const;
51 void putVec(const VVector &aVector, unsigned int start = 0);
52 inline double &operator()(unsigned int i);
53 inline double operator()(unsigned int i) const;
54 unsigned int getNumRows() const;
55 void print() const;
56 VVector operator-(const VVector &aVector) const;
57 VVector &operator=(const VVector &aVector);
58private:
59 unsigned int numRows;
60 std::vector<double> theVec;
61};
62
64class VMatrix {
65public:
66 VMatrix(const unsigned int nRows = 0, const unsigned int nCols = 0);
67 VMatrix(const VMatrix &aMatrix);
68 virtual ~VMatrix();
69 void resize(const unsigned int nRows, const unsigned int nCols);
70 void setZero();
71 VMatrix transpose() const;
72 inline double &operator()(unsigned int i, unsigned int j);
73 inline double operator()(unsigned int i, unsigned int j) const;
74 unsigned int getNumRows() const;
75 unsigned int getNumCols() const;
76 void print() const;
77 VVector operator*(const VVector &aVector) const;
78 VMatrix operator*(const VMatrix &aMatrix) const;
79 VMatrix operator+(const VMatrix &aMatrix) const;
80 VMatrix &operator=(const VMatrix &aMatrix);
81private:
82 unsigned int numRows;
83 unsigned int numCols;
84 std::vector<double> theVec;
85};
86
89public:
90 VSymMatrix(const unsigned int nRows = 0);
91 virtual ~VSymMatrix();
92 void resize(const unsigned int nRows);
93 void setZero();
94 unsigned int invert();
95 inline double &operator()(unsigned int i, unsigned int j);
96 inline double operator()(unsigned int i, unsigned int j) const;
97 unsigned int getNumRows() const;
98 void print() const;
99 VSymMatrix operator-(const VMatrix &aMatrix) const;
100 VVector operator*(const VVector &aVector) const;
101 VMatrix operator*(const VMatrix &aMatrix) const;
102private:
103 unsigned int numRows;
104 std::vector<double> theVec;
105};
106
108inline double &VMatrix::operator()(unsigned int iRow, unsigned int iCol) {
109 return theVec[numCols * iRow + iCol];
110}
111
113inline double VMatrix::operator()(unsigned int iRow, unsigned int iCol) const {
114 return theVec[numCols * iRow + iCol];
115}
116
118inline double &VVector::operator()(unsigned int iRow) {
119 return theVec[iRow];
120}
121
123inline double VVector::operator()(unsigned int iRow) const {
124 return theVec[iRow];
125}
126
128inline double &VSymMatrix::operator()(unsigned int iRow, unsigned int iCol) {
129 return theVec[(iRow * iRow + iRow) / 2 + iCol]; // assuming iCol <= iRow
130}
131
133inline double VSymMatrix::operator()(unsigned int iRow,
134 unsigned int iCol) const {
135 return theVec[(iRow * iRow + iRow) / 2 + iCol]; // assuming iCol <= iRow
136}
137}
138#endif /* VMATRIX_H_ */
Simple Matrix based on std::vector<double>
Definition: VMatrix.h:64
unsigned int getNumCols() const
Get number of columns.
Definition: VMatrix.cpp:92
VMatrix transpose() const
Get transposed matrix.
Definition: VMatrix.cpp:70
VVector operator*(const VVector &aVector) const
Multiplication Matrix*Vector.
Definition: VMatrix.cpp:113
unsigned int numRows
Number of rows.
Definition: VMatrix.h:82
unsigned int getNumRows() const
Get number of rows.
Definition: VMatrix.cpp:84
void resize(const unsigned int nRows, const unsigned int nCols)
Resize Matrix.
Definition: VMatrix.cpp:55
VMatrix operator+(const VMatrix &aMatrix) const
Addition Matrix+Matrix.
Definition: VMatrix.cpp:142
unsigned int numCols
Number of columns.
Definition: VMatrix.h:83
VMatrix & operator=(const VMatrix &aMatrix)
Assignment Matrix=Matrix.
Definition: VMatrix.cpp:153
VMatrix(const unsigned int nRows=0, const unsigned int nCols=0)
Definition: VMatrix.cpp:37
std::vector< double > theVec
Data.
Definition: VMatrix.h:84
double & operator()(unsigned int i, unsigned int j)
access element (i,j)
Definition: VMatrix.h:108
void print() const
Print matrix.
Definition: VMatrix.cpp:97
virtual ~VMatrix()
Definition: VMatrix.cpp:47
void setZero()
Set content to 0.
Definition: VMatrix.cpp:62
Simple symmetric Matrix based on std::vector<double>
Definition: VMatrix.h:88
VSymMatrix(const unsigned int nRows=0)
Definition: VMatrix.cpp:169
VVector operator*(const VVector &aVector) const
Multiplication SymMatrix*Vector.
Definition: VMatrix.cpp:226
void print() const
Print matrix.
Definition: VMatrix.cpp:199
double & operator()(unsigned int i, unsigned int j)
access element (i,j) assuming i>=j
Definition: VMatrix.h:128
unsigned int invert()
Matrix inversion.
Definition: VMatrix.cpp:363
unsigned int getNumRows() const
Get number of rows (= number of colums).
Definition: VMatrix.cpp:194
std::vector< double > theVec
Data (symmetric storage)
Definition: VMatrix.h:104
unsigned int numRows
Number of rows.
Definition: VMatrix.h:103
void resize(const unsigned int nRows)
Resize symmetric matrix.
Definition: VMatrix.cpp:180
virtual ~VSymMatrix()
Definition: VMatrix.cpp:173
VSymMatrix operator-(const VMatrix &aMatrix) const
Subtraction SymMatrix-(sym)Matrix.
Definition: VMatrix.cpp:215
void setZero()
Set content to 0.
Definition: VMatrix.cpp:186
Simple Vector based on std::vector<double>
Definition: VMatrix.h:43
virtual ~VVector()
Definition: VMatrix.cpp:265
void putVec(const VVector &aVector, unsigned int start=0)
Put part of vector.
Definition: VMatrix.cpp:299
std::vector< double > theVec
Data.
Definition: VMatrix.h:60
VVector getVec(unsigned int len, unsigned int start=0) const
Get part of vector.
Definition: VMatrix.cpp:288
VVector operator-(const VVector &aVector) const
Subtraction Vector-Vector.
Definition: VMatrix.cpp:327
void setZero()
Set content to 0.
Definition: VMatrix.cpp:278
void resize(const unsigned int nRows)
Resize vector.
Definition: VMatrix.cpp:272
VVector(const unsigned int nRows=0)
Definition: VMatrix.cpp:256
unsigned int numRows
Number of rows.
Definition: VMatrix.h:59
double & operator()(unsigned int i)
access element (i)
Definition: VMatrix.h:118
void print() const
Print vector.
Definition: VMatrix.cpp:313
VVector & operator=(const VVector &aVector)
Assignment Vector=Vector.
Definition: VMatrix.cpp:336
unsigned int getNumRows() const
Get number of rows.
Definition: VMatrix.cpp:308
Namespace for the general broken lines package.