Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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#include <initializer_list>
39
40template<class Element> class TVectorT;
41template<class Element> class TMatrixT;
42template<class Element> class TMatrixTSym;
43template<class Element> class TMatrixTSparse;
44
45//////////////////////////////////////////////////////////////////////////
46// //
47// TElementActionT //
48// //
49// A class to do a specific operation on every vector or matrix element //
50// (regardless of it position) as the object is being traversed. //
51// This is an abstract class. Derived classes need to implement the //
52// action function Operation(). //
53// //
54//////////////////////////////////////////////////////////////////////////
55
56template<class Element> class TElementActionT {
57
58friend class TMatrixTBase <Element>;
59friend class TMatrixT <Element>;
60friend class TMatrixTSym <Element>;
61friend class TMatrixTSparse<Element>;
62friend class TVectorT <Element>;
63
64protected:
65 virtual ~TElementActionT() { }
66 virtual void Operation(Element &element) const = 0;
67
68private:
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
84template<class Element> class TElementPosActionT {
85
86friend class TMatrixTBase <Element>;
87friend class TMatrixT <Element>;
88friend class TMatrixTSym <Element>;
89friend class TMatrixTSparse<Element>;
90friend class TVectorT <Element>;
91
92protected:
93 mutable Int_t fI; // i position of element being passed to Operation()
94 mutable Int_t fJ; // j position of element being passed to Operation()
95 virtual ~TElementPosActionT() { }
96 virtual void Operation(Element &element) const = 0;
97
98private:
100};
101
102//////////////////////////////////////////////////////////////////////////
103// //
104// TMatrixTRow_const //
105// //
106// Template class represents a row of a TMatrixT/TMatrixTSym //
107// //
108//////////////////////////////////////////////////////////////////////////
109
110template<class Element> class TMatrixTRow_const {
111
112protected:
113 const TMatrixTBase<Element> *fMatrix; // the matrix I am a row of
114 Int_t fRowInd; // effective row index
115 Int_t fInc; // if ptr = @a[row,i], then ptr+inc = @a[row,i+1]
116 const Element *fPtr; // pointer to the a[row,0]
117
118public:
119 TMatrixTRow_const() { fMatrix = nullptr; fRowInd = 0; fInc = 0; fPtr = nullptr; }
120 TMatrixTRow_const(const TMatrixT <Element> &matrix,Int_t row);
123 fMatrix(trc.fMatrix), fRowInd(trc.fRowInd), fInc(trc.fInc), fPtr(trc.fPtr) { }
125 if(this != &trc) { fMatrix=trc.fMatrix; fRowInd=trc.fRowInd; fInc=trc.fInc; fPtr=trc.fPtr; } return *this;}
126 virtual ~TMatrixTRow_const() { }
127
128 inline const TMatrixTBase<Element> *GetMatrix () const { return fMatrix; }
129 inline Int_t GetRowIndex() const { return fRowInd; }
130 inline Int_t GetInc () const { return fInc; }
131 inline const Element *GetPtr () const { return fPtr; }
132 inline const Element &operator ()(Int_t i) const {
134 R__ASSERT(fMatrix->IsValid());
135 const Int_t acoln = i-fMatrix->GetColLwb();
136 if (acoln < fMatrix->GetNcols() && acoln >= 0)
137 return fPtr[acoln];
138 else {
139 Error("operator()","Request col(%d) outside matrix range of %d - %d",
140 i,fMatrix->GetColLwb(),fMatrix->GetColLwb()+fMatrix->GetNcols());
142 }
143 }
144 inline const Element &operator [](Int_t i) const { return (*(const TMatrixTRow_const<Element> *)this)(i); }
145
146 ClassDef(TMatrixTRow_const,0) // Template of General Matrix Row Access class
147};
148
149template<class Element> class TMatrixTRow : public TMatrixTRow_const<Element> {
150
151public:
153 TMatrixTRow(TMatrixT <Element> &matrix,Int_t row);
156
157 inline Element *GetPtr() const { return const_cast<Element *>(this->fPtr); }
158
159 inline const Element &operator()(Int_t i) const {
160 if (!this->fMatrix) return TMatrixTBase<Element>::NaNValue();
161 R__ASSERT(this->fMatrix->IsValid());
162 const Int_t acoln = i-this->fMatrix->GetColLwb();
163 if (acoln < this->fMatrix->GetNcols() || acoln >= 0)
164 return (this->fPtr)[acoln];
165 else {
166 Error("operator()","Request col(%d) outside matrix range of %d - %d",
167 i,this->fMatrix->GetColLwb(),this->fMatrix->GetColLwb()+this->fMatrix->GetNcols());
169 }
170 }
171 inline Element &operator()(Int_t i) {
172 if (!this->fMatrix) return TMatrixTBase<Element>::NaNValue();
173 R__ASSERT(this->fMatrix->IsValid());
174 const Int_t acoln = i-this->fMatrix->GetColLwb();
175 if (acoln < this->fMatrix->GetNcols() && acoln >= 0)
176 return (const_cast<Element *>(this->fPtr))[acoln];
177 else {
178 Error("operator()","Request col(%d) outside matrix range of %d - %d",
179 i,this->fMatrix->GetColLwb(),this->fMatrix->GetColLwb()+this->fMatrix->GetNcols());
180 //return (const_cast<Element *>(this->fPtr))[0];
182 }
183 }
184 inline const Element &operator[](Int_t i) const { return (*(const TMatrixTRow<Element> *)this)(i); }
185 inline Element &operator[](Int_t i) { return (*( TMatrixTRow<Element> *)this)(i); }
186
187 void Assign (Element val);
188 void operator= (std::initializer_list<Element> l);
189 void operator+=(Element val);
190 void operator*=(Element val);
191
193 TMatrixTRow<Element>& operator=(const TMatrixTRow <Element> &r) { operator=((TMatrixTRow_const<Element> &)r); return *this;}
194 void operator=(const TVectorT <Element> &vec);
195
198
199 ClassDefOverride(TMatrixTRow,0) // Template of General Matrix Row Access class
200};
201
202//////////////////////////////////////////////////////////////////////////
203// //
204// TMatrixTColumn_const //
205// //
206// Template class represents a column of a TMatrixT/TMatrixTSym //
207// //
208//////////////////////////////////////////////////////////////////////////
209
210template<class Element> class TMatrixTColumn_const {
211
212protected:
213 const TMatrixTBase<Element> *fMatrix; // the matrix I am a column of
214 Int_t fColInd; // effective column index
215 Int_t fInc; // if ptr = @a[i,col], then ptr+inc = @a[i+1,col]
216 const Element *fPtr; // pointer to the a[0,col] column
217
218public:
219 TMatrixTColumn_const() { fMatrix = nullptr; fColInd = 0; fInc = 0; fPtr = nullptr; }
220 TMatrixTColumn_const(const TMatrixT <Element> &matrix,Int_t col);
223 fMatrix(trc.fMatrix), fColInd(trc.fColInd), fInc(trc.fInc), fPtr(trc.fPtr) { }
225 if(this != &trc) { fMatrix=trc.fMatrix; fColInd=trc.fColInd; fInc=trc.fInc; fPtr=trc.fPtr; } return *this;}
227
228 inline const TMatrixTBase <Element> *GetMatrix () const { return fMatrix; }
229 inline Int_t GetColIndex() const { return fColInd; }
230 inline Int_t GetInc () const { return fInc; }
231 inline const Element *GetPtr () const { return fPtr; }
232 inline const Element &operator ()(Int_t i) const {
233 if (!this->fMatrix) return TMatrixTBase<Element>::NaNValue();
234 R__ASSERT(fMatrix->IsValid());
235 const Int_t arown = i-fMatrix->GetRowLwb();
236 if (arown < fMatrix->GetNrows() && arown >= 0)
237 return fPtr[arown*fInc];
238 else {
239 Error("operator()","Request row(%d) outside matrix range of %d - %d",
240 i,fMatrix->GetRowLwb(),fMatrix->GetRowLwb()+fMatrix->GetNrows());
242 }
243 }
244 inline const Element &operator [](Int_t i) const { return (*(const TMatrixTColumn_const<Element> *)this)(i); }
245
246 ClassDef(TMatrixTColumn_const,0) // Template of General Matrix Column Access class
247};
248
249template<class Element> class TMatrixTColumn : public TMatrixTColumn_const<Element> {
250
251public:
253 TMatrixTColumn(TMatrixT <Element>&matrix,Int_t col);
255 TMatrixTColumn(const TMatrixTColumn <Element>&mc);
256
257 inline Element *GetPtr() const { return const_cast<Element *>(this->fPtr); }
258
259 inline const Element &operator()(Int_t i) const {
260 if (!this->fMatrix) return TMatrixTBase<Element>::NaNValue();
261 R__ASSERT(this->fMatrix->IsValid());
262 const Int_t arown = i-this->fMatrix->GetRowLwb();
263 if (arown < this->fMatrix->GetNrows() && arown >= 0)
264 return (this->fPtr)[arown*this->fInc];
265 else {
266 Error("operator()","Request row(%d) outside matrix range of %d - %d",
267 i,this->fMatrix->GetRowLwb(),this->fMatrix->GetRowLwb()+this->fMatrix->GetNrows());
269 }
270 }
271 inline Element &operator()(Int_t i) {
272 if (!this->fMatrix) return TMatrixTBase<Element>::NaNValue();
273 R__ASSERT(this->fMatrix->IsValid());
274 const Int_t arown = i-this->fMatrix->GetRowLwb();
275
276 if (arown < this->fMatrix->GetNrows() && arown >= 0)
277 return (const_cast<Element *>(this->fPtr))[arown*this->fInc];
278 else {
279 Error("operator()","Request row(%d) outside matrix range of %d - %d",
280 i,this->fMatrix->GetRowLwb(),this->fMatrix->GetRowLwb()+this->fMatrix->GetNrows());
282 }
283 }
284 inline const Element &operator[](Int_t i) const { return (*(const TMatrixTColumn<Element> *)this)(i); }
285 inline Element &operator[](Int_t i) { return (*( TMatrixTColumn<Element> *)this)(i); }
286
287 void Assign (Element val);
288 // keep it for backward compatibility (but it has been removed for TMatrixTRow)
289 void operator= (Element val) { return Assign(val); }
290 void operator= (std::initializer_list<Element> l);
291 void operator+=(Element val);
292 void operator*=(Element val);
293
295 TMatrixTColumn<Element>& operator=(const TMatrixTColumn <Element> &c) { operator=((TMatrixTColumn_const<Element> &)c); return *this;}
296 void operator=(const TVectorT <Element> &vec);
297
300
301 ClassDefOverride(TMatrixTColumn,0) // Template of General Matrix Column Access class
302};
303
304//////////////////////////////////////////////////////////////////////////
305// //
306// TMatrixTDiag_const //
307// //
308// Template class represents the diagonal of a TMatrixT/TMatrixTSym //
309// //
310//////////////////////////////////////////////////////////////////////////
311
312template<class Element> class TMatrixTDiag_const {
313
314protected:
315 const TMatrixTBase<Element> *fMatrix; // the matrix I am the diagonal of
316 Int_t fInc; // if ptr=@a[i,i], then ptr+inc = @a[i+1,i+1]
317 Int_t fNdiag; // number of diag elems, min(nrows,ncols)
318 const Element *fPtr; // pointer to the a[0,0]
319
320public:
321 TMatrixTDiag_const() { fMatrix = nullptr; fInc = 0; fNdiag = 0; fPtr = nullptr; }
322 TMatrixTDiag_const(const TMatrixT <Element> &matrix);
325 fMatrix(trc.fMatrix), fInc(trc.fInc), fNdiag(trc.fNdiag), fPtr(trc.fPtr) { }
327 if(this != &trc) { fMatrix=trc.fMatrix; fInc=trc.fInc; fNdiag=trc.fNdiag; fPtr=trc.fPtr; } return *this;}
329
330 inline const TMatrixTBase<Element> *GetMatrix() const { return fMatrix; }
331 inline const Element *GetPtr () const { return fPtr; }
332 inline Int_t GetInc () const { return fInc; }
333 inline const Element &operator ()(Int_t i) const {
334 R__ASSERT(fMatrix->IsValid());
335 if (i < fNdiag && i >= 0)
336 return fPtr[i*fInc];
337 else {
338 Error("operator()","Request diagonal(%d) outside matrix range of 0 - %d",i,fNdiag);
340 }
341 }
342 inline const Element &operator [](Int_t i) const { return (*(const TMatrixTDiag_const<Element> *)this)(i); }
343
344 Int_t GetNdiags() const { return fNdiag; }
345
346 ClassDef(TMatrixTDiag_const,0) // Template of General Matrix Diagonal Access class
347};
348
349template<class Element> class TMatrixTDiag : public TMatrixTDiag_const<Element> {
350
351public:
353 TMatrixTDiag(TMatrixT <Element>&matrix);
356
357 inline Element *GetPtr() const { return const_cast<Element *>(this->fPtr); }
358
359 inline const Element &operator()(Int_t i) const {
360 R__ASSERT(this->fMatrix->IsValid());
361 if (i < this->fNdiag && i >= 0)
362 return (this->fPtr)[i*this->fInc];
363 else {
364 Error("operator()","Request diagonal(%d) outside matrix range of 0 - %d",i,this->fNdiag);
366 }
367 }
368 inline Element &operator()(Int_t i) {
369 R__ASSERT(this->fMatrix->IsValid());
370 if (i < this->fNdiag && i >= 0)
371 return (const_cast<Element *>(this->fPtr))[i*this->fInc];
372 else {
373 Error("operator()","Request diagonal(%d) outside matrix range of 0 - %d",i,this->fNdiag);
374 return (const_cast<Element *>(this->fPtr))[0];
375 }
376 }
377 inline const Element &operator[](Int_t i) const { return (*(const TMatrixTDiag<Element> *)this)(i); }
378 inline Element &operator[](Int_t i) { return (*( TMatrixTDiag *)this)(i); }
379
380 void operator= (Element val);
381 void operator+=(Element val);
382 void operator*=(Element val);
383
385 TMatrixTDiag<Element>& operator=(const TMatrixTDiag <Element> &d) { operator=((TMatrixTDiag_const<Element> &)d); return *this;}
386 void operator=(const TVectorT <Element> &vec);
387
390
391 ClassDefOverride(TMatrixTDiag,0) // Template of General Matrix Diagonal Access class
392};
393
394//////////////////////////////////////////////////////////////////////////
395// //
396// TMatrixTFlat_const //
397// //
398// Template class represents a flat TMatrixT/TMatrixTSym //
399// //
400//////////////////////////////////////////////////////////////////////////
401
402template<class Element> class TMatrixTFlat_const {
403
404protected:
405 const TMatrixTBase<Element> *fMatrix; // the matrix I am the diagonal of
407 const Element *fPtr; // pointer to the a[0,0]
408
409public:
410 TMatrixTFlat_const() { fMatrix = nullptr; fNelems = 0; fPtr = nullptr; }
411 TMatrixTFlat_const(const TMatrixT <Element> &matrix);
414 fMatrix(trc.fMatrix), fNelems(trc.fNelems), fPtr(trc.fPtr) { }
416 if(this != &trc) { fMatrix=trc.fMatrix; fNelems=trc.fNelems; fPtr=trc.fPtr; } return *this;}
418
419 inline const TMatrixTBase<Element> *GetMatrix() const { return fMatrix; }
420 inline const Element *GetPtr () const { return fPtr; }
421 inline const Element &operator ()(Int_t i) const {
422 R__ASSERT(fMatrix->IsValid());
423 if (i < fNelems && i >= 0)
424 return fPtr[i];
425 else {
426 Error("operator()","Request element(%d) outside matrix range of 0 - %d",i,fNelems);
428 }
429 }
430 inline const Element &operator [](Int_t i) const { return (*(const TMatrixTFlat_const<Element> *)this)(i); }
431
432 ClassDef(TMatrixTFlat_const,0) // Template of General Matrix Flat Representation class
433};
434
435template<class Element> class TMatrixTFlat : public TMatrixTFlat_const<Element> {
436
437public:
439 TMatrixTFlat(TMatrixT <Element> &matrix);
442
443 inline Element *GetPtr() const { return const_cast<Element *>(this->fPtr); }
444
445 inline const Element &operator()(Int_t i) const {
446 R__ASSERT(this->fMatrix->IsValid());
447 if (i < this->fNelems && i >= 0)
448 return (this->fPtr)[i];
449 else {
450 Error("operator()","Request element(%d) outside matrix range of 0 - %d",i,this->fNelems);
452 }
453 }
454 inline Element &operator()(Int_t i) {
455 R__ASSERT(this->fMatrix->IsValid());
456 if (i < this->fNelems && i >= 0)
457 return (const_cast<Element *>(this->fPtr))[i];
458 else {
459 Error("operator()","Request element(%d) outside matrix range of 0 - %d",i,this->fNelems);
461 }
462 }
463 inline const Element &operator[](Int_t i) const { return (*(const TMatrixTFlat<Element> *)this)(i); }
464 inline Element &operator[](Int_t i) { return (*( TMatrixTFlat<Element> *)this)(i); }
465
466 void operator= (Element val);
467 void operator+=(Element val);
468 void operator*=(Element val);
469
471 TMatrixTFlat<Element>& operator=(const TMatrixTFlat <Element> &f) { operator=((TMatrixTFlat_const<Element> &)f); return *this;}
472 void operator=(const TVectorT <Element> &vec);
473
476
477 ClassDefOverride(TMatrixTFlat,0) // Template of General Matrix Flat Representation class
478};
479
480//////////////////////////////////////////////////////////////////////////
481// //
482// TMatrixTSub_const //
483// //
484// Template class represents a sub matrix of TMatrixT/TMatrixTSym //
485// //
486//////////////////////////////////////////////////////////////////////////
487
488template<class Element> class TMatrixTSub_const {
489
490protected:
491 const TMatrixTBase<Element> *fMatrix; // the matrix I am a submatrix of
496
497public:
499 TMatrixTSub_const(const TMatrixT <Element> &matrix,Int_t row_lwb,Int_t row_upb,Int_t col_lwb,Int_t col_upb);
500 TMatrixTSub_const(const TMatrixTSym<Element> &matrix,Int_t row_lwb,Int_t row_upb,Int_t col_lwb,Int_t col_upb);
501 virtual ~TMatrixTSub_const() { }
502
503 inline const TMatrixTBase<Element> *GetMatrix() const { return fMatrix; }
504 inline Int_t GetRowOff() const { return fRowOff; }
505 inline Int_t GetColOff() const { return fColOff; }
506 inline Int_t GetNrows () const { return fNrowsSub; }
507 inline Int_t GetNcols () const { return fNcolsSub; }
508 inline const Element &operator ()(Int_t rown,Int_t coln) const {
509 R__ASSERT(fMatrix->IsValid());
510
511 const Element *ptr = fMatrix->GetMatrixArray();
512 if (rown >= fNrowsSub || rown < 0) {
513 Error("operator()","Request row(%d) outside matrix range of 0 - %d",rown,fNrowsSub);
515 }
516 if (coln >= fNcolsSub || coln < 0) {
517 Error("operator()","Request column(%d) outside matrix range of 0 - %d",coln,fNcolsSub);
519 }
520 const Int_t index = (rown+fRowOff)*fMatrix->GetNcols()+coln+fColOff;
521 return ptr[index];
522 }
523
524 ClassDef(TMatrixTSub_const,0) // Template of Sub Matrix Access class
525};
526
527template<class Element> class TMatrixTSub : public TMatrixTSub_const<Element> {
528
529public:
530
531 enum {kWorkMax = 100};
532
534 TMatrixTSub(TMatrixT <Element> &matrix,Int_t row_lwb,Int_t row_upb,Int_t col_lwb,Int_t col_upb);
535 TMatrixTSub(TMatrixTSym<Element> &matrix,Int_t row_lwb,Int_t row_upb,Int_t col_lwb,Int_t col_upb);
537
538 inline Element &operator()(Int_t rown,Int_t coln) {
539 R__ASSERT(this->fMatrix->IsValid());
540
541 const Element *ptr = this->fMatrix->GetMatrixArray();
542 if (rown >= this->fNrowsSub || rown < 0) {
543 Error("operator()","Request row(%d) outside matrix range of 0 - %d",rown,this->fNrowsSub);
545 }
546 if (coln >= this->fNcolsSub || coln < 0) {
547 Error("operator()","Request column(%d) outside matrix range of 0 - %d",coln,this->fNcolsSub);
549 }
550 const Int_t index = (rown+this->fRowOff)*this->fMatrix->GetNcols()+coln+this->fColOff;
551 return (const_cast<Element *>(ptr))[index];
552 }
553
554 void Rank1Update(const TVectorT<Element> &vec,Element alpha=1.0);
555
556 void operator= (Element val);
557 void operator+=(Element val);
558 void operator*=(Element val);
559
561 TMatrixTSub<Element>& operator=(const TMatrixTSub <Element> &s) { operator=((TMatrixTSub_const<Element> &)s); return *this;}
562 void operator=(const TMatrixTBase <Element> &m);
563
566 void operator+=(const TMatrixTBase <Element> &m);
567 void operator*=(const TMatrixT <Element> &m);
568 void operator*=(const TMatrixTSym <Element> &m);
569
570 ClassDefOverride(TMatrixTSub,0) // Template of Sub Matrix Access class
571};
572
573//////////////////////////////////////////////////////////////////////////
574// //
575// TMatrixTSparseRow_const //
576// //
577// Template class represents a row of TMatrixTSparse //
578// //
579//////////////////////////////////////////////////////////////////////////
580
581template<class Element> class TMatrixTSparseRow_const {
582
583protected:
584 const TMatrixTSparse<Element> *fMatrix; // the matrix I am a row of
585 Int_t fRowInd; // effective row index
586 Int_t fNindex; // index range
587 const Int_t *fColPtr; // column index pointer
588 const Element *fDataPtr; // data pointer
589
590public:
591 TMatrixTSparseRow_const() { fMatrix = nullptr; fRowInd = 0; fNindex = 0; fColPtr = nullptr; fDataPtr = nullptr; }
596 if(this != &trc) { fMatrix=trc.fMatrix; fRowInd=trc.fRowInd; fNindex=trc.fNindex; fColPtr=trc.fColPtr; fDataPtr=trc.fDataPtr; } return *this;}
598
599 inline const TMatrixTBase<Element> *GetMatrix () const { return fMatrix; }
600 inline const Element *GetDataPtr () const { return fDataPtr; }
601 inline const Int_t *GetColPtr () const { return fColPtr; }
602 inline Int_t GetRowIndex() const { return fRowInd; }
603 inline Int_t GetNindex () const { return fNindex; }
604
605 Element operator()(Int_t i) const;
606 inline Element operator[](Int_t i) const { return (*(const TMatrixTSparseRow_const<Element> *)this)(i); }
607
608 ClassDef(TMatrixTSparseRow_const,0) // Template of Sparse Matrix Row Access class
609};
610
611template<class Element> class TMatrixTSparseRow : public TMatrixTSparseRow_const<Element> {
612
613public:
617
618 inline Element *GetDataPtr() const { return const_cast<Element *>(this->fDataPtr); }
619
620 Element operator()(Int_t i) const;
621 Element &operator()(Int_t i);
622 inline Element operator[](Int_t i) const { return (*(const TMatrixTSparseRow<Element> *)this)(i); }
623 inline Element &operator[](Int_t i) { return (*(TMatrixTSparseRow<Element> *)this)(i); }
624
625 void operator= (Element val);
626 void operator+=(Element val);
627 void operator*=(Element val);
628
630 TMatrixTSparseRow<Element>& operator=(const TMatrixTSparseRow <Element> &r) { operator=((TMatrixTSparseRow_const<Element> &)r); return *this;}
631 void operator=(const TVectorT <Element> &vec);
632
635
636 ClassDefOverride(TMatrixTSparseRow,0) // Template of Sparse Matrix Row Access class
637};
638
639//////////////////////////////////////////////////////////////////////////
640// //
641// TMatrixTSparseDiag_const //
642// //
643// Template class represents the diagonal of TMatrixTSparse //
644// //
645//////////////////////////////////////////////////////////////////////////
646
647template<class Element> class TMatrixTSparseDiag_const {
648
649protected:
650 const TMatrixTSparse<Element> *fMatrix; // the matrix I am the diagonal of
651 Int_t fNdiag; // number of diag elems, min(nrows,ncols)
652 const Element *fDataPtr; // data pointer
653
654public:
655 TMatrixTSparseDiag_const() { fMatrix = nullptr; fNdiag = 0; fDataPtr = nullptr; }
658 fMatrix(trc.fMatrix), fNdiag(trc.fNdiag), fDataPtr(trc.fDataPtr) { }
660 if(this != &trc) { fMatrix=trc.fMatrix; fNdiag=trc.fNdiag; fDataPtr=trc.fDataPtr; } return *this;}
662
663 inline const TMatrixTBase<Element> *GetMatrix () const { return fMatrix; }
664 inline const Element *GetDataPtr() const { return fDataPtr; }
665 inline Int_t GetNdiags () const { return fNdiag; }
666
667 Element operator ()(Int_t i) const;
668 inline Element operator [](Int_t i) const { return (*(const TMatrixTSparseRow_const<Element> *)this)(i); }
669
670 ClassDef(TMatrixTSparseDiag_const,0) // Template of Sparse Matrix Diagonal Access class
671};
672
673template<class Element> class TMatrixTSparseDiag : public TMatrixTSparseDiag_const<Element> {
674
675public:
679
680 inline Element *GetDataPtr() const { return const_cast<Element *>(this->fDataPtr); }
681
682 Element operator()(Int_t i) const;
683 Element &operator()(Int_t i);
684 inline Element operator[](Int_t i) const { return (*(const TMatrixTSparseDiag<Element> *)this)(i); }
685 inline Element &operator[](Int_t i) { return (*(TMatrixTSparseDiag<Element> *)this)(i); }
686
687 void operator= (Element val);
688 void operator+=(Element val);
689 void operator*=(Element val);
690
692 TMatrixTSparseDiag<Element>& operator=(const TMatrixTSparseDiag <Element> &d) { operator=((TMatrixTSparseDiag_const<Element> &)d); return *this;}
693 void operator=(const TVectorT <Element> &vec);
694
697
698 ClassDefOverride(TMatrixTSparseDiag,0) // Template of Sparse Matrix Diagonal Access class
699};
700
702#endif
#define d(i)
Definition RSha256.hxx:102
#define f(i)
Definition RSha256.hxx:104
#define c(i)
Definition RSha256.hxx:101
int Int_t
Definition RtypesCore.h:45
#define ClassDef(name, id)
Definition Rtypes.h:337
#define ClassDefOverride(name, id)
Definition Rtypes.h:341
#define R__ASSERT(e)
Definition TError.h:118
void Error(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
Definition TError.cxx:185
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t r
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t index
Double_t Drand(Double_t &ix)
Random number generator [0....1] with seed ix.
TElementActionT & operator=(const TElementActionT< Element > &)
virtual ~TElementActionT()
virtual void Operation(Element &element) const =0
virtual ~TElementPosActionT()
TElementPosActionT< Element > & operator=(const TElementPosActionT< Element > &)
virtual void Operation(Element &element) const =0
TMatrixTBase.
static Element & NaNValue()
const TMatrixTBase< Element > * fMatrix
Int_t GetColIndex() const
const Element & operator[](Int_t i) const
TMatrixTColumn_const(const TMatrixTColumn_const< Element > &trc)
const TMatrixTBase< Element > * GetMatrix() const
virtual ~TMatrixTColumn_const()
const Element * fPtr
const Element & operator()(Int_t i) const
TMatrixTColumn_const< Element > & operator=(const TMatrixTColumn_const< Element > &trc)
const Element * GetPtr() const
void operator+=(Element val)
Add val to every element of the matrix column.
Element & operator[](Int_t i)
const Element & operator[](Int_t i) const
Element & operator()(Int_t i)
TMatrixTColumn< Element > & operator=(const TMatrixTColumn< Element > &c)
Element * GetPtr() const
void operator=(Element val)
void Assign(Element val)
Assign val to every element of the matrix column.
const Element & operator()(Int_t i) const
void operator*=(Element val)
Multiply every element of the matrix column with val.
TMatrixTDiag_const(const TMatrixTDiag_const< Element > &trc)
TMatrixTDiag_const< Element > & operator=(const TMatrixTDiag_const< Element > &trc)
const Element * GetPtr() const
virtual ~TMatrixTDiag_const()
const Element & operator()(Int_t i) const
Int_t GetNdiags() const
const Element & operator[](Int_t i) const
const TMatrixTBase< Element > * GetMatrix() const
const Element * fPtr
const TMatrixTBase< Element > * fMatrix
Int_t GetInc() const
Element & operator[](Int_t i)
Element & operator()(Int_t i)
void operator+=(Element val)
Assign val to every element of the matrix diagonal.
void operator=(Element val)
Assign val to every element of the matrix diagonal.
const Element & operator[](Int_t i) const
const Element & operator()(Int_t i) const
TMatrixTDiag< Element > & operator=(const TMatrixTDiag< Element > &d)
Element * GetPtr() const
void operator*=(Element val)
Assign val to every element of the matrix diagonal.
const Element & operator[](Int_t i) const
const TMatrixTBase< Element > * fMatrix
TMatrixTFlat_const< Element > & operator=(const TMatrixTFlat_const< Element > &trc)
const Element * fPtr
const TMatrixTBase< Element > * GetMatrix() const
const Element * GetPtr() const
const Element & operator()(Int_t i) const
virtual ~TMatrixTFlat_const()
TMatrixTFlat_const(const TMatrixTFlat_const< Element > &trc)
void operator+=(Element val)
Add val to every element of the matrix.
Element & operator[](Int_t i)
TMatrixTFlat< Element > & operator=(const TMatrixTFlat< Element > &f)
const Element & operator[](Int_t i) const
Element * GetPtr() const
Element & operator()(Int_t i)
const Element & operator()(Int_t i) const
void operator*=(Element val)
Multiply every element of the matrix with val.
void operator=(Element val)
Assign val to every element of the matrix.
TMatrixTRow_const(const TMatrixTRow_const< Element > &trc)
virtual ~TMatrixTRow_const()
TMatrixTRow_const< Element > & operator=(const TMatrixTRow_const< Element > &trc)
const Element * GetPtr() const
const Element * fPtr
const Element & operator()(Int_t i) const
Int_t GetInc() const
Int_t GetRowIndex() const
const TMatrixTBase< Element > * fMatrix
const TMatrixTBase< Element > * GetMatrix() const
const Element & operator[](Int_t i) const
const Element & operator[](Int_t i) const
void Assign(Element val)
Assign val to every element of the matrix row.
TMatrixTRow< Element > & operator=(const TMatrixTRow< Element > &r)
const Element & operator()(Int_t i) const
void operator*=(Element val)
Multiply every element of the matrix row with val.
void operator+=(Element val)
Add val to every element of the matrix row.
void operator=(std::initializer_list< Element > l)
Element * GetPtr() const
Element & operator()(Int_t i)
Element & operator[](Int_t i)
const Element * GetDataPtr() const
Element operator()(Int_t i) const
const TMatrixTSparse< Element > * fMatrix
const TMatrixTBase< Element > * GetMatrix() const
TMatrixTSparseDiag_const< Element > & operator=(const TMatrixTSparseDiag_const< Element > &trc)
Element operator[](Int_t i) const
TMatrixTSparseDiag_const(const TMatrixTSparseDiag_const< Element > &trc)
Element & operator[](Int_t i)
Element operator[](Int_t i) const
Element operator()(Int_t i) const
TMatrixTSparseDiag< Element > & operator=(const TMatrixTSparseDiag< Element > &d)
void operator=(Element val)
Assign val to every element of the matrix diagonal.
void operator*=(Element val)
Multiply every element of the matrix diagonal by val.
void operator+=(Element val)
Add val to every element of the matrix diagonal.
Element * GetDataPtr() const
const Int_t * GetColPtr() const
TMatrixTSparseRow_const(const TMatrixTSparseRow_const< Element > &trc)
Element operator[](Int_t i) const
const Element * GetDataPtr() const
const TMatrixTSparse< Element > * fMatrix
TMatrixTSparseRow_const< Element > & operator=(const TMatrixTSparseRow_const< Element > &trc)
Element operator()(Int_t i) const
const Element * fDataPtr
const TMatrixTBase< Element > * GetMatrix() const
void operator+=(Element val)
Add val to every non-zero (!) element of the matrix row.
void operator=(Element val)
Assign val to every non-zero (!) element of the matrix row.
Element & operator[](Int_t i)
Element operator[](Int_t i) const
Element * GetDataPtr() const
void operator*=(Element val)
Multiply every element of the matrix row by val.
Element operator()(Int_t i) const
TMatrixTSparseRow< Element > & operator=(const TMatrixTSparseRow< Element > &r)
TMatrixTSparse.
const TMatrixTBase< Element > * fMatrix
virtual ~TMatrixTSub_const()
Int_t GetNcols() const
const TMatrixTBase< Element > * GetMatrix() const
Int_t GetNrows() const
const Element & operator()(Int_t rown, Int_t coln) const
Int_t GetRowOff() const
Int_t GetColOff() const
void Rank1Update(const TVectorT< Element > &vec, Element alpha=1.0)
Perform a rank 1 operation on the matrix: A += alpha * v * v^T.
void operator*=(Element val)
Multiply every element of the sub matrix by val .
Element & operator()(Int_t rown, Int_t coln)
void operator+=(Element val)
Add val to every element of the sub matrix.
void operator=(Element val)
Assign val to every element of the sub matrix.
TMatrixTSub< Element > & operator=(const TMatrixTSub< Element > &s)
TMatrixTSym.
Definition TMatrixTSym.h:34
TMatrixT.
Definition TMatrixT.h:39
TVectorT.
Definition TVectorT.h:27
TMarker m
Definition textangle.C:8
TLine l
Definition textangle.C:4