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>
73template<
class Element>
76 const Int_t no_rows = row_upb-row_lwb+1;
77 Allocate(no_rows,no_rows,row_lwb,row_lwb);
83template<
class Element>
96template<
class Element>
126 const Element oldTol = this->
SetTol(std::numeric_limits<Element>::min());
138 Error(
"TMatrixTSym(EMatrixCreatorOp1,const TMatrixTSym)",
139 "operation %d not yet implemented", op);
145template<
class Element>
157 Error(
"TMatrixTSym(EMatrixCreatorOp1,const TMatrixT)",
158 "operation %d not yet implemented", op);
164template<
class Element>
173 Allocate(
a.GetNcols(),
a.GetNcols(),
a.GetColLwb(),
a.GetColLwb(),1);
180 Allocate(
a.GetNcols(),
a.GetNcols(),
a.GetColLwb(),
a.GetColLwb(),1);
186 Error(
"TMatrixTSym(EMatrixCreatorOp2)",
"operation %d not yet implemented", op);
192template<
class Element>
198 lazy_constructor.
FillIn(*
this);
200 Error(
"TMatrixTSym(TMatrixTSymLazy)",
"matrix not symmetric");
207template<
class Element>
221template<
class Element>
224 if (
size == 0)
return nullptr;
229 Element *heap =
new Element[
size];
239template<
class Element>
243 if (copySize == 0 || oldp == newp)
249 for (
Int_t i = copySize-1; i >= 0; i--)
252 for (
Int_t i = 0; i < copySize; i++)
257 memcpy(newp,oldp,copySize*
sizeof(Element));
266template<
class Element>
271 this->
fTol = std::numeric_limits<Element>::epsilon();
279 if (no_rows < 0 || no_cols < 0)
281 Error(
"Allocate",
"no_rows=%d no_cols=%d",no_rows,no_cols);
304template<
class Element>
309 Error(
"Plus",
"matrices not compatible");
314 Error(
"Plus",
"this->GetMatrixArray() == a.GetMatrixArray()");
319 Error(
"Plus",
"this->GetMatrixArray() == b.GetMatrixArray()");
324 const Element * ap =
a.GetMatrixArray();
325 const Element * bp =
b.GetMatrixArray();
327 const Element *
const cp_last = cp+this->
fNelems;
329 while (cp < cp_last) {
338template<
class Element>
343 Error(
"Minus",
"matrices not compatible");
348 Error(
"Minus",
"this->GetMatrixArray() == a.GetMatrixArray()");
353 Error(
"Minus",
"this->GetMatrixArray() == b.GetMatrixArray()");
358 const Element * ap =
a.GetMatrixArray();
359 const Element * bp =
b.GetMatrixArray();
361 const Element *
const cp_last = cp+this->
fNelems;
363 while (cp < cp_last) {
373template<
class Element>
379 const Element *ap =
a.GetMatrixArray();
381 if (
typeid(Element) ==
typeid(
Double_t))
382 cblas_dgemm (CblasRowMajor,CblasTrans,CblasNoTrans,this->
fNrows,this->
fNcols,
a.GetNrows(),
383 1.0,ap,
a.GetNcols(),ap,
a.GetNcols(),1.0,cp,this->fNcols);
384 else if (
typeid(Element) !=
typeid(
Float_t))
385 cblas_sgemm (CblasRowMajor,CblasTrans,CblasNoTrans,
fNrows,
fNcols,
a.GetNrows(),
386 1.0,ap,
a.GetNcols(),ap,
a.GetNcols(),1.0,cp,
fNcols);
388 Error(
"TMult",
"type %s not implemented in BLAS library",
typeid(Element));
390 const Int_t nb =
a.GetNoElements();
391 const Int_t ncolsa =
a.GetNcols();
392 const Int_t ncolsb = ncolsa;
393 const Element *
const ap =
a.GetMatrixArray();
394 const Element *
const bp = ap;
397 const Element *acp0 = ap;
398 while (acp0 < ap+
a.GetNcols()) {
399 for (
const Element *bcp = bp; bcp < bp+ncolsb; ) {
400 const Element *acp = acp0;
402 while (bcp < bp+nb) {
421template<
class Element>
427 const Element *ap =
a.GetMatrixArray();
429 if (
typeid(Element) ==
typeid(
Double_t))
430 cblas_dsymm (CblasRowMajor,CblasLeft,CblasUpper,this->
fNrows,this->
fNcols,1.0,
431 ap,
a.GetNcols(),ap,
a.GetNcols(),0.0,cp,this->fNcols);
432 else if (
typeid(Element) !=
typeid(
Float_t))
433 cblas_ssymm (CblasRowMajor,CblasLeft,CblasUpper,
fNrows,
fNcols,1.0,
434 ap1,
a.GetNcols(),ap,
a.GetNcols(),0.0,cp,
fNcols);
436 Error(
"TMult",
"type %s not implemented in BLAS library",
typeid(Element));
438 const Int_t nb =
a.GetNoElements();
439 const Int_t ncolsa =
a.GetNcols();
440 const Int_t ncolsb = ncolsa;
441 const Element *
const ap =
a.GetMatrixArray();
442 const Element *
const bp = ap;
445 const Element *acp0 = ap;
446 while (acp0 < ap+
a.GetNcols()) {
447 for (
const Element *bcp = bp; bcp < bp+ncolsb; ) {
448 const Element *acp = acp0;
450 while (bcp < bp+nb) {
467template<
class Element>
472 Error(
"Use",
"row_upb=%d < row_lwb=%d",row_upb,row_lwb);
477 this->
fNrows = row_upb-row_lwb+1;
495template<
class Element>
502 Error(
"GetSub",
"row_lwb out of bounds");
506 Error(
"GetSub",
"row_upb out of bounds");
509 if (row_upb < row_lwb) {
510 Error(
"GetSub",
"row_upb < row_lwb");
523 row_upb_sub = row_upb-row_lwb;
525 row_lwb_sub = row_lwb;
526 row_upb_sub = row_upb;
529 target.
ResizeTo(row_lwb_sub,row_upb_sub,row_lwb_sub,row_upb_sub);
530 const Int_t nrows_sub = row_upb_sub-row_lwb_sub+1;
533 for (
Int_t irow = 0; irow < nrows_sub; irow++) {
534 for (
Int_t icol = 0; icol < nrows_sub; icol++) {
535 target(irow+row_lwb_sub,icol+row_lwb_sub) = (*this)(row_lwb+irow,row_lwb+icol);
542 for (
Int_t irow = 0; irow < nrows_sub; irow++) {
543 const Element *ap_sub = ap;
544 for (
Int_t icol = 0; icol < nrows_sub; icol++) {
561template<
class Element>
568 Error(
"GetSub",
"row_lwb out of bounds");
572 Error(
"GetSub",
"col_lwb out of bounds");
576 Error(
"GetSub",
"row_upb out of bounds");
580 Error(
"GetSub",
"col_upb out of bounds");
583 if (row_upb < row_lwb || col_upb < col_lwb) {
584 Error(
"GetSub",
"row_upb < row_lwb || col_upb < col_lwb");
593 const Int_t row_lwb_sub = (shift) ? 0 : row_lwb;
594 const Int_t row_upb_sub = (shift) ? row_upb-row_lwb : row_upb;
595 const Int_t col_lwb_sub = (shift) ? 0 : col_lwb;
596 const Int_t col_upb_sub = (shift) ? col_upb-col_lwb : col_upb;
598 target.
ResizeTo(row_lwb_sub,row_upb_sub,col_lwb_sub,col_upb_sub);
599 const Int_t nrows_sub = row_upb_sub-row_lwb_sub+1;
600 const Int_t ncols_sub = col_upb_sub-col_lwb_sub+1;
603 for (
Int_t irow = 0; irow < nrows_sub; irow++) {
604 for (
Int_t icol = 0; icol < ncols_sub; icol++) {
605 target(irow+row_lwb_sub,icol+col_lwb_sub) = (*this)(row_lwb+irow,col_lwb+icol);
612 for (
Int_t irow = 0; irow < nrows_sub; irow++) {
613 const Element *ap_sub = ap;
614 for (
Int_t icol = 0; icol < ncols_sub; icol++) {
628template<
class Element>
636 Error(
"SetSub",
"source matrix is not symmetric");
640 Error(
"SetSub",
"row_lwb outof bounds");
643 if (row_lwb+source.
GetNrows() > this->fRowLwb+this->fNrows) {
644 Error(
"SetSub",
"source matrix too large");
653 for (
Int_t irow = 0; irow < nRows_source; irow++) {
654 for (
Int_t icol = 0; icol < nRows_source; icol++) {
655 (*this)(row_lwb+irow,row_lwb+icol) = source(rowlwb_s+irow,rowlwb_s+icol);
662 for (
Int_t irow = 0; irow < nRows_source; irow++) {
663 Element *ap_sub = ap;
664 for (
Int_t icol = 0; icol < nRows_source; icol++) {
678template<
class Element>
686 Error(
"SetSub",
"row_lwb out of bounds");
690 Error(
"SetSub",
"col_lwb out of bounds");
694 if (row_lwb+source.
GetNrows() > this->fRowLwb+this->fNrows || col_lwb+source.
GetNcols() > this->fRowLwb+this->fNrows) {
695 Error(
"SetSub",
"source matrix too large");
698 if (col_lwb+source.
GetNcols() > this->fRowLwb+this->fNrows || row_lwb+source.
GetNrows() > this->fRowLwb+this->fNrows) {
699 Error(
"SetSub",
"source matrix too large");
709 if (row_lwb >= col_lwb) {
712 for (irow = 0; irow < nRows_source; irow++) {
713 for (
Int_t icol = 0; col_lwb+icol <= row_lwb+irow &&
714 icol < nCols_source; icol++) {
715 (*this)(row_lwb+irow,col_lwb+icol) = source(irow+rowlwb_s,icol+collwb_s);
720 for (irow = 0; irow < nCols_source; irow++) {
721 for (
Int_t icol = nRows_source-1; row_lwb+icol > irow+col_lwb &&
723 (*this)(col_lwb+irow,row_lwb+icol) = source(icol+rowlwb_s,irow+collwb_s);
735template<
class Element>
740 Error(
"SetMatrixArray",
"Matrix is not symmetric after Set");
748template<
class Element>
751 if (row_shift != col_shift) {
752 Error(
"Shift",
"row_shift != col_shift");
763template<
class Element>
768 Error(
"ResizeTo(Int_t,Int_t)",
"Not owner of data array,cannot resize");
772 if (nrows != ncols) {
773 Error(
"ResizeTo(Int_t,Int_t)",
"nrows != ncols");
780 else if (nrows == 0 || ncols == 0) {
798 memset(elements_new,0,this->
fNelems*
sizeof(Element));
799 else if (this->
fNelems > nelems_old)
800 memset(elements_new+nelems_old,0,(this->
fNelems-nelems_old)*
sizeof(Element));
807 if (ncols_old < this->
fNcols) {
808 for (
Int_t i = nrows_copy-1; i >= 0; i--) {
809 Memcpy_m(elements_new+i*this->fNcols,elements_old+i*ncols_old,ncols_copy,
810 nelems_new,nelems_old);
812 memset(elements_new+i*this->fNcols+ncols_copy,0,(this->fNcols-ncols_copy)*
sizeof(Element));
815 for (
Int_t i = 0; i < nrows_copy; i++)
816 Memcpy_m(elements_new+i*this->fNcols,elements_old+i*ncols_old,ncols_copy,
817 nelems_new,nelems_old);
833template<
class Element>
839 Error(
"ResizeTo(Int_t,Int_t,Int_t,Int_t)",
"Not owner of data array,cannot resize");
843 if (row_lwb != col_lwb) {
844 Error(
"ResizeTo(Int_t,Int_t,Int_t,Int_t)",
"row_lwb != col_lwb");
847 if (row_upb != col_upb) {
848 Error(
"ResizeTo(Int_t,Int_t,Int_t,Int_t)",
"row_upb != col_upb");
852 const Int_t new_nrows = row_upb-row_lwb+1;
853 const Int_t new_ncols = col_upb-col_lwb+1;
857 if (this->
fNrows == new_nrows && this->
fNcols == new_ncols &&
860 else if (new_nrows == 0 || new_ncols == 0) {
874 Allocate(new_nrows,new_ncols,row_lwb,col_lwb);
881 memset(elements_new,0,this->
fNelems*
sizeof(Element));
882 else if (this->
fNelems > nelems_old)
883 memset(elements_new+nelems_old,0,(this->
fNelems-nelems_old)*
sizeof(Element));
891 const Int_t nrows_copy = rowUpb_copy-rowLwb_copy+1;
892 const Int_t ncols_copy = colUpb_copy-colLwb_copy+1;
894 if (nrows_copy > 0 && ncols_copy > 0) {
895 const Int_t colOldOff = colLwb_copy-colLwb_old;
897 if (ncols_old < this->
fNcols) {
898 for (
Int_t i = nrows_copy-1; i >= 0; i--) {
899 const Int_t iRowOld = rowLwb_copy+i-rowLwb_old;
901 Memcpy_m(elements_new+iRowNew*this->fNcols+colNewOff,
902 elements_old+iRowOld*ncols_old+colOldOff,ncols_copy,this->
fNelems,nelems_old);
904 memset(elements_new+iRowNew*this->fNcols+colNewOff+ncols_copy,0,
905 (this->fNcols-ncols_copy)*
sizeof(Element));
908 for (
Int_t i = 0; i < nrows_copy; i++) {
909 const Int_t iRowOld = rowLwb_copy+i-rowLwb_old;
911 Memcpy_m(elements_new+iRowNew*this->fNcols+colNewOff,
912 elements_old+iRowOld*ncols_old+colOldOff,ncols_copy,this->
fNelems,nelems_old);
919 Allocate(new_nrows,new_ncols,row_lwb,col_lwb,1);
927template<
class Element>
939template<
class Element>
953template<
class Element>
971template<
class Element>
982 Error(
"InvertFast",
"matrix is singular");
1033template<
class Element>
1042 Error(
"Transpose",
"matrix has wrong shape");
1055template<
class Element>
1061 if (
v.GetNoElements() < this->fNrows) {
1062 Error(
"Rank1Update",
"vector too short");
1067 const Element *
const pv =
v.GetMatrixArray();
1073 const Element tmp = alpha*pv[i];
1074 for (
Int_t j = i; j < this->fNcols; j++) {
1075 if (j > i) *tcp += tmp*pv[j];
1076 *trp++ += tmp*pv[j];
1077 tcp += this->fNcols;
1091template<
class Element>
1097 if (this->
fNcols !=
b.GetNcols() || this->fColLwb !=
b.GetColLwb()) {
1098 Error(
"Similarity(const TMatrixT &)",
"matrices incompatible");
1104 const Int_t nb =
b.GetNoElements();
1105 const Int_t nrowsb =
b.GetNrows();
1106 const Int_t ncolsb =
b.GetNcols();
1108 const Element *
const bp =
b.GetMatrixArray();
1112 Element *bap = work;
1114 isAllocated =
kTRUE;
1115 bap =
new Element[nrowsb*ncolsa];
1120 if (nrowsb != this->
fNrows)
1125 if (
typeid(Element) ==
typeid(
Double_t))
1126 cblas_dgemm (CblasRowMajor,CblasNoTrans,CblasTrans,this->
fNrows,this->
fNcols,ba.GetNcols(),
1127 1.0,bap,ba.GetNcols(),bp,
b.GetNcols(),1.0,cp,this->fNcols);
1128 else if (
typeid(Element) !=
typeid(
Float_t))
1129 cblas_sgemm (CblasRowMajor,CblasNoTrans,CblasTrans,this->
fNrows,this->
fNcols,ba.GetNcols(),
1130 1.0,bap,ba.GetNcols(),bp,
b.GetNcols(),1.0,cp,this->fNcols);
1132 Error(
"Similarity",
"type %s not implemented in BLAS library",
typeid(Element));
1134 const Int_t nba = nrowsb*ncolsa;
1135 const Int_t ncolsba = ncolsa;
1136 const Element * bi1p = bp;
1138 Element *
const cp0 = cp;
1141 const Element *barp0 = bap;
1142 while (barp0 < bap+nba) {
1143 const Element *brp0 = bi1p;
1144 while (brp0 < bp+nb) {
1145 const Element *barp = barp0;
1146 const Element *brp = brp0;
1148 while (brp < brp0+ncolsb)
1149 cij += *barp++ * *brp++;
1161 for (
Int_t irow = 0; irow < this->
fNrows; irow++) {
1162 const Int_t rowOff1 = irow*this->fNrows;
1163 for (
Int_t icol = 0; icol < irow; icol++) {
1164 const Int_t rowOff2 = icol*this->fNrows;
1165 cp[rowOff1+icol] = cp[rowOff2+irow];
1182template<
class Element>
1188 if (this->
fNcols !=
b.GetNcols() || this->fColLwb !=
b.GetColLwb()) {
1189 Error(
"Similarity(const TMatrixTSym &)",
"matrices incompatible");
1195 const Int_t nrowsb =
b.GetNrows();
1200 Element *abtp = work;
1202 isAllocated =
kTRUE;
1203 abtp =
new Element[this->
fNcols];
1208 const Element *bp =
b.GetMatrixArray();
1210 if (
typeid(Element) ==
typeid(
Double_t))
1211 cblas_dsymm (CblasRowMajor,CblasLeft,CblasUpper,this->
fNrows,this->
fNcols,1.0,
1212 bp,
b.GetNcols(),abtp,abt.
GetNcols(),0.0,cp,this->fNcols);
1213 else if (
typeid(Element) !=
typeid(
Float_t))
1214 cblas_ssymm (CblasRowMajor,CblasLeft,CblasUpper,this->
fNrows,this->
fNcols,1.0,
1215 bp,
b.GetNcols(),abtp,abt.
GetNcols(),0.0,cp,this->fNcols);
1217 Error(
"Similarity",
"type %s not implemented in BLAS library",
typeid(Element));
1223 const Int_t nb =
b.GetNoElements();
1224 const Int_t nrowsb =
b.GetNrows();
1225 const Int_t ncolsb =
b.GetNcols();
1227 const Element *
const bp =
b.GetMatrixArray();
1231 Element *bap = work;
1233 isAllocated =
kTRUE;
1234 bap =
new Element[nrowsb*ncolsa];
1239 const Int_t nba = nrowsb*ncolsa;
1240 const Int_t ncolsba = ncolsa;
1241 const Element * bi1p = bp;
1243 Element *
const cp0 = cp;
1246 const Element *barp0 = bap;
1247 while (barp0 < bap+nba) {
1248 const Element *brp0 = bi1p;
1249 while (brp0 < bp+nb) {
1250 const Element *barp = barp0;
1251 const Element *brp = brp0;
1253 while (brp < brp0+ncolsb)
1254 cij += *barp++ * *brp++;
1266 for (
Int_t irow = 0; irow < this->
fNrows; irow++) {
1267 const Int_t rowOff1 = irow*this->fNrows;
1268 for (
Int_t icol = 0; icol < irow; icol++) {
1269 const Int_t rowOff2 = icol*this->fNrows;
1270 cp[rowOff1+icol] = cp[rowOff2+irow];
1284template<
class Element>
1290 if (this->
fNcols !=
v.GetNrows() || this->fColLwb !=
v.GetLwb()) {
1291 Error(
"Similarity(const TVectorT &)",
"vector and matrix incompatible");
1297 const Element *vp =
v.GetMatrixArray();
1300 const Element *
const vp_first = vp;
1301 const Element *
const vp_last = vp+
v.GetNrows();
1302 while (vp < vp_last) {
1304 for (
const Element *sp = vp_first; sp < vp_last; )
1305 sum2 += *mp++ * *sp++;
1306 sum1 += sum2 * *vp++;
1319template<
class Element>
1325 if (this->
fNrows !=
b.GetNrows() || this->fRowLwb !=
b.GetRowLwb()) {
1326 Error(
"SimilarityT(const TMatrixT &)",
"matrices incompatible");
1331 const Int_t ncolsb =
b.GetNcols();
1336 Element *btap = work;
1338 isAllocated =
kTRUE;
1339 btap =
new Element[ncolsb*ncolsa];
1345 if (ncolsb != this->
fNcols)
1349 const Element *bp =
b.GetMatrixArray();
1351 if (
typeid(Element) ==
typeid(
Double_t))
1353 1.0,btap,bta.
GetNcols(),bp,
b.GetNcols(),1.0,cp,this->fNcols);
1354 else if (
typeid(Element) !=
typeid(
Float_t))
1356 1.0,btap,bta.
GetNcols(),bp,
b.GetNcols(),1.0,cp,this->fNcols);
1358 Error(
"similarityT",
"type %s not implemented in BLAS library",
typeid(Element));
1361 const Int_t nb =
b.GetNoElements();
1363 const Element *
const bp =
b.GetMatrixArray();
1365 Element *
const cp0 = cp;
1368 const Element *btarp0 = btap;
1369 const Element *bcp0 = bp;
1370 while (btarp0 < btap+nbta) {
1371 for (
const Element *bcp = bcp0; bcp < bp+ncolsb; ) {
1372 const Element *btarp = btarp0;
1374 while (bcp < bp+nb) {
1375 cij += *btarp++ * *bcp;
1389 for (
Int_t irow = 0; irow < this->
fNrows; irow++) {
1390 const Int_t rowOff1 = irow*this->fNrows;
1391 for (
Int_t icol = 0; icol < irow; icol++) {
1392 const Int_t rowOff2 = icol*this->fNrows;
1393 cp[rowOff1+icol] = cp[rowOff2+irow];
1406template<
class Element>
1410 Error(
"operator=",
"matrices not compatible");
1423template<
class Element>
1428 if (lazy_constructor.
fRowUpb != this->GetRowUpb() ||
1429 lazy_constructor.
fRowLwb != this->GetRowLwb()) {
1430 Error(
"operator=(const TMatrixTSymLazy&)",
"matrix is incompatible with "
1431 "the assigned Lazy matrix");
1435 lazy_constructor.
FillIn(*
this);
1442template<
class Element>
1448 const Element *
const ep_last = ep+this->
fNelems;
1449 while (ep < ep_last)
1458template<
class Element>
1464 const Element *
const ep_last = ep+this->
fNelems;
1465 while (ep < ep_last)
1474template<
class Element>
1480 const Element *
const ep_last = ep+this->
fNelems;
1481 while (ep < ep_last)
1490template<
class Element>
1496 const Element *
const ep_last = ep+this->
fNelems;
1497 while (ep < ep_last)
1506template<
class Element>
1510 Error(
"operator+=",
"matrices not compatible");
1516 const Element *
const tp_last = tp+this->
fNelems;
1517 while (tp < tp_last)
1526template<
class Element>
1530 Error(
"operator-=",
"matrices not compatible");
1536 const Element *
const tp_last = tp+this->
fNelems;
1537 while (tp < tp_last)
1545template<
class Element>
1556 for (
Int_t j = i; j < this->fNcols; j++) {
1558 if (j > i) *tcp = val;
1560 tcp += this->fNcols;
1572template<
class Element>
1584 for (
Int_t j = i; j < this->fNcols; j++) {
1587 if (j > i) *tcp = val;
1589 tcp += this->fNcols;
1600template<
class Element>
1606 Error(
"Randomize(Element,Element,Element &",
"matrix should be square");
1611 const Element scale = beta-alpha;
1612 const Element shift = alpha/scale;
1617 for (
Int_t j = 0; j <= i; j++) {
1618 ep[off+j] = scale*(
Drand(seed)+shift);
1620 ep[j*this->fNcols+i] = ep[off+j];
1631template<
class Element>
1637 Error(
"RandomizeSym(Element,Element,Element &",
"matrix should be square");
1642 const Element scale = beta-alpha;
1643 const Element shift = alpha/scale;
1647 for (i = 0; i < this->
fNrows; i++) {
1649 for (
Int_t j = 0; j <= i; j++)
1650 ep[off+j] = scale*(
Drand(seed)+shift);
1653 for (i = this->fNrows-1; i >= 0; i--) {
1655 for (
Int_t j = i; j >= 0; j--) {
1656 const Int_t off2 = j*this->fNcols;
1657 ep[off1+j] *= ep[off2+j];
1658 for (
Int_t k = j-1; k >= 0; k--) {
1659 ep[off1+j] += ep[off1+k]*ep[off2+k];
1662 ep[off2+i] = ep[off1+j];
1673template<
class Element>
1686template<
class Element>
1696template<
class Element>
1706template<
class Element>
1716template<
class Element>
1724template<
class Element>
1734template<
class Element>
1744template<
class Element>
1747 return Element(-1.0)*
operator-(source1,val);
1752template<
class Element>
1762template<
class Element>
1771template<
class Element>
1777 Error(
"operator&&(const TMatrixTSym&,const TMatrixTSym&)",
"matrices not compatible");
1787 while (tp < tp_last)
1788 *tp++ = (*sp1++ != 0.0 && *sp2++ != 0.0);
1796template<
class Element>
1802 Error(
"operator||(const TMatrixTSym&,const TMatrixTSym&)",
"matrices not compatible");
1812 while (tp < tp_last)
1813 *tp++ = (*sp1++ != 0.0 || *sp2++ != 0.0);
1821template<
class Element>
1827 Error(
"operator>(const TMatrixTSym&,const TMatrixTSym&)",
"matrices not compatible");
1837 while (tp < tp_last) {
1838 *tp++ = (*sp1) > (*sp2); sp1++; sp2++;
1847template<
class Element>
1853 Error(
"operator>=(const TMatrixTSym&,const TMatrixTSym&)",
"matrices not compatible");
1863 while (tp < tp_last) {
1864 *tp++ = (*sp1) >= (*sp2); sp1++; sp2++;
1873template<
class Element>
1879 Error(
"operator<=(const TMatrixTSym&,const TMatrixTSym&)",
"matrices not compatible");
1889 while (tp < tp_last) {
1890 *tp++ = (*sp1) <= (*sp2); sp1++; sp2++;
1899template<
class Element>
1905 Error(
"operator<(const TMatrixTSym&,const TMatrixTSym&)",
"matrices not compatible");
1915 while (tp < tp_last) {
1916 *tp++ = (*sp1) < (*sp2); sp1++; sp2++;
1925template<
class Element>
1929 ::Error(
"Add",
"matrices not compatible");
1939 for (
Int_t i = 0; i < nrows; i++) {
1943 for (
Int_t j = i; j < ncols; j++) {
1944 const Element tmp = scalar * *sp++;
1945 if (j > i) *tcp += tmp;
1958template<
class Element>
1962 ::Error(
"ElementMult",
"matrices not compatible");
1972 for (
Int_t i = 0; i < nrows; i++) {
1976 for (
Int_t j = i; j < ncols; j++) {
1977 if (j > i) *tcp *= *sp;
1990template<
class Element>
1994 ::Error(
"ElementDiv",
"matrices not compatible");
2004 for (
Int_t i = 0; i < nrows; i++) {
2008 for (
Int_t j = i; j < ncols; j++) {
2010 if (j > i) *tcp /= *sp;
2015 Error(
"ElementDiv",
"source (%d,%d) is zero",irow,icol);
2029template<
class Element>
2039 for (i = 0; i < this->
fNrows; i++) {
2043 for (i = 0; i < this->fNrows; i++) {
2044 for (
Int_t j = 0; j < i; j++) {
2048 if (this->fNelems <= this->
kSizeMax) {
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
int Int_t
Signed integer 4 bytes (int).
short Version_t
Class version identifier (short).
char Char_t
Character 1 byte (char).
unsigned int UInt_t
Unsigned integer 4 bytes (unsigned int).
bool Bool_t
Boolean (0=false, 1=true) (bool).
double Double_t
Double 8 bytes.
float Float_t
Float 4 bytes (float).
const char Option_t
Option string (const char).
Error("WriteTObject","The current directory (%s) is not associated with a file. The object (%s) has not been written.", GetName(), objname)
#define R__ASSERT(e)
Checks condition e and reports a fatal error if it's false.
TMatrixTSym< Double_t > TMatrixDSym
TMatrixT< Double_t > TMatrixD
TMatrixTSym< Float_t > TMatrixFSym
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 Version_t ReadVersion(UInt_t *start=nullptr, UInt_t *bcnt=nullptr, const TClass *cl=nullptr)=0
virtual void ReadFastArray(Bool_t *b, Int_t n)=0
virtual Int_t ReadClassBuffer(const TClass *cl, void *pointer, const TClass *onfile_class=nullptr)=0
virtual void WriteFastArray(const Bool_t *b, Long64_t n)=0
virtual Int_t WriteClassBuffer(const TClass *cl, void *pointer)=0
void Det(Double_t &d1, Double_t &d2) override
Calculate determinant det = d1*TMathPower(2.,d2).
static Bool_t InvertLU(TMatrixD &a, Double_t tol, Double_t *det=nullptr)
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
Bool_t fIsOwner
!default kTRUE, when Use array kFALSE
virtual TMatrixTBase< Element > & UnitMatrix()
Make a unit matrix (matrix need not be a square one).
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.
Element SetTol(Element tol)
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.
TMatrixTBase< Element > & ResizeTo(Int_t nrows, Int_t ncols, Int_t=-1) override
Set size of the matrix to nrows x ncols New dynamic elements are created, the overlapping part of the...
const Int_t * GetColIndexArray() const override
TMatrixTSym< Element > & operator+=(Element val)
Add val to every element of the matrix.
virtual TMatrixTSym< Element > & RandomizePD(Element alpha, Element beta, Double_t &seed)
randomize matrix element values but keep matrix symmetric positive definite
TMatrixTBase< Element > & Randomize(Element alpha, Element beta, Double_t &seed) override
randomize matrix element values but keep matrix symmetric
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 subtraction. Replace this matrix with C such that C = A - B.
void TMult(const TMatrixT< Element > &a)
Replace this matrix with C such that C = A' * A.
const Int_t * GetRowIndexArray() const override
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...
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. Replace this matrix with C such that C = A + B.
Element fDataStack[TMatrixTBase< Element >::kSizeMax]
! data container
TMatrixTSym< Element > & InvertFast(Double_t *det=nullptr)
Invert the matrix and calculate its determinant.
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...
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 > & SetSub(Int_t row_lwb, const TMatrixTBase< Element > &source)
Insert matrix source starting at [row_lwb][row_lwb], thereby overwriting the part [row_lwb....
TMatrixTBase< Element > & SetMatrixArray(const Element *data, Option_t *option="") override
Copy array data to matrix .
void Clear(Option_t *="") override
TMatrixTBase< Element > & Shift(Int_t row_shift, Int_t col_shift) override
Shift the row index by adding row_shift and the column index by adding col_shift, respectively.
TMatrixTBase< Element > & Apply(const TElementActionT< Element > &action) override
Apply action to each matrix element.
Double_t Determinant() const override
TMatrixTSym< Element > & Invert(Double_t *det=nullptr)
Invert the matrix and calculate its determinant Notice that the LU decomposition is used instead of B...
const Element * GetMatrixArray() const override
void Streamer(TBuffer &) override
Stream an object of class TMatrixTSym.
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]).
const Element * GetMatrixArray() const override
void TMult(const TMatrixT< Element > &a, const TMatrixT< Element > &b)
Replace this matrix with C such that C = A' * B.
TObject & operator=(const TObject &rhs) noexcept
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] .
Short_t Max(Short_t a, Short_t b)
Returns the largest of a and b.
LongDouble_t Power(LongDouble_t x, LongDouble_t y)
Returns x raised to the power y.
Short_t Min(Short_t a, Short_t b)
Returns the smallest of a and b.
void AMultB(const Element *const ap, Int_t na, Int_t ncolsa, const Element *const bp, Int_t nb, Int_t ncolsb, Element *cp)
Elementary routine to calculate matrix multiplication A*B.
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 .
Bool_t Inv6x6(TMatrixTSym< Element > &m, Double_t *determ)
Bool_t Inv3x3(TMatrixTSym< Element > &m, Double_t *determ)
Bool_t Inv4x4(TMatrixTSym< Element > &m, Double_t *determ)
Bool_t Inv2x2(TMatrixTSym< Element > &m, Double_t *determ)
Bool_t Inv5x5(TMatrixTSym< Element > &m, Double_t *determ)