4 #ifndef ROOT_Math_SMatrix_icc 5 #define ROOT_Math_SMatrix_icc 37 #ifndef ROOT_Math_SMatrix 38 #error "Do not use SMatrix.icc directly. #include \"Math/SMatrix.h\" instead." 39 #endif // ROOT_Math_SMatrix 71 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
74 for(
unsigned int i=0; i<R::kSize; ++i) fRep.Array()[i] = 0;
78 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
80 for(
unsigned int i=0; i<R::kSize; ++i)
83 for(
unsigned int i=0; i<D1; ++i)
87 for(
unsigned int i=0; i<D2; ++i)
92 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
98 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
105 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
106 template <
class A,
class R2>
115 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
116 template <
class InputIterator>
119 for(
unsigned int i=0; i<R::kSize; ++i) fRep.Array()[i] = 0;
123 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
124 template <
class InputIterator>
127 assert( size <= R::kSize);
128 for(
unsigned int i=0; i<R::kSize; ++i) fRep.Array()[i] = 0;
137 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
143 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
153 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
160 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
161 template <
class A,
class R2>
162 SMatrix<T,D1,D2,R>&
SMatrix<T,D1,D2,R>::operator=(
const Expr<A,T,D1,D2,R2>& rhs) {
170 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
172 for(
unsigned int i=0; i<R::kSize; ++i)
175 for(
unsigned int i=0; i<D1; ++i)
179 for(
unsigned int i=0; i<D2; ++i)
190 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
193 for(
unsigned int i=0; i<R::kSize; ++i) {
194 fRep.Array()[i] += rhs;
199 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
209 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
210 template <
class A,
class R2>
211 SMatrix<T,D1,D2,R>&
SMatrix<T,D1,D2,R>::operator+=(
const Expr<A,T,D1,D2,R2>& rhs) {
221 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
224 for(
unsigned int i=0; i<R::kSize; ++i) {
225 fRep.Array()[i] -= rhs;
230 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
240 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
241 template <
class A,
class R2>
242 SMatrix<T,D1,D2,R>&
SMatrix<T,D1,D2,R>::operator-=(
const Expr<A,T,D1,D2,R2>& rhs) {
251 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
254 for(
unsigned int i=0; i<R::kSize; ++i) {
255 fRep.Array()[i] *= rhs;
260 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
265 return operator=(*
this * rhs);
268 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
269 template <
class A,
class R2>
270 SMatrix<T,D1,D2,R>&
SMatrix<T,D1,D2,R>::operator*=(
const Expr<A,T,D1,D2,R2>& rhs) {
273 return operator=(*
this * rhs);
280 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
283 for(
unsigned int i=0; i<R::kSize; ++i) {
284 fRep.Array()[i] /= rhs;
292 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
295 for(
unsigned int i=0; i<R::kSize; ++i) {
296 rc = rc && (fRep.Array()[i] == rhs);
301 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
304 return fRep == rhs.
fRep;
307 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
308 template <
class A,
class R2>
311 for(
unsigned int i=0; i<D1*D2; ++i) {
312 rc = rc && (fRep[i] == rhs.
apply(i));
320 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
325 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
330 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
331 template <
class A,
class R2>
340 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
343 for(
unsigned int i=0; i<D1*D2; ++i) {
344 rc = rc && (fRep[i] > rhs);
349 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
353 for(
unsigned int i=0; i<D1*D2; ++i) {
354 rc = rc && (fRep[i] > rhs.
fRep[i]);
359 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
360 template <
class A,
class R2>
363 for(
unsigned int i=0; i<D1*D2; ++i) {
364 rc = rc && (fRep[i] > rhs.
apply(i));
372 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
375 for(
unsigned int i=0; i<D1*D2; ++i) {
376 rc = rc && (fRep[i] < rhs);
381 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
385 for(
unsigned int i=0; i<D1*D2; ++i) {
386 rc = rc && (fRep[i] < rhs.
fRep[i]);
391 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
392 template <
class A,
class R2>
395 for(
unsigned int i=0; i<D1*D2; ++i) {
396 rc = rc && (fRep[i] < rhs.
apply(i));
405 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
412 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
422 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
429 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
439 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
445 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
459 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
466 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
476 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
477 template <
unsigned int D>
484 for(
unsigned int i=row*D2+col, j=0; j<D; ++i, ++j) {
485 fRep[i] = rhs.
apply(j);
493 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
494 template <
class A,
unsigned int D>
501 for(
unsigned int i=row*D2+col, j=0; j<D; ++i, ++j) {
502 fRep[i] = rhs.
apply(j);
510 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
511 template <
unsigned int D>
518 for(
unsigned int i=row*D2+col, j=0; j<D; i+=D2, ++j) {
519 fRep[i] = rhs.
apply(j);
527 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
528 template <
class A,
unsigned int D>
535 for(
unsigned int i=row*D2+col, j=0; j<D; i+=D2, ++j) {
536 fRep[i] = rhs.
apply(j);
544 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
545 template <
unsigned int D3,
unsigned int D4,
class R2>
546 SMatrix<T,D1,D2,R>&
SMatrix<T,D1,D2,R>::Place_at(
const SMatrix<T,D3,D4,R2>& rhs,
556 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
557 template <
class A,
unsigned int D3,
unsigned int D4,
class R2>
558 SMatrix<T,D1,D2,R>&
SMatrix<T,D1,D2,R>::Place_at(
const Expr<A,T,D3,D4,R2>& rhs,
561 PlaceExpr<T,D1,D2,D3,D4,A,R,R2>::Evaluate(*
this,rhs,row,col);
568 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
571 const unsigned int offset = therow*D2;
574 for(
unsigned int i=0; i<D2; ++i) {
575 tmp[i] = fRep[offset+i];
583 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
587 for(
unsigned int i=0; i<D1; ++i) {
588 tmp[i] = fRep[thecol+i*D2];
596 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
598 const std::ios_base::fmtflags prevFmt = os.setf(std::ios::right,std::ios::adjustfield);
602 for (
unsigned int i=0; i < D1; ++i) {
603 for (
unsigned int j=0; j < D2; ++j) {
604 os << std::setw(12) << fRep[i*D2+j];
605 if ((!((j+1)%12)) && (j < D2-1))
606 os << std::endl <<
" ...";
609 os << std::endl <<
" ";
613 if (prevFmt != os.flags() ) os.setf(prevFmt, std::ios::adjustfield);
620 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
623 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
626 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
632 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
637 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
646 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
653 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
663 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
668 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
670 return fRep.Array() + R::kSize;
673 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
678 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
680 return fRep.Array() + R::kSize;
684 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
685 template <
class InputIterator>
691 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
692 template <
class InputIterator>
695 assert( size <= R::kSize);
704 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
705 template <
class SubVector>
708 const unsigned int offset = therow*D2 + col0;
710 STATIC_CHECK( SubVector::kSize <= D2,SVector_dimension_too_small);
711 assert(col0 + SubVector::kSize <= D2);
714 for(
unsigned int i=0; i<SubVector::kSize; ++i) {
715 tmp[i] = fRep[offset+i];
720 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
721 template <
class SubVector>
724 const unsigned int offset = thecol + row0*D1;
726 STATIC_CHECK( SubVector::kSize <= D1,SVector_dimension_too_small);
727 assert(row0 + SubVector::kSize <= D1);
730 for(
unsigned int i=0; i<SubVector::kSize; ++i) {
731 tmp[i] = fRep[offset+i*D1];
737 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
738 template <
class SubMatrix>
743 (tmp,*
this,row0,col0);
748 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
755 for(
unsigned int i=0; i<D1; ++i) {
756 tmp[i] = fRep[ i*D2 + i];
762 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
763 template <
class Vector>
768 ( ( D2 < D1 ) && Vector::kSize == D2 ), SVector_size_NOT_correct );
771 for(
unsigned int i=0; i<Vector::kSize; ++i) {
772 fRep[ i*D2 + i] = v[i];
777 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
779 unsigned int diagSize = D1;
780 if (D2 < D1) diagSize = D2;
782 for(
unsigned int i=0; i< diagSize; ++i) {
783 trace += fRep[ i*D2 + i] ;
789 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
790 #ifndef UNSUPPORTED_TEMPLATE_EXPRESSION 793 template <
class SubVector>
799 #ifndef UNSUPPORTED_TEMPLATE_EXPRESSION 803 STATIC_CHECK( SubVector::kSize == D1*(D1+1)/2,SVector_Wrong_Size );
808 for(
unsigned int i=0; i<D1; ++i) {
809 for(
unsigned int j=i; j<D2; ++j) {
810 tmp[k] = fRep[ i*D2 + j];
818 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
819 #ifndef UNSUPPORTED_TEMPLATE_EXPRESSION 822 template <
class SubVector>
829 #ifndef UNSUPPORTED_TEMPLATE_EXPRESSION 833 STATIC_CHECK( SubVector::kSize == D1*(D1+1)/2,SVector_Wrong_Size );
838 for(
unsigned int i=0; i<D1; ++i) {
839 for(
unsigned int j=0; j<=i; ++j) {
840 tmp[k] = fRep[ i*D2 + j];
850 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
851 #ifndef UNSUPPORTED_TEMPLATE_EXPRESSION 854 template <
unsigned int N>
861 #ifdef UNSUPPORTED_TEMPLATE_EXPRESSION 868 for(
unsigned int i=0; i<D1; ++i) {
869 for(
unsigned int j=0; j<=i; ++j) {
870 fRep[ i*D2 + j] = v[k];
871 if ( i != j) fRep[ j*D2 + i] = v[k];
877 for(
unsigned int i=0; i<D1; ++i) {
878 for(
unsigned int j=i; j<D2; ++j) {
879 fRep[ i*D2 + j] = v[k];
880 if ( i != j) fRep[ j*D2 + i] = v[k];
888 template <
class T,
unsigned int D1,
unsigned int D2,
class R>
890 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 (statica...
SMatrix< T, D1, D2, R > & operator/=(const T &rhs)
division with a scalar
bool operator!=(const T &rhs) const
element wise comparison
Namespace for new ROOT classes and functions.
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.
Bool_t operator==(const TMatrixTBase< Element > &m1, const TMatrixTBase< Element > &m2)
Check to see if two matrices are identical.
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...
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.