CMS 3D CMS Logo

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 63 of file VMatrix.h.

Constructor & Destructor Documentation

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

Definition at line 37 of file VMatrix.cc.

37  :
38  numRows(nRows), numCols(nCols), theVec(nRows * nCols)
39  {
40  }
unsigned int numCols
Number of columns.
Definition: VMatrix.h:81
unsigned int numRows
Number of rows.
Definition: VMatrix.h:80
std::vector< double > theVec
Data.
Definition: VMatrix.h:82
gbl::VMatrix::VMatrix ( const VMatrix aMatrix)

Definition at line 42 of file VMatrix.cc.

42  :
43  numRows(aMatrix.numRows), numCols(aMatrix.numCols), theVec(aMatrix.theVec)
44  {
45  }
unsigned int numCols
Number of columns.
Definition: VMatrix.h:81
unsigned int numRows
Number of rows.
Definition: VMatrix.h:80
std::vector< double > theVec
Data.
Definition: VMatrix.h:82
gbl::VMatrix::~VMatrix ( )
virtual

Definition at line 47 of file VMatrix.cc.

47  {
48  }

Member Function Documentation

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

Get number of columns.

Returns
Number of columns.

Definition at line 87 of file VMatrix.cc.

References numCols.

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

87  {
88  return numCols;
89  }
unsigned int numCols
Number of columns.
Definition: VMatrix.h:81
unsigned int gbl::VMatrix::getNumRows ( ) const

Get number of rows.

Returns
Number of rows.

Definition at line 79 of file VMatrix.cc.

References numRows.

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

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

access element (i,j)

Definition at line 105 of file VMatrix.h.

References gbl::VVector::theVec.

105  {
106  return theVec[numCols * iRow + iCol];
107  }
unsigned int numCols
Number of columns.
Definition: VMatrix.h:81
std::vector< double > theVec
Data.
Definition: VMatrix.h:82
double gbl::VMatrix::operator() ( unsigned int  i,
unsigned int  j 
) const
inline

access element (i,j)

Definition at line 110 of file VMatrix.h.

References gbl::VVector::theVec.

110  {
111  return theVec[numCols * iRow + iCol];
112  }
unsigned int numCols
Number of columns.
Definition: VMatrix.h:81
std::vector< double > theVec
Data.
Definition: VMatrix.h:82
VVector gbl::VMatrix::operator* ( const VVector aVector) const

Multiplication Matrix*Vector.

Definition at line 108 of file VMatrix.cc.

References mps_fire::i, numCols, numRows, and theVec.

108  {
109  VVector aResult(numRows);
110  for (unsigned int i = 0; i < this->numRows; ++i) {
111  double sum = 0.0;
112  for (unsigned int j = 0; j < this->numCols; ++j) {
113  sum += theVec[numCols * i + j] * aVector(j);
114  }
115  aResult(i) = sum;
116  }
117  return aResult;
118  }
unsigned int numCols
Number of columns.
Definition: VMatrix.h:81
unsigned int numRows
Number of rows.
Definition: VMatrix.h:80
std::vector< double > theVec
Data.
Definition: VMatrix.h:82
VMatrix gbl::VMatrix::operator* ( const VMatrix aMatrix) const

Multiplication Matrix*Matrix.

Definition at line 121 of file VMatrix.cc.

References mps_fire::i, gen::k, numCols, numRows, and theVec.

121  {
122 
123  VMatrix aResult(numRows, aMatrix.numCols);
124  for (unsigned int i = 0; i < numRows; ++i) {
125  for (unsigned int j = 0; j < aMatrix.numCols; ++j) {
126  double sum = 0.0;
127  for (unsigned int k = 0; k < numCols; ++k) {
128  sum += theVec[numCols * i + k] * aMatrix(k, j);
129  }
130  aResult(i, j) = sum;
131  }
132  }
133  return aResult;
134  }
unsigned int numCols
Number of columns.
Definition: VMatrix.h:81
unsigned int numRows
Number of rows.
Definition: VMatrix.h:80
int k[5][pyjets_maxn]
std::vector< double > theVec
Data.
Definition: VMatrix.h:82
VMatrix(const unsigned int nRows=0, const unsigned int nCols=0)
Definition: VMatrix.cc:37
VMatrix gbl::VMatrix::operator+ ( const VMatrix aMatrix) const

Addition Matrix+Matrix.

Definition at line 137 of file VMatrix.cc.

References mps_fire::i, numCols, numRows, and theVec.

137  {
138  VMatrix aResult(numRows, numCols);
139  for (unsigned int i = 0; i < numRows; ++i) {
140  for (unsigned int j = 0; j < numCols; ++j) {
141  aResult(i, j) = theVec[numCols * i + j] + aMatrix(i, j);
142  }
143  }
144  return aResult;
145  }
unsigned int numCols
Number of columns.
Definition: VMatrix.h:81
unsigned int numRows
Number of rows.
Definition: VMatrix.h:80
std::vector< double > theVec
Data.
Definition: VMatrix.h:82
VMatrix(const unsigned int nRows=0, const unsigned int nCols=0)
Definition: VMatrix.cc:37
VMatrix & gbl::VMatrix::operator= ( const VMatrix aMatrix)

Assignment Matrix=Matrix.

Definition at line 148 of file VMatrix.cc.

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

148  {
149  if (this != &aMatrix) { // Gracefully handle self assignment
150  numRows = aMatrix.getNumRows();
151  numCols = aMatrix.getNumCols();
152  theVec.resize(numRows * numCols);
153  for (unsigned int i = 0; i < numRows; ++i) {
154  for (unsigned int j = 0; j < numCols; ++j) {
155  theVec[numCols * i + j] = aMatrix(i, j);
156  }
157  }
158  }
159  return *this;
160  }
unsigned int numCols
Number of columns.
Definition: VMatrix.h:81
unsigned int numRows
Number of rows.
Definition: VMatrix.h:80
std::vector< double > theVec
Data.
Definition: VMatrix.h:82
void gbl::VMatrix::print ( void  ) const

Print matrix.

Definition at line 92 of file VMatrix.cc.

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

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

92  {
93  std::cout << " VMatrix: " << numRows << "*" << numCols << std::endl;
94  for (unsigned int i = 0; i < numRows; ++i) {
95  for (unsigned int j = 0; j < numCols; ++j) {
96  if (j % 5 == 0) {
97  std::cout << std::endl << std::setw(4) << i << ","
98  << std::setw(4) << j << "-" << std::setw(4)
99  << std::min(j + 4, numCols) << ":";
100  }
101  std::cout << std::setw(13) << theVec[numCols * i + j];
102  }
103  }
104  std::cout << std::endl << std::endl;
105  }
unsigned int numCols
Number of columns.
Definition: VMatrix.h:81
unsigned int numRows
Number of rows.
Definition: VMatrix.h:80
T min(T a, T b)
Definition: MathUtil.h:58
std::vector< double > theVec
Data.
Definition: VMatrix.h:82
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 55 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().

55  {
56  numRows = nRows;
57  numCols = nCols;
58  theVec.resize(nRows * nCols);
59  }
unsigned int numCols
Number of columns.
Definition: VMatrix.h:81
unsigned int numRows
Number of rows.
Definition: VMatrix.h:80
std::vector< double > theVec
Data.
Definition: VMatrix.h:82
VMatrix gbl::VMatrix::transpose ( ) const

Get transposed matrix.

Returns
Transposed matrix.

Definition at line 65 of file VMatrix.cc.

References mps_fire::i, numCols, numRows, and theVec.

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

65  {
66  VMatrix aResult(numCols, numRows);
67  for (unsigned int i = 0; i < numRows; ++i) {
68  for (unsigned int j = 0; j < numCols; ++j) {
69  aResult(j, i) = theVec[numCols * i + j];
70  }
71  }
72  return aResult;
73  }
unsigned int numCols
Number of columns.
Definition: VMatrix.h:81
unsigned int numRows
Number of rows.
Definition: VMatrix.h:80
std::vector< double > theVec
Data.
Definition: VMatrix.h:82
VMatrix(const unsigned int nRows=0, const unsigned int nCols=0)
Definition: VMatrix.cc:37

Member Data Documentation

unsigned int gbl::VMatrix::numCols
private

Number of columns.

Definition at line 81 of file VMatrix.h.

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

unsigned int gbl::VMatrix::numRows
private

Number of rows.

Definition at line 80 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 82 of file VMatrix.h.

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