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."
71template <
class T,
unsigned int D1,
unsigned int D2,
class R>
74 for(
unsigned int i=0; i<
R::kSize; ++i) fRep.Array()[i] = 0;
78template <
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)
92template <
class T,
unsigned int D1,
unsigned int D2,
class R>
98template <
class T,
unsigned int D1,
unsigned int D2,
class R>
105template <
class T,
unsigned int D1,
unsigned int D2,
class R>
106template <
class A,
class R2>
115template <
class T,
unsigned int D1,
unsigned int D2,
class R>
116template <
class InputIterator>
119 for(
unsigned int i=0; i<
R::kSize; ++i) fRep.Array()[i] = 0;
123template <
class T,
unsigned int D1,
unsigned int D2,
class R>
124template <
class InputIterator>
128 for(
unsigned int i=0; i<
R::kSize; ++i) fRep.Array()[i] = 0;
137template <
class T,
unsigned int D1,
unsigned int D2,
class R>
143template <
class T,
unsigned int D1,
unsigned int D2,
class R>
153template <
class T,
unsigned int D1,
unsigned int D2,
class R>
160template <
class T,
unsigned int D1,
unsigned int D2,
class R>
161template <
class A,
class R2>
162SMatrix<T,D1,D2,R>&
SMatrix<T,D1,D2,R>::operator=(
const Expr<A,T,D1,D2,R2>& rhs) {
170template <
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)
190template <
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;
199template <
class T,
unsigned int D1,
unsigned int D2,
class R>
209template <
class T,
unsigned int D1,
unsigned int D2,
class R>
210template <
class A,
class R2>
211SMatrix<T,D1,D2,R>&
SMatrix<T,D1,D2,R>::operator+=(
const Expr<A,T,D1,D2,R2>& rhs) {
221template <
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;
230template <
class T,
unsigned int D1,
unsigned int D2,
class R>
240template <
class T,
unsigned int D1,
unsigned int D2,
class R>
241template <
class A,
class R2>
242SMatrix<T,D1,D2,R>&
SMatrix<T,D1,D2,R>::operator-=(
const Expr<A,T,D1,D2,R2>& rhs) {
251template <
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;
260template <
class T,
unsigned int D1,
unsigned int D2,
class R>
268template <
class T,
unsigned int D1,
unsigned int D2,
class R>
269template <
class A,
class R2>
270SMatrix<T,D1,D2,R>&
SMatrix<T,D1,D2,R>::operator*=(
const Expr<A,T,D1,D2,R2>& rhs) {
280template <
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;
292template <
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);
301template <
class T,
unsigned int D1,
unsigned int D2,
class R>
304 return fRep == rhs.
fRep;
307template <
class T,
unsigned int D1,
unsigned int D2,
class R>
308template <
class A,
class R2>
311 for(
unsigned int i=0; i<D1*D2; ++i) {
312 rc = rc && (fRep[i] == rhs.
apply(i));
320template <
class T,
unsigned int D1,
unsigned int D2,
class R>
325template <
class T,
unsigned int D1,
unsigned int D2,
class R>
330template <
class T,
unsigned int D1,
unsigned int D2,
class R>
331template <
class A,
class R2>
340template <
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);
349template <
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]);
359template <
class T,
unsigned int D1,
unsigned int D2,
class R>
360template <
class A,
class R2>
363 for(
unsigned int i=0; i<D1*D2; ++i) {
364 rc = rc && (fRep[i] > rhs.
apply(i));
372template <
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);
381template <
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]);
391template <
class T,
unsigned int D1,
unsigned int D2,
class R>
392template <
class A,
class R2>
395 for(
unsigned int i=0; i<D1*D2; ++i) {
396 rc = rc && (fRep[i] < rhs.
apply(i));
405template <
class T,
unsigned int D1,
unsigned int D2,
class R>
412template <
class T,
unsigned int D1,
unsigned int D2,
class R>
422template <
class T,
unsigned int D1,
unsigned int D2,
class R>
429template <
class T,
unsigned int D1,
unsigned int D2,
class R>
439template <
class T,
unsigned int D1,
unsigned int D2,
class R>
445template <
class T,
unsigned int D1,
unsigned int D2,
class R>
459template <
class T,
unsigned int D1,
unsigned int D2,
class R>
466template <
class T,
unsigned int D1,
unsigned int D2,
class R>
476template <
class T,
unsigned int D1,
unsigned int D2,
class R>
477template <
unsigned int D>
484 for(
unsigned int i=row*D2+col, j=0; j<D; ++i, ++j) {
485 fRep[i] = rhs.
apply(j);
493template <
class T,
unsigned int D1,
unsigned int D2,
class R>
494template <
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);
510template <
class T,
unsigned int D1,
unsigned int D2,
class R>
511template <
unsigned int D>
518 for(
unsigned int i=row*D2+col, j=0; j<D; i+=D2, ++j) {
519 fRep[i] = rhs.
apply(j);
527template <
class T,
unsigned int D1,
unsigned int D2,
class R>
528template <
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);
544template <
class T,
unsigned int D1,
unsigned int D2,
class R>
545template <
unsigned int D3,
unsigned int D4,
class R2>
546SMatrix<T,D1,D2,R>&
SMatrix<T,D1,D2,R>::Place_at(
const SMatrix<T,D3,D4,R2>& rhs,
556template <
class T,
unsigned int D1,
unsigned int D2,
class R>
557template <
class A,
unsigned int D3,
unsigned int D4,
class R2>
558SMatrix<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);
568template <
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];
583template <
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];
596template <
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);
620template <
class T,
unsigned int D1,
unsigned int D2,
class R>
623template <
class T,
unsigned int D1,
unsigned int D2,
class R>
626template <
class T,
unsigned int D1,
unsigned int D2,
class R>
632template <
class T,
unsigned int D1,
unsigned int D2,
class R>
637template <
class T,
unsigned int D1,
unsigned int D2,
class R>
646template <
class T,
unsigned int D1,
unsigned int D2,
class R>
653template <
class T,
unsigned int D1,
unsigned int D2,
class R>
663template <
class T,
unsigned int D1,
unsigned int D2,
class R>
668template <
class T,
unsigned int D1,
unsigned int D2,
class R>
673template <
class T,
unsigned int D1,
unsigned int D2,
class R>
678template <
class T,
unsigned int D1,
unsigned int D2,
class R>
684template <
class T,
unsigned int D1,
unsigned int D2,
class R>
685template <
class InputIterator>
691template <
class T,
unsigned int D1,
unsigned int D2,
class R>
692template <
class InputIterator>
704template <
class T,
unsigned int D1,
unsigned int D2,
class R>
705template <
class SubVector>
708 const unsigned int offset = therow*D2 + col0;
715 tmp[i] = fRep[offset+i];
720template <
class T,
unsigned int D1,
unsigned int D2,
class R>
721template <
class SubVector>
724 const unsigned int offset = thecol + row0*D1;
731 tmp[i] = fRep[offset+i*D1];
737template <
class T,
unsigned int D1,
unsigned int D2,
class R>
738template <
class SubMatrix>
743 (tmp,*
this,row0,col0);
748template <
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];
762template <
class T,
unsigned int D1,
unsigned int D2,
class R>
763template <
class Vector>
768 ( ( D2 < D1 ) &&
Vector::kSize == D2 ), SVector_size_NOT_correct );
772 fRep[ i*D2 + i] =
v[i];
777template <
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] ;
789template <
class T,
unsigned int D1,
unsigned int D2,
class R>
790#ifndef UNSUPPORTED_TEMPLATE_EXPRESSION
793template <
class SubVector>
799#ifndef UNSUPPORTED_TEMPLATE_EXPRESSION
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];
818template <
class T,
unsigned int D1,
unsigned int D2,
class R>
819#ifndef UNSUPPORTED_TEMPLATE_EXPRESSION
822template <
class SubVector>
829#ifndef UNSUPPORTED_TEMPLATE_EXPRESSION
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];
850template <
class T,
unsigned int D1,
unsigned int D2,
class R>
851#ifndef UNSUPPORTED_TEMPLATE_EXPRESSION
854template <
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];
888template <
class T,
unsigned int D1,
unsigned int D2,
class R>
890 return p == fRep.Array();
#define STATIC_CHECK(expr, msg)
Bool_t operator==(const TDatime &d1, const TDatime &d2)
Binding & operator=(OUT(*fun)(void))
static bool Dinv(MatrixRep &)
static bool Dfact(MatRepStd< T, n, idim > &rhs, T &det)
T apply(unsigned int i) const
static bool Dinv(MatrixRep &rhs)
static bool Dinv(MatrixRep &rhs)
matrix inversion for a generic square matrix using LU factorization (code originally from CERNLIB and...
SMatrix: a generic fixed size D1 x D2 Matrix class.
SVector< T, D1 > Col(unsigned int thecol) const
return a full Matrix column as a vector (copy the content in a new vector)
SMatrix()
Default constructor:
SMatrix< T, D1, D2, R > & operator-=(const T &rhs)
subtraction with a scalar
T apply(unsigned int i) const
access the parse tree with the index starting from zero and following the C convention for the order ...
bool Det2(T &det) const
determinant of square Matrix via Dfact.
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...
iterator end()
STL iterator interface.
const T & At(unsigned int i, unsigned int j) const
read only access to matrix element, with indices starting from 0.
bool Det(T &det)
determinant of square Matrix via Dfact.
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.
bool operator>(const T &rhs) const
element wise comparison
std::ostream & Print(std::ostream &os) const
Print: used by operator<<()
SMatrix< T, D1, D2, R > & operator=(const M &rhs)
Assign from another compatible matrix.
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
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,...
SMatrix< T, D1, D2, R > & operator*=(const T &rhs)
multiplication with a scalar
bool operator<(const T &rhs) const
element wise comparison
iterator begin()
STL iterator interface.
void SetElements(InputIterator begin, InputIterator end, bool triang=false, bool lower=true)
Set matrix elements with STL iterator interface.
R fRep
Matrix Storage Object containing matrix data.
SMatrix< T, D1, D2, R > InverseFast(int &ifail) const
Invert a square Matrix and returns a new matrix.
bool operator==(const T &rhs) const
element wise comparison
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
SVector< T, D1 > Diagonal() const
return diagonal elements of a matrix as a Vector.
SMatrix< T, D1, D2, R > InverseChol(int &ifail) const
Invert of a symmetric positive defined Matrix using Choleski decomposition.
void SetDiagonal(const Vector &v)
Set the diagonal elements from a Vector Require that vector implements kSize since a check (staticall...
bool operator!=(const T &rhs) const
element wise comparison
SMatrix< T, D1, D2, R > & operator+=(const T &rhs)
addition with a scalar
bool InvertChol()
Invertion of a symmetric positive defined Matrix using Choleski decomposition.
bool Invert()
Invert a square Matrix ( this method changes the current matrix).
bool IsInUse(const T *p) const
Function to check if a matrix is sharing same memory location of the passed pointer This function is ...
SMatrix< T, D1, D2, R > & operator/=(const T &rhs)
division with a scalar
bool InvertFast()
Fast Invertion of a square Matrix ( this method changes the current matrix).
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...
T Trace() const
return the trace of a matrix Sum of the diagonal elements
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,...
const T & operator()(unsigned int i, unsigned int j) const
read only access to matrix element, with indices starting from 0
SVector< T, D2 > Row(unsigned int therow) const
return a full Matrix row as a vector (copy the content in a new vector)
const T * Array() const
return read-only pointer to internal array
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
SVector: a generic fixed size Vector class.
T apply(unsigned int i) const
access the parse tree. Index starts from zero
Expression wrapper class for Vector objects.
T apply(unsigned int i) const
Namespace for new Math classes and functions.
Namespace for new ROOT classes and functions.
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 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, D1, D2, R2 > &rhs)
static void Evaluate(SMatrix< T, D1, D2, R1 > &lhs, const Expr< A, T, D3, D4, R2 > &rhs, unsigned int row, unsigned int col)
static void Evaluate(SMatrix< T, D1, D2, R1 > &lhs, const SMatrix< T, D3, D4, R2 > &rhs, unsigned int row, unsigned int col)
static void Evaluate(SMatrix< T, D1, D2, R1 > &lhs, const Expr< A, T, D1, D2, R2 > &rhs)
static void Evaluate(SMatrix< T, D1, D2, R1 > &lhs, const SMatrix< T, D3, D4, R2 > &rhs, unsigned int row, unsigned int col)