50template<
class Element>
64template<
class Element>
67 if (size == 0)
return 0;
69 if ( size <= kSizeMax )
72 Element *heap =
new Element[size];
81template<
class Element>
85 Error(
"Add(TVectorT<Element> &)",
"vector's not compatible");
89 const Element *sp =
v.GetMatrixArray();
90 Element *tp = this->GetMatrixArray();
91 const Element *
const tp_last = tp+fNrows;
99template<
class Element>
104 Error(
"Add(TVectorT<Element> &)",
"vectors not compatible");
111 Element *tp = this->GetMatrixArray();
112 const Element *
const tp_last = tp+fNrows;
114 *tp++ = *sv1++ + *sv2++;
121template<
class Element>
125 if (copySize == 0 || oldp == newp)
return 0;
127 if ( newSize <= kSizeMax && oldSize <= kSizeMax ) {
130 for (
Int_t i = copySize-1; i >= 0; i--)
133 for (
Int_t i = 0; i < copySize; i++)
138 memcpy(newp,oldp,copySize*
sizeof(Element));
148template<
class Element>
166 fElements = New_m(fNrows);
168 memset(fElements,0,fNrows*
sizeof(Element));
174template<
class Element>
183template<
class Element>
192template<
class Element>
196 SetElements(elements);
202template<
class Element>
206 SetElements(elements);
212template<
class Element>
223template<
class Element>
235template<
class Element>
247template<
class Element>
262template<
class Element>
266 Error(
"TVectorT(Int_t, Int_t, ...)",
"upb(%d) < lwb(%d)",upb,lwb);
277 for (
Int_t i = lwb+1; i <= upb; i++)
278 (*
this)(i) = (Element)va_arg(args,
Double_t);
280 if (strcmp((
char *)va_arg(args,
char *),
"END"))
281 Error(
"TVectorT(Int_t, Int_t, ...)",
"argument list must be terminated by \"END\"");
291template<
class Element>
296 Error(
"ResizeTo(lwb,upb)",
"Not owner of data array,cannot resize");
300 const Int_t new_nrows = upb-lwb+1;
304 if (fNrows == new_nrows && fRowLwb == lwb)
306 else if (new_nrows == 0) {
311 Element *elements_old = GetMatrixArray();
312 const Int_t nrows_old = fNrows;
313 const Int_t rowLwb_old = fRowLwb;
317 if (fNrows > kSizeMax || nrows_old > kSizeMax)
318 memset(GetMatrixArray(),0,fNrows*
sizeof(Element));
319 else if (fNrows > nrows_old)
320 memset(GetMatrixArray()+nrows_old,0,(fNrows-nrows_old)*
sizeof(Element));
324 const Int_t rowUpb_copy =
TMath::Min(fRowLwb+fNrows-1,rowLwb_old+nrows_old-1);
325 const Int_t nrows_copy = rowUpb_copy-rowLwb_copy+1;
327 const Int_t nelems_new = fNrows;
328 Element *elements_new = GetMatrixArray();
329 if (nrows_copy > 0) {
330 const Int_t rowOldOff = rowLwb_copy-rowLwb_old;
331 const Int_t rowNewOff = rowLwb_copy-fRowLwb;
332 Memcpy_m(elements_new+rowNewOff,elements_old+rowOldOff,nrows_copy,nelems_new,nrows_old);
335 Delete_m(nrows_old,elements_old);
346template<
class Element>
350 Error(
"Use",
"upb(%d) < lwb(%d)",upb,lwb);
370template<
class Element>
375 if (row_lwb < fRowLwb || row_lwb > fRowLwb+fNrows-1) {
376 Error(
"GetSub",
"row_lwb out of bounds");
379 if (row_upb < fRowLwb || row_upb > fRowLwb+fNrows-1) {
380 Error(
"GetSub",
"row_upb out of bounds");
383 if (row_upb < row_lwb) {
384 Error(
"GetSub",
"row_upb < row_lwb");
397 row_upb_sub = row_upb-row_lwb;
399 row_lwb_sub = row_lwb;
400 row_upb_sub = row_upb;
403 target.
ResizeTo(row_lwb_sub,row_upb_sub);
404 const Int_t nrows_sub = row_upb_sub-row_lwb_sub+1;
406 const Element *ap = this->GetMatrixArray()+(row_lwb-fRowLwb);
409 for (
Int_t irow = 0; irow < nrows_sub; irow++)
419template<
class Element>
426 if (row_lwb < fRowLwb && row_lwb > fRowLwb+fNrows-1) {
427 Error(
"SetSub",
"row_lwb outof bounds");
430 if (row_lwb+source.
GetNrows() > fRowLwb+fNrows) {
431 Error(
"SetSub",
"source vector too large");
439 Element *ap = this->GetMatrixArray()+(row_lwb-fRowLwb);
441 for (
Int_t irow = 0; irow < nRows_source; irow++)
450template<
class Element>
454 memset(this->GetMatrixArray(),0,fNrows*
sizeof(Element));
461template<
class Element>
466 Element *ep = this->GetMatrixArray();
467 const Element *
const fp = ep+fNrows;
479template<
class Element>
484 Element *ep = this->GetMatrixArray();
485 const Element *
const fp = ep+fNrows;
497template<
class Element>
502 Element *ep = this->GetMatrixArray();
503 const Element *
const fp = ep+fNrows;
509 Error(
"Sqrt()",
"v(%ld) = %g < 0",
Long_t(ep-this->GetMatrixArray()),(
float)*ep);
519template<
class Element>
524 Element *ep = this->GetMatrixArray();
525 const Element *
const fp = ep+fNrows;
531 Error(
"Invert()",
"v(%ld) = %g",
Long_t(ep-this->GetMatrixArray()),(
float)*ep);
541template<
class Element>
545 Error(
"SelectNonZeros(const TVectorT<Element> &",
"vector's not compatible");
550 Element *ep = this->GetMatrixArray();
551 const Element *
const fp = ep+fNrows;
564template<
class Element>
570 const Element *ep = this->GetMatrixArray();
571 const Element *
const fp = ep+fNrows;
581template<
class Element>
587 const Element *ep = this->GetMatrixArray();
588 const Element *
const fp = ep+fNrows;
590 norm += (*ep) * (*ep);
600template<
class Element>
606 const Element *ep = this->GetMatrixArray();
607 const Element *
const fp = ep+fNrows;
617template<
class Element>
622 Int_t nr_nonzeros = 0;
623 const Element *ep = this->GetMatrixArray();
624 const Element *
const fp = ep+fNrows;
626 if (*ep++) nr_nonzeros++;
634template<
class Element>
640 const Element *ep = this->GetMatrixArray();
641 const Element *
const fp = ep+fNrows;
651template<
class Element>
657 return fElements[index];
663template<
class Element>
669 return fElements[index];
677template<
class Element>
681 Error(
"operator=(const TVectorT<Element> &)",
"vectors not compatible");
695template<
class Element>
704 Error(
"operator=(const TMatrixTRow_const &)",
"vector and row not compatible");
710 const Element *rp = mr.
GetPtr();
711 Element *ep = this->GetMatrixArray();
712 const Element *
const fp = ep+fNrows;
726template<
class Element>
735 Error(
"operator=(const TMatrixTColumn_const &)",
"vector and column not compatible");
741 const Element *cp = mc.
GetPtr();
742 Element *ep = this->GetMatrixArray();
743 const Element *
const fp = ep+fNrows;
757template<
class Element>
766 Error(
"operator=(const TMatrixTDiag_const &)",
"vector and matrix-diagonal not compatible");
772 const Element *dp = md.
GetPtr();
773 Element *ep = this->GetMatrixArray();
774 const Element *
const fp = ep+fNrows;
789template<
class Element>
798 Error(
"operator=(const TMatrixTSparseRow_const &)",
"vector and row not compatible");
804 const Element *
const prData = mr.
GetDataPtr();
806 Element *
const pvData = this->GetMatrixArray();
808 memset(pvData,0,fNrows*
sizeof(Element));
809 for (
Int_t index = 0; index < nIndex; index++) {
810 const Int_t icol = prCol[index];
811 pvData[icol] = prData[index];
820template<
class Element>
829 Error(
"operator=(const TMatrixTSparseDiag_const &)",
"vector and matrix-diagonal not compatible");
834 Element *
const pvData = this->GetMatrixArray();
835 for (
Int_t idiag = 0; idiag < fNrows; idiag++)
836 pvData[idiag] = md(idiag);
844template<
class Element>
849 Element *ep = this->GetMatrixArray();
850 const Element *
const fp = ep+fNrows;
860template<
class Element>
865 Element *ep = this->GetMatrixArray();
866 const Element *
const fp = ep+fNrows;
876template<
class Element>
881 Element *ep = this->GetMatrixArray();
882 const Element *
const fp = ep+fNrows;
892template<
class Element>
897 Element *ep = this->GetMatrixArray();
898 const Element *
const fp = ep+fNrows;
908template<
class Element>
912 Error(
"operator+=(const TVectorT<Element> &)",
"vector's not compatible");
917 Element *tp = this->GetMatrixArray();
918 const Element *
const tp_last = tp+fNrows;
928template<
class Element>
932 Error(
"operator-=(const TVectorT<Element> &)",
"vector's not compatible");
937 Element *tp = this->GetMatrixArray();
938 const Element *
const tp_last = tp+fNrows;
949template<
class Element>
955 if (
a.GetNcols() != fNrows ||
a.GetColLwb() != fRowLwb) {
956 Error(
"operator*=(const TMatrixT &)",
"vector and matrix incompatible");
961 const Bool_t doResize = (fNrows !=
a.GetNrows() || fRowLwb !=
a.GetRowLwb());
962 if (doResize && !fIsOwner) {
963 Error(
"operator*=(const TMatrixT &)",
"vector has to be resized but not owner");
967 Element work[kWorkMax];
969 Element *elements_old = work;
970 const Int_t nrows_old = fNrows;
971 if (nrows_old > kWorkMax) {
973 elements_old =
new Element[nrows_old];
975 memcpy(elements_old,fElements,nrows_old*
sizeof(Element));
978 const Int_t rowlwb_new =
a.GetRowLwb();
979 const Int_t nrows_new =
a.GetNrows();
980 ResizeTo(rowlwb_new,rowlwb_new+nrows_new-1);
982 memset(fElements,0,fNrows*
sizeof(Element));
984 const Element *mp =
a.GetMatrixArray();
985 Element *tp = this->GetMatrixArray();
987 if (
typeid(Element) ==
typeid(
Double_t))
988 cblas_dgemv(CblasRowMajor,CblasNoTrans,
a.GetNrows(),
a.GetNcols(),1.0,mp,
989 a.GetNcols(),elements_old,1,0.0,tp,1);
990 else if (
typeid(Element) !=
typeid(
Float_t))
991 cblas_sgemv(CblasRowMajor,CblasNoTrans,
a.GetNrows(),
a.GetNcols(),1.0,mp,
992 a.GetNcols(),elements_old,1,0.0,tp,1);
994 Error(
"operator*=",
"type %s not implemented in BLAS library",
typeid(Element));
996 const Element *
const tp_last = tp+fNrows;
997 while (tp < tp_last) {
999 for (
const Element *sp = elements_old; sp < elements_old+nrows_old; )
1000 sum += *sp++ * *mp++;
1003 R__ASSERT(mp ==
a.GetMatrixArray()+
a.GetNoElements());
1007 delete [] elements_old;
1016template<
class Element>
1022 if (
a.GetNcols() != fNrows ||
a.GetColLwb() != fRowLwb) {
1023 Error(
"operator*=(const TMatrixTSparse &)",
"vector and matrix incompatible");
1028 const Bool_t doResize = (fNrows !=
a.GetNrows() || fRowLwb !=
a.GetRowLwb());
1029 if (doResize && !fIsOwner) {
1030 Error(
"operator*=(const TMatrixTSparse &)",
"vector has to be resized but not owner");
1034 Element work[kWorkMax];
1036 Element *elements_old = work;
1037 const Int_t nrows_old = fNrows;
1038 if (nrows_old > kWorkMax) {
1039 isAllocated =
kTRUE;
1040 elements_old =
new Element[nrows_old];
1042 memcpy(elements_old,fElements,nrows_old*
sizeof(Element));
1045 const Int_t rowlwb_new =
a.GetRowLwb();
1046 const Int_t nrows_new =
a.GetNrows();
1047 ResizeTo(rowlwb_new,rowlwb_new+nrows_new-1);
1049 memset(fElements,0,fNrows*
sizeof(Element));
1051 const Int_t *
const pRowIndex =
a.GetRowIndexArray();
1052 const Int_t *
const pColIndex =
a.GetColIndexArray();
1053 const Element *
const mp =
a.GetMatrixArray();
1055 const Element *
const sp = elements_old;
1056 Element * tp = this->GetMatrixArray();
1058 for (
Int_t irow = 0; irow < fNrows; irow++) {
1059 const Int_t sIndex = pRowIndex[irow];
1060 const Int_t eIndex = pRowIndex[irow+1];
1062 for (
Int_t index = sIndex; index < eIndex; index++) {
1063 const Int_t icol = pColIndex[index];
1064 sum += mp[index]*sp[icol];
1070 delete [] elements_old;
1079template<
class Element>
1085 if (
a.GetNcols() != fNrows ||
a.GetColLwb() != fRowLwb) {
1086 Error(
"operator*=(const TMatrixTSym &)",
"vector and matrix incompatible");
1091 Element work[kWorkMax];
1093 Element *elements_old = work;
1094 const Int_t nrows_old = fNrows;
1095 if (nrows_old > kWorkMax) {
1096 isAllocated =
kTRUE;
1097 elements_old =
new Element[nrows_old];
1099 memcpy(elements_old,fElements,nrows_old*
sizeof(Element));
1100 memset(fElements,0,fNrows*
sizeof(Element));
1102 const Element *mp =
a.GetMatrixArray();
1103 Element *tp = this->GetMatrixArray();
1105 if (
typeid(Element) ==
typeid(
Double_t))
1106 cblas_dsymv(CblasRowMajor,CblasUpper,fNrows,1.0,mp,
1107 fNrows,elements_old,1,0.0,tp,1);
1108 else if (
typeid(Element) !=
typeid(
Float_t))
1109 cblas_ssymv(CblasRowMajor,CblasUpper,fNrows,1.0,mp,
1110 fNrows,elements_old,1,0.0,tp,1);
1112 Error(
"operator*=",
"type %s not implemented in BLAS library",
typeid(Element));
1114 const Element *
const tp_last = tp+fNrows;
1115 while (tp < tp_last) {
1117 for (
const Element *sp = elements_old; sp < elements_old+nrows_old; )
1118 sum += *sp++ * *mp++;
1121 R__ASSERT(mp ==
a.GetMatrixArray()+
a.GetNoElements());
1125 delete [] elements_old;
1133template<
class Element>
1138 const Element *ep = this->GetMatrixArray();
1139 const Element *
const fp = ep+fNrows;
1141 if (!(*ep++ == val))
1150template<
class Element>
1155 const Element *ep = this->GetMatrixArray();
1156 const Element *
const fp = ep+fNrows;
1158 if (!(*ep++ != val))
1167template<
class Element>
1172 const Element *ep = this->GetMatrixArray();
1173 const Element *
const fp = ep+fNrows;
1184template<
class Element>
1189 const Element *ep = this->GetMatrixArray();
1190 const Element *
const fp = ep+fNrows;
1192 if (!(*ep++ <= val))
1201template<
class Element>
1206 const Element *ep = this->GetMatrixArray();
1207 const Element *
const fp = ep+fNrows;
1218template<
class Element>
1223 const Element *ep = this->GetMatrixArray();
1224 const Element *
const fp = ep+fNrows;
1226 if (!(*ep++ >= val))
1235template<
class Element>
1239 Error(
"MatchesNonZeroPattern(const TVectorT&)",
"vector's not compatible");
1244 const Element *ep = this->GetMatrixArray();
1245 const Element *
const fp = ep+fNrows;
1247 if (*sp == 0.0 && *ep != 0.0)
1258template<
class Element>
1262 Error(
"SomePositive(const TVectorT&)",
"vector's not compatible");
1267 const Element *ep = this->GetMatrixArray();
1268 const Element *
const fp = ep+fNrows;
1270 if (*sp != 0.0 && *ep <= 0.0)
1281template<
class Element>
1285 Error(
"AddSomeConstant(Element,const TVectorT&)(const TVectorT&)",
"vector's not compatible");
1288 Element *ep = this->GetMatrixArray();
1289 const Element *
const fp = ep+fNrows;
1302template<
class Element>
1307 const Element scale =
beta-alpha;
1308 const Element shift = alpha/scale;
1310 Element * ep = GetMatrixArray();
1311 const Element *
const fp = ep+fNrows;
1313 *ep++ = scale*(
Drand(seed)+shift);
1319template<
class Element>
1323 for (Element *ep = fElements; ep < fElements+fNrows; ep++)
1332template<
class Element>
1337 Element *ep = fElements;
1338 for (action.
fI = fRowLwb; action.
fI < fRowLwb+fNrows; action.
fI++)
1350template<
class Element>
1353 gROOT->ProcessLine(
Form(
"THistPainter::PaintSpecialObjects((TObject*)0x%lx,\"%s\");",
1360template<
class Element>
1364 Error(
"Print",
"Vector is invalid");
1368 printf(
"\nVector (%d) %s is as follows",fNrows,flag);
1370 printf(
"\n\n | %6d |", 1);
1371 printf(
"\n%s\n",
"------------------");
1372 for (
Int_t i = 0; i < fNrows; i++) {
1373 printf(
"%4d |",i+fRowLwb);
1375 printf(
"%g \n",(*
this)(i+fRowLwb));
1383template<
class Element>
1393template<
class Element>
1398 Error(
"operator*(const TVectorT<Element> &,const TVectorT<Element> &)",
"vector's are incompatible");
1409template<
class Element>
1420template<
class Element>
1431template<
class Element>
1436 return Add(target,Element(1.0),
a,source);
1442template<
class Element>
1447 return Add(target,Element(1.0),
a,source);
1453template<
class Element>
1458 return Add(target,Element(1.0),
a,source);
1464template<
class Element>
1475template<
class Element>
1481 const Element *
const fv1p = v1p+v1.
GetNrows();
1483 sum += *v1p++ * *v2p++;
1491template <
class Element1,
class Element2>
1507template <
class Element1,
class Element2,
class Element3>
1514 const Element1 *
const m_last = mp + target.
GetNoElements();
1517 const Element2 *
const v1_last = v1p + v1.
GetNrows();
1520 const Element3 * v2p = v20;
1521 const Element3 *
const v2_last = v2p + v2.
GetNrows();
1523 while (v1p < v1_last) {
1525 while (v2p < v2_last) {
1526 *mp++ = *v1p * *v2p++ ;
1531 R__ASSERT(v1p == v1_last && mp == m_last && v2p == v2_last);
1539template <
class Element1,
class Element2,
class Element3>
1545 ::Error(
"Mult",
"Vector v1 and matrix m incompatible");
1549 ::Error(
"Mult",
"Matrix m and vector v2 incompatible");
1555 const Element1 *
const v1_last = v1p + v1.
GetNrows();
1557 const Element2 * mp =
m.GetMatrixArray();
1558 const Element2 *
const m_last = mp +
m.GetNoElements();
1561 const Element3 * v2p = v20;
1562 const Element3 *
const v2_last = v2p + v2.
GetNrows();
1567 while (v1p < v1_last) {
1569 while (v2p < v2_last) {
1570 dot += *mp++ * *v2p++;
1572 sum += *v1p++ * dot;
1576 R__ASSERT(v1p == v1_last && mp == m_last && v2p == v2_last);
1584template<
class Element>
1588 Error(
"Add(TVectorT<Element> &,Element,const TVectorT<Element> &)",
"vector's are incompatible");
1594 const Element *
const ftp = tp+target.
GetNrows();
1595 if (scalar == 1.0 ) {
1598 }
else if (scalar == -1.0) {
1603 *tp++ += scalar * *sp++;
1613template<
class Element>
1620 if (
a.GetNrows() != target.
GetNrows() ||
a.GetRowLwb() != target.
GetLwb()) {
1621 Error(
"Add(TVectorT &,const TMatrixT &,const TVectorT &)",
"target vector and matrix are incompatible");
1626 if (
a.GetNcols() != source.
GetNrows() ||
a.GetColLwb() != source.
GetLwb()) {
1627 Error(
"Add(TVectorT &,const TMatrixT &,const TVectorT &)",
"source vector and matrix are incompatible");
1633 const Element * mp =
a.GetMatrixArray();
1636 if (
typeid(Element) ==
typeid(
Double_t))
1637 cblas_dsymv(CblasRowMajor,CblasUpper,fNrows,scalar,mp,
1638 fNrows,sp,1,0.0,tp,1);
1639 else if (
typeid(Element) !=
typeid(
Float_t))
1640 cblas_ssymv(CblasRowMajor,CblasUpper,fNrows,scalar,mp,
1641 fNrows,sp,1,0.0,tp,1);
1643 Error(
"operator*=",
"type %s not implemented in BLAS library",
typeid(Element));
1645 const Element *
const sp_last = sp+source.
GetNrows();
1646 const Element *
const tp_last = tp+target.
GetNrows();
1647 if (scalar == 1.0) {
1648 while (tp < tp_last) {
1649 const Element *sp1 = sp;
1651 while (sp1 < sp_last)
1652 sum += *sp1++ * *mp++;
1655 }
else if (scalar == 0.0) {
1656 while (tp < tp_last) {
1657 const Element *sp1 = sp;
1659 while (sp1 < sp_last)
1660 sum += *sp1++ * *mp++;
1663 }
else if (scalar == -1.0) {
1664 while (tp < tp_last) {
1665 const Element *sp1 = sp;
1667 while (sp1 < sp_last)
1668 sum += *sp1++ * *mp++;
1672 while (tp < tp_last) {
1673 const Element *sp1 = sp;
1675 while (sp1 < sp_last)
1676 sum += *sp1++ * *mp++;
1677 *tp++ += scalar *
sum;
1691template<
class Element>
1699 if (
a.GetNrows() != target.
GetNrows() ||
a.GetRowLwb() != target.
GetLwb()) {
1700 Error(
"Add(TVectorT &,const TMatrixT &,const TVectorT &)",
"target vector and matrix are incompatible");
1706 const Element * mp =
a.GetMatrixArray();
1709 if (
typeid(Element) ==
typeid(
Double_t))
1710 cblas_dsymv(CblasRowMajor,CblasUpper,fNrows,1.0,mp,
1711 fNrows,sp,1,0.0,tp,1);
1712 else if (
typeid(Element) !=
typeid(
Float_t))
1713 cblas_ssymv(CblasRowMajor,CblasUpper,fNrows,1.0,mp,
1714 fNrows,sp,1,0.0,tp,1);
1716 Error(
"operator*=",
"type %s not implemented in BLAS library",
typeid(Element));
1718 const Element *
const sp_last = sp+source.
GetNrows();
1719 const Element *
const tp_last = tp+target.
GetNrows();
1720 if (scalar == 1.0) {
1721 while (tp < tp_last) {
1722 const Element *sp1 = sp;
1724 while (sp1 < sp_last)
1725 sum += *sp1++ * *mp++;
1728 }
else if (scalar == 0.0) {
1729 while (tp < tp_last) {
1730 const Element *sp1 = sp;
1732 while (sp1 < sp_last)
1733 sum += *sp1++ * *mp++;
1736 }
else if (scalar == -1.0) {
1737 while (tp < tp_last) {
1738 const Element *sp1 = sp;
1740 while (sp1 < sp_last)
1741 sum += *sp1++ * *mp++;
1745 while (tp < tp_last) {
1746 const Element *sp1 = sp;
1748 while (sp1 < sp_last)
1749 sum += *sp1++ * *mp++;
1750 *tp++ += scalar *
sum;
1753 R__ASSERT(mp ==
a.GetMatrixArray()+
a.GetNoElements());
1763template<
class Element>
1770 if (
a.GetNrows() != target.
GetNrows() ||
a.GetRowLwb() != target.
GetLwb()) {
1771 Error(
"Add(TVectorT &,const TMatrixT &,const TVectorT &)",
"target vector and matrix are incompatible");
1776 if (
a.GetNcols() != source.
GetNrows() ||
a.GetColLwb() != source.
GetLwb()) {
1777 Error(
"Add(TVectorT &,const TMatrixT &,const TVectorT &)",
"source vector and matrix are incompatible");
1782 const Int_t *
const pRowIndex =
a.GetRowIndexArray();
1783 const Int_t *
const pColIndex =
a.GetColIndexArray();
1784 const Element *
const mp =
a.GetMatrixArray();
1789 if (scalar == 1.0) {
1790 for (
Int_t irow = 0; irow <
a.GetNrows(); irow++) {
1791 const Int_t sIndex = pRowIndex[irow];
1792 const Int_t eIndex = pRowIndex[irow+1];
1794 for (
Int_t index = sIndex; index < eIndex; index++) {
1795 const Int_t icol = pColIndex[index];
1796 sum += mp[index]*sp[icol];
1800 }
else if (scalar == 0.0) {
1801 for (
Int_t irow = 0; irow <
a.GetNrows(); irow++) {
1802 const Int_t sIndex = pRowIndex[irow];
1803 const Int_t eIndex = pRowIndex[irow+1];
1805 for (
Int_t index = sIndex; index < eIndex; index++) {
1806 const Int_t icol = pColIndex[index];
1807 sum += mp[index]*sp[icol];
1811 }
else if (scalar == -1.0) {
1812 for (
Int_t irow = 0; irow <
a.GetNrows(); irow++) {
1813 const Int_t sIndex = pRowIndex[irow];
1814 const Int_t eIndex = pRowIndex[irow+1];
1816 for (
Int_t index = sIndex; index < eIndex; index++) {
1817 const Int_t icol = pColIndex[index];
1818 sum += mp[index]*sp[icol];
1823 for (
Int_t irow = 0; irow <
a.GetNrows(); irow++) {
1824 const Int_t sIndex = pRowIndex[irow];
1825 const Int_t eIndex = pRowIndex[irow+1];
1827 for (
Int_t index = sIndex; index < eIndex; index++) {
1828 const Int_t icol = pColIndex[index];
1829 sum += mp[index]*sp[icol];
1831 tp[irow] += scalar *
sum;
1841template<
class Element>
1846 Error(
"AddElemMult(TVectorT<Element> &,Element,const TVectorT<Element> &,const TVectorT<Element> &)",
1847 "vector's are incompatible");
1854 const Element *
const ftp = tp+target.
GetNrows();
1856 if (scalar == 1.0 ) {
1858 *tp++ += *sp1++ * *sp2++;
1859 }
else if (scalar == -1.0) {
1861 *tp++ -= *sp1++ * *sp2++;
1864 *tp++ += scalar * *sp1++ * *sp2++;
1874template<
class Element>
1880 Error(
"AddElemMult(TVectorT<Element> &,Element,const TVectorT<Element> &,const TVectorT<Element> &,onst TVectorT<Element> &)",
1881 "vector's are incompatible");
1889 const Element *
const ftp = tp+target.
GetNrows();
1891 if (scalar == 1.0 ) {
1892 while ( tp < ftp ) {
1893 if (*mp) *tp += *sp1 * *sp2;
1894 mp++; tp++; sp1++; sp2++;
1896 }
else if (scalar == -1.0) {
1897 while ( tp < ftp ) {
1898 if (*mp) *tp -= *sp1 * *sp2;
1899 mp++; tp++; sp1++; sp2++;
1902 while ( tp < ftp ) {
1903 if (*mp) *tp += scalar * *sp1 * *sp2;
1904 mp++; tp++; sp1++; sp2++;
1914template<
class Element>
1919 Error(
"AddElemDiv(TVectorT<Element> &,Element,const TVectorT<Element> &,const TVectorT<Element> &)",
1920 "vector's are incompatible");
1927 const Element *
const ftp = tp+target.
GetNrows();
1929 if (scalar == 1.0 ) {
1930 while ( tp < ftp ) {
1935 Error(
"AddElemDiv",
"source2 (%d) is zero",irow);
1939 }
else if (scalar == -1.0) {
1940 while ( tp < ftp ) {
1945 Error(
"AddElemDiv",
"source2 (%d) is zero",irow);
1950 while ( tp < ftp ) {
1952 *tp += scalar * *sp1 / *sp2;
1955 Error(
"AddElemDiv",
"source2 (%d) is zero",irow);
1968template<
class Element>
1974 Error(
"AddElemDiv(TVectorT<Element> &,Element,const TVectorT<Element> &,const TVectorT<Element> &,onst TVectorT<Element> &)",
1975 "vector's are incompatible");
1983 const Element *
const ftp = tp+target.
GetNrows();
1985 if (scalar == 1.0 ) {
1986 while ( tp < ftp ) {
1992 Error(
"AddElemDiv",
"source2 (%d) is zero",irow);
1995 mp++; tp++; sp1++; sp2++;
1997 }
else if (scalar == -1.0) {
1998 while ( tp < ftp ) {
2004 Error(
"AddElemDiv",
"source2 (%d) is zero",irow);
2007 mp++; tp++; sp1++; sp2++;
2010 while ( tp < ftp ) {
2013 *tp += scalar * *sp1 / *sp2;
2016 Error(
"AddElemDiv",
"source2 (%d) is zero",irow);
2019 mp++; tp++; sp1++; sp2++;
2029template<
class Element>
2033 Error(
"ElementMult(TVectorT<Element> &,const TVectorT<Element> &)",
"vector's are incompatible");
2039 const Element *
const ftp = tp+target.
GetNrows();
2049template<
class Element>
2053 Error(
"ElementMult(TVectorT<Element> &,const TVectorT<Element> &,const TVectorT<Element> &)",
"vector's are incompatible");
2060 const Element *
const ftp = tp+target.
GetNrows();
2061 while ( tp < ftp ) {
2062 if (*mp) *tp *= *sp;
2072template<
class Element>
2076 Error(
"ElementDiv(TVectorT<Element> &,const TVectorT<Element> &)",
"vector's are incompatible");
2082 const Element *
const ftp = tp+target.
GetNrows();
2083 while ( tp < ftp ) {
2088 Error(
"ElementDiv",
"source (%d) is zero",irow);
2098template<
class Element>
2102 Error(
"ElementDiv(TVectorT<Element> &,const TVectorT<Element> &,const TVectorT<Element> &)",
"vector's are incompatible");
2109 const Element *
const ftp = tp+target.
GetNrows();
2110 while ( tp < ftp ) {
2116 Error(
"ElementDiv",
"source (%d) is zero",irow);
2128template<
class Element1,
class Element2>
2133 ::Error(
"AreCompatible",
"vector 1 not valid");
2138 ::Error(
"AreCompatible",
"vector 2 not valid");
2144 ::Error(
"AreCompatible",
"matrices 1 and 2 not compatible");
2154template<
class Element1,
class Element2>
2159 ::Error(
"AreCompatible",
"Matrix not valid");
2164 ::Error(
"AreCompatible",
"vector not valid");
2168 if (
m.GetNcols() !=
v.GetNrows() ) {
2170 ::Error(
"AreCompatible",
"matrix and vector not compatible");
2180template<
class Element1,
class Element2>
2185 ::Error(
"AreCompatible",
"Matrix not valid");
2190 ::Error(
"AreCompatible",
"vector not valid");
2194 if (
v.GetNrows() !=
m.GetNrows() ) {
2196 ::Error(
"AreCompatible",
"vector and matrix not compatible");
2206template<
class Element>
2210 Error(
"Compare(const TVectorT<Element> &,const TVectorT<Element> &)",
"vectors are incompatible");
2214 printf(
"\n\nComparison of two TVectorTs:\n");
2220 Element difmax = -1;
2225 const Element mv1 = *mp1++;
2226 const Element mv2 = *mp2++;
2229 if (diff > difmax) {
2239 printf(
"\nMaximal discrepancy \t\t%g",difmax);
2240 printf(
"\n occured at the point\t\t(%d)",imax);
2241 const Element mv1 = v1(imax);
2242 const Element mv2 = v2(imax);
2243 printf(
"\n Vector 1 element is \t\t%g",mv1);
2244 printf(
"\n Vector 2 element is \t\t%g",mv2);
2245 printf(
"\n Absolute error v2[i]-v1[i]\t\t%g",mv2-mv1);
2246 printf(
"\n Relative error\t\t\t\t%g\n",
2249 printf(
"\n||Vector 1|| \t\t\t%g",norm1);
2250 printf(
"\n||Vector 2|| \t\t\t%g",norm2);
2251 printf(
"\n||Vector1-Vector2||\t\t\t\t%g",ndiff);
2252 printf(
"\n||Vector1-Vector2||/sqrt(||Vector1|| ||Vector2||)\t%g\n\n",
2259template<
class Element>
2264 Element maxDevObs = 0;
2269 for (
Int_t i =
v.GetLwb(); i <=
v.GetUpb(); i++) {
2271 if (dev > maxDevObs) {
2281 printf(
"Largest dev for (%d); dev = |%g - %g| = %g\n",imax,
v(imax),val,maxDevObs);
2282 if (maxDevObs > maxDevAllow)
2283 Error(
"VerifyVectorValue",
"Deviation > %g\n",maxDevAllow);
2286 if (maxDevObs > maxDevAllow)
2294template<
class Element>
2299 Element maxDevObs = 0;
2309 if (dev > maxDevObs) {
2319 printf(
"Largest dev for (%d); dev = |%g - %g| = %g\n",imax,v1(imax),v2(imax),maxDevObs);
2320 if (maxDevObs > maxDevAllow)
2321 Error(
"VerifyVectorIdentity",
"Deviation > %g\n",maxDevAllow);
2324 if (maxDevObs > maxDevAllow) {
2333template<
class Element>
2343 TObject::Streamer(R__b);
2348 if (fNrows > 0 && fNrows <= kSizeMax) {
2349 memcpy(fDataStack,fElements,fNrows*
sizeof(Element));
2350 delete [] fElements;
2351 fElements = fDataStack;
2352 }
else if (fNrows < 0)
#define templateClassImp(name)
void Error(const char *location, const char *msgfmt,...)
R__EXTERN Int_t gMatrixCheck
char * Form(const char *fmt,...)
TVectorT< Element > & ElementDiv(TVectorT< Element > &target, const TVectorT< Element > &source)
Divide target by the source, element-by-element.
template Bool_t AreCompatible< Double_t, Float_t >(const TVectorD &v1, const TVectorF &v2, Int_t verbose)
TVectorT< Element > operator+(const TVectorT< Element > &source1, const TVectorT< Element > &source2)
Return source1+source2.
template Bool_t VerifyVectorIdentity< Float_t >(const TVectorF &m1, const TVectorF &m2, Int_t verbose, Float_t maxDevAllow)
template Double_t Mult< Double_t, Double_t, Double_t >(const TVectorD &v1, const TMatrixD &m, const TVectorD &v2)
template TVectorD & ElementMult< Double_t >(TVectorD &target, const TVectorD &source)
template Float_t Dot< Float_t >(const TVectorF &v1, const TVectorF &v2)
template Bool_t AreCompatible< Float_t, Float_t >(const TVectorF &v1, const TVectorF &v2, Int_t verbose)
template TMatrixD & OuterProduct< Double_t, Double_t, Double_t >(TMatrixD &target, const TVectorD &v1, const TVectorD &v2)
template Bool_t AreCompatible< Float_t, Double_t >(const TVectorF &v1, const TVectorD &v2, Int_t verbose)
Double_t Drand(Double_t &ix)
Random number generator [0....1] with seed ix.
Bool_t VerifyVectorIdentity(const TVectorT< Element > &v1, const TVectorT< Element > &v2, Int_t verbose, Element maxDevAllow)
Verify that elements of the two vectors are equal within maxDevAllow .
TVectorT< Element > & Add(TVectorT< Element > &target, Element scalar, const TVectorT< Element > &source)
Modify addition: target += scalar * source.
template TVectorF & AddElemDiv< Float_t >(TVectorF &target, Float_t scalar, const TVectorF &source1, const TVectorF &source2)
Bool_t AreCompatible(const TVectorT< Element1 > &v1, const TVectorT< Element2 > &v2, Int_t verbose)
Check if v1 and v2 are both valid and have the same shape.
template Bool_t AreCompatible< Double_t, Double_t >(const TVectorD &v1, const TVectorD &v2, Int_t verbose)
template TVectorF & AddElemMult< Float_t >(TVectorF &target, Float_t scalar, const TVectorF &source1, const TVectorF &source2)
template Bool_t VerifyVectorValue< Double_t >(const TVectorD &m, Double_t val, Int_t verbose, Double_t maxDevAllow)
template TVectorF & Add< Float_t >(TVectorF &target, Float_t scalar, const TVectorF &source)
TVectorT< Element > & AddElemDiv(TVectorT< Element > &target, Element scalar, const TVectorT< Element > &source1, const TVectorT< Element > &source2)
Modify addition: target += scalar * ElementDiv(source1,source2) .
template TMatrixF & OuterProduct< Float_t, Float_t, Float_t >(TMatrixF &target, const TVectorF &v1, const TVectorF &v2)
template TVectorD & Add< Double_t >(TVectorD &target, Double_t scalar, const TVectorD &source)
Element operator*(const TVectorT< Element > &v1, const TVectorT< Element > &v2)
Compute the scalar product.
TVectorT< Element > & AddElemMult(TVectorT< Element > &target, Element scalar, const TVectorT< Element > &source1, const TVectorT< Element > &source2)
Modify addition: target += scalar * ElementMult(source1,source2) .
Bool_t operator==(const TVectorT< Element > &v1, const TVectorT< Element > &v2)
Check to see if two vectors are identical.
template TVectorD & AddElemDiv< Double_t >(TVectorD &target, Double_t scalar, const TVectorD &source1, const TVectorD &source2)
template Float_t Mult< Float_t, Float_t, Float_t >(const TVectorF &v1, const TMatrixF &m, const TVectorF &v2)
TVectorT< Element > operator-(const TVectorT< Element > &source1, const TVectorT< Element > &source2)
Return source1-source2.
TVectorT< Element > & ElementMult(TVectorT< Element > &target, const TVectorT< Element > &source)
Multiply target by the source, element-by-element.
template TVectorF & ElementDiv< Float_t >(TVectorF &target, const TVectorF &source)
Element Dot(const TVectorT< Element > &v1, const TVectorT< Element > &v2)
return inner-produvt v1 . v2
template void Compare< Double_t >(const TVectorD &v1, const TVectorD &v2)
template TVectorF & ElementMult< Float_t >(TVectorF &target, const TVectorF &source)
template void Compare< Float_t >(const TVectorF &v1, const TVectorF &v2)
TMatrixT< Element1 > OuterProduct(const TVectorT< Element1 > &v1, const TVectorT< Element2 > &v2)
Return the matrix M = v1 * v2'.
template Bool_t VerifyVectorValue< Float_t >(const TVectorF &m, Float_t val, Int_t verbose, Float_t maxDevAllow)
Bool_t VerifyVectorValue(const TVectorT< Element > &v, Element val, Int_t verbose, Element maxDevAllow)
Validate that all elements of vector have value val within maxDevAllow .
template Bool_t VerifyVectorIdentity< Double_t >(const TVectorD &m1, const TVectorD &m2, Int_t verbose, Double_t maxDevAllow)
template TMatrixF OuterProduct< Float_t, Float_t >(const TVectorF &v1, const TVectorF &v2)
template TVectorD & AddElemMult< Double_t >(TVectorD &target, Double_t scalar, const TVectorD &source1, const TVectorD &source2)
Element1 Mult(const TVectorT< Element1 > &v1, const TMatrixT< Element2 > &m, const TVectorT< Element3 > &v2)
Perform v1 * M * v2, a scalar result.
void Compare(const TVectorT< Element > &v1, const TVectorT< Element > &v2)
Compare two vectors and print out the result of the comparison.
template TVectorD & ElementDiv< Double_t >(TVectorD &target, const TVectorD &source)
template Double_t Dot< Double_t >(const TVectorD &v1, const TVectorD &v2)
template TMatrixD OuterProduct< Double_t, Double_t >(const TVectorD &v1, const TVectorD &v2)
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 Int_t ReadArray(Bool_t *&b)=0
virtual Int_t CheckByteCount(UInt_t startpos, UInt_t bcnt, const TClass *clss)=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
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...
virtual const Element * GetMatrixArray() const
Mother of all ROOT objects.
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 > & 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.
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] .
void Draw(Option_t *option="")
Draw this vector The histogram is named "TVectorT" by default and no title.
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.
void Print(Option_t *option="") const
Print the vector as a list of elements.
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 }.
Element * GetMatrixArray()
TVectorT< Element > & operator-=(Element val)
Subtract val from every element of the vector.
TVectorT< Element > & Sqrt()
Take square root of all elements.
double beta(double x, double y)
Calculates the beta function.
TCppObject_t Allocate(TCppType_t type)
static constexpr double m2
Long64_t LocMin(Long64_t n, const T *a)
Return index of array with the minimum element.
Short_t Max(Short_t a, Short_t b)
Long64_t LocMax(Long64_t n, const T *a)
Return index of array with the maximum element.
Double_t Sqrt(Double_t x)
Short_t Min(Short_t a, Short_t b)
static long int sum(long int i)