ROOT  6.06/09
Reference Guide
TMatrixTUtils.cxx
Go to the documentation of this file.
1 // @(#)root/matrix:$Id$
2 // Authors: Fons Rademakers, Eddy Offermann Nov 2003
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 //////////////////////////////////////////////////////////////////////////
13 // //
14 // Matrix utility classes. //
15 // //
16 // Templates of utility classes in the Linear Algebra Package. //
17 // The following classes are defined here: //
18 // //
19 // Different matrix views without copying data elements : //
20 // TMatrixTRow_const TMatrixTRow //
21 // TMatrixTColumn_const TMatrixTColumn //
22 // TMatrixTDiag_const TMatrixTDiag //
23 // TMatrixTFlat_const TMatrixTFlat //
24 // TMatrixTSub_const TMatrixTSub //
25 // TMatrixTSparseRow_const TMatrixTSparseRow //
26 // TMatrixTSparseDiag_const TMatrixTSparseDiag //
27 // //
28 // TElementActionT //
29 // TElementPosActionT //
30 // //
31 //////////////////////////////////////////////////////////////////////////
32 
33 #include "TMatrixTUtils.h"
34 #include "TMatrixT.h"
35 #include "TMatrixTSym.h"
36 #include "TMatrixTSparse.h"
37 #include "TMath.h"
38 #include "TVectorT.h"
39 
40 ////////////////////////////////////////////////////////////////////////////////
41 /// Constructor with row "row" of matrix
42 
43 template<class Element>
45 {
46  R__ASSERT(matrix.IsValid());
47 
48  fRowInd = row-matrix.GetRowLwb();
49  if (fRowInd >= matrix.GetNrows() || fRowInd < 0) {
50  Error("TMatrixTRow_const(const TMatrixT<Element> &,Int_t)","row index out of bounds");
51  fMatrix = 0;
52  fPtr = 0;
53  fInc = 0;
54  return;
55  }
56 
57  fMatrix = &matrix;
58  fPtr = matrix.GetMatrixArray()+fRowInd*matrix.GetNcols();
59  fInc = 1;
60 }
61 
62 ////////////////////////////////////////////////////////////////////////////////
63 /// Constructor with row "row" of symmetric matrix
64 
65 template<class Element>
67 {
68  R__ASSERT(matrix.IsValid());
69 
70  fRowInd = row-matrix.GetRowLwb();
71  if (fRowInd >= matrix.GetNrows() || fRowInd < 0) {
72  Error("TMatrixTRow_const(const TMatrixTSym &,Int_t)","row index out of bounds");
73  fMatrix = 0;
74  fPtr = 0;
75  fInc = 0;
76  return;
77  }
78 
79  fMatrix = &matrix;
80  fPtr = matrix.GetMatrixArray()+fRowInd*matrix.GetNcols();
81  fInc = 1;
82 }
83 
84 ////////////////////////////////////////////////////////////////////////////////
85 /// Constructor with row "row" of symmetric matrix
86 
87 template<class Element>
89  :TMatrixTRow_const<Element>(matrix,row)
90 {
91 }
92 
93 ////////////////////////////////////////////////////////////////////////////////
94 /// Constructor with row "row" of symmetric matrix
95 
96 template<class Element>
98  :TMatrixTRow_const<Element>(matrix,row)
99 {
100 }
101 
102 ////////////////////////////////////////////////////////////////////////////////
103 /// Copy constructor
104 
105 template<class Element>
107 {
108  *this = mr;
109 }
110 
111 ////////////////////////////////////////////////////////////////////////////////
112 /// Assign val to every element of the matrix row.
113 
114 template<class Element>
116 {
117  R__ASSERT(this->fMatrix->IsValid());
118  Element *rp = const_cast<Element *>(this->fPtr);
119  for ( ; rp < this->fPtr+this->fMatrix->GetNcols(); rp += this->fInc)
120  *rp = val;
121 }
122 
123 ////////////////////////////////////////////////////////////////////////////////
124 /// Add val to every element of the matrix row.
125 
126 template<class Element>
128 {
129  R__ASSERT(this->fMatrix->IsValid());
130  Element *rp = const_cast<Element *>(this->fPtr);
131  for ( ; rp < this->fPtr+this->fMatrix->GetNcols(); rp += this->fInc)
132  *rp += val;
133 }
134 
135 ////////////////////////////////////////////////////////////////////////////////
136 /// Multiply every element of the matrix row with val.
137 
138 template<class Element>
140 {
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)
144  *rp *= val;
145 }
146 
147 ////////////////////////////////////////////////////////////////////////////////
148 /// Assignment operator
149 
150 template<class Element>
152 {
153  const TMatrixTBase<Element> *mt = mr.GetMatrix();
154  if (this->fMatrix->GetMatrixArray() == mt->GetMatrixArray() && this->fRowInd == mr.GetRowIndex()) return;
155 
156  R__ASSERT(this->fMatrix->IsValid());
157  R__ASSERT(mt->IsValid());
158 
159  if (this->fMatrix->GetNcols() != mt->GetNcols() || this->fMatrix->GetColLwb() != mt->GetColLwb()) {
160  Error("operator=(const TMatrixTRow_const &)", "matrix rows not compatible");
161  return;
162  }
163 
164  Element *rp1 = const_cast<Element *>(this->fPtr);
165  const Element *rp2 = mr.GetPtr();
166  for ( ; rp1 < this->fPtr+this->fMatrix->GetNcols(); rp1 += this->fInc,rp2 += mr.GetInc())
167  *rp1 = *rp2;
168 }
169 
170 ////////////////////////////////////////////////////////////////////////////////
171 /// Assign a vector to a matrix row. The vector is considered row-vector
172 /// to allow the assignment in the strict sense.
173 
174 template<class Element>
176 {
177  R__ASSERT(this->fMatrix->IsValid());
178  R__ASSERT(vec.IsValid());
179 
180  if (this->fMatrix->GetColLwb() != vec.GetLwb() || this->fMatrix->GetNcols() != vec.GetNrows()) {
181  Error("operator=(const TVectorT &)","vector length != matrix-row length");
182  return;
183  }
184 
185  Element *rp = const_cast<Element *>(this->fPtr);
186  const Element *vp = vec.GetMatrixArray();
187  for ( ; rp < this->fPtr+this->fMatrix->GetNcols(); rp += this->fInc)
188  *rp = *vp++;
189 }
190 
191 ////////////////////////////////////////////////////////////////////////////////
192 /// Add to every element of the matrix row the corresponding element of row r.
193 
194 template<class Element>
196 {
197  const TMatrixTBase<Element> *mt = r.GetMatrix();
198 
199  R__ASSERT(this->fMatrix->IsValid());
200  R__ASSERT(mt->IsValid());
201 
202  if (this->fMatrix->GetColLwb() != mt->GetColLwb() || this->fMatrix->GetNcols() != mt->GetNcols()) {
203  Error("operator+=(const TMatrixTRow_const &)","different row lengths");
204  return;
205  }
206 
207  Element *rp1 = const_cast<Element *>(this->fPtr);
208  const Element *rp2 = r.GetPtr();
209  for ( ; rp1 < this->fPtr+this->fMatrix->GetNcols(); rp1 += this->fInc,rp2 += r.GetInc())
210  *rp1 += *rp2;
211 }
212 
213 ////////////////////////////////////////////////////////////////////////////////
214 /// Multiply every element of the matrix row with the
215 /// corresponding element of row r.
216 
217 template<class Element>
219 {
220  const TMatrixTBase<Element> *mt = r.GetMatrix();
221 
222  R__ASSERT(this->fMatrix->IsValid());
223  R__ASSERT(mt->IsValid());
224 
225  if (this->fMatrix->GetColLwb() != mt->GetColLwb() || this->fMatrix->GetNcols() != mt->GetNcols()) {
226  Error("operator*=(const TMatrixTRow_const &)","different row lengths");
227  return;
228  }
229 
230  Element *rp1 = const_cast<Element *>(this->fPtr);
231  const Element *rp2 = r.GetPtr();
232  for ( ; rp1 < this->fPtr+this->fMatrix->GetNcols(); rp1 += this->fInc,rp2 += r.GetInc())
233  *rp1 *= *rp2;
234 }
235 
236 ////////////////////////////////////////////////////////////////////////////////
237 /// Constructor with column "col" of matrix
238 
239 template<class Element>
241 {
242  R__ASSERT(matrix.IsValid());
243 
244  this->fColInd = col-matrix.GetColLwb();
245  if (this->fColInd >= matrix.GetNcols() || this->fColInd < 0) {
246  Error("TMatrixTColumn_const(const TMatrixT &,Int_t)","column index out of bounds");
247  fMatrix = 0;
248  fPtr = 0;
249  fInc = 0;
250  return;
251  }
252 
253  fMatrix = &matrix;
254  fPtr = matrix.GetMatrixArray()+fColInd;
255  fInc = matrix.GetNcols();
256 }
257 
258 ////////////////////////////////////////////////////////////////////////////////
259 /// Constructor with column "col" of matrix
260 
261 template<class Element>
263 {
264  R__ASSERT(matrix.IsValid());
265 
266  fColInd = col-matrix.GetColLwb();
267  if (fColInd >= matrix.GetNcols() || fColInd < 0) {
268  Error("TMatrixTColumn_const(const TMatrixTSym &,Int_t)","column index out of bounds");
269  fMatrix = 0;
270  fPtr = 0;
271  fInc = 0;
272  return;
273  }
274 
275  fMatrix = &matrix;
276  fPtr = matrix.GetMatrixArray()+fColInd;
277  fInc = matrix.GetNcols();
278 }
279 
280 ////////////////////////////////////////////////////////////////////////////////
281 /// Constructor with column "col" of matrix
282 
283 template<class Element>
285  :TMatrixTColumn_const<Element>(matrix,col)
286 {
287 }
288 
289 ////////////////////////////////////////////////////////////////////////////////
290 /// Constructor with column "col" of matrix
291 
292 template<class Element>
294  :TMatrixTColumn_const<Element>(matrix,col)
295 {
296 }
297 
298 ////////////////////////////////////////////////////////////////////////////////
299 /// Copy constructor
300 
301 template<class Element>
303 {
304  *this = mc;
305 }
306 
307 ////////////////////////////////////////////////////////////////////////////////
308 /// Assign val to every element of the matrix column.
309 
310 template<class Element>
312 {
313  R__ASSERT(this->fMatrix->IsValid());
314  Element *cp = const_cast<Element *>(this->fPtr);
315  for ( ; cp < this->fPtr+this->fMatrix->GetNoElements(); cp += this->fInc)
316  *cp = val;
317 }
318 
319 ////////////////////////////////////////////////////////////////////////////////
320 /// Add val to every element of the matrix column.
321 
322 template<class Element>
324 {
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)
328  *cp += val;
329 }
330 
331 ////////////////////////////////////////////////////////////////////////////////
332 /// Multiply every element of the matrix column with val.
333 
334 template<class Element>
336 {
337  R__ASSERT(this->fMatrix->IsValid());
338  Element *cp = const_cast<Element *>(this->fPtr);
339  for ( ; cp < this->fPtr+this->fMatrix->GetNoElements(); cp += this->fInc)
340  *cp *= val;
341 }
342 
343 ////////////////////////////////////////////////////////////////////////////////
344 /// Assignment operator
345 
346 template<class Element>
348 {
349  const TMatrixTBase<Element> *mt = mc.GetMatrix();
350  if (this->fMatrix->GetMatrixArray() == mt->GetMatrixArray() && this->fColInd == mc.GetColIndex()) return;
351 
352  R__ASSERT(this->fMatrix->IsValid());
353  R__ASSERT(mt->IsValid());
354 
355  if (this->fMatrix->GetNrows() != mt->GetNrows() || this->fMatrix->GetRowLwb() != mt->GetRowLwb()) {
356  Error("operator=(const TMatrixTColumn_const &)", "matrix columns not compatible");
357  return;
358  }
359 
360  Element *cp1 = const_cast<Element *>(this->fPtr);
361  const Element *cp2 = mc.GetPtr();
362  for ( ; cp1 < this->fPtr+this->fMatrix->GetNoElements(); cp1 += this->fInc,cp2 += mc.GetInc())
363  *cp1 = *cp2;
364 }
365 
366 ////////////////////////////////////////////////////////////////////////////////
367 /// Assign a vector to a matrix column.
368 
369 template<class Element>
371 {
372  R__ASSERT(this->fMatrix->IsValid());
373  R__ASSERT(vec.IsValid());
374 
375  if (this->fMatrix->GetRowLwb() != vec.GetLwb() || this->fMatrix->GetNrows() != vec.GetNrows()) {
376  Error("operator=(const TVectorT &)","vector length != matrix-column length");
377  return;
378  }
379 
380  Element *cp = const_cast<Element *>(this->fPtr);
381  const Element *vp = vec.GetMatrixArray();
382  for ( ; cp < this->fPtr+this->fMatrix->GetNoElements(); cp += this->fInc)
383  *cp = *vp++;
384 
385  R__ASSERT(vp == vec.GetMatrixArray()+vec.GetNrows());
386 }
387 
388 ////////////////////////////////////////////////////////////////////////////////
389 /// Add to every element of the matrix row the corresponding element of row mc.
390 
391 template<class Element>
393 {
394  const TMatrixTBase<Element> *mt = mc.GetMatrix();
395 
396  R__ASSERT(this->fMatrix->IsValid());
397  R__ASSERT(mt->IsValid());
398 
399  if (this->fMatrix->GetRowLwb() != mt->GetRowLwb() || this->fMatrix->GetNrows() != mt->GetNrows()) {
400  Error("operator+=(const TMatrixTColumn_const &)","different row lengths");
401  return;
402  }
403 
404  Element *cp1 = const_cast<Element *>(this->fPtr);
405  const Element *cp2 = mc.GetPtr();
406  for ( ; cp1 < this->fPtr+this->fMatrix->GetNoElements(); cp1 += this->fInc,cp2 += mc.GetInc())
407  *cp1 += *cp2;
408 }
409 
410 ////////////////////////////////////////////////////////////////////////////////
411 /// Multiply every element of the matrix column with the
412 /// corresponding element of column mc.
413 
414 template<class Element>
416 {
417  const TMatrixTBase<Element> *mt = mc.GetMatrix();
418 
419  R__ASSERT(this->fMatrix->IsValid());
420  R__ASSERT(mt->IsValid());
421 
422  if (this->fMatrix->GetRowLwb() != mt->GetRowLwb() || this->fMatrix->GetNrows() != mt->GetNrows()) {
423  Error("operator*=(const TMatrixTColumn_const &)","different row lengths");
424  return;
425  }
426 
427  Element *cp1 = const_cast<Element *>(this->fPtr);
428  const Element *cp2 = mc.GetPtr();
429  for ( ; cp1 < this->fPtr+this->fMatrix->GetNoElements(); cp1 += this->fInc,cp2 += mc.GetInc())
430  *cp1 *= *cp2;
431 }
432 
433 ////////////////////////////////////////////////////////////////////////////////
434 /// Constructor
435 
436 template<class Element>
438 {
439  R__ASSERT(matrix.IsValid());
440 
441  fMatrix = &matrix;
442  fNdiag = TMath::Min(matrix.GetNrows(),matrix.GetNcols());
443  fPtr = matrix.GetMatrixArray();
444  fInc = matrix.GetNcols()+1;
445 }
446 
447 ////////////////////////////////////////////////////////////////////////////////
448 /// Constructor
449 
450 template<class Element>
452 {
453  R__ASSERT(matrix.IsValid());
454 
455  fMatrix = &matrix;
456  fNdiag = TMath::Min(matrix.GetNrows(),matrix.GetNcols());
457  fPtr = matrix.GetMatrixArray();
458  fInc = matrix.GetNcols()+1;
459 }
460 
461 ////////////////////////////////////////////////////////////////////////////////
462 /// Constructor
463 
464 template<class Element>
466  :TMatrixTDiag_const<Element>(matrix)
467 {
468 }
469 
470 ////////////////////////////////////////////////////////////////////////////////
471 /// Constructor
472 
473 template<class Element>
475  :TMatrixTDiag_const<Element>(matrix)
476 {
477 }
478 
479 ////////////////////////////////////////////////////////////////////////////////
480 /// Copy constructor
481 
482 template<class Element>
484 {
485  *this = md;
486 }
487 
488 ////////////////////////////////////////////////////////////////////////////////
489 /// Assign val to every element of the matrix diagonal.
490 
491 template<class Element>
493 {
494  R__ASSERT(this->fMatrix->IsValid());
495  Element *dp = const_cast<Element *>(this->fPtr);
496  for (Int_t i = 0; i < this->fNdiag; i++, dp += this->fInc)
497  *dp = val;
498 }
499 
500 ////////////////////////////////////////////////////////////////////////////////
501 /// Assign val to every element of the matrix diagonal.
502 
503 template<class Element>
505 {
506  R__ASSERT(this->fMatrix->IsValid());
507  Element *dp = const_cast<Element *>(this->fPtr);
508  for (Int_t i = 0; i < this->fNdiag; i++, dp += this->fInc)
509  *dp += val;
510 }
511 
512 ////////////////////////////////////////////////////////////////////////////////
513 /// Assign val to every element of the matrix diagonal.
514 
515 template<class Element>
517 {
518  R__ASSERT(this->fMatrix->IsValid());
519  Element *dp = const_cast<Element *>(this->fPtr);
520  for (Int_t i = 0; i < this->fNdiag; i++, dp += this->fInc)
521  *dp *= val;
522 }
523 
524 ////////////////////////////////////////////////////////////////////////////////
525 /// Assignment operator
526 
527 template<class Element>
529 {
530  const TMatrixTBase<Element> *mt = md.GetMatrix();
531  if (this->fMatrix == mt) return;
532 
533  R__ASSERT(this->fMatrix->IsValid());
534  R__ASSERT(mt->IsValid());
535 
536  if (this->GetNdiags() != md.GetNdiags()) {
537  Error("operator=(const TMatrixTDiag_const &)","diagonals not compatible");
538  return;
539  }
540 
541  Element *dp1 = const_cast<Element *>(this->fPtr);
542  const Element *dp2 = md.GetPtr();
543  for (Int_t i = 0; i < this->fNdiag; i++, dp1 += this->fInc, dp2 += md.GetInc())
544  *dp1 = *dp2;
545 }
546 
547 ////////////////////////////////////////////////////////////////////////////////
548 /// Assign a vector to the matrix diagonal.
549 
550 template<class Element>
552 {
553  R__ASSERT(this->fMatrix->IsValid());
554  R__ASSERT(vec.IsValid());
555 
556  if (this->fNdiag != vec.GetNrows()) {
557  Error("operator=(const TVectorT &)","vector length != matrix-diagonal length");
558  return;
559  }
560 
561  Element *dp = const_cast<Element *>(this->fPtr);
562  const Element *vp = vec.GetMatrixArray();
563  for ( ; vp < vec.GetMatrixArray()+vec.GetNrows(); dp += this->fInc)
564  *dp = *vp++;
565 }
566 
567 ////////////////////////////////////////////////////////////////////////////////
568 /// Add to every element of the matrix diagonal the
569 /// corresponding element of diagonal md.
570 
571 template<class Element>
573 {
574  const TMatrixTBase<Element> *mt = md.GetMatrix();
575 
576  R__ASSERT(this->fMatrix->IsValid());
577  R__ASSERT(mt->IsValid());
578  if (this->fNdiag != md.GetNdiags()) {
579  Error("operator=(const TMatrixTDiag_const &)","matrix-diagonal's different length");
580  return;
581  }
582 
583  Element *dp1 = const_cast<Element *>(this->fPtr);
584  const Element *dp2 = md.GetPtr();
585  for (Int_t i = 0; i < this->fNdiag; i++, dp1 += this->fInc, dp2 += md.GetInc())
586  *dp1 += *dp2;
587 }
588 
589 ////////////////////////////////////////////////////////////////////////////////
590 /// Multiply every element of the matrix diagonal with the
591 /// corresponding element of diagonal md.
592 
593 template<class Element>
595 {
596  const TMatrixTBase<Element> *mt = md.GetMatrix();
597 
598  R__ASSERT(this->fMatrix->IsValid());
599  R__ASSERT(mt->IsValid());
600  if (this->fNdiag != md.GetNdiags()) {
601  Error("operator*=(const TMatrixTDiag_const &)","matrix-diagonal's different length");
602  return;
603  }
604 
605  Element *dp1 = const_cast<Element *>(this->fPtr);
606  const Element *dp2 = md.GetPtr();
607  for (Int_t i = 0; i < this->fNdiag; i++, dp1 += this->fInc, dp2 += md.GetInc())
608  *dp1 *= *dp2;
609 }
610 
611 ////////////////////////////////////////////////////////////////////////////////
612 /// Constructor
613 
614 template<class Element>
616 {
617  R__ASSERT(matrix.IsValid());
618 
619  fMatrix = &matrix;
620  fPtr = matrix.GetMatrixArray();
621  fNelems = matrix.GetNoElements();
622 }
623 
624 ////////////////////////////////////////////////////////////////////////////////
625 /// Constructor
626 
627 template<class Element>
629 {
630  R__ASSERT(matrix.IsValid());
631 
632  fMatrix = &matrix;
633  fPtr = matrix.GetMatrixArray();
634  fNelems = matrix.GetNoElements();
635 }
636 
637 ////////////////////////////////////////////////////////////////////////////////
638 /// Constructor
639 
640 template<class Element>
642  :TMatrixTFlat_const<Element>(matrix)
643 {
644 }
645 
646 ////////////////////////////////////////////////////////////////////////////////
647 /// Constructor
648 
649 template<class Element>
651  :TMatrixTFlat_const<Element>(matrix)
652 {
653 }
654 
655 ////////////////////////////////////////////////////////////////////////////////
656 /// Copy constructor
657 
658 template<class Element>
660 {
661  *this = mf;
662 }
663 
664 ////////////////////////////////////////////////////////////////////////////////
665 /// Assign val to every element of the matrix.
666 
667 template<class Element>
669 {
670  R__ASSERT(this->fMatrix->IsValid());
671  Element *fp = const_cast<Element *>(this->fPtr);
672  while (fp < this->fPtr+this->fMatrix->GetNoElements())
673  *fp++ = val;
674 }
675 
676 ////////////////////////////////////////////////////////////////////////////////
677 /// Add val to every element of the matrix.
678 
679 template<class Element>
681 {
682  R__ASSERT(this->fMatrix->IsValid());
683  Element *fp = const_cast<Element *>(this->fPtr);
684  while (fp < this->fPtr+this->fMatrix->GetNoElements())
685  *fp++ += val;
686 }
687 
688 ////////////////////////////////////////////////////////////////////////////////
689 /// Multiply every element of the matrix with val.
690 
691 template<class Element>
693 {
694  R__ASSERT(this->fMatrix->IsValid());
695  Element *fp = const_cast<Element *>(this->fPtr);
696  while (fp < this->fPtr+this->fMatrix->GetNoElements())
697  *fp++ *= val;
698 }
699 
700 ////////////////////////////////////////////////////////////////////////////////
701 /// Assignment operator
702 
703 template<class Element>
705 {
706  const TMatrixTBase<Element> *mt = mf.GetMatrix();
707  if (this->fMatrix->GetMatrixArray() == mt->GetMatrixArray()) return;
708 
709  R__ASSERT(this->fMatrix->IsValid());
710  R__ASSERT(mt->IsValid());
711  if (this->fMatrix->GetNoElements() != mt->GetNoElements()) {
712  Error("operator=(const TMatrixTFlat_const &)","matrix lengths different");
713  return;
714  }
715 
716  Element *fp1 = const_cast<Element *>(this->fPtr);
717  const Element *fp2 = mf.GetPtr();
718  while (fp1 < this->fPtr+this->fMatrix->GetNoElements())
719  *fp1++ = *fp2++;
720 }
721 
722 ////////////////////////////////////////////////////////////////////////////////
723 /// Assign a vector to the matrix. The matrix is traversed row-wise
724 
725 template<class Element>
727 {
728  R__ASSERT(vec.IsValid());
729 
730  if (this->fMatrix->GetNoElements() != vec.GetNrows()) {
731  Error("operator=(const TVectorT &)","vector length != # matrix-elements");
732  return;
733  }
734 
735  Element *fp = const_cast<Element *>(this->fPtr);
736  const Element *vp = vec.GetMatrixArray();
737  while (fp < this->fPtr+this->fMatrix->GetNoElements())
738  *fp++ = *vp++;
739 }
740 
741 ////////////////////////////////////////////////////////////////////////////////
742 /// Add to every element of the matrix the corresponding element of matrix mf.
743 
744 template<class Element>
746 {
747  const TMatrixTBase<Element> *mt = mf.GetMatrix();
748 
749  R__ASSERT(this->fMatrix->IsValid());
750  R__ASSERT(mt->IsValid());
751  if (this->fMatrix->GetNoElements() != mt->GetNoElements()) {
752  Error("operator+=(const TMatrixTFlat_const &)","matrices lengths different");
753  return;
754  }
755 
756  Element *fp1 = const_cast<Element *>(this->fPtr);
757  const Element *fp2 = mf.GetPtr();
758  while (fp1 < this->fPtr + this->fMatrix->GetNoElements())
759  *fp1++ += *fp2++;
760 }
761 
762 ////////////////////////////////////////////////////////////////////////////////
763 /// Multiply every element of the matrix with the corresponding element of diagonal mf.
764 
765 template<class Element>
767 {
768  const TMatrixTBase<Element> *mt = mf.GetMatrix();
769 
770  R__ASSERT(this->fMatrix->IsValid());
771  R__ASSERT(mt->IsValid());
772  if (this->fMatrix->GetNoElements() != mt->GetNoElements()) {
773  Error("operator*=(const TMatrixTFlat_const &)","matrices lengths different");
774  return;
775  }
776 
777  Element *fp1 = const_cast<Element *>(this->fPtr);
778  const Element *fp2 = mf.GetPtr();
779  while (fp1 < this->fPtr + this->fMatrix->GetNoElements())
780  *fp1++ *= *fp2++;
781 }
782 
783 ////////////////////////////////////////////////////////////////////////////////
784 /// make a reference to submatrix [row_lwbs..row_upbs][col_lwbs..col_upbs];
785 /// The indexing range of the reference is
786 /// [0..row_upbs-row_lwbs+1][0..col_upb-col_lwbs+1] (default)
787 
788 template<class Element>
790  Int_t col_lwbs,Int_t col_upbs)
791 {
792  R__ASSERT(matrix.IsValid());
793 
794  fRowOff = 0;
795  fColOff = 0;
796  fNrowsSub = 0;
797  fNcolsSub = 0;
798  fMatrix = &matrix;
799 
800  if (row_upbs < row_lwbs) {
801  Error("TMatrixTSub_const","Request sub-matrix with row_upbs(%d) < row_lwbs(%d)",row_upbs,row_lwbs);
802  return;
803  }
804  if (col_upbs < col_lwbs) {
805  Error("TMatrixTSub_const","Request sub-matrix with col_upbs(%d) < col_lwbs(%d)",col_upbs,col_lwbs);
806  return;
807  }
808 
809  const Int_t rowLwb = matrix.GetRowLwb();
810  const Int_t rowUpb = matrix.GetRowUpb();
811  const Int_t colLwb = matrix.GetColLwb();
812  const Int_t colUpb = matrix.GetColUpb();
813 
814  if (row_lwbs < rowLwb || row_lwbs > rowUpb) {
815  Error("TMatrixTSub_const","Request row_lwbs sub-matrix(%d) outside matrix range of %d - %d",row_lwbs,rowLwb,rowUpb);
816  return;
817  }
818  if (col_lwbs < colLwb || col_lwbs > colUpb) {
819  Error("TMatrixTSub_const","Request col_lwbs sub-matrix(%d) outside matrix range of %d - %d",col_lwbs,colLwb,colUpb);
820  return;
821  }
822  if (row_upbs < rowLwb || row_upbs > rowUpb) {
823  Error("TMatrixTSub_const","Request row_upbs sub-matrix(%d) outside matrix range of %d - %d",row_upbs,rowLwb,rowUpb);
824  return;
825  }
826  if (col_upbs < colLwb || col_upbs > colUpb) {
827  Error("TMatrixTSub_const","Request col_upbs sub-matrix(%d) outside matrix range of %d - %d",col_upbs,colLwb,colUpb);
828  return;
829  }
830 
831  fRowOff = row_lwbs-rowLwb;
832  fColOff = col_lwbs-colLwb;
833  fNrowsSub = row_upbs-row_lwbs+1;
834  fNcolsSub = col_upbs-col_lwbs+1;
835 }
836 
837 ////////////////////////////////////////////////////////////////////////////////
838 /// make a reference to submatrix [row_lwbs..row_upbs][col_lwbs..col_upbs];
839 /// The indexing range of the reference is
840 /// [0..row_upbs-row_lwbs+1][0..col_upb-col_lwbs+1] (default)
841 
842 template<class Element>
844  Int_t col_lwbs,Int_t col_upbs)
845 {
846  R__ASSERT(matrix.IsValid());
847 
848  fRowOff = 0;
849  fColOff = 0;
850  fNrowsSub = 0;
851  fNcolsSub = 0;
852  fMatrix = &matrix;
853 
854  if (row_upbs < row_lwbs) {
855  Error("TMatrixTSub_const","Request sub-matrix with row_upbs(%d) < row_lwbs(%d)",row_upbs,row_lwbs);
856  return;
857  }
858  if (col_upbs < col_lwbs) {
859  Error("TMatrixTSub_const","Request sub-matrix with col_upbs(%d) < col_lwbs(%d)",col_upbs,col_lwbs);
860  return;
861  }
862 
863  const Int_t rowLwb = matrix.GetRowLwb();
864  const Int_t rowUpb = matrix.GetRowUpb();
865  const Int_t colLwb = matrix.GetColLwb();
866  const Int_t colUpb = matrix.GetColUpb();
867 
868  if (row_lwbs < rowLwb || row_lwbs > rowUpb) {
869  Error("TMatrixTSub_const","Request row_lwbs sub-matrix(%d) outside matrix range of %d - %d",row_lwbs,rowLwb,rowUpb);
870  return;
871  }
872  if (col_lwbs < colLwb || col_lwbs > colUpb) {
873  Error("TMatrixTSub_const","Request col_lwbs sub-matrix(%d) outside matrix range of %d - %d",col_lwbs,colLwb,colUpb);
874  return;
875  }
876  if (row_upbs < rowLwb || row_upbs > rowUpb) {
877  Error("TMatrixTSub_const","Request row_upbs sub-matrix(%d) outside matrix range of %d - %d",row_upbs,rowLwb,rowUpb);
878  return;
879  }
880  if (col_upbs < colLwb || col_upbs > colUpb) {
881  Error("TMatrixTSub_const","Request col_upbs sub-matrix(%d) outside matrix range of %d - %d",col_upbs,colLwb,colUpb);
882  return;
883  }
884 
885  fRowOff = row_lwbs-rowLwb;
886  fColOff = col_lwbs-colLwb;
887  fNrowsSub = row_upbs-row_lwbs+1;
888  fNcolsSub = col_upbs-col_lwbs+1;
889 }
890 
891 ////////////////////////////////////////////////////////////////////////////////
892 /// Constructor
893 
894 template<class Element>
896  Int_t col_lwbs,Int_t col_upbs)
897  :TMatrixTSub_const<Element>(matrix,row_lwbs,row_upbs,col_lwbs,col_upbs)
898 {
899 }
900 
901 ////////////////////////////////////////////////////////////////////////////////
902 /// Constructor
903 
904 template<class Element>
906  Int_t col_lwbs,Int_t col_upbs)
907  :TMatrixTSub_const<Element>(matrix,row_lwbs,row_upbs,col_lwbs,col_upbs)
908 {
909 }
910 
911 ////////////////////////////////////////////////////////////////////////////////
912 /// Copy constructor
913 
914 template<class Element>
916 {
917  *this = ms;
918 }
919 
920 ////////////////////////////////////////////////////////////////////////////////
921 /// Perform a rank 1 operation on the matrix:
922 /// A += alpha * v * v^T
923 
924 template<class Element>
926 {
927  R__ASSERT(this->fMatrix->IsValid());
928  R__ASSERT(v.IsValid());
929 
930  if (v.GetNoElements() < TMath::Max(this->fNrowsSub,this->fNcolsSub)) {
931  Error("Rank1Update","vector too short");
932  return;
933  }
934 
935  const Element * const pv = v.GetMatrixArray();
936  Element *mp = (const_cast<TMatrixTBase<Element> *>(this->fMatrix))->GetMatrixArray();
937 
938  const Int_t ncols = this->fMatrix->GetNcols();
939  for (Int_t irow = 0; irow < this->fNrowsSub; irow++) {
940  const Int_t off = (irow+this->fRowOff)*ncols+this->fColOff;
941  const Element tmp = alpha*pv[irow];
942  for (Int_t icol = 0; icol < this->fNcolsSub; icol++)
943  mp[off+icol] += tmp*pv[icol];
944  }
945 }
946 
947 ////////////////////////////////////////////////////////////////////////////////
948 /// Assign val to every element of the sub matrix.
949 
950 template<class Element>
952 {
953  R__ASSERT(this->fMatrix->IsValid());
954 
955  Element *p = (const_cast<TMatrixTBase<Element> *>(this->fMatrix))->GetMatrixArray();
956  const Int_t ncols = this->fMatrix->GetNcols();
957  for (Int_t irow = 0; irow < this->fNrowsSub; irow++) {
958  const Int_t off = (irow+this->fRowOff)*ncols+this->fColOff;
959  for (Int_t icol = 0; icol < this->fNcolsSub; icol++)
960  p[off+icol] = val;
961  }
962 }
963 
964 ////////////////////////////////////////////////////////////////////////////////
965 /// Add val to every element of the sub matrix.
966 
967 template<class Element>
969 {
970  R__ASSERT(this->fMatrix->IsValid());
971 
972  Element *p = (const_cast<TMatrixTBase<Element> *>(this->fMatrix))->GetMatrixArray();
973  const Int_t ncols = this->fMatrix->GetNcols();
974  for (Int_t irow = 0; irow < this->fNrowsSub; irow++) {
975  const Int_t off = (irow+this->fRowOff)*ncols+this->fColOff;
976  for (Int_t icol = 0; icol < this->fNcolsSub; icol++)
977  p[off+icol] += val;
978  }
979 }
980 
981 ////////////////////////////////////////////////////////////////////////////////
982 /// Multiply every element of the sub matrix by val .
983 
984 template<class Element>
986 {
987  R__ASSERT(this->fMatrix->IsValid());
988 
989  Element *p = (const_cast<TMatrixTBase<Element> *>(this->fMatrix))->GetMatrixArray();
990  const Int_t ncols = this->fMatrix->GetNcols();
991  for (Int_t irow = 0; irow < this->fNrowsSub; irow++) {
992  const Int_t off = (irow+this->fRowOff)*ncols+this->fColOff;
993  for (Int_t icol = 0; icol < this->fNcolsSub; icol++)
994  p[off+icol] *= val;
995  }
996 }
997 
998 ////////////////////////////////////////////////////////////////////////////////
999 /// Assignment operator
1000 
1001 template<class Element>
1003 {
1004  const TMatrixTBase<Element> *mt = ms.GetMatrix();
1005 
1006  R__ASSERT(this->fMatrix->IsValid());
1007  R__ASSERT(mt->IsValid());
1008 
1009  if (this->fMatrix == mt &&
1010  (this->GetNrows() == ms.GetNrows () && this->GetNcols() == ms.GetNcols () &&
1011  this->GetRowOff() == ms.GetRowOff() && this->GetColOff() == ms.GetColOff()) )
1012  return;
1013 
1014  if (this->GetNrows() != ms.GetNrows() || this->GetNcols() != ms.GetNcols()) {
1015  Error("operator=(const TMatrixTSub_const &)","sub matrices have different size");
1016  return;
1017  }
1018 
1019  const Int_t rowOff2 = ms.GetRowOff();
1020  const Int_t colOff2 = ms.GetColOff();
1021 
1022  Bool_t overlap = (this->fMatrix == mt) &&
1023  ( (rowOff2 >= this->fRowOff && rowOff2 < this->fRowOff+this->fNrowsSub) ||
1024  (colOff2 >= this->fColOff && colOff2 < this->fColOff+this->fNcolsSub) );
1025 
1026  Element *p1 = const_cast<Element *>(this->fMatrix->GetMatrixArray());
1027  if (!overlap) {
1028  const Element *p2 = mt->GetMatrixArray();
1029 
1030  const Int_t ncols1 = this->fMatrix->GetNcols();
1031  const Int_t ncols2 = mt->GetNcols();
1032  for (Int_t irow = 0; irow < this->fNrowsSub; irow++) {
1033  const Int_t off1 = (irow+this->fRowOff)*ncols1+this->fColOff;
1034  const Int_t off2 = (irow+rowOff2)*ncols2+colOff2;
1035  for (Int_t icol = 0; icol < this->fNcolsSub; icol++)
1036  p1[off1+icol] = p2[off2+icol];
1037  }
1038  } else {
1039  const Int_t row_lwbs = rowOff2+mt->GetRowLwb();
1040  const Int_t row_upbs = row_lwbs+this->fNrowsSub-1;
1041  const Int_t col_lwbs = colOff2+mt->GetColLwb();
1042  const Int_t col_upbs = col_lwbs+this->fNcolsSub-1;
1043  TMatrixT<Element> tmp; mt->GetSub(row_lwbs,row_upbs,col_lwbs,col_upbs,tmp);
1044  const Element *p2 = tmp.GetMatrixArray();
1045 
1046  const Int_t ncols1 = this->fMatrix->GetNcols();
1047  const Int_t ncols2 = tmp.GetNcols();
1048  for (Int_t irow = 0; irow < this->fNrowsSub; irow++) {
1049  const Int_t off1 = (irow+this->fRowOff)*ncols1+this->fColOff;
1050  const Int_t off2 = irow*ncols2;
1051  for (Int_t icol = 0; icol < this->fNcolsSub; icol++)
1052  p1[off1+icol] = p2[off2+icol];
1053  }
1054  }
1055 }
1056 
1057 ////////////////////////////////////////////////////////////////////////////////
1058 /// Assignment operator
1059 
1060 template<class Element>
1062 {
1063  R__ASSERT(this->fMatrix->IsValid());
1064  R__ASSERT(m.IsValid());
1065 
1066  if (this->fMatrix->GetMatrixArray() == m.GetMatrixArray()) return;
1067 
1068  if (this->fNrowsSub != m.GetNrows() || this->fNcolsSub != m.GetNcols()) {
1069  Error("operator=(const TMatrixTBase<Element> &)","sub matrices and matrix have different size");
1070  return;
1071  }
1072  const Int_t row_lwbs = this->fRowOff+this->fMatrix->GetRowLwb();
1073  const Int_t col_lwbs = this->fColOff+this->fMatrix->GetColLwb();
1074  (const_cast<TMatrixTBase<Element> *>(this->fMatrix))->SetSub(row_lwbs,col_lwbs,m);
1075 }
1076 
1077 ////////////////////////////////////////////////////////////////////////////////
1078 /// Add to every element of the submatrix the corresponding element of submatrix ms.
1079 
1080 template<class Element>
1082 {
1083  const TMatrixTBase<Element> *mt = ms.GetMatrix();
1084 
1085  R__ASSERT(this->fMatrix->IsValid());
1086  R__ASSERT(mt->IsValid());
1087 
1088  if (this->GetNrows() != ms.GetNrows() || this->GetNcols() != ms.GetNcols()) {
1089  Error("operator+=(const TMatrixTSub_const &)","sub matrices have different size");
1090  return;
1091  }
1092 
1093  const Int_t rowOff2 = ms.GetRowOff();
1094  const Int_t colOff2 = ms.GetColOff();
1095 
1096  Bool_t overlap = (this->fMatrix == mt) &&
1097  ( (rowOff2 >= this->fRowOff && rowOff2 < this->fRowOff+this->fNrowsSub) ||
1098  (colOff2 >= this->fColOff && colOff2 < this->fColOff+this->fNcolsSub) );
1099 
1100  Element *p1 = const_cast<Element *>(this->fMatrix->GetMatrixArray());
1101  if (!overlap) {
1102  const Element *p2 = mt->GetMatrixArray();
1103 
1104  const Int_t ncols1 = this->fMatrix->GetNcols();
1105  const Int_t ncols2 = mt->GetNcols();
1106  for (Int_t irow = 0; irow < this->fNrowsSub; irow++) {
1107  const Int_t off1 = (irow+this->fRowOff)*ncols1+this->fColOff;
1108  const Int_t off2 = (irow+rowOff2)*ncols2+colOff2;
1109  for (Int_t icol = 0; icol < this->fNcolsSub; icol++)
1110  p1[off1+icol] += p2[off2+icol];
1111  }
1112  } else {
1113  const Int_t row_lwbs = rowOff2+mt->GetRowLwb();
1114  const Int_t row_upbs = row_lwbs+this->fNrowsSub-1;
1115  const Int_t col_lwbs = colOff2+mt->GetColLwb();
1116  const Int_t col_upbs = col_lwbs+this->fNcolsSub-1;
1117  TMatrixT<Element> tmp; mt->GetSub(row_lwbs,row_upbs,col_lwbs,col_upbs,tmp);
1118  const Element *p2 = tmp.GetMatrixArray();
1119 
1120  const Int_t ncols1 = this->fMatrix->GetNcols();
1121  const Int_t ncols2 = tmp.GetNcols();
1122  for (Int_t irow = 0; irow < this->fNrowsSub; irow++) {
1123  const Int_t off1 = (irow+this->fRowOff)*ncols1+this->fColOff;
1124  const Int_t off2 = irow*ncols2;
1125  for (Int_t icol = 0; icol < this->fNcolsSub; icol++)
1126  p1[off1+icol] += p2[off2+icol];
1127  }
1128  }
1129 }
1130 
1131 ////////////////////////////////////////////////////////////////////////////////
1132 /// Multiply submatrix with submatrix ms.
1133 
1134 template<class Element>
1136 {
1137  if (this->fNcolsSub != ms.GetNrows() || this->fNcolsSub != ms.GetNcols()) {
1138  Error("operator*=(const TMatrixTSub_const &)","source sub matrix has wrong shape");
1139  return;
1140  }
1141 
1142  const TMatrixTBase<Element> *source = ms.GetMatrix();
1143 
1144  TMatrixT<Element> source_sub;
1145  {
1146  const Int_t row_lwbs = ms.GetRowOff()+source->GetRowLwb();
1147  const Int_t row_upbs = row_lwbs+this->fNrowsSub-1;
1148  const Int_t col_lwbs = ms.GetColOff()+source->GetColLwb();
1149  const Int_t col_upbs = col_lwbs+this->fNcolsSub-1;
1150  source->GetSub(row_lwbs,row_upbs,col_lwbs,col_upbs,source_sub);
1151  }
1152 
1153  const Element *sp = source_sub.GetMatrixArray();
1154  const Int_t ncols = this->fMatrix->GetNcols();
1155 
1156  // One row of the old_target matrix
1157  Element work[kWorkMax];
1158  Bool_t isAllocated = kFALSE;
1159  Element *trp = work;
1160  if (this->fNcolsSub > kWorkMax) {
1161  isAllocated = kTRUE;
1162  trp = new Element[this->fNcolsSub];
1163  }
1164 
1165  Element *cp = const_cast<Element *>(this->fMatrix->GetMatrixArray())+this->fRowOff*ncols+this->fColOff;
1166  const Element *trp0 = cp; // Pointer to target[i,0];
1167  const Element * const trp0_last = trp0+this->fNrowsSub*ncols;
1168  while (trp0 < trp0_last) {
1169  memcpy(trp,trp0,this->fNcolsSub*sizeof(Element)); // copy the i-th row of target, Start at target[i,0]
1170  for (const Element *scp = sp; scp < sp+this->fNcolsSub; ) { // Pointer to the j-th column of source,
1171  // Start scp = source[0,0]
1172  Element cij = 0;
1173  for (Int_t j = 0; j < this->fNcolsSub; j++) {
1174  cij += trp[j] * *scp; // the j-th col of source
1175  scp += this->fNcolsSub;
1176  }
1177  *cp++ = cij;
1178  scp -= source_sub.GetNoElements()-1; // Set bcp to the (j+1)-th col
1179  }
1180  cp += ncols-this->fNcolsSub;
1181  trp0 += ncols; // Set trp0 to the (i+1)-th row
1182  R__ASSERT(trp0 == cp);
1183  }
1184 
1185  R__ASSERT(cp == trp0_last && trp0 == trp0_last);
1186  if (isAllocated)
1187  delete [] trp;
1188 }
1189 
1190 ////////////////////////////////////////////////////////////////////////////////
1191 /// Add to every element of the submatrix the corresponding element of matrix mt.
1192 
1193 template<class Element>
1195 {
1196  R__ASSERT(this->fMatrix->IsValid());
1197  R__ASSERT(mt.IsValid());
1198 
1199  if (this->GetNrows() != mt.GetNrows() || this->GetNcols() != mt.GetNcols()) {
1200  Error("operator+=(const TMatrixTBase<Element> &)","sub matrix and matrix have different size");
1201  return;
1202  }
1203 
1204  Element *p1 = const_cast<Element *>(this->fMatrix->GetMatrixArray());
1205  const Element *p2 = mt.GetMatrixArray();
1206 
1207  const Int_t ncols1 = this->fMatrix->GetNcols();
1208  const Int_t ncols2 = mt.GetNcols();
1209  for (Int_t irow = 0; irow < this->fNrowsSub; irow++) {
1210  const Int_t off1 = (irow+this->fRowOff)*ncols1+this->fColOff;
1211  const Int_t off2 = irow*ncols2;
1212  for (Int_t icol = 0; icol < this->fNcolsSub; icol++)
1213  p1[off1+icol] += p2[off2+icol];
1214  }
1215 }
1216 
1217 ////////////////////////////////////////////////////////////////////////////////
1218 /// Multiply submatrix with matrix source.
1219 
1220 template<class Element>
1222 {
1223  if (this->fNcolsSub != source.GetNrows() || this->fNcolsSub != source.GetNcols()) {
1224  Error("operator*=(const TMatrixT<Element> &)","source matrix has wrong shape");
1225  return;
1226  }
1227 
1228  // Check for A *= A;
1229  const Element *sp;
1230  TMatrixT<Element> tmp;
1231  if (this->fMatrix->GetMatrixArray() == source.GetMatrixArray()) {
1232  tmp.ResizeTo(source);
1233  tmp = source;
1234  sp = tmp.GetMatrixArray();
1235  }
1236  else
1237  sp = source.GetMatrixArray();
1238 
1239  const Int_t ncols = this->fMatrix->GetNcols();
1240 
1241  // One row of the old_target matrix
1242  Element work[kWorkMax];
1243  Bool_t isAllocated = kFALSE;
1244  Element *trp = work;
1245  if (this->fNcolsSub > kWorkMax) {
1246  isAllocated = kTRUE;
1247  trp = new Element[this->fNcolsSub];
1248  }
1249 
1250  Element *cp = const_cast<Element *>(this->fMatrix->GetMatrixArray())+this->fRowOff*ncols+this->fColOff;
1251  const Element *trp0 = cp; // Pointer to target[i,0];
1252  const Element * const trp0_last = trp0+this->fNrowsSub*ncols;
1253  while (trp0 < trp0_last) {
1254  memcpy(trp,trp0,this->fNcolsSub*sizeof(Element)); // copy the i-th row of target, Start at target[i,0]
1255  for (const Element *scp = sp; scp < sp+this->fNcolsSub; ) { // Pointer to the j-th column of source,
1256  // Start scp = source[0,0]
1257  Element cij = 0;
1258  for (Int_t j = 0; j < this->fNcolsSub; j++) {
1259  cij += trp[j] * *scp; // the j-th col of source
1260  scp += this->fNcolsSub;
1261  }
1262  *cp++ = cij;
1263  scp -= source.GetNoElements()-1; // Set bcp to the (j+1)-th col
1264  }
1265  cp += ncols-this->fNcolsSub;
1266  trp0 += ncols; // Set trp0 to the (i+1)-th row
1267  R__ASSERT(trp0 == cp);
1268  }
1269 
1270  R__ASSERT(cp == trp0_last && trp0 == trp0_last);
1271  if (isAllocated)
1272  delete [] trp;
1273 }
1274 
1275 ////////////////////////////////////////////////////////////////////////////////
1276 /// Multiply submatrix with matrix source.
1277 
1278 template<class Element>
1280 {
1281  if (this->fNcolsSub != source.GetNrows() || this->fNcolsSub != source.GetNcols()) {
1282  Error("operator*=(const TMatrixTSym<Element> &)","source matrix has wrong shape");
1283  return;
1284  }
1285 
1286  // Check for A *= A;
1287  const Element *sp;
1289  if (this->fMatrix->GetMatrixArray() == source.GetMatrixArray()) {
1290  tmp.ResizeTo(source);
1291  tmp = source;
1292  sp = tmp.GetMatrixArray();
1293  }
1294  else
1295  sp = source.GetMatrixArray();
1296 
1297  const Int_t ncols = this->fMatrix->GetNcols();
1298 
1299  // One row of the old_target matrix
1300  Element work[kWorkMax];
1301  Bool_t isAllocated = kFALSE;
1302  Element *trp = work;
1303  if (this->fNcolsSub > kWorkMax) {
1304  isAllocated = kTRUE;
1305  trp = new Element[this->fNcolsSub];
1306  }
1307 
1308  Element *cp = const_cast<Element *>(this->fMatrix->GetMatrixArray())+this->fRowOff*ncols+this->fColOff;
1309  const Element *trp0 = cp; // Pointer to target[i,0];
1310  const Element * const trp0_last = trp0+this->fNrowsSub*ncols;
1311  while (trp0 < trp0_last) {
1312  memcpy(trp,trp0,this->fNcolsSub*sizeof(Element)); // copy the i-th row of target, Start at target[i,0]
1313  for (const Element *scp = sp; scp < sp+this->fNcolsSub; ) { // Pointer to the j-th column of source,
1314  // Start scp = source[0,0]
1315  Element cij = 0;
1316  for (Int_t j = 0; j < this->fNcolsSub; j++) {
1317  cij += trp[j] * *scp; // the j-th col of source
1318  scp += this->fNcolsSub;
1319  }
1320  *cp++ = cij;
1321  scp -= source.GetNoElements()-1; // Set bcp to the (j+1)-th col
1322  }
1323  cp += ncols-this->fNcolsSub;
1324  trp0 += ncols; // Set trp0 to the (i+1)-th row
1325  R__ASSERT(trp0 == cp);
1326  }
1327 
1328  R__ASSERT(cp == trp0_last && trp0 == trp0_last);
1329  if (isAllocated)
1330  delete [] trp;
1331 }
1332 
1333 ////////////////////////////////////////////////////////////////////////////////
1334 /// Constructor with row "row" of matrix
1335 
1336 template<class Element>
1338 {
1339  R__ASSERT(matrix.IsValid());
1340 
1341  fRowInd = row-matrix.GetRowLwb();
1342  if (fRowInd >= matrix.GetNrows() || fRowInd < 0) {
1343  Error("TMatrixTSparseRow_const(const TMatrixTSparse &,Int_t)","row index out of bounds");
1344  fMatrix = 0;
1345  fNindex = 0;
1346  fColPtr = 0;
1347  fDataPtr = 0;
1348  return;
1349  }
1350 
1351  const Int_t sIndex = matrix.GetRowIndexArray()[fRowInd];
1352  const Int_t eIndex = matrix.GetRowIndexArray()[fRowInd+1];
1353  fMatrix = &matrix;
1354  fNindex = eIndex-sIndex;
1355  fColPtr = matrix.GetColIndexArray()+sIndex;
1356  fDataPtr = matrix.GetMatrixArray()+sIndex;
1357 }
1358 
1359 ////////////////////////////////////////////////////////////////////////////////
1360 
1361 template<class Element>
1363 {
1364  if (!fMatrix) return TMatrixTBase<Element>::NaNValue();
1365  R__ASSERT(fMatrix->IsValid());
1366  const Int_t acoln = i-fMatrix->GetColLwb();
1367  if (acoln < fMatrix->GetNcols() && acoln >= 0) {
1368  const Int_t index = TMath::BinarySearch(fNindex,fColPtr,acoln);
1369  if (index >= 0 && fColPtr[index] == acoln) return fDataPtr[index];
1370  else return 0.0;
1371  } else {
1372  Error("operator()","Request col(%d) outside matrix range of %d - %d",
1373  i,fMatrix->GetColLwb(),fMatrix->GetColLwb()+fMatrix->GetNcols());
1375  }
1376  }
1377 
1378 ////////////////////////////////////////////////////////////////////////////////
1379 /// Constructor with row "row" of matrix
1380 
1381 template<class Element>
1383  : TMatrixTSparseRow_const<Element>(matrix,row)
1384 {
1385 }
1386 
1387 ////////////////////////////////////////////////////////////////////////////////
1388 /// Copy constructor
1389 
1390 template<class Element>
1392  : TMatrixTSparseRow_const<Element>(mr)
1393 {
1394  *this = mr;
1395 }
1396 
1397 ////////////////////////////////////////////////////////////////////////////////
1398 
1399 template<class Element>
1401 {
1402  if (!this->fMatrix) return TMatrixTBase<Element>::NaNValue();
1403  R__ASSERT(this->fMatrix->IsValid());
1404  const Int_t acoln = i-this->fMatrix->GetColLwb();
1405  if (acoln < this->fMatrix->GetNcols() && acoln >= 0) {
1406  const Int_t index = TMath::BinarySearch(this->fNindex,this->fColPtr,acoln);
1407  if (index >= 0 && this->fColPtr[index] == acoln) return this->fDataPtr[index];
1408  else return 0.0;
1409  } else {
1410  Error("operator()","Request col(%d) outside matrix range of %d - %d",
1411  i,this->fMatrix->GetColLwb(),this->fMatrix->GetColLwb()+this->fMatrix->GetNcols());
1413  }
1414 }
1415 
1416 ////////////////////////////////////////////////////////////////////////////////
1417 /// operator() : pick element row(i)
1418 
1419 template<class Element>
1421 {
1422  if (!this->fMatrix) return TMatrixTBase<Element>::NaNValue();
1423  R__ASSERT(this->fMatrix->IsValid());
1424 
1425  const Int_t acoln = i-this->fMatrix->GetColLwb();
1426  if (acoln >= this->fMatrix->GetNcols() || acoln < 0) {
1427  Error("operator()(Int_t","Requested element %d outside range : %d - %d",i,
1428  this->fMatrix->GetColLwb(),this->fMatrix->GetColLwb()+this->fMatrix->GetNcols());
1430  }
1431 
1432  Int_t index = TMath::BinarySearch(this->fNindex,this->fColPtr,acoln);
1433  if (index >= 0 && this->fColPtr[index] == acoln)
1434  return (const_cast<Element*>(this->fDataPtr))[index];
1435  else {
1436  TMatrixTSparse<Element> *mt = const_cast<TMatrixTSparse<Element> *>(this->fMatrix);
1437  const Int_t row = this->fRowInd+mt->GetRowLwb();
1438  Element val = 0.;
1439  mt->InsertRow(row,i,&val,1);
1440  const Int_t sIndex = mt->GetRowIndexArray()[this->fRowInd];
1441  const Int_t eIndex = mt->GetRowIndexArray()[this->fRowInd+1];
1442  this->fNindex = eIndex-sIndex;
1443  this->fColPtr = mt->GetColIndexArray()+sIndex;
1444  this->fDataPtr = mt->GetMatrixArray()+sIndex;
1445  index = TMath::BinarySearch(this->fNindex,this->fColPtr,acoln);
1446  if (index >= 0 && this->fColPtr[index] == acoln)
1447  return (const_cast<Element*>(this->fDataPtr))[index];
1448  else {
1449  Error("operator()(Int_t","Insert row failed");
1451  }
1452  }
1453 }
1454 
1455 ////////////////////////////////////////////////////////////////////////////////
1456 /// Assign val to every non-zero (!) element of the matrix row.
1457 
1458 template<class Element>
1460 {
1461  R__ASSERT(this->fMatrix->IsValid());
1462  Element *rp = const_cast<Element *>(this->fDataPtr);
1463  for ( ; rp < this->fDataPtr+this->fNindex; rp++)
1464  *rp = val;
1465 }
1466 
1467 ////////////////////////////////////////////////////////////////////////////////
1468 /// Add val to every non-zero (!) element of the matrix row.
1469 
1470 template<class Element>
1472 {
1473  R__ASSERT(this->fMatrix->IsValid());
1474  Element *rp = const_cast<Element *>(this->fDataPtr);
1475  for ( ; rp < this->fDataPtr+this->fNindex; rp++)
1476  *rp += val;
1477 }
1478 
1479 ////////////////////////////////////////////////////////////////////////////////
1480 /// Multiply every element of the matrix row by val.
1481 
1482 template<class Element>
1484 {
1485  R__ASSERT(this->fMatrix->IsValid());
1486  Element *rp = const_cast<Element *>(this->fDataPtr);
1487  for ( ; rp < this->fDataPtr+this->fNindex; rp++)
1488  *rp *= val;
1489 }
1490 
1491 ////////////////////////////////////////////////////////////////////////////////
1492 /// Assignment operator
1493 
1494 template<class Element>
1496 {
1497  const TMatrixTBase<Element> *mt = mr.GetMatrix();
1498  if (this->fMatrix == mt) return;
1499 
1500  R__ASSERT(this->fMatrix->IsValid());
1501  R__ASSERT(mt->IsValid());
1502  if (this->fMatrix->GetColLwb() != mt->GetColLwb() || this->fMatrix->GetNcols() != mt->GetNcols()) {
1503  Error("operator=(const TMatrixTSparseRow_const &)","matrix rows not compatible");
1504  return;
1505  }
1506 
1507  const Int_t ncols = this->fMatrix->GetNcols();
1508  const Int_t row1 = this->fRowInd+this->fMatrix->GetRowLwb();
1509  const Int_t row2 = mr.GetRowIndex()+mt->GetRowLwb();
1510  const Int_t col = this->fMatrix->GetColLwb();
1511 
1512  TVectorT<Element> v(ncols);
1513  mt->ExtractRow(row2,col,v.GetMatrixArray());
1514  const_cast<TMatrixTSparse<Element> *>(this->fMatrix)->InsertRow(row1,col,v.GetMatrixArray());
1515 
1516  const Int_t sIndex = this->fMatrix->GetRowIndexArray()[this->fRowInd];
1517  const Int_t eIndex = this->fMatrix->GetRowIndexArray()[this->fRowInd+1];
1518  this->fNindex = eIndex-sIndex;
1519  this->fColPtr = this->fMatrix->GetColIndexArray()+sIndex;
1520  this->fDataPtr = this->fMatrix->GetMatrixArray()+sIndex;
1521 }
1522 
1523 ////////////////////////////////////////////////////////////////////////////////
1524 /// Assign a vector to a matrix row. The vector is considered row-vector
1525 /// to allow the assignment in the strict sense.
1526 
1527 template<class Element>
1529 {
1530  R__ASSERT(this->fMatrix->IsValid());
1531  R__ASSERT(vec.IsValid());
1532 
1533  if (this->fMatrix->GetColLwb() != vec.GetLwb() || this->fMatrix->GetNcols() != vec.GetNrows()) {
1534  Error("operator=(const TVectorT &)","vector length != matrix-row length");
1535  return;
1536  }
1537 
1538  const Element *vp = vec.GetMatrixArray();
1539  const Int_t row = this->fRowInd+this->fMatrix->GetRowLwb();
1540  const Int_t col = this->fMatrix->GetColLwb();
1541  const_cast<TMatrixTSparse<Element> *>(this->fMatrix)->InsertRow(row,col,vp,vec.GetNrows());
1542 
1543  const Int_t sIndex = this->fMatrix->GetRowIndexArray()[this->fRowInd];
1544  const Int_t eIndex = this->fMatrix->GetRowIndexArray()[this->fRowInd+1];
1545  this->fNindex = eIndex-sIndex;
1546  this->fColPtr = this->fMatrix->GetColIndexArray()+sIndex;
1547  this->fDataPtr = this->fMatrix->GetMatrixArray()+sIndex;
1548 }
1549 
1550 ////////////////////////////////////////////////////////////////////////////////
1551 /// Add to every element of the matrix row the corresponding element of row r.
1552 
1553 template<class Element>
1555 {
1556  const TMatrixTBase<Element> *mt = r.GetMatrix();
1557 
1558  R__ASSERT(this->fMatrix->IsValid());
1559  R__ASSERT(mt->IsValid());
1560  if (this->fMatrix->GetColLwb() != mt->GetColLwb() || this->fMatrix->GetNcols() != mt->GetNcols()) {
1561  Error("operator+=(const TMatrixTRow_const &)","different row lengths");
1562  return;
1563  }
1564 
1565  const Int_t ncols = this->fMatrix->GetNcols();
1566  const Int_t row1 = this->fRowInd+this->fMatrix->GetRowLwb();
1567  const Int_t row2 = r.GetRowIndex()+mt->GetRowLwb();
1568  const Int_t col = this->fMatrix->GetColLwb();
1569 
1570  TVectorT<Element> v1(ncols);
1571  TVectorT<Element> v2(ncols);
1572  this->fMatrix->ExtractRow(row1,col,v1.GetMatrixArray());
1573  mt ->ExtractRow(row2,col,v2.GetMatrixArray());
1574  v1 += v2;
1575  const_cast<TMatrixTSparse<Element> *>(this->fMatrix)->InsertRow(row1,col,v1.GetMatrixArray());
1576 
1577  const Int_t sIndex = this->fMatrix->GetRowIndexArray()[this->fRowInd];
1578  const Int_t eIndex = this->fMatrix->GetRowIndexArray()[this->fRowInd+1];
1579  this->fNindex = eIndex-sIndex;
1580  this->fColPtr = this->fMatrix->GetColIndexArray()+sIndex;
1581  this->fDataPtr = this->fMatrix->GetMatrixArray()+sIndex;
1582 }
1583 
1584 ////////////////////////////////////////////////////////////////////////////////
1585 /// Multiply every element of the matrix row with the
1586 /// corresponding element of row r.
1587 
1588 template<class Element>
1590 {
1591  const TMatrixTBase<Element> *mt = r.GetMatrix();
1592 
1593  R__ASSERT(this->fMatrix->IsValid());
1594  R__ASSERT(mt->IsValid());
1595  if (this->fMatrix->GetColLwb() != mt->GetColLwb() || this->fMatrix->GetNcols() != mt->GetNcols()) {
1596  Error("operator+=(const TMatrixTRow_const &)","different row lengths");
1597  return;
1598  }
1599 
1600  const Int_t ncols = this->fMatrix->GetNcols();
1601  const Int_t row1 = r.GetRowIndex()+mt->GetRowLwb();
1602  const Int_t row2 = r.GetRowIndex()+mt->GetRowLwb();
1603  const Int_t col = this->fMatrix->GetColLwb();
1604 
1605  TVectorT<Element> v1(ncols);
1606  TVectorT<Element> v2(ncols);
1607  this->fMatrix->ExtractRow(row1,col,v1.GetMatrixArray());
1608  mt ->ExtractRow(row2,col,v2.GetMatrixArray());
1609 
1610  ElementMult(v1,v2);
1611  const_cast<TMatrixTSparse<Element> *>(this->fMatrix)->InsertRow(row1,col,v1.GetMatrixArray());
1612 
1613  const Int_t sIndex = this->fMatrix->GetRowIndexArray()[this->fRowInd];
1614  const Int_t eIndex = this->fMatrix->GetRowIndexArray()[this->fRowInd+1];
1615  this->fNindex = eIndex-sIndex;
1616  this->fColPtr = this->fMatrix->GetColIndexArray()+sIndex;
1617  this->fDataPtr = this->fMatrix->GetMatrixArray()+sIndex;
1618 }
1619 
1620 ////////////////////////////////////////////////////////////////////////////////
1621 /// Constructor
1622 
1623 template<class Element>
1625 {
1626  R__ASSERT(matrix.IsValid());
1627 
1628  fMatrix = &matrix;
1629  fNdiag = TMath::Min(matrix.GetNrows(),matrix.GetNcols());
1630  fDataPtr = matrix.GetMatrixArray();
1631 }
1632 
1633 ////////////////////////////////////////////////////////////////////////////////
1634 
1635 template<class Element>
1637 {
1638  R__ASSERT(fMatrix->IsValid());
1639  if (i < fNdiag && i >= 0) {
1640  const Int_t * const pR = fMatrix->GetRowIndexArray();
1641  const Int_t * const pC = fMatrix->GetColIndexArray();
1642  const Element * const pD = fMatrix->GetMatrixArray();
1643  const Int_t sIndex = pR[i];
1644  const Int_t eIndex = pR[i+1];
1645  const Int_t index = TMath::BinarySearch(eIndex-sIndex,pC+sIndex,i)+sIndex;
1646  if (index >= sIndex && pC[index] == i) return pD[index];
1647  else return 0.0;
1648  } else {
1649  Error("operator()","Request diagonal(%d) outside matrix range of 0 - %d",i,fNdiag);
1650  return 0.0;
1651  }
1652  return 0.0;
1653 }
1654 
1655 ////////////////////////////////////////////////////////////////////////////////
1656 /// Constructor
1657 
1658 template<class Element>
1660  :TMatrixTSparseDiag_const<Element>(matrix)
1661 {
1662 }
1663 
1664 ////////////////////////////////////////////////////////////////////////////////
1665 /// Constructor
1666 
1667 template<class Element>
1669  : TMatrixTSparseDiag_const<Element>(md)
1670 {
1671  *this = md;
1672 }
1673 
1674 ////////////////////////////////////////////////////////////////////////////////
1675 
1676 template<class Element>
1678 {
1679  R__ASSERT(this->fMatrix->IsValid());
1680  if (i < this->fNdiag && i >= 0) {
1681  const Int_t * const pR = this->fMatrix->GetRowIndexArray();
1682  const Int_t * const pC = this->fMatrix->GetColIndexArray();
1683  const Element * const pD = this->fMatrix->GetMatrixArray();
1684  const Int_t sIndex = pR[i];
1685  const Int_t eIndex = pR[i+1];
1686  const Int_t index = TMath::BinarySearch(eIndex-sIndex,pC+sIndex,i)+sIndex;
1687  if (index >= sIndex && pC[index] == i) return pD[index];
1688  else return 0.0;
1689  } else {
1690  Error("operator()","Request diagonal(%d) outside matrix range of 0 - %d",i,this->fNdiag);
1691  return 0.0;
1692  }
1693  return 0.0;
1694  }
1695 
1696 ////////////////////////////////////////////////////////////////////////////////
1697 /// operator() : pick element diag(i)
1698 
1699 template<class Element>
1701 {
1702  R__ASSERT(this->fMatrix->IsValid());
1703 
1704  if (i < 0 || i >= this->fNdiag) {
1705  Error("operator()(Int_t","Requested element %d outside range : 0 - %d",i,this->fNdiag);
1706  return (const_cast<Element*>(this->fDataPtr))[0];
1707  }
1708 
1709  TMatrixTSparse<Element> *mt = const_cast<TMatrixTSparse<Element> *>(this->fMatrix);
1710  const Int_t *pR = mt->GetRowIndexArray();
1711  const Int_t *pC = mt->GetColIndexArray();
1712  Int_t sIndex = pR[i];
1713  Int_t eIndex = pR[i+1];
1714  Int_t index = TMath::BinarySearch(eIndex-sIndex,pC+sIndex,i)+sIndex;
1715  if (index >= sIndex && pC[index] == i)
1716  return (const_cast<Element*>(this->fDataPtr))[index];
1717  else {
1718  const Int_t row = i+mt->GetRowLwb();
1719  const Int_t col = i+mt->GetColLwb();
1720  Element val = 0.;
1721  mt->InsertRow(row,col,&val,1);
1722  this->fDataPtr = mt->GetMatrixArray();
1723  pR = mt->GetRowIndexArray();
1724  pC = mt->GetColIndexArray();
1725  sIndex = pR[i];
1726  eIndex = pR[i+1];
1727  index = TMath::BinarySearch(eIndex-sIndex,pC+sIndex,i)+sIndex;
1728  if (index >= sIndex && pC[index] == i)
1729  return (const_cast<Element*>(this->fDataPtr))[index];
1730  else {
1731  Error("operator()(Int_t","Insert row failed");
1732  return (const_cast<Element*>(this->fDataPtr))[0];
1733  }
1734  }
1735 }
1736 
1737 ////////////////////////////////////////////////////////////////////////////////
1738 /// Assign val to every element of the matrix diagonal.
1739 
1740 template<class Element>
1742 {
1743  R__ASSERT(this->fMatrix->IsValid());
1744  for (Int_t i = 0; i < this->fNdiag; i++)
1745  (*this)(i) = val;
1746 }
1747 
1748 ////////////////////////////////////////////////////////////////////////////////
1749 /// Add val to every element of the matrix diagonal.
1750 
1751 template<class Element>
1753 {
1754  R__ASSERT(this->fMatrix->IsValid());
1755  for (Int_t i = 0; i < this->fNdiag; i++)
1756  (*this)(i) += val;
1757 }
1758 
1759 ////////////////////////////////////////////////////////////////////////////////
1760 /// Multiply every element of the matrix diagonal by val.
1761 
1762 template<class Element>
1764 {
1765  R__ASSERT(this->fMatrix->IsValid());
1766  for (Int_t i = 0; i < this->fNdiag; i++)
1767  (*this)(i) *= val;
1768 }
1769 
1770 ////////////////////////////////////////////////////////////////////////////////
1771 /// Assignment operator
1772 
1773 template<class Element>
1775 {
1776  const TMatrixTBase<Element> *mt = md.GetMatrix();
1777  if (this->fMatrix == mt) return;
1778 
1779  R__ASSERT(this->fMatrix->IsValid());
1780  R__ASSERT(mt->IsValid());
1781  if (this->fNdiag != md.GetNdiags()) {
1782  Error("operator=(const TMatrixTSparseDiag_const &)","matrix-diagonal's different length");
1783  return;
1784  }
1785 
1786  for (Int_t i = 0; i < this->fNdiag; i++)
1787  (*this)(i) = md(i);
1788 }
1789 
1790 ////////////////////////////////////////////////////////////////////////////////
1791 /// Assign a vector to the matrix diagonal.
1792 
1793 template<class Element>
1795 {
1796  R__ASSERT(this->fMatrix->IsValid());
1797  R__ASSERT(vec.IsValid());
1798 
1799  if (this->fNdiag != vec.GetNrows()) {
1800  Error("operator=(const TVectorT &)","vector length != matrix-diagonal length");
1801  return;
1802  }
1803 
1804  const Element *vp = vec.GetMatrixArray();
1805  for (Int_t i = 0; i < this->fNdiag; i++)
1806  (*this)(i) = vp[i];
1807 }
1808 
1809 ////////////////////////////////////////////////////////////////////////////////
1810 /// Add to every element of the matrix diagonal the
1811 /// corresponding element of diagonal md.
1812 
1813 template<class Element>
1815 {
1816  const TMatrixTBase<Element> *mt = md.GetMatrix();
1817 
1818  R__ASSERT(this->fMatrix->IsValid());
1819  R__ASSERT(mt->IsValid());
1820  if (this->fNdiag != md.GetNdiags()) {
1821  Error("operator+=(const TMatrixTSparseDiag_const &)","matrix-diagonal's different length");
1822  return;
1823  }
1824 
1825  for (Int_t i = 0; i < this->fNdiag; i++)
1826  (*this)(i) += md(i);
1827 }
1828 
1829 ////////////////////////////////////////////////////////////////////////////////
1830 /// Multiply every element of the matrix diagonal with the
1831 /// corresponding element of diagonal md.
1832 
1833 template<class Element>
1835 {
1836  const TMatrixTBase<Element> *mt = md.GetMatrix();
1837 
1838  R__ASSERT(this->fMatrix->IsValid());
1839  R__ASSERT(mt->IsValid());
1840  if (this->fNdiag != md.GetNdiags()) {
1841  Error("operator*=(const TMatrixTSparseDiag_const &)","matrix-diagonal's different length");
1842  return;
1843  }
1844 
1845  for (Int_t i = 0; i < this->fNdiag; i++)
1846  (*this)(i) *= md(i);
1847 }
1848 
1849 ////////////////////////////////////////////////////////////////////////////////
1850 /// Random number generator [0....1] with seed ix
1851 
1853 {
1854  const Double_t a = 16807.0;
1855  const Double_t b15 = 32768.0;
1856  const Double_t b16 = 65536.0;
1857  const Double_t p = 2147483647.0;
1858  Double_t xhi = ix/b16;
1859  Int_t xhiint = (Int_t) xhi;
1860  xhi = xhiint;
1861  Double_t xalo = (ix-xhi*b16)*a;
1862 
1863  Double_t leftlo = xalo/b16;
1864  Int_t leftloint = (int) leftlo;
1865  leftlo = leftloint;
1866  Double_t fhi = xhi*a+leftlo;
1867  Double_t k = fhi/b15;
1868  Int_t kint = (Int_t) k;
1869  k = kint;
1870  ix = (((xalo-leftlo*b16)-p)+(fhi-k*b15)*b16)+k;
1871  if (ix < 0.0) ix = ix+p;
1872 
1873  return (ix*4.656612875e-10);
1874 }
1875 
1876 template class TMatrixTRow_const <Float_t>;
1877 template class TMatrixTColumn_const <Float_t>;
1878 template class TMatrixTDiag_const <Float_t>;
1879 template class TMatrixTFlat_const <Float_t>;
1880 template class TMatrixTSub_const <Float_t>;
1881 template class TMatrixTSparseRow_const <Float_t>;
1882 template class TMatrixTSparseDiag_const<Float_t>;
1883 template class TMatrixTRow <Float_t>;
1884 template class TMatrixTColumn <Float_t>;
1885 template class TMatrixTDiag <Float_t>;
1886 template class TMatrixTFlat <Float_t>;
1887 template class TMatrixTSub <Float_t>;
1888 template class TMatrixTSparseRow <Float_t>;
1889 template class TMatrixTSparseDiag <Float_t>;
1890 template class TElementActionT <Float_t>;
1891 template class TElementPosActionT <Float_t>;
1892 
1893 template class TMatrixTRow_const <Double_t>;
1894 template class TMatrixTColumn_const <Double_t>;
1895 template class TMatrixTDiag_const <Double_t>;
1896 template class TMatrixTFlat_const <Double_t>;
1897 template class TMatrixTSub_const <Double_t>;
1898 template class TMatrixTSparseRow_const <Double_t>;
1899 template class TMatrixTSparseDiag_const<Double_t>;
1900 template class TMatrixTRow <Double_t>;
1901 template class TMatrixTColumn <Double_t>;
1902 template class TMatrixTDiag <Double_t>;
1903 template class TMatrixTFlat <Double_t>;
1904 template class TMatrixTSub <Double_t>;
1905 template class TMatrixTSparseRow <Double_t>;
1906 template class TMatrixTSparseDiag <Double_t>;
1907 template class TElementActionT <Double_t>;
1908 template class TElementPosActionT <Double_t>;
Int_t GetRowLwb() const
Definition: TMatrixTBase.h:132
void Rank1Update(const TVectorT< Element > &vec, Element alpha=1.0)
Perform a rank 1 operation on the matrix: A += alpha * v * v^T.
Element operator()(Int_t i) const
virtual const Element * GetMatrixArray() const =0
virtual TMatrixTBase< Element > & InsertRow(Int_t row, Int_t col, const Element *v, Int_t n=-1)
Insert in row rown, n elements of array v at column coln.
virtual void ExtractRow(Int_t row, Int_t col, Element *v, Int_t n=-1) const
Store in array v, n matrix elements of row rown starting at column coln.
Int_t GetNrows() const
virtual TMatrixTBase< Element > & ResizeTo(Int_t nrows, Int_t ncols, Int_t=-1)
Set size of the matrix to nrows x ncols New dynamic elements are created, the overlapping part of the...
Int_t GetRowIndex() const
void operator+=(Element val)
Add val to every element of the matrix column.
const Double_t * v1
Definition: TArcBall.cxx:33
Bool_t IsValid() const
Definition: TVectorT.h:89
virtual const Element * GetMatrixArray() const
Int_t GetRowUpb() const
Definition: TMatrixTBase.h:133
void operator*=(Element val)
Multiply every element of the matrix with val.
Int_t GetNrows() const
Definition: TVectorT.h:81
void operator+=(Element val)
Assign val to every element of the matrix diagonal.
Double_t Drand(Double_t &ix)
Random number generator [0....1] with seed ix.
void operator*=(Element val)
Multiply every element of the sub matrix by val .
#define R__ASSERT(e)
Definition: TError.h:98
Int_t GetNoElements() const
Definition: TMatrixTBase.h:138
const TMatrixTBase< Element > * GetMatrix() const
Short_t Min(Short_t a, Short_t b)
Definition: TMathBase.h:170
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
TArc * a
Definition: textangle.C:12
const Bool_t kFALSE
Definition: Rtypes.h:92
void operator=(Element val)
Assign val to every element of the matrix diagonal.
void operator+=(Element val)
Add val to every non-zero (!) element of the matrix row.
void operator*=(Element val)
Multiply every element of the matrix row with val.
virtual TMatrixTBase< Element > & ResizeTo(Int_t nrows, Int_t ncols, Int_t=-1)
Set size of the matrix to nrows x ncols New dynamic elements are created, the overlapping part of the...
Definition: TMatrixT.cxx:1201
const TMatrixTBase< Element > * GetMatrix() const
Int_t GetNcols() const
Bool_t IsValid() const
Definition: TMatrixTBase.h:157
Element operator()(Int_t i) const
Element operator()(Int_t i) const
void operator*=(Element val)
Multiply every element of the matrix diagonal by val.
static double p2(double t, double a, double b, double c)
Int_t GetInc() const
const TMatrixTBase< Element > * GetMatrix() const
void Error(const char *location, const char *msgfmt,...)
Int_t GetColUpb() const
Definition: TMatrixTBase.h:136
virtual const Element * GetMatrixArray() const
Definition: TMatrixTSym.h:183
Int_t GetNrows() const
Definition: TMatrixTBase.h:134
void operator=(Element val)
Assign val to every element of the matrix column.
Element * GetMatrixArray()
Definition: TVectorT.h:84
void operator=(Element val)
Assign val to every element of the matrix.
Int_t GetRowOff() const
ROOT::R::TRInterface & r
Definition: Object.C:4
virtual const Int_t * GetRowIndexArray() const
SVector< double, 2 > v
Definition: Dict.h:5
const TMatrixTBase< Element > * GetMatrix() const
TMatrixT< Element > & ElementMult(TMatrixT< Element > &target, const TMatrixT< Element > &source)
Multiply target by the source, element-by-element.
Definition: TMatrixT.cxx:2972
TMarker * m
Definition: textangle.C:8
Int_t GetColIndex() const
virtual const Element * GetMatrixArray() const
Definition: TMatrixT.h:211
static double p1(double t, double a, double b)
const TMatrixTBase< Element > * GetMatrix() const
Int_t GetColLwb() const
Definition: TMatrixTBase.h:135
Int_t GetRowIndex() const
void operator+=(Element val)
Add val to every element of the sub matrix.
const TMatrixTBase< Element > * GetMatrix() const
void operator+=(Element val)
Add val to every element of the matrix.
void operator=(Element val)
Assign val to every element of the sub matrix.
const Element * GetPtr() const
Int_t GetLwb() const
Definition: TVectorT.h:79
void operator+=(Element val)
Add val to every element of the matrix diagonal.
double Double_t
Definition: RtypesCore.h:55
Int_t GetColOff() const
Int_t GetNcols() const
Definition: TMatrixTBase.h:137
const Element * GetPtr() const
void operator=(Element val)
Assign val to every element of the matrix row.
virtual const Int_t * GetColIndexArray() const
void operator*=(Element val)
Multiply every element of the matrix row by val.
Int_t GetNoElements() const
Definition: TVectorT.h:82
const Element * GetPtr() const
const TMatrixTBase< Element > * GetMatrix() const
const Element * GetPtr() const
void operator*=(Element val)
Multiply every element of the matrix column with val.
Short_t Max(Short_t a, Short_t b)
Definition: TMathBase.h:202
Int_t GetInc() const
Element operator()(Int_t i) const
static Element & NaNValue()
void operator=(Element val)
Assign val to every non-zero (!) element of the matrix row.
Int_t GetNdiags() const
TGMatrixLayout * fMatrix
const Bool_t kTRUE
Definition: Rtypes.h:91
void operator*=(Element val)
Assign val to every element of the matrix diagonal.
virtual TMatrixTBase< Element > & GetSub(Int_t row_lwb, Int_t row_upb, Int_t col_lwb, Int_t col_upb, TMatrixTBase< Element > &target, Option_t *option="S") const =0
void operator+=(Element val)
Add val to every element of the matrix row.
Long64_t BinarySearch(Long64_t n, const T *array, T value)
Definition: TMath.h:944
Int_t GetInc() const
Definition: drr.cxx:518
void operator=(Element val)
Assign val to every element of the matrix diagonal.
Int_t GetNdiags() const