63 template<
class Element>
66 if (size == 0)
return 0;
68 if ( size <= kSizeMax )
71 Element *heap =
new Element[size];
80 template<
class Element>
84 Error(
"Add(TVectorT<Element> &)",
"vector's not compatible");
89 Element *tp = this->GetMatrixArray();
90 const Element *
const tp_last = tp+fNrows;
98 template<
class Element>
103 Error(
"Add(TVectorT<Element> &)",
"vectors not compatible");
110 Element *tp = this->GetMatrixArray();
111 const Element *
const tp_last = tp+fNrows;
113 *tp++ = *sv1++ + *sv2++;
120 template<
class Element>
124 if (copySize == 0 || oldp == newp)
return 0;
126 if ( newSize <= kSizeMax && oldSize <= kSizeMax ) {
129 for (
Int_t i = copySize-1; i >= 0; i--)
132 for (
Int_t i = 0; i < copySize; i++)
137 memcpy(newp,oldp,copySize*
sizeof(Element));
147 template<
class Element>
157 Error(
"Allocate",
"nrows=%d",nrows);
165 fElements = New_m(fNrows);
167 memset(fElements,0,fNrows*
sizeof(Element));
173 template<
class Element>
182 template<
class Element>
191 template<
class Element>
195 SetElements(elements);
201 template<
class Element>
205 SetElements(elements);
211 template<
class Element>
222 template<
class Element>
234 template<
class Element>
246 template<
class Element>
261 template<
class Element>
265 Error(
"TVectorT(Int_t, Int_t, ...)",
"upb(%d) < lwb(%d)",upb,lwb);
272 va_start(args,
va_(iv1));
276 for (
Int_t i = lwb+1; i <= upb; i++)
277 (*
this)(i) = (Element)va_arg(args,
Double_t);
279 if (strcmp((
char *)va_arg(args,
char *),
"END"))
280 Error(
"TVectorT(Int_t, Int_t, ...)",
"argument list must be terminated by \"END\"");
290 template<
class Element>
295 Error(
"ResizeTo(lwb,upb)",
"Not owner of data array,cannot resize");
299 const Int_t new_nrows = upb-lwb+1;
303 if (fNrows == new_nrows && fRowLwb == lwb)
305 else if (new_nrows == 0) {
310 Element *elements_old = GetMatrixArray();
311 const Int_t nrows_old = fNrows;
312 const Int_t rowLwb_old = fRowLwb;
316 if (fNrows > kSizeMax || nrows_old > kSizeMax)
317 memset(GetMatrixArray(),0,fNrows*
sizeof(Element));
318 else if (fNrows > nrows_old)
319 memset(GetMatrixArray()+nrows_old,0,(fNrows-nrows_old)*
sizeof(Element));
323 const Int_t rowUpb_copy =
TMath::Min(fRowLwb+fNrows-1,rowLwb_old+nrows_old-1);
324 const Int_t nrows_copy = rowUpb_copy-rowLwb_copy+1;
326 const Int_t nelems_new = fNrows;
327 Element *elements_new = GetMatrixArray();
328 if (nrows_copy > 0) {
329 const Int_t rowOldOff = rowLwb_copy-rowLwb_old;
330 const Int_t rowNewOff = rowLwb_copy-fRowLwb;
331 Memcpy_m(elements_new+rowNewOff,elements_old+rowOldOff,nrows_copy,nelems_new,nrows_old);
334 Delete_m(nrows_old,elements_old);
345 template<
class Element>
349 Error(
"Use",
"upb(%d) < lwb(%d)",upb,lwb);
369 template<
class Element>
374 if (row_lwb < fRowLwb || row_lwb > fRowLwb+fNrows-1) {
375 Error(
"GetSub",
"row_lwb out of bounds");
378 if (row_upb < fRowLwb || row_upb > fRowLwb+fNrows-1) {
379 Error(
"GetSub",
"row_upb out of bounds");
382 if (row_upb < row_lwb) {
383 Error(
"GetSub",
"row_upb < row_lwb");
396 row_upb_sub = row_upb-row_lwb;
398 row_lwb_sub = row_lwb;
399 row_upb_sub = row_upb;
402 target.
ResizeTo(row_lwb_sub,row_upb_sub);
403 const Int_t nrows_sub = row_upb_sub-row_lwb_sub+1;
405 const Element *ap = this->GetMatrixArray()+(row_lwb-fRowLwb);
408 for (
Int_t irow = 0; irow < nrows_sub; irow++)
418 template<
class Element>
425 if (row_lwb < fRowLwb && row_lwb > fRowLwb+fNrows-1) {
426 Error(
"SetSub",
"row_lwb outof bounds");
429 if (row_lwb+source.
GetNrows() > fRowLwb+fNrows) {
430 Error(
"SetSub",
"source vector too large");
438 Element *ap = this->GetMatrixArray()+(row_lwb-fRowLwb);
440 for (
Int_t irow = 0; irow < nRows_source; irow++)
449 template<
class Element>
453 memset(this->GetMatrixArray(),0,fNrows*
sizeof(Element));
460 template<
class Element>
465 Element *ep = this->GetMatrixArray();
466 const Element *
const fp = ep+fNrows;
478 template<
class Element>
483 Element *ep = this->GetMatrixArray();
484 const Element *
const fp = ep+fNrows;
496 template<
class Element>
501 Element *ep = this->GetMatrixArray();
502 const Element *
const fp = ep+fNrows;
508 Error(
"Sqrt()",
"v(%ld) = %g < 0",
Long_t(ep-this->GetMatrixArray()),(
float)*ep);
518 template<
class Element>
523 Element *ep = this->GetMatrixArray();
524 const Element *
const fp = ep+fNrows;
530 Error(
"Invert()",
"v(%ld) = %g",
Long_t(ep-this->GetMatrixArray()),(
float)*ep);
540 template<
class Element>
544 Error(
"SelectNonZeros(const TVectorT<Element> &",
"vector's not compatible");
549 Element *ep = this->GetMatrixArray();
550 const Element *
const fp = ep+fNrows;
563 template<
class Element>
569 const Element *ep = this->GetMatrixArray();
570 const Element *
const fp = ep+fNrows;
580 template<
class Element>
586 const Element *ep = this->GetMatrixArray();
587 const Element *
const fp = ep+fNrows;
589 norm += (*ep) * (*ep);
599 template<
class Element>
605 const Element *ep = this->GetMatrixArray();
606 const Element *
const fp = ep+fNrows;
616 template<
class Element>
621 Int_t nr_nonzeros = 0;
622 const Element *ep = this->GetMatrixArray();
623 const Element *
const fp = ep+fNrows;
625 if (*ep++) nr_nonzeros++;
633 template<
class Element>
639 const Element *ep = this->GetMatrixArray();
640 const Element *
const fp = ep+fNrows;
650 template<
class Element>
656 return fElements[index];
662 template<
class Element>
668 return fElements[index];
676 template<
class Element>
680 Error(
"operator=(const TVectorT<Element> &)",
"vectors not compatible");
694 template<
class Element>
703 Error(
"operator=(const TMatrixTRow_const &)",
"vector and row not compatible");
709 const Element *rp = mr.
GetPtr();
710 Element *ep = this->GetMatrixArray();
711 const Element *
const fp = ep+fNrows;
725 template<
class Element>
734 Error(
"operator=(const TMatrixTColumn_const &)",
"vector and column not compatible");
740 const Element *cp = mc.
GetPtr();
741 Element *ep = this->GetMatrixArray();
742 const Element *
const fp = ep+fNrows;
756 template<
class Element>
765 Error(
"operator=(const TMatrixTDiag_const &)",
"vector and matrix-diagonal not compatible");
771 const Element *dp = md.
GetPtr();
772 Element *ep = this->GetMatrixArray();
773 const Element *
const fp = ep+fNrows;
788 template<
class Element>
797 Error(
"operator=(const TMatrixTSparseRow_const &)",
"vector and row not compatible");
803 const Element *
const prData = mr.
GetDataPtr();
805 Element *
const pvData = this->GetMatrixArray();
807 memset(pvData,0,fNrows*
sizeof(Element));
808 for (
Int_t index = 0; index < nIndex; index++) {
809 const Int_t icol = prCol[index];
810 pvData[icol] = prData[index];
819 template<
class Element>
828 Error(
"operator=(const TMatrixTSparseDiag_const &)",
"vector and matrix-diagonal not compatible");
833 Element *
const pvData = this->GetMatrixArray();
834 for (
Int_t idiag = 0; idiag < fNrows; idiag++)
835 pvData[idiag] = md(idiag);
843 template<
class Element>
848 Element *ep = this->GetMatrixArray();
849 const Element *
const fp = ep+fNrows;
859 template<
class Element>
864 Element *ep = this->GetMatrixArray();
865 const Element *
const fp = ep+fNrows;
875 template<
class Element>
880 Element *ep = this->GetMatrixArray();
881 const Element *
const fp = ep+fNrows;
891 template<
class Element>
896 Element *ep = this->GetMatrixArray();
897 const Element *
const fp = ep+fNrows;
907 template<
class Element>
911 Error(
"operator+=(const TVectorT<Element> &)",
"vector's not compatible");
916 Element *tp = this->GetMatrixArray();
917 const Element *
const tp_last = tp+fNrows;
927 template<
class Element>
931 Error(
"operator-=(const TVectorT<Element> &)",
"vector's not compatible");
936 Element *tp = this->GetMatrixArray();
937 const Element *
const tp_last = tp+fNrows;
948 template<
class Element>
955 Error(
"operator*=(const TMatrixT &)",
"vector and matrix incompatible");
961 if (doResize && !fIsOwner) {
962 Error(
"operator*=(const TMatrixT &)",
"vector has to be resized but not owner");
966 Element work[kWorkMax];
968 Element *elements_old = work;
969 const Int_t nrows_old = fNrows;
970 if (nrows_old > kWorkMax) {
972 elements_old =
new Element[nrows_old];
974 memcpy(elements_old,fElements,nrows_old*
sizeof(Element));
979 ResizeTo(rowlwb_new,rowlwb_new+nrows_new-1);
981 memset(fElements,0,fNrows*
sizeof(Element));
984 Element *tp = this->GetMatrixArray();
986 if (
typeid(Element) ==
typeid(
Double_t))
988 a.
GetNcols(),elements_old,1,0.0,tp,1);
989 else if (
typeid(Element) !=
typeid(
Float_t))
991 a.
GetNcols(),elements_old,1,0.0,tp,1);
993 Error(
"operator*=",
"type %s not implemented in BLAS library",
typeid(Element));
995 const Element *
const tp_last = tp+fNrows;
996 while (tp < tp_last) {
998 for (
const Element *sp = elements_old; sp < elements_old+nrows_old; )
999 sum += *sp++ * *mp++;
1006 delete [] elements_old;
1015 template<
class Element>
1022 Error(
"operator*=(const TMatrixTSparse &)",
"vector and matrix incompatible");
1028 if (doResize && !fIsOwner) {
1029 Error(
"operator*=(const TMatrixTSparse &)",
"vector has to be resized but not owner");
1033 Element work[kWorkMax];
1035 Element *elements_old = work;
1036 const Int_t nrows_old = fNrows;
1037 if (nrows_old > kWorkMax) {
1038 isAllocated =
kTRUE;
1039 elements_old =
new Element[nrows_old];
1041 memcpy(elements_old,fElements,nrows_old*
sizeof(Element));
1046 ResizeTo(rowlwb_new,rowlwb_new+nrows_new-1);
1048 memset(fElements,0,fNrows*
sizeof(Element));
1054 const Element *
const sp = elements_old;
1055 Element * tp = this->GetMatrixArray();
1057 for (
Int_t irow = 0; irow < fNrows; irow++) {
1058 const Int_t sIndex = pRowIndex[irow];
1059 const Int_t eIndex = pRowIndex[irow+1];
1061 for (
Int_t index = sIndex; index < eIndex; index++) {
1062 const Int_t icol = pColIndex[index];
1063 sum += mp[index]*sp[icol];
1069 delete [] elements_old;
1078 template<
class Element>
1085 Error(
"operator*=(const TMatrixTSym &)",
"vector and matrix incompatible");
1090 Element work[kWorkMax];
1092 Element *elements_old = work;
1093 const Int_t nrows_old = fNrows;
1094 if (nrows_old > kWorkMax) {
1095 isAllocated =
kTRUE;
1096 elements_old =
new Element[nrows_old];
1098 memcpy(elements_old,fElements,nrows_old*
sizeof(Element));
1099 memset(fElements,0,fNrows*
sizeof(Element));
1102 Element *tp = this->GetMatrixArray();
1104 if (
typeid(Element) ==
typeid(
Double_t))
1105 cblas_dsymv(CblasRowMajor,CblasUpper,fNrows,1.0,mp,
1106 fNrows,elements_old,1,0.0,tp,1);
1107 else if (
typeid(Element) !=
typeid(
Float_t))
1108 cblas_ssymv(CblasRowMajor,CblasUpper,fNrows,1.0,mp,
1109 fNrows,elements_old,1,0.0,tp,1);
1111 Error(
"operator*=",
"type %s not implemented in BLAS library",
typeid(Element));
1113 const Element *
const tp_last = tp+fNrows;
1114 while (tp < tp_last) {
1116 for (
const Element *sp = elements_old; sp < elements_old+nrows_old; )
1117 sum += *sp++ * *mp++;
1124 delete [] elements_old;
1132 template<
class Element>
1137 const Element *ep = this->GetMatrixArray();
1138 const Element *
const fp = ep+fNrows;
1140 if (!(*ep++ == val))
1149 template<
class Element>
1154 const Element *ep = this->GetMatrixArray();
1155 const Element *
const fp = ep+fNrows;
1157 if (!(*ep++ != val))
1166 template<
class Element>
1171 const Element *ep = this->GetMatrixArray();
1172 const Element *
const fp = ep+fNrows;
1183 template<
class Element>
1188 const Element *ep = this->GetMatrixArray();
1189 const Element *
const fp = ep+fNrows;
1191 if (!(*ep++ <= val))
1200 template<
class Element>
1205 const Element *ep = this->GetMatrixArray();
1206 const Element *
const fp = ep+fNrows;
1217 template<
class Element>
1222 const Element *ep = this->GetMatrixArray();
1223 const Element *
const fp = ep+fNrows;
1225 if (!(*ep++ >= val))
1234 template<
class Element>
1238 Error(
"MatchesNonZeroPattern(const TVectorT&)",
"vector's not compatible");
1243 const Element *ep = this->GetMatrixArray();
1244 const Element *
const fp = ep+fNrows;
1246 if (*sp == 0.0 && *ep != 0.0)
1257 template<
class Element>
1261 Error(
"SomePositive(const TVectorT&)",
"vector's not compatible");
1266 const Element *ep = this->GetMatrixArray();
1267 const Element *
const fp = ep+fNrows;
1269 if (*sp != 0.0 && *ep <= 0.0)
1280 template<
class Element>
1284 Error(
"AddSomeConstant(Element,const TVectorT&)(const TVectorT&)",
"vector's not compatible");
1287 Element *ep = this->GetMatrixArray();
1288 const Element *
const fp = ep+fNrows;
1301 template<
class Element>
1306 const Element scale = beta-alpha;
1307 const Element shift = alpha/scale;
1309 Element * ep = GetMatrixArray();
1310 const Element *
const fp = ep+fNrows;
1312 *ep++ = scale*(
Drand(seed)+shift);
1318 template<
class Element>
1322 for (Element *ep = fElements; ep < fElements+fNrows; ep++)
1331 template<
class Element>
1336 Element *ep = fElements;
1337 for (action.
fI = fRowLwb; action.
fI < fRowLwb+fNrows; action.
fI++)
1349 template<
class Element>
1352 gROOT->ProcessLine(
Form(
"THistPainter::PaintSpecialObjects((TObject*)0x%lx,\"%s\");",
1359 template<
class Element>
1363 Error(
"Print",
"Vector is invalid");
1367 printf(
"\nVector (%d) %s is as follows",fNrows,flag);
1369 printf(
"\n\n | %6d |", 1);
1370 printf(
"\n%s\n",
"------------------");
1371 for (
Int_t i = 0; i < fNrows; i++) {
1372 printf(
"%4d |",i+fRowLwb);
1374 printf(
"%g \n",(*
this)(i+fRowLwb));
1382 template<
class Element>
1392 template<
class Element>
1397 Error(
"operator*(const TVectorT<Element> &,const TVectorT<Element> &)",
"vector's are incompatible");
1408 template<
class Element>
1419 template<
class Element>
1430 template<
class Element>
1435 return Add(target,Element(1.0),a,source);
1441 template<
class Element>
1446 return Add(target,Element(1.0),a,source);
1452 template<
class Element>
1457 return Add(target,Element(1.0),a,source);
1463 template<
class Element>
1474 template<
class Element>
1480 const Element *
const fv1p = v1p+v1.
GetNrows();
1482 sum += *v1p++ * *v2p++;
1490 template <
class Element1,
class Element2>
1506 template <
class Element1,
class Element2,
class Element3>
1513 const Element1 *
const m_last = mp + target.
GetNoElements();
1516 const Element2 *
const v1_last = v1p + v1.
GetNrows();
1519 const Element3 * v2p = v20;
1520 const Element3 *
const v2_last = v2p + v2.
GetNrows();
1522 while (v1p < v1_last) {
1524 while (v2p < v2_last) {
1525 *mp++ = *v1p * *v2p++ ;
1530 R__ASSERT(v1p == v1_last && mp == m_last && v2p == v2_last);
1538 template <
class Element1,
class Element2,
class Element3>
1544 ::Error(
"Mult",
"Vector v1 and matrix m incompatible");
1548 ::Error(
"Mult",
"Matrix m and vector v2 incompatible");
1554 const Element1 *
const v1_last = v1p + v1.
GetNrows();
1560 const Element3 * v2p = v20;
1561 const Element3 *
const v2_last = v2p + v2.
GetNrows();
1566 while (v1p < v1_last) {
1568 while (v2p < v2_last) {
1569 dot += *mp++ * *v2p++;
1571 sum += *v1p++ *
dot;
1575 R__ASSERT(v1p == v1_last && mp == m_last && v2p == v2_last);
1583 template<
class Element>
1587 Error(
"Add(TVectorT<Element> &,Element,const TVectorT<Element> &)",
"vector's are incompatible");
1593 const Element *
const ftp = tp+target.
GetNrows();
1594 if (scalar == 1.0 ) {
1597 }
else if (scalar == -1.0) {
1602 *tp++ += scalar * *sp++;
1612 template<
class Element>
1620 Error(
"Add(TVectorT &,const TMatrixT &,const TVectorT &)",
"target vector and matrix are incompatible");
1626 Error(
"Add(TVectorT &,const TMatrixT &,const TVectorT &)",
"source vector and matrix are incompatible");
1635 if (
typeid(Element) ==
typeid(
Double_t))
1636 cblas_dsymv(CblasRowMajor,CblasUpper,fNrows,scalar,mp,
1637 fNrows,sp,1,0.0,tp,1);
1638 else if (
typeid(Element) !=
typeid(
Float_t))
1639 cblas_ssymv(CblasRowMajor,CblasUpper,fNrows,scalar,mp,
1640 fNrows,sp,1,0.0,tp,1);
1642 Error(
"operator*=",
"type %s not implemented in BLAS library",
typeid(Element));
1644 const Element *
const sp_last = sp+source.
GetNrows();
1645 const Element *
const tp_last = tp+target.
GetNrows();
1646 if (scalar == 1.0) {
1647 while (tp < tp_last) {
1648 const Element *sp1 = sp;
1650 while (sp1 < sp_last)
1651 sum += *sp1++ * *mp++;
1654 }
else if (scalar == 0.0) {
1655 while (tp < tp_last) {
1656 const Element *sp1 = sp;
1658 while (sp1 < sp_last)
1659 sum += *sp1++ * *mp++;
1662 }
else if (scalar == -1.0) {
1663 while (tp < tp_last) {
1664 const Element *sp1 = sp;
1666 while (sp1 < sp_last)
1667 sum += *sp1++ * *mp++;
1671 while (tp < tp_last) {
1672 const Element *sp1 = sp;
1674 while (sp1 < sp_last)
1675 sum += *sp1++ * *mp++;
1676 *tp++ += scalar * sum;
1690 template<
class Element>
1699 Error(
"Add(TVectorT &,const TMatrixT &,const TVectorT &)",
"target vector and matrix are incompatible");
1708 if (
typeid(Element) ==
typeid(
Double_t))
1709 cblas_dsymv(CblasRowMajor,CblasUpper,fNrows,1.0,mp,
1710 fNrows,sp,1,0.0,tp,1);
1711 else if (
typeid(Element) !=
typeid(
Float_t))
1712 cblas_ssymv(CblasRowMajor,CblasUpper,fNrows,1.0,mp,
1713 fNrows,sp,1,0.0,tp,1);
1715 Error(
"operator*=",
"type %s not implemented in BLAS library",
typeid(Element));
1717 const Element *
const sp_last = sp+source.
GetNrows();
1718 const Element *
const tp_last = tp+target.
GetNrows();
1719 if (scalar == 1.0) {
1720 while (tp < tp_last) {
1721 const Element *sp1 = sp;
1723 while (sp1 < sp_last)
1724 sum += *sp1++ * *mp++;
1727 }
else if (scalar == 0.0) {
1728 while (tp < tp_last) {
1729 const Element *sp1 = sp;
1731 while (sp1 < sp_last)
1732 sum += *sp1++ * *mp++;
1735 }
else if (scalar == -1.0) {
1736 while (tp < tp_last) {
1737 const Element *sp1 = sp;
1739 while (sp1 < sp_last)
1740 sum += *sp1++ * *mp++;
1744 while (tp < tp_last) {
1745 const Element *sp1 = sp;
1747 while (sp1 < sp_last)
1748 sum += *sp1++ * *mp++;
1749 *tp++ += scalar * sum;
1762 template<
class Element>
1770 Error(
"Add(TVectorT &,const TMatrixT &,const TVectorT &)",
"target vector and matrix are incompatible");
1776 Error(
"Add(TVectorT &,const TMatrixT &,const TVectorT &)",
"source vector and matrix are incompatible");
1788 if (scalar == 1.0) {
1790 const Int_t sIndex = pRowIndex[irow];
1791 const Int_t eIndex = pRowIndex[irow+1];
1793 for (
Int_t index = sIndex; index < eIndex; index++) {
1794 const Int_t icol = pColIndex[index];
1795 sum += mp[index]*sp[icol];
1799 }
else if (scalar == 0.0) {
1801 const Int_t sIndex = pRowIndex[irow];
1802 const Int_t eIndex = pRowIndex[irow+1];
1804 for (
Int_t index = sIndex; index < eIndex; index++) {
1805 const Int_t icol = pColIndex[index];
1806 sum += mp[index]*sp[icol];
1810 }
else if (scalar == -1.0) {
1812 const Int_t sIndex = pRowIndex[irow];
1813 const Int_t eIndex = pRowIndex[irow+1];
1815 for (
Int_t index = sIndex; index < eIndex; index++) {
1816 const Int_t icol = pColIndex[index];
1817 sum += mp[index]*sp[icol];
1823 const Int_t sIndex = pRowIndex[irow];
1824 const Int_t eIndex = pRowIndex[irow+1];
1826 for (
Int_t index = sIndex; index < eIndex; index++) {
1827 const Int_t icol = pColIndex[index];
1828 sum += mp[index]*sp[icol];
1830 tp[irow] += scalar * sum;
1840 template<
class Element>
1845 Error(
"AddElemMult(TVectorT<Element> &,Element,const TVectorT<Element> &,const TVectorT<Element> &)",
1846 "vector's are incompatible");
1853 const Element *
const ftp = tp+target.
GetNrows();
1855 if (scalar == 1.0 ) {
1857 *tp++ += *sp1++ * *sp2++;
1858 }
else if (scalar == -1.0) {
1860 *tp++ -= *sp1++ * *sp2++;
1863 *tp++ += scalar * *sp1++ * *sp2++;
1873 template<
class Element>
1879 Error(
"AddElemMult(TVectorT<Element> &,Element,const TVectorT<Element> &,const TVectorT<Element> &,onst TVectorT<Element> &)",
1880 "vector's are incompatible");
1888 const Element *
const ftp = tp+target.
GetNrows();
1890 if (scalar == 1.0 ) {
1891 while ( tp < ftp ) {
1892 if (*mp) *tp += *sp1 * *sp2;
1893 mp++; tp++; sp1++; sp2++;
1895 }
else if (scalar == -1.0) {
1896 while ( tp < ftp ) {
1897 if (*mp) *tp -= *sp1 * *sp2;
1898 mp++; tp++; sp1++; sp2++;
1901 while ( tp < ftp ) {
1902 if (*mp) *tp += scalar * *sp1 * *sp2;
1903 mp++; tp++; sp1++; sp2++;
1913 template<
class Element>
1918 Error(
"AddElemDiv(TVectorT<Element> &,Element,const TVectorT<Element> &,const TVectorT<Element> &)",
1919 "vector's are incompatible");
1926 const Element *
const ftp = tp+target.
GetNrows();
1928 if (scalar == 1.0 ) {
1929 while ( tp < ftp ) {
1934 Error(
"AddElemDiv",
"source2 (%d) is zero",irow);
1938 }
else if (scalar == -1.0) {
1939 while ( tp < ftp ) {
1944 Error(
"AddElemDiv",
"source2 (%d) is zero",irow);
1949 while ( tp < ftp ) {
1951 *tp += scalar * *sp1 / *sp2;
1954 Error(
"AddElemDiv",
"source2 (%d) is zero",irow);
1967 template<
class Element>
1973 Error(
"AddElemDiv(TVectorT<Element> &,Element,const TVectorT<Element> &,const TVectorT<Element> &,onst TVectorT<Element> &)",
1974 "vector's are incompatible");
1982 const Element *
const ftp = tp+target.
GetNrows();
1984 if (scalar == 1.0 ) {
1985 while ( tp < ftp ) {
1991 Error(
"AddElemDiv",
"source2 (%d) is zero",irow);
1994 mp++; tp++; sp1++; sp2++;
1996 }
else if (scalar == -1.0) {
1997 while ( tp < ftp ) {
2003 Error(
"AddElemDiv",
"source2 (%d) is zero",irow);
2006 mp++; tp++; sp1++; sp2++;
2009 while ( tp < ftp ) {
2012 *tp += scalar * *sp1 / *sp2;
2015 Error(
"AddElemDiv",
"source2 (%d) is zero",irow);
2018 mp++; tp++; sp1++; sp2++;
2028 template<
class Element>
2032 Error(
"ElementMult(TVectorT<Element> &,const TVectorT<Element> &)",
"vector's are incompatible");
2038 const Element *
const ftp = tp+target.
GetNrows();
2048 template<
class Element>
2052 Error(
"ElementMult(TVectorT<Element> &,const TVectorT<Element> &,const TVectorT<Element> &)",
"vector's are incompatible");
2059 const Element *
const ftp = tp+target.
GetNrows();
2060 while ( tp < ftp ) {
2061 if (*mp) *tp *= *sp;
2071 template<
class Element>
2075 Error(
"ElementDiv(TVectorT<Element> &,const TVectorT<Element> &)",
"vector's are incompatible");
2081 const Element *
const ftp = tp+target.
GetNrows();
2082 while ( tp < ftp ) {
2087 Error(
"ElementDiv",
"source (%d) is zero",irow);
2097 template<
class Element>
2101 Error(
"ElementDiv(TVectorT<Element> &,const TVectorT<Element> &,const TVectorT<Element> &)",
"vector's are incompatible");
2108 const Element *
const ftp = tp+target.
GetNrows();
2109 while ( tp < ftp ) {
2115 Error(
"ElementDiv",
"source (%d) is zero",irow);
2127 template<
class Element1,
class Element2>
2132 ::Error(
"AreCompatible",
"vector 1 not valid");
2137 ::Error(
"AreCompatible",
"vector 2 not valid");
2143 ::Error(
"AreCompatible",
"matrices 1 and 2 not compatible");
2153 template<
class Element1,
class Element2>
2158 ::Error(
"AreCompatible",
"Matrix not valid");
2163 ::Error(
"AreCompatible",
"vector not valid");
2169 ::Error(
"AreCompatible",
"matrix and vector not compatible");
2179 template<
class Element1,
class Element2>
2184 ::Error(
"AreCompatible",
"Matrix not valid");
2189 ::Error(
"AreCompatible",
"vector not valid");
2195 ::Error(
"AreCompatible",
"vector and matrix not compatible");
2205 template<
class Element>
2209 Error(
"Compare(const TVectorT<Element> &,const TVectorT<Element> &)",
"vectors are incompatible");
2213 printf(
"\n\nComparison of two TVectorTs:\n");
2219 Element difmax = -1;
2224 const Element mv1 = *mp1++;
2225 const Element mv2 = *mp2++;
2228 if (diff > difmax) {
2238 printf(
"\nMaximal discrepancy \t\t%g",difmax);
2239 printf(
"\n occured at the point\t\t(%d)",imax);
2240 const Element mv1 =
v1(imax);
2241 const Element mv2 = v2(imax);
2242 printf(
"\n Vector 1 element is \t\t%g",mv1);
2243 printf(
"\n Vector 2 element is \t\t%g",mv2);
2244 printf(
"\n Absolute error v2[i]-v1[i]\t\t%g",mv2-mv1);
2245 printf(
"\n Relative error\t\t\t\t%g\n",
2248 printf(
"\n||Vector 1|| \t\t\t%g",norm1);
2249 printf(
"\n||Vector 2|| \t\t\t%g",norm2);
2250 printf(
"\n||Vector1-Vector2||\t\t\t\t%g",ndiff);
2251 printf(
"\n||Vector1-Vector2||/sqrt(||Vector1|| ||Vector2||)\t%g\n\n",
2258 template<
class Element>
2260 Int_t verbose,Element maxDevAllow)
2263 Element maxDevObs = 0;
2270 if (dev > maxDevObs) {
2280 printf(
"Largest dev for (%d); dev = |%g - %g| = %g\n",imax,
v(imax),val,maxDevObs);
2281 if (maxDevObs > maxDevAllow)
2282 Error(
"VerifyVectorValue",
"Deviation > %g\n",maxDevAllow);
2285 if (maxDevObs > maxDevAllow)
2293 template<
class Element>
2295 Int_t verbose, Element maxDevAllow)
2298 Element maxDevObs = 0;
2308 if (dev > maxDevObs) {
2318 printf(
"Largest dev for (%d); dev = |%g - %g| = %g\n",imax,
v1(imax),v2(imax),maxDevObs);
2319 if (maxDevObs > maxDevAllow)
2320 Error(
"VerifyVectorIdentity",
"Deviation > %g\n",maxDevAllow);
2323 if (maxDevObs > maxDevAllow) {
2332 template<
class Element>
2342 TObject::Streamer(R__b);
2347 if (fNrows > 0 && fNrows <= kSizeMax) {
2348 memcpy(fDataStack,fElements,fNrows*
sizeof(Element));
2349 delete [] fElements;
2350 fElements = fDataStack;
2351 }
else if (fNrows < 0)
2361 #ifndef ROOT_TMatrixFfwd
2364 #ifndef ROOT_TMatrixFSymfwd
2367 #ifndef ROOT_TMatrixFSparsefwd
2419 #ifndef ROOT_TMatrixDfwd
2422 #ifndef ROOT_TMatrixDSymfwd
2425 #ifndef ROOT_TMatrixDSparsefwd
2429 template class TVectorT<Double_t>;
Element Sum() const
Compute sum of elements.
TVectorT< Element > & ResizeTo(Int_t lwb, Int_t upb)
Resize the vector to [lwb:upb] .
virtual Int_t WriteClassBuffer(const TClass *cl, void *pointer)=0
Small helper to encapsulate whether to return the value pointed to by the iterator or its address...
Long64_t LocMax(Long64_t n, const T *a)
TVectorT< Element > & operator-=(Element val)
Subtract val from every element of the vector.
Element Max() const
return maximum vector element value
virtual const Element * GetMatrixArray() const
void Add(const TVectorT< Element > &v)
Add vector v to this vector.
template Double_t Dot< Double_t >(const TVectorD &v1, const TVectorD &v2)
void Draw(Option_t *option="")
Draw this vector The histogram is named "TVectorT" by default and no title.
template void Compare< Double_t >(const TVectorD &v1, const TVectorD &v2)
TVectorT< Element > & AddElemDiv(TVectorT< Element > &target, Element scalar, const TVectorT< Element > &source1, const TVectorT< Element > &source2)
Modify addition: target += scalar * ElementDiv(source1,source2) .
TMatrixT< Element1 > OuterProduct(const TVectorT< Element1 > &v1, const TVectorT< Element2 > &v2)
Return the matrix M = v1 * v2'.
void ToUpper()
Change string to upper case.
Buffer base class used for serializing objects.
template TVectorD & AddElemMult< Double_t >(TVectorD &target, Double_t scalar, const TVectorD &source1, const TVectorD &source2)
Int_t GetNoElements() const
const TMatrixTBase< Element > * GetMatrix() const
virtual Int_t CheckByteCount(UInt_t startpos, UInt_t bcnt, const TClass *clss)=0
TVectorT< Element > & Invert()
v[i] = 1/v[i]
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...
template TVectorF & ElementDiv< Float_t >(TVectorF &target, const TVectorF &source)
template Float_t Mult< Float_t, Float_t, Float_t >(const TVectorF &v1, const TMatrixF &m, const TVectorF &v2)
Short_t Min(Short_t a, Short_t b)
TVectorT< Element > operator-(const TVectorT< Element > &source1, const TVectorT< Element > &source2)
Return source1-source2.
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 .
template Bool_t AreCompatible< Float_t, Double_t >(const TVectorF &v1, const TVectorD &v2, Int_t verbose)
template TVectorD & ElementDiv< Double_t >(TVectorD &target, const TVectorD &source)
template TVectorF & AddElemDiv< Float_t >(TVectorF &target, Float_t scalar, const TVectorF &source1, const TVectorF &source2)
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...
Bool_t operator>(Element val) const
Are all vector elements > val?
TVectorT< Element > & Sqr()
Square each element of the vector.
const TMatrixTBase< Element > * GetMatrix() const
double beta(double x, double y)
Calculates the beta function.
void Randomize(Element alpha, Element beta, Double_t &seed)
randomize vector elements value
Element1 Mult(const TVectorT< Element1 > &v1, const TMatrixT< Element2 > &m, const TVectorT< Element3 > &v2)
Perform v1 * M * v2, a scalar result.
template TMatrixF OuterProduct< Float_t, Float_t >(const TVectorF &v1, const TVectorF &v2)
TVectorT< Element > & Use(Int_t lwb, Int_t upb, Element *data)
Use the array data to fill the vector lwb..upb].
Double_t dot(const TVector2 &v1, const TVector2 &v2)
template TVectorD & Add< Double_t >(TVectorD &target, Double_t scalar, const TVectorD &source)
virtual void Operation(Element &element) const =0
template TVectorF & AddElemMult< Float_t >(TVectorF &target, Float_t scalar, const TVectorF &source1, const TVectorF &source2)
TVectorT< Element > & SetSub(Int_t row_lwb, const TVectorT< Element > &source)
Insert vector source starting at [row_lwb], thereby overwriting the part [row_lwb..row_lwb+nrows_source];.
template void Compare< Float_t >(const TVectorF &v1, const TVectorF &v2)
Element operator*(const TVectorT< Element > &v1, const TVectorT< Element > &v2)
Compute the scalar product.
Element Dot(const TVectorT< Element > &v1, const TVectorT< Element > &v2)
return inner-produvt v1 . v2
TObject & operator=(const TObject &rhs)
TObject assignment operator.
template TVectorF & Add< Float_t >(TVectorF &target, Float_t scalar, const TVectorF &source)
TVectorT< Element > & Sqrt()
Take square root of all elements.
template TMatrixF & OuterProduct< Float_t, Float_t, Float_t >(TMatrixF &target, const TVectorF &v1, const TVectorF &v2)
void Error(const char *location, const char *msgfmt,...)
virtual const Element * GetMatrixArray() const
TVectorT< Element > & ElementMult(TVectorT< Element > &target, const TVectorT< Element > &source)
Multiply target by the source, element-by-element.
void Allocate(Int_t nrows, Int_t row_lwb=0, Int_t init=0)
Allocate new vector.
Element * GetMatrixArray()
const Element * GetDataPtr() const
void Print(Option_t *option="") const
Print the vector as a list of elements.
template Bool_t AreCompatible< Double_t, Double_t >(const TVectorD &v1, const TVectorD &v2, Int_t verbose)
Bool_t operator==(Element val) const
Are all vector elements equal to val?
template Bool_t VerifyVectorIdentity< Float_t >(const TVectorF &m1, const TVectorF &m2, Int_t verbose, Float_t maxDevAllow)
Bool_t operator>=(Element val) const
Are all vector elements >= val?
Int_t NonZeros() const
Compute the number of elements != 0.0.
TVectorT< Element > & Add(TVectorT< Element > &target, Element scalar, const TVectorT< Element > &source)
Modify addition: target += scalar * source.
template Bool_t VerifyVectorIdentity< Double_t >(const TVectorD &m1, const TVectorD &m2, Int_t verbose, Double_t maxDevAllow)
Element Min() const
return minimum vector element value
virtual const Int_t * GetRowIndexArray() const
Bool_t operator==(const TVectorT< Element > &v1, const TVectorT< Element > &v2)
Check to see if two vectors are identical.
Element NormInf() const
Compute the infinity-norm of the vector MAX{ |v[i]| }.
Bool_t operator!=(Element val) const
Are all vector elements not equal to val?
const TMatrixTBase< Element > * GetMatrix() const
TVectorT< Element > & operator=(const TVectorT< Element > &source)
Notice that this assignment does NOT change the ownership : if the storage space was adopted...
const Int_t * GetColPtr() const
TVectorT< Element > & operator*=(Element val)
Multiply every element of the vector with val.
TVectorT< Element > & Zero()
Set vector elements to zero.
char * Form(const char *fmt,...)
virtual const Element * GetMatrixArray() const
template TMatrixD & OuterProduct< Double_t, Double_t, Double_t >(TMatrixD &target, const TVectorD &v1, const TVectorD &v2)
const TMatrixTBase< Element > * GetMatrix() const
R__EXTERN Int_t gMatrixCheck
Element Norm2Sqr() const
Compute the square of the 2-norm SUM{ v[i]^2 }.
TVectorT< Element > operator+(const TVectorT< Element > &source1, const TVectorT< Element > &source2)
Return source1+source2.
template Bool_t AreCompatible< Double_t, Float_t >(const TVectorD &v1, const TVectorF &v2, Int_t verbose)
TVectorT< Element > & SelectNonZeros(const TVectorT< Element > &select)
Keep only element as selected through array select non-zero.
virtual Int_t ReadClassBuffer(const TClass *cl, void *pointer, const TClass *onfile_class=0)=0
const Element * GetPtr() const
TVectorT< Element > & ElementDiv(TVectorT< Element > &target, const TVectorT< Element > &source)
Divide target by the source, element-by-element.
Element Norm1() const
Compute the 1-norm of the vector SUM{ |v[i]| }.
ClassImp(TMCParticle) void TMCParticle printf(": p=(%7.3f,%7.3f,%9.3f) ;", fPx, fPy, fPz)
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 .
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<=(Element val) const
Are all vector elements <= val?
template TVectorD & ElementMult< Double_t >(TVectorD &target, const TVectorD &source)
virtual void Operation(Element &element) const =0
TCppObject_t Allocate(TCppType_t type)
Mother of all ROOT objects.
virtual const Int_t * GetColIndexArray() const
const Element * GetPtr() const
Int_t Memcpy_m(Element *newp, const Element *oldp, Int_t copySize, Int_t newSize, Int_t oldSize)
Copy copySize doubles from *oldp to *newp .
const TMatrixTBase< Element > * GetMatrix() const
const Element * GetPtr() const
Short_t Max(Short_t a, Short_t b)
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
TVectorT< Element > & Abs()
Take an absolute value of a vector, i.e. apply Abs() to each element.
Bool_t MatchesNonZeroPattern(const TVectorT< Element > &select)
Check if vector elements as selected through array select are non-zero.
template Bool_t AreCompatible< Float_t, Float_t >(const TVectorF &v1, const TVectorF &v2, Int_t verbose)
template Double_t Mult< Double_t, Double_t, Double_t >(const TVectorD &v1, const TMatrixD &m, const TVectorD &v2)
Double_t Sqrt(Double_t x)
void Compare(const TVectorT< Element > &v1, const TVectorT< Element > &v2)
Compare two vectors and print out the result of the comparison.
template Float_t Dot< Float_t >(const TVectorF &v1, const TVectorF &v2)
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.
Long64_t LocMin(Long64_t n, const T *a)
template Bool_t VerifyVectorValue< Float_t >(const TVectorF &m, Float_t val, Int_t verbose, Float_t maxDevAllow)
double norm(double *x, double *p)
Element * New_m(Int_t size)
default kTRUE, when Use array kFALSE
template Bool_t VerifyVectorValue< Double_t >(const TVectorD &m, Double_t val, Int_t verbose, Double_t maxDevAllow)
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 < val?
templateClassImp(TVectorT) template< class Element > void TVectorT< Element >
Delete data pointer m, if it was assigned on the heap.
template TVectorF & ElementMult< Float_t >(TVectorF &target, const TVectorF &source)
Bool_t SomePositive(const TVectorT< Element > &select)
Check if vector elements as selected through array select are all positive.
template TVectorD & AddElemDiv< Double_t >(TVectorD &target, Double_t scalar, const TVectorD &source1, const TVectorD &source2)
virtual Version_t ReadVersion(UInt_t *start=0, UInt_t *bcnt=0, const TClass *cl=0)=0
TVectorT< Element > & operator+=(Element val)
Add val to every element of the vector.
TVectorT< Element > & Apply(const TElementActionT< Element > &action)
Apply action to each element of the vector.
virtual Int_t ReadArray(Bool_t *&b)=0
template TMatrixD OuterProduct< Double_t, Double_t >(const TVectorD &v1, const TVectorD &v2)
Double_t Drand(Double_t &ix)
Random number generator [0....1] with seed ix.