TMatrixTBase.h

Go to the documentation of this file.
00001 // @(#)root/matrix:$Id: TMatrixTBase.h 20882 2007-11-19 11:31:26Z rdm $
00002 // Authors: Fons Rademakers, Eddy Offermann   Nov 2003
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
00006  * All rights reserved.                                                  *
00007  *                                                                       *
00008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00010  *************************************************************************/
00011 
00012 #ifndef ROOT_TMatrixTBase
00013 #define ROOT_TMatrixTBase
00014 
00015 //////////////////////////////////////////////////////////////////////////
00016 //                                                                      //
00017 // TMatrixTBase                                                         //
00018 //                                                                      //
00019 // Template of base class in the linear algebra package                 //
00020 //                                                                      //
00021 //  matrix properties are stored here, however the data storage is part //
00022 //  of the derived classes                                              //
00023 //                                                                      //
00024 //////////////////////////////////////////////////////////////////////////
00025 
00026 //======================================================================//
00027 // Summary of the streamer version history                              //
00028 //======================================================================//
00029 //              3.10/02      4.00/a   4.00/b   4.00/c 4.00-08 5.05-1    //
00030 // TMatrixFBase   -          2        2        2       4      5         //
00031 // TMatrix        2          3        3        3       3      4         //
00032 // TMatrixF       -          3        3        3       3      4         //
00033 // TMatrixFSym    -          1        1        1       1      2         //
00034 // TMatrixDSparse -          -        -        -       -      2         //
00035 //                                                                      //
00036 // TMatrixDBase   -          2        3        3       4      5         //
00037 // TMatrixD       2          3        3        3       3      4         //
00038 // TMatrixDSym    -          1        1        1       1      2         //
00039 // TMatrixDSparse -          -        1        1       1      2         //
00040 //                                                                      //
00041 // TVector        2          3        3        3       3      4         //
00042 // TVectorF       -          2        2        2       3      4         //
00043 //                                                                      //
00044 // TVectorD       2          2        2        2       3      4         //
00045 //======================================================================//
00046 //                                                                      //
00047 // 4.00/a : (Jan 25 2004) introduced new classes/inheritance scheme,    //
00048 //          TMatrix now inherits from TMatrixF                          //
00049 //                                                                      //
00050 //          TMatrixF::TMatrixFBase                                      //
00051 //          TMatrixFSym::TMatrixFBase                                   //
00052 //          TMatrixD::TMatrixDBase                                      //
00053 //          TMatrixDSym::TMatrixDBase                                   //
00054 //                                                                      //
00055 // 4.00/b : (May 12 2004) introduced TMatrixDSparse and added new       //
00056 //          element fNRowIndex to TMatrixFBase and TMatrixDBase         //
00057 //          TMatrixDSparse::TMatrixDBase                                //
00058 //                                                                      //
00059 // 4.00/c : (May 27 2004) Used the TObject::fBits to store validity     //
00060 //           state for vectors and matrices                             //
00061 //                                                                      //
00062 // 5.05-1 :  templates TMatrixTBase,TMatrixT,TMatrixTSym and            //
00063 //           TMatrixTSparse were introduced, all versions were          //
00064 //           increased by 1 .                                           //
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();  // This function is now obsolete (and is not implemented) you should use TMatrix::GetMatrixArray().
00099 
00100 protected:
00101    Int_t    fNrows;               // number of rows
00102    Int_t    fNcols;               // number of columns
00103    Int_t    fRowLwb;              // lower bound of the row index
00104    Int_t    fColLwb;              // lower bound of the col index
00105    Int_t    fNelems;              // number of elements in matrix
00106    Int_t    fNrowIndex;           // length of row index array (= fNrows+1) wich is only used for sparse matrices
00107 
00108    Element  fTol;                 // sqrt(epsilon); epsilon is smallest number number so that  1+epsilon > 1
00109                                   //  fTol is used in matrix decomposition (like in inversion)
00110 
00111    Bool_t   fIsOwner;             //!default kTRUE, when Use array kFALSE
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};          // size data container on stack, see New_m(),Delete_m()
00118    enum {kWorkMax = 100};         // size of work array's in several routines
00119 
00120    enum EMatrixStatusBits {
00121      kStatus = BIT(14) // set if matrix object is valid
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="");       // *MENU*
00195    void Print(Option_t *name  ="") const; // *MENU*
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) // Matrix base class (template)
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 // Service functions (useful in the verification code).
00230 // They print some detail info if the validation condition fails
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

Generated on Tue Jul 5 14:27:11 2011 for ROOT_528-00b_version by  doxygen 1.5.1