00001 #ifndef ROOT_TRMatrix
00002 #define ROOT_TRMatrix
00003 #include "TError.h"
00004 #include "TRArray.h"
00005 class TRSymMatrix;
00006 #include "TRSymMatrix.h"
00007 class TRMatrix : public TRArray {
00008 public:
00009 TRMatrix(Int_t nrows=0,Int_t ncols=0) : TRArray(nrows*ncols), fNrows(nrows), fNcols(ncols) {}
00010 TRMatrix(Int_t nrows,Int_t ncols,const Double_t *Array) : TRArray(nrows*ncols,Array), fNrows(nrows), fNcols(ncols) {}
00011 TRMatrix(Int_t nrows,Int_t ncols,const Float_t *Array) : TRArray(nrows*ncols,Array), fNrows(nrows), fNcols(ncols) {}
00012 TRMatrix(const TRMatrix& A, ETRMatrixCreatorsOp kop,const TRMatrix& B);
00013 TRMatrix(ETRMatrixCreatorsOp kop,Int_t nrows);
00014 TRMatrix(const TRMatrix& A, ETRMatrixCreatorsOp kop);
00015 TRMatrix(Int_t nrows,Int_t ncols,const Char_t *s) : TRArray(nrows*ncols,s), fNrows(nrows), fNcols(ncols) {}
00016 TRMatrix(const TRSymMatrix &S, ETRMatrixCreatorsOp kop,const TRMatrix& A);
00017 TRMatrix(const TRMatrix& A, ETRMatrixCreatorsOp kop,const TRSymMatrix &S);
00018 TRMatrix(const TRSymMatrix &S);
00019 TRMatrix(const TRMatrix &S, Int_t NI, Int_t NJ=0, Int_t I=1, Int_t J=1);
00020 #ifndef __CINT__
00021 TRMatrix(Int_t nrows,Int_t ncols,Double_t a0, ...);
00022 #endif
00023 TRMatrix &operator=(const TRMatrix &rhs);
00024 virtual ~TRMatrix(){;}
00025 Int_t GetNrows() const {return fNrows;}
00026 Int_t GetNcols() const {return fNcols;}
00027 Int_t NI() const {return fNrows;}
00028 Int_t NJ() const {return fNcols;}
00029 void SetMatrix(Int_t nrows,Int_t ncols,const Double_t *array=0);
00030 ETRMatrixType GetMatrixType() const {return kRectangular;}
00031 Double_t &operator()(Int_t i) {return TRArray::operator[](i);}
00032 Double_t operator()(Int_t i) const {return TRArray::operator[](i);}
00033 Double_t &operator()(Int_t i,Int_t j);
00034 Double_t operator()(Int_t i,Int_t j) const {return operator()(i,j);}
00035 protected:
00036 Int_t fNrows;
00037 Int_t fNcols;
00038 public:
00039 void Add(const TRMatrix& A, ETRMatrixCreatorsOp kop,const TRMatrix& B);
00040 void Substruct(const TRMatrix& A, ETRMatrixCreatorsOp kop,const TRMatrix& B);
00041 void AddRow(const Double_t *row) {
00042 fNrows++; Set(fNrows*fNcols); TCL::ucopy(row, fArray+(fNrows-1)*fNcols, fNcols);
00043 }
00044 void AddRow(const Float_t *row) {
00045 fNrows++; Set(fNrows*fNcols); TCL::ucopy(row, fArray+(fNrows-1)*fNcols, fNcols);
00046 }
00047 const Double_t *GetRow(UInt_t col = 0) const {return GetArray() + col*fNcols;}
00048 virtual void Print(Option_t *opt="") const;
00049 friend TRMatrix operator*(const TRMatrix &source, Double_t scalar) {TRMatrix s(source); s *= scalar; return s;}
00050 friend TRMatrix operator*(Double_t scalar, const TRMatrix &source) {TRMatrix s(source); s *= scalar; return s;}
00051 friend TRMatrix operator/(const TRMatrix &source, Double_t scalar) {TRMatrix s(source); s /= scalar; return s;}
00052 friend TRMatrix operator+(const TRMatrix &source, Double_t scalar) {TRMatrix s(source); s += scalar; return s;}
00053 friend TRMatrix operator+(Double_t scalar, const TRMatrix &source) {TRMatrix s(source); s += scalar; return s;}
00054 friend TRMatrix operator-(const TRMatrix &source, Double_t scalar) {TRMatrix s(source); s -= scalar; return s;}
00055 friend TRMatrix operator-(Double_t scalar, const TRMatrix &source) {TRMatrix s(source); s -= scalar; return s;}
00056 ClassDef(TRMatrix,1)
00057 };
00058 ostream& operator<<(ostream& s,const TRMatrix &target);
00059 inline Double_t &TRMatrix::operator()(Int_t i,Int_t j){
00060 if (j < 0 || j >= fNcols) {
00061 ::Error("TRMatrix::operator()", "index j %d out of bounds (size: %d, this: %p)",
00062 j, fNcols, this);
00063 j = 0;
00064 }
00065 if (i < 0 || i >= fNrows) {
00066 ::Error("TRMatrix::operator()", "index i %d out of bounds (size: %d, this: %p)",
00067 i, fNrows, this);
00068 i = 0;
00069 }
00070 return TArrayD::operator[](j + i*fNcols);
00071 }
00072 #endif