45 template<
class Element>
46 TMatrixTRow_const<Element>::TMatrixTRow_const(
const TMatrixT<Element> &matrix,Int_t row)
48 R__ASSERT(matrix.IsValid());
50 fRowInd = row-matrix.GetRowLwb();
51 if (fRowInd >= matrix.GetNrows() || fRowInd < 0) {
52 Error(
"TMatrixTRow_const(const TMatrixT<Element> &,Int_t)",
"row index out of bounds");
60 fPtr = matrix.GetMatrixArray()+fRowInd*matrix.GetNcols();
67 template<
class Element>
68 TMatrixTRow_const<Element>::TMatrixTRow_const(
const TMatrixTSym<Element> &matrix,Int_t row)
70 R__ASSERT(matrix.IsValid());
72 fRowInd = row-matrix.GetRowLwb();
73 if (fRowInd >= matrix.GetNrows() || fRowInd < 0) {
74 Error(
"TMatrixTRow_const(const TMatrixTSym &,Int_t)",
"row index out of bounds");
82 fPtr = matrix.GetMatrixArray()+fRowInd*matrix.GetNcols();
89 template<
class Element>
90 TMatrixTRow<Element>::TMatrixTRow(TMatrixT<Element> &matrix,Int_t row)
91 :TMatrixTRow_const<Element>(matrix,row)
98 template<
class Element>
99 TMatrixTRow<Element>::TMatrixTRow(TMatrixTSym<Element> &matrix,Int_t row)
100 :TMatrixTRow_const<Element>(matrix,row)
107 template<
class Element>
108 TMatrixTRow<Element>::TMatrixTRow(
const TMatrixTRow<Element> &mr) : TMatrixTRow_const<Element>(mr)
116 template<
class Element>
117 void TMatrixTRow<Element>::Assign(Element val)
119 R__ASSERT(this->fMatrix->IsValid());
120 Element *rp =
const_cast<Element *
>(this->fPtr);
121 for ( ; rp < this->fPtr+this->fMatrix->GetNcols(); rp += this->fInc)
125 template<
class Element>
126 void TMatrixTRow<Element>::operator=(std::initializer_list<Element> l)
128 R__ASSERT(this->fMatrix->IsValid());
129 Element *rp =
const_cast<Element *
>(this->fPtr);
130 auto litr = l.begin();
131 for ( ; rp < this->fPtr+this->fMatrix->GetNcols() && litr != l.end(); rp += this->fInc)
138 template<
class Element>
139 void TMatrixTRow<Element>::operator+=(Element val)
141 R__ASSERT(this->fMatrix->IsValid());
142 Element *rp =
const_cast<Element *
>(this->fPtr);
143 for ( ; rp < this->fPtr+this->fMatrix->GetNcols(); rp += this->fInc)
150 template<
class Element>
151 void TMatrixTRow<Element>::operator*=(Element val)
153 R__ASSERT(this->fMatrix->IsValid());
154 Element *rp =
const_cast<Element *
>(this->fPtr);
155 for ( ; rp < this->fPtr + this->fMatrix->GetNcols(); rp += this->fInc)
162 template<
class Element>
163 void TMatrixTRow<Element>::operator=(
const TMatrixTRow_const<Element> &mr)
165 const TMatrixTBase<Element> *mt = mr.GetMatrix();
166 if (this->fMatrix->GetMatrixArray() == mt->GetMatrixArray() && this->fRowInd == mr.GetRowIndex())
return;
168 R__ASSERT(this->fMatrix->IsValid());
169 R__ASSERT(mt->IsValid());
171 if (this->fMatrix->GetNcols() != mt->GetNcols() || this->fMatrix->GetColLwb() != mt->GetColLwb()) {
172 Error(
"operator=(const TMatrixTRow_const &)",
"matrix rows not compatible");
176 Element *rp1 =
const_cast<Element *
>(this->fPtr);
177 const Element *rp2 = mr.GetPtr();
178 for ( ; rp1 < this->fPtr+this->fMatrix->GetNcols(); rp1 += this->fInc,rp2 += mr.GetInc())
186 template<
class Element>
187 void TMatrixTRow<Element>::operator=(
const TVectorT<Element> &vec)
189 R__ASSERT(this->fMatrix->IsValid());
190 R__ASSERT(vec.IsValid());
192 if (this->fMatrix->GetColLwb() != vec.GetLwb() || this->fMatrix->GetNcols() != vec.GetNrows()) {
193 Error(
"operator=(const TVectorT &)",
"vector length != matrix-row length");
197 Element *rp =
const_cast<Element *
>(this->fPtr);
198 const Element *vp = vec.GetMatrixArray();
199 for ( ; rp < this->fPtr+this->fMatrix->GetNcols(); rp += this->fInc)
206 template<
class Element>
207 void TMatrixTRow<Element>::operator+=(
const TMatrixTRow_const<Element> &r)
209 const TMatrixTBase<Element> *mt = r.GetMatrix();
211 R__ASSERT(this->fMatrix->IsValid());
212 R__ASSERT(mt->IsValid());
214 if (this->fMatrix->GetColLwb() != mt->GetColLwb() || this->fMatrix->GetNcols() != mt->GetNcols()) {
215 Error(
"operator+=(const TMatrixTRow_const &)",
"different row lengths");
219 Element *rp1 =
const_cast<Element *
>(this->fPtr);
220 const Element *rp2 = r.GetPtr();
221 for ( ; rp1 < this->fPtr+this->fMatrix->GetNcols(); rp1 += this->fInc,rp2 += r.GetInc())
229 template<
class Element>
230 void TMatrixTRow<Element>::operator*=(
const TMatrixTRow_const<Element> &r)
232 const TMatrixTBase<Element> *mt = r.GetMatrix();
234 R__ASSERT(this->fMatrix->IsValid());
235 R__ASSERT(mt->IsValid());
237 if (this->fMatrix->GetColLwb() != mt->GetColLwb() || this->fMatrix->GetNcols() != mt->GetNcols()) {
238 Error(
"operator*=(const TMatrixTRow_const &)",
"different row lengths");
242 Element *rp1 =
const_cast<Element *
>(this->fPtr);
243 const Element *rp2 = r.GetPtr();
244 for ( ; rp1 < this->fPtr+this->fMatrix->GetNcols(); rp1 += this->fInc,rp2 += r.GetInc())
251 template<
class Element>
252 TMatrixTColumn_const<Element>::TMatrixTColumn_const(
const TMatrixT<Element> &matrix,Int_t col)
254 R__ASSERT(matrix.IsValid());
256 this->fColInd = col-matrix.GetColLwb();
257 if (this->fColInd >= matrix.GetNcols() || this->fColInd < 0) {
258 Error(
"TMatrixTColumn_const(const TMatrixT &,Int_t)",
"column index out of bounds");
266 fPtr = matrix.GetMatrixArray()+fColInd;
267 fInc = matrix.GetNcols();
273 template<
class Element>
274 TMatrixTColumn_const<Element>::TMatrixTColumn_const(
const TMatrixTSym<Element> &matrix,Int_t col)
276 R__ASSERT(matrix.IsValid());
278 fColInd = col-matrix.GetColLwb();
279 if (fColInd >= matrix.GetNcols() || fColInd < 0) {
280 Error(
"TMatrixTColumn_const(const TMatrixTSym &,Int_t)",
"column index out of bounds");
288 fPtr = matrix.GetMatrixArray()+fColInd;
289 fInc = matrix.GetNcols();
295 template<
class Element>
296 TMatrixTColumn<Element>::TMatrixTColumn(TMatrixT<Element> &matrix,Int_t col)
297 :TMatrixTColumn_const<Element>(matrix,col)
304 template<
class Element>
305 TMatrixTColumn<Element>::TMatrixTColumn(TMatrixTSym<Element> &matrix,Int_t col)
306 :TMatrixTColumn_const<Element>(matrix,col)
313 template<
class Element>
314 TMatrixTColumn<Element>::TMatrixTColumn(
const TMatrixTColumn<Element> &mc) : TMatrixTColumn_const<Element>(mc)
322 template<
class Element>
323 void TMatrixTColumn<Element>::Assign(Element val)
325 R__ASSERT(this->fMatrix->IsValid());
326 Element *cp =
const_cast<Element *
>(this->fPtr);
327 for ( ; cp < this->fPtr+this->fMatrix->GetNoElements(); cp += this->fInc)
334 template<
class Element>
335 void TMatrixTColumn<Element>::operator=(std::initializer_list<Element> l)
337 R__ASSERT(this->fMatrix->IsValid());
338 Element *rp =
const_cast<Element *
>(this->fPtr);
339 auto litr = l.begin();
340 for ( ; rp < this->fPtr+this->fMatrix->GetNoElements() && litr != l.end(); rp += this->fInc)
347 template<
class Element>
348 void TMatrixTColumn<Element>::operator+=(Element val)
350 R__ASSERT(this->fMatrix->IsValid());
351 Element *cp =
const_cast<Element *
>(this->fPtr);
352 for ( ; cp < this->fPtr+this->fMatrix->GetNoElements(); cp += this->fInc)
359 template<
class Element>
360 void TMatrixTColumn<Element>::operator*=(Element val)
362 R__ASSERT(this->fMatrix->IsValid());
363 Element *cp =
const_cast<Element *
>(this->fPtr);
364 for ( ; cp < this->fPtr+this->fMatrix->GetNoElements(); cp += this->fInc)
371 template<
class Element>
372 void TMatrixTColumn<Element>::operator=(
const TMatrixTColumn_const<Element> &mc)
374 const TMatrixTBase<Element> *mt = mc.GetMatrix();
375 if (this->fMatrix->GetMatrixArray() == mt->GetMatrixArray() && this->fColInd == mc.GetColIndex())
return;
377 R__ASSERT(this->fMatrix->IsValid());
378 R__ASSERT(mt->IsValid());
380 if (this->fMatrix->GetNrows() != mt->GetNrows() || this->fMatrix->GetRowLwb() != mt->GetRowLwb()) {
381 Error(
"operator=(const TMatrixTColumn_const &)",
"matrix columns not compatible");
385 Element *cp1 =
const_cast<Element *
>(this->fPtr);
386 const Element *cp2 = mc.GetPtr();
387 for ( ; cp1 < this->fPtr+this->fMatrix->GetNoElements(); cp1 += this->fInc,cp2 += mc.GetInc())
394 template<
class Element>
395 void TMatrixTColumn<Element>::operator=(
const TVectorT<Element> &vec)
397 R__ASSERT(this->fMatrix->IsValid());
398 R__ASSERT(vec.IsValid());
400 if (this->fMatrix->GetRowLwb() != vec.GetLwb() || this->fMatrix->GetNrows() != vec.GetNrows()) {
401 Error(
"operator=(const TVectorT &)",
"vector length != matrix-column length");
405 Element *cp =
const_cast<Element *
>(this->fPtr);
406 const Element *vp = vec.GetMatrixArray();
407 for ( ; cp < this->fPtr+this->fMatrix->GetNoElements(); cp += this->fInc)
410 R__ASSERT(vp == vec.GetMatrixArray()+vec.GetNrows());
416 template<
class Element>
417 void TMatrixTColumn<Element>::operator+=(
const TMatrixTColumn_const<Element> &mc)
419 const TMatrixTBase<Element> *mt = mc.GetMatrix();
421 R__ASSERT(this->fMatrix->IsValid());
422 R__ASSERT(mt->IsValid());
424 if (this->fMatrix->GetRowLwb() != mt->GetRowLwb() || this->fMatrix->GetNrows() != mt->GetNrows()) {
425 Error(
"operator+=(const TMatrixTColumn_const &)",
"different row lengths");
429 Element *cp1 =
const_cast<Element *
>(this->fPtr);
430 const Element *cp2 = mc.GetPtr();
431 for ( ; cp1 < this->fPtr+this->fMatrix->GetNoElements(); cp1 += this->fInc,cp2 += mc.GetInc())
439 template<
class Element>
440 void TMatrixTColumn<Element>::operator*=(
const TMatrixTColumn_const<Element> &mc)
442 const TMatrixTBase<Element> *mt = mc.GetMatrix();
444 R__ASSERT(this->fMatrix->IsValid());
445 R__ASSERT(mt->IsValid());
447 if (this->fMatrix->GetRowLwb() != mt->GetRowLwb() || this->fMatrix->GetNrows() != mt->GetNrows()) {
448 Error(
"operator*=(const TMatrixTColumn_const &)",
"different row lengths");
452 Element *cp1 =
const_cast<Element *
>(this->fPtr);
453 const Element *cp2 = mc.GetPtr();
454 for ( ; cp1 < this->fPtr+this->fMatrix->GetNoElements(); cp1 += this->fInc,cp2 += mc.GetInc())
461 template<
class Element>
462 TMatrixTDiag_const<Element>::TMatrixTDiag_const(
const TMatrixT<Element> &matrix)
464 R__ASSERT(matrix.IsValid());
467 fNdiag = TMath::Min(matrix.GetNrows(),matrix.GetNcols());
468 fPtr = matrix.GetMatrixArray();
469 fInc = matrix.GetNcols()+1;
475 template<
class Element>
476 TMatrixTDiag_const<Element>::TMatrixTDiag_const(
const TMatrixTSym<Element> &matrix)
478 R__ASSERT(matrix.IsValid());
481 fNdiag = TMath::Min(matrix.GetNrows(),matrix.GetNcols());
482 fPtr = matrix.GetMatrixArray();
483 fInc = matrix.GetNcols()+1;
489 template<
class Element>
490 TMatrixTDiag<Element>::TMatrixTDiag(TMatrixT<Element> &matrix)
491 :TMatrixTDiag_const<Element>(matrix)
498 template<
class Element>
499 TMatrixTDiag<Element>::TMatrixTDiag(TMatrixTSym<Element> &matrix)
500 :TMatrixTDiag_const<Element>(matrix)
507 template<
class Element>
508 TMatrixTDiag<Element>::TMatrixTDiag(
const TMatrixTDiag<Element> &md) : TMatrixTDiag_const<Element>(md)
516 template<
class Element>
517 void TMatrixTDiag<Element>::operator=(Element val)
519 R__ASSERT(this->fMatrix->IsValid());
520 Element *dp =
const_cast<Element *
>(this->fPtr);
521 for (Int_t i = 0; i < this->fNdiag; i++, dp += this->fInc)
528 template<
class Element>
529 void TMatrixTDiag<Element>::operator+=(Element val)
531 R__ASSERT(this->fMatrix->IsValid());
532 Element *dp =
const_cast<Element *
>(this->fPtr);
533 for (Int_t i = 0; i < this->fNdiag; i++, dp += this->fInc)
540 template<
class Element>
541 void TMatrixTDiag<Element>::operator*=(Element val)
543 R__ASSERT(this->fMatrix->IsValid());
544 Element *dp =
const_cast<Element *
>(this->fPtr);
545 for (Int_t i = 0; i < this->fNdiag; i++, dp += this->fInc)
552 template<
class Element>
553 void TMatrixTDiag<Element>::operator=(
const TMatrixTDiag_const<Element> &md)
555 const TMatrixTBase<Element> *mt = md.GetMatrix();
556 if (this->fMatrix == mt)
return;
558 R__ASSERT(this->fMatrix->IsValid());
559 R__ASSERT(mt->IsValid());
561 if (this->GetNdiags() != md.GetNdiags()) {
562 Error(
"operator=(const TMatrixTDiag_const &)",
"diagonals not compatible");
566 Element *dp1 =
const_cast<Element *
>(this->fPtr);
567 const Element *dp2 = md.GetPtr();
568 for (Int_t i = 0; i < this->fNdiag; i++, dp1 += this->fInc, dp2 += md.GetInc())
575 template<
class Element>
576 void TMatrixTDiag<Element>::operator=(
const TVectorT<Element> &vec)
578 R__ASSERT(this->fMatrix->IsValid());
579 R__ASSERT(vec.IsValid());
581 if (this->fNdiag != vec.GetNrows()) {
582 Error(
"operator=(const TVectorT &)",
"vector length != matrix-diagonal length");
586 Element *dp =
const_cast<Element *
>(this->fPtr);
587 const Element *vp = vec.GetMatrixArray();
588 for ( ; vp < vec.GetMatrixArray()+vec.GetNrows(); dp += this->fInc)
596 template<
class Element>
597 void TMatrixTDiag<Element>::operator+=(
const TMatrixTDiag_const<Element> &md)
599 const TMatrixTBase<Element> *mt = md.GetMatrix();
601 R__ASSERT(this->fMatrix->IsValid());
602 R__ASSERT(mt->IsValid());
603 if (this->fNdiag != md.GetNdiags()) {
604 Error(
"operator=(const TMatrixTDiag_const &)",
"matrix-diagonal's different length");
608 Element *dp1 =
const_cast<Element *
>(this->fPtr);
609 const Element *dp2 = md.GetPtr();
610 for (Int_t i = 0; i < this->fNdiag; i++, dp1 += this->fInc, dp2 += md.GetInc())
618 template<
class Element>
619 void TMatrixTDiag<Element>::operator*=(
const TMatrixTDiag_const<Element> &md)
621 const TMatrixTBase<Element> *mt = md.GetMatrix();
623 R__ASSERT(this->fMatrix->IsValid());
624 R__ASSERT(mt->IsValid());
625 if (this->fNdiag != md.GetNdiags()) {
626 Error(
"operator*=(const TMatrixTDiag_const &)",
"matrix-diagonal's different length");
630 Element *dp1 =
const_cast<Element *
>(this->fPtr);
631 const Element *dp2 = md.GetPtr();
632 for (Int_t i = 0; i < this->fNdiag; i++, dp1 += this->fInc, dp2 += md.GetInc())
639 template<
class Element>
640 TMatrixTFlat_const<Element>::TMatrixTFlat_const(
const TMatrixT<Element> &matrix)
642 R__ASSERT(matrix.IsValid());
645 fPtr = matrix.GetMatrixArray();
646 fNelems = matrix.GetNoElements();
652 template<
class Element>
653 TMatrixTFlat_const<Element>::TMatrixTFlat_const(
const TMatrixTSym<Element> &matrix)
655 R__ASSERT(matrix.IsValid());
658 fPtr = matrix.GetMatrixArray();
659 fNelems = matrix.GetNoElements();
665 template<
class Element>
666 TMatrixTFlat<Element>::TMatrixTFlat(TMatrixT<Element> &matrix)
667 :TMatrixTFlat_const<Element>(matrix)
674 template<
class Element>
675 TMatrixTFlat<Element>::TMatrixTFlat(TMatrixTSym<Element> &matrix)
676 :TMatrixTFlat_const<Element>(matrix)
683 template<
class Element>
684 TMatrixTFlat<Element>::TMatrixTFlat(
const TMatrixTFlat<Element> &mf) : TMatrixTFlat_const<Element>(mf)
692 template<
class Element>
693 void TMatrixTFlat<Element>::operator=(Element val)
695 R__ASSERT(this->fMatrix->IsValid());
696 Element *fp =
const_cast<Element *
>(this->fPtr);
697 while (fp < this->fPtr+this->fMatrix->GetNoElements())
704 template<
class Element>
705 void TMatrixTFlat<Element>::operator+=(Element val)
707 R__ASSERT(this->fMatrix->IsValid());
708 Element *fp =
const_cast<Element *
>(this->fPtr);
709 while (fp < this->fPtr+this->fMatrix->GetNoElements())
716 template<
class Element>
717 void TMatrixTFlat<Element>::operator*=(Element val)
719 R__ASSERT(this->fMatrix->IsValid());
720 Element *fp =
const_cast<Element *
>(this->fPtr);
721 while (fp < this->fPtr+this->fMatrix->GetNoElements())
728 template<
class Element>
729 void TMatrixTFlat<Element>::operator=(
const TMatrixTFlat_const<Element> &mf)
731 const TMatrixTBase<Element> *mt = mf.GetMatrix();
732 if (this->fMatrix->GetMatrixArray() == mt->GetMatrixArray())
return;
734 R__ASSERT(this->fMatrix->IsValid());
735 R__ASSERT(mt->IsValid());
736 if (this->fMatrix->GetNoElements() != mt->GetNoElements()) {
737 Error(
"operator=(const TMatrixTFlat_const &)",
"matrix lengths different");
741 Element *fp1 =
const_cast<Element *
>(this->fPtr);
742 const Element *fp2 = mf.GetPtr();
743 while (fp1 < this->fPtr+this->fMatrix->GetNoElements())
750 template<
class Element>
751 void TMatrixTFlat<Element>::operator=(
const TVectorT<Element> &vec)
753 R__ASSERT(vec.IsValid());
755 if (this->fMatrix->GetNoElements() != vec.GetNrows()) {
756 Error(
"operator=(const TVectorT &)",
"vector length != # matrix-elements");
760 Element *fp =
const_cast<Element *
>(this->fPtr);
761 const Element *vp = vec.GetMatrixArray();
762 while (fp < this->fPtr+this->fMatrix->GetNoElements())
769 template<
class Element>
770 void TMatrixTFlat<Element>::operator+=(
const TMatrixTFlat_const<Element> &mf)
772 const TMatrixTBase<Element> *mt = mf.GetMatrix();
774 R__ASSERT(this->fMatrix->IsValid());
775 R__ASSERT(mt->IsValid());
776 if (this->fMatrix->GetNoElements() != mt->GetNoElements()) {
777 Error(
"operator+=(const TMatrixTFlat_const &)",
"matrices lengths different");
781 Element *fp1 =
const_cast<Element *
>(this->fPtr);
782 const Element *fp2 = mf.GetPtr();
783 while (fp1 < this->fPtr + this->fMatrix->GetNoElements())
790 template<
class Element>
791 void TMatrixTFlat<Element>::operator*=(
const TMatrixTFlat_const<Element> &mf)
793 const TMatrixTBase<Element> *mt = mf.GetMatrix();
795 R__ASSERT(this->fMatrix->IsValid());
796 R__ASSERT(mt->IsValid());
797 if (this->fMatrix->GetNoElements() != mt->GetNoElements()) {
798 Error(
"operator*=(const TMatrixTFlat_const &)",
"matrices lengths different");
802 Element *fp1 =
const_cast<Element *
>(this->fPtr);
803 const Element *fp2 = mf.GetPtr();
804 while (fp1 < this->fPtr + this->fMatrix->GetNoElements())
813 template<
class Element>
814 TMatrixTSub_const<Element>::TMatrixTSub_const(
const TMatrixT<Element> &matrix,Int_t row_lwbs,Int_t row_upbs,
815 Int_t col_lwbs,Int_t col_upbs)
817 R__ASSERT(matrix.IsValid());
825 if (row_upbs < row_lwbs) {
826 Error(
"TMatrixTSub_const",
"Request sub-matrix with row_upbs(%d) < row_lwbs(%d)",row_upbs,row_lwbs);
829 if (col_upbs < col_lwbs) {
830 Error(
"TMatrixTSub_const",
"Request sub-matrix with col_upbs(%d) < col_lwbs(%d)",col_upbs,col_lwbs);
834 const Int_t rowLwb = matrix.GetRowLwb();
835 const Int_t rowUpb = matrix.GetRowUpb();
836 const Int_t colLwb = matrix.GetColLwb();
837 const Int_t colUpb = matrix.GetColUpb();
839 if (row_lwbs < rowLwb || row_lwbs > rowUpb) {
840 Error(
"TMatrixTSub_const",
"Request row_lwbs sub-matrix(%d) outside matrix range of %d - %d",row_lwbs,rowLwb,rowUpb);
843 if (col_lwbs < colLwb || col_lwbs > colUpb) {
844 Error(
"TMatrixTSub_const",
"Request col_lwbs sub-matrix(%d) outside matrix range of %d - %d",col_lwbs,colLwb,colUpb);
847 if (row_upbs < rowLwb || row_upbs > rowUpb) {
848 Error(
"TMatrixTSub_const",
"Request row_upbs sub-matrix(%d) outside matrix range of %d - %d",row_upbs,rowLwb,rowUpb);
851 if (col_upbs < colLwb || col_upbs > colUpb) {
852 Error(
"TMatrixTSub_const",
"Request col_upbs sub-matrix(%d) outside matrix range of %d - %d",col_upbs,colLwb,colUpb);
856 fRowOff = row_lwbs-rowLwb;
857 fColOff = col_lwbs-colLwb;
858 fNrowsSub = row_upbs-row_lwbs+1;
859 fNcolsSub = col_upbs-col_lwbs+1;
867 template<
class Element>
868 TMatrixTSub_const<Element>::TMatrixTSub_const(
const TMatrixTSym<Element> &matrix,Int_t row_lwbs,Int_t row_upbs,
869 Int_t col_lwbs,Int_t col_upbs)
871 R__ASSERT(matrix.IsValid());
879 if (row_upbs < row_lwbs) {
880 Error(
"TMatrixTSub_const",
"Request sub-matrix with row_upbs(%d) < row_lwbs(%d)",row_upbs,row_lwbs);
883 if (col_upbs < col_lwbs) {
884 Error(
"TMatrixTSub_const",
"Request sub-matrix with col_upbs(%d) < col_lwbs(%d)",col_upbs,col_lwbs);
888 const Int_t rowLwb = matrix.GetRowLwb();
889 const Int_t rowUpb = matrix.GetRowUpb();
890 const Int_t colLwb = matrix.GetColLwb();
891 const Int_t colUpb = matrix.GetColUpb();
893 if (row_lwbs < rowLwb || row_lwbs > rowUpb) {
894 Error(
"TMatrixTSub_const",
"Request row_lwbs sub-matrix(%d) outside matrix range of %d - %d",row_lwbs,rowLwb,rowUpb);
897 if (col_lwbs < colLwb || col_lwbs > colUpb) {
898 Error(
"TMatrixTSub_const",
"Request col_lwbs sub-matrix(%d) outside matrix range of %d - %d",col_lwbs,colLwb,colUpb);
901 if (row_upbs < rowLwb || row_upbs > rowUpb) {
902 Error(
"TMatrixTSub_const",
"Request row_upbs sub-matrix(%d) outside matrix range of %d - %d",row_upbs,rowLwb,rowUpb);
905 if (col_upbs < colLwb || col_upbs > colUpb) {
906 Error(
"TMatrixTSub_const",
"Request col_upbs sub-matrix(%d) outside matrix range of %d - %d",col_upbs,colLwb,colUpb);
910 fRowOff = row_lwbs-rowLwb;
911 fColOff = col_lwbs-colLwb;
912 fNrowsSub = row_upbs-row_lwbs+1;
913 fNcolsSub = col_upbs-col_lwbs+1;
919 template<
class Element>
920 TMatrixTSub<Element>::TMatrixTSub(TMatrixT<Element> &matrix,Int_t row_lwbs,Int_t row_upbs,
921 Int_t col_lwbs,Int_t col_upbs)
922 :TMatrixTSub_const<Element>(matrix,row_lwbs,row_upbs,col_lwbs,col_upbs)
929 template<
class Element>
930 TMatrixTSub<Element>::TMatrixTSub(TMatrixTSym<Element> &matrix,Int_t row_lwbs,Int_t row_upbs,
931 Int_t col_lwbs,Int_t col_upbs)
932 :TMatrixTSub_const<Element>(matrix,row_lwbs,row_upbs,col_lwbs,col_upbs)
939 template<
class Element>
940 TMatrixTSub<Element>::TMatrixTSub(
const TMatrixTSub<Element> &ms) : TMatrixTSub_const<Element>(ms)
949 template<
class Element>
950 void TMatrixTSub<Element>::Rank1Update(
const TVectorT<Element> &v,Element alpha)
952 R__ASSERT(this->fMatrix->IsValid());
953 R__ASSERT(v.IsValid());
955 if (v.GetNoElements() < TMath::Max(this->fNrowsSub,this->fNcolsSub)) {
956 Error(
"Rank1Update",
"vector too short");
960 const Element *
const pv = v.GetMatrixArray();
961 Element *mp = (
const_cast<TMatrixTBase<Element> *
>(this->fMatrix))->GetMatrixArray();
963 const Int_t ncols = this->fMatrix->GetNcols();
964 for (Int_t irow = 0; irow < this->fNrowsSub; irow++) {
965 const Int_t off = (irow+this->fRowOff)*ncols+this->fColOff;
966 const Element tmp = alpha*pv[irow];
967 for (Int_t icol = 0; icol < this->fNcolsSub; icol++)
968 mp[off+icol] += tmp*pv[icol];
975 template<
class Element>
976 void TMatrixTSub<Element>::operator=(Element val)
978 R__ASSERT(this->fMatrix->IsValid());
980 Element *p = (
const_cast<TMatrixTBase<Element> *
>(this->fMatrix))->GetMatrixArray();
981 const Int_t ncols = this->fMatrix->GetNcols();
982 for (Int_t irow = 0; irow < this->fNrowsSub; irow++) {
983 const Int_t off = (irow+this->fRowOff)*ncols+this->fColOff;
984 for (Int_t icol = 0; icol < this->fNcolsSub; icol++)
992 template<
class Element>
993 void TMatrixTSub<Element>::operator+=(Element val)
995 R__ASSERT(this->fMatrix->IsValid());
997 Element *p = (
const_cast<TMatrixTBase<Element> *
>(this->fMatrix))->GetMatrixArray();
998 const Int_t ncols = this->fMatrix->GetNcols();
999 for (Int_t irow = 0; irow < this->fNrowsSub; irow++) {
1000 const Int_t off = (irow+this->fRowOff)*ncols+this->fColOff;
1001 for (Int_t icol = 0; icol < this->fNcolsSub; icol++)
1009 template<
class Element>
1010 void TMatrixTSub<Element>::operator*=(Element val)
1012 R__ASSERT(this->fMatrix->IsValid());
1014 Element *p = (
const_cast<TMatrixTBase<Element> *
>(this->fMatrix))->GetMatrixArray();
1015 const Int_t ncols = this->fMatrix->GetNcols();
1016 for (Int_t irow = 0; irow < this->fNrowsSub; irow++) {
1017 const Int_t off = (irow+this->fRowOff)*ncols+this->fColOff;
1018 for (Int_t icol = 0; icol < this->fNcolsSub; icol++)
1026 template<
class Element>
1027 void TMatrixTSub<Element>::operator=(
const TMatrixTSub_const<Element> &ms)
1029 const TMatrixTBase<Element> *mt = ms.GetMatrix();
1031 R__ASSERT(this->fMatrix->IsValid());
1032 R__ASSERT(mt->IsValid());
1034 if (this->fMatrix == mt &&
1035 (this->GetNrows() == ms.GetNrows () && this->GetNcols() == ms.GetNcols () &&
1036 this->GetRowOff() == ms.GetRowOff() && this->GetColOff() == ms.GetColOff()) )
1039 if (this->GetNrows() != ms.GetNrows() || this->GetNcols() != ms.GetNcols()) {
1040 Error(
"operator=(const TMatrixTSub_const &)",
"sub matrices have different size");
1044 const Int_t rowOff2 = ms.GetRowOff();
1045 const Int_t colOff2 = ms.GetColOff();
1047 Bool_t overlap = (this->fMatrix == mt) &&
1048 ( (rowOff2 >= this->fRowOff && rowOff2 < this->fRowOff+this->fNrowsSub) ||
1049 (colOff2 >= this->fColOff && colOff2 < this->fColOff+this->fNcolsSub) );
1051 Element *p1 =
const_cast<Element *
>(this->fMatrix->GetMatrixArray());
1053 const Element *p2 = mt->GetMatrixArray();
1055 const Int_t ncols1 = this->fMatrix->GetNcols();
1056 const Int_t ncols2 = mt->GetNcols();
1057 for (Int_t irow = 0; irow < this->fNrowsSub; irow++) {
1058 const Int_t off1 = (irow+this->fRowOff)*ncols1+this->fColOff;
1059 const Int_t off2 = (irow+rowOff2)*ncols2+colOff2;
1060 for (Int_t icol = 0; icol < this->fNcolsSub; icol++)
1061 p1[off1+icol] = p2[off2+icol];
1064 const Int_t row_lwbs = rowOff2+mt->GetRowLwb();
1065 const Int_t row_upbs = row_lwbs+this->fNrowsSub-1;
1066 const Int_t col_lwbs = colOff2+mt->GetColLwb();
1067 const Int_t col_upbs = col_lwbs+this->fNcolsSub-1;
1068 TMatrixT<Element> tmp; mt->GetSub(row_lwbs,row_upbs,col_lwbs,col_upbs,tmp);
1069 const Element *p2 = tmp.GetMatrixArray();
1071 const Int_t ncols1 = this->fMatrix->GetNcols();
1072 const Int_t ncols2 = tmp.GetNcols();
1073 for (Int_t irow = 0; irow < this->fNrowsSub; irow++) {
1074 const Int_t off1 = (irow+this->fRowOff)*ncols1+this->fColOff;
1075 const Int_t off2 = irow*ncols2;
1076 for (Int_t icol = 0; icol < this->fNcolsSub; icol++)
1077 p1[off1+icol] = p2[off2+icol];
1085 template<
class Element>
1086 void TMatrixTSub<Element>::operator=(
const TMatrixTBase<Element> &m)
1088 R__ASSERT(this->fMatrix->IsValid());
1089 R__ASSERT(m.IsValid());
1091 if (this->fMatrix->GetMatrixArray() == m.GetMatrixArray())
return;
1093 if (this->fNrowsSub != m.GetNrows() || this->fNcolsSub != m.GetNcols()) {
1094 Error(
"operator=(const TMatrixTBase<Element> &)",
"sub matrices and matrix have different size");
1097 const Int_t row_lwbs = this->fRowOff+this->fMatrix->GetRowLwb();
1098 const Int_t col_lwbs = this->fColOff+this->fMatrix->GetColLwb();
1099 (
const_cast<TMatrixTBase<Element> *
>(this->fMatrix))->SetSub(row_lwbs,col_lwbs,m);
1105 template<
class Element>
1106 void TMatrixTSub<Element>::operator+=(
const TMatrixTSub_const<Element> &ms)
1108 const TMatrixTBase<Element> *mt = ms.GetMatrix();
1110 R__ASSERT(this->fMatrix->IsValid());
1111 R__ASSERT(mt->IsValid());
1113 if (this->GetNrows() != ms.GetNrows() || this->GetNcols() != ms.GetNcols()) {
1114 Error(
"operator+=(const TMatrixTSub_const &)",
"sub matrices have different size");
1118 const Int_t rowOff2 = ms.GetRowOff();
1119 const Int_t colOff2 = ms.GetColOff();
1121 Bool_t overlap = (this->fMatrix == mt) &&
1122 ( (rowOff2 >= this->fRowOff && rowOff2 < this->fRowOff+this->fNrowsSub) ||
1123 (colOff2 >= this->fColOff && colOff2 < this->fColOff+this->fNcolsSub) );
1125 Element *p1 =
const_cast<Element *
>(this->fMatrix->GetMatrixArray());
1127 const Element *p2 = mt->GetMatrixArray();
1129 const Int_t ncols1 = this->fMatrix->GetNcols();
1130 const Int_t ncols2 = mt->GetNcols();
1131 for (Int_t irow = 0; irow < this->fNrowsSub; irow++) {
1132 const Int_t off1 = (irow+this->fRowOff)*ncols1+this->fColOff;
1133 const Int_t off2 = (irow+rowOff2)*ncols2+colOff2;
1134 for (Int_t icol = 0; icol < this->fNcolsSub; icol++)
1135 p1[off1+icol] += p2[off2+icol];
1138 const Int_t row_lwbs = rowOff2+mt->GetRowLwb();
1139 const Int_t row_upbs = row_lwbs+this->fNrowsSub-1;
1140 const Int_t col_lwbs = colOff2+mt->GetColLwb();
1141 const Int_t col_upbs = col_lwbs+this->fNcolsSub-1;
1142 TMatrixT<Element> tmp; mt->GetSub(row_lwbs,row_upbs,col_lwbs,col_upbs,tmp);
1143 const Element *p2 = tmp.GetMatrixArray();
1145 const Int_t ncols1 = this->fMatrix->GetNcols();
1146 const Int_t ncols2 = tmp.GetNcols();
1147 for (Int_t irow = 0; irow < this->fNrowsSub; irow++) {
1148 const Int_t off1 = (irow+this->fRowOff)*ncols1+this->fColOff;
1149 const Int_t off2 = irow*ncols2;
1150 for (Int_t icol = 0; icol < this->fNcolsSub; icol++)
1151 p1[off1+icol] += p2[off2+icol];
1159 template<
class Element>
1160 void TMatrixTSub<Element>::operator*=(
const TMatrixTSub_const<Element> &ms)
1162 if (this->fNcolsSub != ms.GetNrows() || this->fNcolsSub != ms.GetNcols()) {
1163 Error(
"operator*=(const TMatrixTSub_const &)",
"source sub matrix has wrong shape");
1167 const TMatrixTBase<Element> *source = ms.GetMatrix();
1169 TMatrixT<Element> source_sub;
1171 const Int_t row_lwbs = ms.GetRowOff()+source->GetRowLwb();
1172 const Int_t row_upbs = row_lwbs+this->fNrowsSub-1;
1173 const Int_t col_lwbs = ms.GetColOff()+source->GetColLwb();
1174 const Int_t col_upbs = col_lwbs+this->fNcolsSub-1;
1175 source->GetSub(row_lwbs,row_upbs,col_lwbs,col_upbs,source_sub);
1178 const Element *sp = source_sub.GetMatrixArray();
1179 const Int_t ncols = this->fMatrix->GetNcols();
1182 Element work[kWorkMax];
1183 Bool_t isAllocated = kFALSE;
1184 Element *trp = work;
1185 if (this->fNcolsSub > kWorkMax) {
1186 isAllocated = kTRUE;
1187 trp =
new Element[this->fNcolsSub];
1190 Element *cp =
const_cast<Element *
>(this->fMatrix->GetMatrixArray())+this->fRowOff*ncols+this->fColOff;
1191 const Element *trp0 = cp;
1192 const Element *
const trp0_last = trp0+this->fNrowsSub*ncols;
1193 while (trp0 < trp0_last) {
1194 memcpy(trp,trp0,this->fNcolsSub*
sizeof(Element));
1195 for (
const Element *scp = sp; scp < sp+this->fNcolsSub; ) {
1198 for (Int_t j = 0; j < this->fNcolsSub; j++) {
1199 cij += trp[j] * *scp;
1200 scp += this->fNcolsSub;
1203 scp -= source_sub.GetNoElements()-1;
1205 cp += ncols-this->fNcolsSub;
1207 R__ASSERT(trp0 == cp);
1210 R__ASSERT(cp == trp0_last && trp0 == trp0_last);
1218 template<
class Element>
1219 void TMatrixTSub<Element>::operator+=(
const TMatrixTBase<Element> &mt)
1221 R__ASSERT(this->fMatrix->IsValid());
1222 R__ASSERT(mt.IsValid());
1224 if (this->GetNrows() != mt.GetNrows() || this->GetNcols() != mt.GetNcols()) {
1225 Error(
"operator+=(const TMatrixTBase<Element> &)",
"sub matrix and matrix have different size");
1229 Element *p1 =
const_cast<Element *
>(this->fMatrix->GetMatrixArray());
1230 const Element *p2 = mt.GetMatrixArray();
1232 const Int_t ncols1 = this->fMatrix->GetNcols();
1233 const Int_t ncols2 = mt.GetNcols();
1234 for (Int_t irow = 0; irow < this->fNrowsSub; irow++) {
1235 const Int_t off1 = (irow+this->fRowOff)*ncols1+this->fColOff;
1236 const Int_t off2 = irow*ncols2;
1237 for (Int_t icol = 0; icol < this->fNcolsSub; icol++)
1238 p1[off1+icol] += p2[off2+icol];
1245 template<
class Element>
1246 void TMatrixTSub<Element>::operator*=(
const TMatrixT<Element> &source)
1248 if (this->fNcolsSub != source.GetNrows() || this->fNcolsSub != source.GetNcols()) {
1249 Error(
"operator*=(const TMatrixT<Element> &)",
"source matrix has wrong shape");
1255 TMatrixT<Element> tmp;
1256 if (this->fMatrix->GetMatrixArray() == source.GetMatrixArray()) {
1257 tmp.ResizeTo(source);
1259 sp = tmp.GetMatrixArray();
1262 sp = source.GetMatrixArray();
1264 const Int_t ncols = this->fMatrix->GetNcols();
1267 Element work[kWorkMax];
1268 Bool_t isAllocated = kFALSE;
1269 Element *trp = work;
1270 if (this->fNcolsSub > kWorkMax) {
1271 isAllocated = kTRUE;
1272 trp =
new Element[this->fNcolsSub];
1275 Element *cp =
const_cast<Element *
>(this->fMatrix->GetMatrixArray())+this->fRowOff*ncols+this->fColOff;
1276 const Element *trp0 = cp;
1277 const Element *
const trp0_last = trp0+this->fNrowsSub*ncols;
1278 while (trp0 < trp0_last) {
1279 memcpy(trp,trp0,this->fNcolsSub*
sizeof(Element));
1280 for (
const Element *scp = sp; scp < sp+this->fNcolsSub; ) {
1283 for (Int_t j = 0; j < this->fNcolsSub; j++) {
1284 cij += trp[j] * *scp;
1285 scp += this->fNcolsSub;
1288 scp -= source.GetNoElements()-1;
1290 cp += ncols-this->fNcolsSub;
1292 R__ASSERT(trp0 == cp);
1295 R__ASSERT(cp == trp0_last && trp0 == trp0_last);
1303 template<
class Element>
1304 void TMatrixTSub<Element>::operator*=(
const TMatrixTSym<Element> &source)
1306 if (this->fNcolsSub != source.GetNrows() || this->fNcolsSub != source.GetNcols()) {
1307 Error(
"operator*=(const TMatrixTSym<Element> &)",
"source matrix has wrong shape");
1313 TMatrixTSym<Element> tmp;
1314 if (this->fMatrix->GetMatrixArray() == source.GetMatrixArray()) {
1315 tmp.ResizeTo(source);
1317 sp = tmp.GetMatrixArray();
1320 sp = source.GetMatrixArray();
1322 const Int_t ncols = this->fMatrix->GetNcols();
1325 Element work[kWorkMax];
1326 Bool_t isAllocated = kFALSE;
1327 Element *trp = work;
1328 if (this->fNcolsSub > kWorkMax) {
1329 isAllocated = kTRUE;
1330 trp =
new Element[this->fNcolsSub];
1333 Element *cp =
const_cast<Element *
>(this->fMatrix->GetMatrixArray())+this->fRowOff*ncols+this->fColOff;
1334 const Element *trp0 = cp;
1335 const Element *
const trp0_last = trp0+this->fNrowsSub*ncols;
1336 while (trp0 < trp0_last) {
1337 memcpy(trp,trp0,this->fNcolsSub*
sizeof(Element));
1338 for (
const Element *scp = sp; scp < sp+this->fNcolsSub; ) {
1341 for (Int_t j = 0; j < this->fNcolsSub; j++) {
1342 cij += trp[j] * *scp;
1343 scp += this->fNcolsSub;
1346 scp -= source.GetNoElements()-1;
1348 cp += ncols-this->fNcolsSub;
1350 R__ASSERT(trp0 == cp);
1353 R__ASSERT(cp == trp0_last && trp0 == trp0_last);
1361 template<
class Element>
1362 TMatrixTSparseRow_const<Element>::TMatrixTSparseRow_const(
const TMatrixTSparse<Element> &matrix,Int_t row)
1364 R__ASSERT(matrix.IsValid());
1366 fRowInd = row-matrix.GetRowLwb();
1367 if (fRowInd >= matrix.GetNrows() || fRowInd < 0) {
1368 Error(
"TMatrixTSparseRow_const(const TMatrixTSparse &,Int_t)",
"row index out of bounds");
1376 const Int_t sIndex = matrix.GetRowIndexArray()[fRowInd];
1377 const Int_t eIndex = matrix.GetRowIndexArray()[fRowInd+1];
1379 fNindex = eIndex-sIndex;
1380 fColPtr = matrix.GetColIndexArray()+sIndex;
1381 fDataPtr = matrix.GetMatrixArray()+sIndex;
1386 template<
class Element>
1387 Element TMatrixTSparseRow_const<Element>::operator()(Int_t i)
const
1389 if (!fMatrix)
return TMatrixTBase<Element>::NaNValue();
1390 R__ASSERT(fMatrix->IsValid());
1391 const Int_t acoln = i-fMatrix->GetColLwb();
1392 if (acoln < fMatrix->GetNcols() && acoln >= 0) {
1393 const Int_t index = TMath::BinarySearch(fNindex,fColPtr,acoln);
1394 if (index >= 0 && fColPtr[index] == acoln)
return fDataPtr[index];
1397 Error(
"operator()",
"Request col(%d) outside matrix range of %d - %d",
1398 i,fMatrix->GetColLwb(),fMatrix->GetColLwb()+fMatrix->GetNcols());
1399 return TMatrixTBase<Element>::NaNValue();
1406 template<
class Element>
1407 TMatrixTSparseRow<Element>::TMatrixTSparseRow(TMatrixTSparse<Element> &matrix,Int_t row)
1408 : TMatrixTSparseRow_const<Element>(matrix,row)
1415 template<
class Element>
1416 TMatrixTSparseRow<Element>::TMatrixTSparseRow(
const TMatrixTSparseRow<Element> &mr)
1417 : TMatrixTSparseRow_const<Element>(mr)
1424 template<
class Element>
1425 Element TMatrixTSparseRow<Element>::operator()(Int_t i)
const
1427 if (!this->fMatrix)
return TMatrixTBase<Element>::NaNValue();
1428 R__ASSERT(this->fMatrix->IsValid());
1429 const Int_t acoln = i-this->fMatrix->GetColLwb();
1430 if (acoln < this->fMatrix->GetNcols() && acoln >= 0) {
1431 const Int_t index = TMath::BinarySearch(this->fNindex,this->fColPtr,acoln);
1432 if (index >= 0 && this->fColPtr[index] == acoln)
return this->fDataPtr[index];
1435 Error(
"operator()",
"Request col(%d) outside matrix range of %d - %d",
1436 i,this->fMatrix->GetColLwb(),this->fMatrix->GetColLwb()+this->fMatrix->GetNcols());
1437 return TMatrixTBase<Element>::NaNValue();
1444 template<
class Element>
1445 Element &TMatrixTSparseRow<Element>::operator()(Int_t i)
1447 if (!this->fMatrix)
return TMatrixTBase<Element>::NaNValue();
1448 R__ASSERT(this->fMatrix->IsValid());
1450 const Int_t acoln = i-this->fMatrix->GetColLwb();
1451 if (acoln >= this->fMatrix->GetNcols() || acoln < 0) {
1452 Error(
"operator()(Int_t",
"Requested element %d outside range : %d - %d",i,
1453 this->fMatrix->GetColLwb(),this->fMatrix->GetColLwb()+this->fMatrix->GetNcols());
1454 return TMatrixTBase<Element>::NaNValue();
1457 Int_t index = TMath::BinarySearch(this->fNindex,this->fColPtr,acoln);
1458 if (index >= 0 && this->fColPtr[index] == acoln)
1459 return (const_cast<Element*>(this->fDataPtr))[index];
1461 TMatrixTSparse<Element> *mt =
const_cast<TMatrixTSparse<Element> *
>(this->fMatrix);
1462 const Int_t row = this->fRowInd+mt->GetRowLwb();
1464 mt->InsertRow(row,i,&val,1);
1465 const Int_t sIndex = mt->GetRowIndexArray()[this->fRowInd];
1466 const Int_t eIndex = mt->GetRowIndexArray()[this->fRowInd+1];
1467 this->fNindex = eIndex-sIndex;
1468 this->fColPtr = mt->GetColIndexArray()+sIndex;
1469 this->fDataPtr = mt->GetMatrixArray()+sIndex;
1470 index = TMath::BinarySearch(this->fNindex,this->fColPtr,acoln);
1471 if (index >= 0 && this->fColPtr[index] == acoln)
1472 return (const_cast<Element*>(this->fDataPtr))[index];
1474 Error(
"operator()(Int_t",
"Insert row failed");
1475 return TMatrixTBase<Element>::NaNValue();
1483 template<
class Element>
1484 void TMatrixTSparseRow<Element>::operator=(Element val)
1486 R__ASSERT(this->fMatrix->IsValid());
1487 Element *rp =
const_cast<Element *
>(this->fDataPtr);
1488 for ( ; rp < this->fDataPtr+this->fNindex; rp++)
1495 template<
class Element>
1496 void TMatrixTSparseRow<Element>::operator+=(Element val)
1498 R__ASSERT(this->fMatrix->IsValid());
1499 Element *rp =
const_cast<Element *
>(this->fDataPtr);
1500 for ( ; rp < this->fDataPtr+this->fNindex; rp++)
1507 template<
class Element>
1508 void TMatrixTSparseRow<Element>::operator*=(Element val)
1510 R__ASSERT(this->fMatrix->IsValid());
1511 Element *rp =
const_cast<Element *
>(this->fDataPtr);
1512 for ( ; rp < this->fDataPtr+this->fNindex; rp++)
1519 template<
class Element>
1520 void TMatrixTSparseRow<Element>::operator=(
const TMatrixTSparseRow_const<Element> &mr)
1522 const TMatrixTBase<Element> *mt = mr.GetMatrix();
1523 if (this->fMatrix == mt)
return;
1525 R__ASSERT(this->fMatrix->IsValid());
1526 R__ASSERT(mt->IsValid());
1527 if (this->fMatrix->GetColLwb() != mt->GetColLwb() || this->fMatrix->GetNcols() != mt->GetNcols()) {
1528 Error(
"operator=(const TMatrixTSparseRow_const &)",
"matrix rows not compatible");
1532 const Int_t ncols = this->fMatrix->GetNcols();
1533 const Int_t row1 = this->fRowInd+this->fMatrix->GetRowLwb();
1534 const Int_t row2 = mr.GetRowIndex()+mt->GetRowLwb();
1535 const Int_t col = this->fMatrix->GetColLwb();
1537 TVectorT<Element> v(ncols);
1538 mt->ExtractRow(row2,col,v.GetMatrixArray());
1539 const_cast<TMatrixTSparse<Element> *
>(this->fMatrix)->InsertRow(row1,col,v.GetMatrixArray());
1541 const Int_t sIndex = this->fMatrix->GetRowIndexArray()[this->fRowInd];
1542 const Int_t eIndex = this->fMatrix->GetRowIndexArray()[this->fRowInd+1];
1543 this->fNindex = eIndex-sIndex;
1544 this->fColPtr = this->fMatrix->GetColIndexArray()+sIndex;
1545 this->fDataPtr = this->fMatrix->GetMatrixArray()+sIndex;
1552 template<
class Element>
1553 void TMatrixTSparseRow<Element>::operator=(
const TVectorT<Element> &vec)
1555 R__ASSERT(this->fMatrix->IsValid());
1556 R__ASSERT(vec.IsValid());
1558 if (this->fMatrix->GetColLwb() != vec.GetLwb() || this->fMatrix->GetNcols() != vec.GetNrows()) {
1559 Error(
"operator=(const TVectorT &)",
"vector length != matrix-row length");
1563 const Element *vp = vec.GetMatrixArray();
1564 const Int_t row = this->fRowInd+this->fMatrix->GetRowLwb();
1565 const Int_t col = this->fMatrix->GetColLwb();
1566 const_cast<TMatrixTSparse<Element> *
>(this->fMatrix)->InsertRow(row,col,vp,vec.GetNrows());
1568 const Int_t sIndex = this->fMatrix->GetRowIndexArray()[this->fRowInd];
1569 const Int_t eIndex = this->fMatrix->GetRowIndexArray()[this->fRowInd+1];
1570 this->fNindex = eIndex-sIndex;
1571 this->fColPtr = this->fMatrix->GetColIndexArray()+sIndex;
1572 this->fDataPtr = this->fMatrix->GetMatrixArray()+sIndex;
1578 template<
class Element>
1579 void TMatrixTSparseRow<Element>::operator+=(
const TMatrixTSparseRow_const<Element> &r)
1581 const TMatrixTBase<Element> *mt = r.GetMatrix();
1583 R__ASSERT(this->fMatrix->IsValid());
1584 R__ASSERT(mt->IsValid());
1585 if (this->fMatrix->GetColLwb() != mt->GetColLwb() || this->fMatrix->GetNcols() != mt->GetNcols()) {
1586 Error(
"operator+=(const TMatrixTRow_const &)",
"different row lengths");
1590 const Int_t ncols = this->fMatrix->GetNcols();
1591 const Int_t row1 = this->fRowInd+this->fMatrix->GetRowLwb();
1592 const Int_t row2 = r.GetRowIndex()+mt->GetRowLwb();
1593 const Int_t col = this->fMatrix->GetColLwb();
1595 TVectorT<Element> v1(ncols);
1596 TVectorT<Element> v2(ncols);
1597 this->fMatrix->ExtractRow(row1,col,v1.GetMatrixArray());
1598 mt ->ExtractRow(row2,col,v2.GetMatrixArray());
1600 const_cast<TMatrixTSparse<Element> *
>(this->fMatrix)->InsertRow(row1,col,v1.GetMatrixArray());
1602 const Int_t sIndex = this->fMatrix->GetRowIndexArray()[this->fRowInd];
1603 const Int_t eIndex = this->fMatrix->GetRowIndexArray()[this->fRowInd+1];
1604 this->fNindex = eIndex-sIndex;
1605 this->fColPtr = this->fMatrix->GetColIndexArray()+sIndex;
1606 this->fDataPtr = this->fMatrix->GetMatrixArray()+sIndex;
1613 template<
class Element>
1614 void TMatrixTSparseRow<Element>::operator*=(
const TMatrixTSparseRow_const<Element> &r)
1616 const TMatrixTBase<Element> *mt = r.GetMatrix();
1618 R__ASSERT(this->fMatrix->IsValid());
1619 R__ASSERT(mt->IsValid());
1620 if (this->fMatrix->GetColLwb() != mt->GetColLwb() || this->fMatrix->GetNcols() != mt->GetNcols()) {
1621 Error(
"operator+=(const TMatrixTRow_const &)",
"different row lengths");
1625 const Int_t ncols = this->fMatrix->GetNcols();
1626 const Int_t row1 = r.GetRowIndex()+mt->GetRowLwb();
1627 const Int_t row2 = r.GetRowIndex()+mt->GetRowLwb();
1628 const Int_t col = this->fMatrix->GetColLwb();
1630 TVectorT<Element> v1(ncols);
1631 TVectorT<Element> v2(ncols);
1632 this->fMatrix->ExtractRow(row1,col,v1.GetMatrixArray());
1633 mt ->ExtractRow(row2,col,v2.GetMatrixArray());
1636 const_cast<TMatrixTSparse<Element> *
>(this->fMatrix)->InsertRow(row1,col,v1.GetMatrixArray());
1638 const Int_t sIndex = this->fMatrix->GetRowIndexArray()[this->fRowInd];
1639 const Int_t eIndex = this->fMatrix->GetRowIndexArray()[this->fRowInd+1];
1640 this->fNindex = eIndex-sIndex;
1641 this->fColPtr = this->fMatrix->GetColIndexArray()+sIndex;
1642 this->fDataPtr = this->fMatrix->GetMatrixArray()+sIndex;
1648 template<
class Element>
1649 TMatrixTSparseDiag_const<Element>::TMatrixTSparseDiag_const(
const TMatrixTSparse<Element> &matrix)
1651 R__ASSERT(matrix.IsValid());
1654 fNdiag = TMath::Min(matrix.GetNrows(),matrix.GetNcols());
1655 fDataPtr = matrix.GetMatrixArray();
1660 template<
class Element>
1661 Element TMatrixTSparseDiag_const<Element>::operator()(Int_t i)
const
1663 R__ASSERT(fMatrix->IsValid());
1664 if (i < fNdiag && i >= 0) {
1665 const Int_t *
const pR = fMatrix->GetRowIndexArray();
1666 const Int_t *
const pC = fMatrix->GetColIndexArray();
1667 const Element *
const pD = fMatrix->GetMatrixArray();
1668 const Int_t sIndex = pR[i];
1669 const Int_t eIndex = pR[i+1];
1670 const Int_t index = TMath::BinarySearch(eIndex-sIndex,pC+sIndex,i)+sIndex;
1671 if (index >= sIndex && pC[index] == i)
return pD[index];
1674 Error(
"operator()",
"Request diagonal(%d) outside matrix range of 0 - %d",i,fNdiag);
1683 template<
class Element>
1684 TMatrixTSparseDiag<Element>::TMatrixTSparseDiag(TMatrixTSparse<Element> &matrix)
1685 :TMatrixTSparseDiag_const<Element>(matrix)
1692 template<
class Element>
1693 TMatrixTSparseDiag<Element>::TMatrixTSparseDiag(
const TMatrixTSparseDiag<Element> &md)
1694 : TMatrixTSparseDiag_const<Element>(md)
1701 template<
class Element>
1702 Element TMatrixTSparseDiag<Element>::operator()(Int_t i)
const
1704 R__ASSERT(this->fMatrix->IsValid());
1705 if (i < this->fNdiag && i >= 0) {
1706 const Int_t *
const pR = this->fMatrix->GetRowIndexArray();
1707 const Int_t *
const pC = this->fMatrix->GetColIndexArray();
1708 const Element *
const pD = this->fMatrix->GetMatrixArray();
1709 const Int_t sIndex = pR[i];
1710 const Int_t eIndex = pR[i+1];
1711 const Int_t index = TMath::BinarySearch(eIndex-sIndex,pC+sIndex,i)+sIndex;
1712 if (index >= sIndex && pC[index] == i)
return pD[index];
1715 Error(
"operator()",
"Request diagonal(%d) outside matrix range of 0 - %d",i,this->fNdiag);
1724 template<
class Element>
1725 Element &TMatrixTSparseDiag<Element>::operator()(Int_t i)
1727 R__ASSERT(this->fMatrix->IsValid());
1729 if (i < 0 || i >= this->fNdiag) {
1730 Error(
"operator()(Int_t",
"Requested element %d outside range : 0 - %d",i,this->fNdiag);
1731 return (const_cast<Element*>(this->fDataPtr))[0];
1734 TMatrixTSparse<Element> *mt =
const_cast<TMatrixTSparse<Element> *
>(this->fMatrix);
1735 const Int_t *pR = mt->GetRowIndexArray();
1736 const Int_t *pC = mt->GetColIndexArray();
1737 Int_t sIndex = pR[i];
1738 Int_t eIndex = pR[i+1];
1739 Int_t index = TMath::BinarySearch(eIndex-sIndex,pC+sIndex,i)+sIndex;
1740 if (index >= sIndex && pC[index] == i)
1741 return (const_cast<Element*>(this->fDataPtr))[index];
1743 const Int_t row = i+mt->GetRowLwb();
1744 const Int_t col = i+mt->GetColLwb();
1746 mt->InsertRow(row,col,&val,1);
1747 this->fDataPtr = mt->GetMatrixArray();
1748 pR = mt->GetRowIndexArray();
1749 pC = mt->GetColIndexArray();
1752 index = TMath::BinarySearch(eIndex-sIndex,pC+sIndex,i)+sIndex;
1753 if (index >= sIndex && pC[index] == i)
1754 return (const_cast<Element*>(this->fDataPtr))[index];
1756 Error(
"operator()(Int_t",
"Insert row failed");
1757 return (const_cast<Element*>(this->fDataPtr))[0];
1765 template<
class Element>
1766 void TMatrixTSparseDiag<Element>::operator=(Element val)
1768 R__ASSERT(this->fMatrix->IsValid());
1769 for (Int_t i = 0; i < this->fNdiag; i++)
1776 template<
class Element>
1777 void TMatrixTSparseDiag<Element>::operator+=(Element val)
1779 R__ASSERT(this->fMatrix->IsValid());
1780 for (Int_t i = 0; i < this->fNdiag; i++)
1787 template<
class Element>
1788 void TMatrixTSparseDiag<Element>::operator*=(Element val)
1790 R__ASSERT(this->fMatrix->IsValid());
1791 for (Int_t i = 0; i < this->fNdiag; i++)
1798 template<
class Element>
1799 void TMatrixTSparseDiag<Element>::operator=(
const TMatrixTSparseDiag_const<Element> &md)
1801 const TMatrixTBase<Element> *mt = md.GetMatrix();
1802 if (this->fMatrix == mt)
return;
1804 R__ASSERT(this->fMatrix->IsValid());
1805 R__ASSERT(mt->IsValid());
1806 if (this->fNdiag != md.GetNdiags()) {
1807 Error(
"operator=(const TMatrixTSparseDiag_const &)",
"matrix-diagonal's different length");
1811 for (Int_t i = 0; i < this->fNdiag; i++)
1818 template<
class Element>
1819 void TMatrixTSparseDiag<Element>::operator=(
const TVectorT<Element> &vec)
1821 R__ASSERT(this->fMatrix->IsValid());
1822 R__ASSERT(vec.IsValid());
1824 if (this->fNdiag != vec.GetNrows()) {
1825 Error(
"operator=(const TVectorT &)",
"vector length != matrix-diagonal length");
1829 const Element *vp = vec.GetMatrixArray();
1830 for (Int_t i = 0; i < this->fNdiag; i++)
1838 template<
class Element>
1839 void TMatrixTSparseDiag<Element>::operator+=(
const TMatrixTSparseDiag_const<Element> &md)
1841 const TMatrixTBase<Element> *mt = md.GetMatrix();
1843 R__ASSERT(this->fMatrix->IsValid());
1844 R__ASSERT(mt->IsValid());
1845 if (this->fNdiag != md.GetNdiags()) {
1846 Error(
"operator+=(const TMatrixTSparseDiag_const &)",
"matrix-diagonal's different length");
1850 for (Int_t i = 0; i < this->fNdiag; i++)
1851 (*
this)(i) += md(i);
1858 template<
class Element>
1859 void TMatrixTSparseDiag<Element>::operator*=(
const TMatrixTSparseDiag_const<Element> &md)
1861 const TMatrixTBase<Element> *mt = md.GetMatrix();
1863 R__ASSERT(this->fMatrix->IsValid());
1864 R__ASSERT(mt->IsValid());
1865 if (this->fNdiag != md.GetNdiags()) {
1866 Error(
"operator*=(const TMatrixTSparseDiag_const &)",
"matrix-diagonal's different length");
1870 for (Int_t i = 0; i < this->fNdiag; i++)
1871 (*
this)(i) *= md(i);
1877 Double_t Drand(Double_t &ix)
1879 const Double_t a = 16807.0;
1880 const Double_t b15 = 32768.0;
1881 const Double_t b16 = 65536.0;
1882 const Double_t p = 2147483647.0;
1883 Double_t xhi = ix/b16;
1884 Int_t xhiint = (Int_t) xhi;
1886 Double_t xalo = (ix-xhi*b16)*a;
1888 Double_t leftlo = xalo/b16;
1889 Int_t leftloint = (int) leftlo;
1891 Double_t fhi = xhi*a+leftlo;
1892 Double_t k = fhi/b15;
1893 Int_t kint = (Int_t) k;
1895 ix = (((xalo-leftlo*b16)-p)+(fhi-k*b15)*b16)+k;
1896 if (ix < 0.0) ix = ix+p;
1898 return (ix*4.656612875e-10);
1901 template class TMatrixTRow_const <Float_t>;
1902 template class TMatrixTColumn_const <Float_t>;
1903 template class TMatrixTDiag_const <Float_t>;
1904 template class TMatrixTFlat_const <Float_t>;
1905 template class TMatrixTSub_const <Float_t>;
1906 template class TMatrixTSparseRow_const <Float_t>;
1907 template class TMatrixTSparseDiag_const<Float_t>;
1908 template class TMatrixTRow <Float_t>;
1909 template class TMatrixTColumn <Float_t>;
1910 template class TMatrixTDiag <Float_t>;
1911 template class TMatrixTFlat <Float_t>;
1912 template class TMatrixTSub <Float_t>;
1913 template class TMatrixTSparseRow <Float_t>;
1914 template class TMatrixTSparseDiag <Float_t>;
1915 template class TElementActionT <Float_t>;
1916 template class TElementPosActionT <Float_t>;
1918 template class TMatrixTRow_const <Double_t>;
1919 template class TMatrixTColumn_const <Double_t>;
1920 template class TMatrixTDiag_const <Double_t>;
1921 template class TMatrixTFlat_const <Double_t>;
1922 template class TMatrixTSub_const <Double_t>;
1923 template class TMatrixTSparseRow_const <Double_t>;
1924 template class TMatrixTSparseDiag_const<Double_t>;
1925 template class TMatrixTRow <Double_t>;
1926 template class TMatrixTColumn <Double_t>;
1927 template class TMatrixTDiag <Double_t>;
1928 template class TMatrixTFlat <Double_t>;
1929 template class TMatrixTSub <Double_t>;
1930 template class TMatrixTSparseRow <Double_t>;
1931 template class TMatrixTSparseDiag <Double_t>;
1932 template class TElementActionT <Double_t>;
1933 template class TElementPosActionT <Double_t>;