39template<
class Element>
47template<
class Element>
50 const Int_t no_rows = row_upb-row_lwb+1;
51 Allocate(no_rows,no_rows,row_lwb,row_lwb,1);
63template<
class Element>
67 SetMatrixArray(elements,option);
68 if (!this->IsSymmetric()) {
69 Error(
"TMatrixTSym(Int_t,Element*,Option_t*)",
"matrix not symmetric");
76template<
class Element>
79 const Int_t no_rows = row_upb-row_lwb+1;
81 SetMatrixArray(elements,option);
82 if (!this->IsSymmetric()) {
83 Error(
"TMatrixTSym(Int_t,Int_t,Element*,Option_t*)",
"matrix not symmetric");
89template<
class Element>
102template<
class Element>
132 const Element oldTol = this->SetTol(std::numeric_limits<Element>::min());
134 this->SetTol(oldTol);
144 Error(
"TMatrixTSym(EMatrixCreatorOp1,const TMatrixTSym)",
145 "operation %d not yet implemented", op);
151template<
class Element>
163 Error(
"TMatrixTSym(EMatrixCreatorOp1,const TMatrixT)",
164 "operation %d not yet implemented", op);
170template<
class Element>
179 Allocate(
a.GetNcols(),
a.GetNcols(),
a.GetColLwb(),
a.GetColLwb(),1);
186 Allocate(
a.GetNcols(),
a.GetNcols(),
a.GetColLwb(),
a.GetColLwb(),1);
192 Error(
"TMatrixTSym(EMatrixCreatorOp2)",
"operation %d not yet implemented", op);
198template<
class Element>
204 lazy_constructor.
FillIn(*
this);
205 if (!this->IsSymmetric()) {
206 Error(
"TMatrixTSym(TMatrixTSymLazy)",
"matrix not symmetric");
213template<
class Element>
217 if (size > this->kSizeMax)
227template<
class Element>
230 if (size == 0)
return 0;
232 if ( size <= this->kSizeMax )
235 Element *heap =
new Element[size];
245template<
class Element>
249 if (copySize == 0 || oldp == newp)
252 if ( newSize <= this->kSizeMax && oldSize <= this->kSizeMax ) {
255 for (
Int_t i = copySize-1; i >= 0; i--)
258 for (
Int_t i = 0; i < copySize; i++)
263 memcpy(newp,oldp,copySize*
sizeof(Element));
272template<
class Element>
276 this->fIsOwner =
kTRUE;
285 if (no_rows < 0 || no_cols < 0)
287 Error(
"Allocate",
"no_rows=%d no_cols=%d",no_rows,no_cols);
293 this->fNrows = no_rows;
294 this->fNcols = no_cols;
295 this->fRowLwb = row_lwb;
296 this->fColLwb = col_lwb;
297 this->fNelems = this->fNrows*this->fNcols;
299 if (this->fNelems > 0) {
300 fElements = New_m(this->fNelems);
302 memset(fElements,0,this->fNelems*
sizeof(Element));
310template<
class Element>
315 Error(
"Plus",
"matrices not compatible");
319 if (this->GetMatrixArray() ==
a.GetMatrixArray()) {
320 Error(
"Plus",
"this->GetMatrixArray() == a.GetMatrixArray()");
324 if (this->GetMatrixArray() ==
b.GetMatrixArray()) {
325 Error(
"Plus",
"this->GetMatrixArray() == b.GetMatrixArray()");
330 const Element * ap =
a.GetMatrixArray();
331 const Element * bp =
b.GetMatrixArray();
332 Element * cp = this->GetMatrixArray();
333 const Element *
const cp_last = cp+this->fNelems;
335 while (cp < cp_last) {
344template<
class Element>
349 Error(
"Minus",
"matrices not compatible");
353 if (this->GetMatrixArray() ==
a.GetMatrixArray()) {
354 Error(
"Minus",
"this->GetMatrixArray() == a.GetMatrixArray()");
358 if (this->GetMatrixArray() ==
b.GetMatrixArray()) {
359 Error(
"Minus",
"this->GetMatrixArray() == b.GetMatrixArray()");
364 const Element * ap =
a.GetMatrixArray();
365 const Element * bp =
b.GetMatrixArray();
366 Element * cp = this->GetMatrixArray();
367 const Element *
const cp_last = cp+this->fNelems;
369 while (cp < cp_last) {
379template<
class Element>
385 const Element *ap =
a.GetMatrixArray();
386 Element *cp = this->GetMatrixArray();
387 if (
typeid(Element) ==
typeid(
Double_t))
388 cblas_dgemm (CblasRowMajor,CblasTrans,CblasNoTrans,this->fNrows,this->fNcols,
a.GetNrows(),
389 1.0,ap,
a.GetNcols(),ap,
a.GetNcols(),1.0,cp,this->fNcols);
390 else if (
typeid(Element) !=
typeid(
Float_t))
391 cblas_sgemm (CblasRowMajor,CblasTrans,CblasNoTrans,fNrows,fNcols,
a.GetNrows(),
392 1.0,ap,
a.GetNcols(),ap,
a.GetNcols(),1.0,cp,fNcols);
394 Error(
"TMult",
"type %s not implemented in BLAS library",
typeid(Element));
396 const Int_t nb =
a.GetNoElements();
397 const Int_t ncolsa =
a.GetNcols();
398 const Int_t ncolsb = ncolsa;
399 const Element *
const ap =
a.GetMatrixArray();
400 const Element *
const bp = ap;
401 Element * cp = this->GetMatrixArray();
403 const Element *acp0 = ap;
404 while (acp0 < ap+
a.GetNcols()) {
405 for (
const Element *bcp = bp; bcp < bp+ncolsb; ) {
406 const Element *acp = acp0;
408 while (bcp < bp+nb) {
419 R__ASSERT(cp == this->GetMatrixArray()+this->fNelems && acp0 == ap+ncolsa);
427template<
class Element>
433 const Element *ap =
a.GetMatrixArray();
434 Element *cp = this->GetMatrixArray();
435 if (
typeid(Element) ==
typeid(
Double_t))
436 cblas_dsymm (CblasRowMajor,CblasLeft,CblasUpper,this->fNrows,this->fNcols,1.0,
437 ap,
a.GetNcols(),ap,
a.GetNcols(),0.0,cp,this->fNcols);
438 else if (
typeid(Element) !=
typeid(
Float_t))
439 cblas_ssymm (CblasRowMajor,CblasLeft,CblasUpper,fNrows,fNcols,1.0,
440 ap1,
a.GetNcols(),ap,
a.GetNcols(),0.0,cp,fNcols);
442 Error(
"TMult",
"type %s not implemented in BLAS library",
typeid(Element));
444 const Int_t nb =
a.GetNoElements();
445 const Int_t ncolsa =
a.GetNcols();
446 const Int_t ncolsb = ncolsa;
447 const Element *
const ap =
a.GetMatrixArray();
448 const Element *
const bp = ap;
449 Element * cp = this->GetMatrixArray();
451 const Element *acp0 = ap;
452 while (acp0 < ap+
a.GetNcols()) {
453 for (
const Element *bcp = bp; bcp < bp+ncolsb; ) {
454 const Element *acp = acp0;
456 while (bcp < bp+nb) {
467 R__ASSERT(cp == this->GetMatrixArray()+this->fNelems && acp0 == ap+ncolsa);
473template<
class Element>
478 Error(
"Use",
"row_upb=%d < row_lwb=%d",row_upb,row_lwb);
483 this->fNrows = row_upb-row_lwb+1;
484 this->fNcols = this->fNrows;
485 this->fRowLwb = row_lwb;
486 this->fColLwb = row_lwb;
487 this->fNelems = this->fNrows*this->fNcols;
501template<
class Element>
507 if (row_lwb < this->fRowLwb || row_lwb > this->fRowLwb+this->fNrows-1) {
508 Error(
"GetSub",
"row_lwb out of bounds");
511 if (row_upb < this->fRowLwb || row_upb > this->fRowLwb+this->fNrows-1) {
512 Error(
"GetSub",
"row_upb out of bounds");
515 if (row_upb < row_lwb) {
516 Error(
"GetSub",
"row_upb < row_lwb");
529 row_upb_sub = row_upb-row_lwb;
531 row_lwb_sub = row_lwb;
532 row_upb_sub = row_upb;
535 target.
ResizeTo(row_lwb_sub,row_upb_sub,row_lwb_sub,row_upb_sub);
536 const Int_t nrows_sub = row_upb_sub-row_lwb_sub+1;
539 for (
Int_t irow = 0; irow < nrows_sub; irow++) {
540 for (
Int_t icol = 0; icol < nrows_sub; icol++) {
541 target(irow+row_lwb_sub,icol+row_lwb_sub) = (*this)(row_lwb+irow,row_lwb+icol);
545 const Element *ap = this->GetMatrixArray()+(row_lwb-this->fRowLwb)*this->fNrows+(row_lwb-this->fRowLwb);
548 for (
Int_t irow = 0; irow < nrows_sub; irow++) {
549 const Element *ap_sub = ap;
550 for (
Int_t icol = 0; icol < nrows_sub; icol++) {
567template<
class Element>
573 if (row_lwb < this->fRowLwb || row_lwb > this->fRowLwb+this->fNrows-1) {
574 Error(
"GetSub",
"row_lwb out of bounds");
577 if (col_lwb < this->fColLwb || col_lwb > this->fColLwb+this->fNcols-1) {
578 Error(
"GetSub",
"col_lwb out of bounds");
581 if (row_upb < this->fRowLwb || row_upb > this->fRowLwb+this->fNrows-1) {
582 Error(
"GetSub",
"row_upb out of bounds");
585 if (col_upb < this->fColLwb || col_upb > this->fColLwb+this->fNcols-1) {
586 Error(
"GetSub",
"col_upb out of bounds");
589 if (row_upb < row_lwb || col_upb < col_lwb) {
590 Error(
"GetSub",
"row_upb < row_lwb || col_upb < col_lwb");
599 const Int_t row_lwb_sub = (shift) ? 0 : row_lwb;
600 const Int_t row_upb_sub = (shift) ? row_upb-row_lwb : row_upb;
601 const Int_t col_lwb_sub = (shift) ? 0 : col_lwb;
602 const Int_t col_upb_sub = (shift) ? col_upb-col_lwb : col_upb;
604 target.
ResizeTo(row_lwb_sub,row_upb_sub,col_lwb_sub,col_upb_sub);
605 const Int_t nrows_sub = row_upb_sub-row_lwb_sub+1;
606 const Int_t ncols_sub = col_upb_sub-col_lwb_sub+1;
609 for (
Int_t irow = 0; irow < nrows_sub; irow++) {
610 for (
Int_t icol = 0; icol < ncols_sub; icol++) {
611 target(irow+row_lwb_sub,icol+col_lwb_sub) = (*this)(row_lwb+irow,col_lwb+icol);
615 const Element *ap = this->GetMatrixArray()+(row_lwb-this->fRowLwb)*this->fNcols+(col_lwb-this->fColLwb);
618 for (
Int_t irow = 0; irow < nrows_sub; irow++) {
619 const Element *ap_sub = ap;
620 for (
Int_t icol = 0; icol < ncols_sub; icol++) {
634template<
class Element>
642 Error(
"SetSub",
"source matrix is not symmetric");
645 if (row_lwb < this->fRowLwb || row_lwb > this->fRowLwb+this->fNrows-1) {
646 Error(
"SetSub",
"row_lwb outof bounds");
649 if (row_lwb+source.
GetNrows() > this->fRowLwb+this->fNrows) {
650 Error(
"SetSub",
"source matrix too large");
659 for (
Int_t irow = 0; irow < nRows_source; irow++) {
660 for (
Int_t icol = 0; icol < nRows_source; icol++) {
661 (*this)(row_lwb+irow,row_lwb+icol) = source(rowlwb_s+irow,rowlwb_s+icol);
666 Element *ap = this->GetMatrixArray()+(row_lwb-this->fRowLwb)*this->fNrows+(row_lwb-this->fRowLwb);
668 for (
Int_t irow = 0; irow < nRows_source; irow++) {
669 Element *ap_sub = ap;
670 for (
Int_t icol = 0; icol < nRows_source; icol++) {
684template<
class Element>
691 if (row_lwb < this->fRowLwb || row_lwb > this->fRowLwb+this->fNrows-1) {
692 Error(
"SetSub",
"row_lwb out of bounds");
695 if (col_lwb < this->fColLwb || col_lwb > this->fColLwb+this->fNcols-1) {
696 Error(
"SetSub",
"col_lwb out of bounds");
700 if (row_lwb+source.
GetNrows() > this->fRowLwb+this->fNrows || col_lwb+source.
GetNcols() > this->fRowLwb+this->fNrows) {
701 Error(
"SetSub",
"source matrix too large");
704 if (col_lwb+source.
GetNcols() > this->fRowLwb+this->fNrows || row_lwb+source.
GetNrows() > this->fRowLwb+this->fNrows) {
705 Error(
"SetSub",
"source matrix too large");
715 if (row_lwb >= col_lwb) {
718 for (irow = 0; irow < nRows_source; irow++) {
719 for (
Int_t icol = 0; col_lwb+icol <= row_lwb+irow &&
720 icol < nCols_source; icol++) {
721 (*this)(row_lwb+irow,col_lwb+icol) = source(irow+rowlwb_s,icol+collwb_s);
726 for (irow = 0; irow < nCols_source; irow++) {
727 for (
Int_t icol = nRows_source-1; row_lwb+icol > irow+col_lwb &&
729 (*this)(col_lwb+irow,row_lwb+icol) = source(icol+rowlwb_s,irow+collwb_s);
741template<
class Element>
745 if (!this->IsSymmetric()) {
746 Error(
"SetMatrixArray",
"Matrix is not symmetric after Set");
754template<
class Element>
757 if (row_shift != col_shift) {
758 Error(
"Shift",
"row_shift != col_shift");
769template<
class Element>
773 if (!this->fIsOwner) {
774 Error(
"ResizeTo(Int_t,Int_t)",
"Not owner of data array,cannot resize");
778 if (nrows != ncols) {
779 Error(
"ResizeTo(Int_t,Int_t)",
"nrows != ncols");
783 if (this->fNelems > 0) {
784 if (this->fNrows == nrows && this->fNcols == ncols)
786 else if (nrows == 0 || ncols == 0) {
787 this->fNrows = nrows; this->fNcols = ncols;
792 Element *elements_old = GetMatrixArray();
793 const Int_t nelems_old = this->fNelems;
794 const Int_t nrows_old = this->fNrows;
795 const Int_t ncols_old = this->fNcols;
800 Element *elements_new = GetMatrixArray();
803 if (this->fNelems > this->kSizeMax || nelems_old > this->kSizeMax)
804 memset(elements_new,0,this->fNelems*
sizeof(Element));
805 else if (this->fNelems > nelems_old)
806 memset(elements_new+nelems_old,0,(this->fNelems-nelems_old)*
sizeof(Element));
812 const Int_t nelems_new = this->fNelems;
813 if (ncols_old < this->fNcols) {
814 for (
Int_t i = nrows_copy-1; i >= 0; i--) {
815 Memcpy_m(elements_new+i*this->fNcols,elements_old+i*ncols_old,ncols_copy,
816 nelems_new,nelems_old);
817 if (this->fNelems <= this->kSizeMax && nelems_old <= this->kSizeMax)
818 memset(elements_new+i*this->fNcols+ncols_copy,0,(this->fNcols-ncols_copy)*
sizeof(Element));
821 for (
Int_t i = 0; i < nrows_copy; i++)
822 Memcpy_m(elements_new+i*this->fNcols,elements_old+i*ncols_old,ncols_copy,
823 nelems_new,nelems_old);
826 Delete_m(nelems_old,elements_old);
839template<
class Element>
844 if (!this->fIsOwner) {
845 Error(
"ResizeTo(Int_t,Int_t,Int_t,Int_t)",
"Not owner of data array,cannot resize");
849 if (row_lwb != col_lwb) {
850 Error(
"ResizeTo(Int_t,Int_t,Int_t,Int_t)",
"row_lwb != col_lwb");
853 if (row_upb != col_upb) {
854 Error(
"ResizeTo(Int_t,Int_t,Int_t,Int_t)",
"row_upb != col_upb");
858 const Int_t new_nrows = row_upb-row_lwb+1;
859 const Int_t new_ncols = col_upb-col_lwb+1;
861 if (this->fNelems > 0) {
863 if (this->fNrows == new_nrows && this->fNcols == new_ncols &&
864 this->fRowLwb == row_lwb && this->fColLwb == col_lwb)
866 else if (new_nrows == 0 || new_ncols == 0) {
867 this->fNrows = new_nrows; this->fNcols = new_ncols;
868 this->fRowLwb = row_lwb; this->fColLwb = col_lwb;
873 Element *elements_old = GetMatrixArray();
874 const Int_t nelems_old = this->fNelems;
875 const Int_t nrows_old = this->fNrows;
876 const Int_t ncols_old = this->fNcols;
877 const Int_t rowLwb_old = this->fRowLwb;
878 const Int_t colLwb_old = this->fColLwb;
880 Allocate(new_nrows,new_ncols,row_lwb,col_lwb);
883 Element *elements_new = GetMatrixArray();
886 if (this->fNelems > this->kSizeMax || nelems_old > this->kSizeMax)
887 memset(elements_new,0,this->fNelems*
sizeof(Element));
888 else if (this->fNelems > nelems_old)
889 memset(elements_new+nelems_old,0,(this->fNelems-nelems_old)*
sizeof(Element));
894 const Int_t rowUpb_copy =
TMath::Min(this->fRowLwb+this->fNrows-1,rowLwb_old+nrows_old-1);
895 const Int_t colUpb_copy =
TMath::Min(this->fColLwb+this->fNcols-1,colLwb_old+ncols_old-1);
897 const Int_t nrows_copy = rowUpb_copy-rowLwb_copy+1;
898 const Int_t ncols_copy = colUpb_copy-colLwb_copy+1;
900 if (nrows_copy > 0 && ncols_copy > 0) {
901 const Int_t colOldOff = colLwb_copy-colLwb_old;
902 const Int_t colNewOff = colLwb_copy-this->fColLwb;
903 if (ncols_old < this->fNcols) {
904 for (
Int_t i = nrows_copy-1; i >= 0; i--) {
905 const Int_t iRowOld = rowLwb_copy+i-rowLwb_old;
906 const Int_t iRowNew = rowLwb_copy+i-this->fRowLwb;
907 Memcpy_m(elements_new+iRowNew*this->fNcols+colNewOff,
908 elements_old+iRowOld*ncols_old+colOldOff,ncols_copy,this->fNelems,nelems_old);
909 if (this->fNelems <= this->kSizeMax && nelems_old <= this->kSizeMax)
910 memset(elements_new+iRowNew*this->fNcols+colNewOff+ncols_copy,0,
911 (this->fNcols-ncols_copy)*
sizeof(Element));
914 for (
Int_t i = 0; i < nrows_copy; i++) {
915 const Int_t iRowOld = rowLwb_copy+i-rowLwb_old;
916 const Int_t iRowNew = rowLwb_copy+i-this->fRowLwb;
917 Memcpy_m(elements_new+iRowNew*this->fNcols+colNewOff,
918 elements_old+iRowOld*ncols_old+colOldOff,ncols_copy,this->fNelems,nelems_old);
923 Delete_m(nelems_old,elements_old);
925 Allocate(new_nrows,new_ncols,row_lwb,col_lwb,1);
933template<
class Element>
945template<
class Element>
959template<
class Element>
966 Element *p2 = this->GetMatrixArray();
967 for (
Int_t i = 0; i < this->GetNoElements(); i++)
977template<
class Element>
986 Element *pM = this->GetMatrixArray();
988 Error(
"InvertFast",
"matrix is singular");
998 TMatrixTSymCramerInv::Inv2x2<Element>(*
this,det);
1003 TMatrixTSymCramerInv::Inv3x3<Element>(*
this,det);
1008 TMatrixTSymCramerInv::Inv4x4<Element>(*
this,det);
1013 TMatrixTSymCramerInv::Inv5x5<Element>(*
this,det);
1018 TMatrixTSymCramerInv::Inv6x6<Element>(*
this,det);
1027 Element *p2 = this->GetMatrixArray();
1028 for (
Int_t i = 0; i < this->GetNoElements(); i++)
1039template<
class Element>
1048 Error(
"Transpose",
"matrix has wrong shape");
1061template<
class Element>
1067 if (
v.GetNoElements() < this->fNrows) {
1068 Error(
"Rank1Update",
"vector too short");
1073 const Element *
const pv =
v.GetMatrixArray();
1074 Element *trp = this->GetMatrixArray();
1076 for (
Int_t i = 0; i < this->fNrows; i++) {
1078 tcp += i*this->fNcols;
1079 const Element tmp = alpha*pv[i];
1080 for (
Int_t j = i; j < this->fNcols; j++) {
1081 if (j > i) *tcp += tmp*pv[j];
1082 *trp++ += tmp*pv[j];
1083 tcp += this->fNcols;
1085 tcp -= this->fNelems-1;
1097template<
class Element>
1103 if (this->fNcols !=
b.GetNcols() || this->fColLwb !=
b.GetColLwb()) {
1104 Error(
"Similarity(const TMatrixT &)",
"matrices incompatible");
1109 const Int_t ncolsa = this->fNcols;
1110 const Int_t nb =
b.GetNoElements();
1111 const Int_t nrowsb =
b.GetNrows();
1112 const Int_t ncolsb =
b.GetNcols();
1114 const Element *
const bp =
b.GetMatrixArray();
1116 Element work[kWorkMax];
1118 Element *bap = work;
1119 if (nrowsb*ncolsa > kWorkMax) {
1120 isAllocated =
kTRUE;
1121 bap =
new Element[nrowsb*ncolsa];
1124 AMultB(bp,nb,ncolsb,this->fElements,this->fNelems,this->fNcols,bap);
1126 if (nrowsb != this->fNrows)
1127 this->ResizeTo(nrowsb,nrowsb);
1130 Element *cp = this->GetMatrixArray();
1131 if (
typeid(Element) ==
typeid(
Double_t))
1132 cblas_dgemm (CblasRowMajor,CblasNoTrans,CblasTrans,this->fNrows,this->fNcols,ba.GetNcols(),
1133 1.0,bap,ba.GetNcols(),bp,
b.GetNcols(),1.0,cp,this->fNcols);
1134 else if (
typeid(Element) !=
typeid(
Float_t))
1135 cblas_sgemm (CblasRowMajor,CblasNoTrans,CblasTrans,this->fNrows,this->fNcols,ba.GetNcols(),
1136 1.0,bap,ba.GetNcols(),bp,
b.GetNcols(),1.0,cp,this->fNcols);
1138 Error(
"Similarity",
"type %s not implemented in BLAS library",
typeid(Element));
1140 const Int_t nba = nrowsb*ncolsa;
1141 const Int_t ncolsba = ncolsa;
1142 const Element * bi1p = bp;
1143 Element * cp = this->GetMatrixArray();
1144 Element *
const cp0 = cp;
1147 const Element *barp0 = bap;
1148 while (barp0 < bap+nba) {
1149 const Element *brp0 = bi1p;
1150 while (brp0 < bp+nb) {
1151 const Element *barp = barp0;
1152 const Element *brp = brp0;
1154 while (brp < brp0+ncolsb)
1155 cij += *barp++ * *brp++;
1164 R__ASSERT(cp == cp0+this->fNelems+ishift && barp0 == bap+nba);
1167 for (
Int_t irow = 0; irow < this->fNrows; irow++) {
1168 const Int_t rowOff1 = irow*this->fNrows;
1169 for (
Int_t icol = 0; icol < irow; icol++) {
1170 const Int_t rowOff2 = icol*this->fNrows;
1171 cp[rowOff1+icol] = cp[rowOff2+irow];
1188template<
class Element>
1194 if (this->fNcols !=
b.GetNcols() || this->fColLwb !=
b.GetColLwb()) {
1195 Error(
"Similarity(const TMatrixTSym &)",
"matrices incompatible");
1201 const Int_t nrowsb =
b.GetNrows();
1202 const Int_t ncolsa = this->GetNcols();
1204 Element work[kWorkMax];
1206 Element *abtp = work;
1207 if (this->fNcols > kWorkMax) {
1208 isAllocated =
kTRUE;
1209 abtp =
new Element[this->fNcols];
1214 const Element *bp =
b.GetMatrixArray();
1215 Element *cp = this->GetMatrixArray();
1216 if (
typeid(Element) ==
typeid(
Double_t))
1217 cblas_dsymm (CblasRowMajor,CblasLeft,CblasUpper,this->fNrows,this->fNcols,1.0,
1218 bp,
b.GetNcols(),abtp,abt.
GetNcols(),0.0,cp,this->fNcols);
1219 else if (
typeid(Element) !=
typeid(
Float_t))
1220 cblas_ssymm (CblasRowMajor,CblasLeft,CblasUpper,this->fNrows,this->fNcols,1.0,
1221 bp,
b.GetNcols(),abtp,abt.
GetNcols(),0.0,cp,this->fNcols);
1223 Error(
"Similarity",
"type %s not implemented in BLAS library",
typeid(Element));
1228 const Int_t ncolsa = this->GetNcols();
1229 const Int_t nb =
b.GetNoElements();
1230 const Int_t nrowsb =
b.GetNrows();
1231 const Int_t ncolsb =
b.GetNcols();
1233 const Element *
const bp =
b.GetMatrixArray();
1235 Element work[kWorkMax];
1237 Element *bap = work;
1238 if (nrowsb*ncolsa > kWorkMax) {
1239 isAllocated =
kTRUE;
1240 bap =
new Element[nrowsb*ncolsa];
1243 AMultB(bp,nb,ncolsb,this->fElements,this->fNelems,this->fNcols,bap);
1245 const Int_t nba = nrowsb*ncolsa;
1246 const Int_t ncolsba = ncolsa;
1247 const Element * bi1p = bp;
1248 Element * cp = this->GetMatrixArray();
1249 Element *
const cp0 = cp;
1252 const Element *barp0 = bap;
1253 while (barp0 < bap+nba) {
1254 const Element *brp0 = bi1p;
1255 while (brp0 < bp+nb) {
1256 const Element *barp = barp0;
1257 const Element *brp = brp0;
1259 while (brp < brp0+ncolsb)
1260 cij += *barp++ * *brp++;
1269 R__ASSERT(cp == cp0+this->fNelems+ishift && barp0 == bap+nba);
1272 for (
Int_t irow = 0; irow < this->fNrows; irow++) {
1273 const Int_t rowOff1 = irow*this->fNrows;
1274 for (
Int_t icol = 0; icol < irow; icol++) {
1275 const Int_t rowOff2 = icol*this->fNrows;
1276 cp[rowOff1+icol] = cp[rowOff2+irow];
1290template<
class Element>
1296 if (this->fNcols !=
v.GetNrows() || this->fColLwb !=
v.GetLwb()) {
1297 Error(
"Similarity(const TVectorT &)",
"vector and matrix incompatible");
1302 const Element *mp = this->GetMatrixArray();
1303 const Element *vp =
v.GetMatrixArray();
1306 const Element *
const vp_first = vp;
1307 const Element *
const vp_last = vp+
v.GetNrows();
1308 while (vp < vp_last) {
1310 for (
const Element *sp = vp_first; sp < vp_last; )
1311 sum2 += *mp++ * *sp++;
1312 sum1 += sum2 * *vp++;
1315 R__ASSERT(mp == this->GetMatrixArray()+this->GetNoElements());
1325template<
class Element>
1331 if (this->fNrows !=
b.GetNrows() || this->fRowLwb !=
b.GetRowLwb()) {
1332 Error(
"SimilarityT(const TMatrixT &)",
"matrices incompatible");
1337 const Int_t ncolsb =
b.GetNcols();
1338 const Int_t ncolsa = this->GetNcols();
1340 Element work[kWorkMax];
1342 Element *btap = work;
1343 if (ncolsb*ncolsa > kWorkMax) {
1344 isAllocated =
kTRUE;
1345 btap =
new Element[ncolsb*ncolsa];
1351 if (ncolsb != this->fNcols)
1352 this->ResizeTo(ncolsb,ncolsb);
1355 const Element *bp =
b.GetMatrixArray();
1356 Element *cp = this->GetMatrixArray();
1357 if (
typeid(Element) ==
typeid(
Double_t))
1358 cblas_dgemm (CblasRowMajor,CblasNoTrans,CblasNoTrans,this->fNrows,this->fNcols,bta.
GetNcols(),
1359 1.0,btap,bta.
GetNcols(),bp,
b.GetNcols(),1.0,cp,this->fNcols);
1360 else if (
typeid(Element) !=
typeid(
Float_t))
1361 cblas_sgemm (CblasRowMajor,CblasNoTrans,CblasNoTrans,this->fNrows,this->fNcols,bta.
GetNcols(),
1362 1.0,btap,bta.
GetNcols(),bp,
b.GetNcols(),1.0,cp,this->fNcols);
1364 Error(
"similarityT",
"type %s not implemented in BLAS library",
typeid(Element));
1367 const Int_t nb =
b.GetNoElements();
1369 const Element *
const bp =
b.GetMatrixArray();
1370 Element * cp = this->GetMatrixArray();
1371 Element *
const cp0 = cp;
1374 const Element *btarp0 = btap;
1375 const Element *bcp0 = bp;
1376 while (btarp0 < btap+nbta) {
1377 for (
const Element *bcp = bcp0; bcp < bp+ncolsb; ) {
1378 const Element *btarp = btarp0;
1380 while (bcp < bp+nb) {
1381 cij += *btarp++ * *bcp;
1392 R__ASSERT(cp == cp0+this->fNelems+ishift && btarp0 == btap+nbta);
1395 for (
Int_t irow = 0; irow < this->fNrows; irow++) {
1396 const Int_t rowOff1 = irow*this->fNrows;
1397 for (
Int_t icol = 0; icol < irow; icol++) {
1398 const Int_t rowOff2 = icol*this->fNrows;
1399 cp[rowOff1+icol] = cp[rowOff2+irow];
1412template<
class Element>
1416 Error(
"operator=",
"matrices not compatible");
1422 memcpy(this->GetMatrixArray(),source.
fElements,this->fNelems*
sizeof(Element));
1429template<
class Element>
1434 if (lazy_constructor.
fRowUpb != this->GetRowUpb() ||
1435 lazy_constructor.
fRowLwb != this->GetRowLwb()) {
1436 Error(
"operator=(const TMatrixTSymLazy&)",
"matrix is incompatible with "
1437 "the assigned Lazy matrix");
1441 lazy_constructor.
FillIn(*
this);
1448template<
class Element>
1453 Element *ep = fElements;
1454 const Element *
const ep_last = ep+this->fNelems;
1455 while (ep < ep_last)
1464template<
class Element>
1469 Element *ep = fElements;
1470 const Element *
const ep_last = ep+this->fNelems;
1471 while (ep < ep_last)
1480template<
class Element>
1485 Element *ep = fElements;
1486 const Element *
const ep_last = ep+this->fNelems;
1487 while (ep < ep_last)
1496template<
class Element>
1501 Element *ep = fElements;
1502 const Element *
const ep_last = ep+this->fNelems;
1503 while (ep < ep_last)
1512template<
class Element>
1516 Error(
"operator+=",
"matrices not compatible");
1521 Element *tp = this->GetMatrixArray();
1522 const Element *
const tp_last = tp+this->fNelems;
1523 while (tp < tp_last)
1532template<
class Element>
1536 Error(
"operator-=",
"matrices not compatible");
1541 Element *tp = this->GetMatrixArray();
1542 const Element *
const tp_last = tp+this->fNelems;
1543 while (tp < tp_last)
1551template<
class Element>
1557 Element *trp = this->GetMatrixArray();
1559 for (
Int_t i = 0; i < this->fNrows; i++) {
1561 tcp += i*this->fNcols;
1562 for (
Int_t j = i; j < this->fNcols; j++) {
1564 if (j > i) *tcp = val;
1566 tcp += this->fNcols;
1568 tcp -= this->fNelems-1;
1578template<
class Element>
1584 Element *trp = this->GetMatrixArray();
1586 for (
Int_t i = 0; i < this->fNrows; i++) {
1587 action.
fI = i+this->fRowLwb;
1589 tcp += i*this->fNcols;
1590 for (
Int_t j = i; j < this->fNcols; j++) {
1591 action.
fJ = j+this->fColLwb;
1593 if (j > i) *tcp = val;
1595 tcp += this->fNcols;
1597 tcp -= this->fNelems-1;
1606template<
class Element>
1611 if (this->fNrows != this->fNcols || this->fRowLwb != this->fColLwb) {
1612 Error(
"Randomize(Element,Element,Element &",
"matrix should be square");
1617 const Element scale =
beta-alpha;
1618 const Element shift = alpha/scale;
1620 Element *ep = GetMatrixArray();
1621 for (
Int_t i = 0; i < this->fNrows; i++) {
1622 const Int_t off = i*this->fNcols;
1623 for (
Int_t j = 0; j <= i; j++) {
1624 ep[off+j] = scale*(
Drand(seed)+shift);
1626 ep[j*this->fNcols+i] = ep[off+j];
1637template<
class Element>
1642 if (this->fNrows != this->fNcols || this->fRowLwb != this->fColLwb) {
1643 Error(
"RandomizeSym(Element,Element,Element &",
"matrix should be square");
1648 const Element scale =
beta-alpha;
1649 const Element shift = alpha/scale;
1651 Element *ep = GetMatrixArray();
1653 for (i = 0; i < this->fNrows; i++) {
1654 const Int_t off = i*this->fNcols;
1655 for (
Int_t j = 0; j <= i; j++)
1656 ep[off+j] = scale*(
Drand(seed)+shift);
1659 for (i = this->fNrows-1; i >= 0; i--) {
1660 const Int_t off1 = i*this->fNcols;
1661 for (
Int_t j = i; j >= 0; j--) {
1662 const Int_t off2 = j*this->fNcols;
1663 ep[off1+j] *= ep[off2+j];
1664 for (
Int_t k = j-1; k >= 0; k--) {
1665 ep[off1+j] += ep[off1+k]*ep[off2+k];
1668 ep[off2+i] = ep[off1+j];
1679template<
class Element>
1684 eigenValues.
ResizeTo(this->fNrows);
1692template<
class Element>
1702template<
class Element>
1712template<
class Element>
1722template<
class Element>
1730template<
class Element>
1740template<
class Element>
1750template<
class Element>
1753 return Element(-1.0)*
operator-(source1,val);
1758template<
class Element>
1768template<
class Element>
1777template<
class Element>
1783 Error(
"operator&&(const TMatrixTSym&,const TMatrixTSym&)",
"matrices not compatible");
1793 while (tp < tp_last)
1794 *tp++ = (*sp1++ != 0.0 && *sp2++ != 0.0);
1802template<
class Element>
1808 Error(
"operator||(const TMatrixTSym&,const TMatrixTSym&)",
"matrices not compatible");
1818 while (tp < tp_last)
1819 *tp++ = (*sp1++ != 0.0 || *sp2++ != 0.0);
1827template<
class Element>
1833 Error(
"operator>(const TMatrixTSym&,const TMatrixTSym&)",
"matrices not compatible");
1843 while (tp < tp_last) {
1844 *tp++ = (*sp1) > (*sp2); sp1++; sp2++;
1853template<
class Element>
1859 Error(
"operator>=(const TMatrixTSym&,const TMatrixTSym&)",
"matrices not compatible");
1869 while (tp < tp_last) {
1870 *tp++ = (*sp1) >= (*sp2); sp1++; sp2++;
1879template<
class Element>
1885 Error(
"operator<=(const TMatrixTSym&,const TMatrixTSym&)",
"matrices not compatible");
1895 while (tp < tp_last) {
1896 *tp++ = (*sp1) <= (*sp2); sp1++; sp2++;
1905template<
class Element>
1911 Error(
"operator<(const TMatrixTSym&,const TMatrixTSym&)",
"matrices not compatible");
1921 while (tp < tp_last) {
1922 *tp++ = (*sp1) < (*sp2); sp1++; sp2++;
1931template<
class Element>
1935 ::Error(
"Add",
"matrices not compatible");
1945 for (
Int_t i = 0; i < nrows; i++) {
1949 for (
Int_t j = i; j < ncols; j++) {
1950 const Element tmp = scalar * *sp++;
1951 if (j > i) *tcp += tmp;
1964template<
class Element>
1968 ::Error(
"ElementMult",
"matrices not compatible");
1978 for (
Int_t i = 0; i < nrows; i++) {
1982 for (
Int_t j = i; j < ncols; j++) {
1983 if (j > i) *tcp *= *sp;
1996template<
class Element>
2000 ::Error(
"ElementDiv",
"matrices not compatible");
2010 for (
Int_t i = 0; i < nrows; i++) {
2014 for (
Int_t j = i; j < ncols; j++) {
2016 if (j > i) *tcp /= *sp;
2021 Error(
"ElementDiv",
"source (%d,%d) is zero",irow,icol);
2035template<
class Element>
2043 fElements =
new Element[this->fNelems];
2045 for (i = 0; i < this->fNrows; i++) {
2046 R__b.
ReadFastArray(fElements+i*this->fNcols+i,this->fNcols-i);
2049 for (i = 0; i < this->fNrows; i++) {
2050 for (
Int_t j = 0; j < i; j++) {
2051 fElements[i*this->fNcols+j] = fElements[j*this->fNrows+i];
2054 if (this->fNelems <= this->kSizeMax) {
2055 memcpy(fDataStack,fElements,this->fNelems*
sizeof(Element));
2056 delete [] fElements;
2057 fElements = fDataStack;
2062 for (
Int_t i = 0; i < this->fNrows; i++) {
#define templateClassImp(name)
void Error(const char *location, const char *msgfmt,...)
R__EXTERN Int_t gMatrixCheck
Bool_t AreCompatible(const TMatrixTBase< Element1 > &m1, const TMatrixTBase< Element2 > &m2, Int_t verbose=0)
Check that matrice sm1 and m2 areboth valid and have identical shapes .
template TMatrixDSym & ElementMult< Double_t >(TMatrixDSym &target, const TMatrixDSym &source)
TMatrixTSym< Element > & ElementDiv(TMatrixTSym< Element > &target, const TMatrixTSym< Element > &source)
Multiply target by the source, element-by-element.
TMatrixTSym< Element > operator*(const TMatrixTSym< Element > &source1, Element val)
TMatrixTSym< Element > operator<(const TMatrixTSym< Element > &source1, const TMatrixTSym< Element > &source2)
source1 < source2
template TMatrixFSym & ElementMult< Float_t >(TMatrixFSym &target, const TMatrixFSym &source)
TMatrixTSym< Element > operator+(const TMatrixTSym< Element > &source1, const TMatrixTSym< Element > &source2)
template TMatrixFSym & Add< Float_t >(TMatrixFSym &target, Float_t scalar, const TMatrixFSym &source)
template TMatrixFSym & ElementDiv< Float_t >(TMatrixFSym &target, const TMatrixFSym &source)
template TMatrixDSym & Add< Double_t >(TMatrixDSym &target, Double_t scalar, const TMatrixDSym &source)
TMatrixTSym< Element > operator-(const TMatrixTSym< Element > &source1, const TMatrixTSym< Element > &source2)
template TMatrixFSym operator<=< Float_t >(const TMatrixFSym &source1, const TMatrixFSym &source2)
TMatrixTSym< Element > & Add(TMatrixTSym< Element > &target, Element scalar, const TMatrixTSym< Element > &source)
Modify addition: target += scalar * source.
TMatrixTSym< Element > & ElementMult(TMatrixTSym< Element > &target, const TMatrixTSym< Element > &source)
Multiply target by the source, element-by-element.
TMatrixTSym< Element > operator>(const TMatrixTSym< Element > &source1, const TMatrixTSym< Element > &source2)
source1 > source2
TMatrixTSym< Element > operator>=(const TMatrixTSym< Element > &source1, const TMatrixTSym< Element > &source2)
source1 >= source2
TMatrixTSym< Element > operator<=(const TMatrixTSym< Element > &source1, const TMatrixTSym< Element > &source2)
source1 <= source2
template TMatrixFSym operator<<Float_t >(const TMatrixFSym &source1, const TMatrixFSym &source2)
template TMatrixDSym & ElementDiv< Double_t >(TMatrixDSym &target, const TMatrixDSym &source)
TMatrixTSym< Element > operator||(const TMatrixTSym< Element > &source1, const TMatrixTSym< Element > &source2)
Logical Or.
TMatrixTSym< Element > operator&&(const TMatrixTSym< Element > &source1, const TMatrixTSym< Element > &source2)
Logical AND.
template TMatrixDSym operator<<Double_t >(const TMatrixDSym &source1, const TMatrixDSym &source2)
Bool_t operator==(const TMatrixTSym< Element > &m1, const TMatrixTSym< Element > &m2)
Check to see if two matrices are identical.
template TMatrixDSym operator<=< Double_t >(const TMatrixDSym &source1, const TMatrixDSym &source2)
Double_t Drand(Double_t &ix)
Random number generator [0....1] with seed ix.
Buffer base class used for serializing objects.
virtual Int_t ReadClassBuffer(const TClass *cl, void *pointer, const TClass *onfile_class=0)=0
virtual Version_t ReadVersion(UInt_t *start=0, UInt_t *bcnt=0, const TClass *cl=0)=0
virtual void ReadFastArray(Bool_t *b, Int_t n)=0
virtual Int_t WriteClassBuffer(const TClass *cl, void *pointer)=0
virtual void WriteFastArray(const Bool_t *b, Int_t n)=0
virtual void Det(Double_t &d1, Double_t &d2)
Calculate determinant det = d1*TMath::Power(2.,d2)
static Bool_t InvertLU(TMatrixD &a, Double_t tol, Double_t *det=0)
Calculate matrix inversion through in place forward/backward substitution.
virtual void Operation(Element &element) const =0
virtual void Operation(Element &element) const =0
const TVectorD & GetEigenValues() const
const TMatrixD & GetEigenVectors() const
virtual const Element * GetMatrixArray() const =0
virtual const Int_t * GetRowIndexArray() const =0
virtual const Int_t * GetColIndexArray() const =0
virtual TMatrixTBase< Element > & ResizeTo(Int_t nrows, Int_t ncols, Int_t nr_nonzeros=-1)=0
Int_t GetNoElements() const
virtual TMatrixTBase< Element > & Shift(Int_t row_shift, Int_t col_shift)
Shift the row index by adding row_shift and the column index by adding col_shift, respectively.
virtual Bool_t IsSymmetric() const
Check whether matrix is symmetric.
virtual TMatrixTBase< Element > & SetMatrixArray(const Element *data, Option_t *option="")
Copy array data to matrix .
virtual void FillIn(TMatrixTSym< Element > &m) const =0
TMatrixTSym< Element > & operator*=(Element val)
Multiply every element of the matrix with val.
virtual const Element * GetMatrixArray() const
TMatrixTSym< Element > & operator+=(Element val)
Add val to every element of the matrix.
virtual Double_t Determinant() const
virtual TMatrixTSym< Element > & RandomizePD(Element alpha, Element beta, Double_t &seed)
randomize matrix element values but keep matrix symmetric positive definite
virtual const Int_t * GetColIndexArray() const
TMatrixTSym< Element > & Transpose(const TMatrixTSym< Element > &source)
Transpose a matrix.
Element * New_m(Int_t size)
return data pointer .
TMatrixTSym< Element > & Use(Int_t row_lwb, Int_t row_upb, Element *data)
TMatrixTSym< Element > & Rank1Update(const TVectorT< Element > &v, Element alpha=1.0)
Perform a rank 1 operation on the matrix: A += alpha * v * v^T.
void Minus(const TMatrixTSym< Element > &a, const TMatrixTSym< Element > &b)
Symmetric matrix summation. Create a matrix C such that C = A + B.
virtual TMatrixTBase< Element > & Shift(Int_t row_shift, Int_t col_shift)
Shift the row index by adding row_shift and the column index by adding col_shift, respectively.
TMatrixTSym< Element > & Invert(Double_t *det=0)
Invert the matrix and calculate its determinant Notice that the LU decomposition is used instead of B...
void TMult(const TMatrixT< Element > &a)
Create a matrix C such that C = A' * A.
void Delete_m(Int_t size, Element *&)
delete data pointer m, if it was assigned on the heap
void Allocate(Int_t nrows, Int_t ncols, Int_t row_lwb=0, Int_t col_lwb=0, Int_t init=0, Int_t=-1)
Allocate new matrix.
TMatrixTSym< Element > & GetSub(Int_t row_lwb, Int_t row_upb, TMatrixTSym< Element > &target, Option_t *option="S") const
Get submatrix [row_lwb..row_upb][row_lwb..row_upb]; The indexing range of the returned matrix depends...
virtual TMatrixTBase< Element > & SetMatrixArray(const Element *data, Option_t *option="")
Copy array data to matrix .
Int_t Memcpy_m(Element *newp, const Element *oldp, Int_t copySize, Int_t newSize, Int_t oldSize)
copy copySize doubles from *oldp to *newp .
const TMatrixT< Element > EigenVectors(TVectorT< Element > &eigenValues) const
Return a matrix containing the eigen-vectors ordered by descending eigen-values.
TMatrixTSym< Element > & operator-=(Element val)
Subtract val from every element of the matrix.
void Plus(const TMatrixTSym< Element > &a, const TMatrixTSym< Element > &b)
Symmetric matrix summation. Create a matrix C such that C = A + B.
virtual const Int_t * GetRowIndexArray() const
TMatrixTBase< Element > & Apply(const TElementActionT< Element > &action)
Apply action to each matrix element.
TMatrixTSym< Element > & SimilarityT(const TMatrixT< Element > &n)
Calculate B^T * (*this) * B , final matrix will be (ncolsb x ncolsb) It is more efficient than applyi...
virtual TMatrixTBase< Element > & Randomize(Element alpha, Element beta, Double_t &seed)
randomize matrix element values but keep matrix symmetric
TMatrixTSym< Element > & Similarity(const TMatrixT< Element > &n)
Calculate B * (*this) * B^T , final matrix will be (nrowsb x nrowsb) This is a similarity transform w...
TMatrixTSym< Element > & operator=(const TMatrixTSym< Element > &source)
TMatrixTSym< Element > & InvertFast(Double_t *det=0)
Invert the matrix and calculate its determinant.
TMatrixTSym< Element > & SetSub(Int_t row_lwb, const TMatrixTBase< Element > &source)
Insert matrix source starting at [row_lwb][row_lwb], thereby overwriting the part [row_lwb....
Element * fElements
data container
virtual TMatrixTBase< Element > & ResizeTo(Int_t nrows, Int_t ncols, Int_t=-1)
Set size of the matrix to nrows x ncols New dynamic elements are created, the overlapping part of the...
TMatrixT< Element > & Use(Int_t row_lwb, Int_t row_upb, Int_t col_lwb, Int_t col_upb, Element *data)
Use the array data to fill the matrix ([row_lwb..row_upb] x [col_lwb..col_upb])
virtual const Element * GetMatrixArray() const
void TMult(const TMatrixT< Element > &a, const TMatrixT< Element > &b)
Create a matrix C such that C = A' * B.
TObject & operator=(const TObject &rhs)
TObject assignment operator.
void ToUpper()
Change string to upper case.
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
TVectorT< Element > & ResizeTo(Int_t lwb, Int_t upb)
Resize the vector to [lwb:upb] .
Expr< TransposeOp< SMatrix< T, D1, D2, R >, T, D1, D2 >, T, D2, D1, typename TranspPolicy< T, D1, D2, R >::RepType > Transpose(const SMatrix< T, D1, D2, R > &rhs)
Matrix Transpose B(i,j) = A(j,i) returning a matrix expression.
double beta(double x, double y)
Calculates the beta function.
EvaluateInfo init(std::vector< RooRealProxy > parameters, std::vector< ArrayWrapper * > wrappers, std::vector< double * > arrays, size_t begin, size_t batchSize)
TCppObject_t Allocate(TCppType_t type)
void AMultB(int n, int m, int k, const double *A, const double *B, double *C)
int Invert(LASymMatrix &)
static constexpr double m2
Short_t Max(Short_t a, Short_t b)
LongDouble_t Power(LongDouble_t x, LongDouble_t y)
Short_t Min(Short_t a, Short_t b)