44 templateClassImp(TVectorT);
50 template<
class Element>
51 void TVectorT<Element>::Delete_m(Int_t size,Element *&m)
64 template<
class Element>
65 Element* TVectorT<Element>::New_m(Int_t size)
67 if (size == 0)
return 0;
69 if ( size <= kSizeMax )
72 Element *heap =
new Element[size];
81 template<
class Element>
82 void TVectorT<Element>::Add(
const TVectorT<Element> &v)
84 if (gMatrixCheck && !AreCompatible(*
this,v)) {
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;
99 template<
class Element>
100 void TVectorT<Element>::Add(
const TVectorT<Element> &v1,
const TVectorT<Element> &v2)
103 if ( !AreCompatible(*
this,v1) && !AreCompatible(*
this,v2)) {
104 Error(
"Add(TVectorT<Element> &)",
"vectors not compatible");
109 const Element *sv1 = v1.GetMatrixArray();
110 const Element *sv2 = v2.GetMatrixArray();
111 Element *tp = this->GetMatrixArray();
112 const Element *
const tp_last = tp+fNrows;
114 *tp++ = *sv1++ + *sv2++;
121 template<
class Element>
122 Int_t TVectorT<Element>::Memcpy_m(Element *newp,
const Element *oldp,Int_t copySize,
123 Int_t newSize,Int_t oldSize)
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));
148 template<
class Element>
149 void TVectorT<Element>::Allocate(Int_t nrows,Int_t row_lwb,Int_t init)
158 Error(
"Allocate",
"nrows=%d",nrows);
166 fElements = New_m(fNrows);
168 memset(fElements,0,fNrows*
sizeof(Element));
174 template<
class Element>
175 TVectorT<Element>::TVectorT(Int_t n)
183 template<
class Element>
184 TVectorT<Element>::TVectorT(Int_t lwb,Int_t upb)
186 Allocate(upb-lwb+1,lwb,1);
192 template<
class Element>
193 TVectorT<Element>::TVectorT(Int_t n,
const Element *elements)
196 SetElements(elements);
202 template<
class Element>
203 TVectorT<Element>::TVectorT(Int_t lwb,Int_t upb,
const Element *elements)
205 Allocate(upb-lwb+1,lwb);
206 SetElements(elements);
212 template<
class Element>
213 TVectorT<Element>::TVectorT(
const TVectorT &another) : TObject(another)
215 R__ASSERT(another.IsValid());
216 Allocate(another.GetUpb()-another.GetLwb()+1,another.GetLwb());
223 template<
class Element>
224 TVectorT<Element>::TVectorT(
const TMatrixTRow_const<Element> &mr) : TObject()
226 const TMatrixTBase<Element> *mt = mr.GetMatrix();
227 R__ASSERT(mt->IsValid());
228 Allocate(mt->GetColUpb()-mt->GetColLwb()+1,mt->GetColLwb());
235 template<
class Element>
236 TVectorT<Element>::TVectorT(
const TMatrixTColumn_const<Element> &mc) : TObject()
238 const TMatrixTBase<Element> *mt = mc.GetMatrix();
239 R__ASSERT(mt->IsValid());
240 Allocate(mt->GetRowUpb()-mt->GetRowLwb()+1,mt->GetRowLwb());
247 template<
class Element>
248 TVectorT<Element>::TVectorT(
const TMatrixTDiag_const<Element> &md) : TObject()
250 const TMatrixTBase<Element> *mt = md.GetMatrix();
251 R__ASSERT(mt->IsValid());
252 Allocate(TMath::Min(mt->GetNrows(),mt->GetNcols()));
262 template<
class Element>
263 TVectorT<Element>::TVectorT(Int_t lwb,Int_t upb,Double_t iv1, ...)
266 Error(
"TVectorT(Int_t, Int_t, ...)",
"upb(%d) < lwb(%d)",upb,lwb);
270 Allocate(upb-lwb+1,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\"");
291 template<
class Element>
292 TVectorT<Element> &TVectorT<Element>::ResizeTo(Int_t lwb,Int_t upb)
294 R__ASSERT(IsValid());
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;
315 Allocate(new_nrows,lwb);
316 R__ASSERT(IsValid());
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));
323 const Int_t rowLwb_copy = TMath::Max(fRowLwb,rowLwb_old);
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);
337 Allocate(upb-lwb+1,lwb,1);
346 template<
class Element>
347 TVectorT<Element> &TVectorT<Element>::Use(Int_t lwb,Int_t upb,Element *data)
350 Error(
"Use",
"upb(%d) < lwb(%d)",upb,lwb);
370 template<
class Element>
371 TVectorT<Element> &TVectorT<Element>::GetSub(Int_t row_lwb,Int_t row_upb,TVectorT<Element> &target,Option_t *option)
const
374 R__ASSERT(IsValid());
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");
391 const Int_t shift = (opt.Contains(
"S")) ? 1 : 0;
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);
407 Element *bp = target.GetMatrixArray();
409 for (Int_t irow = 0; irow < nrows_sub; irow++)
419 template<
class Element>
420 TVectorT<Element> &TVectorT<Element>::SetSub(Int_t row_lwb,
const TVectorT<Element> &source)
423 R__ASSERT(IsValid());
424 R__ASSERT(source.IsValid());
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");
436 const Int_t nRows_source = source.GetNrows();
438 const Element *bp = source.GetMatrixArray();
439 Element *ap = this->GetMatrixArray()+(row_lwb-fRowLwb);
441 for (Int_t irow = 0; irow < nRows_source; irow++)
450 template<
class Element>
451 TVectorT<Element> &TVectorT<Element>::Zero()
453 R__ASSERT(IsValid());
454 memset(this->GetMatrixArray(),0,fNrows*
sizeof(Element));
461 template<
class Element>
462 TVectorT<Element> &TVectorT<Element>::Abs()
464 R__ASSERT(IsValid());
466 Element *ep = this->GetMatrixArray();
467 const Element *
const fp = ep+fNrows;
469 *ep = TMath::Abs(*ep);
479 template<
class Element>
480 TVectorT<Element> &TVectorT<Element>::Sqr()
482 R__ASSERT(IsValid());
484 Element *ep = this->GetMatrixArray();
485 const Element *
const fp = ep+fNrows;
497 template<
class Element>
498 TVectorT<Element> &TVectorT<Element>::Sqrt()
500 R__ASSERT(IsValid());
502 Element *ep = this->GetMatrixArray();
503 const Element *
const fp = ep+fNrows;
507 *ep = TMath::Sqrt(*ep);
509 Error(
"Sqrt()",
"v(%ld) = %g < 0",Long_t(ep-this->GetMatrixArray()),(
float)*ep);
519 template<
class Element>
520 TVectorT<Element> &TVectorT<Element>::Invert()
522 R__ASSERT(IsValid());
524 Element *ep = this->GetMatrixArray();
525 const Element *
const fp = ep+fNrows;
527 R__ASSERT(*ep != 0.0);
531 Error(
"Invert()",
"v(%ld) = %g",Long_t(ep-this->GetMatrixArray()),(
float)*ep);
541 template<
class Element>
542 TVectorT<Element> &TVectorT<Element>::SelectNonZeros(
const TVectorT<Element> &select)
544 if (gMatrixCheck && !AreCompatible(*
this,select)) {
545 Error(
"SelectNonZeros(const TVectorT<Element> &",
"vector's not compatible");
549 const Element *sp = select.GetMatrixArray();
550 Element *ep = this->GetMatrixArray();
551 const Element *
const fp = ep+fNrows;
564 template<
class Element>
565 Element TVectorT<Element>::Norm1()
const
567 R__ASSERT(IsValid());
570 const Element *ep = this->GetMatrixArray();
571 const Element *
const fp = ep+fNrows;
573 norm += TMath::Abs(*ep++);
581 template<
class Element>
582 Element TVectorT<Element>::Norm2Sqr()
const
584 R__ASSERT(IsValid());
587 const Element *ep = this->GetMatrixArray();
588 const Element *
const fp = ep+fNrows;
590 norm += (*ep) * (*ep);
600 template<
class Element>
601 Element TVectorT<Element>::NormInf()
const
603 R__ASSERT(IsValid());
606 const Element *ep = this->GetMatrixArray();
607 const Element *
const fp = ep+fNrows;
609 norm = TMath::Max(norm,TMath::Abs(*ep++));
617 template<
class Element>
618 Int_t TVectorT<Element>::NonZeros()
const
620 R__ASSERT(IsValid());
622 Int_t nr_nonzeros = 0;
623 const Element *ep = this->GetMatrixArray();
624 const Element *
const fp = ep+fNrows;
626 if (*ep++) nr_nonzeros++;
634 template<
class Element>
635 Element TVectorT<Element>::Sum()
const
637 R__ASSERT(IsValid());
640 const Element *ep = this->GetMatrixArray();
641 const Element *
const fp = ep+fNrows;
651 template<
class Element>
652 Element TVectorT<Element>::Min()
const
654 R__ASSERT(IsValid());
656 const Int_t index = TMath::LocMin(fNrows,fElements);
657 return fElements[index];
663 template<
class Element>
664 Element TVectorT<Element>::Max()
const
666 R__ASSERT(IsValid());
668 const Int_t index = TMath::LocMax(fNrows,fElements);
669 return fElements[index];
677 template<
class Element>
678 TVectorT<Element> &TVectorT<Element>::operator=(
const TVectorT<Element> &source)
680 if (gMatrixCheck && !AreCompatible(*
this,source)) {
681 Error(
"operator=(const TVectorT<Element> &)",
"vectors not compatible");
685 if (this->GetMatrixArray() != source.GetMatrixArray()) {
686 TObject::operator=(source);
687 memcpy(fElements,source.GetMatrixArray(),fNrows*
sizeof(Element));
695 template<
class Element>
696 TVectorT<Element> &TVectorT<Element>::operator=(
const TMatrixTRow_const<Element> &mr)
698 const TMatrixTBase<Element> *mt = mr.GetMatrix();
701 R__ASSERT(IsValid());
702 R__ASSERT(mt->IsValid());
703 if (mt->GetColLwb() != fRowLwb || mt->GetNcols() != fNrows) {
704 Error(
"operator=(const TMatrixTRow_const &)",
"vector and row not compatible");
709 const Int_t inc = mr.GetInc();
710 const Element *rp = mr.GetPtr();
711 Element *ep = this->GetMatrixArray();
712 const Element *
const fp = ep+fNrows;
718 R__ASSERT(rp == mr.GetPtr()+mt->GetNcols());
726 template<
class Element>
727 TVectorT<Element> &TVectorT<Element>::operator=(
const TMatrixTColumn_const<Element> &mc)
729 const TMatrixTBase<Element> *mt = mc.GetMatrix();
732 R__ASSERT(IsValid());
733 R__ASSERT(mt->IsValid());
734 if (mt->GetRowLwb() != fRowLwb || mt->GetNrows() != fNrows) {
735 Error(
"operator=(const TMatrixTColumn_const &)",
"vector and column not compatible");
740 const Int_t inc = mc.GetInc();
741 const Element *cp = mc.GetPtr();
742 Element *ep = this->GetMatrixArray();
743 const Element *
const fp = ep+fNrows;
749 R__ASSERT(cp == mc.GetPtr()+mt->GetNoElements());
757 template<
class Element>
758 TVectorT<Element> &TVectorT<Element>::operator=(
const TMatrixTDiag_const<Element> &md)
760 const TMatrixTBase<Element> *mt = md.GetMatrix();
763 R__ASSERT(IsValid());
764 R__ASSERT(mt->IsValid());
765 if (md.GetNdiags() != fNrows) {
766 Error(
"operator=(const TMatrixTDiag_const &)",
"vector and matrix-diagonal not compatible");
771 const Int_t inc = md.GetInc();
772 const Element *dp = md.GetPtr();
773 Element *ep = this->GetMatrixArray();
774 const Element *
const fp = ep+fNrows;
780 R__ASSERT(dp < md.GetPtr()+mt->GetNoElements()+inc);
789 template<
class Element>
790 TVectorT<Element> &TVectorT<Element>::operator=(
const TMatrixTSparseRow_const<Element> &mr)
792 const TMatrixTBase<Element> *mt = mr.GetMatrix();
795 R__ASSERT(IsValid());
796 R__ASSERT(mt->IsValid());
797 if (mt->GetColLwb() != fRowLwb || mt->GetNcols() != fNrows) {
798 Error(
"operator=(const TMatrixTSparseRow_const &)",
"vector and row not compatible");
803 const Int_t nIndex = mr.GetNindex();
804 const Element *
const prData = mr.GetDataPtr();
805 const Int_t *
const prCol = mr.GetColPtr();
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];
820 template<
class Element>
821 TVectorT<Element> &TVectorT<Element>::operator=(
const TMatrixTSparseDiag_const<Element> &md)
823 const TMatrixTBase<Element> *mt = md.GetMatrix();
826 R__ASSERT(IsValid());
827 R__ASSERT(mt->IsValid());
828 if (md.GetNdiags() != fNrows) {
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);
844 template<
class Element>
845 TVectorT<Element> &TVectorT<Element>::operator=(Element val)
847 R__ASSERT(IsValid());
849 Element *ep = this->GetMatrixArray();
850 const Element *
const fp = ep+fNrows;
860 template<
class Element>
861 TVectorT<Element> &TVectorT<Element>::operator+=(Element val)
863 R__ASSERT(IsValid());
865 Element *ep = this->GetMatrixArray();
866 const Element *
const fp = ep+fNrows;
876 template<
class Element>
877 TVectorT<Element> &TVectorT<Element>::operator-=(Element val)
879 R__ASSERT(IsValid());
881 Element *ep = this->GetMatrixArray();
882 const Element *
const fp = ep+fNrows;
892 template<
class Element>
893 TVectorT<Element> &TVectorT<Element>::operator*=(Element val)
895 R__ASSERT(IsValid());
897 Element *ep = this->GetMatrixArray();
898 const Element *
const fp = ep+fNrows;
908 template<
class Element>
909 TVectorT<Element> &TVectorT<Element>::operator+=(
const TVectorT<Element> &source)
911 if (gMatrixCheck && !AreCompatible(*
this,source)) {
912 Error(
"operator+=(const TVectorT<Element> &)",
"vector's not compatible");
916 const Element *sp = source.GetMatrixArray();
917 Element *tp = this->GetMatrixArray();
918 const Element *
const tp_last = tp+fNrows;
928 template<
class Element>
929 TVectorT<Element> &TVectorT<Element>::operator-=(
const TVectorT<Element> &source)
931 if (gMatrixCheck && !AreCompatible(*
this,source)) {
932 Error(
"operator-=(const TVectorT<Element> &)",
"vector's not compatible");
936 const Element *sp = source.GetMatrixArray();
937 Element *tp = this->GetMatrixArray();
938 const Element *
const tp_last = tp+fNrows;
949 template<
class Element>
950 TVectorT<Element> &TVectorT<Element>::operator*=(
const TMatrixT<Element> &a)
953 R__ASSERT(IsValid());
954 R__ASSERT(a.IsValid());
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];
968 Bool_t isAllocated = kFALSE;
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;
1016 template<
class Element>
1017 TVectorT<Element> &TVectorT<Element>::operator*=(
const TMatrixTSparse<Element> &a)
1020 R__ASSERT(IsValid());
1021 R__ASSERT(a.IsValid());
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];
1035 Bool_t isAllocated = kFALSE;
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;
1079 template<
class Element>
1080 TVectorT<Element> &TVectorT<Element>::operator*=(
const TMatrixTSym<Element> &a)
1083 R__ASSERT(IsValid());
1084 R__ASSERT(a.IsValid());
1085 if (a.GetNcols() != fNrows || a.GetColLwb() != fRowLwb) {
1086 Error(
"operator*=(const TMatrixTSym &)",
"vector and matrix incompatible");
1091 Element work[kWorkMax];
1092 Bool_t isAllocated = kFALSE;
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;
1133 template<
class Element>
1134 Bool_t TVectorT<Element>::operator==(Element val)
const
1136 R__ASSERT(IsValid());
1138 const Element *ep = this->GetMatrixArray();
1139 const Element *
const fp = ep+fNrows;
1141 if (!(*ep++ == val))
1150 template<
class Element>
1151 Bool_t TVectorT<Element>::operator!=(Element val)
const
1153 R__ASSERT(IsValid());
1155 const Element *ep = this->GetMatrixArray();
1156 const Element *
const fp = ep+fNrows;
1158 if (!(*ep++ != val))
1167 template<
class Element>
1168 Bool_t TVectorT<Element>::operator<(Element val)
const
1170 R__ASSERT(IsValid());
1172 const Element *ep = this->GetMatrixArray();
1173 const Element *
const fp = ep+fNrows;
1184 template<
class Element>
1185 Bool_t TVectorT<Element>::operator<=(Element val)
const
1187 R__ASSERT(IsValid());
1189 const Element *ep = this->GetMatrixArray();
1190 const Element *
const fp = ep+fNrows;
1192 if (!(*ep++ <= val))
1201 template<
class Element>
1202 Bool_t TVectorT<Element>::operator>(Element val)
const
1204 R__ASSERT(IsValid());
1206 const Element *ep = this->GetMatrixArray();
1207 const Element *
const fp = ep+fNrows;
1218 template<
class Element>
1219 Bool_t TVectorT<Element>::operator>=(Element val)
const
1221 R__ASSERT(IsValid());
1223 const Element *ep = this->GetMatrixArray();
1224 const Element *
const fp = ep+fNrows;
1226 if (!(*ep++ >= val))
1235 template<
class Element>
1236 Bool_t TVectorT<Element>::MatchesNonZeroPattern(
const TVectorT<Element> &select)
1238 if (gMatrixCheck && !AreCompatible(*
this,select)) {
1239 Error(
"MatchesNonZeroPattern(const TVectorT&)",
"vector's not compatible");
1243 const Element *sp = select.GetMatrixArray();
1244 const Element *ep = this->GetMatrixArray();
1245 const Element *
const fp = ep+fNrows;
1247 if (*sp == 0.0 && *ep != 0.0)
1258 template<
class Element>
1259 Bool_t TVectorT<Element>::SomePositive(
const TVectorT<Element> &select)
1261 if (gMatrixCheck && !AreCompatible(*
this,select)) {
1262 Error(
"SomePositive(const TVectorT&)",
"vector's not compatible");
1266 const Element *sp = select.GetMatrixArray();
1267 const Element *ep = this->GetMatrixArray();
1268 const Element *
const fp = ep+fNrows;
1270 if (*sp != 0.0 && *ep <= 0.0)
1281 template<
class Element>
1282 void TVectorT<Element>::AddSomeConstant(Element val,
const TVectorT<Element> &select)
1284 if (gMatrixCheck && !AreCompatible(*
this,select))
1285 Error(
"AddSomeConstant(Element,const TVectorT&)(const TVectorT&)",
"vector's not compatible");
1287 const Element *sp = select.GetMatrixArray();
1288 Element *ep = this->GetMatrixArray();
1289 const Element *
const fp = ep+fNrows;
1297 extern Double_t Drand(Double_t &ix);
1302 template<
class Element>
1303 void TVectorT<Element>::Randomize(Element alpha,Element beta,Double_t &seed)
1305 R__ASSERT(IsValid());
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);
1319 template<
class Element>
1320 TVectorT<Element> &TVectorT<Element>::Apply(
const TElementActionT<Element> &action)
1322 R__ASSERT(IsValid());
1323 for (Element *ep = fElements; ep < fElements+fNrows; ep++)
1324 action.Operation(*ep);
1332 template<
class Element>
1333 TVectorT<Element> &TVectorT<Element>::Apply(
const TElementPosActionT<Element> &action)
1335 R__ASSERT(IsValid());
1337 Element *ep = fElements;
1338 for (action.fI = fRowLwb; action.fI < fRowLwb+fNrows; action.fI++)
1339 action.Operation(*ep++);
1341 R__ASSERT(ep == fElements+fNrows);
1350 template<
class Element>
1351 void TVectorT<Element>::Draw(Option_t *option)
1353 gROOT->ProcessLine(Form(
"THistPainter::PaintSpecialObjects((TObject*)0x%lx,\"%s\");",
1354 (ULong_t)
this, option));
1360 template<
class Element>
1361 void TVectorT<Element>::Print(Option_t *flag)
const
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));
1383 template<
class Element>
1384 Bool_t operator==(
const TVectorT<Element> &v1,
const TVectorT<Element> &v2)
1386 if (!AreCompatible(v1,v2))
return kFALSE;
1387 return (memcmp(v1.GetMatrixArray(),v2.GetMatrixArray(),v1.GetNrows()*
sizeof(Element)) == 0);
1393 template<
class Element>
1394 Element operator*(
const TVectorT<Element> &v1,
const TVectorT<Element> &v2)
1397 if (!AreCompatible(v1,v2)) {
1398 Error(
"operator*(const TVectorT<Element> &,const TVectorT<Element> &)",
"vector's are incompatible");
1409 template<
class Element>
1410 TVectorT<Element> operator+(
const TVectorT<Element> &source1,
const TVectorT<Element> &source2)
1412 TVectorT<Element> target = source1;
1420 template<
class Element>
1421 TVectorT<Element> operator-(
const TVectorT<Element> &source1,
const TVectorT<Element> &source2)
1423 TVectorT<Element> target = source1;
1431 template<
class Element>
1432 TVectorT<Element> operator*(
const TMatrixT<Element> &a,
const TVectorT<Element> &source)
1434 R__ASSERT(a.IsValid());
1435 TVectorT<Element> target(a.GetRowLwb(),a.GetRowUpb());
1436 return Add(target,Element(1.0),a,source);
1442 template<
class Element>
1443 TVectorT<Element> operator*(
const TMatrixTSym<Element> &a,
const TVectorT<Element> &source)
1445 R__ASSERT(a.IsValid());
1446 TVectorT<Element> target(a.GetRowLwb(),a.GetRowUpb());
1447 return Add(target,Element(1.0),a,source);
1453 template<
class Element>
1454 TVectorT<Element> operator*(
const TMatrixTSparse<Element> &a,
const TVectorT<Element> &source)
1456 R__ASSERT(a.IsValid());
1457 TVectorT<Element> target(a.GetRowLwb(),a.GetRowUpb());
1458 return Add(target,Element(1.0),a,source);
1464 template<
class Element>
1465 TVectorT<Element> operator*(Element val,
const TVectorT<Element> &source)
1467 TVectorT<Element> target = source;
1475 template<
class Element>
1476 Element Dot(
const TVectorT<Element> &v1,
const TVectorT<Element> &v2)
1478 const Element *v1p = v1.GetMatrixArray();
1479 const Element *v2p = v2.GetMatrixArray();
1481 const Element *
const fv1p = v1p+v1.GetNrows();
1483 sum += *v1p++ * *v2p++;
1491 template <
class Element1,
class Element2>
1493 OuterProduct(
const TVectorT<Element1> &v1,
const TVectorT<Element2> &v2)
1499 TMatrixT<Element1> target;
1501 return OuterProduct(target,v1,v2);
1507 template <
class Element1,
class Element2,
class Element3>
1509 &OuterProduct(TMatrixT<Element1> &target,
const TVectorT<Element2> &v1,
const TVectorT<Element3> &v2)
1511 target.ResizeTo(v1.GetLwb(), v1.GetUpb(), v2.GetLwb(), v2.GetUpb());
1513 Element1 * mp = target.GetMatrixArray();
1514 const Element1 *
const m_last = mp + target.GetNoElements();
1516 const Element2 * v1p = v1.GetMatrixArray();
1517 const Element2 *
const v1_last = v1p + v1.GetNrows();
1519 const Element3 *
const v20 = v2.GetMatrixArray();
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);
1539 template <
class Element1,
class Element2,
class Element3>
1540 Element1 Mult(
const TVectorT<Element1> &v1,
const TMatrixT<Element2> &m,
1541 const TVectorT<Element3> &v2)
1544 if (!AreCompatible(v1, m)) {
1545 ::Error(
"Mult",
"Vector v1 and matrix m incompatible");
1548 if (!AreCompatible(m, v2)) {
1549 ::Error(
"Mult",
"Matrix m and vector v2 incompatible");
1554 const Element1 * v1p = v1.GetMatrixArray();
1555 const Element1 *
const v1_last = v1p + v1.GetNrows();
1557 const Element2 * mp = m.GetMatrixArray();
1558 const Element2 *
const m_last = mp + m.GetNoElements();
1560 const Element3 *
const v20 = v2.GetMatrixArray();
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);
1584 template<
class Element>
1585 TVectorT<Element> &Add(TVectorT<Element> &target,Element scalar,
const TVectorT<Element> &source)
1587 if (gMatrixCheck && !AreCompatible(target,source)) {
1588 Error(
"Add(TVectorT<Element> &,Element,const TVectorT<Element> &)",
"vector's are incompatible");
1592 const Element * sp = source.GetMatrixArray();
1593 Element * tp = target.GetMatrixArray();
1594 const Element *
const ftp = tp+target.GetNrows();
1595 if (scalar == 1.0 ) {
1598 }
else if (scalar == -1.0) {
1603 *tp++ += scalar * *sp++;
1613 template<
class Element>
1614 TVectorT<Element> &Add(TVectorT<Element> &target,Element scalar,
1615 const TMatrixT<Element> &a,
const TVectorT<Element> &source)
1618 R__ASSERT(target.IsValid());
1619 R__ASSERT(a.IsValid());
1620 if (a.GetNrows() != target.GetNrows() || a.GetRowLwb() != target.GetLwb()) {
1621 Error(
"Add(TVectorT &,const TMatrixT &,const TVectorT &)",
"target vector and matrix are incompatible");
1625 R__ASSERT(source.IsValid());
1626 if (a.GetNcols() != source.GetNrows() || a.GetColLwb() != source.GetLwb()) {
1627 Error(
"Add(TVectorT &,const TMatrixT &,const TVectorT &)",
"source vector and matrix are incompatible");
1632 const Element *
const sp = source.GetMatrixArray();
1633 const Element * mp = a.GetMatrixArray();
1634 Element * tp = target.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;
1681 if (gMatrixCheck) R__ASSERT(mp == a.GetMatrixArray()+a.GetNoElements());
1691 template<
class Element>
1692 TVectorT<Element> &Add(TVectorT<Element> &target,Element scalar,
1693 const TMatrixTSym<Element> &a,
const TVectorT<Element> &source)
1696 R__ASSERT(target.IsValid());
1697 R__ASSERT(source.IsValid());
1698 R__ASSERT(a.IsValid());
1699 if (a.GetNrows() != target.GetNrows() || a.GetRowLwb() != target.GetLwb()) {
1700 Error(
"Add(TVectorT &,const TMatrixT &,const TVectorT &)",
"target vector and matrix are incompatible");
1705 const Element *
const sp = source.GetMatrixArray();
1706 const Element * mp = a.GetMatrixArray();
1707 Element * tp = target.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());
1763 template<
class Element>
1764 TVectorT<Element> &Add(TVectorT<Element> &target,Element scalar,
1765 const TMatrixTSparse<Element> &a,
const TVectorT<Element> &source)
1768 R__ASSERT(target.IsValid());
1769 R__ASSERT(a.IsValid());
1770 if (a.GetNrows() != target.GetNrows() || a.GetRowLwb() != target.GetLwb()) {
1771 Error(
"Add(TVectorT &,const TMatrixT &,const TVectorT &)",
"target vector and matrix are incompatible");
1775 R__ASSERT(source.IsValid());
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();
1786 const Element *
const sp = source.GetMatrixArray();
1787 Element * tp = target.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;
1841 template<
class Element>
1842 TVectorT<Element> &AddElemMult(TVectorT<Element> &target,Element scalar,
1843 const TVectorT<Element> &source1,
const TVectorT<Element> &source2)
1845 if (gMatrixCheck && !(AreCompatible(target,source1) && AreCompatible(target,source2))) {
1846 Error(
"AddElemMult(TVectorT<Element> &,Element,const TVectorT<Element> &,const TVectorT<Element> &)",
1847 "vector's are incompatible");
1851 const Element * sp1 = source1.GetMatrixArray();
1852 const Element * sp2 = source2.GetMatrixArray();
1853 Element * tp = target.GetMatrixArray();
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++;
1874 template<
class Element>
1875 TVectorT<Element> &AddElemMult(TVectorT<Element> &target,Element scalar,
1876 const TVectorT<Element> &source1,
const TVectorT<Element> &source2,
const TVectorT<Element> &select)
1878 if (gMatrixCheck && !( AreCompatible(target,source1) && AreCompatible(target,source2) &&
1879 AreCompatible(target,select) )) {
1880 Error(
"AddElemMult(TVectorT<Element> &,Element,const TVectorT<Element> &,const TVectorT<Element> &,onst TVectorT<Element> &)",
1881 "vector's are incompatible");
1885 const Element * sp1 = source1.GetMatrixArray();
1886 const Element * sp2 = source2.GetMatrixArray();
1887 const Element * mp = select.GetMatrixArray();
1888 Element * tp = target.GetMatrixArray();
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++;
1914 template<
class Element>
1915 TVectorT<Element> &AddElemDiv(TVectorT<Element> &target,Element scalar,
1916 const TVectorT<Element> &source1,
const TVectorT<Element> &source2)
1918 if (gMatrixCheck && !(AreCompatible(target,source1) && AreCompatible(target,source2))) {
1919 Error(
"AddElemDiv(TVectorT<Element> &,Element,const TVectorT<Element> &,const TVectorT<Element> &)",
1920 "vector's are incompatible");
1924 const Element * sp1 = source1.GetMatrixArray();
1925 const Element * sp2 = source2.GetMatrixArray();
1926 Element * tp = target.GetMatrixArray();
1927 const Element *
const ftp = tp+target.GetNrows();
1929 if (scalar == 1.0 ) {
1930 while ( tp < ftp ) {
1934 const Int_t irow = (sp2-source2.GetMatrixArray())/source2.GetNrows();
1935 Error(
"AddElemDiv",
"source2 (%d) is zero",irow);
1939 }
else if (scalar == -1.0) {
1940 while ( tp < ftp ) {
1944 const Int_t irow = (sp2-source2.GetMatrixArray())/source2.GetNrows();
1945 Error(
"AddElemDiv",
"source2 (%d) is zero",irow);
1950 while ( tp < ftp ) {
1952 *tp += scalar * *sp1 / *sp2;
1954 const Int_t irow = (sp2-source2.GetMatrixArray())/source2.GetNrows();
1955 Error(
"AddElemDiv",
"source2 (%d) is zero",irow);
1968 template<
class Element>
1969 TVectorT<Element> &AddElemDiv(TVectorT<Element> &target,Element scalar,
1970 const TVectorT<Element> &source1,
const TVectorT<Element> &source2,
const TVectorT<Element> &select)
1972 if (gMatrixCheck && !( AreCompatible(target,source1) && AreCompatible(target,source2) &&
1973 AreCompatible(target,select) )) {
1974 Error(
"AddElemDiv(TVectorT<Element> &,Element,const TVectorT<Element> &,const TVectorT<Element> &,onst TVectorT<Element> &)",
1975 "vector's are incompatible");
1979 const Element * sp1 = source1.GetMatrixArray();
1980 const Element * sp2 = source2.GetMatrixArray();
1981 const Element * mp = select.GetMatrixArray();
1982 Element * tp = target.GetMatrixArray();
1983 const Element *
const ftp = tp+target.GetNrows();
1985 if (scalar == 1.0 ) {
1986 while ( tp < ftp ) {
1991 const Int_t irow = (sp2-source2.GetMatrixArray())/source2.GetNrows();
1992 Error(
"AddElemDiv",
"source2 (%d) is zero",irow);
1995 mp++; tp++; sp1++; sp2++;
1997 }
else if (scalar == -1.0) {
1998 while ( tp < ftp ) {
2003 const Int_t irow = (sp2-source2.GetMatrixArray())/source2.GetNrows();
2004 Error(
"AddElemDiv",
"source2 (%d) is zero",irow);
2007 mp++; tp++; sp1++; sp2++;
2010 while ( tp < ftp ) {
2013 *tp += scalar * *sp1 / *sp2;
2015 const Int_t irow = (sp2-source2.GetMatrixArray())/source2.GetNrows();
2016 Error(
"AddElemDiv",
"source2 (%d) is zero",irow);
2019 mp++; tp++; sp1++; sp2++;
2029 template<
class Element>
2030 TVectorT<Element> &ElementMult(TVectorT<Element> &target,
const TVectorT<Element> &source)
2032 if (gMatrixCheck && !AreCompatible(target,source)) {
2033 Error(
"ElementMult(TVectorT<Element> &,const TVectorT<Element> &)",
"vector's are incompatible");
2037 const Element * sp = source.GetMatrixArray();
2038 Element * tp = target.GetMatrixArray();
2039 const Element *
const ftp = tp+target.GetNrows();
2049 template<
class Element>
2050 TVectorT<Element> &ElementMult(TVectorT<Element> &target,
const TVectorT<Element> &source,
const TVectorT<Element> &select)
2052 if (gMatrixCheck && !(AreCompatible(target,source) && AreCompatible(target,select))) {
2053 Error(
"ElementMult(TVectorT<Element> &,const TVectorT<Element> &,const TVectorT<Element> &)",
"vector's are incompatible");
2057 const Element * sp = source.GetMatrixArray();
2058 const Element * mp = select.GetMatrixArray();
2059 Element * tp = target.GetMatrixArray();
2060 const Element *
const ftp = tp+target.GetNrows();
2061 while ( tp < ftp ) {
2062 if (*mp) *tp *= *sp;
2072 template<
class Element>
2073 TVectorT<Element> &ElementDiv(TVectorT<Element> &target,
const TVectorT<Element> &source)
2075 if (gMatrixCheck && !AreCompatible(target,source)) {
2076 Error(
"ElementDiv(TVectorT<Element> &,const TVectorT<Element> &)",
"vector's are incompatible");
2080 const Element * sp = source.GetMatrixArray();
2081 Element * tp = target.GetMatrixArray();
2082 const Element *
const ftp = tp+target.GetNrows();
2083 while ( tp < ftp ) {
2087 const Int_t irow = (sp-source.GetMatrixArray())/source.GetNrows();
2088 Error(
"ElementDiv",
"source (%d) is zero",irow);
2098 template<
class Element>
2099 TVectorT<Element> &ElementDiv(TVectorT<Element> &target,
const TVectorT<Element> &source,
const TVectorT<Element> &select)
2101 if (gMatrixCheck && !AreCompatible(target,source)) {
2102 Error(
"ElementDiv(TVectorT<Element> &,const TVectorT<Element> &,const TVectorT<Element> &)",
"vector's are incompatible");
2106 const Element * sp = source.GetMatrixArray();
2107 const Element * mp = select.GetMatrixArray();
2108 Element * tp = target.GetMatrixArray();
2109 const Element *
const ftp = tp+target.GetNrows();
2110 while ( tp < ftp ) {
2115 const Int_t irow = (sp-source.GetMatrixArray())/source.GetNrows();
2116 Error(
"ElementDiv",
"source (%d) is zero",irow);
2128 template<
class Element1,
class Element2>
2129 Bool_t AreCompatible(
const TVectorT<Element1> &v1,
const TVectorT<Element2> &v2,Int_t verbose)
2131 if (!v1.IsValid()) {
2133 ::Error(
"AreCompatible",
"vector 1 not valid");
2136 if (!v2.IsValid()) {
2138 ::Error(
"AreCompatible",
"vector 2 not valid");
2142 if (v1.GetNrows() != v2.GetNrows() || v1.GetLwb() != v2.GetLwb()) {
2144 ::Error(
"AreCompatible",
"matrices 1 and 2 not compatible");
2154 template<
class Element1,
class Element2>
2155 Bool_t AreCompatible(
const TMatrixT<Element1> &m,
const TVectorT<Element2> &v,Int_t verbose)
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");
2180 template<
class Element1,
class Element2>
2181 Bool_t AreCompatible(
const TVectorT<Element1> &v,
const TMatrixT<Element2> &m,Int_t verbose)
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");
2206 template<
class Element>
2207 void Compare(
const TVectorT<Element> &v1,
const TVectorT<Element> &v2)
2209 if (!AreCompatible(v1,v2)) {
2210 Error(
"Compare(const TVectorT<Element> &,const TVectorT<Element> &)",
"vectors are incompatible");
2214 printf(
"\n\nComparison of two TVectorTs:\n");
2220 Element difmax = -1;
2221 const Element *mp1 = v1.GetMatrixArray();
2222 const Element *mp2 = v2.GetMatrixArray();
2224 for (Int_t i = 0; i < v1.GetNrows(); i++) {
2225 const Element mv1 = *mp1++;
2226 const Element mv2 = *mp2++;
2227 const Element diff = TMath::Abs(mv1-mv2);
2229 if (diff > difmax) {
2233 norm1 += TMath::Abs(mv1);
2234 norm2 += TMath::Abs(mv2);
2235 ndiff += TMath::Abs(diff);
2238 imax += v1.GetLwb();
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",
2247 (mv2-mv1)/TMath::Max(TMath::Abs(mv2+mv1)/2,(Element)1e-7));
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",
2253 ndiff/TMath::Max(TMath::Sqrt(norm1*norm2),1e-7));
2259 template<
class Element>
2260 Bool_t VerifyVectorValue(
const TVectorT<Element> &v,Element val,
2261 Int_t verbose,Element maxDevAllow)
2264 Element maxDevObs = 0;
2266 if (TMath::Abs(maxDevAllow) <= 0.0)
2267 maxDevAllow = std::numeric_limits<Element>::epsilon();
2269 for (Int_t i = v.GetLwb(); i <= v.GetUpb(); i++) {
2270 const Element dev = TMath::Abs(v(i)-val);
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)
2294 template<
class Element>
2295 Bool_t VerifyVectorIdentity(
const TVectorT<Element> &v1,
const TVectorT<Element> &v2,
2296 Int_t verbose, Element maxDevAllow)
2299 Element maxDevObs = 0;
2301 if (!AreCompatible(v1,v2))
2304 if (TMath::Abs(maxDevAllow) <= 0.0)
2305 maxDevAllow = std::numeric_limits<Element>::epsilon();
2307 for (Int_t i = v1.GetLwb(); i <= v1.GetUpb(); i++) {
2308 const Element dev = TMath::Abs(v1(i)-v2(i));
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) {
2333 template<
class Element>
2334 void TVectorT<Element>::Streamer(TBuffer &R__b)
2336 if (R__b.IsReading()) {
2338 Version_t R__v = R__b.ReadVersion(&R__s,&R__c);
2341 R__b.ReadClassBuffer(TVectorT<Element>::Class(),
this,R__v,R__s,R__c);
2343 TObject::Streamer(R__b);
2345 fNrows = R__b.ReadArray(fElements);
2346 R__b.CheckByteCount(R__s, R__c, TVectorT<Element>::IsA());
2348 if (fNrows > 0 && fNrows <= kSizeMax) {
2349 memcpy(fDataStack,fElements,fNrows*
sizeof(Element));
2350 delete [] fElements;
2351 fElements = fDataStack;
2352 }
else if (fNrows < 0)
2358 R__b.WriteClassBuffer(TVectorT<Element>::Class(),
this);
2366 template class TVectorT<Float_t>;
2368 template Bool_t
operator== <Float_t>(
const TVectorF &source1,
const TVectorF &source2);
2369 template TVectorF
operator+ <Float_t>(
const TVectorF &source1,
const TVectorF &source2);
2370 template TVectorF
operator- <Float_t>(
const TVectorF &source1,
const TVectorF &source2);
2371 template Float_t
operator* <Float_t>(
const TVectorF &source1,
const TVectorF &source2);
2372 template TVectorF
operator* <Float_t>(
const TMatrixF &a,
const TVectorF &source);
2373 template TVectorF
operator* <Float_t>(
const TMatrixFSym &a,
const TVectorF &source);
2374 template TVectorF
operator* <Float_t>(
const TMatrixFSparse &a,
const TVectorF &source);
2375 template TVectorF
operator* <Float_t>( Float_t val,
const TVectorF &source);
2377 template Float_t Dot <Float_t>(
const TVectorF &v1,
const TVectorF &v2);
2378 template TMatrixF OuterProduct <Float_t,Float_t>
2379 (
const TVectorF &v1,
const TVectorF &v2);
2380 template TMatrixF &OuterProduct <Float_t,Float_t,Float_t>
2381 ( TMatrixF &target,
const TVectorF &v1,
const TVectorF &v2);
2382 template Float_t Mult <Float_t,Float_t,Float_t>
2383 (
const TVectorF &v1,
const TMatrixF &m,
const TVectorF &v2);
2385 template TVectorF &Add <Float_t>( TVectorF &target, Float_t scalar,
const TVectorF &source);
2386 template TVectorF &Add <Float_t>( TVectorF &target, Float_t scalar,
const TMatrixF &a,
2387 const TVectorF &source);
2388 template TVectorF &Add <Float_t>( TVectorF &target, Float_t scalar,
const TMatrixFSym &a,
2389 const TVectorF &source);
2390 template TVectorF &Add <Float_t>( TVectorF &target, Float_t scalar,
const TMatrixFSparse &a,
2391 const TVectorF &source);
2392 template TVectorF &AddElemMult <Float_t>( TVectorF &target, Float_t scalar,
const TVectorF &source1,
2393 const TVectorF &source2);
2394 template TVectorF &AddElemMult <Float_t>( TVectorF &target, Float_t scalar,
const TVectorF &source1,
2395 const TVectorF &source2,
const TVectorF &select);
2396 template TVectorF &AddElemDiv <Float_t>( TVectorF &target, Float_t scalar,
const TVectorF &source1,
2397 const TVectorF &source2);
2398 template TVectorF &AddElemDiv <Float_t>( TVectorF &target, Float_t scalar,
const TVectorF &source1,
2399 const TVectorF &source2,
const TVectorF &select);
2400 template TVectorF &ElementMult <Float_t>( TVectorF &target,
const TVectorF &source);
2401 template TVectorF &ElementMult <Float_t>( TVectorF &target,
const TVectorF &source,
const TVectorF &select);
2402 template TVectorF &ElementDiv <Float_t>( TVectorF &target,
const TVectorF &source);
2403 template TVectorF &ElementDiv <Float_t>( TVectorF &target,
const TVectorF &source,
const TVectorF &select);
2405 template Bool_t AreCompatible <Float_t,Float_t> (
const TVectorF &v1,
const TVectorF &v2,Int_t verbose);
2406 template Bool_t AreCompatible <Float_t,Double_t>(
const TVectorF &v1,
const TVectorD &v2,Int_t verbose);
2407 template Bool_t AreCompatible <Float_t,Float_t> (
const TMatrixF &m,
const TVectorF &v, Int_t verbose);
2408 template Bool_t AreCompatible <Float_t,Float_t> (
const TVectorF &v,
const TMatrixF &m, Int_t verbose);
2410 template void Compare <Float_t> (
const TVectorF &v1,
const TVectorF &v2);
2411 template Bool_t VerifyVectorValue <Float_t> (
const TVectorF &m, Float_t val,Int_t verbose,Float_t maxDevAllow);
2412 template Bool_t VerifyVectorIdentity<Float_t> (
const TVectorF &m1,
const TVectorF &m2, Int_t verbose,Float_t maxDevAllow);
2418 template class TVectorT<Double_t>;
2420 template Bool_t
operator== <Double_t>(
const TVectorD &source1,
const TVectorD &source2);
2421 template TVectorD
operator+ <Double_t>(
const TVectorD &source1,
const TVectorD &source2);
2422 template TVectorD
operator- <Double_t>(
const TVectorD &source1,
const TVectorD &source2);
2423 template Double_t
operator* <Double_t>(
const TVectorD &source1,
const TVectorD &source2);
2424 template TVectorD
operator* <Double_t>(
const TMatrixD &a,
const TVectorD &source);
2425 template TVectorD
operator* <Double_t>(
const TMatrixDSym &a,
const TVectorD &source);
2426 template TVectorD
operator* <Double_t>(
const TMatrixDSparse &a,
const TVectorD &source);
2427 template TVectorD
operator* <Double_t>( Double_t val,
const TVectorD &source);
2429 template Double_t Dot <Double_t>(
const TVectorD &v1,
const TVectorD &v2);
2430 template TMatrixD OuterProduct <Double_t,Double_t>
2431 (
const TVectorD &v1,
const TVectorD &v2);
2432 template TMatrixD &OuterProduct <Double_t,Double_t,Double_t>
2433 ( TMatrixD &target,
const TVectorD &v1,
const TVectorD &v2);
2434 template Double_t Mult <Double_t,Double_t,Double_t>
2435 (
const TVectorD &v1,
const TMatrixD &m,
const TVectorD &v2);
2437 template TVectorD &Add <Double_t>( TVectorD &target, Double_t scalar,
const TVectorD &source);
2438 template TVectorD &Add <Double_t>( TVectorD &target, Double_t scalar,
const TMatrixD &a,
2439 const TVectorD &source);
2440 template TVectorD &Add <Double_t>( TVectorD &target, Double_t scalar,
const TMatrixDSym &a
2441 ,
const TVectorD &source);
2442 template TVectorD &Add <Double_t>( TVectorD &target, Double_t scalar,
const TMatrixDSparse &a
2443 ,
const TVectorD &source);
2444 template TVectorD &AddElemMult <Double_t>( TVectorD &target, Double_t scalar,
const TVectorD &source1,
2445 const TVectorD &source2);
2446 template TVectorD &AddElemMult <Double_t>( TVectorD &target, Double_t scalar,
const TVectorD &source1,
2447 const TVectorD &source2,
const TVectorD &select);
2448 template TVectorD &AddElemDiv <Double_t>( TVectorD &target, Double_t scalar,
const TVectorD &source1,
2449 const TVectorD &source2);
2450 template TVectorD &AddElemDiv <Double_t>( TVectorD &target, Double_t scalar,
const TVectorD &source1,
2451 const TVectorD &source2,
const TVectorD &select);
2452 template TVectorD &ElementMult <Double_t>( TVectorD &target,
const TVectorD &source);
2453 template TVectorD &ElementMult <Double_t>( TVectorD &target,
const TVectorD &source,
const TVectorD &select);
2454 template TVectorD &ElementDiv <Double_t>( TVectorD &target,
const TVectorD &source);
2455 template TVectorD &ElementDiv <Double_t>( TVectorD &target,
const TVectorD &source,
const TVectorD &select);
2457 template Bool_t AreCompatible <Double_t,Double_t>(
const TVectorD &v1,
const TVectorD &v2,Int_t verbose);
2458 template Bool_t AreCompatible <Double_t,Float_t> (
const TVectorD &v1,
const TVectorF &v2,Int_t verbose);
2459 template Bool_t AreCompatible <Double_t,Double_t>(
const TMatrixD &m,
const TVectorD &v, Int_t verbose);
2460 template Bool_t AreCompatible <Double_t,Double_t>(
const TVectorD &v,
const TMatrixD &m, Int_t verbose);
2462 template void Compare <Double_t> (
const TVectorD &v1,
const TVectorD &v2);
2463 template Bool_t VerifyVectorValue <Double_t> (
const TVectorD &m, Double_t val,Int_t verbose,Double_t maxDevAllow);
2464 template Bool_t VerifyVectorIdentity<Double_t> (
const TVectorD &m1,
const TVectorD &m2, Int_t verbose,Double_t maxDevAllow);