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>
127 assert(
size <= R::kSize);
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>
166template <
class T,
unsigned int D1,
unsigned int D2,
class R>
167template <
class A,
class R2>
168SMatrix<T,D1,D2,R>&
SMatrix<T,D1,D2,R>::operator=(
const Expr<A,T,D1,D2,R2>& rhs) {
176template <
class T,
unsigned int D1,
unsigned int D2,
class R>
178 for(
unsigned int i=0; i<R::kSize; ++i)
181 for(
unsigned int i=0; i<D1; ++i)
185 for(
unsigned int i=0; i<D2; ++i)
196template <
class T,
unsigned int D1,
unsigned int D2,
class R>
199 for(
unsigned int i=0; i<R::kSize; ++i) {
200 fRep.
Array()[i] += rhs;
205template <
class T,
unsigned int D1,
unsigned int D2,
class R>
215template <
class T,
unsigned int D1,
unsigned int D2,
class R>
216template <
class A,
class R2>
217SMatrix<T,D1,D2,R>&
SMatrix<T,D1,D2,R>::operator+=(
const Expr<A,T,D1,D2,R2>& rhs) {
227template <
class T,
unsigned int D1,
unsigned int D2,
class R>
230 for(
unsigned int i=0; i<R::kSize; ++i) {
231 fRep.
Array()[i] -= rhs;
236template <
class T,
unsigned int D1,
unsigned int D2,
class R>
246template <
class T,
unsigned int D1,
unsigned int D2,
class R>
247template <
class A,
class R2>
248SMatrix<T,D1,D2,R>&
SMatrix<T,D1,D2,R>::operator-=(
const Expr<A,T,D1,D2,R2>& rhs) {
257template <
class T,
unsigned int D1,
unsigned int D2,
class R>
260 for(
unsigned int i=0; i<R::kSize; ++i) {
261 fRep.
Array()[i] *= rhs;
266template <
class T,
unsigned int D1,
unsigned int D2,
class R>
274template <
class T,
unsigned int D1,
unsigned int D2,
class R>
275template <
class A,
class R2>
276SMatrix<T,D1,D2,R>&
SMatrix<T,D1,D2,R>::operator*=(
const Expr<A,T,D1,D2,R2>& rhs) {
286template <
class T,
unsigned int D1,
unsigned int D2,
class R>
289 for(
unsigned int i=0; i<R::kSize; ++i) {
290 fRep.
Array()[i] /= rhs;
298template <
class T,
unsigned int D1,
unsigned int D2,
class R>
301 for(
unsigned int i=0; i<R::kSize; ++i) {
302 rc = rc && (fRep.Array()[i] == rhs);
307template <
class T,
unsigned int D1,
unsigned int D2,
class R>
310 return fRep == rhs.
fRep;
313template <
class T,
unsigned int D1,
unsigned int D2,
class R>
314template <
class A,
class R2>
317 for(
unsigned int i=0; i<D1*D2; ++i) {
318 rc = rc && (fRep[i] == rhs.
apply(i));
326template <
class T,
unsigned int D1,
unsigned int D2,
class R>
331template <
class T,
unsigned int D1,
unsigned int D2,
class R>
336template <
class T,
unsigned int D1,
unsigned int D2,
class R>
337template <
class A,
class R2>
346template <
class T,
unsigned int D1,
unsigned int D2,
class R>
349 for(
unsigned int i=0; i<D1*D2; ++i) {
350 rc = rc && (fRep[i] > rhs);
355template <
class T,
unsigned int D1,
unsigned int D2,
class R>
359 for(
unsigned int i=0; i<D1*D2; ++i) {
360 rc = rc && (fRep[i] > rhs.
fRep[i]);
365template <
class T,
unsigned int D1,
unsigned int D2,
class R>
366template <
class A,
class R2>
369 for(
unsigned int i=0; i<D1*D2; ++i) {
370 rc = rc && (fRep[i] > rhs.
apply(i));
378template <
class T,
unsigned int D1,
unsigned int D2,
class R>
381 for(
unsigned int i=0; i<D1*D2; ++i) {
382 rc = rc && (fRep[i] < rhs);
387template <
class T,
unsigned int D1,
unsigned int D2,
class R>
391 for(
unsigned int i=0; i<D1*D2; ++i) {
392 rc = rc && (fRep[i] < rhs.
fRep[i]);
397template <
class T,
unsigned int D1,
unsigned int D2,
class R>
398template <
class A,
class R2>
401 for(
unsigned int i=0; i<D1*D2; ++i) {
402 rc = rc && (fRep[i] < rhs.
apply(i));
411template <
class T,
unsigned int D1,
unsigned int D2,
class R>
418template <
class T,
unsigned int D1,
unsigned int D2,
class R>
421 bool ok = tmp.Invert();
428template <
class T,
unsigned int D1,
unsigned int D2,
class R>
435template <
class T,
unsigned int D1,
unsigned int D2,
class R>
438 bool ok = tmp.InvertFast();
445template <
class T,
unsigned int D1,
unsigned int D2,
class R>
451template <
class T,
unsigned int D1,
unsigned int D2,
class R>
465template <
class T,
unsigned int D1,
unsigned int D2,
class R>
472template <
class T,
unsigned int D1,
unsigned int D2,
class R>
482template <
class T,
unsigned int D1,
unsigned int D2,
class R>
483template <
unsigned int D>
490 for(
unsigned int i=row*D2+col, j=0; j<D; ++i, ++j) {
491 fRep[i] = rhs.
apply(j);
499template <
class T,
unsigned int D1,
unsigned int D2,
class R>
500template <
class A,
unsigned int D>
507 for(
unsigned int i=row*D2+col, j=0; j<D; ++i, ++j) {
508 fRep[i] = rhs.
apply(j);
516template <
class T,
unsigned int D1,
unsigned int D2,
class R>
517template <
unsigned int D>
524 for(
unsigned int i=row*D2+col, j=0; j<D; i+=D2, ++j) {
525 fRep[i] = rhs.
apply(j);
533template <
class T,
unsigned int D1,
unsigned int D2,
class R>
534template <
class A,
unsigned int D>
541 for(
unsigned int i=row*D2+col, j=0; j<D; i+=D2, ++j) {
542 fRep[i] = rhs.
apply(j);
550template <
class T,
unsigned int D1,
unsigned int D2,
class R>
551template <
unsigned int D3,
unsigned int D4,
class R2>
552SMatrix<T,D1,D2,R>&
SMatrix<T,D1,D2,R>::Place_at(
const SMatrix<T,D3,D4,R2>& rhs,
562template <
class T,
unsigned int D1,
unsigned int D2,
class R>
563template <
class A,
unsigned int D3,
unsigned int D4,
class R2>
564SMatrix<T,D1,D2,R>&
SMatrix<T,D1,D2,R>::Place_at(
const Expr<A,T,D3,D4,R2>& rhs,
567 PlaceExpr<T,D1,D2,D3,D4,A,R,R2>::Evaluate(*
this,rhs,row,col);
574template <
class T,
unsigned int D1,
unsigned int D2,
class R>
577 const unsigned int offset = therow*D2;
580 for(
unsigned int i=0; i<D2; ++i) {
589template <
class T,
unsigned int D1,
unsigned int D2,
class R>
593 for(
unsigned int i=0; i<D1; ++i) {
594 tmp[i] = fRep[thecol+i*D2];
602template <
class T,
unsigned int D1,
unsigned int D2,
class R>
604 const std::ios_base::fmtflags prevFmt = os.setf(std::ios::right,std::ios::adjustfield);
608 for (
unsigned int i=0; i < D1; ++i) {
609 for (
unsigned int j=0; j < D2; ++j) {
610 os << std::setw(12) << fRep[i*D2+j];
611 if ((!((j+1)%12)) && (j < D2-1))
612 os << std::endl <<
" ...";
615 os << std::endl <<
" ";
619 if (prevFmt != os.flags() ) os.setf(prevFmt, std::ios::adjustfield);
626template <
class T,
unsigned int D1,
unsigned int D2,
class R>
629template <
class T,
unsigned int D1,
unsigned int D2,
class R>
632template <
class T,
unsigned int D1,
unsigned int D2,
class R>
638template <
class T,
unsigned int D1,
unsigned int D2,
class R>
643template <
class T,
unsigned int D1,
unsigned int D2,
class R>
652template <
class T,
unsigned int D1,
unsigned int D2,
class R>
659template <
class T,
unsigned int D1,
unsigned int D2,
class R>
669template <
class T,
unsigned int D1,
unsigned int D2,
class R>
674template <
class T,
unsigned int D1,
unsigned int D2,
class R>
676 return fRep.Array() + R::kSize;
679template <
class T,
unsigned int D1,
unsigned int D2,
class R>
684template <
class T,
unsigned int D1,
unsigned int D2,
class R>
686 return fRep.Array() + R::kSize;
690template <
class T,
unsigned int D1,
unsigned int D2,
class R>
691template <
class InputIterator>
697template <
class T,
unsigned int D1,
unsigned int D2,
class R>
698template <
class InputIterator>
701 assert(
size <= R::kSize);
710template <
class T,
unsigned int D1,
unsigned int D2,
class R>
711template <
class SubVector>
714 const unsigned int offset = therow*D2 + col0;
716 STATIC_CHECK( SubVector::kSize <= D2,SVector_dimension_too_small);
717 assert(col0 + SubVector::kSize <= D2);
720 for(
unsigned int i=0; i<SubVector::kSize; ++i) {
726template <
class T,
unsigned int D1,
unsigned int D2,
class R>
727template <
class SubVector>
730 const unsigned int offset = thecol + row0*D1;
732 STATIC_CHECK( SubVector::kSize <= D1,SVector_dimension_too_small);
733 assert(row0 + SubVector::kSize <= D1);
736 for(
unsigned int i=0; i<SubVector::kSize; ++i) {
737 tmp[i] = fRep[
offset+i*D1];
743template <
class T,
unsigned int D1,
unsigned int D2,
class R>
744template <
class SubMatrix>
749 (tmp,*
this,row0,col0);
754template <
class T,
unsigned int D1,
unsigned int D2,
class R>
761 for(
unsigned int i=0; i<D1; ++i) {
762 tmp[i] = fRep[ i*D2 + i];
768template <
class T,
unsigned int D1,
unsigned int D2,
class R>
769template <
class Vector>
774 ( ( D2 < D1 ) && Vector::kSize == D2 ), SVector_size_NOT_correct );
777 for(
unsigned int i=0; i<Vector::kSize; ++i) {
778 fRep[ i*D2 + i] =
v[i];
783template <
class T,
unsigned int D1,
unsigned int D2,
class R>
785 unsigned int diagSize = D1;
786 if (D2 < D1) diagSize = D2;
788 for(
unsigned int i=0; i< diagSize; ++i) {
789 trace += fRep[ i*D2 + i] ;
795template <
class T,
unsigned int D1,
unsigned int D2,
class R>
796#ifndef UNSUPPORTED_TEMPLATE_EXPRESSION
799template <
class SubVector>
805#ifndef UNSUPPORTED_TEMPLATE_EXPRESSION
806 SVector<T, D1 * (D2 +1)/2 > tmp;
809 STATIC_CHECK( SubVector::kSize == D1*(D1+1)/2,SVector_Wrong_Size );
814 for(
unsigned int i=0; i<D1; ++i) {
815 for(
unsigned int j=i; j<D2; ++j) {
816 tmp[k] = fRep[ i*D2 + j];
824template <
class T,
unsigned int D1,
unsigned int D2,
class R>
825#ifndef UNSUPPORTED_TEMPLATE_EXPRESSION
828template <
class SubVector>
835#ifndef UNSUPPORTED_TEMPLATE_EXPRESSION
836 SVector<T, D1 * (D2 +1)/2 > tmp;
839 STATIC_CHECK( SubVector::kSize == D1*(D1+1)/2,SVector_Wrong_Size );
844 for(
unsigned int i=0; i<D1; ++i) {
845 for(
unsigned int j=0; j<=i; ++j) {
846 tmp[k] = fRep[ i*D2 + j];
856template <
class T,
unsigned int D1,
unsigned int D2,
class R>
857#ifndef UNSUPPORTED_TEMPLATE_EXPRESSION
860template <
unsigned int N>
867#ifdef UNSUPPORTED_TEMPLATE_EXPRESSION
874 for(
unsigned int i=0; i<D1; ++i) {
875 for(
unsigned int j=0; j<=i; ++j) {
876 fRep[ i*D2 + j] =
v[k];
877 if ( i != j) fRep[ j*D2 + i] =
v[k];
883 for(
unsigned int i=0; i<D1; ++i) {
884 for(
unsigned int j=i; j<D2; ++j) {
885 fRep[ i*D2 + j] =
v[k];
886 if ( i != j) fRep[ j*D2 + i] =
v[k];
894template <
class T,
unsigned int D1,
unsigned int D2,
class R>
896 return p == fRep.Array();
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
#define STATIC_CHECK(expr, msg)
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h offset
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 SVector::kSize since a check (...
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.
bool operator==(const RConcurrentHashColl::HashValue &lhs, const RConcurrentHashColl::HashValue &rhs)
This file contains a specialised ROOT message handler to test for diagnostic in unit tests.
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)