test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Private Attributes
gbl::VMatrix Class Reference

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

#include <VMatrix.h>

Public Member Functions

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

Private Attributes

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

Detailed Description

Simple Matrix based on std::vector<double>

Definition at line 41 of file VMatrix.h.

Constructor & Destructor Documentation

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 numCols
Number of columns.
Definition: VMatrix.h:59
unsigned int numRows
Number of rows.
Definition: VMatrix.h:58
std::vector< double > theVec
Data.
Definition: VMatrix.h:60
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 }
unsigned int numCols
Number of columns.
Definition: VMatrix.h:59
unsigned int numRows
Number of rows.
Definition: VMatrix.h:58
std::vector< double > theVec
Data.
Definition: VMatrix.h:60
gbl::VMatrix::~VMatrix ( )
virtual

Definition at line 25 of file VMatrix.cc.

25  {
26 }

Member Function Documentation

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

Get number of columns.

Returns
Number of columns.

Definition at line 65 of file VMatrix.cc.

References numCols.

Referenced by gbl::VSymMatrix::operator*(), operator=(), and gbl::BorderedBandMatrix::solveBand().

65  {
66  return numCols;
67 }
unsigned int numCols
Number of columns.
Definition: VMatrix.h:59
unsigned int gbl::VMatrix::getNumRows ( ) const

Get number of rows.

Returns
Number of rows.

Definition at line 57 of file VMatrix.cc.

References numRows.

Referenced by operator=(), and gbl::BorderedBandMatrix::solveBand().

57  {
58  return numRows;
59 }
unsigned int numRows
Number of rows.
Definition: VMatrix.h:58
double & gbl::VMatrix::operator() ( unsigned int  i,
unsigned int  j 
)
inline

access element (i,j)

Definition at line 83 of file VMatrix.h.

References numCols, and theVec.

83  {
84  return theVec[numCols * iRow + iCol];
85 }
unsigned int numCols
Number of columns.
Definition: VMatrix.h:59
std::vector< double > theVec
Data.
Definition: VMatrix.h:60
double gbl::VMatrix::operator() ( unsigned int  i,
unsigned int  j 
) const
inline

access element (i,j)

Definition at line 88 of file VMatrix.h.

References numCols, and theVec.

88  {
89  return theVec[numCols * iRow + iCol];
90 }
unsigned int numCols
Number of columns.
Definition: VMatrix.h:59
std::vector< double > theVec
Data.
Definition: VMatrix.h:60
VVector gbl::VMatrix::operator* ( const VVector aVector) const

Multiplication Matrix*Vector.

Definition at line 86 of file VMatrix.cc.

References i, j, numCols, numRows, and theVec.

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 }
int i
Definition: DBlmapReader.cc:9
unsigned int numCols
Number of columns.
Definition: VMatrix.h:59
unsigned int numRows
Number of rows.
Definition: VMatrix.h:58
int j
Definition: DBlmapReader.cc:9
std::vector< double > theVec
Data.
Definition: VMatrix.h:60
VMatrix gbl::VMatrix::operator* ( const VMatrix aMatrix) const

Multiplication Matrix*Matrix.

Definition at line 99 of file VMatrix.cc.

References i, j, relval_2017::k, numCols, numRows, and theVec.

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 }
int i
Definition: DBlmapReader.cc:9
unsigned int numCols
Number of columns.
Definition: VMatrix.h:59
unsigned int numRows
Number of rows.
Definition: VMatrix.h:58
int j
Definition: DBlmapReader.cc:9
std::vector< double > theVec
Data.
Definition: VMatrix.h:60
VMatrix(const unsigned int nRows=0, const unsigned int nCols=0)
Definition: VMatrix.cc:15
VMatrix gbl::VMatrix::operator+ ( const VMatrix aMatrix) const

Addition Matrix+Matrix.

Definition at line 115 of file VMatrix.cc.

References i, j, numCols, numRows, and theVec.

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 }
int i
Definition: DBlmapReader.cc:9
unsigned int numCols
Number of columns.
Definition: VMatrix.h:59
unsigned int numRows
Number of rows.
Definition: VMatrix.h:58
int j
Definition: DBlmapReader.cc:9
std::vector< double > theVec
Data.
Definition: VMatrix.h:60
VMatrix(const unsigned int nRows=0, const unsigned int nCols=0)
Definition: VMatrix.cc:15
VMatrix & gbl::VMatrix::operator= ( const VMatrix aMatrix)

Assignment Matrix=Matrix.

Definition at line 126 of file VMatrix.cc.

References getNumCols(), getNumRows(), i, j, numCols, numRows, and theVec.

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 }
int i
Definition: DBlmapReader.cc:9
unsigned int numCols
Number of columns.
Definition: VMatrix.h:59
unsigned int numRows
Number of rows.
Definition: VMatrix.h:58
int j
Definition: DBlmapReader.cc:9
std::vector< double > theVec
Data.
Definition: VMatrix.h:60
void gbl::VMatrix::print ( void  ) const

Print matrix.

Definition at line 70 of file VMatrix.cc.

References gather_cfg::cout, i, j, min(), numCols, numRows, and theVec.

Referenced by gbl::BorderedBandMatrix::printMatrix().

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 }
int i
Definition: DBlmapReader.cc:9
unsigned int numCols
Number of columns.
Definition: VMatrix.h:59
unsigned int numRows
Number of rows.
Definition: VMatrix.h:58
int j
Definition: DBlmapReader.cc:9
T min(T a, T b)
Definition: MathUtil.h:58
tuple cout
Definition: gather_cfg.py:145
std::vector< double > theVec
Data.
Definition: VMatrix.h:60
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.

References numCols, numRows, and theVec.

Referenced by Vispa.Gui.TextDialog.TextDialog::__init__(), Vispa.Plugins.ConfigEditor.ToolDialog.ToolDialog::__init__(), Vispa.Main.MainWindow.MainWindow::_loadIni(), gbl::BorderedBandMatrix::resize(), and Vispa.Gui.PortConnection.PointToPointConnection::updateConnection().

33  {
34  numRows = nRows;
35  numCols = nCols;
36  theVec.resize(nRows * nCols);
37 }
unsigned int numCols
Number of columns.
Definition: VMatrix.h:59
unsigned int numRows
Number of rows.
Definition: VMatrix.h:58
std::vector< double > theVec
Data.
Definition: VMatrix.h:60
VMatrix gbl::VMatrix::transpose ( ) const

Get transposed matrix.

Returns
Transposed matrix.

Definition at line 43 of file VMatrix.cc.

References i, j, numCols, numRows, and theVec.

Referenced by gbl::BorderedBandMatrix::solveAndInvertBorderedBand().

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 }
int i
Definition: DBlmapReader.cc:9
unsigned int numCols
Number of columns.
Definition: VMatrix.h:59
unsigned int numRows
Number of rows.
Definition: VMatrix.h:58
int j
Definition: DBlmapReader.cc:9
std::vector< double > theVec
Data.
Definition: VMatrix.h:60
VMatrix(const unsigned int nRows=0, const unsigned int nCols=0)
Definition: VMatrix.cc:15

Member Data Documentation

unsigned int gbl::VMatrix::numCols
private

Number of columns.

Definition at line 59 of file VMatrix.h.

Referenced by getNumCols(), operator()(), operator*(), operator+(), operator=(), print(), resize(), and transpose().

unsigned int gbl::VMatrix::numRows
private

Number of rows.

Definition at line 58 of file VMatrix.h.

Referenced by getNumRows(), operator*(), operator+(), operator=(), print(), resize(), and transpose().

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

Data.

Definition at line 60 of file VMatrix.h.

Referenced by operator()(), operator*(), operator+(), operator=(), print(), resize(), and transpose().