4 #ifndef ROOT_Math_SMatrix_icc 5 #define ROOT_Math_SMatrix_icc 45 #ifndef ROOT_Math_Dfact 48 #ifndef ROOT_Math_Dinv 51 #ifndef ROOT_Math_Functions 54 #ifndef ROOT_Math_HelperOps 57 #ifndef ROOT_Math_StaticCheck 76 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
79 for(
unsigned int i=0; i<
R::kSize; ++i) fRep.Array()[i] = 0;
83 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
85 for(
unsigned int i=0; i<
R::kSize; ++i)
88 for(
unsigned int i=0; i<D1; ++i)
92 for(
unsigned int i=0; i<D2; ++i)
97 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
103 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
110 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
111 template <
class A,
class R2>
120 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
121 template <
class InputIterator>
124 for(
unsigned int i=0; i<
R::kSize; ++i) fRep.Array()[i] = 0;
128 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
129 template <
class InputIterator>
133 for(
unsigned int i=0; i<
R::kSize; ++i) fRep.Array()[i] = 0;
142 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
148 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
158 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
165 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
166 template <
class A,
class R2>
167 SMatrix<T,D1,D2,R>&
SMatrix<T,D1,D2,R>::operator=(
const Expr<A,T,D1,D2,R2>& rhs) {
175 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
177 for(
unsigned int i=0; i<
R::kSize; ++i)
180 for(
unsigned int i=0; i<D1; ++i)
184 for(
unsigned int i=0; i<D2; ++i)
195 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
198 for(
unsigned int i=0; i<
R::kSize; ++i) {
199 fRep.Array()[i] += rhs;
204 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
214 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
215 template <
class A,
class R2>
216 SMatrix<T,D1,D2,R>&
SMatrix<T,D1,D2,R>::operator+=(
const Expr<A,T,D1,D2,R2>& rhs) {
226 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
229 for(
unsigned int i=0; i<
R::kSize; ++i) {
230 fRep.Array()[i] -= rhs;
235 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
245 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
246 template <
class A,
class R2>
247 SMatrix<T,D1,D2,R>&
SMatrix<T,D1,D2,R>::operator-=(
const Expr<A,T,D1,D2,R2>& rhs) {
256 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
259 for(
unsigned int i=0; i<
R::kSize; ++i) {
260 fRep.Array()[i] *= rhs;
265 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
270 return operator=(*
this * rhs);
273 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
274 template <
class A,
class R2>
275 SMatrix<T,D1,D2,R>&
SMatrix<T,D1,D2,R>::operator*=(
const Expr<A,T,D1,D2,R2>& rhs) {
278 return operator=(*
this * rhs);
285 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
288 for(
unsigned int i=0; i<
R::kSize; ++i) {
289 fRep.Array()[i] /= rhs;
297 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
300 for(
unsigned int i=0; i<
R::kSize; ++i) {
301 rc = rc && (fRep.Array()[i] == rhs);
306 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
309 return fRep == rhs.
fRep;
312 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
313 template <
class A,
class R2>
316 for(
unsigned int i=0; i<D1*D2; ++i) {
317 rc = rc && (fRep[i] == rhs.
apply(i));
325 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
330 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
335 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
336 template <
class A,
class R2>
345 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
348 for(
unsigned int i=0; i<D1*D2; ++i) {
349 rc = rc && (fRep[i] > rhs);
354 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
358 for(
unsigned int i=0; i<D1*D2; ++i) {
359 rc = rc && (fRep[i] > rhs.
fRep[i]);
364 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
365 template <
class A,
class R2>
368 for(
unsigned int i=0; i<D1*D2; ++i) {
369 rc = rc && (fRep[i] > rhs.
apply(i));
377 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
380 for(
unsigned int i=0; i<D1*D2; ++i) {
381 rc = rc && (fRep[i] < rhs);
386 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
390 for(
unsigned int i=0; i<D1*D2; ++i) {
391 rc = rc && (fRep[i] < rhs.
fRep[i]);
396 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
397 template <
class A,
class R2>
400 for(
unsigned int i=0; i<D1*D2; ++i) {
401 rc = rc && (fRep[i] < rhs.
apply(i));
410 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
417 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
427 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
434 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
444 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
450 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
464 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
471 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
481 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
482 template <
unsigned int D>
489 for(
unsigned int i=row*D2+col, j=0; j<D; ++i, ++j) {
490 fRep[i] = rhs.
apply(j);
498 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
499 template <
class A,
unsigned int D>
506 for(
unsigned int i=row*D2+col, j=0; j<D; ++i, ++j) {
507 fRep[i] = rhs.
apply(j);
515 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
516 template <
unsigned int D>
523 for(
unsigned int i=row*D2+col, j=0; j<D; i+=D2, ++j) {
524 fRep[i] = rhs.
apply(j);
532 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
533 template <
class A,
unsigned int D>
540 for(
unsigned int i=row*D2+col, j=0; j<D; i+=D2, ++j) {
541 fRep[i] = rhs.
apply(j);
549 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
550 template <
unsigned int D3,
unsigned int D4,
class R2>
551 SMatrix<T,D1,D2,R>&
SMatrix<T,D1,D2,R>::Place_at(
const SMatrix<T,D3,D4,R2>& rhs,
561 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
562 template <
class A,
unsigned int D3,
unsigned int D4,
class R2>
563 SMatrix<T,D1,D2,R>&
SMatrix<T,D1,D2,R>::Place_at(
const Expr<A,T,D3,D4,R2>& rhs,
566 PlaceExpr<T,D1,D2,D3,D4,A,R,R2>::Evaluate(*
this,rhs,row,col);
573 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
576 const unsigned int offset = therow*D2;
579 for(
unsigned int i=0; i<D2; ++i) {
580 tmp[i] = fRep[offset+i];
588 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
592 for(
unsigned int i=0; i<D1; ++i) {
593 tmp[i] = fRep[thecol+i*D2];
601 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
603 const std::ios_base::fmtflags prevFmt = os.setf(std::ios::right,std::ios::adjustfield);
607 for (
unsigned int i=0; i < D1; ++i) {
608 for (
unsigned int j=0; j < D2; ++j) {
609 os << std::setw(12) << fRep[i*D2+j];
610 if ((!((j+1)%12)) && (j < D2-1))
611 os << std::endl <<
" ...";
614 os << std::endl <<
" ";
618 if (prevFmt != os.flags() ) os.setf(prevFmt, std::ios::adjustfield);
625 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
628 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
631 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
637 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
642 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
651 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
658 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
668 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
673 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
678 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
683 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
689 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
690 template <
class InputIterator>
696 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
697 template <
class InputIterator>
709 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
710 template <
class SubVector>
713 const unsigned int offset = therow*D2 + col0;
720 tmp[i] = fRep[offset+i];
725 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
726 template <
class SubVector>
729 const unsigned int offset = thecol + row0*D1;
736 tmp[i] = fRep[offset+i*D1];
742 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
743 template <
class SubMatrix>
748 (tmp,*
this,row0,col0);
753 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
760 for(
unsigned int i=0; i<D1; ++i) {
761 tmp[i] = fRep[ i*D2 + i];
767 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
768 template <
class Vector>
773 ( ( D2 < D1 ) &&
Vector::kSize == D2 ), SVector_size_NOT_correct );
777 fRep[ i*D2 + i] = v[i];
782 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
784 unsigned int diagSize = D1;
785 if (D2 < D1) diagSize = D2;
787 for(
unsigned int i=0; i< diagSize; ++i) {
788 trace += fRep[ i*D2 + i] ;
794 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
795 #ifndef UNSUPPORTED_TEMPLATE_EXPRESSION 798 template <
class SubVector>
804 #ifndef UNSUPPORTED_TEMPLATE_EXPRESSION 813 for(
unsigned int i=0; i<D1; ++i) {
814 for(
unsigned int j=i; j<D2; ++j) {
815 tmp[k] = fRep[ i*D2 + j];
823 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
824 #ifndef UNSUPPORTED_TEMPLATE_EXPRESSION 827 template <
class SubVector>
834 #ifndef UNSUPPORTED_TEMPLATE_EXPRESSION 843 for(
unsigned int i=0; i<D1; ++i) {
844 for(
unsigned int j=0; j<=i; ++j) {
845 tmp[k] = fRep[ i*D2 + j];
855 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
856 #ifndef UNSUPPORTED_TEMPLATE_EXPRESSION 859 template <
unsigned int N>
866 #ifdef UNSUPPORTED_TEMPLATE_EXPRESSION 873 for(
unsigned int i=0; i<D1; ++i) {
874 for(
unsigned int j=0; j<=i; ++j) {
875 fRep[ i*D2 + j] = v[k];
876 if ( i != j) fRep[ j*D2 + i] = v[k];
882 for(
unsigned int i=0; i<D1; ++i) {
883 for(
unsigned int j=i; j<D2; ++j) {
884 fRep[ i*D2 + j] = v[k];
885 if ( i != j) fRep[ j*D2 + i] = v[k];
893 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
895 return p == fRep.Array();
SMatrix< T, D1, D2, R > InverseChol(int &ifail) const
Invert of a symmetric positive defined Matrix using Choleski decomposition.
SMatrix< T, D1, D2, R > & operator+=(const T &rhs)
addition with a scalar
SMatrix< T, D1, D2, R > & operator*=(const T &rhs)
multiplication with a scalar
void SetDiagonal(const Vector &v)
Set the diagonal elements from a Vector Require that vector implements kSize since a check (staticall...
SMatrix< T, D1, D2, R > & operator/=(const T &rhs)
division with a scalar
bool operator!=(const T &rhs) const
element wise comparison
This namespace contains pre-defined functions to be used in conjuction with TExecutor::Map and TExecu...
bool operator<(const T &rhs) const
element wise comparison
static bool Dinv(MatrixRep &)
SMatrix< T, D1, D2, R > & operator-=(const T &rhs)
subtraction with a scalar
static bool Dinv(MatrixRep &rhs)
static void Evaluate(SMatrix< T, D1, D2, R1 > &lhs, const Expr< A, T, D1, D2, R2 > &rhs)
SMatrix< T, D1, D2, R > & operator=(const M &rhs)
Assign from another compatible matrix.
const T * Array() const
return read-only pointer to internal array
bool Invert()
Invert a square Matrix ( this method changes the current matrix).
SVector< T, D2 > Row(unsigned int therow) const
return a full Matrix row as a vector (copy the content in a new vector)
bool InvertFast()
Fast Invertion of a square Matrix ( this method changes the current matrix).
bool InvertChol()
Invertion of a symmetric positive defined Matrix using Choleski decomposition.
#define STATIC_CHECK(expr, msg)
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.
SMatrix< T, D1, D2, R > InverseFast(int &ifail) const
Invert a square Matrix and returns a new matrix.
static void Evaluate(SMatrix< T, D1, D2, R1 > &lhs, const SMatrix< T, D3, D4, R2 > &rhs, unsigned int row, unsigned int col)
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
bool Det(T &det)
determinant of square Matrix via Dfact.
SMatrix: a generic fixed size D1 x D2 Matrix class.
SMatrix()
Default constructor:
const T & operator()(unsigned int i, unsigned int j) const
read only access to matrix element, with indices starting from 0
bool IsInUse(const T *p) const
Function to check if a matrix is sharing same memory location of the passed pointer This function is ...
const T & At(unsigned int i, unsigned int j) const
read only access to matrix element, with indices starting from 0.
R fRep
Matrix Storage Object containing matrix data.
std::ostream & Print(std::ostream &os) const
Print: used by operator<<()
iterator begin()
STL iterator interface.
SVector< T, D1 > Diagonal() const
return diagonal elements of a matrix as a Vector.
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
T apply(unsigned int i) const
access the parse tree. Index starts from zero
bool Det2(T &det) const
determinant of square Matrix via Dfact.
SMatrix< T, D1, D2, R > Inverse(int &ifail) const
Invert a square Matrix and returns a new matrix.
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...
bool operator>(const T &rhs) const
element wise comparison
static void Evaluate(SMatrix< T, D1, D2, R1 > &lhs, const Expr< A, T, D1, D2, R2 > &rhs)
static void Evaluate(SMatrix< T, D1, D2, R > &lhs, Iterator begin, Iterator end, bool triang, bool lower, bool check=true)
static void Evaluate(SMatrix< T, D1, D2, R1 > &lhs, const SMatrix< T, D3, D4, R2 > &rhs, unsigned int row, unsigned int col)
T apply(unsigned int i) const
access the parse tree with the index starting from zero and following the C convention for the order ...
T Trace() const
return the trace of a matrix Sum of the diagonal elements
static bool Dinv(MatrixRep &rhs)
matrix inversion for a generic square matrix using LU factorization (code originally from CERNLIB and...
Namespace for new Math classes and functions.
bool operator==(const T &rhs) const
element wise comparison
Expression wrapper class for Vector objects.
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...
Bool_t operator==(const TDatime &d1, const TDatime &d2)
static void Evaluate(SMatrix< T, D1, D2, R1 > &lhs, const Expr< A, T, D1, D2, R2 > &rhs)
Evaluate the expression from general to general matrices.
static void Evaluate(SMatrix< T, D1, D2, R1 > &lhs, const Expr< A, T, D3, D4, R2 > &rhs, unsigned int row, unsigned int col)
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
static bool Dfact(MatRepStd< T, n, idim > &rhs, T &det)
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
void SetElements(InputIterator begin, InputIterator end, bool triang=false, bool lower=true)
Set matrix elements with STL iterator interface.
T apply(unsigned int i) const
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...
SVector< T, D1 > Col(unsigned int thecol) const
return a full Matrix column as a vector (copy the content in a new vector)
SVector: a generic fixed size Vector class.
T apply(unsigned int i) const
iterator end()
STL iterator interface.