CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Classes | Public Member Functions | Private Attributes
ROOT::Math::CholeskyDecomp< F, N > Class Template Reference

class to compute the Cholesky decomposition of a matrix More...

#include <CholeskyDecomp.h>

Classes

class  PackedArrayAdapter
 adapter for packed arrays (to SMatrix indexing conventions) More...
 

Public Member Functions

template<class M >
 CholeskyDecomp (const M &m)
 perform a Cholesky decomposition More...
 
template<typename G >
 CholeskyDecomp (G *m)
 perform a Cholesky decomposition More...
 
template<class M >
bool Invert (M &m) const
 place the inverse into m More...
 
template<typename G >
bool Invert (G *m) const
 place the inverse into m More...
 
bool ok () const
 returns true if decomposition was successful More...
 
 operator bool () const
 returns true if decomposition was successful More...
 
template<class V >
bool Solve (V &rhs) const
 solves a linear system for the given right hand side More...
 

Private Attributes

F fL [N *(N+1)/2]
 lower triangular matrix L More...
 
bool fOk
 flag indicating a successful decomposition More...
 

Detailed Description

template<class F, unsigned N>
class ROOT::Math::CholeskyDecomp< F, N >

class to compute the Cholesky decomposition of a matrix

class to compute the Cholesky decomposition of a symmetric positive definite matrix

provides routines to check if the decomposition succeeded (i.e. if matrix is positive definite and non-singular), to solve a linear system for the given matrix and to obtain its inverse

the actual functionality is implemented in templated helper classes which have specializations for dimensions N = 1 to 6 to achieve a gain in speed for common matrix sizes

usage example:

* // let m be a symmetric positive definite SMatrix (use type float
* // for internal computations, matrix size is 4x4)
* CholeskyDecomp<float, 4> decomp(m);
* // check if the decomposition succeeded
* if (!decomp) {
* std::cerr << "decomposition failed!" << std::endl;
* } else {
* // let rhs be a vector; we seek a vector x such that m * x = rhs
* decomp.Solve(rhs);
* // rhs now contains the solution we are looking for
*
* // obtain the inverse of m, put it into m itself
* decomp.Invert(m);
* }
*

Definition at line 62 of file CholeskyDecomp.h.

Constructor & Destructor Documentation

template<class F, unsigned N>
template<class M >
ROOT::Math::CholeskyDecomp< F, N >::CholeskyDecomp ( const M &  m)
inline

perform a Cholesky decomposition

perfrom a Cholesky decomposition of a symmetric positive definite matrix m

this is the constructor to uses with an SMatrix (and objects that behave like an SMatrix in terms of using operator()(int i, int j) for access to elements)

Definition at line 95 of file CholeskyDecomp.h.

References ROOT::Math::CholeskyDecomp< F, N >::fL, and ROOT::Math::CholeskyDecomp< F, N >::fOk.

96  {
97  using CholeskyDecompHelpers::_decomposer;
98  fOk = _decomposer<F, N, M>()(fL, m);
99  }
F fL[N *(N+1)/2]
lower triangular matrix L
bool fOk
flag indicating a successful decomposition
template<class F, unsigned N>
template<typename G >
ROOT::Math::CholeskyDecomp< F, N >::CholeskyDecomp ( G *  m)
inline

perform a Cholesky decomposition

perfrom a Cholesky decomposition of a symmetric positive definite matrix m

this is the constructor to use in special applications where plain arrays are used

NOTE: the matrix is given in packed representation, matrix element m(i,j) (j <= i) is supposed to be in array element (i * (i + 1)) / 2 + j

Definition at line 112 of file CholeskyDecomp.h.

References ROOT::Math::CholeskyDecomp< F, N >::fL, and ROOT::Math::CholeskyDecomp< F, N >::fOk.

113  {
114  using CholeskyDecompHelpers::_decomposer;
115  fOk = _decomposer<F, N, PackedArrayAdapter<G> >()(
116  fL, PackedArrayAdapter<G>(m));
117  }
F fL[N *(N+1)/2]
lower triangular matrix L
bool fOk
flag indicating a successful decomposition

Member Function Documentation

template<class F, unsigned N>
template<class M >
bool ROOT::Math::CholeskyDecomp< F, N >::Invert ( M &  m) const
inline

place the inverse into m

place the inverse into m

This is the method to use with an SMatrix.

Returns
if the decomposition was successful

Definition at line 148 of file CholeskyDecomp.h.

References ROOT::Math::CholeskyDecomp< F, N >::fL, and ROOT::Math::CholeskyDecomp< F, N >::fOk.

Referenced by invertPosDefMatrix().

149  {
150  using CholeskyDecompHelpers::_inverter;
151  if (fOk) _inverter<F,N,M>()(m, fL); return fOk;
152  }
F fL[N *(N+1)/2]
lower triangular matrix L
bool fOk
flag indicating a successful decomposition
template<class F, unsigned N>
template<typename G >
bool ROOT::Math::CholeskyDecomp< F, N >::Invert ( G *  m) const
inline

place the inverse into m

place the inverse into m

This is the method to use with a plain array.

Returns
if the decomposition was successful

NOTE: the matrix is given in packed representation, matrix element m(i,j) (j <= i) is supposed to be in array element (i * (i + 1)) / 2 + j

Definition at line 165 of file CholeskyDecomp.h.

References ROOT::Math::CholeskyDecomp< F, N >::fL, and ROOT::Math::CholeskyDecomp< F, N >::fOk.

166  {
167  using CholeskyDecompHelpers::_inverter;
168  if (fOk) {
169  PackedArrayAdapter<G> adapted(m);
170  _inverter<F,N,PackedArrayAdapter<G> >()(adapted, fL);
171  }
172  return fOk;
173  }
F fL[N *(N+1)/2]
lower triangular matrix L
bool fOk
flag indicating a successful decomposition
template<class F, unsigned N>
bool ROOT::Math::CholeskyDecomp< F, N >::ok ( ) const
inline

returns true if decomposition was successful

Returns
true if decomposition was successful

Definition at line 121 of file CholeskyDecomp.h.

References ROOT::Math::CholeskyDecomp< F, N >::fOk.

121 { return fOk; }
bool fOk
flag indicating a successful decomposition
template<class F, unsigned N>
ROOT::Math::CholeskyDecomp< F, N >::operator bool ( ) const
inline

returns true if decomposition was successful

Returns
true if decomposition was successful

Definition at line 124 of file CholeskyDecomp.h.

References ROOT::Math::CholeskyDecomp< F, N >::fOk.

124 { return fOk; }
bool fOk
flag indicating a successful decomposition
template<class F, unsigned N>
template<class V >
bool ROOT::Math::CholeskyDecomp< F, N >::Solve ( V &  rhs) const
inline

solves a linear system for the given right hand side

solves a linear system for the given right hand side

Note that you can use both SVector classes and plain arrays for rhs. (Make sure that the sizes match!). It will work with any vector implementing the operator [i]

Returns
if the decomposition was successful

Definition at line 135 of file CholeskyDecomp.h.

References ROOT::Math::CholeskyDecomp< F, N >::fL, and ROOT::Math::CholeskyDecomp< F, N >::fOk.

136  {
137  using CholeskyDecompHelpers::_solver;
138  if (fOk) _solver<F,N,V>()(rhs, fL); return fOk;
139  }
F fL[N *(N+1)/2]
lower triangular matrix L
bool fOk
flag indicating a successful decomposition

Member Data Documentation

template<class F, unsigned N>
F ROOT::Math::CholeskyDecomp< F, N >::fL[N *(N+1)/2]
private

lower triangular matrix L

lower triangular matrix L, packed storage, with diagonal elements pre-inverted

Definition at line 68 of file CholeskyDecomp.h.

Referenced by ROOT::Math::CholeskyDecomp< F, N >::CholeskyDecomp(), ROOT::Math::CholeskyDecomp< F, N >::Invert(), and ROOT::Math::CholeskyDecomp< F, N >::Solve().

template<class F, unsigned N>
bool ROOT::Math::CholeskyDecomp< F, N >::fOk
private