00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef ROOT_TMatrixTBase
00013 #define ROOT_TMatrixTBase
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068 #include <limits>
00069
00070 #ifndef ROOT_TNamed
00071 #include "TNamed.h"
00072 #endif
00073 #ifndef ROOT_TMatrixFBasefwd
00074 #include "TMatrixFBasefwd.h"
00075 #endif
00076 #ifndef ROOT_TMatrixDBasefwd
00077 #include "TMatrixDBasefwd.h"
00078 #endif
00079 #ifndef ROOT_TVectorFfwd
00080 #include "TVectorFfwd.h"
00081 #endif
00082 #ifndef ROOT_TVectorDfwd
00083 #include "TVectorDfwd.h"
00084 #endif
00085 #ifndef ROOT_TError
00086 #include "TError.h"
00087 #endif
00088
00089 template<class Element> class TVectorT;
00090 template<class Element> class TElementActionT;
00091 template<class Element> class TElementPosActionT;
00092
00093 R__EXTERN Int_t gMatrixCheck;
00094
00095 template<class Element> class TMatrixTBase : public TObject {
00096
00097 private:
00098 Element *GetElements();
00099
00100 protected:
00101 Int_t fNrows;
00102 Int_t fNcols;
00103 Int_t fRowLwb;
00104 Int_t fColLwb;
00105 Int_t fNelems;
00106 Int_t fNrowIndex;
00107
00108 Element fTol;
00109
00110
00111 Bool_t fIsOwner;
00112
00113 static void DoubleLexSort (Int_t n,Int_t *first,Int_t *second,Element *data);
00114 static void IndexedLexSort(Int_t n,Int_t *first,Int_t swapFirst,
00115 Int_t *second,Int_t swapSecond,Int_t *index);
00116
00117 enum {kSizeMax = 25};
00118 enum {kWorkMax = 100};
00119
00120 enum EMatrixStatusBits {
00121 kStatus = BIT(14)
00122 };
00123
00124 public:
00125
00126 TMatrixTBase():
00127 fNrows(0), fNcols(0), fRowLwb(0), fColLwb(0), fNelems(0), fNrowIndex(0),
00128 fTol(0), fIsOwner(kTRUE) { }
00129
00130 virtual ~TMatrixTBase() {}
00131
00132 inline Int_t GetRowLwb () const { return fRowLwb; }
00133 inline Int_t GetRowUpb () const { return fNrows+fRowLwb-1; }
00134 inline Int_t GetNrows () const { return fNrows; }
00135 inline Int_t GetColLwb () const { return fColLwb; }
00136 inline Int_t GetColUpb () const { return fNcols+fColLwb-1; }
00137 inline Int_t GetNcols () const { return fNcols; }
00138 inline Int_t GetNoElements () const { return fNelems; }
00139 inline Element GetTol () const { return fTol; }
00140
00141 virtual const Element *GetMatrixArray () const = 0;
00142 virtual Element *GetMatrixArray () = 0;
00143 virtual const Int_t *GetRowIndexArray() const = 0;
00144 virtual Int_t *GetRowIndexArray() = 0;
00145 virtual const Int_t *GetColIndexArray() const = 0;
00146 virtual Int_t *GetColIndexArray() = 0;
00147
00148 virtual TMatrixTBase<Element> &SetRowIndexArray(Int_t *data) = 0;
00149 virtual TMatrixTBase<Element> &SetColIndexArray(Int_t *data) = 0;
00150 virtual TMatrixTBase<Element> &SetMatrixArray (const Element *data,Option_t *option="");
00151 inline Element SetTol (Element tol);
00152
00153 virtual void Clear (Option_t *option="") = 0;
00154
00155 inline void Invalidate () { SetBit(kStatus); }
00156 inline void MakeValid () { ResetBit(kStatus); }
00157 inline Bool_t IsValid () const { return !TestBit(kStatus); }
00158 inline Bool_t IsOwner () const { return fIsOwner; }
00159 virtual Bool_t IsSymmetric() const;
00160
00161 virtual TMatrixTBase<Element> &GetSub(Int_t row_lwb,Int_t row_upb,Int_t col_lwb,Int_t col_upb,
00162 TMatrixTBase<Element> &target,Option_t *option="S") const = 0;
00163 virtual TMatrixTBase<Element> &SetSub(Int_t row_lwb,Int_t col_lwb,const TMatrixTBase<Element> &source) = 0;
00164
00165 virtual void GetMatrix2Array(Element *data,Option_t *option="") const;
00166 virtual TMatrixTBase<Element> &InsertRow (Int_t row,Int_t col,const Element *v,Int_t n = -1);
00167 virtual void ExtractRow (Int_t row,Int_t col, Element *v,Int_t n = -1) const;
00168
00169 virtual TMatrixTBase<Element> &Shift (Int_t row_shift,Int_t col_shift);
00170 virtual TMatrixTBase<Element> &ResizeTo (Int_t nrows,Int_t ncols,Int_t nr_nonzeros=-1) = 0;
00171 virtual TMatrixTBase<Element> &ResizeTo (Int_t row_lwb,Int_t row_upb,Int_t col_lwb,Int_t col_upb,Int_t nr_nonzeros=-1) = 0;
00172
00173 virtual Double_t Determinant() const { AbstractMethod("Determinant()"); return 0.; }
00174 virtual void Determinant(Double_t &d1,Double_t &d2) const { AbstractMethod("Determinant()"); d1 = 0.; d2 = 0.; }
00175
00176 virtual TMatrixTBase<Element> &Zero ();
00177 virtual TMatrixTBase<Element> &Abs ();
00178 virtual TMatrixTBase<Element> &Sqr ();
00179 virtual TMatrixTBase<Element> &Sqrt ();
00180 virtual TMatrixTBase<Element> &UnitMatrix ();
00181
00182 virtual TMatrixTBase<Element> &NormByDiag (const TVectorT<Element> &v,Option_t *option="D");
00183
00184 virtual Element RowNorm () const;
00185 virtual Element ColNorm () const;
00186 virtual Element E2Norm () const;
00187 inline Element NormInf () const { return RowNorm(); }
00188 inline Element Norm1 () const { return ColNorm(); }
00189 virtual Int_t NonZeros () const;
00190 virtual Element Sum () const;
00191 virtual Element Min () const;
00192 virtual Element Max () const;
00193
00194 void Draw (Option_t *option="");
00195 void Print(Option_t *name ="") const;
00196
00197 virtual Element operator()(Int_t rown,Int_t coln) const = 0;
00198 virtual Element &operator()(Int_t rown,Int_t coln) = 0;
00199
00200 Bool_t operator==(Element val) const;
00201 Bool_t operator!=(Element val) const;
00202 Bool_t operator< (Element val) const;
00203 Bool_t operator<=(Element val) const;
00204 Bool_t operator> (Element val) const;
00205 Bool_t operator>=(Element val) const;
00206
00207 virtual TMatrixTBase<Element> &Apply(const TElementActionT<Element> &action);
00208 virtual TMatrixTBase<Element> &Apply(const TElementPosActionT<Element> &action);
00209
00210 virtual TMatrixTBase<Element> &Randomize(Element alpha,Element beta,Double_t &seed);
00211
00212 ClassDef(TMatrixTBase,5)
00213 };
00214
00215 template<class Element> Element TMatrixTBase<Element>::SetTol(Element newTol)
00216 {
00217 const Element oldTol = fTol;
00218 if (newTol >= 0.0)
00219 fTol = newTol;
00220 return oldTol;
00221 }
00222
00223 template<class Element> Bool_t operator== (const TMatrixTBase<Element> &m1,const TMatrixTBase<Element> &m2);
00224 template<class Element> Element E2Norm (const TMatrixTBase<Element> &m1,const TMatrixTBase<Element> &m2);
00225 template<class Element1,class Element2>
00226 Bool_t AreCompatible(const TMatrixTBase<Element1> &m1,const TMatrixTBase<Element2> &m2,Int_t verbose=0);
00227 template<class Element> void Compare (const TMatrixTBase<Element> &m1,const TMatrixTBase<Element> &m2);
00228
00229
00230
00231
00232 template<class Element> Bool_t VerifyMatrixValue (const TMatrixTBase<Element> &m,Element val,
00233 Int_t verbose,Element maxDevAllow);
00234 template<class Element> Bool_t VerifyMatrixValue (const TMatrixTBase<Element> &m,Element val,Int_t verbose)
00235 { return VerifyMatrixValue(m,val,verbose,Element(0.)); }
00236 template<class Element> Bool_t VerifyMatrixValue (const TMatrixTBase<Element> &m,Element val)
00237 { return VerifyMatrixValue(m,val,1,Element(0.)); }
00238 template<class Element> Bool_t VerifyMatrixIdentity(const TMatrixTBase<Element> &m1,const TMatrixTBase<Element> &m2,
00239 Int_t verbose,Element maxDevAllow);
00240 template<class Element> Bool_t VerifyMatrixIdentity(const TMatrixTBase<Element> &m1,const TMatrixTBase<Element> &m2,Int_t verbose)
00241 { return VerifyMatrixIdentity(m1,m2,verbose,Element(0.)); }
00242 template<class Element> Bool_t VerifyMatrixIdentity(const TMatrixTBase<Element> &m1,const TMatrixTBase<Element> &m2)
00243 { return VerifyMatrixIdentity(m1,m2,1,Element(0.)); }
00244
00245 #endif