52template<
class Element>
66template<
class Element>
69 if (
size == 0)
return nullptr;
71 if (
size <= kSizeMax )
74 Element *heap =
new Element[
size];
83template<
class Element>
87 Error(
"Add(TVectorT<Element> &)",
"vector's not compatible");
91 const Element *sp =
v.GetMatrixArray();
92 Element *tp = this->GetMatrixArray();
93 const Element *
const tp_last = tp+fNrows;
101template<
class Element>
106 Error(
"Add(TVectorT<Element> &)",
"vectors not compatible");
111 const Element *sv1 =
v1.GetMatrixArray();
112 const Element *sv2 =
v2.GetMatrixArray();
113 Element *tp = this->GetMatrixArray();
114 const Element *
const tp_last = tp+fNrows;
116 *tp++ = *sv1++ + *sv2++;
123template<
class Element>
127 if (copySize == 0 || oldp == newp)
return 0;
129 if ( newSize <= kSizeMax && oldSize <= kSizeMax ) {
132 for (
Int_t i = copySize-1; i >= 0; i--)
135 for (
Int_t i = 0; i < copySize; i++)
140 memcpy(newp,oldp,copySize*
sizeof(Element));
150template<
class Element>
160 Error(
"Allocate",
"nrows=%d",nrows);
168 fElements = New_m(fNrows);
170 memset(fElements,0,fNrows*
sizeof(Element));
176template<
class Element>
185template<
class Element>
188 Allocate(upb-lwb+1,lwb,1);
194template<
class Element>
198 SetElements(elements);
204template<
class Element>
207 Allocate(upb-lwb+1,lwb);
208 SetElements(elements);
214template<
class Element>
225template<
class Element>
237template<
class Element>
249template<
class Element>
264template<
class Element>
268 Error(
"TVectorT(Int_t, Int_t, ...)",
"upb(%d) < lwb(%d)",upb,lwb);
272 Allocate(upb-lwb+1,lwb);
279 for (
Int_t i = lwb+1; i <= upb; i++)
280 (*
this)(i) = (Element)va_arg(args,
Double_t);
282 if (strcmp((
char *)va_arg(args,
char *),
"END"))
283 Error(
"TVectorT(Int_t, Int_t, ...)",
"argument list must be terminated by \"END\"");
293template<
class Element>
298 Error(
"ResizeTo(lwb,upb)",
"Not owner of data array,cannot resize");
302 const Int_t new_nrows = upb-lwb+1;
306 if (fNrows == new_nrows && fRowLwb == lwb)
308 else if (new_nrows == 0) {
313 Element *elements_old = GetMatrixArray();
314 const Int_t nrows_old = fNrows;
315 const Int_t rowLwb_old = fRowLwb;
317 Allocate(new_nrows,lwb);
319 if (fNrows > kSizeMax || nrows_old > kSizeMax)
320 memset(GetMatrixArray(),0,fNrows*
sizeof(Element));
321 else if (fNrows > nrows_old)
322 memset(GetMatrixArray()+nrows_old,0,(fNrows-nrows_old)*
sizeof(Element));
326 const Int_t rowUpb_copy =
TMath::Min(fRowLwb+fNrows-1,rowLwb_old+nrows_old-1);
327 const Int_t nrows_copy = rowUpb_copy-rowLwb_copy+1;
329 const Int_t nelems_new = fNrows;
330 Element *elements_new = GetMatrixArray();
331 if (nrows_copy > 0) {
332 const Int_t rowOldOff = rowLwb_copy-rowLwb_old;
333 const Int_t rowNewOff = rowLwb_copy-fRowLwb;
334 Memcpy_m(elements_new+rowNewOff,elements_old+rowOldOff,nrows_copy,nelems_new,nrows_old);
337 Delete_m(nrows_old,elements_old);
339 Allocate(upb-lwb+1,lwb,1);
348template<
class Element>
352 Error(
"Use",
"upb(%d) < lwb(%d)",upb,lwb);
372template<
class Element>
377 if (row_lwb < fRowLwb || row_lwb > fRowLwb+fNrows-1) {
378 Error(
"GetSub",
"row_lwb out of bounds");
381 if (row_upb < fRowLwb || row_upb > fRowLwb+fNrows-1) {
382 Error(
"GetSub",
"row_upb out of bounds");
385 if (row_upb < row_lwb) {
386 Error(
"GetSub",
"row_upb < row_lwb");
399 row_upb_sub = row_upb-row_lwb;
401 row_lwb_sub = row_lwb;
402 row_upb_sub = row_upb;
405 target.ResizeTo(row_lwb_sub,row_upb_sub);
406 const Int_t nrows_sub = row_upb_sub-row_lwb_sub+1;
408 const Element *ap = this->GetMatrixArray()+(row_lwb-fRowLwb);
409 Element *bp =
target.GetMatrixArray();
411 for (
Int_t irow = 0; irow < nrows_sub; irow++)
421template<
class Element>
428 if (row_lwb < fRowLwb && row_lwb > fRowLwb+fNrows-1) {
429 Error(
"SetSub",
"row_lwb outof bounds");
432 if (row_lwb+source.
GetNrows() > fRowLwb+fNrows) {
433 Error(
"SetSub",
"source vector too large");
441 Element *ap = this->GetMatrixArray()+(row_lwb-fRowLwb);
443 for (
Int_t irow = 0; irow < nRows_source; irow++)
452template<
class Element>
456 memset(this->GetMatrixArray(),0,fNrows*
sizeof(Element));
463template<
class Element>
468 Element *ep = this->GetMatrixArray();
469 const Element *
const fp = ep+fNrows;
481template<
class Element>
486 Element *ep = this->GetMatrixArray();
487 const Element *
const fp = ep+fNrows;
499template<
class Element>
504 Element *ep = this->GetMatrixArray();
505 const Element *
const fp = ep+fNrows;
511 Error(
"Sqrt()",
"v(%ld) = %g < 0",
Long_t(ep-this->GetMatrixArray()),(
float)*ep);
521template<
class Element>
526 Element *ep = this->GetMatrixArray();
527 const Element *
const fp = ep+fNrows;
533 Error(
"Invert()",
"v(%ld) = %g",
Long_t(ep-this->GetMatrixArray()),(
float)*ep);
543template<
class Element>
547 Error(
"SelectNonZeros(const TVectorT<Element> &",
"vector's not compatible");
552 Element *ep = this->GetMatrixArray();
553 const Element *
const fp = ep+fNrows;
566template<
class Element>
572 const Element *ep = this->GetMatrixArray();
573 const Element *
const fp = ep+fNrows;
583template<
class Element>
589 const Element *ep = this->GetMatrixArray();
590 const Element *
const fp = ep+fNrows;
592 norm += (*ep) * (*ep);
602template<
class Element>
608 const Element *ep = this->GetMatrixArray();
609 const Element *
const fp = ep+fNrows;
619template<
class Element>
624 Int_t nr_nonzeros = 0;
625 const Element *ep = this->GetMatrixArray();
626 const Element *
const fp = ep+fNrows;
628 if (*ep++) nr_nonzeros++;
636template<
class Element>
642 const Element *ep = this->GetMatrixArray();
643 const Element *
const fp = ep+fNrows;
653template<
class Element>
659 return fElements[
index];
665template<
class Element>
671 return fElements[
index];
679template<
class Element>
683 Error(
"operator=(const TVectorT<Element> &)",
"vectors not compatible");
697template<
class Element>
706 Error(
"operator=(const TMatrixTRow_const &)",
"vector and row not compatible");
712 const Element *rp = mr.
GetPtr();
713 Element *ep = this->GetMatrixArray();
714 const Element *
const fp = ep+fNrows;
728template<
class Element>
737 Error(
"operator=(const TMatrixTColumn_const &)",
"vector and column not compatible");
743 const Element *cp = mc.
GetPtr();
744 Element *ep = this->GetMatrixArray();
745 const Element *
const fp = ep+fNrows;
759template<
class Element>
768 Error(
"operator=(const TMatrixTDiag_const &)",
"vector and matrix-diagonal not compatible");
774 const Element *dp = md.
GetPtr();
775 Element *ep = this->GetMatrixArray();
776 const Element *
const fp = ep+fNrows;
791template<
class Element>
800 Error(
"operator=(const TMatrixTSparseRow_const &)",
"vector and row not compatible");
806 const Element *
const prData = mr.
GetDataPtr();
808 Element *
const pvData = this->GetMatrixArray();
810 memset(pvData,0,fNrows*
sizeof(Element));
813 pvData[icol] = prData[
index];
822template<
class Element>
831 Error(
"operator=(const TMatrixTSparseDiag_const &)",
"vector and matrix-diagonal not compatible");
836 Element *
const pvData = this->GetMatrixArray();
837 for (
Int_t idiag = 0; idiag < fNrows; idiag++)
838 pvData[idiag] = md(idiag);
846template<
class Element>
851 Element *ep = this->GetMatrixArray();
852 const Element *
const fp = ep+fNrows;
862template<
class Element>
867 Element *ep = this->GetMatrixArray();
868 const Element *
const fp = ep+fNrows;
878template<
class Element>
883 Element *ep = this->GetMatrixArray();
884 const Element *
const fp = ep+fNrows;
894template<
class Element>
899 Element *ep = this->GetMatrixArray();
900 const Element *
const fp = ep+fNrows;
910template<
class Element>
914 Error(
"operator+=(const TVectorT<Element> &)",
"vector's not compatible");
919 Element *tp = this->GetMatrixArray();
920 const Element *
const tp_last = tp+fNrows;
930template<
class Element>
934 Error(
"operator-=(const TVectorT<Element> &)",
"vector's not compatible");
939 Element *tp = this->GetMatrixArray();
940 const Element *
const tp_last = tp+fNrows;
951template<
class Element>
957 if (
a.GetNcols() != fNrows ||
a.GetColLwb() != fRowLwb) {
958 Error(
"operator*=(const TMatrixT &)",
"vector and matrix incompatible");
963 const Bool_t doResize = (fNrows !=
a.GetNrows() || fRowLwb !=
a.GetRowLwb());
964 if (doResize && !fIsOwner) {
965 Error(
"operator*=(const TMatrixT &)",
"vector has to be resized but not owner");
969 Element work[kWorkMax];
971 Element *elements_old = work;
972 const Int_t nrows_old = fNrows;
973 if (nrows_old > kWorkMax) {
975 elements_old =
new Element[nrows_old];
977 memcpy(elements_old,fElements,nrows_old*
sizeof(Element));
980 const Int_t rowlwb_new =
a.GetRowLwb();
981 const Int_t nrows_new =
a.GetNrows();
982 ResizeTo(rowlwb_new,rowlwb_new+nrows_new-1);
984 memset(fElements,0,fNrows*
sizeof(Element));
986 const Element *mp =
a.GetMatrixArray();
987 Element *tp = this->GetMatrixArray();
989 if (
typeid(Element) ==
typeid(
Double_t))
990 cblas_dgemv(CblasRowMajor,CblasNoTrans,
a.GetNrows(),
a.GetNcols(),1.0,mp,
991 a.GetNcols(),elements_old,1,0.0,tp,1);
992 else if (
typeid(Element) !=
typeid(
Float_t))
993 cblas_sgemv(CblasRowMajor,CblasNoTrans,
a.GetNrows(),
a.GetNcols(),1.0,mp,
994 a.GetNcols(),elements_old,1,0.0,tp,1);
996 Error(
"operator*=",
"type %s not implemented in BLAS library",
typeid(Element));
998 const Element *
const tp_last = tp+fNrows;
999 while (tp < tp_last) {
1001 for (
const Element *sp = elements_old; sp < elements_old+nrows_old; )
1002 sum += *sp++ * *mp++;
1005 R__ASSERT(mp ==
a.GetMatrixArray()+
a.GetNoElements());
1009 delete [] elements_old;
1018template<
class Element>
1024 if (
a.GetNcols() != fNrows ||
a.GetColLwb() != fRowLwb) {
1025 Error(
"operator*=(const TMatrixTSparse &)",
"vector and matrix incompatible");
1030 const Bool_t doResize = (fNrows !=
a.GetNrows() || fRowLwb !=
a.GetRowLwb());
1031 if (doResize && !fIsOwner) {
1032 Error(
"operator*=(const TMatrixTSparse &)",
"vector has to be resized but not owner");
1036 Element work[kWorkMax];
1038 Element *elements_old = work;
1039 const Int_t nrows_old = fNrows;
1040 if (nrows_old > kWorkMax) {
1041 isAllocated =
kTRUE;
1042 elements_old =
new Element[nrows_old];
1044 memcpy(elements_old,fElements,nrows_old*
sizeof(Element));
1047 const Int_t rowlwb_new =
a.GetRowLwb();
1048 const Int_t nrows_new =
a.GetNrows();
1049 ResizeTo(rowlwb_new,rowlwb_new+nrows_new-1);
1051 memset(fElements,0,fNrows*
sizeof(Element));
1053 const Int_t *
const pRowIndex =
a.GetRowIndexArray();
1054 const Int_t *
const pColIndex =
a.GetColIndexArray();
1055 const Element *
const mp =
a.GetMatrixArray();
1057 const Element *
const sp = elements_old;
1058 Element * tp = this->GetMatrixArray();
1060 for (
Int_t irow = 0; irow < fNrows; irow++) {
1061 const Int_t sIndex = pRowIndex[irow];
1062 const Int_t eIndex = pRowIndex[irow+1];
1072 delete [] elements_old;
1081template<
class Element>
1087 if (
a.GetNcols() != fNrows ||
a.GetColLwb() != fRowLwb) {
1088 Error(
"operator*=(const TMatrixTSym &)",
"vector and matrix incompatible");
1093 Element work[kWorkMax];
1095 Element *elements_old = work;
1096 const Int_t nrows_old = fNrows;
1097 if (nrows_old > kWorkMax) {
1098 isAllocated =
kTRUE;
1099 elements_old =
new Element[nrows_old];
1101 memcpy(elements_old,fElements,nrows_old*
sizeof(Element));
1102 memset(fElements,0,fNrows*
sizeof(Element));
1104 const Element *mp =
a.GetMatrixArray();
1105 Element *tp = this->GetMatrixArray();
1107 if (
typeid(Element) ==
typeid(
Double_t))
1108 cblas_dsymv(CblasRowMajor,CblasUpper,fNrows,1.0,mp,
1109 fNrows,elements_old,1,0.0,tp,1);
1110 else if (
typeid(Element) !=
typeid(
Float_t))
1111 cblas_ssymv(CblasRowMajor,CblasUpper,fNrows,1.0,mp,
1112 fNrows,elements_old,1,0.0,tp,1);
1114 Error(
"operator*=",
"type %s not implemented in BLAS library",
typeid(Element));
1116 const Element *
const tp_last = tp+fNrows;
1117 while (tp < tp_last) {
1119 for (
const Element *sp = elements_old; sp < elements_old+nrows_old; )
1120 sum += *sp++ * *mp++;
1123 R__ASSERT(mp ==
a.GetMatrixArray()+
a.GetNoElements());
1127 delete [] elements_old;
1135template<
class Element>
1140 const Element *ep = this->GetMatrixArray();
1141 const Element *
const fp = ep+fNrows;
1143 if (!(*ep++ == val))
1152template<
class Element>
1157 const Element *ep = this->GetMatrixArray();
1158 const Element *
const fp = ep+fNrows;
1160 if (!(*ep++ != val))
1169template<
class Element>
1174 const Element *ep = this->GetMatrixArray();
1175 const Element *
const fp = ep+fNrows;
1186template<
class Element>
1191 const Element *ep = this->GetMatrixArray();
1192 const Element *
const fp = ep+fNrows;
1194 if (!(*ep++ <= val))
1203template<
class Element>
1208 const Element *ep = this->GetMatrixArray();
1209 const Element *
const fp = ep+fNrows;
1220template<
class Element>
1225 const Element *ep = this->GetMatrixArray();
1226 const Element *
const fp = ep+fNrows;
1228 if (!(*ep++ >= val))
1237template<
class Element>
1241 Error(
"MatchesNonZeroPattern(const TVectorT&)",
"vector's not compatible");
1246 const Element *ep = this->GetMatrixArray();
1247 const Element *
const fp = ep+fNrows;
1249 if (*sp == 0.0 && *ep != 0.0)
1260template<
class Element>
1264 Error(
"SomePositive(const TVectorT&)",
"vector's not compatible");
1269 const Element *ep = this->GetMatrixArray();
1270 const Element *
const fp = ep+fNrows;
1272 if (*sp != 0.0 && *ep <= 0.0)
1283template<
class Element>
1287 Error(
"AddSomeConstant(Element,const TVectorT&)(const TVectorT&)",
"vector's not compatible");
1290 Element *ep = this->GetMatrixArray();
1291 const Element *
const fp = ep+fNrows;
1304template<
class Element>
1309 const Element scale = beta-alpha;
1310 const Element shift = alpha/scale;
1312 Element * ep = GetMatrixArray();
1313 const Element *
const fp = ep+fNrows;
1315 *ep++ = scale*(
Drand(seed)+shift);
1321template<
class Element>
1325 for (Element *ep = fElements; ep < fElements+fNrows; ep++)
1334template<
class Element>
1339 Element *ep = fElements;
1340 for (action.
fI = fRowLwb; action.
fI < fRowLwb+fNrows; action.
fI++)
1352template<
class Element>
1355 gROOT->ProcessLine(
Form(
"THistPainter::PaintSpecialObjects((TObject*)0x%zx,\"%s\");",
1362template<
class Element>
1366 Error(
"Print",
"Vector is invalid");
1370 printf(
"\nVector (%d) %s is as follows",fNrows,flag);
1372 printf(
"\n\n | %6d |", 1);
1373 printf(
"\n%s\n",
"------------------");
1374 for (
Int_t i = 0; i < fNrows; i++) {
1375 printf(
"%4d |",i+fRowLwb);
1377 printf(
"%g \n",(*
this)(i+fRowLwb));
1385template<
class Element>
1389 return (memcmp(
v1.GetMatrixArray(),
v2.GetMatrixArray(),
v1.GetNrows()*
sizeof(Element)) == 0);
1395template<
class Element>
1400 Error(
"operator*(const TVectorT<Element> &,const TVectorT<Element> &)",
"vector's are incompatible");
1411template<
class Element>
1422template<
class Element>
1433template<
class Element>
1444template<
class Element>
1455template<
class Element>
1466template<
class Element>
1477template<
class Element>
1480 const Element *v1p =
v1.GetMatrixArray();
1481 const Element *v2p =
v2.GetMatrixArray();
1483 const Element *
const fv1p = v1p+
v1.GetNrows();
1485 sum += *v1p++ * *v2p++;
1493template <
class Element1,
class Element2>
1509template <
class Element1,
class Element2,
class Element3>
1513 target.ResizeTo(
v1.GetLwb(),
v1.GetUpb(),
v2.GetLwb(),
v2.GetUpb());
1515 Element1 * mp =
target.GetMatrixArray();
1516 const Element1 *
const m_last = mp +
target.GetNoElements();
1518 const Element2 * v1p =
v1.GetMatrixArray();
1519 const Element2 *
const v1_last = v1p +
v1.GetNrows();
1521 const Element3 *
const v20 =
v2.GetMatrixArray();
1522 const Element3 * v2p = v20;
1523 const Element3 *
const v2_last = v2p +
v2.GetNrows();
1525 while (v1p < v1_last) {
1527 while (v2p < v2_last) {
1528 *mp++ = *v1p * *v2p++ ;
1533 R__ASSERT(v1p == v1_last && mp == m_last && v2p == v2_last);
1541template <
class Element1,
class Element2,
class Element3>
1547 ::Error(
"Mult",
"Vector v1 and matrix m incompatible");
1551 ::Error(
"Mult",
"Matrix m and vector v2 incompatible");
1556 const Element1 * v1p =
v1.GetMatrixArray();
1557 const Element1 *
const v1_last = v1p +
v1.GetNrows();
1559 const Element2 * mp =
m.GetMatrixArray();
1560 const Element2 *
const m_last = mp +
m.GetNoElements();
1562 const Element3 *
const v20 =
v2.GetMatrixArray();
1563 const Element3 * v2p = v20;
1564 const Element3 *
const v2_last = v2p +
v2.GetNrows();
1569 while (v1p < v1_last) {
1571 while (v2p < v2_last) {
1572 dot += *mp++ * *v2p++;
1574 sum += *v1p++ * dot;
1578 R__ASSERT(v1p == v1_last && mp == m_last && v2p == v2_last);
1586template<
class Element>
1590 Error(
"Add(TVectorT<Element> &,Element,const TVectorT<Element> &)",
"vector's are incompatible");
1595 Element * tp =
target.GetMatrixArray();
1596 const Element *
const ftp = tp+
target.GetNrows();
1597 if (scalar == 1.0 ) {
1600 }
else if (scalar == -1.0) {
1605 *tp++ += scalar * *sp++;
1615template<
class Element>
1622 if (
a.GetNrows() !=
target.GetNrows() ||
a.GetRowLwb() !=
target.GetLwb()) {
1623 Error(
"Add(TVectorT &,const TMatrixT &,const TVectorT &)",
"target vector and matrix are incompatible");
1628 if (
a.GetNcols() != source.
GetNrows() ||
a.GetColLwb() != source.
GetLwb()) {
1629 Error(
"Add(TVectorT &,const TMatrixT &,const TVectorT &)",
"source vector and matrix are incompatible");
1635 const Element * mp =
a.GetMatrixArray();
1636 Element * tp =
target.GetMatrixArray();
1638 if (
typeid(Element) ==
typeid(
Double_t))
1639 cblas_dsymv(CblasRowMajor,CblasUpper,fNrows,scalar,mp,
1640 fNrows,sp,1,0.0,tp,1);
1641 else if (
typeid(Element) !=
typeid(
Float_t))
1642 cblas_ssymv(CblasRowMajor,CblasUpper,fNrows,scalar,mp,
1643 fNrows,sp,1,0.0,tp,1);
1645 Error(
"operator*=",
"type %s not implemented in BLAS library",
typeid(Element));
1647 const Element *
const sp_last = sp+source.
GetNrows();
1648 const Element *
const tp_last = tp+
target.GetNrows();
1649 if (scalar == 1.0) {
1650 while (tp < tp_last) {
1651 const Element *sp1 = sp;
1653 while (sp1 < sp_last)
1654 sum += *sp1++ * *mp++;
1657 }
else if (scalar == 0.0) {
1658 while (tp < tp_last) {
1659 const Element *sp1 = sp;
1661 while (sp1 < sp_last)
1662 sum += *sp1++ * *mp++;
1665 }
else if (scalar == -1.0) {
1666 while (tp < tp_last) {
1667 const Element *sp1 = sp;
1669 while (sp1 < sp_last)
1670 sum += *sp1++ * *mp++;
1674 while (tp < tp_last) {
1675 const Element *sp1 = sp;
1677 while (sp1 < sp_last)
1678 sum += *sp1++ * *mp++;
1679 *tp++ += scalar *
sum;
1693template<
class Element>
1701 if (
a.GetNrows() !=
target.GetNrows() ||
a.GetRowLwb() !=
target.GetLwb()) {
1702 Error(
"Add(TVectorT &,const TMatrixT &,const TVectorT &)",
"target vector and matrix are incompatible");
1708 const Element * mp =
a.GetMatrixArray();
1709 Element * tp =
target.GetMatrixArray();
1711 if (
typeid(Element) ==
typeid(
Double_t))
1712 cblas_dsymv(CblasRowMajor,CblasUpper,fNrows,1.0,mp,
1713 fNrows,sp,1,0.0,tp,1);
1714 else if (
typeid(Element) !=
typeid(
Float_t))
1715 cblas_ssymv(CblasRowMajor,CblasUpper,fNrows,1.0,mp,
1716 fNrows,sp,1,0.0,tp,1);
1718 Error(
"operator*=",
"type %s not implemented in BLAS library",
typeid(Element));
1720 const Element *
const sp_last = sp+source.
GetNrows();
1721 const Element *
const tp_last = tp+
target.GetNrows();
1722 if (scalar == 1.0) {
1723 while (tp < tp_last) {
1724 const Element *sp1 = sp;
1726 while (sp1 < sp_last)
1727 sum += *sp1++ * *mp++;
1730 }
else if (scalar == 0.0) {
1731 while (tp < tp_last) {
1732 const Element *sp1 = sp;
1734 while (sp1 < sp_last)
1735 sum += *sp1++ * *mp++;
1738 }
else if (scalar == -1.0) {
1739 while (tp < tp_last) {
1740 const Element *sp1 = sp;
1742 while (sp1 < sp_last)
1743 sum += *sp1++ * *mp++;
1747 while (tp < tp_last) {
1748 const Element *sp1 = sp;
1750 while (sp1 < sp_last)
1751 sum += *sp1++ * *mp++;
1752 *tp++ += scalar *
sum;
1755 R__ASSERT(mp ==
a.GetMatrixArray()+
a.GetNoElements());
1765template<
class Element>
1772 if (
a.GetNrows() !=
target.GetNrows() ||
a.GetRowLwb() !=
target.GetLwb()) {
1773 Error(
"Add(TVectorT &,const TMatrixT &,const TVectorT &)",
"target vector and matrix are incompatible");
1778 if (
a.GetNcols() != source.
GetNrows() ||
a.GetColLwb() != source.
GetLwb()) {
1779 Error(
"Add(TVectorT &,const TMatrixT &,const TVectorT &)",
"source vector and matrix are incompatible");
1784 const Int_t *
const pRowIndex =
a.GetRowIndexArray();
1785 const Int_t *
const pColIndex =
a.GetColIndexArray();
1786 const Element *
const mp =
a.GetMatrixArray();
1789 Element * tp =
target.GetMatrixArray();
1791 if (scalar == 1.0) {
1792 for (
Int_t irow = 0; irow <
a.GetNrows(); irow++) {
1793 const Int_t sIndex = pRowIndex[irow];
1794 const Int_t eIndex = pRowIndex[irow+1];
1802 }
else if (scalar == 0.0) {
1803 for (
Int_t irow = 0; irow <
a.GetNrows(); irow++) {
1804 const Int_t sIndex = pRowIndex[irow];
1805 const Int_t eIndex = pRowIndex[irow+1];
1813 }
else if (scalar == -1.0) {
1814 for (
Int_t irow = 0; irow <
a.GetNrows(); irow++) {
1815 const Int_t sIndex = pRowIndex[irow];
1816 const Int_t eIndex = pRowIndex[irow+1];
1825 for (
Int_t irow = 0; irow <
a.GetNrows(); irow++) {
1826 const Int_t sIndex = pRowIndex[irow];
1827 const Int_t eIndex = pRowIndex[irow+1];
1833 tp[irow] += scalar *
sum;
1843template<
class Element>
1848 Error(
"AddElemMult(TVectorT<Element> &,Element,const TVectorT<Element> &,const TVectorT<Element> &)",
1849 "vector's are incompatible");
1855 Element * tp =
target.GetMatrixArray();
1856 const Element *
const ftp = tp+
target.GetNrows();
1858 if (scalar == 1.0 ) {
1860 *tp++ += *sp1++ * *sp2++;
1861 }
else if (scalar == -1.0) {
1863 *tp++ -= *sp1++ * *sp2++;
1866 *tp++ += scalar * *sp1++ * *sp2++;
1876template<
class Element>
1882 Error(
"AddElemMult(TVectorT<Element> &,Element,const TVectorT<Element> &,const TVectorT<Element> &,onst TVectorT<Element> &)",
1883 "vector's are incompatible");
1890 Element * tp =
target.GetMatrixArray();
1891 const Element *
const ftp = tp+
target.GetNrows();
1893 if (scalar == 1.0 ) {
1894 while ( tp < ftp ) {
1895 if (*mp) *tp += *sp1 * *sp2;
1896 mp++; tp++; sp1++; sp2++;
1898 }
else if (scalar == -1.0) {
1899 while ( tp < ftp ) {
1900 if (*mp) *tp -= *sp1 * *sp2;
1901 mp++; tp++; sp1++; sp2++;
1904 while ( tp < ftp ) {
1905 if (*mp) *tp += scalar * *sp1 * *sp2;
1906 mp++; tp++; sp1++; sp2++;
1916template<
class Element>
1921 Error(
"AddElemDiv(TVectorT<Element> &,Element,const TVectorT<Element> &,const TVectorT<Element> &)",
1922 "vector's are incompatible");
1928 Element * tp =
target.GetMatrixArray();
1929 const Element *
const ftp = tp+
target.GetNrows();
1931 if (scalar == 1.0 ) {
1932 while ( tp < ftp ) {
1937 Error(
"AddElemDiv",
"source2 (%d) is zero",irow);
1941 }
else if (scalar == -1.0) {
1942 while ( tp < ftp ) {
1947 Error(
"AddElemDiv",
"source2 (%d) is zero",irow);
1952 while ( tp < ftp ) {
1954 *tp += scalar * *sp1 / *sp2;
1957 Error(
"AddElemDiv",
"source2 (%d) is zero",irow);
1970template<
class Element>
1976 Error(
"AddElemDiv(TVectorT<Element> &,Element,const TVectorT<Element> &,const TVectorT<Element> &,onst TVectorT<Element> &)",
1977 "vector's are incompatible");
1984 Element * tp =
target.GetMatrixArray();
1985 const Element *
const ftp = tp+
target.GetNrows();
1987 if (scalar == 1.0 ) {
1988 while ( tp < ftp ) {
1994 Error(
"AddElemDiv",
"source2 (%d) is zero",irow);
1997 mp++; tp++; sp1++; sp2++;
1999 }
else if (scalar == -1.0) {
2000 while ( tp < ftp ) {
2006 Error(
"AddElemDiv",
"source2 (%d) is zero",irow);
2009 mp++; tp++; sp1++; sp2++;
2012 while ( tp < ftp ) {
2015 *tp += scalar * *sp1 / *sp2;
2018 Error(
"AddElemDiv",
"source2 (%d) is zero",irow);
2021 mp++; tp++; sp1++; sp2++;
2031template<
class Element>
2035 Error(
"ElementMult(TVectorT<Element> &,const TVectorT<Element> &)",
"vector's are incompatible");
2040 Element * tp =
target.GetMatrixArray();
2041 const Element *
const ftp = tp+
target.GetNrows();
2051template<
class Element>
2055 Error(
"ElementMult(TVectorT<Element> &,const TVectorT<Element> &,const TVectorT<Element> &)",
"vector's are incompatible");
2061 Element * tp =
target.GetMatrixArray();
2062 const Element *
const ftp = tp+
target.GetNrows();
2063 while ( tp < ftp ) {
2064 if (*mp) *tp *= *sp;
2074template<
class Element>
2078 Error(
"ElementDiv(TVectorT<Element> &,const TVectorT<Element> &)",
"vector's are incompatible");
2083 Element * tp =
target.GetMatrixArray();
2084 const Element *
const ftp = tp+
target.GetNrows();
2085 while ( tp < ftp ) {
2090 Error(
"ElementDiv",
"source (%d) is zero",irow);
2100template<
class Element>
2104 Error(
"ElementDiv(TVectorT<Element> &,const TVectorT<Element> &,const TVectorT<Element> &)",
"vector's are incompatible");
2110 Element * tp =
target.GetMatrixArray();
2111 const Element *
const ftp = tp+
target.GetNrows();
2112 while ( tp < ftp ) {
2118 Error(
"ElementDiv",
"source (%d) is zero",irow);
2130template<
class Element1,
class Element2>
2133 if (!
v1.IsValid()) {
2135 ::Error(
"AreCompatible",
"vector 1 not valid");
2138 if (!
v2.IsValid()) {
2140 ::Error(
"AreCompatible",
"vector 2 not valid");
2144 if (
v1.GetNrows() !=
v2.GetNrows() ||
v1.GetLwb() !=
v2.GetLwb()) {
2146 ::Error(
"AreCompatible",
"matrices 1 and 2 not compatible");
2156template<
class Element1,
class Element2>
2161 ::Error(
"AreCompatible",
"Matrix not valid");
2166 ::Error(
"AreCompatible",
"vector not valid");
2170 if (
m.GetNcols() !=
v.GetNrows() ) {
2172 ::Error(
"AreCompatible",
"matrix and vector not compatible");
2182template<
class Element1,
class Element2>
2187 ::Error(
"AreCompatible",
"Matrix not valid");
2192 ::Error(
"AreCompatible",
"vector not valid");
2196 if (
v.GetNrows() !=
m.GetNrows() ) {
2198 ::Error(
"AreCompatible",
"vector and matrix not compatible");
2208template<
class Element>
2212 Error(
"Compare(const TVectorT<Element> &,const TVectorT<Element> &)",
"vectors are incompatible");
2216 printf(
"\n\nComparison of two TVectorTs:\n");
2222 Element difmax = -1;
2223 const Element *mp1 =
v1.GetMatrixArray();
2224 const Element *mp2 =
v2.GetMatrixArray();
2226 for (
Int_t i = 0; i <
v1.GetNrows(); i++) {
2227 const Element mv1 = *mp1++;
2228 const Element mv2 = *mp2++;
2231 if (diff > difmax) {
2240 imax +=
v1.GetLwb();
2241 printf(
"\nMaximal discrepancy \t\t%g",difmax);
2242 printf(
"\n occurred at the point\t\t(%d)",imax);
2243 const Element mv1 =
v1(imax);
2244 const Element mv2 =
v2(imax);
2245 printf(
"\n Vector 1 element is \t\t%g",mv1);
2246 printf(
"\n Vector 2 element is \t\t%g",mv2);
2247 printf(
"\n Absolute error v2[i]-v1[i]\t\t%g",mv2-mv1);
2248 printf(
"\n Relative error\t\t\t\t%g\n",
2251 printf(
"\n||Vector 1|| \t\t\t%g",norm1);
2252 printf(
"\n||Vector 2|| \t\t\t%g",norm2);
2253 printf(
"\n||Vector1-Vector2||\t\t\t\t%g",ndiff);
2254 printf(
"\n||Vector1-Vector2||/sqrt(||Vector1|| ||Vector2||)\t%g\n\n",
2261template<
class Element>
2263 Int_t verbose,Element maxDevAllow)
2266 Element maxDevObs = 0;
2269 maxDevAllow = std::numeric_limits<Element>::epsilon();
2271 for (
Int_t i =
v.GetLwb(); i <=
v.GetUpb(); i++) {
2273 if (dev > maxDevObs) {
2283 printf(
"Largest dev for (%d); dev = |%g - %g| = %g\n",imax,
v(imax),val,maxDevObs);
2284 if (maxDevObs > maxDevAllow)
2285 Error(
"VerifyVectorValue",
"Deviation > %g\n",maxDevAllow);
2288 if (maxDevObs > maxDevAllow)
2296template<
class Element>
2298 Int_t verbose, Element maxDevAllow)
2301 Element maxDevObs = 0;
2307 maxDevAllow = std::numeric_limits<Element>::epsilon();
2309 for (
Int_t i =
v1.GetLwb(); i <=
v1.GetUpb(); i++) {
2311 if (dev > maxDevObs) {
2321 printf(
"Largest dev for (%d); dev = |%g - %g| = %g\n",imax,
v1(imax),
v2(imax),maxDevObs);
2322 if (maxDevObs > maxDevAllow)
2323 Error(
"VerifyVectorIdentity",
"Deviation > %g\n",maxDevAllow);
2326 if (maxDevObs > maxDevAllow) {
2335template<
class Element>
2350 if (fNrows > 0 && fNrows <= kSizeMax) {
2351 memcpy(fDataStack,fElements,fNrows*
sizeof(Element));
2352 delete [] fElements;
2353 fElements = fDataStack;
2354 }
else if (fNrows < 0)
2380template TMatrixF TMatrixTAutoloadOps::OuterProduct <Float_t,Float_t>
2382template TMatrixF &TMatrixTAutoloadOps::OuterProduct <Float_t,Float_t,Float_t>
2384template Float_t TMatrixTAutoloadOps::Mult <Float_t,Float_t,Float_t>
2432template TMatrixD TMatrixTAutoloadOps::OuterProduct <Double_t,Double_t>
2434template TMatrixD &TMatrixTAutoloadOps::OuterProduct <Double_t,Double_t,Double_t>
2436template Double_t TMatrixTAutoloadOps::Mult <Double_t,Double_t,Double_t>
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
#define templateClassImp(name)
void Error(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
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 Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t target
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t index
R__EXTERN Int_t gMatrixCheck
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
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 Int_t ReadArray(Bool_t *&b)=0
virtual Int_t CheckByteCount(UInt_t startpos, UInt_t bcnt, const TClass *clss)=0
virtual Int_t ReadClassBuffer(const TClass *cl, void *pointer, const TClass *onfile_class=nullptr)=0
virtual Int_t WriteClassBuffer(const TClass *cl, void *pointer)=0
virtual void Operation(Element &element) const =0
virtual void Operation(Element &element) const =0
Int_t GetNoElements() const
const TMatrixTBase< Element > * GetMatrix() const
const Element * GetPtr() const
const Element * GetPtr() const
const TMatrixTBase< Element > * GetMatrix() const
const Element * GetPtr() const
const TMatrixTBase< Element > * GetMatrix() const
const TMatrixTBase< Element > * GetMatrix() const
const Int_t * GetColPtr() const
const Element * GetDataPtr() const
const TMatrixTBase< Element > * GetMatrix() const
Mother of all ROOT objects.
TObject & operator=(const TObject &rhs)
TObject assignment operator.
virtual void Streamer(TBuffer &)
Stream an object of class TObject.
void ToUpper()
Change string to upper case.
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
TVectorT< Element > & Zero()
Set vector elements to zero.
Bool_t operator>=(Element val) const
Are all vector elements >= val?
Element * New_m(Int_t size)
default kTRUE, when Use array kFALSE
TVectorT< Element > & Apply(const TElementActionT< Element > &action)
Apply action to each element of the vector.
void Allocate(Int_t nrows, Int_t row_lwb=0, Int_t init=0)
Allocate new vector.
TVectorT< Element > & Sqr()
Square each element of the vector.
Element Min() const
return minimum vector element value
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 .
Element Norm1() const
Compute the 1-norm of the vector SUM{ |v[i]| }.
void Delete_m(Int_t size, Element *&)
Delete data pointer m, if it was assigned on the heap.
Element NormInf() const
Compute the infinity-norm of the vector MAX{ |v[i]| }.
Element Sum() const
Compute sum of elements.
void AddSomeConstant(Element val, const TVectorT< Element > &select)
Add to vector elements as selected through array select the value val.
Bool_t operator!=(Element val) const
Are all vector elements not equal to val?
Bool_t MatchesNonZeroPattern(const TVectorT< Element > &select)
Check if vector elements as selected through array select are non-zero.
void Streamer(TBuffer &) override
Stream an object of class TVectorT.
TVectorT< Element > & GetSub(Int_t row_lwb, Int_t row_upb, TVectorT< Element > &target, Option_t *option="S") const
Get subvector [row_lwb..row_upb]; The indexing range of the returned vector depends on the argument o...
TVectorT< Element > & Abs()
Take an absolute value of a vector, i.e. apply Abs() to each element.
Bool_t operator==(Element val) const
Are all vector elements equal to val?
Bool_t operator>(Element val) const
Are all vector elements > val?
TVectorT< Element > & ResizeTo(Int_t lwb, Int_t upb)
Resize the vector to [lwb:upb] .
TVectorT< Element > & operator=(const TVectorT< Element > &source)
Notice that this assignment does NOT change the ownership : if the storage space was adopted,...
TVectorT< Element > & SetSub(Int_t row_lwb, const TVectorT< Element > &source)
Insert vector source starting at [row_lwb], thereby overwriting the part [row_lwb....
void Randomize(Element alpha, Element beta, Double_t &seed)
randomize vector elements value
void Add(const TVectorT< Element > &v)
Add vector v to this vector.
TVectorT< Element > & operator+=(Element val)
Add val to every element of the vector.
TVectorT< Element > & Use(Int_t lwb, Int_t upb, Element *data)
Use the array data to fill the vector lwb..upb].
TVectorT< Element > & SelectNonZeros(const TVectorT< Element > &select)
Keep only element as selected through array select non-zero.
Element Max() const
return maximum vector element value
Bool_t operator<(Element val) const
Are all vector elements < val?
Bool_t operator<=(Element val) const
Are all vector elements <= val?
TVectorT< Element > & operator*=(Element val)
Multiply every element of the vector with val.
Bool_t SomePositive(const TVectorT< Element > &select)
Check if vector elements as selected through array select are all positive.
Int_t NonZeros() const
Compute the number of elements != 0.0.
TVectorT< Element > & Invert()
v[i] = 1/v[i]
Element Norm2Sqr() const
Compute the square of the 2-norm SUM{ v[i]^2 }.
void Print(Option_t *option="") const override
Print the vector as a list of elements.
Element * GetMatrixArray()
TVectorT< Element > & operator-=(Element val)
Subtract val from every element of the vector.
void Draw(Option_t *option="") override
Draw this vector The histogram is named "TVectorT" by default and no title.
TVectorT< Element > & Sqrt()
Take square root of all elements.
Long64_t LocMin(Long64_t n, const T *a)
Returns index of array with the minimum element.
Short_t Max(Short_t a, Short_t b)
Returns the largest of a and b.
Long64_t LocMax(Long64_t n, const T *a)
Returns index of array with the maximum element.
Double_t Sqrt(Double_t x)
Returns the square root of x.
Short_t Min(Short_t a, Short_t b)
Returns the smallest of a and b.
Short_t Abs(Short_t d)
Returns the absolute value of parameter Short_t d.
Bool_t VerifyVectorValue(const TVectorT< Element > &m, Element val, Int_t verbose, Element maxDevAllow)
Validate that all elements of vector have value val within maxDevAllow .
TVectorT< Element > & AddElemDiv(TVectorT< Element > &target, Element scalar, const TVectorT< Element > &source1, const TVectorT< Element > &source2)
Modify addition: target += scalar * ElementDiv(source1,source2) .
TMatrixT< Element > operator+(const TMatrixT< Element > &source1, const TMatrixT< Element > &source2)
operation this = source1+source2
void Compare(const TMatrixTBase< Element > &m1, const TMatrixTBase< Element > &m2)
Compare two matrices and print out the result of the comparison.
TMatrixT< Element > & ElementMult(TMatrixT< Element > &target, const TMatrixT< Element > &source)
Multiply target by the source, element-by-element.
TVectorT< Element > & AddElemMult(TVectorT< Element > &target, Element scalar, const TVectorT< Element > &source1, const TVectorT< Element > &source2)
Modify addition: target += scalar * ElementMult(source1,source2) .
TMatrixT< Element > & Add(TMatrixT< Element > &target, Element scalar, const TMatrixT< Element > &source)
Modify addition: target += scalar * source.
TMatrixT< Element1 > OuterProduct(const TVectorT< Element1 > &v1, const TVectorT< Element2 > &v2)
Return the matrix M = v1 * v2'.
Element Dot(const TVectorT< Element > &source1, const TVectorT< Element > &source2)
return inner-produvt v1 . v2
Bool_t VerifyVectorIdentity(const TVectorT< Element > &m1, const TVectorT< Element > &m2, Int_t verbose, Element maxDevAllow)
Verify that elements of the two vectors are equal within maxDevAllow .
TMatrixT< Element > & ElementDiv(TMatrixT< Element > &target, const TMatrixT< Element > &source)
Divide target by the source, element-by-element.
Element1 Mult(const TVectorT< Element1 > &v1, const TMatrixT< Element2 > &m, const TVectorT< Element3 > &v2)
Perform v1 * M * v2, a scalar result.
TMatrixT< Element > operator-(const TMatrixT< Element > &source1, const TMatrixT< Element > &source2)
operation this = source1-source2
Bool_t operator==(const TMatrixTBase< Element > &m1, const TMatrixTBase< Element > &m2)
Check to see if two matrices are identical.
TMatrixT< Element > operator*(Element val, const TMatrixT< Element > &source)
operation this = val*source
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 .
static uint64_t sum(uint64_t i)