53template<
class Element>
67template<
class Element>
70 if (size == 0)
return 0;
72 if ( size <= kSizeMax )
75 Element *heap =
new Element[size];
84template<
class Element>
88 Error(
"Add(TVectorT<Element> &)",
"vector's not compatible");
92 const Element *sp =
v.GetMatrixArray();
93 Element *tp = this->GetMatrixArray();
94 const Element *
const tp_last = tp+fNrows;
102template<
class Element>
107 Error(
"Add(TVectorT<Element> &)",
"vectors not compatible");
112 const Element *sv1 =
v1.GetMatrixArray();
113 const Element *sv2 =
v2.GetMatrixArray();
114 Element *tp = this->GetMatrixArray();
115 const Element *
const tp_last = tp+fNrows;
117 *tp++ = *sv1++ + *sv2++;
124template<
class Element>
128 if (copySize == 0 || oldp == newp)
return 0;
130 if ( newSize <= kSizeMax && oldSize <= kSizeMax ) {
133 for (
Int_t i = copySize-1; i >= 0; i--)
136 for (
Int_t i = 0; i < copySize; i++)
141 memcpy(newp,oldp,copySize*
sizeof(Element));
151template<
class Element>
169 fElements = New_m(fNrows);
171 memset(fElements,0,fNrows*
sizeof(Element));
177template<
class Element>
186template<
class Element>
195template<
class Element>
199 SetElements(elements);
205template<
class Element>
209 SetElements(elements);
215template<
class Element>
226template<
class Element>
238template<
class Element>
250template<
class Element>
265template<
class Element>
269 Error(
"TVectorT(Int_t, Int_t, ...)",
"upb(%d) < lwb(%d)",upb,lwb);
280 for (
Int_t i = lwb+1; i <= upb; i++)
281 (*
this)(i) = (Element)va_arg(args,
Double_t);
283 if (strcmp((
char *)va_arg(args,
char *),
"END"))
284 Error(
"TVectorT(Int_t, Int_t, ...)",
"argument list must be terminated by \"END\"");
294template<
class Element>
299 Error(
"ResizeTo(lwb,upb)",
"Not owner of data array,cannot resize");
303 const Int_t new_nrows = upb-lwb+1;
307 if (fNrows == new_nrows && fRowLwb == lwb)
309 else if (new_nrows == 0) {
314 Element *elements_old = GetMatrixArray();
315 const Int_t nrows_old = fNrows;
316 const Int_t rowLwb_old = fRowLwb;
320 if (fNrows > kSizeMax || nrows_old > kSizeMax)
321 memset(GetMatrixArray(),0,fNrows*
sizeof(Element));
322 else if (fNrows > nrows_old)
323 memset(GetMatrixArray()+nrows_old,0,(fNrows-nrows_old)*
sizeof(Element));
327 const Int_t rowUpb_copy =
TMath::Min(fRowLwb+fNrows-1,rowLwb_old+nrows_old-1);
328 const Int_t nrows_copy = rowUpb_copy-rowLwb_copy+1;
330 const Int_t nelems_new = fNrows;
331 Element *elements_new = GetMatrixArray();
332 if (nrows_copy > 0) {
333 const Int_t rowOldOff = rowLwb_copy-rowLwb_old;
334 const Int_t rowNewOff = rowLwb_copy-fRowLwb;
335 Memcpy_m(elements_new+rowNewOff,elements_old+rowOldOff,nrows_copy,nelems_new,nrows_old);
338 Delete_m(nrows_old,elements_old);
349template<
class Element>
353 Error(
"Use",
"upb(%d) < lwb(%d)",upb,lwb);
373template<
class Element>
378 if (row_lwb < fRowLwb || row_lwb > fRowLwb+fNrows-1) {
379 Error(
"GetSub",
"row_lwb out of bounds");
382 if (row_upb < fRowLwb || row_upb > fRowLwb+fNrows-1) {
383 Error(
"GetSub",
"row_upb out of bounds");
386 if (row_upb < row_lwb) {
387 Error(
"GetSub",
"row_upb < row_lwb");
400 row_upb_sub = row_upb-row_lwb;
402 row_lwb_sub = row_lwb;
403 row_upb_sub = row_upb;
406 target.
ResizeTo(row_lwb_sub,row_upb_sub);
407 const Int_t nrows_sub = row_upb_sub-row_lwb_sub+1;
409 const Element *ap = this->GetMatrixArray()+(row_lwb-fRowLwb);
412 for (
Int_t irow = 0; irow < nrows_sub; irow++)
422template<
class Element>
429 if (row_lwb < fRowLwb && row_lwb > fRowLwb+fNrows-1) {
430 Error(
"SetSub",
"row_lwb outof bounds");
433 if (row_lwb+source.
GetNrows() > fRowLwb+fNrows) {
434 Error(
"SetSub",
"source vector too large");
442 Element *ap = this->GetMatrixArray()+(row_lwb-fRowLwb);
444 for (
Int_t irow = 0; irow < nRows_source; irow++)
453template<
class Element>
457 memset(this->GetMatrixArray(),0,fNrows*
sizeof(Element));
464template<
class Element>
469 Element *ep = this->GetMatrixArray();
470 const Element *
const fp = ep+fNrows;
482template<
class Element>
487 Element *ep = this->GetMatrixArray();
488 const Element *
const fp = ep+fNrows;
500template<
class Element>
505 Element *ep = this->GetMatrixArray();
506 const Element *
const fp = ep+fNrows;
512 Error(
"Sqrt()",
"v(%ld) = %g < 0",
Long_t(ep-this->GetMatrixArray()),(
float)*ep);
522template<
class Element>
527 Element *ep = this->GetMatrixArray();
528 const Element *
const fp = ep+fNrows;
534 Error(
"Invert()",
"v(%ld) = %g",
Long_t(ep-this->GetMatrixArray()),(
float)*ep);
544template<
class Element>
548 Error(
"SelectNonZeros(const TVectorT<Element> &",
"vector's not compatible");
553 Element *ep = this->GetMatrixArray();
554 const Element *
const fp = ep+fNrows;
567template<
class Element>
573 const Element *ep = this->GetMatrixArray();
574 const Element *
const fp = ep+fNrows;
584template<
class Element>
590 const Element *ep = this->GetMatrixArray();
591 const Element *
const fp = ep+fNrows;
593 norm += (*ep) * (*ep);
603template<
class Element>
609 const Element *ep = this->GetMatrixArray();
610 const Element *
const fp = ep+fNrows;
620template<
class Element>
625 Int_t nr_nonzeros = 0;
626 const Element *ep = this->GetMatrixArray();
627 const Element *
const fp = ep+fNrows;
629 if (*ep++) nr_nonzeros++;
637template<
class Element>
643 const Element *ep = this->GetMatrixArray();
644 const Element *
const fp = ep+fNrows;
654template<
class Element>
660 return fElements[index];
666template<
class Element>
672 return fElements[index];
680template<
class Element>
684 Error(
"operator=(const TVectorT<Element> &)",
"vectors not compatible");
698template<
class Element>
707 Error(
"operator=(const TMatrixTRow_const &)",
"vector and row not compatible");
713 const Element *rp = mr.
GetPtr();
714 Element *ep = this->GetMatrixArray();
715 const Element *
const fp = ep+fNrows;
729template<
class Element>
738 Error(
"operator=(const TMatrixTColumn_const &)",
"vector and column not compatible");
744 const Element *cp = mc.
GetPtr();
745 Element *ep = this->GetMatrixArray();
746 const Element *
const fp = ep+fNrows;
760template<
class Element>
769 Error(
"operator=(const TMatrixTDiag_const &)",
"vector and matrix-diagonal not compatible");
775 const Element *dp = md.
GetPtr();
776 Element *ep = this->GetMatrixArray();
777 const Element *
const fp = ep+fNrows;
792template<
class Element>
801 Error(
"operator=(const TMatrixTSparseRow_const &)",
"vector and row not compatible");
807 const Element *
const prData = mr.
GetDataPtr();
809 Element *
const pvData = this->GetMatrixArray();
811 memset(pvData,0,fNrows*
sizeof(Element));
812 for (
Int_t index = 0; index < nIndex; index++) {
813 const Int_t icol = prCol[index];
814 pvData[icol] = prData[index];
823template<
class Element>
832 Error(
"operator=(const TMatrixTSparseDiag_const &)",
"vector and matrix-diagonal not compatible");
837 Element *
const pvData = this->GetMatrixArray();
838 for (
Int_t idiag = 0; idiag < fNrows; idiag++)
839 pvData[idiag] = md(idiag);
847template<
class Element>
852 Element *ep = this->GetMatrixArray();
853 const Element *
const fp = ep+fNrows;
863template<
class Element>
868 Element *ep = this->GetMatrixArray();
869 const Element *
const fp = ep+fNrows;
879template<
class Element>
884 Element *ep = this->GetMatrixArray();
885 const Element *
const fp = ep+fNrows;
895template<
class Element>
900 Element *ep = this->GetMatrixArray();
901 const Element *
const fp = ep+fNrows;
911template<
class Element>
915 Error(
"operator+=(const TVectorT<Element> &)",
"vector's not compatible");
920 Element *tp = this->GetMatrixArray();
921 const Element *
const tp_last = tp+fNrows;
931template<
class Element>
935 Error(
"operator-=(const TVectorT<Element> &)",
"vector's not compatible");
940 Element *tp = this->GetMatrixArray();
941 const Element *
const tp_last = tp+fNrows;
952template<
class Element>
958 if (
a.GetNcols() != fNrows ||
a.GetColLwb() != fRowLwb) {
959 Error(
"operator*=(const TMatrixT &)",
"vector and matrix incompatible");
964 const Bool_t doResize = (fNrows !=
a.GetNrows() || fRowLwb !=
a.GetRowLwb());
965 if (doResize && !fIsOwner) {
966 Error(
"operator*=(const TMatrixT &)",
"vector has to be resized but not owner");
970 Element work[kWorkMax];
972 Element *elements_old = work;
973 const Int_t nrows_old = fNrows;
974 if (nrows_old > kWorkMax) {
976 elements_old =
new Element[nrows_old];
978 memcpy(elements_old,fElements,nrows_old*
sizeof(Element));
981 const Int_t rowlwb_new =
a.GetRowLwb();
982 const Int_t nrows_new =
a.GetNrows();
983 ResizeTo(rowlwb_new,rowlwb_new+nrows_new-1);
985 memset(fElements,0,fNrows*
sizeof(Element));
987 const Element *mp =
a.GetMatrixArray();
988 Element *tp = this->GetMatrixArray();
990 if (
typeid(Element) ==
typeid(
Double_t))
991 cblas_dgemv(CblasRowMajor,CblasNoTrans,
a.GetNrows(),
a.GetNcols(),1.0,mp,
992 a.GetNcols(),elements_old,1,0.0,tp,1);
993 else if (
typeid(Element) !=
typeid(
Float_t))
994 cblas_sgemv(CblasRowMajor,CblasNoTrans,
a.GetNrows(),
a.GetNcols(),1.0,mp,
995 a.GetNcols(),elements_old,1,0.0,tp,1);
997 Error(
"operator*=",
"type %s not implemented in BLAS library",
typeid(Element));
999 const Element *
const tp_last = tp+fNrows;
1000 while (tp < tp_last) {
1002 for (
const Element *sp = elements_old; sp < elements_old+nrows_old; )
1003 sum += *sp++ * *mp++;
1006 R__ASSERT(mp ==
a.GetMatrixArray()+
a.GetNoElements());
1010 delete [] elements_old;
1019template<
class Element>
1025 if (
a.GetNcols() != fNrows ||
a.GetColLwb() != fRowLwb) {
1026 Error(
"operator*=(const TMatrixTSparse &)",
"vector and matrix incompatible");
1031 const Bool_t doResize = (fNrows !=
a.GetNrows() || fRowLwb !=
a.GetRowLwb());
1032 if (doResize && !fIsOwner) {
1033 Error(
"operator*=(const TMatrixTSparse &)",
"vector has to be resized but not owner");
1037 Element work[kWorkMax];
1039 Element *elements_old = work;
1040 const Int_t nrows_old = fNrows;
1041 if (nrows_old > kWorkMax) {
1042 isAllocated =
kTRUE;
1043 elements_old =
new Element[nrows_old];
1045 memcpy(elements_old,fElements,nrows_old*
sizeof(Element));
1048 const Int_t rowlwb_new =
a.GetRowLwb();
1049 const Int_t nrows_new =
a.GetNrows();
1050 ResizeTo(rowlwb_new,rowlwb_new+nrows_new-1);
1052 memset(fElements,0,fNrows*
sizeof(Element));
1054 const Int_t *
const pRowIndex =
a.GetRowIndexArray();
1055 const Int_t *
const pColIndex =
a.GetColIndexArray();
1056 const Element *
const mp =
a.GetMatrixArray();
1058 const Element *
const sp = elements_old;
1059 Element * tp = this->GetMatrixArray();
1061 for (
Int_t irow = 0; irow < fNrows; irow++) {
1062 const Int_t sIndex = pRowIndex[irow];
1063 const Int_t eIndex = pRowIndex[irow+1];
1065 for (
Int_t index = sIndex; index < eIndex; index++) {
1066 const Int_t icol = pColIndex[index];
1067 sum += mp[index]*sp[icol];
1073 delete [] elements_old;
1082template<
class Element>
1088 if (
a.GetNcols() != fNrows ||
a.GetColLwb() != fRowLwb) {
1089 Error(
"operator*=(const TMatrixTSym &)",
"vector and matrix incompatible");
1094 Element work[kWorkMax];
1096 Element *elements_old = work;
1097 const Int_t nrows_old = fNrows;
1098 if (nrows_old > kWorkMax) {
1099 isAllocated =
kTRUE;
1100 elements_old =
new Element[nrows_old];
1102 memcpy(elements_old,fElements,nrows_old*
sizeof(Element));
1103 memset(fElements,0,fNrows*
sizeof(Element));
1105 const Element *mp =
a.GetMatrixArray();
1106 Element *tp = this->GetMatrixArray();
1108 if (
typeid(Element) ==
typeid(
Double_t))
1109 cblas_dsymv(CblasRowMajor,CblasUpper,fNrows,1.0,mp,
1110 fNrows,elements_old,1,0.0,tp,1);
1111 else if (
typeid(Element) !=
typeid(
Float_t))
1112 cblas_ssymv(CblasRowMajor,CblasUpper,fNrows,1.0,mp,
1113 fNrows,elements_old,1,0.0,tp,1);
1115 Error(
"operator*=",
"type %s not implemented in BLAS library",
typeid(Element));
1117 const Element *
const tp_last = tp+fNrows;
1118 while (tp < tp_last) {
1120 for (
const Element *sp = elements_old; sp < elements_old+nrows_old; )
1121 sum += *sp++ * *mp++;
1124 R__ASSERT(mp ==
a.GetMatrixArray()+
a.GetNoElements());
1128 delete [] elements_old;
1136template<
class Element>
1141 const Element *ep = this->GetMatrixArray();
1142 const Element *
const fp = ep+fNrows;
1144 if (!(*ep++ == val))
1153template<
class Element>
1158 const Element *ep = this->GetMatrixArray();
1159 const Element *
const fp = ep+fNrows;
1161 if (!(*ep++ != val))
1170template<
class Element>
1175 const Element *ep = this->GetMatrixArray();
1176 const Element *
const fp = ep+fNrows;
1187template<
class Element>
1192 const Element *ep = this->GetMatrixArray();
1193 const Element *
const fp = ep+fNrows;
1195 if (!(*ep++ <= val))
1204template<
class Element>
1209 const Element *ep = this->GetMatrixArray();
1210 const Element *
const fp = ep+fNrows;
1221template<
class Element>
1226 const Element *ep = this->GetMatrixArray();
1227 const Element *
const fp = ep+fNrows;
1229 if (!(*ep++ >= val))
1238template<
class Element>
1242 Error(
"MatchesNonZeroPattern(const TVectorT&)",
"vector's not compatible");
1247 const Element *ep = this->GetMatrixArray();
1248 const Element *
const fp = ep+fNrows;
1250 if (*sp == 0.0 && *ep != 0.0)
1261template<
class Element>
1265 Error(
"SomePositive(const TVectorT&)",
"vector's not compatible");
1270 const Element *ep = this->GetMatrixArray();
1271 const Element *
const fp = ep+fNrows;
1273 if (*sp != 0.0 && *ep <= 0.0)
1284template<
class Element>
1288 Error(
"AddSomeConstant(Element,const TVectorT&)(const TVectorT&)",
"vector's not compatible");
1291 Element *ep = this->GetMatrixArray();
1292 const Element *
const fp = ep+fNrows;
1305template<
class Element>
1310 const Element scale =
beta-alpha;
1311 const Element shift = alpha/scale;
1313 Element * ep = GetMatrixArray();
1314 const Element *
const fp = ep+fNrows;
1316 *ep++ = scale*(
Drand(seed)+shift);
1322template<
class Element>
1326 for (Element *ep = fElements; ep < fElements+fNrows; ep++)
1335template<
class Element>
1340 Element *ep = fElements;
1341 for (action.
fI = fRowLwb; action.
fI < fRowLwb+fNrows; action.
fI++)
1353template<
class Element>
1356 gROOT->ProcessLine(
Form(
"THistPainter::PaintSpecialObjects((TObject*)0x%lx,\"%s\");",
1363template<
class Element>
1367 Error(
"Print",
"Vector is invalid");
1371 printf(
"\nVector (%d) %s is as follows",fNrows,flag);
1373 printf(
"\n\n | %6d |", 1);
1374 printf(
"\n%s\n",
"------------------");
1375 for (
Int_t i = 0; i < fNrows; i++) {
1376 printf(
"%4d |",i+fRowLwb);
1378 printf(
"%g \n",(*
this)(i+fRowLwb));
1386template<
class Element>
1390 return (memcmp(
v1.GetMatrixArray(),
v2.GetMatrixArray(),
v1.GetNrows()*
sizeof(Element)) == 0);
1396template<
class Element>
1401 Error(
"operator*(const TVectorT<Element> &,const TVectorT<Element> &)",
"vector's are incompatible");
1412template<
class Element>
1423template<
class Element>
1434template<
class Element>
1439 return Add(target,Element(1.0),
a,source);
1445template<
class Element>
1450 return Add(target,Element(1.0),
a,source);
1456template<
class Element>
1461 return Add(target,Element(1.0),
a,source);
1467template<
class Element>
1478template<
class Element>
1481 const Element *v1p =
v1.GetMatrixArray();
1482 const Element *v2p =
v2.GetMatrixArray();
1484 const Element *
const fv1p = v1p+
v1.GetNrows();
1486 sum += *v1p++ * *v2p++;
1494template <
class Element1,
class Element2>
1510template <
class Element1,
class Element2,
class Element3>
1517 const Element1 *
const m_last = mp + target.
GetNoElements();
1519 const Element2 * v1p =
v1.GetMatrixArray();
1520 const Element2 *
const v1_last = v1p +
v1.GetNrows();
1522 const Element3 *
const v20 =
v2.GetMatrixArray();
1523 const Element3 * v2p = v20;
1524 const Element3 *
const v2_last = v2p +
v2.GetNrows();
1526 while (v1p < v1_last) {
1528 while (v2p < v2_last) {
1529 *mp++ = *v1p * *v2p++ ;
1534 R__ASSERT(v1p == v1_last && mp == m_last && v2p == v2_last);
1542template <
class Element1,
class Element2,
class Element3>
1548 ::Error(
"Mult",
"Vector v1 and matrix m incompatible");
1552 ::Error(
"Mult",
"Matrix m and vector v2 incompatible");
1557 const Element1 * v1p =
v1.GetMatrixArray();
1558 const Element1 *
const v1_last = v1p +
v1.GetNrows();
1560 const Element2 * mp =
m.GetMatrixArray();
1561 const Element2 *
const m_last = mp +
m.GetNoElements();
1563 const Element3 *
const v20 =
v2.GetMatrixArray();
1564 const Element3 * v2p = v20;
1565 const Element3 *
const v2_last = v2p +
v2.GetNrows();
1570 while (v1p < v1_last) {
1572 while (v2p < v2_last) {
1573 dot += *mp++ * *v2p++;
1575 sum += *v1p++ * dot;
1579 R__ASSERT(v1p == v1_last && mp == m_last && v2p == v2_last);
1587template<
class Element>
1591 Error(
"Add(TVectorT<Element> &,Element,const TVectorT<Element> &)",
"vector's are incompatible");
1597 const Element *
const ftp = tp+target.
GetNrows();
1598 if (scalar == 1.0 ) {
1601 }
else if (scalar == -1.0) {
1606 *tp++ += scalar * *sp++;
1616template<
class Element>
1623 if (
a.GetNrows() != target.
GetNrows() ||
a.GetRowLwb() != target.
GetLwb()) {
1624 Error(
"Add(TVectorT &,const TMatrixT &,const TVectorT &)",
"target vector and matrix are incompatible");
1629 if (
a.GetNcols() != source.
GetNrows() ||
a.GetColLwb() != source.
GetLwb()) {
1630 Error(
"Add(TVectorT &,const TMatrixT &,const TVectorT &)",
"source vector and matrix are incompatible");
1636 const Element * mp =
a.GetMatrixArray();
1639 if (
typeid(Element) ==
typeid(
Double_t))
1640 cblas_dsymv(CblasRowMajor,CblasUpper,fNrows,scalar,mp,
1641 fNrows,sp,1,0.0,tp,1);
1642 else if (
typeid(Element) !=
typeid(
Float_t))
1643 cblas_ssymv(CblasRowMajor,CblasUpper,fNrows,scalar,mp,
1644 fNrows,sp,1,0.0,tp,1);
1646 Error(
"operator*=",
"type %s not implemented in BLAS library",
typeid(Element));
1648 const Element *
const sp_last = sp+source.
GetNrows();
1649 const Element *
const tp_last = tp+target.
GetNrows();
1650 if (scalar == 1.0) {
1651 while (tp < tp_last) {
1652 const Element *sp1 = sp;
1654 while (sp1 < sp_last)
1655 sum += *sp1++ * *mp++;
1658 }
else if (scalar == 0.0) {
1659 while (tp < tp_last) {
1660 const Element *sp1 = sp;
1662 while (sp1 < sp_last)
1663 sum += *sp1++ * *mp++;
1666 }
else if (scalar == -1.0) {
1667 while (tp < tp_last) {
1668 const Element *sp1 = sp;
1670 while (sp1 < sp_last)
1671 sum += *sp1++ * *mp++;
1675 while (tp < tp_last) {
1676 const Element *sp1 = sp;
1678 while (sp1 < sp_last)
1679 sum += *sp1++ * *mp++;
1680 *tp++ += scalar *
sum;
1694template<
class Element>
1702 if (
a.GetNrows() != target.
GetNrows() ||
a.GetRowLwb() != target.
GetLwb()) {
1703 Error(
"Add(TVectorT &,const TMatrixT &,const TVectorT &)",
"target vector and matrix are incompatible");
1709 const Element * mp =
a.GetMatrixArray();
1712 if (
typeid(Element) ==
typeid(
Double_t))
1713 cblas_dsymv(CblasRowMajor,CblasUpper,fNrows,1.0,mp,
1714 fNrows,sp,1,0.0,tp,1);
1715 else if (
typeid(Element) !=
typeid(
Float_t))
1716 cblas_ssymv(CblasRowMajor,CblasUpper,fNrows,1.0,mp,
1717 fNrows,sp,1,0.0,tp,1);
1719 Error(
"operator*=",
"type %s not implemented in BLAS library",
typeid(Element));
1721 const Element *
const sp_last = sp+source.
GetNrows();
1722 const Element *
const tp_last = tp+target.
GetNrows();
1723 if (scalar == 1.0) {
1724 while (tp < tp_last) {
1725 const Element *sp1 = sp;
1727 while (sp1 < sp_last)
1728 sum += *sp1++ * *mp++;
1731 }
else if (scalar == 0.0) {
1732 while (tp < tp_last) {
1733 const Element *sp1 = sp;
1735 while (sp1 < sp_last)
1736 sum += *sp1++ * *mp++;
1739 }
else if (scalar == -1.0) {
1740 while (tp < tp_last) {
1741 const Element *sp1 = sp;
1743 while (sp1 < sp_last)
1744 sum += *sp1++ * *mp++;
1748 while (tp < tp_last) {
1749 const Element *sp1 = sp;
1751 while (sp1 < sp_last)
1752 sum += *sp1++ * *mp++;
1753 *tp++ += scalar *
sum;
1756 R__ASSERT(mp ==
a.GetMatrixArray()+
a.GetNoElements());
1766template<
class Element>
1773 if (
a.GetNrows() != target.
GetNrows() ||
a.GetRowLwb() != target.
GetLwb()) {
1774 Error(
"Add(TVectorT &,const TMatrixT &,const TVectorT &)",
"target vector and matrix are incompatible");
1779 if (
a.GetNcols() != source.
GetNrows() ||
a.GetColLwb() != source.
GetLwb()) {
1780 Error(
"Add(TVectorT &,const TMatrixT &,const TVectorT &)",
"source vector and matrix are incompatible");
1785 const Int_t *
const pRowIndex =
a.GetRowIndexArray();
1786 const Int_t *
const pColIndex =
a.GetColIndexArray();
1787 const Element *
const mp =
a.GetMatrixArray();
1792 if (scalar == 1.0) {
1793 for (
Int_t irow = 0; irow <
a.GetNrows(); irow++) {
1794 const Int_t sIndex = pRowIndex[irow];
1795 const Int_t eIndex = pRowIndex[irow+1];
1797 for (
Int_t index = sIndex; index < eIndex; index++) {
1798 const Int_t icol = pColIndex[index];
1799 sum += mp[index]*sp[icol];
1803 }
else if (scalar == 0.0) {
1804 for (
Int_t irow = 0; irow <
a.GetNrows(); irow++) {
1805 const Int_t sIndex = pRowIndex[irow];
1806 const Int_t eIndex = pRowIndex[irow+1];
1808 for (
Int_t index = sIndex; index < eIndex; index++) {
1809 const Int_t icol = pColIndex[index];
1810 sum += mp[index]*sp[icol];
1814 }
else if (scalar == -1.0) {
1815 for (
Int_t irow = 0; irow <
a.GetNrows(); irow++) {
1816 const Int_t sIndex = pRowIndex[irow];
1817 const Int_t eIndex = pRowIndex[irow+1];
1819 for (
Int_t index = sIndex; index < eIndex; index++) {
1820 const Int_t icol = pColIndex[index];
1821 sum += mp[index]*sp[icol];
1826 for (
Int_t irow = 0; irow <
a.GetNrows(); irow++) {
1827 const Int_t sIndex = pRowIndex[irow];
1828 const Int_t eIndex = pRowIndex[irow+1];
1830 for (
Int_t index = sIndex; index < eIndex; index++) {
1831 const Int_t icol = pColIndex[index];
1832 sum += mp[index]*sp[icol];
1834 tp[irow] += scalar *
sum;
1844template<
class Element>
1849 Error(
"AddElemMult(TVectorT<Element> &,Element,const TVectorT<Element> &,const TVectorT<Element> &)",
1850 "vector's are incompatible");
1857 const Element *
const ftp = tp+target.
GetNrows();
1859 if (scalar == 1.0 ) {
1861 *tp++ += *sp1++ * *sp2++;
1862 }
else if (scalar == -1.0) {
1864 *tp++ -= *sp1++ * *sp2++;
1867 *tp++ += scalar * *sp1++ * *sp2++;
1877template<
class Element>
1883 Error(
"AddElemMult(TVectorT<Element> &,Element,const TVectorT<Element> &,const TVectorT<Element> &,onst TVectorT<Element> &)",
1884 "vector's are incompatible");
1892 const Element *
const ftp = tp+target.
GetNrows();
1894 if (scalar == 1.0 ) {
1895 while ( tp < ftp ) {
1896 if (*mp) *tp += *sp1 * *sp2;
1897 mp++; tp++; sp1++; sp2++;
1899 }
else if (scalar == -1.0) {
1900 while ( tp < ftp ) {
1901 if (*mp) *tp -= *sp1 * *sp2;
1902 mp++; tp++; sp1++; sp2++;
1905 while ( tp < ftp ) {
1906 if (*mp) *tp += scalar * *sp1 * *sp2;
1907 mp++; tp++; sp1++; sp2++;
1917template<
class Element>
1922 Error(
"AddElemDiv(TVectorT<Element> &,Element,const TVectorT<Element> &,const TVectorT<Element> &)",
1923 "vector's are incompatible");
1930 const Element *
const ftp = tp+target.
GetNrows();
1932 if (scalar == 1.0 ) {
1933 while ( tp < ftp ) {
1938 Error(
"AddElemDiv",
"source2 (%d) is zero",irow);
1942 }
else if (scalar == -1.0) {
1943 while ( tp < ftp ) {
1948 Error(
"AddElemDiv",
"source2 (%d) is zero",irow);
1953 while ( tp < ftp ) {
1955 *tp += scalar * *sp1 / *sp2;
1958 Error(
"AddElemDiv",
"source2 (%d) is zero",irow);
1971template<
class Element>
1977 Error(
"AddElemDiv(TVectorT<Element> &,Element,const TVectorT<Element> &,const TVectorT<Element> &,onst TVectorT<Element> &)",
1978 "vector's are incompatible");
1986 const Element *
const ftp = tp+target.
GetNrows();
1988 if (scalar == 1.0 ) {
1989 while ( tp < ftp ) {
1995 Error(
"AddElemDiv",
"source2 (%d) is zero",irow);
1998 mp++; tp++; sp1++; sp2++;
2000 }
else if (scalar == -1.0) {
2001 while ( tp < ftp ) {
2007 Error(
"AddElemDiv",
"source2 (%d) is zero",irow);
2010 mp++; tp++; sp1++; sp2++;
2013 while ( tp < ftp ) {
2016 *tp += scalar * *sp1 / *sp2;
2019 Error(
"AddElemDiv",
"source2 (%d) is zero",irow);
2022 mp++; tp++; sp1++; sp2++;
2032template<
class Element>
2036 Error(
"ElementMult(TVectorT<Element> &,const TVectorT<Element> &)",
"vector's are incompatible");
2042 const Element *
const ftp = tp+target.
GetNrows();
2052template<
class Element>
2056 Error(
"ElementMult(TVectorT<Element> &,const TVectorT<Element> &,const TVectorT<Element> &)",
"vector's are incompatible");
2063 const Element *
const ftp = tp+target.
GetNrows();
2064 while ( tp < ftp ) {
2065 if (*mp) *tp *= *sp;
2075template<
class Element>
2079 Error(
"ElementDiv(TVectorT<Element> &,const TVectorT<Element> &)",
"vector's are incompatible");
2085 const Element *
const ftp = tp+target.
GetNrows();
2086 while ( tp < ftp ) {
2091 Error(
"ElementDiv",
"source (%d) is zero",irow);
2101template<
class Element>
2105 Error(
"ElementDiv(TVectorT<Element> &,const TVectorT<Element> &,const TVectorT<Element> &)",
"vector's are incompatible");
2112 const Element *
const ftp = tp+target.
GetNrows();
2113 while ( tp < ftp ) {
2119 Error(
"ElementDiv",
"source (%d) is zero",irow);
2131template<
class Element1,
class Element2>
2134 if (!
v1.IsValid()) {
2136 ::Error(
"AreCompatible",
"vector 1 not valid");
2139 if (!
v2.IsValid()) {
2141 ::Error(
"AreCompatible",
"vector 2 not valid");
2145 if (
v1.GetNrows() !=
v2.GetNrows() ||
v1.GetLwb() !=
v2.GetLwb()) {
2147 ::Error(
"AreCompatible",
"matrices 1 and 2 not compatible");
2157template<
class Element1,
class Element2>
2162 ::Error(
"AreCompatible",
"Matrix not valid");
2167 ::Error(
"AreCompatible",
"vector not valid");
2171 if (
m.GetNcols() !=
v.GetNrows() ) {
2173 ::Error(
"AreCompatible",
"matrix and vector not compatible");
2183template<
class Element1,
class Element2>
2188 ::Error(
"AreCompatible",
"Matrix not valid");
2193 ::Error(
"AreCompatible",
"vector not valid");
2197 if (
v.GetNrows() !=
m.GetNrows() ) {
2199 ::Error(
"AreCompatible",
"vector and matrix not compatible");
2209template<
class Element>
2213 Error(
"Compare(const TVectorT<Element> &,const TVectorT<Element> &)",
"vectors are incompatible");
2217 printf(
"\n\nComparison of two TVectorTs:\n");
2223 Element difmax = -1;
2224 const Element *mp1 =
v1.GetMatrixArray();
2225 const Element *mp2 =
v2.GetMatrixArray();
2227 for (
Int_t i = 0; i <
v1.GetNrows(); i++) {
2228 const Element mv1 = *mp1++;
2229 const Element mv2 = *mp2++;
2232 if (diff > difmax) {
2241 imax +=
v1.GetLwb();
2242 printf(
"\nMaximal discrepancy \t\t%g",difmax);
2243 printf(
"\n occured at the point\t\t(%d)",imax);
2244 const Element mv1 =
v1(imax);
2245 const Element mv2 =
v2(imax);
2246 printf(
"\n Vector 1 element is \t\t%g",mv1);
2247 printf(
"\n Vector 2 element is \t\t%g",mv2);
2248 printf(
"\n Absolute error v2[i]-v1[i]\t\t%g",mv2-mv1);
2249 printf(
"\n Relative error\t\t\t\t%g\n",
2252 printf(
"\n||Vector 1|| \t\t\t%g",norm1);
2253 printf(
"\n||Vector 2|| \t\t\t%g",norm2);
2254 printf(
"\n||Vector1-Vector2||\t\t\t\t%g",ndiff);
2255 printf(
"\n||Vector1-Vector2||/sqrt(||Vector1|| ||Vector2||)\t%g\n\n",
2262template<
class Element>
2267 Element maxDevObs = 0;
2272 for (
Int_t i =
v.GetLwb(); i <=
v.GetUpb(); i++) {
2274 if (dev > maxDevObs) {
2284 printf(
"Largest dev for (%d); dev = |%g - %g| = %g\n",imax,
v(imax),val,maxDevObs);
2285 if (maxDevObs > maxDevAllow)
2286 Error(
"VerifyVectorValue",
"Deviation > %g\n",maxDevAllow);
2289 if (maxDevObs > maxDevAllow)
2297template<
class Element>
2302 Element maxDevObs = 0;
2310 for (
Int_t i =
v1.GetLwb(); i <=
v1.GetUpb(); i++) {
2312 if (dev > maxDevObs) {
2322 printf(
"Largest dev for (%d); dev = |%g - %g| = %g\n",imax,
v1(imax),
v2(imax),maxDevObs);
2323 if (maxDevObs > maxDevAllow)
2324 Error(
"VerifyVectorIdentity",
"Deviation > %g\n",maxDevAllow);
2327 if (maxDevObs > maxDevAllow) {
2336template<
class Element>
2346 TObject::Streamer(R__b);
2351 if (fNrows > 0 && fNrows <= kSizeMax) {
2352 memcpy(fDataStack,fElements,fNrows*
sizeof(Element));
2353 delete [] fElements;
2354 fElements = fDataStack;
2355 }
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.
EvaluateInfo init(std::vector< RooRealProxy > parameters, std::vector< ArrayWrapper * > wrappers, std::vector< double * > arrays, size_t begin, size_t batchSize)
RPY_EXPORTED 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)