Matrix Class Template Reference

#include <MatrixN.hh>

Inheritance diagram for Matrix:

Inheritance graph
[legend]

List of all members.


Detailed Description

template<size_t N>
class Rivet::Matrix< N >

General $ N $-dimensional mathematical matrix object.

Definition at line 30 of file MatrixN.hh.


Public Member Functions

 Matrix ()
 Matrix (const Matrix< N > &other)
Matrixset (const size_t i, const size_t j, const double value)
double get (const size_t i, const size_t j) const
Vector< N > getRow (const size_t row) const
Matrix< N > & setRow (const size_t row, const Vector< N > &r)
Vector< N > getColumn (const size_t col) const
Matrix< N > & setColumn (const size_t col, const Vector< N > &c)
Matrix< N > transpose () const
Matrix< N > inverse () const
 Calculate inverse.
double det () const
 Calculate determinant.
double trace () const
 Calculate trace.
Matrix< N > operator- () const
 Negate.
size_t size () const
 Get dimensionality.
bool isZero (double tolerance=1E-5) const
 Index-wise check for nullness, allowing for numerical precision.
bool isEqual (Matrix< N > other) const
 Check for index-wise equality, allowing for numerical precision.
bool isSymm () const
 Check for symmetry under transposition.
bool isDiag () const
 Check that all off-diagonal elements are zero, allowing for numerical precision.
bool operator== (const Matrix< N > &a) const
bool operator!= (const Matrix< N > &a) const
bool operator< (const Matrix< N > &a) const
bool operator<= (const Matrix< N > &a) const
bool operator> (const Matrix< N > &a) const
bool operator>= (const Matrix< N > &a) const
Matrix< N > & operator*= (const Matrix< N > &m)
Matrix< N > & operator*= (const double a)
Matrix< N > & operator/= (const double a)
Matrix< N > & operator+= (const Matrix< N > &m)
Matrix< N > & operator-= (const Matrix< N > &m)

Static Public Member Functions

static Matrix< N > mkZero ()
static Matrix< N > mkDiag (Vector< N > diag)
static Matrix< N > mkIdentity ()

Protected Types

typedef Eigen::Matrix< double, N > EMatrix

Protected Attributes

EMatrix _matrix

Friends

template<size_t M>
Matrix< M > add (const Matrix< M > &, const Matrix< M > &)
template<size_t M>
Matrix< M > multiply (const double, const Matrix< M > &)
template<size_t M>
Matrix< M > multiply (const Matrix< M > &, const Matrix< M > &)
template<size_t M>
Vector< M > multiply (const Matrix< M > &, const Vector< M > &)
template<size_t M>
Matrix< M > divide (const Matrix< M > &, const double)

Member Typedef Documentation

typedef Eigen::Matrix<double,N> EMatrix [protected]

Definition at line 254 of file MatrixN.hh.


Constructor & Destructor Documentation

Matrix (  )  [inline]

Definition at line 67 of file MatrixN.hh.

00067              {
00068       _matrix.loadZero();
00069     }

Matrix ( const Matrix< N > &  other  )  [inline]

Definition at line 71 of file MatrixN.hh.

00071                                    {
00072       _matrix = other._matrix;
00073     }


Member Function Documentation

static Matrix<N> mkZero (  )  [inline, static]

Definition at line 43 of file MatrixN.hh.

00043                               {
00044       Matrix<N> rtn;
00045       return rtn;
00046     }

static Matrix<N> mkDiag ( Vector< N >  diag  )  [inline, static]

Definition at line 48 of file MatrixN.hh.

00048                                             {
00049       Matrix<N> rtn;
00050       for (size_t i = 0; i < N; ++i) {
00051         rtn.set(i, i, diag[i]);
00052       }
00053       return rtn;
00054     }

static Matrix<N> mkIdentity (  )  [inline, static]

Definition at line 56 of file MatrixN.hh.

00056                                   {
00057       Matrix<N> rtn;
00058       for (size_t i = 0; i < N; ++i) {
00059         rtn.set(i, i, 1);
00060       }
00061       return rtn;
00062     }

Matrix& set ( const size_t  i,
const size_t  j,
const double  value 
) [inline]

Definition at line 75 of file MatrixN.hh.

Referenced by Sphericity::_calcSphericity(), Matrix< 4 >::mkDiag(), Matrix< 4 >::mkIdentity(), LorentzTransform::mkMatrix4(), and LorentzTransform::setBoost().

00075                                                                     {
00076       if (i < N && j < N) {
00077         _matrix(i, j) = value;
00078       } else {
00079         throw std::runtime_error("Attempted set access outside matrix bounds.");
00080       }
00081       return *this;
00082     }

double get ( const size_t  i,
const size_t  j 
) const [inline]

Definition at line 84 of file MatrixN.hh.

Referenced by Sphericity::_calcSphericity(), Rivet::diagonalize(), Rivet::fuzzyEquals(), LorentzTransform::mkMatrix4(), and Rivet::toString().

00084                                                      {
00085       if (i < N && j < N) {
00086         return _matrix(i, j);
00087       } else {
00088         throw std::runtime_error("Attempted get access outside matrix bounds.");
00089       }
00090     }

Vector<N> getRow ( const size_t  row  )  const [inline]

Definition at line 92 of file MatrixN.hh.

00092                                              {
00093       Vector<N> rtn;
00094       for (size_t i = 0; i < N; ++i) {
00095         rtn.set(i, _matrix(row,i));
00096       }
00097       return rtn;
00098     }

Matrix<N>& setRow ( const size_t  row,
const Vector< N > &  r 
) [inline]

Definition at line 100 of file MatrixN.hh.

00100                                                             {
00101       for (size_t i = 0; i < N; ++i) {
00102         _matrix(row,i) = r.get(i);
00103       }
00104       return *this;
00105     }

Vector<N> getColumn ( const size_t  col  )  const [inline]

Definition at line 107 of file MatrixN.hh.

Referenced by LorentzTransform::boost().

00107                                                 {
00108       const Eigen::Vector<double,N> eVec = _matrix.column(col);
00109       Vector<N> rtn;
00110       for (size_t i = 0; i < N; ++i) {
00111         rtn.set(i, _matrix(i,col));
00112       }
00113       return rtn;
00114     }

Matrix<N>& setColumn ( const size_t  col,
const Vector< N > &  c 
) [inline]

Definition at line 116 of file MatrixN.hh.

00116                                                                {
00117       for (size_t i = 0; i < N; ++i) {
00118         _matrix(i,col) = c.get(i);
00119       }
00120       return *this;
00121     }

Matrix<N> transpose (  )  const [inline]

Definition at line 123 of file MatrixN.hh.

Referenced by Matrix< 4 >::isSymm(), and Rivet::transpose().

00123                                 {
00124       Matrix<N> tmp = *this;
00125       tmp._matrix.replaceWithAdjoint();
00126       return tmp;
00127     }

Matrix<N> inverse (  )  const [inline]

Calculate inverse.

Definition at line 135 of file MatrixN.hh.

Referenced by Rivet::inverse(), LorentzTransform::inverse(), and LorentzTransform::rotate().

00135                               {
00136       Matrix<N> tmp;
00137       tmp._matrix = _matrix.inverse();
00138       return tmp;
00139     }

double det (  )  const [inline]

Calculate determinant.

Definition at line 142 of file MatrixN.hh.

00142                         {
00143       return _matrix.determinant();
00144     }

double trace (  )  const [inline]

Calculate trace.

Definition at line 147 of file MatrixN.hh.

Referenced by Rivet::trace().

00147                          {
00148       double tr = 0.0;
00149       for (size_t i = 0; i < N; ++i) {
00150         tr += _matrix(i,i);
00151       }
00152       return tr;
00153       // return _matrix.trace();
00154     }

Matrix<N> operator- (  )  const [inline]

Negate.

Definition at line 157 of file MatrixN.hh.

00157                                 {
00158       Matrix<N> rtn;
00159       rtn._matrix = -_matrix;
00160       return rtn;
00161     }

size_t size (  )  const [inline]

Get dimensionality.

Definition at line 164 of file MatrixN.hh.

Referenced by Rivet::toString().

00164                         {
00165       return N;
00166     }

bool isZero ( double  tolerance = 1E-5  )  const [inline]

Index-wise check for nullness, allowing for numerical precision.

Definition at line 169 of file MatrixN.hh.

Referenced by Rivet::isZero().

00169                                              {
00170       for (size_t i=0; i < N; ++i) {
00171         for (size_t j=0; j < N; ++j) {
00172           if (! Rivet::isZero(_matrix(i,j), tolerance) ) return false;
00173         }
00174       }
00175       return true;
00176     }

bool isEqual ( Matrix< N >  other  )  const [inline]

Check for index-wise equality, allowing for numerical precision.

Definition at line 179 of file MatrixN.hh.

Referenced by Matrix< 4 >::isSymm().

00179                                         {
00180       for (size_t i=0; i < N; ++i) {
00181         for (size_t j=i; j < N; ++j) {
00182           if (! Rivet::isZero(_matrix(i,j) - other._matrix(i,j)) ) return false;
00183         }
00184       }
00185       return true;
00186     }

bool isSymm (  )  const [inline]

Check for symmetry under transposition.

Definition at line 189 of file MatrixN.hh.

Referenced by Sphericity::_calcSphericity().

00189                         {
00190       return isEqual(this->transpose());
00191     }

bool isDiag (  )  const [inline]

Check that all off-diagonal elements are zero, allowing for numerical precision.

Definition at line 194 of file MatrixN.hh.

00194                         {
00195       for (size_t i=0; i < N; ++i) {
00196         for (size_t j=0; j < N; ++j) {
00197           if (i == j) continue;
00198           if (! Rivet::isZero(_matrix(i,j)) ) return false;
00199         }
00200       }
00201       return true;
00202     }

bool operator== ( const Matrix< N > &  a  )  const [inline]

Definition at line 204 of file MatrixN.hh.

00204                                               {
00205       return _matrix == a._matrix;
00206     }

bool operator!= ( const Matrix< N > &  a  )  const [inline]

Definition at line 208 of file MatrixN.hh.

00208                                               {
00209       return _matrix != a._matrix;
00210     }

bool operator< ( const Matrix< N > &  a  )  const [inline]

Definition at line 212 of file MatrixN.hh.

00212                                              {
00213       return _matrix < a._matrix;
00214     }

bool operator<= ( const Matrix< N > &  a  )  const [inline]

Definition at line 216 of file MatrixN.hh.

00216                                               {
00217       return _matrix <= a._matrix;
00218     }

bool operator> ( const Matrix< N > &  a  )  const [inline]

Definition at line 220 of file MatrixN.hh.

00220                                              {
00221       return _matrix > a._matrix;
00222     }

bool operator>= ( const Matrix< N > &  a  )  const [inline]

Definition at line 224 of file MatrixN.hh.

00224                                               {
00225       return _matrix >= a._matrix;
00226     }

Matrix<N>& operator*= ( const Matrix< N > &  m  )  [inline]

Definition at line 228 of file MatrixN.hh.

00228                                               {
00229       _matrix = _matrix * m._matrix;
00230       return *this;
00231     }

Matrix<N>& operator*= ( const double  a  )  [inline]

Definition at line 233 of file MatrixN.hh.

00233                                           {
00234       _matrix *= a;
00235       return *this;
00236     }

Matrix<N>& operator/= ( const double  a  )  [inline]

Definition at line 238 of file MatrixN.hh.

00238                                           {
00239       _matrix /= a;
00240       return *this;
00241     }

Matrix<N>& operator+= ( const Matrix< N > &  m  )  [inline]

Definition at line 243 of file MatrixN.hh.

00243                                               {
00244       _matrix += m._matrix;
00245       return *this;
00246     }

Matrix<N>& operator-= ( const Matrix< N > &  m  )  [inline]

Definition at line 248 of file MatrixN.hh.

00248                                               {
00249       _matrix -= m._matrix;
00250       return *this;
00251     }


Friends And Related Function Documentation

Matrix<M> add ( const Matrix< M > &  ,
const Matrix< M > &   
) [friend]

Matrix<M> multiply ( const   double,
const Matrix< M > &   
) [friend]

Matrix<M> multiply ( const Matrix< M > &  ,
const Matrix< M > &   
) [friend]

Vector<M> multiply ( const Matrix< M > &  ,
const Vector< M > &   
) [friend]

Matrix<M> divide ( const Matrix< M > &  ,
const   double 
) [friend]


Member Data Documentation

EMatrix _matrix [protected]


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