SND@LHC Software
Loading...
Searching...
No Matches
gbl::VMatrix Class Reference

Simple Matrix based on std::vector<double> More...

#include <VMatrix.h>

Public Member Functions

 VMatrix (const unsigned int nRows=0, const unsigned int nCols=0)
 
 VMatrix (const VMatrix &aMatrix)
 
virtual ~VMatrix ()
 
void resize (const unsigned int nRows, const unsigned int nCols)
 Resize Matrix.
 
VMatrix transpose () const
 Get transposed matrix.
 
double & operator() (unsigned int i, unsigned int j)
 access element (i,j)
 
double operator() (unsigned int i, unsigned int j) const
 access element (i,j)
 
unsigned int getNumRows () const
 Get number of rows.
 
unsigned int getNumCols () const
 Get number of columns.
 
void print () const
 Print matrix.
 
VVector operator* (const VVector &aVector) const
 Multiplication Matrix*Vector.
 
VMatrix operator* (const VMatrix &aMatrix) const
 Multiplication Matrix*Matrix.
 
VMatrix operator+ (const VMatrix &aMatrix) const
 Addition Matrix+Matrix.
 
VMatrixoperator= (const VMatrix &aMatrix)
 Assignment Matrix=Matrix.
 

Private Attributes

unsigned int numRows
 Number of rows.
 
unsigned int numCols
 Number of columns.
 
std::vector< double > theVec
 Data.
 

Detailed Description

Simple Matrix based on std::vector<double>

Definition at line 42 of file VMatrix.h.

Constructor & Destructor Documentation

◆ VMatrix() [1/2]

gbl::VMatrix::VMatrix ( const unsigned int  nRows = 0,
const unsigned int  nCols = 0 
)

Definition at line 15 of file VMatrix.cc.

15 :
16 numRows(nRows), numCols(nCols), theVec(nRows * nCols) {
17}
unsigned int numRows
Number of rows.
Definition VMatrix.h:59
unsigned int numCols
Number of columns.
Definition VMatrix.h:60
std::vector< double > theVec
Data.
Definition VMatrix.h:61

◆ VMatrix() [2/2]

gbl::VMatrix::VMatrix ( const VMatrix aMatrix)

Definition at line 19 of file VMatrix.cc.

19 :
20 numRows(aMatrix.numRows), numCols(aMatrix.numCols), theVec(
21 aMatrix.theVec) {
22
23}

◆ ~VMatrix()

gbl::VMatrix::~VMatrix ( )
virtual

Definition at line 25 of file VMatrix.cc.

25 {
26}

Member Function Documentation

◆ getNumCols()

unsigned int gbl::VMatrix::getNumCols ( ) const

Get number of columns.

Returns
Number of columns.

Definition at line 65 of file VMatrix.cc.

65 {
66 return numCols;
67}

◆ getNumRows()

unsigned int gbl::VMatrix::getNumRows ( ) const

Get number of rows.

Returns
Number of rows.

Definition at line 57 of file VMatrix.cc.

57 {
58 return numRows;
59}

◆ operator()() [1/2]

double & gbl::VMatrix::operator() ( unsigned int  i,
unsigned int  j 
)
inline

access element (i,j)

Definition at line 84 of file VMatrix.h.

84 {
85 return theVec[numCols * iRow + iCol];
86}

◆ operator()() [2/2]

double gbl::VMatrix::operator() ( unsigned int  i,
unsigned int  j 
) const
inline

access element (i,j)

Definition at line 89 of file VMatrix.h.

89 {
90 return theVec[numCols * iRow + iCol];
91}

◆ operator*() [1/2]

VMatrix gbl::VMatrix::operator* ( const VMatrix aMatrix) const

Multiplication Matrix*Matrix.

Definition at line 99 of file VMatrix.cc.

99 {
100
101 VMatrix aResult(numRows, aMatrix.numCols);
102 for (unsigned int i = 0; i < numRows; ++i) {
103 for (unsigned int j = 0; j < aMatrix.numCols; ++j) {
104 double sum = 0.0;
105 for (unsigned int k = 0; k < numCols; ++k) {
106 sum += theVec[numCols * i + k] * aMatrix(k, j);
107 }
108 aResult(i, j) = sum;
109 }
110 }
111 return aResult;
112}
VMatrix(const unsigned int nRows=0, const unsigned int nCols=0)
Definition VMatrix.cc:15
int i
Definition ShipAna.py:86

◆ operator*() [2/2]

VVector gbl::VMatrix::operator* ( const VVector aVector) const

Multiplication Matrix*Vector.

Definition at line 86 of file VMatrix.cc.

86 {
87 VVector aResult(numRows);
88 for (unsigned int i = 0; i < this->numRows; ++i) {
89 double sum = 0.0;
90 for (unsigned int j = 0; j < this->numCols; ++j) {
91 sum += theVec[numCols * i + j] * aVector(j);
92 }
93 aResult(i) = sum;
94 }
95 return aResult;
96}

◆ operator+()

VMatrix gbl::VMatrix::operator+ ( const VMatrix aMatrix) const

Addition Matrix+Matrix.

Definition at line 115 of file VMatrix.cc.

115 {
116 VMatrix aResult(numRows, numCols);
117 for (unsigned int i = 0; i < numRows; ++i) {
118 for (unsigned int j = 0; j < numCols; ++j) {
119 aResult(i, j) = theVec[numCols * i + j] + aMatrix(i, j);
120 }
121 }
122 return aResult;
123}

◆ operator=()

VMatrix & gbl::VMatrix::operator= ( const VMatrix aMatrix)

Assignment Matrix=Matrix.

Definition at line 126 of file VMatrix.cc.

126 {
127 if (this != &aMatrix) { // Gracefully handle self assignment
128 numRows = aMatrix.getNumRows();
129 numCols = aMatrix.getNumCols();
130 theVec.resize(numRows * numCols);
131 for (unsigned int i = 0; i < numRows; ++i) {
132 for (unsigned int j = 0; j < numCols; ++j) {
133 theVec[numCols * i + j] = aMatrix(i, j);
134 }
135 }
136 }
137 return *this;
138}

◆ print()

void gbl::VMatrix::print ( ) const

Print matrix.

Definition at line 70 of file VMatrix.cc.

70 {
71 std::cout << " VMatrix: " << numRows << "*" << numCols << std::endl;
72 for (unsigned int i = 0; i < numRows; ++i) {
73 for (unsigned int j = 0; j < numCols; ++j) {
74 if (j % 5 == 0) {
75 std::cout << std::endl << std::setw(4) << i << ","
76 << std::setw(4) << j << "-" << std::setw(4)
77 << std::min(j + 4, numCols) << ":";
78 }
79 std::cout << std::setw(13) << theVec[numCols * i + j];
80 }
81 }
82 std::cout << std::endl << std::endl;
83}

◆ resize()

void gbl::VMatrix::resize ( const unsigned int  nRows,
const unsigned int  nCols 
)

Resize Matrix.

Parameters
[in]nRowsNumber of rows.
[in]nColsNumber of columns.

Definition at line 33 of file VMatrix.cc.

33 {
34 numRows = nRows;
35 numCols = nCols;
36 theVec.resize(nRows * nCols);
37}

◆ transpose()

VMatrix gbl::VMatrix::transpose ( ) const

Get transposed matrix.

Returns
Transposed matrix.

Definition at line 43 of file VMatrix.cc.

43 {
44 VMatrix aResult(numCols, numRows);
45 for (unsigned int i = 0; i < numRows; ++i) {
46 for (unsigned int j = 0; j < numCols; ++j) {
47 aResult(j, i) = theVec[numCols * i + j];
48 }
49 }
50 return aResult;
51}

Member Data Documentation

◆ numCols

unsigned int gbl::VMatrix::numCols
private

Number of columns.

Definition at line 60 of file VMatrix.h.

◆ numRows

unsigned int gbl::VMatrix::numRows
private

Number of rows.

Definition at line 59 of file VMatrix.h.

◆ theVec

std::vector<double> gbl::VMatrix::theVec
private

Data.

Definition at line 61 of file VMatrix.h.


The documentation for this class was generated from the following files: