HepDiagMatrix


HepDiagMatrix is a class for diagonal matrix. This is useful for a covariance matrix of measured quantities since they are uncorrelated to each other and therefore diagonal. It is obviously smaller and faster to manipulate.

Authors

Nobu Katayama and Mike Smyth

See also

HepGenMatrix, HepMatrix, HepSymMatrix, HepVector, HepPile,

Declaration

#include "CLHEP/Matrix/DiagMatrix.h"

class HepDiagMatrix : public HepGenMatrix

Public Member Classes

HepDiagMatrix_row
Helper class to implement m[i][j]
Declaration
class HepDiagMatrix_row
Constructor
inline HepDiagMatrix_row(HepDiagMatrix&, int)
[]
inline HepDouble & operator[](int)

HepDiagMatrix_row_const
Helper class to implement m[i][j]
Declaration
class HepDiagMatrix_row_const
Constructor
inline HepDiagMatrix_row_const(const HepDiagMatrix&, int)
[]
inline const HepDouble & operator[](int) const

Public Member Functions

Constructor
inline HepDiagMatrix()
Default constructor. Gives 0 x 0 matrix.
Another HepDiagMatrix can be assigned to it.
Constructor
HepDiagMatrix(int p)
HepDiagMatrix(int p, int)
Gives p x p diagonal matrix.
With a second argument, either 0 or 1, the matrix is initialized.
0 means a zero matrix, 1 means the identity matrix.
Constructor
#ifdef HEP_USE_RANDOM
HepDiagMatrix(int p, HepRandom &r)
#endif
Constructor with a Random object.
Copy constructor
HepDiagMatrix(const HepDiagMatrix &m1)
Destructor
virtual ~HepDiagMatrix()
=
HepDiagMatrix & operator = (const HepDiagMatrix &m2)
Assignment operator.
To assign HepSymMatrix to HepDiagMatrix, use d << s
+=
HepDiagMatrix & operator += (const HepDiagMatrix &m2)
Add a HepDiagMatrix.
-
HepDiagMatrix operator - () const
Unary minus, i.e. flip the sign of each element.
-=
HepDiagMatrix & operator -= (const HepDiagMatrix &m2)
Subtract a HepDiagMatrix.
*=
HepDiagMatrix & operator *= (HepDouble t)
Multiply a HepDiagMatrix by a floating number.
/=
HepDiagMatrix & operator /= (HepDouble t)
Divide a HepDiagMatrix by a floating number.
()
HepDouble & operator()(int row, int col)
const HepDouble & operator()(int row, int col) const
Read or write a matrix element. row must be equal to col.
** Note that indexing starts from (1,1) **
[]
inline HepDiagMatrix_row operator[] (int)
inline HepDiagMatrix_row_const operator[] (int) const
Read or write a matrix element.
While it may not look like it, you simply do m[i][j] to get an element.
** Note that the indexing starts from [0][0] **
apply
HepDiagMatrix apply(HepDouble (*f)(HepDouble, int, int)) const
Apply a function to all elements of the matrix.
assign
void assign(const HepMatrix &m2)
Assigns m2 to d, assuming m2 is a diagnal matrix.

void assign(const HepSymMatrix &m2)
Assigns m2 to d, assuming m2 is a diagnal matrix.

void assign(const HepDiagMatrix &m2)
Another form of assignment. For consistency.
determinant
HepDouble determinant() const
Calculate the determinant of the matrix.
fast
HepDouble & fast(int row, int col)
const HepDouble & fast(int row, int col) const
Fast element access. Must be row >= col.
** Note that indexing starts from (1,1) **
inverse
HepDiagMatrix inverse(int &ierr) const
Invert a HepDiagMatrix. The matrix is not changed.
Returns 0 when successful, otherwise non-zero.
invert
void invert(int &ierr)
Invert a HepDiagMatrix.
N.B. the contents of the matrix are replaced by the inverse.
Returns ierr = 0 when successful, otherwise non-zero.
This method has less overhead then inverse().
num_col
inline int num_col() const
Returns number of columns.
num_row
inline int num_row() const
Returns number of rows.
similarity
HepSymMatrix similarity(const HepMatrix &m1) const
Returns m1*s*m1.T()

HepDouble similarity(const HepVector &v) const
Returns v.T()*s*v (This is a scaler).
similarityT
HepSymMatrix similarityT(const HepMatrix &m1) const
Returns m1.T()*s*m1
sub
HepDiagMatrix sub(int min_row, int max_row) const
Returns a sub matrix of a HepDiagMatrix.

#ifdef HEP_CC_NEED_SUB_WITHOUT_CONST
HepDiagMatrix sub(int min_row, int max_row)
#endif
SGI CC bug. I have to have both with/without const. I should not need one without const.

void sub(int row, const HepDiagMatrix &m1)
Sub matrix of this HepDiagMatrix is replaced with m1.
T
HepDiagMatrix T() const
Returns the transpose of a HepDiagMatrix (which is itself).
trace
HepDouble trace() const
Calculate the trace of the matrix (sum of diagonal elements).

Non-Member Functions

+
HepMatrix operator + (const HepMatrix &m1, const HepDiagMatrix &d2)
HepMatrix operator + (const HepDiagMatrix &d1, const HepMatrix &m2)
HepDiagMatrix operator + (const HepDiagMatrix &m1, const HepDiagMatrix &d2)
HepSymMatrix operator + (const HepSymMatrix &s1, const HepDiagMatrix &d2)
HepSymMatrix operator + (const HepDiagMatrix &d1, const HepSymMatrix &s2)
Addition operators.
-
HepMatrix operator - (const HepMatrix &m1, const HepDiagMatrix &d2)
HepMatrix operator - (const HepDiagMatrix &d1, const HepMatrix &m2)
HepDiagMatrix operator - (const HepDiagMatrix &d1, const HepDiagMatrix &d2)
HepSymMatrix operator - (const HepSymMatrix &s1, const HepDiagMatrix &d2)
HepSymMatrix operator - (const HepDiagMatrix &d1, const HepSymMatrix &s2)
Subtraction operators.
*
HepMatrix operator * (const HepMatrix &m1, const HepDiagMatrix &m2)
HepMatrix operator * (const HepDiagMatrix &m1, const HepMatrix &m2)
Multiplication operators.
Note that m *= m1 is always faster than m = m * m1

HepDiagMatrix operator * (HepDouble t, const HepDiagMatrix &d1)
HepDiagMatrix operator * (const HepDiagMatrix &d1, HepDouble t)
Multiplication with a number.
/
HepDiagMatrix operator / (const HepDiagMatrix &m1, HepDouble t)
Division with a number.
Note that d /= t is faster if you can use it.
<<
ostream & operator << (ostream &s, const HepDiagMatrix &q)
Output to a stream.
dsum
HepDiagMatrix dsum(const HepDiagMatrix &d1, const HepDiagMatrix &d2)
Direct sum of two diagonal matricies.

Example

CLHEP/test/testMatrix.cc


8 October 1997
EVC