ROOT  6.06/09
Reference Guide
SMatrix.h
Go to the documentation of this file.
1 // @(#)root/smatrix:$Id$
2 // Author: T. Glebe, L. Moneta, J. Palacios 2005
3 
4 #ifndef ROOT_Math_SMatrix
5 #define ROOT_Math_SMatrix
6 
7 /*********************************************************************************
8 //
9 // source:
10 //
11 // type: source code
12 //
13 // created: 20. Mar 2001
14 //
15 // author: Thorsten Glebe
16 // HERA-B Collaboration
17 // Max-Planck-Institut fuer Kernphysik
18 // Saupfercheckweg 1
19 // 69117 Heidelberg
20 // Germany
21 // E-mail: T.Glebe@mpi-hd.mpg.de
22 //
23 // Description: A fixed size two dimensional Matrix class
24 //
25 // changes:
26 // 20 Mar 2001 (TG) creation
27 // 21 Mar 2001 (TG) added operators +=, -=, *=, /=
28 // 26 Mar 2001 (TG) place_in_row(), place_in_col() added
29 // 02 Apr 2001 (TG) non-const Array() added
30 // 03 Apr 2001 (TG) invert() added
31 // 07 Apr 2001 (TG) CTOR from SVertex (dyadic product) added
32 // 09 Apr 2001 (TG) CTOR from array added
33 // 11 Apr 2001 (TG) rows(), cols(), size() replaced by rows, cols, size
34 // 25 Mai 2001 (TG) row(), col() added
35 // 04 Sep 2001 (TG) moved inlined functions to .icc file
36 // 11 Jan 2002 (TG) added operator==(), operator!=()
37 // 14 Jan 2002 (TG) added more operator==(), operator!=(), operator>(), operator<()
38 //
39 ***************************************************************************/
40 // for platform specific configurations
41 
42 #ifndef ROOT_Math_MnConfig
43 #include "Math/MConfig.h"
44 #endif
45 
46 #include <iosfwd>
47 
48 
49 
50 
51 //doxygen tag
52 
53 /**
54  @defgroup SMatrixGroup SMatrix
55  @ingroup Math
56 
57  \ref SMatrixPage for high performance vector and matrix computations.
58  Classes representing Matrices and Vectors of arbitrary type and dimension and related functions.
59  For a detailed description and usage examples see:
60  <ul>
61  <li>\ref SMatrixPage home page
62  <li>\ref SVectorDoc
63  <li>\ref SMatrixDoc
64  <li>\ref MatVecFunctions
65  </ul>
66 
67 
68 */
69 
70 /**
71  @defgroup SMatrixSVector Matrix and Vector classes
72 
73  @ingroup SMatrixGroup
74 
75  Classes representing Matrices and Vectors of arbitrary type and dimension.
76  For a detailed description and usage examples see:
77  <ul>
78  <li>\ref SVectorDoc
79  <li>\ref SMatrixDoc
80  <li>\ref MatVecFunctions
81  </ul>
82 
83 */
84 
85 
86 #ifndef ROOT_Math_Expression
87 #include "Math/Expression.h"
88 #endif
89 #ifndef ROOT_Math_MatrixRepresentationsStatic
91 #endif
92 
93 
94 namespace ROOT {
95 
96 namespace Math {
97 
98 
99 template <class T, unsigned int D> class SVector;
100 
101 struct SMatrixIdentity { };
102 struct SMatrixNoInit { };
103 
104 //__________________________________________________________________________
105 /**
106  SMatrix: a generic fixed size D1 x D2 Matrix class.
107  The class is template on the scalar type, on the matrix sizes:
108  D1 = number of rows and D2 = number of columns
109  amd on the representation storage type.
110  By default the representation is MatRepStd<T,D1,D2> (standard D1xD2 of type T),
111  but it can be of type MatRepSym<T,D> for symmetric matrices DxD, where the storage is only
112  D*(D+1)/2.
113 
114  See \ref SMatrixDoc.
115 
116  Original author is Thorsten Glebe
117  HERA-B Collaboration, MPI Heidelberg (Germany)
118 
119  @ingroup SMatrixSVector
120 
121  @authors T. Glebe, L. Moneta and J. Palacios
122 */
123 //==============================================================================
124 // SMatrix: column-wise storage
125 //==============================================================================
126 template <class T,
127  unsigned int D1,
128  unsigned int D2 = D1,
129  class R=MatRepStd<T, D1, D2> >
130 class SMatrix {
131 public:
132  /** @name --- Typedefs --- */
133 
134  /** contained scalar type */
135  typedef T value_type;
136 
137  /** storage representation type */
138  typedef R rep_type;
139 
140  /** STL iterator interface. */
141  typedef T* iterator;
142 
143  /** STL const_iterator interface. */
144  typedef const T* const_iterator;
145 
146 
147 
148  /** @name --- Constructors and Assignment --- */
149 
150  /**
151  Default constructor:
152  */
153  SMatrix();
154  ///
155  /**
156  construct from without initialization
157  */
158  inline SMatrix( SMatrixNoInit ){}
159 
160  /**
161  construct from an identity matrix
162  */
164  /**
165  copy constructor (from a matrix of the same representation
166  */
167  SMatrix(const SMatrix<T,D1,D2,R>& rhs);
168  /**
169  construct from a matrix with different representation.
170  Works only from symmetric to general and not viceversa.
171  */
172  template <class R2>
173  SMatrix(const SMatrix<T,D1,D2,R2>& rhs);
174 
175  /**
176  Construct from an expression.
177  In case of symmetric matrices does not work if expression is of type general
178  matrices. In case one needs to force the assignment from general to symmetric, one can use the
179  ROOT::Math::AssignSym::Evaluate function.
180  */
181  template <class A, class R2>
182  SMatrix(const Expr<A,T,D1,D2,R2>& rhs);
183 
184 
185  /**
186  Constructor with STL iterator interface. The data will be copied into the matrix
187  \param begin start iterator position
188  \param end end iterator position
189  \param triang if true only the triangular lower/upper part of the matrix is filled from the iterators
190  \param lower if true the lower triangular part is filled
191 
192  Size of the matrix must match size of the iterators, if triang is false, otherwise the size of the
193  triangular block. In the case of symmetric matrices triang is considered always to be true
194  (what-ever the user specifies) and the size of the iterators must be equal to the size of the
195  triangular block, which is the number of independent elements of a symmetric matrix: N*(N+1)/2
196 
197  */
198  template<class InputIterator>
199  SMatrix(InputIterator begin, InputIterator end, bool triang = false, bool lower = true);
200 
201  /**
202  Constructor with STL iterator interface. The data will be copied into the matrix
203  \param begin start iterator position
204  \param size iterator size
205  \param triang if true only the triangular lower/upper part of the matrix is filled from the iterators
206  \param lower if true the lower triangular part is filled
207 
208  Size of the iterators must not be larger than the size of the matrix representation.
209  In the case of symmetric matrices the size is N*(N+1)/2.
210 
211  */
212  template<class InputIterator>
213  SMatrix(InputIterator begin, unsigned int size, bool triang = false, bool lower = true);
214 
215  /**
216  constructor of a symmetrix a matrix from a SVector containing the lower (upper)
217  triangular part.
218  */
219 #ifndef UNSUPPORTED_TEMPLATE_EXPRESSION
220  SMatrix(const SVector<T, D1*(D2+1)/2> & v, bool lower = true );
221 #else
222  template<unsigned int N>
223  SMatrix(const SVector<T,N> & v, bool lower = true );
224 #endif
225 
226 
227  /**
228  Construct from a scalar value (only for size 1 matrices)
229  */
230  explicit SMatrix(const T& rhs);
231 
232  /**
233  Assign from another compatible matrix.
234  Possible Symmetirc to general but NOT vice-versa
235  */
236  template <class M>
237  SMatrix<T,D1,D2,R>& operator=(const M& rhs);
238 
239  /**
240  Assign from a matrix expression
241  */
242  template <class A, class R2>
244 
245  /**
246  Assign from an identity matrix
247  */
249 
250  /**
251  Assign from a scalar value (only for size 1 matrices)
252  */
253  SMatrix<T,D1,D2,R>& operator=(const T& rhs);
254 
255  /** @name --- Matrix dimension --- */
256 
257  /**
258  Enumeration defining the matrix dimension,
259  number of rows, columns and size = rows*columns)
260  */
261  enum {
262  /// return no. of matrix rows
263  kRows = D1,
264  /// return no. of matrix columns
265  kCols = D2,
266  /// return no of elements: rows*columns
267  kSize = D1*D2
268  };
269 
270  /** @name --- Access functions --- */
271 
272  /** access the parse tree with the index starting from zero and
273  following the C convention for the order in accessing
274  the matrix elements.
275  Same convention for general and symmetric matrices.
276  */
277  T apply(unsigned int i) const;
278 
279  /// return read-only pointer to internal array
280  const T* Array() const;
281  /// return pointer to internal array
282  T* Array();
283 
284  /** @name --- STL-like interface ---
285  The iterators access the matrix element in the order how they are
286  stored in memory. The C (row-major) convention is used, and in the
287  case of symmetric matrices the iterator spans only the lower diagonal
288  block. For example for a symmetric 3x3 matrices the order of the 6
289  elements \f${a_0,...a_5}\f$ is:
290  \f[
291  M = \left( \begin{array}{ccc}
292  a_0 & a_1 & a_3 \\
293  a_1 & a_2 & a_4 \\
294  a_3 & a_4 & a_5 \end{array} \right)
295  \f]
296  */
297 
298  /** STL iterator interface. */
299  iterator begin();
300 
301  /** STL iterator interface. */
302  iterator end();
303 
304  /** STL const_iterator interface. */
305  const_iterator begin() const;
306 
307  /** STL const_iterator interface. */
308  const_iterator end() const;
309 
310  /**
311  Set matrix elements with STL iterator interface. The data will be copied into the matrix
312  \param begin start iterator position
313  \param end end iterator position
314  \param triang if true only the triangular lower/upper part of the matrix is filled from the iterators
315  \param lower if true the lower triangular part is filled
316 
317  Size of the matrix must match size of the iterators, if triang is false, otherwise the size of the
318  triangular block. In the case of symmetric matrices triang is considered always to be true
319  (what-ever the user specifies) and the size of the iterators must be equal to the size of the
320  triangular block, which is the number of independent elements of a symmetric matrix: N*(N+1)/2
321 
322  */
323  template<class InputIterator>
324  void SetElements(InputIterator begin, InputIterator end, bool triang = false, bool lower = true);
325 
326  /**
327  Constructor with STL iterator interface. The data will be copied into the matrix
328  \param begin start iterator position
329  \param size iterator size
330  \param triang if true only the triangular lower/upper part of the matrix is filled from the iterators
331  \param lower if true the lower triangular part is filled
332 
333  Size of the iterators must not be larger than the size of the matrix representation.
334  In the case of symmetric matrices the size is N*(N+1)/2.
335 
336  */
337  template<class InputIterator>
338  void SetElements(InputIterator begin, unsigned int size, bool triang = false, bool lower = true);
339 
340 
341  /** @name --- Operators --- */
342  /// element wise comparison
343  bool operator==(const T& rhs) const;
344  /// element wise comparison
345  bool operator!=(const T& rhs) const;
346  /// element wise comparison
347  template <class R2>
348  bool operator==(const SMatrix<T,D1,D2,R2>& rhs) const;
349  /// element wise comparison
350  bool operator!=(const SMatrix<T,D1,D2,R>& rhs) const;
351  /// element wise comparison
352  template <class A, class R2>
353  bool operator==(const Expr<A,T,D1,D2,R2>& rhs) const;
354  /// element wise comparison
355  template <class A, class R2>
356  bool operator!=(const Expr<A,T,D1,D2,R2>& rhs) const;
357 
358  /// element wise comparison
359  bool operator>(const T& rhs) const;
360  /// element wise comparison
361  bool operator<(const T& rhs) const;
362  /// element wise comparison
363  template <class R2>
364  bool operator>(const SMatrix<T,D1,D2,R2>& rhs) const;
365  /// element wise comparison
366  template <class R2>
367  bool operator<(const SMatrix<T,D1,D2,R2>& rhs) const;
368  /// element wise comparison
369  template <class A, class R2>
370  bool operator>(const Expr<A,T,D1,D2,R2>& rhs) const;
371  /// element wise comparison
372  template <class A, class R2>
373  bool operator<(const Expr<A,T,D1,D2,R2>& rhs) const;
374 
375  /**
376  read only access to matrix element, with indices starting from 0
377  */
378  const T& operator()(unsigned int i, unsigned int j) const;
379  /**
380  read/write access to matrix element with indices starting from 0
381  */
382  T& operator()(unsigned int i, unsigned int j);
383 
384  /**
385  read only access to matrix element, with indices starting from 0.
386  Function will check index values and it will assert if they are wrong
387  */
388  const T& At(unsigned int i, unsigned int j) const;
389  /**
390  read/write access to matrix element with indices starting from 0.
391  Function will check index values and it will assert if they are wrong
392  */
393  T& At(unsigned int i, unsigned int j);
394 
395 
396  // helper class for implementing the m[i][j] operator
397 
398  class SMatrixRow {
399  public:
400  SMatrixRow ( SMatrix<T,D1,D2,R> & rhs, unsigned int i ) :
401  fMat(&rhs), fRow(i)
402  {}
403  T & operator[](int j) { return (*fMat)(fRow,j); }
404  private:
406  unsigned int fRow;
407  };
408 
410  public:
411  SMatrixRow_const ( const SMatrix<T,D1,D2,R> & rhs, unsigned int i ) :
412  fMat(&rhs), fRow(i)
413  {}
414 
415  const T & operator[](int j) const { return (*fMat)(fRow, j); }
416 
417  private:
419  unsigned int fRow;
420  };
421 
422  /**
423  read only access to matrix element, with indices starting from 0 : m[i][j]
424  */
425  SMatrixRow_const operator[](unsigned int i) const { return SMatrixRow_const(*this, i); }
426  /**
427  read/write access to matrix element with indices starting from 0 : m[i][j]
428  */
429  SMatrixRow operator[](unsigned int i) { return SMatrixRow(*this, i); }
430 
431 
432  /**
433  addition with a scalar
434  */
435  SMatrix<T,D1,D2,R>&operator+=(const T& rhs);
436 
437  /**
438  addition with another matrix of any compatible representation
439  */
440  template <class R2>
442 
443  /**
444  addition with a compatible matrix expression
445  */
446  template <class A, class R2>
448 
449  /**
450  subtraction with a scalar
451  */
452  SMatrix<T,D1,D2,R>& operator-=(const T& rhs);
453 
454  /**
455  subtraction with another matrix of any compatible representation
456  */
457  template <class R2>
459 
460  /**
461  subtraction with a compatible matrix expression
462  */
463  template <class A, class R2>
465 
466  /**
467  multiplication with a scalar
468  */
469  SMatrix<T,D1,D2,R>& operator*=(const T& rhs);
470 
471 #ifndef __CINT__
472 
473 
474  /**
475  multiplication with another compatible matrix (it is a real matrix multiplication)
476  Note that this operation does not avid to create a temporary to store intermidiate result
477  */
478  template <class R2>
480 
481  /**
482  multiplication with a compatible matrix expression (it is a real matrix multiplication)
483  */
484  template <class A, class R2>
486 
487 #endif
488 
489  /**
490  division with a scalar
491  */
492  SMatrix<T,D1,D2,R>& operator/=(const T& rhs);
493 
494 
495 
496  /** @name --- Linear Algebra Functions --- */
497 
498  /**
499  Invert a square Matrix ( this method changes the current matrix).
500  Return true if inversion is successfull.
501  The method used for general square matrices is the LU factorization taken from Dinv routine
502  from the CERNLIB (written in C++ from CLHEP authors)
503  In case of symmetric matrices Bunch-Kaufman diagonal pivoting method is used
504  (The implementation is the one written by the CLHEP authors)
505  */
506  bool Invert();
507 
508  /**
509  Invert a square Matrix and returns a new matrix. In case the inversion fails
510  the current matrix is returned.
511  \param ifail . ifail will be set to 0 when inversion is successfull.
512  See ROOT::Math::SMatrix::Invert for the inversion algorithm
513  */
514  SMatrix<T,D1,D2,R> Inverse(int & ifail ) const;
515 
516  /**
517  Fast Invertion of a square Matrix ( this method changes the current matrix).
518  Return true if inversion is successfull.
519  The method used is based on direct inversion using the Cramer rule for
520  matrices upto 5x5. Afterwards the same default algorithm of Invert() is used.
521  Note that this method is faster but can suffer from much larger numerical accuracy
522  when the condition of the matrix is large
523  */
524  bool InvertFast();
525 
526  /**
527  Invert a square Matrix and returns a new matrix. In case the inversion fails
528  the current matrix is returned.
529  \param ifail . ifail will be set to 0 when inversion is successfull.
530  See ROOT::Math::SMatrix::InvertFast for the inversion algorithm
531  */
532  SMatrix<T,D1,D2,R> InverseFast(int & ifail ) const;
533 
534  /**
535  Invertion of a symmetric positive defined Matrix using Choleski decomposition.
536  ( this method changes the current matrix).
537  Return true if inversion is successfull.
538  The method used is based on Choleski decomposition
539  A compile error is given if the matrix is not of type symmetric and a run-time failure if the
540  matrix is not positive defined.
541  For solving a linear system, it is possible to use also the function
542  ROOT::Math::SolveChol(matrix, vector) which will be faster than performing the inversion
543  */
544  bool InvertChol();
545 
546  /**
547  Invert of a symmetric positive defined Matrix using Choleski decomposition.
548  A compile error is given if the matrix is not of type symmetric and a run-time failure if the
549  matrix is not positive defined.
550  In case the inversion fails the current matrix is returned.
551  \param ifail . ifail will be set to 0 when inversion is successfull.
552  See ROOT::Math::SMatrix::InvertChol for the inversion algorithm
553  */
554  SMatrix<T,D1,D2,R> InverseChol(int & ifail ) const;
555 
556  /**
557  determinant of square Matrix via Dfact.
558  Return true when the calculation is successfull.
559  \param det will contain the calculated determinant value
560  \b Note: this will destroy the contents of the Matrix!
561  */
562  bool Det(T& det);
563 
564  /**
565  determinant of square Matrix via Dfact.
566  Return true when the calculation is successfull.
567  \param det will contain the calculated determinant value
568  \b Note: this will preserve the content of the Matrix!
569  */
570  bool Det2(T& det) const;
571 
572 
573  /** @name --- Matrix Slice Functions --- */
574 
575  /// place a vector in a Matrix row
576  template <unsigned int D>
578  unsigned int row,
579  unsigned int col);
580  /// place a vector expression in a Matrix row
581  template <class A, unsigned int D>
583  unsigned int row,
584  unsigned int col);
585  /// place a vector in a Matrix column
586  template <unsigned int D>
588  unsigned int row,
589  unsigned int col);
590  /// place a vector expression in a Matrix column
591  template <class A, unsigned int D>
593  unsigned int row,
594  unsigned int col);
595  /// place a matrix in this matrix
596  template <unsigned int D3, unsigned int D4, class R2>
598  unsigned int row,
599  unsigned int col);
600  /// place a matrix expression in this matrix
601  template <class A, unsigned int D3, unsigned int D4, class R2>
603  unsigned int row,
604  unsigned int col);
605 
606  /**
607  return a full Matrix row as a vector (copy the content in a new vector)
608  */
609  SVector<T,D2> Row(unsigned int therow) const;
610 
611  /**
612  return a full Matrix column as a vector (copy the content in a new vector)
613  */
614  SVector<T,D1> Col(unsigned int thecol) const;
615 
616  /**
617  return a slice of therow as a vector starting at the colum value col0 until col0+N,
618  where N is the size of the vector (SubVector::kSize )
619  Condition col0+N <= D2
620  */
621  template <class SubVector>
622  SubVector SubRow(unsigned int therow, unsigned int col0 = 0 ) const;
623 
624  /**
625  return a slice of the column as a vector starting at the row value row0 until row0+Dsub.
626  where N is the size of the vector (SubVector::kSize )
627  Condition row0+N <= D1
628  */
629  template <class SubVector>
630  SubVector SubCol(unsigned int thecol, unsigned int row0 = 0) const;
631 
632  /**
633  return a submatrix with the upper left corner at the values (row0, col0) and with sizes N1, N2
634  where N1 and N2 are the dimension of the sub-matrix (SubMatrix::kRows and SubMatrix::kCols )
635  Condition row0+N1 <= D1 && col0+N2 <=D2
636  */
637  template <class SubMatrix >
638  SubMatrix Sub(unsigned int row0, unsigned int col0) const;
639 
640  /**
641  return diagonal elements of a matrix as a Vector.
642  It works only for squared matrices D1 == D2, otherwise it will produce a compile error
643  */
644  SVector<T,D1> Diagonal() const;
645 
646  /**
647  Set the diagonal elements from a Vector
648  Require that vector implements ::kSize since a check (statically) is done on
649  diagonal size == vector size
650  */
651  template <class Vector>
652  void SetDiagonal(const Vector & v);
653 
654  /**
655  return the trace of a matrix
656  Sum of the diagonal elements
657  */
658  T Trace() const;
659 
660 
661  /**
662  return the upper Triangular block of the matrices (including the diagonal) as
663  a vector of sizes N = D1 * (D1 + 1)/2.
664  It works only for square matrices with D1==D2, otherwise it will produce a compile error
665  */
666 #ifndef UNSUPPORTED_TEMPLATE_EXPRESSION
667  SVector<T, D1 * (D2 +1)/2> UpperBlock() const;
668 #else
669  template<class SubVector>
670  SubVector UpperBlock() const;
671 #endif
672 
673  /**
674  return the lower Triangular block of the matrices (including the diagonal) as
675  a vector of sizes N = D1 * (D1 + 1)/2.
676  It works only for square matrices with D1==D2, otherwise it will produce a compile error
677  */
678 #ifndef UNSUPPORTED_TEMPLATE_EXPRESSION
679  SVector<T, D1 * (D2 +1)/2> LowerBlock() const;
680 #else
681  template<class SubVector>
682  SubVector LowerBlock() const;
683 #endif
684 
685 
686  /** @name --- Other Functions --- */
687 
688  /**
689  Function to check if a matrix is sharing same memory location of the passed pointer
690  This function is used by the expression templates to avoid the alias problem during
691  expression evaluation. When the matrix is in use, for example in operations
692  like A = B * A, a temporary object storing the intermediate result is automatically
693  created when evaluating the expression.
694 
695  */
696  bool IsInUse(const T* p) const;
697 
698  // submatrices
699 
700  /// Print: used by operator<<()
701  std::ostream& Print(std::ostream& os) const;
702 
703 
704 
705 
706 public:
707 
708  /** @name --- Data Member --- */
709 
710  /**
711  Matrix Storage Object containing matrix data
712  */
713  R fRep;
714 
715 }; // end of class SMatrix
716 
717 
718 
719 
720 //==============================================================================
721 // operator<<
722 //==============================================================================
723 template <class T, unsigned int D1, unsigned int D2, class R>
724 inline std::ostream& operator<<(std::ostream& os, const ROOT::Math::SMatrix<T,D1,D2,R>& rhs) {
725  return rhs.Print(os);
726 }
727 
728 
729  } // namespace Math
730 
731 } // namespace ROOT
732 
733 
734 
735 
736 
737 
738 #ifndef __CINT__
739 
740 #ifndef ROOT_Math_SMatrix_icc
741 #include "Math/SMatrix.icc"
742 #endif
743 
744 #ifndef ROOT_Math_MatrixFunctions
745 #include "Math/MatrixFunctions.h"
746 #endif
747 
748 #endif //__CINT__
749 
750 #endif /* ROOT_Math_SMatrix */
SMatrix< T, D1, D2, R > & operator+=(const T &rhs)
addition with a scalar
Definition: SMatrix.icc:196
SubVector SubRow(unsigned int therow, unsigned int col0=0) const
return a slice of therow as a vector starting at the colum value col0 until col0+N, where N is the size of the vector (SubVector::kSize ) Condition col0+N <= D2
Definition: SMatrix.icc:711
SMatrix< T, D1, D2, R > & operator*=(const T &rhs)
multiplication with a scalar
Definition: SMatrix.icc:257
void SetDiagonal(const Vector &v)
Set the diagonal elements from a Vector Require that vector implements kSize since a check (staticall...
Definition: SMatrix.icc:769
bool operator==(const T &rhs) const
element wise comparison
Definition: SMatrix.icc:298
SMatrix< T, D1, D2, R > InverseChol(int &ifail) const
Invert of a symmetric positive defined Matrix using Choleski decomposition.
Definition: SMatrix.icc:451
SMatrix< T, D1, D2, R > & operator/=(const T &rhs)
division with a scalar
Definition: SMatrix.icc:286
Namespace for new ROOT classes and functions.
Definition: ROOT.py:1
double T(double x)
Definition: ChebyshevPol.h:34
SMatrix< T, D1, D2, R > & operator-=(const T &rhs)
subtraction with a scalar
Definition: SMatrix.icc:227
SMatrix< T, D1, D2, R > & operator=(const M &rhs)
Assign from another compatible matrix.
Definition: SMatrix.icc:160
T * iterator
STL iterator interface.
Definition: SMatrix.h:141
return no. of matrix rows
Definition: SMatrix.h:263
SMatrix< T, D1, D2, R > * fMat
Definition: SMatrix.h:405
bool Invert()
Invert a square Matrix ( this method changes the current matrix).
Definition: SMatrix.icc:411
bool InvertFast()
Fast Invertion of a square Matrix ( this method changes the current matrix).
Definition: SMatrix.icc:428
bool InvertChol()
Invertion of a symmetric positive defined Matrix using Choleski decomposition.
Definition: SMatrix.icc:445
SVector< T, D1 > Diagonal() const
return diagonal elements of a matrix as a Vector.
Definition: SMatrix.icc:754
bool Det2(T &det) const
determinant of square Matrix via Dfact.
Definition: SMatrix.icc:472
const T * const_iterator
STL const_iterator interface.
Definition: SMatrix.h:144
bool Det(T &det)
determinant of square Matrix via Dfact.
Definition: SMatrix.icc:465
SMatrix: a generic fixed size D1 x D2 Matrix class.
T apply(unsigned int i) const
access the parse tree with the index starting from zero and following the C convention for the order ...
Definition: SMatrix.icc:626
SMatrix()
Default constructor:
Definition: SMatrix.icc:77
const T * Array() const
return read-only pointer to internal array
Definition: SMatrix.icc:629
const T & operator[](int j) const
Definition: SMatrix.h:415
SVector< T, D1 *(D2+1)/2 > LowerBlock() const
return the lower Triangular block of the matrices (including the diagonal) as a vector of sizes N = D...
Definition: SMatrix.icc:825
SVector< T, D1 > Col(unsigned int thecol) const
return a full Matrix column as a vector (copy the content in a new vector)
Definition: SMatrix.icc:589
R rep_type
storage representation type
Definition: SMatrix.h:138
Expression wrapper class for Matrix objects.
Definition: Expression.h:134
R fRep
Matrix Storage Object containing matrix data.
Definition: SMatrix.h:713
SMatrix< T, D1, D2, R > InverseFast(int &ifail) const
Invert a square Matrix and returns a new matrix.
Definition: SMatrix.icc:435
SMatrixRow_const operator[](unsigned int i) const
read only access to matrix element, with indices starting from 0 : m[i][j]
Definition: SMatrix.h:425
SMatrixRow operator[](unsigned int i)
read/write access to matrix element with indices starting from 0 : m[i][j]
Definition: SMatrix.h:429
SVector< double, 2 > v
Definition: Dict.h:5
iterator begin()
STL iterator interface.
Definition: SMatrix.icc:669
SubVector SubCol(unsigned int thecol, unsigned int row0=0) const
return a slice of the column as a vector starting at the row value row0 until row0+Dsub.
Definition: SMatrix.icc:727
SMatrix< T, D1, D2, R > & Place_in_row(const SVector< T, D > &rhs, unsigned int row, unsigned int col)
place a vector in a Matrix row
Definition: SMatrix.icc:483
bool IsInUse(const T *p) const
Function to check if a matrix is sharing same memory location of the passed pointer This function is ...
Definition: SMatrix.icc:894
return no. of matrix columns
Definition: SMatrix.h:265
SMatrix(SMatrixNoInit)
construct from without initialization
Definition: SMatrix.h:158
const T & operator()(unsigned int i, unsigned int j) const
read only access to matrix element, with indices starting from 0
Definition: SMatrix.icc:638
SVector< T, D1 *(D2+1)/2 > UpperBlock() const
return the upper Triangular block of the matrices (including the diagonal) as a vector of sizes N = D...
Definition: SMatrix.icc:796
bool operator<(const T &rhs) const
element wise comparison
Definition: SMatrix.icc:378
SMatrixRow_const(const SMatrix< T, D1, D2, R > &rhs, unsigned int i)
Definition: SMatrix.h:411
T value_type
contained scalar type
Definition: SMatrix.h:135
SMatrixRow(SMatrix< T, D1, D2, R > &rhs, unsigned int i)
Definition: SMatrix.h:400
return no of elements: rows*columns
Definition: SMatrix.h:267
std::ostream & Print(std::ostream &os) const
Print: used by operator<<()
Definition: SMatrix.icc:602
const T & At(unsigned int i, unsigned int j) const
read only access to matrix element, with indices starting from 0.
Definition: SMatrix.icc:652
SubMatrix Sub(unsigned int row0, unsigned int col0) const
return a submatrix with the upper left corner at the values (row0, col0) and with sizes N1...
Definition: SMatrix.icc:744
bool operator>(const T &rhs) const
element wise comparison
Definition: SMatrix.icc:346
const SMatrix< T, D1, D2, R > * fMat
Definition: SMatrix.h:418
T Trace() const
return the trace of a matrix Sum of the diagonal elements
Definition: SMatrix.icc:783
Namespace for new Math classes and functions.
Expression wrapper class for Vector objects.
Definition: Expression.h:64
SMatrix< T, D1, D2, R > & Place_at(const SMatrix< T, D3, D4, R2 > &rhs, unsigned int row, unsigned int col)
place a matrix in this matrix
Definition: SMatrix.icc:551
bool operator!=(const T &rhs) const
element wise comparison
Definition: SMatrix.icc:326
SVector< T, D2 > Row(unsigned int therow) const
return a full Matrix row as a vector (copy the content in a new vector)
Definition: SMatrix.icc:574
SMatrix< T, D1, D2, R > Inverse(int &ifail) const
Invert a square Matrix and returns a new matrix.
Definition: SMatrix.icc:418
SMatrix< T, D1, D2, R > & Place_in_col(const SVector< T, D > &rhs, unsigned int row, unsigned int col)
place a vector in a Matrix column
Definition: SMatrix.icc:517
void SetElements(InputIterator begin, InputIterator end, bool triang=false, bool lower=true)
Set matrix elements with STL iterator interface.
Definition: SMatrix.icc:691
TRandom3 R
a TMatrixD.
Definition: testIO.cxx:28
static const float lower
Definition: main.cpp:48
SVector: a generic fixed size Vector class.
iterator end()
STL iterator interface.
Definition: SMatrix.icc:674