FEDRA emulsion software from the OPERA Collaboration
MATRIX::VtMatrix Class Reference

#include <VtMatrix.hh>

Inheritance diagram for MATRIX::VtMatrix:

Classes

class  VtMatrix_row
 
class  VtMatrix_row_const
 

Public Member Functions

— Constructors —
 VtMatrix (const unsigned int row, const unsigned int col)
 
 VtMatrix (const VtMatrix &rhs)
 
virtual ~VtMatrix ()
 
— Access functions —
unsigned int nrow () const
 no of rows $n$ More...
 
unsigned int ncol () const
 no of columns $m$ More...
 
int size () const
 $m\times n$ More...
 
VtMatrix_row operator[] (int row)
 
VtMatrix_row_const operator[] (int row) const
 
virtual double operator() (unsigned int row, unsigned int col) const
 
virtual double & operator() (const unsigned int row, const unsigned int col)
 
double get (unsigned int row, unsigned int col) const
 
double & get (unsigned int row, unsigned int col)
 
— Matrix operations —
void VtT (void)
 transform into transpose matrix More...
 
const VtMatrix T (void) const
 return transpose More...
 
virtual void place_at (const VtMatrix &rhs, const unsigned int row, const unsigned int col)
 copy a smaller matrix at a certain place More...
 
virtual void place_at (const VtVector &rhs, const unsigned int row, const unsigned int col)
 copy a vector at a certain place More...
 
void copy (const VtMatrix &rhs)
 to be used if matrix dimensions are not equal More...
 
void clear (void)
 set matrix elements to 0 More...
 
const VtMatrixoperator= (const VtMatrix &rhs)
 $\textbf{A} = \textbf{B}$ More...
 
const VtMatrixoperator= (const VtNegMatrix &rhs)
 
virtual const VtMatrixoperator+= (const double rhs)
 $\textbf{A} = (a_{\mu\nu} + \alpha)$ More...
 
virtual const VtMatrixoperator-= (const double rhs)
 $\textbf{A} = (a_{\mu\nu} - \alpha)$ More...
 
virtual const VtMatrixoperator*= (const double rhs)
 $\textbf{A} = (a_{\mu\nu} \cdot\alpha)$ More...
 
virtual const VtMatrixoperator/= (const double rhs)
 $\textbf{A} = (a_{\mu\nu} / \alpha)$ More...
 
const VtMatrixoperator+= (const VtMatrix &rhs)
 $\textbf{A} = (a_{\mu\nu} + b_{\mu\nu})$ More...
 
const VtMatrixoperator-= (const VtMatrix &rhs)
 $\textbf{A} = (a_{\mu\nu} - b_{\mu\nu})$ More...
 
const VtMatrix operator+ (const VtMatrix &rhs) const
 $\textbf{A} + \textbf{B}$ More...
 
const VtMatrix operator+ (const VtNegMatrix &rhs) const
 
const VtMatrix operator- (const VtMatrix &rhs) const
 $\textbf{A} - \textbf{B}$ More...
 
const VtMatrix operator- (const VtNegMatrix &rhs) const
 
const VtNegMatrix operator- (void) const
 $-\textbf{A}$ More...
 
const VtMatrix operator* (const VtMatrix &rhs) const
 $\textbf{A}\cdot\textbf{B} = \sum_{\nu=1}^n a_{\mu\nu}b_{\nu\lambda}$ More...
 
const VtVector operator* (const VtVector &rhs) const
 $\textbf{A}\cdot\vec{v} = (\sum_{\nu=1}^n a_{\mu\nu}v_{\nu})$ More...
 

— Expert functions —

double * m
 
double * work
 
unsigned int m_nrow
 
unsigned int m_ncol
 
class VtMatrix_row
 
class VtMatrix_row_const
 
int m_size
 
double * array () const
 return pointer to internal array More...
 
virtual void print (std::ostream &os) const
 

Detailed Description

Simple Matrix computation base class

Constructor & Destructor Documentation

◆ VtMatrix() [1/2]

MATRIX::VtMatrix::VtMatrix ( const unsigned int  row,
const unsigned int  col 
)
38  :
39  m_nrow(row),
40  m_ncol(col),
41  m_size(row*col) {
42  m = new double[m_size];
43  work = new double[m_size];
44  memset(m, 0, m_size * sizeof(double));
45  }
double * m
Definition: VtMatrix.hh:171
int m_size
Definition: VtMatrix.hh:179
unsigned int m_nrow
Definition: VtMatrix.hh:173
unsigned int m_ncol
Definition: VtMatrix.hh:174
double * work
Definition: VtMatrix.hh:172

◆ VtMatrix() [2/2]

MATRIX::VtMatrix::VtMatrix ( const VtMatrix rhs)
47  :
48  m_nrow(rhs.nrow()),
49  m_ncol(rhs.ncol()),
50  m_size(rhs.size()) {
51  m = new double[m_size];
52  work = new double[m_size];
53  memcpy(m, rhs.m, m_size * sizeof(double));
54  }

◆ ~VtMatrix()

MATRIX::VtMatrix::~VtMatrix ( )
virtual
56  {
57  delete[] m;
58  delete[] work;
59  }

Member Function Documentation

◆ array()

double* MATRIX::VtMatrix::array ( ) const
inline

return pointer to internal array

166 { return m; }

◆ clear()

void MATRIX::VtMatrix::clear ( void  )

set matrix elements to 0

394  {
395  memset(m, 0, m_size * sizeof(double));
396  return;
397  }

◆ copy()

void MATRIX::VtMatrix::copy ( const VtMatrix rhs)

to be used if matrix dimensions are not equal

379  {
380 
381  const unsigned int nrow = (m_nrow < rhs.nrow()) ? m_nrow : rhs.nrow();
382  const unsigned int ncol = (m_ncol < rhs.ncol()) ? m_ncol : rhs.ncol();
383 
384  for(unsigned int i = 0; i < nrow; ++i)
385  for(unsigned int j = 0; j < ncol; ++j)
386  operator()(i,j) = rhs(i,j);
387 
388  return;
389  }
unsigned int ncol() const
no of columns $m$
Definition: VtMatrix.hh:63
unsigned int nrow() const
no of rows $n$
Definition: VtMatrix.hh:61

◆ get() [1/2]

double& MATRIX::VtMatrix::get ( unsigned int  row,
unsigned int  col 
)
inline
109  {
110  return *(m + row*m_ncol + col);
111  }

◆ get() [2/2]

double MATRIX::VtMatrix::get ( unsigned int  row,
unsigned int  col 
) const
inline
105  {
106  return *(m + row*m_ncol + col);
107  }

◆ ncol()

unsigned int MATRIX::VtMatrix::ncol ( ) const
inline

no of columns $m$

63 { return m_ncol; }

◆ nrow()

unsigned int MATRIX::VtMatrix::nrow ( ) const
inline

no of rows $n$

61 { return m_nrow; }

◆ operator()() [1/2]

double & MATRIX::VtMatrix::operator() ( const unsigned int  row,
const unsigned int  col 
)
virtual

Reimplemented in MATRIX::VtNegMatrix.

113  {
114  return *(m + row*m_ncol + col);
115  }

◆ operator()() [2/2]

double MATRIX::VtMatrix::operator() ( unsigned int  row,
unsigned int  col 
) const
virtual

Reimplemented in MATRIX::VtNegMatrix.

109  {
110  return *(m + row*m_ncol + col);
111  }

◆ operator*() [1/2]

const VtMatrix MATRIX::VtMatrix::operator* ( const VtMatrix rhs) const

$\textbf{A}\cdot\textbf{B} = \sum_{\nu=1}^n a_{\mu\nu}b_{\nu\lambda}$

283  {
284 
285 #ifndef VtFAST
286  assert(ncol() == rhs.nrow());
287 #endif
288 
289  const unsigned int rncol = rhs.ncol();
290 
291  VtMatrix tmp(m_nrow, rncol);
292 
293  for(unsigned int i=0; i<m_nrow; ++i) {
294  for(unsigned int j=0; j<rncol; ++j) {
295  for(unsigned int k=0; k<m_ncol; ++k) {
296  // tmp(i,j) += operator()(i,k) * rhs(k,j);
297  tmp.get(i,j) += get(i,k) * rhs.get(k,j);
298  }
299  }
300  }
301 
302  return tmp;
303  }
double get(unsigned int row, unsigned int col) const
Definition: VtMatrix.hh:105
VtMatrix(const unsigned int row, const unsigned int col)
Definition: VtMatrix.C:38

◆ operator*() [2/2]

const VtVector MATRIX::VtMatrix::operator* ( const VtVector rhs) const

$\textbf{A}\cdot\vec{v} = (\sum_{\nu=1}^n a_{\mu\nu}v_{\nu})$

308  {
309 
310 #ifndef VtFAST
311  assert(ncol() == rhs.nrow());
312 #endif
313 
314  VtVector tmp(m_nrow);
315 
316  for(unsigned int i=0; i<m_nrow; ++i) {
317  for(unsigned int j=0; j<m_ncol; ++j) {
318  // tmp[i] += operator()(i,j) * rhs[j];
319  tmp[i] += get(i,j) * rhs[j];
320  }
321  }
322 
323  return tmp;
324  }

◆ operator*=()

const VtMatrix & MATRIX::VtMatrix::operator*= ( const double  rhs)
virtual

$\textbf{A} = (a_{\mu\nu} \cdot\alpha)$

Reimplemented in MATRIX::VtSymMatrix, and MATRIX::VtNegMatrix.

200  {
201  for(int i=0; i<m_size; ++i) m[i] *= rhs;
202  return *this;
203  }

◆ operator+() [1/2]

const VtMatrix MATRIX::VtMatrix::operator+ ( const VtMatrix rhs) const

$\textbf{A} + \textbf{B}$

216  {
217 
218 #ifndef VtFAST
219  assert(ncol() == rhs.ncol() && nrow() == rhs.nrow());
220 #endif
221 
222  VtMatrix tmp(*this);
223 
224  return tmp += rhs;
225  }

◆ operator+() [2/2]

const VtMatrix MATRIX::VtMatrix::operator+ ( const VtNegMatrix rhs) const
230  {
231 
232 #ifndef VtFAST
233  assert(ncol() == rhs.ncol() && nrow() == rhs.nrow());
234 #endif
235 
236  VtMatrix tmp(*this);
237  return tmp -= rhs;
238  }

◆ operator+=() [1/2]

const VtMatrix & MATRIX::VtMatrix::operator+= ( const double  rhs)
virtual

$\textbf{A} = (a_{\mu\nu} + \alpha)$

Reimplemented in MATRIX::VtSymMatrix, and MATRIX::VtNegMatrix.

158  {
159  for(int i=0; i<m_size; ++i) m[i] += rhs;
160  return *this;
161  }

◆ operator+=() [2/2]

const VtMatrix & MATRIX::VtMatrix::operator+= ( const VtMatrix rhs)

$\textbf{A} = (a_{\mu\nu} + b_{\mu\nu})$

166  {
167 
168 #ifndef VtFAST
169  assert(size() == rhs.size());
170 #endif
171 
172  for(int i=0; i<m_size; ++i) m[i] += rhs.m[i];
173  return *this;
174  }
int size() const
$m\times n$
Definition: VtMatrix.hh:65

◆ operator-() [1/3]

const VtMatrix MATRIX::VtMatrix::operator- ( const VtMatrix rhs) const

$\textbf{A} - \textbf{B}$

243  {
244 
245 #ifndef VtFAST
246  assert(ncol() == rhs.ncol() && nrow() == rhs.nrow());
247 #endif
248 
249  VtMatrix tmp(*this);
250 
251  return tmp -= rhs;
252  }

◆ operator-() [2/3]

const VtMatrix MATRIX::VtMatrix::operator- ( const VtNegMatrix rhs) const
257  {
258 
259 #ifndef VtFAST
260  assert(ncol() == rhs.ncol() && nrow() == rhs.nrow());
261 #endif
262 
263  VtMatrix tmp(*this);
264 
265  return tmp += rhs;
266  }

◆ operator-() [3/3]

const VtNegMatrix MATRIX::VtMatrix::operator- ( void  ) const

$-\textbf{A}$

271  {
272 
273 #ifdef VtDEBUG
274  cout << "VtMatrix::operator- (unary) called!" << endl;
275 #endif
276 
277  return VtNegMatrix(*this);
278  }

◆ operator-=() [1/2]

const VtMatrix & MATRIX::VtMatrix::operator-= ( const double  rhs)
virtual

$\textbf{A} = (a_{\mu\nu} - \alpha)$

Reimplemented in MATRIX::VtSymMatrix, and MATRIX::VtNegMatrix.

179  {
180  for(int i=0; i<m_size; ++i) m[i] -= rhs;
181  return *this;
182  }

◆ operator-=() [2/2]

const VtMatrix & MATRIX::VtMatrix::operator-= ( const VtMatrix rhs)

$\textbf{A} = (a_{\mu\nu} - b_{\mu\nu})$

187  {
188 
189 #ifndef VtFAST
190  assert(size() == rhs.size());
191 #endif
192 
193  for(int i=0; i<m_size; ++i) m[i] -= rhs.m[i];
194  return *this;
195  }

◆ operator/=()

const VtMatrix & MATRIX::VtMatrix::operator/= ( const double  rhs)
virtual

$\textbf{A} = (a_{\mu\nu} / \alpha)$

Reimplemented in MATRIX::VtSymMatrix, and MATRIX::VtNegMatrix.

208  {
209  for(int i=0; i<m_size; ++i) m[i] /= rhs;
210  return *this;
211  }

◆ operator=() [1/2]

const VtMatrix & MATRIX::VtMatrix::operator= ( const VtMatrix rhs)

$\textbf{A} = \textbf{B}$

120  {
121  if(this == &rhs) return *this;
122 
123 #ifndef VtFAST
124  assert(size() == rhs.size());
125 #endif
126 
127  m_nrow = rhs.nrow();
128  m_ncol = rhs.ncol();
129  m_size = rhs.size();
130 
131  memcpy(m, rhs.m, m_size * sizeof(double));
132 
133  return *this;
134  }

◆ operator=() [2/2]

const VtMatrix & MATRIX::VtMatrix::operator= ( const VtNegMatrix rhs)
140  {
141 
142 #ifndef VtFAST
143  assert(size() == rhs.size());
144 #endif
145 
146  m_nrow = rhs.nrow();
147  m_ncol = rhs.ncol();
148  m_size = rhs.size();
149 
150  for(int i=0; i<m_size; ++i) m[i] = -rhs.m[i];
151 
152  return *this;
153  }

◆ operator[]() [1/2]

VtMatrix_row MATRIX::VtMatrix::operator[] ( int  row)
inline
95  {
96  return VtMatrix_row(*this, row);
97  }
friend class VtMatrix_row
Definition: VtMatrix.hh:177

◆ operator[]() [2/2]

VtMatrix_row_const MATRIX::VtMatrix::operator[] ( int  row) const
inline
98  {
99  return VtMatrix_row_const(*this, row);
100  }
friend class VtMatrix_row_const
Definition: VtMatrix.hh:178

◆ place_at() [1/2]

void MATRIX::VtMatrix::place_at ( const VtMatrix rhs,
const unsigned int  row,
const unsigned int  col 
)
virtual

copy a smaller matrix at a certain place

Reimplemented in MATRIX::VtSymMatrix.

67  {
68 #ifndef VtFAST
69  assert(nrow() >= rhs.nrow()+row && ncol() >= rhs.ncol()+col);
70 #endif
71 
72  const unsigned int rnrow = rhs.nrow();
73  const unsigned int rncol = rhs.ncol();
74 
75  for(unsigned int i=0; i<rnrow; ++i) {
76  const unsigned int nr = i + row;
77  for(unsigned int j=0, nc=col; j<rncol; ++j,++nc) {
78  operator()(nr,nc) = rhs(i,j);
79  }
80  }
81 
82  return;
83  }
virtual double operator()(unsigned int row, unsigned int col) const
Definition: VtMatrix.C:109

◆ place_at() [2/2]

void MATRIX::VtMatrix::place_at ( const VtVector rhs,
const unsigned int  row,
const unsigned int  col 
)
virtual

copy a vector at a certain place

90  {
91 
92 #ifndef VtFAST
93  assert(nrow() >= rhs.nrow()+row && ncol() >= col+1);
94 #endif
95 
96  const unsigned int rnrow = rhs.nrow();
97 
98  for(unsigned int i=0; i<rnrow; ++i) {
99  operator()(i+row,col) = rhs(i);
100  }
101 
102  return;
103  }

◆ print()

void MATRIX::VtMatrix::print ( std::ostream &  os) const
virtual

Reimplemented in MATRIX::VtSymMatrix.

358  {
359  /* Fixed format needs 3 extra characters for field, while scientific needs 7 */
360  int width;
361  os << std::endl;
362  if(os.flags() & std::ios::fixed)
363  width = os.precision()+3;
364  else
365  width = os.precision()+7;
366  for(unsigned int row = 0; row < m_nrow; ++row) {
367  for(unsigned int col = 0; col < m_ncol; ++col) {
368  os.width(width);
369  os << operator()(row,col) << " ";
370  }
371  os << std::endl;
372  }
373  return;
374  }
float width
Definition: emthickness.cpp:71

◆ size()

int MATRIX::VtMatrix::size ( ) const
inline

$m\times n$

65 { return m_size; }

◆ T()

const VtMatrix MATRIX::VtMatrix::T ( void  ) const

return transpose

349  {
350  VtMatrix tmp(*this);
351  tmp.VtT();
352  return tmp;
353  }

◆ VtT()

void MATRIX::VtMatrix::VtT ( void  )

transform into transpose matrix

330  {
331 
332  memcpy( work, m, size() * sizeof(double) );
333  for(unsigned int i=0; i<m_nrow; ++i) {
334  for(unsigned int j=0; j<m_ncol; ++j) {
335  m[j*m_nrow+i] = work[i*m_ncol+j];
336  }
337  }
338  const int tmp = m_nrow;
339  m_nrow = m_ncol;
340  m_ncol = tmp;
341 
342  return;
343  }

Friends And Related Function Documentation

◆ VtMatrix_row

friend class VtMatrix_row
friend

◆ VtMatrix_row_const

friend class VtMatrix_row_const
friend

Member Data Documentation

◆ m

double* MATRIX::VtMatrix::m
protected

◆ m_ncol

unsigned int MATRIX::VtMatrix::m_ncol
protected

◆ m_nrow

unsigned int MATRIX::VtMatrix::m_nrow
protected

◆ m_size

int MATRIX::VtMatrix::m_size
private

◆ work

double* MATRIX::VtMatrix::work
protected

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