StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
TRMatrix.h
1 #ifndef ROOT_TRMatrix
2 #define ROOT_TRMatrix
3 #include "TError.h"
4 #include "TRArray.h"
5 class TRSymMatrix;
6 #include "TRSymMatrix.h"
7 class TRMatrix : public TRArray {
8  public:
9  TRMatrix(Int_t nrows=0,Int_t ncols=0) : TRArray(nrows*ncols), fNrows(nrows), fNcols(ncols) {}
10  TRMatrix(Int_t nrows,Int_t ncols,const Double_t *Array) : TRArray(nrows*ncols,Array), fNrows(nrows), fNcols(ncols) {}
11  TRMatrix(Int_t nrows,Int_t ncols,const Float_t *Array) : TRArray(nrows*ncols,Array), fNrows(nrows), fNcols(ncols) {}
12  TRMatrix(const TRMatrix& A, ETRMatrixCreatorsOp kop,const TRMatrix& B);
13  TRMatrix(ETRMatrixCreatorsOp kop,Int_t nrows);
14  TRMatrix(const TRMatrix& A, ETRMatrixCreatorsOp kop);
15  TRMatrix(Int_t nrows,Int_t ncols,const Char_t *s) : TRArray(nrows*ncols,s), fNrows(nrows), fNcols(ncols) {}
16  TRMatrix(const TRSymMatrix &S, ETRMatrixCreatorsOp kop,const TRMatrix& A);
17  TRMatrix(const TRMatrix& A, ETRMatrixCreatorsOp kop,const TRSymMatrix &S);
18  TRMatrix(const TRSymMatrix &S);
19  TRMatrix(const TRMatrix &S, Int_t NI, Int_t NJ=0, Int_t I=1, Int_t J=1);
20 #ifndef __CINT__
21  TRMatrix(Int_t nrows,Int_t ncols,Double_t a0, ...);
22 #endif
23  TRMatrix &operator=(const TRMatrix &rhs);
24  virtual ~TRMatrix(){;}
25  Int_t GetNrows() const {return fNrows;}
26  Int_t GetNcols() const {return fNcols;}
27  Int_t NI() const {return fNrows;}
28  Int_t NJ() const {return fNcols;}
29  void SetMatrix(Int_t nrows,Int_t ncols,const Double_t *array=0);
30  ETRMatrixType GetMatrixType() const {return kRectangular;}
31  Double_t &operator()(Int_t i) {return TRArray::operator[](i);}
32  Double_t operator()(Int_t i) const {return TRArray::operator[](i);}
33  Double_t &operator()(Int_t i,Int_t j);
34  Double_t operator()(Int_t i,Int_t j) const {return operator()(i,j);}
35  protected:
36  Int_t fNrows; // number of rows
37  Int_t fNcols; // number of columns
38  public:
39  void Add(const TRMatrix& A, ETRMatrixCreatorsOp kop,const TRMatrix& B);
40  void Substruct(const TRMatrix& A, ETRMatrixCreatorsOp kop,const TRMatrix& B);
41  void AddRow(const Double_t *row) {
42  fNrows++; Set(fNrows*fNcols); TCL::ucopy(row, fArray+(fNrows-1)*fNcols, fNcols);
43  }
44  void AddRow(const Float_t *row) {
45  fNrows++; Set(fNrows*fNcols); TCL::ucopy(row, fArray+(fNrows-1)*fNcols, fNcols);
46  }
47  const Double_t *GetRow(UInt_t col = 0) const {return GetArray() + col*fNcols;}
48  virtual void Print(Option_t *opt="") const;
49  friend TRMatrix operator*(const TRMatrix &source, Double_t scalar) {TRMatrix s(source); s *= scalar; return s;}
50  friend TRMatrix operator*(Double_t scalar, const TRMatrix &source) {TRMatrix s(source); s *= scalar; return s;}
51  friend TRMatrix operator/(const TRMatrix &source, Double_t scalar) {TRMatrix s(source); s /= scalar; return s;}
52  friend TRMatrix operator+(const TRMatrix &source, Double_t scalar) {TRMatrix s(source); s += scalar; return s;}
53  friend TRMatrix operator+(Double_t scalar, const TRMatrix &source) {TRMatrix s(source); s += scalar; return s;}
54  friend TRMatrix operator-(const TRMatrix &source, Double_t scalar) {TRMatrix s(source); s -= scalar; return s;}
55  friend TRMatrix operator-(Double_t scalar, const TRMatrix &source) {TRMatrix s(source); s -= scalar; return s;}
56  ClassDef(TRMatrix,1) // TRMatrix class (double precision)
57 };
58 std::ostream& operator<<(std::ostream& s,const TRMatrix &target);
59 inline Double_t &TRMatrix::operator()(Int_t i,Int_t j){
60  if (j < 0 || j >= fNcols) {
61  ::Error("TRMatrix::operator()", "index j %d out of bounds (size: %d, this: %p)",
62  j, fNcols, this);
63  j = 0;
64  }
65  if (i < 0 || i >= fNrows) {
66  ::Error("TRMatrix::operator()", "index i %d out of bounds (size: %d, this: %p)",
67  i, fNrows, this);
68  i = 0;
69  }
70  return TArrayD::operator[](j + i*fNcols);
71 }
72 #endif
Definition: FJcore.h:367