00001 #ifndef ROOT_TRDiagMatrix
00002 #define ROOT_TRDiagMatrix
00003 #include "TRArray.h"
00004 class TRMatrix;
00005 class TRVector;
00006 class TRDiagMatrix : public TRArray {
00007 public:
00008 TRDiagMatrix(Int_t nrows=0) : TRArray(nrows), fNrows(nrows) {}
00009 TRDiagMatrix(Int_t nrows,const Double_t *Array) : TRArray(nrows,Array), fNrows(nrows) {}
00010 TRDiagMatrix(Int_t nrows,const Float_t *Array) : TRArray(nrows,Array), fNrows(nrows) {}
00011 TRDiagMatrix(Int_t nrows,const Char_t *s) : TRArray(nrows,s), fNrows(nrows) {}
00012 TRDiagMatrix(const TRDiagMatrix& W,ETRMatrixCreatorsOp kop);
00013 #ifndef __CINT__
00014 TRDiagMatrix (Int_t nrows, Double_t a0, ...);
00015 #endif
00016 virtual ~TRDiagMatrix() {}
00017 void Inverse() { TCL::trsinv(fArray,fArray, fNrows);}
00018 Int_t GetNrows() const {return fNrows;}
00019 Int_t GetNcols() const {return GetNrows();}
00020 virtual ETRMatrixType GetMatrixType() const {return kDiagonalMatrix;}
00021 virtual Double_t Product(const TRVector& A,ETRMatrixCreatorsOp kop);
00022 virtual void Print(Option_t *opt="") const;
00023 Double_t &operator()(Int_t i) {return TRArray::operator[](i);}
00024 Double_t operator()(Int_t i) const {return TRArray::operator[](i);}
00025 Double_t &operator()(Int_t i,Int_t j);
00026 Double_t operator()(Int_t i,Int_t j) const {return operator()(i,j);}
00027 void AddRow(const Double_t *row) {
00028 fNrows++; Set(fNrows*(fNrows+1)/2); memcpy(fArray+(fNrows-1)*fNrows/2, row, fNrows*sizeof(Double_t));
00029 }
00030 void AddRow(const Double_t row) {
00031 fNrows++; Set(fNrows*(fNrows+1)/2); fArray[(fNrows+1)*fNrows/2-1] = row;
00032 }
00033 protected:
00034 Int_t fNrows;
00035 public:
00036 ClassDef(TRDiagMatrix,1)
00037 };
00038 ostream& operator<<(ostream& s,const TRDiagMatrix &target);
00039 inline Double_t &TRDiagMatrix::operator()(Int_t i,Int_t j){
00040 if (j < 0 || j >= fNrows) {
00041 ::Error("TRDiagMatrix::operator()", "index j %d out of bounds (size: %d, this: %p)",
00042 j, fNrows, this);
00043 j = 0;
00044 }
00045 if (i < 0 || i >= fNrows) {
00046 ::Error("TRDiagMatrix::operator()", "index i %d out of bounds (size: %d, this: %p)",
00047 i, fNrows, this);
00048 i = 0;
00049 }
00050 Int_t m = i;
00051 Int_t l = j;
00052 if (i > j) {m = j; l = i;}
00053 return TArrayD::operator[](m + (l+1)*l/2);
00054 }
00055 #endif
00056