Logo ROOT   6.10/00
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
TMatrixTUtils.h
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 #ifndef ROOT_TMatrixTUtils
13 #define ROOT_TMatrixTUtils
14 
15 //////////////////////////////////////////////////////////////////////////
16 // //
17 // Matrix utility classes. //
18 // //
19 // Templates of utility classes in the Linear Algebra Package. //
20 // The following classes are defined here: //
21 // //
22 // Different matrix views without copying data elements : //
23 // TMatrixTRow_const TMatrixTRow //
24 // TMatrixTColumn_const TMatrixTColumn //
25 // TMatrixTDiag_const TMatrixTDiag //
26 // TMatrixTFlat_const TMatrixTFlat //
27 // TMatrixTSub_const TMatrixTSub //
28 // TMatrixTSparseRow_const TMatrixTSparseRow //
29 // TMatrixTSparseDiag_const TMatrixTSparseDiag //
30 // //
31 // TElementActionT //
32 // TElementPosActionT //
33 // //
34 //////////////////////////////////////////////////////////////////////////
35 
36 #include "TMatrixTBase.h"
37 
38 template<class Element> class TVectorT;
39 template<class Element> class TMatrixT;
40 template<class Element> class TMatrixTSym;
41 template<class Element> class TMatrixTSparse;
42 
43 //////////////////////////////////////////////////////////////////////////
44 // //
45 // TElementActionT //
46 // //
47 // A class to do a specific operation on every vector or matrix element //
48 // (regardless of it position) as the object is being traversed. //
49 // This is an abstract class. Derived classes need to implement the //
50 // action function Operation(). //
51 // //
52 //////////////////////////////////////////////////////////////////////////
53 
54 template<class Element> class TElementActionT {
55 
56 #ifndef __CINT__
57 friend class TMatrixTBase <Element>;
58 friend class TMatrixT <Element>;
59 friend class TMatrixTSym <Element>;
60 friend class TMatrixTSparse<Element>;
61 friend class TVectorT <Element>;
62 #endif
63 
64 protected:
65  virtual ~TElementActionT() { }
66  virtual void Operation(Element &element) const = 0;
67 
68 private:
70 };
71 
72 //////////////////////////////////////////////////////////////////////////
73 // //
74 // TElementPosActionT //
75 // //
76 // A class to do a specific operation on every vector or matrix element //
77 // as the object is being traversed. This is an abstract class. //
78 // Derived classes need to implement the action function Operation(). //
79 // In the action function the location of the current element is //
80 // known (fI=row, fJ=columns). //
81 // //
82 //////////////////////////////////////////////////////////////////////////
83 
84 template<class Element> class TElementPosActionT {
85 
86 #ifndef __CINT__
87 friend class TMatrixTBase <Element>;
88 friend class TMatrixT <Element>;
89 friend class TMatrixTSym <Element>;
90 friend class TMatrixTSparse<Element>;
91 friend class TVectorT <Element>;
92 #endif
93 
94 protected:
95  mutable Int_t fI; // i position of element being passed to Operation()
96  mutable Int_t fJ; // j position of element being passed to Operation()
97  virtual ~TElementPosActionT() { }
98  virtual void Operation(Element &element) const = 0;
99 
100 private:
102 };
103 
104 //////////////////////////////////////////////////////////////////////////
105 // //
106 // TMatrixTRow_const //
107 // //
108 // Template class represents a row of a TMatrixT/TMatrixTSym //
109 // //
110 //////////////////////////////////////////////////////////////////////////
111 
112 template<class Element> class TMatrixTRow_const {
113 
114 protected:
115  const TMatrixTBase<Element> *fMatrix; // the matrix I am a row of
116  Int_t fRowInd; // effective row index
117  Int_t fInc; // if ptr = @a[row,i], then ptr+inc = @a[row,i+1]
118  const Element *fPtr; // pointer to the a[row,0]
119 
120 public:
121  TMatrixTRow_const() { fMatrix = 0; fRowInd = 0; fInc = 0; fPtr = 0; }
122  TMatrixTRow_const(const TMatrixT <Element> &matrix,Int_t row);
123  TMatrixTRow_const(const TMatrixTSym<Element> &matrix,Int_t row);
125  fMatrix(trc.fMatrix), fRowInd(trc.fRowInd), fInc(trc.fInc), fPtr(trc.fPtr) { }
127  if(this != &trc) { fMatrix=trc.fMatrix; fRowInd=trc.fRowInd; fInc=trc.fInc; fPtr=trc.fPtr; } return *this;}
128  virtual ~TMatrixTRow_const() { }
129 
130  inline const TMatrixTBase<Element> *GetMatrix () const { return fMatrix; }
131  inline Int_t GetRowIndex() const { return fRowInd; }
132  inline Int_t GetInc () const { return fInc; }
133  inline const Element *GetPtr () const { return fPtr; }
134  inline const Element &operator ()(Int_t i) const {
136  R__ASSERT(fMatrix->IsValid());
137  const Int_t acoln = i-fMatrix->GetColLwb();
138  if (acoln < fMatrix->GetNcols() && acoln >= 0)
139  return fPtr[acoln];
140  else {
141  Error("operator()","Request col(%d) outside matrix range of %d - %d",
142  i,fMatrix->GetColLwb(),fMatrix->GetColLwb()+fMatrix->GetNcols());
144  }
145  }
146  inline const Element &operator [](Int_t i) const { return (*(const TMatrixTRow_const<Element> *)this)(i); }
147 
148  ClassDef(TMatrixTRow_const,0) // Template of General Matrix Row Access class
149 };
150 
151 template<class Element> class TMatrixTRow : public TMatrixTRow_const<Element> {
152 
153 public:
155  TMatrixTRow(TMatrixT <Element> &matrix,Int_t row);
158 
159  inline Element *GetPtr() const { return const_cast<Element *>(this->fPtr); }
160 
161  inline const Element &operator()(Int_t i) const {
162  if (!this->fMatrix) return TMatrixTBase<Element>::NaNValue();
163  R__ASSERT(this->fMatrix->IsValid());
164  const Int_t acoln = i-this->fMatrix->GetColLwb();
165  if (acoln < this->fMatrix->GetNcols() || acoln >= 0)
166  return (this->fPtr)[acoln];
167  else {
168  Error("operator()","Request col(%d) outside matrix range of %d - %d",
169  i,this->fMatrix->GetColLwb(),this->fMatrix->GetColLwb()+this->fMatrix->GetNcols());
171  }
172  }
173  inline Element &operator()(Int_t i) {
174  if (!this->fMatrix) return TMatrixTBase<Element>::NaNValue();
175  R__ASSERT(this->fMatrix->IsValid());
176  const Int_t acoln = i-this->fMatrix->GetColLwb();
177  if (acoln < this->fMatrix->GetNcols() && acoln >= 0)
178  return (const_cast<Element *>(this->fPtr))[acoln];
179  else {
180  Error("operator()","Request col(%d) outside matrix range of %d - %d",
181  i,this->fMatrix->GetColLwb(),this->fMatrix->GetColLwb()+this->fMatrix->GetNcols());
182  //return (const_cast<Element *>(this->fPtr))[0];
184  }
185  }
186  inline const Element &operator[](Int_t i) const { return (*(const TMatrixTRow<Element> *)this)(i); }
187  inline Element &operator[](Int_t i) { return (*( TMatrixTRow<Element> *)this)(i); }
188 
189  void Assign (Element val);
190  void operator= (std::initializer_list<Element> l);
191  void operator+=(Element val);
192  void operator*=(Element val);
193 
196  void operator=(const TVectorT <Element> &vec);
197 
200 
201  ClassDef(TMatrixTRow,0) // Template of General Matrix Row Access class
202 };
203 
204 //////////////////////////////////////////////////////////////////////////
205 // //
206 // TMatrixTColumn_const //
207 // //
208 // Template class represents a column of a TMatrixT/TMatrixTSym //
209 // //
210 //////////////////////////////////////////////////////////////////////////
211 
212 template<class Element> class TMatrixTColumn_const {
213 
214 protected:
215  const TMatrixTBase<Element> *fMatrix; // the matrix I am a column of
216  Int_t fColInd; // effective column index
217  Int_t fInc; // if ptr = @a[i,col], then ptr+inc = @a[i+1,col]
218  const Element *fPtr; // pointer to the a[0,col] column
219 
220 public:
221  TMatrixTColumn_const() { fMatrix = 0; fColInd = 0; fInc = 0; fPtr = 0; }
222  TMatrixTColumn_const(const TMatrixT <Element> &matrix,Int_t col);
225  fMatrix(trc.fMatrix), fColInd(trc.fColInd), fInc(trc.fInc), fPtr(trc.fPtr) { }
227  if(this != &trc) { fMatrix=trc.fMatrix; fColInd=trc.fColInd; fInc=trc.fInc; fPtr=trc.fPtr; } return *this;}
228  virtual ~TMatrixTColumn_const() { }
229 
230  inline const TMatrixTBase <Element> *GetMatrix () const { return fMatrix; }
231  inline Int_t GetColIndex() const { return fColInd; }
232  inline Int_t GetInc () const { return fInc; }
233  inline const Element *GetPtr () const { return fPtr; }
234  inline const Element &operator ()(Int_t i) const {
235  if (!this->fMatrix) return TMatrixTBase<Element>::NaNValue();
236  R__ASSERT(fMatrix->IsValid());
237  const Int_t arown = i-fMatrix->GetRowLwb();
238  if (arown < fMatrix->GetNrows() && arown >= 0)
239  return fPtr[arown*fInc];
240  else {
241  Error("operator()","Request row(%d) outside matrix range of %d - %d",
242  i,fMatrix->GetRowLwb(),fMatrix->GetRowLwb()+fMatrix->GetNrows());
244  }
245  }
246  inline const Element &operator [](Int_t i) const { return (*(const TMatrixTColumn_const<Element> *)this)(i); }
247 
248  ClassDef(TMatrixTColumn_const,0) // Template of General Matrix Column Access class
249 };
250 
251 template<class Element> class TMatrixTColumn : public TMatrixTColumn_const<Element> {
252 
253 public:
258 
259  inline Element *GetPtr() const { return const_cast<Element *>(this->fPtr); }
260 
261  inline const Element &operator()(Int_t i) const {
262  if (!this->fMatrix) return TMatrixTBase<Element>::NaNValue();
263  R__ASSERT(this->fMatrix->IsValid());
264  const Int_t arown = i-this->fMatrix->GetRowLwb();
265  if (arown < this->fMatrix->GetNrows() && arown >= 0)
266  return (this->fPtr)[arown*this->fInc];
267  else {
268  Error("operator()","Request row(%d) outside matrix range of %d - %d",
269  i,this->fMatrix->GetRowLwb(),this->fMatrix->GetRowLwb()+this->fMatrix->GetNrows());
271  }
272  }
273  inline Element &operator()(Int_t i) {
274  if (!this->fMatrix) return TMatrixTBase<Element>::NaNValue();
275  R__ASSERT(this->fMatrix->IsValid());
276  const Int_t arown = i-this->fMatrix->GetRowLwb();
277 
278  if (arown < this->fMatrix->GetNrows() && arown >= 0)
279  return (const_cast<Element *>(this->fPtr))[arown*this->fInc];
280  else {
281  Error("operator()","Request row(%d) outside matrix range of %d - %d",
282  i,this->fMatrix->GetRowLwb(),this->fMatrix->GetRowLwb()+this->fMatrix->GetNrows());
284  }
285  }
286  inline const Element &operator[](Int_t i) const { return (*(const TMatrixTColumn<Element> *)this)(i); }
287  inline Element &operator[](Int_t i) { return (*( TMatrixTColumn<Element> *)this)(i); }
288 
289  void Assign (Element val);
290  // keep it for backward compatibility (but it has been removed for TMatrixTRow)
291  void operator= (Element val) { return Assign(val); }
292  void operator= (std::initializer_list<Element> l);
293  void operator+=(Element val);
294  void operator*=(Element val);
295 
298  void operator=(const TVectorT <Element> &vec);
299 
302 
303  ClassDef(TMatrixTColumn,0) // Template of General Matrix Column Access class
304 };
305 
306 //////////////////////////////////////////////////////////////////////////
307 // //
308 // TMatrixTDiag_const //
309 // //
310 // Template class represents the diagonal of a TMatrixT/TMatrixTSym //
311 // //
312 //////////////////////////////////////////////////////////////////////////
313 
314 template<class Element> class TMatrixTDiag_const {
315 
316 protected:
317  const TMatrixTBase<Element> *fMatrix; // the matrix I am the diagonal of
318  Int_t fInc; // if ptr=@a[i,i], then ptr+inc = @a[i+1,i+1]
319  Int_t fNdiag; // number of diag elems, min(nrows,ncols)
320  const Element *fPtr; // pointer to the a[0,0]
321 
322 public:
323  TMatrixTDiag_const() { fMatrix = 0; fInc = 0; fNdiag = 0; fPtr = 0; }
324  TMatrixTDiag_const(const TMatrixT <Element> &matrix);
327  fMatrix(trc.fMatrix), fInc(trc.fInc), fNdiag(trc.fNdiag), fPtr(trc.fPtr) { }
329  if(this != &trc) { fMatrix=trc.fMatrix; fInc=trc.fInc; fNdiag=trc.fNdiag; fPtr=trc.fPtr; } return *this;}
330  virtual ~TMatrixTDiag_const() { }
331 
332  inline const TMatrixTBase<Element> *GetMatrix() const { return fMatrix; }
333  inline const Element *GetPtr () const { return fPtr; }
334  inline Int_t GetInc () const { return fInc; }
335  inline const Element &operator ()(Int_t i) const {
336  R__ASSERT(fMatrix->IsValid());
337  if (i < fNdiag && i >= 0)
338  return fPtr[i*fInc];
339  else {
340  Error("operator()","Request diagonal(%d) outside matrix range of 0 - %d",i,fNdiag);
342  }
343  }
344  inline const Element &operator [](Int_t i) const { return (*(const TMatrixTDiag_const<Element> *)this)(i); }
345 
346  Int_t GetNdiags() const { return fNdiag; }
347 
348  ClassDef(TMatrixTDiag_const,0) // Template of General Matrix Diagonal Access class
349 };
350 
351 template<class Element> class TMatrixTDiag : public TMatrixTDiag_const<Element> {
352 
353 public:
358 
359  inline Element *GetPtr() const { return const_cast<Element *>(this->fPtr); }
360 
361  inline const Element &operator()(Int_t i) const {
362  R__ASSERT(this->fMatrix->IsValid());
363  if (i < this->fNdiag && i >= 0)
364  return (this->fPtr)[i*this->fInc];
365  else {
366  Error("operator()","Request diagonal(%d) outside matrix range of 0 - %d",i,this->fNdiag);
368  }
369  }
370  inline Element &operator()(Int_t i) {
371  R__ASSERT(this->fMatrix->IsValid());
372  if (i < this->fNdiag && i >= 0)
373  return (const_cast<Element *>(this->fPtr))[i*this->fInc];
374  else {
375  Error("operator()","Request diagonal(%d) outside matrix range of 0 - %d",i,this->fNdiag);
376  return (const_cast<Element *>(this->fPtr))[0];
377  }
378  }
379  inline const Element &operator[](Int_t i) const { return (*(const TMatrixTDiag<Element> *)this)(i); }
380  inline Element &operator[](Int_t i) { return (*( TMatrixTDiag *)this)(i); }
381 
382  void operator= (Element val);
383  void operator+=(Element val);
384  void operator*=(Element val);
385 
386  void operator=(const TMatrixTDiag_const<Element> &d);
388  void operator=(const TVectorT <Element> &vec);
389 
392 
393  ClassDef(TMatrixTDiag,0) // Template of General Matrix Diagonal Access class
394 };
395 
396 //////////////////////////////////////////////////////////////////////////
397 // //
398 // TMatrixTFlat_const //
399 // //
400 // Template class represents a flat TMatrixT/TMatrixTSym //
401 // //
402 //////////////////////////////////////////////////////////////////////////
403 
404 template<class Element> class TMatrixTFlat_const {
405 
406 protected:
407  const TMatrixTBase<Element> *fMatrix; // the matrix I am the diagonal of
409  const Element *fPtr; // pointer to the a[0,0]
410 
411 public:
412  TMatrixTFlat_const() { fMatrix = 0; fNelems = 0; fPtr = 0; }
413  TMatrixTFlat_const(const TMatrixT <Element> &matrix);
416  fMatrix(trc.fMatrix), fNelems(trc.fNelems), fPtr(trc.fPtr) { }
418  if(this != &trc) { fMatrix=trc.fMatrix; fNelems=trc.fNelems; fPtr=trc.fPtr; } return *this;}
419  virtual ~TMatrixTFlat_const() { }
420 
421  inline const TMatrixTBase<Element> *GetMatrix() const { return fMatrix; }
422  inline const Element *GetPtr () const { return fPtr; }
423  inline const Element &operator ()(Int_t i) const {
424  R__ASSERT(fMatrix->IsValid());
425  if (i < fNelems && i >= 0)
426  return fPtr[i];
427  else {
428  Error("operator()","Request element(%d) outside matrix range of 0 - %d",i,fNelems);
430  }
431  }
432  inline const Element &operator [](Int_t i) const { return (*(const TMatrixTFlat_const<Element> *)this)(i); }
433 
434  ClassDef(TMatrixTFlat_const,0) // Template of General Matrix Flat Representation class
435 };
436 
437 template<class Element> class TMatrixTFlat : public TMatrixTFlat_const<Element> {
438 
439 public:
444 
445  inline Element *GetPtr() const { return const_cast<Element *>(this->fPtr); }
446 
447  inline const Element &operator()(Int_t i) const {
448  R__ASSERT(this->fMatrix->IsValid());
449  if (i < this->fNelems && i >= 0)
450  return (this->fPtr)[i];
451  else {
452  Error("operator()","Request element(%d) outside matrix range of 0 - %d",i,this->fNelems);
454  }
455  }
456  inline Element &operator()(Int_t i) {
457  R__ASSERT(this->fMatrix->IsValid());
458  if (i < this->fNelems && i >= 0)
459  return (const_cast<Element *>(this->fPtr))[i];
460  else {
461  Error("operator()","Request element(%d) outside matrix range of 0 - %d",i,this->fNelems);
463  }
464  }
465  inline const Element &operator[](Int_t i) const { return (*(const TMatrixTFlat<Element> *)this)(i); }
466  inline Element &operator[](Int_t i) { return (*( TMatrixTFlat<Element> *)this)(i); }
467 
468  void operator= (Element val);
469  void operator+=(Element val);
470  void operator*=(Element val);
471 
474  void operator=(const TVectorT <Element> &vec);
475 
478 
479  ClassDef(TMatrixTFlat,0) // Template of General Matrix Flat Representation class
480 };
481 
482 //////////////////////////////////////////////////////////////////////////
483 // //
484 // TMatrixTSub_const //
485 // //
486 // Template class represents a sub matrix of TMatrixT/TMatrixTSym //
487 // //
488 //////////////////////////////////////////////////////////////////////////
489 
490 template<class Element> class TMatrixTSub_const {
491 
492 protected:
493  const TMatrixTBase<Element> *fMatrix; // the matrix I am a submatrix of
498 
499 public:
501  TMatrixTSub_const(const TMatrixT <Element> &matrix,Int_t row_lwb,Int_t row_upb,Int_t col_lwb,Int_t col_upb);
502  TMatrixTSub_const(const TMatrixTSym<Element> &matrix,Int_t row_lwb,Int_t row_upb,Int_t col_lwb,Int_t col_upb);
503  virtual ~TMatrixTSub_const() { }
504 
505  inline const TMatrixTBase<Element> *GetMatrix() const { return fMatrix; }
506  inline Int_t GetRowOff() const { return fRowOff; }
507  inline Int_t GetColOff() const { return fColOff; }
508  inline Int_t GetNrows () const { return fNrowsSub; }
509  inline Int_t GetNcols () const { return fNcolsSub; }
510  inline const Element &operator ()(Int_t rown,Int_t coln) const {
511  R__ASSERT(fMatrix->IsValid());
512 
513  const Element *ptr = fMatrix->GetMatrixArray();
514  if (rown >= fNrowsSub || rown < 0) {
515  Error("operator()","Request row(%d) outside matrix range of 0 - %d",rown,fNrowsSub);
517  }
518  if (coln >= fNcolsSub || coln < 0) {
519  Error("operator()","Request column(%d) outside matrix range of 0 - %d",coln,fNcolsSub);
521  }
522  const Int_t index = (rown+fRowOff)*fMatrix->GetNcols()+coln+fColOff;
523  return ptr[index];
524  }
525 
526  ClassDef(TMatrixTSub_const,0) // Template of Sub Matrix Access class
527 };
528 
529 template<class Element> class TMatrixTSub : public TMatrixTSub_const<Element> {
530 
531 public:
532 
533  enum {kWorkMax = 100};
534 
536  TMatrixTSub(TMatrixT <Element> &matrix,Int_t row_lwb,Int_t row_upb,Int_t col_lwb,Int_t col_upb);
537  TMatrixTSub(TMatrixTSym<Element> &matrix,Int_t row_lwb,Int_t row_upb,Int_t col_lwb,Int_t col_upb);
539 
540  inline Element &operator()(Int_t rown,Int_t coln) {
541  R__ASSERT(this->fMatrix->IsValid());
542 
543  const Element *ptr = this->fMatrix->GetMatrixArray();
544  if (rown >= this->fNrowsSub || rown < 0) {
545  Error("operator()","Request row(%d) outside matrix range of 0 - %d",rown,this->fNrowsSub);
547  }
548  if (coln >= this->fNcolsSub || coln < 0) {
549  Error("operator()","Request column(%d) outside matrix range of 0 - %d",coln,this->fNcolsSub);
551  }
552  const Int_t index = (rown+this->fRowOff)*this->fMatrix->GetNcols()+coln+this->fColOff;
553  return (const_cast<Element *>(ptr))[index];
554  }
555 
556  void Rank1Update(const TVectorT<Element> &vec,Element alpha=1.0);
557 
558  void operator= (Element val);
559  void operator+=(Element val);
560  void operator*=(Element val);
561 
562  void operator=(const TMatrixTSub_const<Element> &s);
564  void operator=(const TMatrixTBase <Element> &m);
565 
566  void operator+=(const TMatrixTSub_const<Element> &s);
567  void operator*=(const TMatrixTSub_const<Element> &s);
568  void operator+=(const TMatrixTBase <Element> &m);
569  void operator*=(const TMatrixT <Element> &m);
570  void operator*=(const TMatrixTSym <Element> &m);
571 
572  ClassDef(TMatrixTSub,0) // Template of Sub Matrix Access class
573 };
574 
575 //////////////////////////////////////////////////////////////////////////
576 // //
577 // TMatrixTSparseRow_const //
578 // //
579 // Template class represents a row of TMatrixTSparse //
580 // //
581 //////////////////////////////////////////////////////////////////////////
582 
583 template<class Element> class TMatrixTSparseRow_const {
584 
585 protected:
586  const TMatrixTSparse<Element> *fMatrix; // the matrix I am a row of
587  Int_t fRowInd; // effective row index
588  Int_t fNindex; // index range
589  const Int_t *fColPtr; // column index pointer
590  const Element *fDataPtr; // data pointer
591 
592 public:
596  fMatrix(trc.fMatrix), fRowInd(trc.fRowInd), fNindex(trc.fNindex), fColPtr(trc.fColPtr), fDataPtr(trc.fDataPtr) { }
598  if(this != &trc) { fMatrix=trc.fMatrix; fRowInd=trc.fRowInd; fNindex=trc.fNindex; fColPtr=trc.fColPtr; fDataPtr=trc.fDataPtr; } return *this;}
600 
601  inline const TMatrixTBase<Element> *GetMatrix () const { return fMatrix; }
602  inline const Element *GetDataPtr () const { return fDataPtr; }
603  inline const Int_t *GetColPtr () const { return fColPtr; }
604  inline Int_t GetRowIndex() const { return fRowInd; }
605  inline Int_t GetNindex () const { return fNindex; }
606 
607  Element operator()(Int_t i) const;
608  inline Element operator[](Int_t i) const { return (*(const TMatrixTSparseRow_const<Element> *)this)(i); }
609 
610  ClassDef(TMatrixTSparseRow_const,0) // Template of Sparse Matrix Row Access class
611 };
612 
613 template<class Element> class TMatrixTSparseRow : public TMatrixTSparseRow_const<Element> {
614 
615 public:
619 
620  inline Element *GetDataPtr() const { return const_cast<Element *>(this->fDataPtr); }
621 
622  Element operator()(Int_t i) const;
623  Element &operator()(Int_t i);
624  inline Element operator[](Int_t i) const { return (*(const TMatrixTSparseRow<Element> *)this)(i); }
625  inline Element &operator[](Int_t i) { return (*(TMatrixTSparseRow<Element> *)this)(i); }
626 
627  void operator= (Element val);
628  void operator+=(Element val);
629  void operator*=(Element val);
630 
633  void operator=(const TVectorT <Element> &vec);
634 
637 
638  ClassDef(TMatrixTSparseRow,0) // Template of Sparse Matrix Row Access class
639 };
640 
641 //////////////////////////////////////////////////////////////////////////
642 // //
643 // TMatrixTSparseDiag_const //
644 // //
645 // Template class represents the diagonal of TMatrixTSparse //
646 // //
647 //////////////////////////////////////////////////////////////////////////
648 
649 template<class Element> class TMatrixTSparseDiag_const {
650 
651 protected:
652  const TMatrixTSparse<Element> *fMatrix; // the matrix I am the diagonal of
653  Int_t fNdiag; // number of diag elems, min(nrows,ncols)
654  const Element *fDataPtr; // data pointer
655 
656 public:
660  fMatrix(trc.fMatrix), fNdiag(trc.fNdiag), fDataPtr(trc.fDataPtr) { }
662  if(this != &trc) { fMatrix=trc.fMatrix; fNdiag=trc.fNdiag; fDataPtr=trc.fDataPtr; } return *this;}
664 
665  inline const TMatrixTBase<Element> *GetMatrix () const { return fMatrix; }
666  inline const Element *GetDataPtr() const { return fDataPtr; }
667  inline Int_t GetNdiags () const { return fNdiag; }
668 
669  Element operator ()(Int_t i) const;
670  inline Element operator [](Int_t i) const { return (*(const TMatrixTSparseRow_const<Element> *)this)(i); }
671 
672  ClassDef(TMatrixTSparseDiag_const,0) // Template of Sparse Matrix Diagonal Access class
673 };
674 
675 template<class Element> class TMatrixTSparseDiag : public TMatrixTSparseDiag_const<Element> {
676 
677 public:
681 
682  inline Element *GetDataPtr() const { return const_cast<Element *>(this->fDataPtr); }
683 
684  Element operator()(Int_t i) const;
685  Element &operator()(Int_t i);
686  inline Element operator[](Int_t i) const { return (*(const TMatrixTSparseDiag<Element> *)this)(i); }
687  inline Element &operator[](Int_t i) { return (*(TMatrixTSparseDiag<Element> *)this)(i); }
688 
689  void operator= (Element val);
690  void operator+=(Element val);
691  void operator*=(Element val);
692 
695  void operator=(const TVectorT <Element> &vec);
696 
699 
700  ClassDef(TMatrixTSparseDiag,0) // Template of Sparse Matrix Diagonal Access class
701 };
702 
703 Double_t Drand(Double_t &ix);
704 #endif
Element operator[](Int_t i) const
void Rank1Update(const TVectorT< Element > &vec, Element alpha=1.0)
Perform a rank 1 operation on the matrix: A += alpha * v * v^T.
const TMatrixTSparse< Element > * fMatrix
Element operator()(Int_t i) const
TMatrixTSparseDiag_const< Element > & operator=(const TMatrixTSparseDiag_const< Element > &trc)
const Element & operator[](Int_t i) const
const Element & operator()(Int_t i) const
Int_t GetNrows() const
const Element & operator[](Int_t i) const
Element & operator()(Int_t i)
Element * GetPtr() const
Int_t GetRowIndex() const
void operator+=(Element val)
Add val to every element of the matrix column.
Element * GetPtr() const
const Element & operator()(Int_t i) const
const Element * fPtr
virtual ~TMatrixTSparseDiag_const()
void operator*=(Element val)
Multiply every element of the matrix with val.
TMatrixTSparseRow< Element > & operator=(const TMatrixTSparseRow< Element > &r)
const TMatrixTBase< Element > * fMatrix
void Assign(Element val)
Assign val to every element of the matrix row.
TMatrixTFlat_const(const TMatrixTFlat_const< Element > &trc)
void operator+=(Element val)
Assign val to every element of the matrix diagonal.
const Element & operator()(Int_t i) const
TVectorT.
Definition: TMatrixTBase.h:77
void operator*=(Element val)
Multiply every element of the sub matrix by val .
Element * GetPtr() const
#define R__ASSERT(e)
Definition: TError.h:96
const TMatrixTBase< Element > * GetMatrix() const
Element & operator()(Int_t i)
TMatrixTColumn< Element > & operator=(const TMatrixTColumn< Element > &c)
int Int_t
Definition: RtypesCore.h:41
void operator=(Element val)
Assign val to every element of the matrix diagonal.
const Element & operator[](Int_t i) const
const Element * fDataPtr
void operator+=(Element val)
Add val to every non-zero (!) element of the matrix row.
Element & operator()(Int_t i)
void operator*=(Element val)
Multiply every element of the matrix row with val.
TMatrixTSparseRow_const< Element > & operator=(const TMatrixTSparseRow_const< Element > &trc)
TMatrixTSub< Element > & operator=(const TMatrixTSub< Element > &s)
Int_t GetNindex() const
const Element & operator()(Int_t rown, Int_t coln) const
const TMatrixTBase< Element > * GetMatrix() const
Int_t GetNcols() const
Element & operator()(Int_t rown, Int_t coln)
void operator=(std::initializer_list< Element > l)
TMatrixT.
Definition: TMatrixDfwd.h:22
Element operator[](Int_t i) const
TMatrixTDiag_const< Element > & operator=(const TMatrixTDiag_const< Element > &trc)
virtual ~TElementPosActionT()
Definition: TMatrixTUtils.h:97
const Element * fPtr
#define ClassDef(name, id)
Definition: Rtypes.h:297
Element operator()(Int_t i) const
virtual void Operation(Element &element) const =0
TMatrixTSparseDiag_const(const TMatrixTSparseDiag_const< Element > &trc)
const TMatrixTBase< Element > * fMatrix
Element operator()(Int_t i) const
Element & operator[](Int_t i)
void operator*=(Element val)
Multiply every element of the matrix diagonal by val.
const Element & operator()(Int_t i) const
const Element & operator[](Int_t i) const
Int_t GetInc() const
TMatrixTSparseDiag< Element > & operator=(const TMatrixTSparseDiag< Element > &d)
const Element & operator()(Int_t i) const
const Element * fDataPtr
TMatrixTSym.
Element * GetDataPtr() const
const TMatrixTBase< Element > * GetMatrix() const
void Error(const char *location, const char *msgfmt,...)
virtual ~TMatrixTSub_const()
void operator=(Element val)
void operator=(Element val)
Assign val to every element of the matrix.
TMatrixTDiag< Element > & operator=(const TMatrixTDiag< Element > &d)
const Element * GetDataPtr() const
Element & operator[](Int_t i)
Int_t GetRowOff() const
const Element & operator[](Int_t i) const
TRandom2 r(17)
TMatrixTColumn_const< Element > & operator=(const TMatrixTColumn_const< Element > &trc)
TMatrixTSparseRow_const(const TMatrixTSparseRow_const< Element > &trc)
TMatrixTSparse.
const TMatrixTBase< Element > * GetMatrix() const
Element operator[](Int_t i) const
Element operator[](Int_t i) const
Element * GetPtr() const
const Int_t * GetColPtr() const
TMarker * m
Definition: textangle.C:8
Element * GetDataPtr() const
Int_t GetColIndex() const
const Element & operator()(Int_t i) const
TLine * l
Definition: textangle.C:4
const Element * fPtr
const Element & operator()(Int_t i) const
const Element & operator[](Int_t i) const
const TMatrixTBase< Element > * GetMatrix() const
Element & operator[](Int_t i)
const TMatrixTBase< Element > * fMatrix
Int_t GetRowIndex() const
TMatrixTRow< Element > & operator=(const TMatrixTRow< Element > &r)
void operator+=(Element val)
Add val to every element of the sub matrix.
TElementActionT & operator=(const TElementActionT< Element > &)
Definition: TMatrixTUtils.h:69
Linear Algebra Package.
virtual ~TMatrixTRow_const()
const Element & operator()(Int_t i) const
void Assign(Element val)
Assign val to every element of the matrix column.
virtual ~TMatrixTFlat_const()
const TMatrixTBase< Element > * GetMatrix() const
void operator+=(Element val)
Add val to every element of the matrix.
Element & operator[](Int_t i)
TMatrixTRow_const< Element > & operator=(const TMatrixTRow_const< Element > &trc)
void operator=(Element val)
Assign val to every element of the sub matrix.
double f(double x)
const Element * GetPtr() const
void operator+=(Element val)
Add val to every element of the matrix diagonal.
double Double_t
Definition: RtypesCore.h:55
TMatrixTRow_const(const TMatrixTRow_const< Element > &trc)
Int_t GetColOff() const
const Element & operator[](Int_t i) const
const Element * GetPtr() const
virtual void Operation(Element &element) const =0
const TMatrixTSparse< Element > * fMatrix
virtual ~TElementActionT()
Definition: TMatrixTUtils.h:65
const TMatrixTBase< Element > * fMatrix
TMatrixTDiag_const(const TMatrixTDiag_const< Element > &trc)
void operator*=(Element val)
Multiply every element of the matrix row by val.
Element & operator[](Int_t i)
const Element * GetPtr() const
const Element * fPtr
const TMatrixTBase< Element > * GetMatrix() const
const Element * GetPtr() const
void operator*=(Element val)
Multiply every element of the matrix column with val.
Int_t GetInc() const
virtual ~TMatrixTDiag_const()
const Element * GetDataPtr() 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.
Element & operator()(Int_t i)
Int_t GetNdiags() const
virtual ~TMatrixTColumn_const()
const TMatrixTBase< Element > * fMatrix
void operator*=(Element val)
Assign val to every element of the matrix diagonal.
TMatrixTColumn_const(const TMatrixTColumn_const< Element > &trc)
virtual ~TMatrixTSparseRow_const()
Double_t Drand(Double_t &ix)
Random number generator [0....1] with seed ix.
void operator+=(Element val)
Add val to every element of the matrix row.
TMatrixTFlat_const< Element > & operator=(const TMatrixTFlat_const< Element > &trc)
Int_t GetInc() const
Element & operator[](Int_t i)
TMatrixTFlat< Element > & operator=(const TMatrixTFlat< Element > &f)
void operator=(Element val)
Assign val to every element of the matrix diagonal.
Int_t GetNdiags() const
TElementPosActionT< Element > & operator=(const TElementPosActionT< Element > &)
const Element & operator[](Int_t i) const