// @(#)root/matrix:$Id: TMatrixTUtils.h 20882 2007-11-19 11:31:26Z rdm $ // Authors: Fons Rademakers, Eddy Offermann Nov 2003 /************************************************************************* * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. * * All rights reserved. * * * * For the licensing terms see $ROOTSYS/LICENSE. * * For the list of contributors see $ROOTSYS/README/CREDITS. * *************************************************************************/ #ifndef ROOT_TMatrixTUtils #define ROOT_TMatrixTUtils ////////////////////////////////////////////////////////////////////////// // // // Matrix utility classes. // // // // Templates of utility classes in the Linear Algebra Package. // // The following classes are defined here: // // // // Different matrix views without copying data elements : // // TMatrixTRow_const TMatrixTRow // // TMatrixTColumn_const TMatrixTColumn // // TMatrixTDiag_const TMatrixTDiag // // TMatrixTFlat_const TMatrixTFlat // // TMatrixTSub_const TMatrixTSub // // TMatrixTSparseRow_const TMatrixTSparseRow // // TMatrixTSparseDiag_const TMatrixTSparseDiag // // // // TElementActionT // // TElementPosActionT // // // ////////////////////////////////////////////////////////////////////////// #ifndef ROOT_TMatrixTBase #include "TMatrixTBase.h" #endif template class TVectorT; template class TMatrixT; template class TMatrixTSym; template class TMatrixTSparse; ////////////////////////////////////////////////////////////////////////// // // // TElementActionT // // // // A class to do a specific operation on every vector or matrix element // // (regardless of it position) as the object is being traversed. // // This is an abstract class. Derived classes need to implement the // // action function Operation(). // // // ////////////////////////////////////////////////////////////////////////// template class TElementActionT { #ifndef __CINT__ friend class TMatrixTBase ; friend class TMatrixT ; friend class TMatrixTSym ; friend class TMatrixTSparse; friend class TVectorT ; #endif protected: virtual ~TElementActionT() { } virtual void Operation(Element &element) const = 0; private: TElementActionT& operator=(const TElementActionT &) {return *this;} }; ////////////////////////////////////////////////////////////////////////// // // // TElementPosActionT // // // // A class to do a specific operation on every vector or matrix element // // as the object is being traversed. This is an abstract class. // // Derived classes need to implement the action function Operation(). // // In the action function the location of the current element is // // known (fI=row, fJ=columns). // // // ////////////////////////////////////////////////////////////////////////// template class TElementPosActionT { #ifndef __CINT__ friend class TMatrixTBase ; friend class TMatrixT ; friend class TMatrixTSym ; friend class TMatrixTSparse; friend class TVectorT ; #endif protected: mutable Int_t fI; // i position of element being passed to Operation() mutable Int_t fJ; // j position of element being passed to Operation() virtual ~TElementPosActionT() { } virtual void Operation(Element &element) const = 0; private: TElementPosActionT& operator=(const TElementPosActionT &) {return *this;} }; ////////////////////////////////////////////////////////////////////////// // // // TMatrixTRow_const // // // // Template class represents a row of a TMatrixT/TMatrixTSym // // // ////////////////////////////////////////////////////////////////////////// template class TMatrixTRow_const { protected: const TMatrixTBase *fMatrix; // the matrix I am a row of Int_t fRowInd; // effective row index Int_t fInc; // if ptr = @a[row,i], then ptr+inc = @a[row,i+1] const Element *fPtr; // pointer to the a[row,0] public: TMatrixTRow_const() { fMatrix = 0; fInc = 0; fPtr = 0; } TMatrixTRow_const(const TMatrixT &matrix,Int_t row); TMatrixTRow_const(const TMatrixTSym &matrix,Int_t row); TMatrixTRow_const(const TMatrixTRow_const& trc): fMatrix(trc.fMatrix), fRowInd(trc.fRowInd), fInc(trc.fInc), fPtr(trc.fPtr) { } TMatrixTRow_const& operator=(const TMatrixTRow_const& trc) { fMatrix=trc.fMatrix; fRowInd=trc.fRowInd; fInc=trc.fInc; fPtr=trc.fPtr; return *this;} virtual ~TMatrixTRow_const() { } inline const TMatrixTBase *GetMatrix () const { return fMatrix; } inline Int_t GetRowIndex() const { return fRowInd; } inline Int_t GetInc () const { return fInc; } inline const Element *GetPtr () const { return fPtr; } inline const Element &operator ()(Int_t i) const { R__ASSERT(fMatrix->IsValid()); const Int_t acoln = i-fMatrix->GetColLwb(); if (acoln < fMatrix->GetNcols() && acoln >= 0) return fPtr[acoln]; else { Error("operator()","Request col(%d) outside matrix range of %d - %d", i,fMatrix->GetColLwb(),fMatrix->GetColLwb()+fMatrix->GetNcols()); return fPtr[0]; } } inline const Element &operator [](Int_t i) const { return (*(const TMatrixTRow_const *)this)(i); } ClassDef(TMatrixTRow_const,0) // Template of General Matrix Row Access class }; template class TMatrixTRow : public TMatrixTRow_const { public: TMatrixTRow() {} TMatrixTRow(TMatrixT &matrix,Int_t row); TMatrixTRow(TMatrixTSym &matrix,Int_t row); TMatrixTRow(const TMatrixTRow &mr); inline Element *GetPtr() const { return const_cast(this->fPtr); } inline const Element &operator()(Int_t i) const { R__ASSERT(this->fMatrix->IsValid()); const Int_t acoln = i-this->fMatrix->GetColLwb(); if (acoln < this->fMatrix->GetNcols() || acoln >= 0) return (this->fPtr)[acoln]; else { Error("operator()","Request col(%d) outside matrix range of %d - %d", i,this->fMatrix->GetColLwb(),this->fMatrix->GetColLwb()+this->fMatrix->GetNcols()); return (this->fPtr)[0]; } } inline Element &operator()(Int_t i) { R__ASSERT(this->fMatrix->IsValid()); const Int_t acoln = i-this->fMatrix->GetColLwb(); if (acoln < this->fMatrix->GetNcols() && acoln >= 0) return (const_cast(this->fPtr))[acoln]; else { Error("operator()","Request col(%d) outside matrix range of %d - %d", i,this->fMatrix->GetColLwb(),this->fMatrix->GetColLwb()+this->fMatrix->GetNcols()); return (const_cast(this->fPtr))[0]; } } inline const Element &operator[](Int_t i) const { return (*(const TMatrixTRow *)this)(i); } inline Element &operator[](Int_t i) { return (*( TMatrixTRow *)this)(i); } void operator= (Element val); void operator+=(Element val); void operator*=(Element val); void operator=(const TMatrixTRow_const &r); TMatrixTRow& operator=(const TMatrixTRow &r) { operator=((TMatrixTRow_const &)r); return *this;} void operator=(const TVectorT &vec); void operator+=(const TMatrixTRow_const &r); void operator*=(const TMatrixTRow_const &r); ClassDef(TMatrixTRow,0) // Template of General Matrix Row Access class }; ////////////////////////////////////////////////////////////////////////// // // // TMatrixTColumn_const // // // // Template class represents a column of a TMatrixT/TMatrixTSym // // // ////////////////////////////////////////////////////////////////////////// template class TMatrixTColumn_const { protected: const TMatrixTBase *fMatrix; // the matrix I am a column of Int_t fColInd; // effective column index Int_t fInc; // if ptr = @a[i,col], then ptr+inc = @a[i+1,col] const Element *fPtr; // pointer to the a[0,col] column public: TMatrixTColumn_const() { fMatrix = 0; fInc = 0; fPtr = 0; } TMatrixTColumn_const(const TMatrixT &matrix,Int_t col); TMatrixTColumn_const(const TMatrixTSym &matrix,Int_t col); TMatrixTColumn_const(const TMatrixTColumn_const& trc): fMatrix(trc.fMatrix), fColInd(trc.fColInd), fInc(trc.fInc), fPtr(trc.fPtr) { } TMatrixTColumn_const& operator=(const TMatrixTColumn_const& trc) { fMatrix=trc.fMatrix; fColInd=trc.fColInd; fInc=trc.fInc; fPtr=trc.fPtr; return *this;} virtual ~TMatrixTColumn_const() { } inline const TMatrixTBase *GetMatrix () const { return fMatrix; } inline Int_t GetColIndex() const { return fColInd; } inline Int_t GetInc () const { return fInc; } inline const Element *GetPtr () const { return fPtr; } inline const Element &operator ()(Int_t i) const { R__ASSERT(fMatrix->IsValid()); const Int_t arown = i-fMatrix->GetRowLwb(); if (arown < fMatrix->GetNrows() && arown >= 0) return fPtr[arown*fInc]; else { Error("operator()","Request row(%d) outside matrix range of %d - %d", i,fMatrix->GetRowLwb(),fMatrix->GetRowLwb()+fMatrix->GetNrows()); return fPtr[0]; } } inline const Element &operator [](Int_t i) const { return (*(const TMatrixTColumn_const *)this)(i); } ClassDef(TMatrixTColumn_const,0) // Template of General Matrix Column Access class }; template class TMatrixTColumn : public TMatrixTColumn_const { public: TMatrixTColumn() {} TMatrixTColumn(TMatrixT &matrix,Int_t col); TMatrixTColumn(TMatrixTSym&matrix,Int_t col); TMatrixTColumn(const TMatrixTColumn &mc); inline Element *GetPtr() const { return const_cast(this->fPtr); } inline const Element &operator()(Int_t i) const { R__ASSERT(this->fMatrix->IsValid()); const Int_t arown = i-this->fMatrix->GetRowLwb(); if (arown < this->fMatrix->GetNrows() && arown >= 0) return (this->fPtr)[arown*this->fInc]; else { Error("operator()","Request row(%d) outside matrix range of %d - %d", i,this->fMatrix->GetRowLwb(),this->fMatrix->GetRowLwb()+this->fMatrix->GetNrows()); return (this->fPtr)[0]; } } inline Element &operator()(Int_t i) { R__ASSERT(this->fMatrix->IsValid()); const Int_t arown = i-this->fMatrix->GetRowLwb(); R__ASSERT(arown < this->fMatrix->GetNrows() && arown >= 0); return (const_cast(this->fPtr))[arown*this->fInc]; if (arown < this->fMatrix->GetNrows() && arown >= 0) return (const_cast(this->fPtr))[arown*this->fInc]; else { Error("operator()","Request row(%d) outside matrix range of %d - %d", i,this->fMatrix->GetRowLwb(),this->fMatrix->GetRowLwb()+this->fMatrix->GetNrows()); return (const_cast(this->fPtr))[0]; } } inline const Element &operator[](Int_t i) const { return (*(const TMatrixTColumn *)this)(i); } inline Element &operator[](Int_t i) { return (*( TMatrixTColumn *)this)(i); } void operator= (Element val); void operator+=(Element val); void operator*=(Element val); void operator=(const TMatrixTColumn_const &c); TMatrixTColumn& operator=(const TMatrixTColumn &c) { operator=((TMatrixTColumn_const &)c); return *this;} void operator=(const TVectorT &vec); void operator+=(const TMatrixTColumn_const &c); void operator*=(const TMatrixTColumn_const &c); ClassDef(TMatrixTColumn,0) // Template of General Matrix Column Access class }; ////////////////////////////////////////////////////////////////////////// // // // TMatrixTDiag_const // // // // Template class represents the diagonal of a TMatrixT/TMatrixTSym // // // ////////////////////////////////////////////////////////////////////////// template class TMatrixTDiag_const { protected: const TMatrixTBase *fMatrix; // the matrix I am the diagonal of Int_t fInc; // if ptr=@a[i,i], then ptr+inc = @a[i+1,i+1] Int_t fNdiag; // number of diag elems, min(nrows,ncols) const Element *fPtr; // pointer to the a[0,0] public: TMatrixTDiag_const() { fMatrix = 0; fInc = 0; fNdiag = 0; fPtr = 0; } TMatrixTDiag_const(const TMatrixT &matrix); TMatrixTDiag_const(const TMatrixTSym &matrix); TMatrixTDiag_const(const TMatrixTDiag_const& trc): fMatrix(trc.fMatrix), fInc(trc.fInc), fNdiag(trc.fNdiag), fPtr(trc.fPtr) { } TMatrixTDiag_const& operator=(const TMatrixTDiag_const& trc) { fMatrix=trc.fMatrix; fInc=trc.fInc; fNdiag=trc.fNdiag; fPtr=trc.fPtr; return *this;} virtual ~TMatrixTDiag_const() { } inline const TMatrixTBase *GetMatrix() const { return fMatrix; } inline const Element *GetPtr () const { return fPtr; } inline Int_t GetInc () const { return fInc; } inline const Element &operator ()(Int_t i) const { R__ASSERT(fMatrix->IsValid()); if (i < fNdiag && i >= 0) return fPtr[i*fInc]; else { Error("operator()","Request diagonal(%d) outside matrix range of 0 - %d",i,fNdiag); return fPtr[0]; } } inline const Element &operator [](Int_t i) const { return (*(const TMatrixTDiag_const *)this)(i); } Int_t GetNdiags() const { return fNdiag; } ClassDef(TMatrixTDiag_const,0) // Template of General Matrix Diagonal Access class }; template class TMatrixTDiag : public TMatrixTDiag_const { public: TMatrixTDiag() {} TMatrixTDiag(TMatrixT &matrix); TMatrixTDiag(TMatrixTSym&matrix); TMatrixTDiag(const TMatrixTDiag &md); inline Element *GetPtr() const { return const_cast(this->fPtr); } inline const Element &operator()(Int_t i) const { R__ASSERT(this->fMatrix->IsValid()); if (i < this->fNdiag && i >= 0) return (this->fPtr)[i*this->fInc]; else { Error("operator()","Request diagonal(%d) outside matrix range of 0 - %d",i,this->fNdiag); return (this->fPtr)[0]; } } inline Element &operator()(Int_t i) { R__ASSERT(this->fMatrix->IsValid()); if (i < this->fNdiag && i >= 0) return (const_cast(this->fPtr))[i*this->fInc]; else { Error("operator()","Request diagonal(%d) outside matrix range of 0 - %d",i,this->fNdiag); return (const_cast(this->fPtr))[0]; } } inline const Element &operator[](Int_t i) const { return (*(const TMatrixTDiag *)this)(i); } inline Element &operator[](Int_t i) { return (*( TMatrixTDiag *)this)(i); } void operator= (Element val); void operator+=(Element val); void operator*=(Element val); void operator=(const TMatrixTDiag_const &d); TMatrixTDiag& operator=(const TMatrixTDiag &d) { operator=((TMatrixTDiag_const &)d); return *this;} void operator=(const TVectorT &vec); void operator+=(const TMatrixTDiag_const &d); void operator*=(const TMatrixTDiag_const &d); ClassDef(TMatrixTDiag,0) // Template of General Matrix Diagonal Access class }; ////////////////////////////////////////////////////////////////////////// // // // TMatrixTFlat_const // // // // Template class represents a flat TMatrixT/TMatrixTSym // // // ////////////////////////////////////////////////////////////////////////// template class TMatrixTFlat_const { protected: const TMatrixTBase *fMatrix; // the matrix I am the diagonal of Int_t fNelems; // const Element *fPtr; // pointer to the a[0,0] public: TMatrixTFlat_const() { fMatrix = 0; fNelems = 0; fPtr = 0; } TMatrixTFlat_const(const TMatrixT &matrix); TMatrixTFlat_const(const TMatrixTSym &matrix); TMatrixTFlat_const(const TMatrixTFlat_const& trc): fMatrix(trc.fMatrix), fNelems(trc.fNelems), fPtr(trc.fPtr) { } TMatrixTFlat_const& operator=(const TMatrixTFlat_const& trc) { fMatrix=trc.fMatrix; fNelems=trc.fNelems; fPtr=trc.fPtr; return *this;} virtual ~TMatrixTFlat_const() { } inline const TMatrixTBase *GetMatrix() const { return fMatrix; } inline const Element *GetPtr () const { return fPtr; } inline const Element &operator ()(Int_t i) const { R__ASSERT(fMatrix->IsValid()); if (i < fNelems && i >= 0) return fPtr[i]; else { Error("operator()","Request element(%d) outside matrix range of 0 - %d",i,fNelems); return fPtr[0]; } } inline const Element &operator [](Int_t i) const { return (*(const TMatrixTFlat_const *)this)(i); } ClassDef(TMatrixTFlat_const,0) // Template of General Matrix Flat Representation class }; template class TMatrixTFlat : public TMatrixTFlat_const { public: TMatrixTFlat() {} TMatrixTFlat(TMatrixT &matrix); TMatrixTFlat(TMatrixTSym &matrix); TMatrixTFlat(const TMatrixTFlat &mf); inline Element *GetPtr() const { return const_cast(this->fPtr); } inline const Element &operator()(Int_t i) const { R__ASSERT(this->fMatrix->IsValid()); if (i < this->fNelems && i >= 0) return (this->fPtr)[i]; else { Error("operator()","Request element(%d) outside matrix range of 0 - %d",i,this->fNelems); return (this->fPtr)[0]; } } inline Element &operator()(Int_t i) { R__ASSERT(this->fMatrix->IsValid()); if (i < this->fNelems && i >= 0) return (const_cast(this->fPtr))[i]; else { Error("operator()","Request element(%d) outside matrix range of 0 - %d",i,this->fNelems); return (const_cast(this->fPtr))[0]; } } inline const Element &operator[](Int_t i) const { return (*(const TMatrixTFlat *)this)(i); } inline Element &operator[](Int_t i) { return (*( TMatrixTFlat *)this)(i); } void operator= (Element val); void operator+=(Element val); void operator*=(Element val); void operator=(const TMatrixTFlat_const &f); TMatrixTFlat& operator=(const TMatrixTFlat &f) { operator=((TMatrixTFlat_const &)f); return *this;} void operator=(const TVectorT &vec); void operator+=(const TMatrixTFlat_const &f); void operator*=(const TMatrixTFlat_const &f); ClassDef(TMatrixTFlat,0) // Template of General Matrix Flat Representation class }; ////////////////////////////////////////////////////////////////////////// // // // TMatrixTSub_const // // // // Template class represents a sub matrix of TMatrixT/TMatrixTSym // // // ////////////////////////////////////////////////////////////////////////// template class TMatrixTSub_const { protected: const TMatrixTBase *fMatrix; // the matrix I am a submatrix of Int_t fRowOff; // Int_t fColOff; // Int_t fNrowsSub; // Int_t fNcolsSub; // public: TMatrixTSub_const() { fRowOff = fColOff = fNrowsSub = fNcolsSub = 0; fMatrix = 0; } TMatrixTSub_const(const TMatrixT &matrix,Int_t row_lwb,Int_t row_upb,Int_t col_lwb,Int_t col_upb); TMatrixTSub_const(const TMatrixTSym &matrix,Int_t row_lwb,Int_t row_upb,Int_t col_lwb,Int_t col_upb); virtual ~TMatrixTSub_const() { } inline const TMatrixTBase *GetMatrix() const { return fMatrix; } inline Int_t GetRowOff() const { return fRowOff; } inline Int_t GetColOff() const { return fColOff; } inline Int_t GetNrows () const { return fNrowsSub; } inline Int_t GetNcols () const { return fNcolsSub; } inline const Element &operator ()(Int_t rown,Int_t coln) const { R__ASSERT(fMatrix->IsValid()); const Element *ptr = fMatrix->GetMatrixArray(); if (rown >= fNrowsSub || rown < 0) { Error("operator()","Request row(%d) outside matrix range of 0 - %d",rown,fNrowsSub); return ptr[0]; } if (coln >= fNcolsSub || coln < 0) { Error("operator()","Request column(%d) outside matrix range of 0 - %d",coln,fNcolsSub); return ptr[0]; } const Int_t index = (rown+fRowOff)*fMatrix->GetNcols()+coln+fColOff; return ptr[index]; } ClassDef(TMatrixTSub_const,0) // Template of Sub Matrix Access class }; template class TMatrixTSub : public TMatrixTSub_const { public: enum {kWorkMax = 100}; TMatrixTSub() {} TMatrixTSub(TMatrixT &matrix,Int_t row_lwb,Int_t row_upb,Int_t col_lwb,Int_t col_upb); TMatrixTSub(TMatrixTSym &matrix,Int_t row_lwb,Int_t row_upb,Int_t col_lwb,Int_t col_upb); TMatrixTSub(const TMatrixTSub &ms); inline Element &operator()(Int_t rown,Int_t coln) { R__ASSERT(this->fMatrix->IsValid()); const Element *ptr = this->fMatrix->GetMatrixArray(); if (rown >= this->fNrowsSub || rown < 0) { Error("operator()","Request row(%d) outside matrix range of 0 - %d",rown,this->fNrowsSub); return (const_cast(ptr))[0]; } if (coln >= this->fNcolsSub || coln < 0) { Error("operator()","Request column(%d) outside matrix range of 0 - %d",coln,this->fNcolsSub); return (const_cast(ptr))[0]; } const Int_t index = (rown+this->fRowOff)*this->fMatrix->GetNcols()+coln+this->fColOff; return (const_cast(ptr))[index]; } void Rank1Update(const TVectorT &vec,Element alpha=1.0); void operator= (Element val); void operator+=(Element val); void operator*=(Element val); void operator=(const TMatrixTSub_const &s); TMatrixTSub& operator=(const TMatrixTSub &s) { operator=((TMatrixTSub_const &)s); return *this;} void operator=(const TMatrixTBase &m); void operator+=(const TMatrixTSub_const &s); void operator*=(const TMatrixTSub_const &s); void operator+=(const TMatrixTBase &m); void operator*=(const TMatrixT &m); void operator*=(const TMatrixTSym &m); ClassDef(TMatrixTSub,0) // Template of Sub Matrix Access class }; ////////////////////////////////////////////////////////////////////////// // // // TMatrixTSparseRow_const // // // // Template class represents a row of TMatrixTSparse // // // ////////////////////////////////////////////////////////////////////////// template class TMatrixTSparseRow_const { protected: const TMatrixTBase *fMatrix; // the matrix I am a row of Int_t fRowInd; // effective row index Int_t fNindex; // index range const Int_t *fColPtr; // column index pointer const Element *fDataPtr; // data pointer public: TMatrixTSparseRow_const() { fMatrix = 0; fRowInd = 0; fNindex = 0; fColPtr = 0; fDataPtr = 0; } TMatrixTSparseRow_const(const TMatrixTSparse &matrix,Int_t row); TMatrixTSparseRow_const(const TMatrixTSparseRow_const& trc): fMatrix(trc.fMatrix), fRowInd(trc.fRowInd), fNindex(trc.fNindex), fColPtr(trc.fColPtr), fDataPtr(trc.fDataPtr) { } TMatrixTSparseRow_const& operator=(const TMatrixTSparseRow_const& trc) { fMatrix=trc.fMatrix; fRowInd=trc.fRowInd; fNindex=trc.fNindex; fColPtr=trc.fColPtr; fDataPtr=trc.fDataPtr; return *this;} virtual ~TMatrixTSparseRow_const() { } inline const TMatrixTBase *GetMatrix () const { return fMatrix; } inline const Element *GetDataPtr () const { return fDataPtr; } inline const Int_t *GetColPtr () const { return fColPtr; } inline Int_t GetRowIndex() const { return fRowInd; } inline Int_t GetNindex () const { return fNindex; } Element operator()(Int_t i) const; inline Element operator[](Int_t i) const { return (*(const TMatrixTSparseRow_const *)this)(i); } ClassDef(TMatrixTSparseRow_const,0) // Template of Sparse Matrix Row Access class }; template class TMatrixTSparseRow : public TMatrixTSparseRow_const { public: TMatrixTSparseRow() {} TMatrixTSparseRow(TMatrixTSparse &matrix,Int_t row); TMatrixTSparseRow(const TMatrixTSparseRow &mr); inline Element *GetDataPtr() const { return const_cast(this->fDataPtr); } Element operator()(Int_t i) const; Element &operator()(Int_t i); inline Element operator[](Int_t i) const { return (*(const TMatrixTSparseRow *)this)(i); } inline Element &operator[](Int_t i) { return (*(TMatrixTSparseRow *)this)(i); } void operator= (Element val); void operator+=(Element val); void operator*=(Element val); void operator=(const TMatrixTSparseRow_const &r); TMatrixTSparseRow& operator=(const TMatrixTSparseRow &r) { operator=((TMatrixTSparseRow_const &)r); return *this;} void operator=(const TVectorT &vec); void operator+=(const TMatrixTSparseRow_const &r); void operator*=(const TMatrixTSparseRow_const &r); ClassDef(TMatrixTSparseRow,0) // Template of Sparse Matrix Row Access class }; ////////////////////////////////////////////////////////////////////////// // // // TMatrixTSparseDiag_const // // // // Template class represents the diagonal of TMatrixTSparse // // // ////////////////////////////////////////////////////////////////////////// template class TMatrixTSparseDiag_const { protected: const TMatrixTBase *fMatrix; // the matrix I am the diagonal of Int_t fNdiag; // number of diag elems, min(nrows,ncols) const Element *fDataPtr; // data pointer public: TMatrixTSparseDiag_const() { fMatrix = 0; fNdiag = 0; fDataPtr = 0; } TMatrixTSparseDiag_const(const TMatrixTSparse &matrix); TMatrixTSparseDiag_const(const TMatrixTSparseDiag_const& trc): fMatrix(trc.fMatrix), fNdiag(trc.fNdiag), fDataPtr(trc.fDataPtr) { } TMatrixTSparseDiag_const& operator=(const TMatrixTSparseDiag_const& trc) { fMatrix=trc.fMatrix; fNdiag=trc.fNdiag; fDataPtr=trc.fDataPtr; return *this;} virtual ~TMatrixTSparseDiag_const() { } inline const TMatrixTBase *GetMatrix () const { return fMatrix; } inline const Element *GetDataPtr() const { return fDataPtr; } inline Int_t GetNdiags () const { return fNdiag; } Element operator ()(Int_t i) const; inline Element operator [](Int_t i) const { return (*(const TMatrixTSparseRow_const *)this)(i); } ClassDef(TMatrixTSparseDiag_const,0) // Template of Sparse Matrix Diagonal Access class }; template class TMatrixTSparseDiag : public TMatrixTSparseDiag_const { public: TMatrixTSparseDiag() {} TMatrixTSparseDiag(TMatrixTSparse &matrix); TMatrixTSparseDiag(const TMatrixTSparseDiag &md); inline Element *GetDataPtr() const { return const_cast(this->fDataPtr); } Element operator()(Int_t i) const; Element &operator()(Int_t i); inline Element operator[](Int_t i) const { return (*(const TMatrixTSparseDiag *)this)(i); } inline Element &operator[](Int_t i) { return (*(TMatrixTSparseDiag *)this)(i); } void operator= (Element val); void operator+=(Element val); void operator*=(Element val); void operator=(const TMatrixTSparseDiag_const &d); TMatrixTSparseDiag& operator=(const TMatrixTSparseDiag &d) { operator=((TMatrixTSparseDiag_const &)d); return *this;} void operator=(const TVectorT &vec); void operator+=(const TMatrixTSparseDiag_const &d); void operator*=(const TMatrixTSparseDiag_const &d); ClassDef(TMatrixTSparseDiag,0) // Template of Sparse Matrix Diagonal Access class }; Double_t Drand(Double_t &ix); #endif