Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/root/TMatrixTBase.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 // @(#)root/matrix:$Id$
0002 // Authors: Fons Rademakers, Eddy Offermann   Nov 2003
0003 
0004 /*************************************************************************
0005  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
0006  * All rights reserved.                                                  *
0007  *                                                                       *
0008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
0009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
0010  *************************************************************************/
0011 
0012 #ifndef ROOT_TMatrixTBase
0013 #define ROOT_TMatrixTBase
0014 
0015 //////////////////////////////////////////////////////////////////////////
0016 //                                                                      //
0017 // TMatrixTBase                                                         //
0018 //                                                                      //
0019 // Template of base class in the linear algebra package                 //
0020 //                                                                      //
0021 //  matrix properties are stored here, however the data storage is part //
0022 //  of the derived classes                                              //
0023 //                                                                      //
0024 //////////////////////////////////////////////////////////////////////////
0025 
0026 //======================================================================//
0027 // Summary of the streamer version history                              //
0028 //======================================================================//
0029 //              3.10/02      4.00/a   4.00/b   4.00/c 4.00-08 5.05-1    //
0030 // TMatrixFBase   -          2        2        2       4      5         //
0031 // TMatrix        2          3        3        3       3      4         //
0032 // TMatrixF       -          3        3        3       3      4         //
0033 // TMatrixFSym    -          1        1        1       1      2         //
0034 // TMatrixDSparse -          -        -        -       -      2         //
0035 //                                                                      //
0036 // TMatrixDBase   -          2        3        3       4      5         //
0037 // TMatrixD       2          3        3        3       3      4         //
0038 // TMatrixDSym    -          1        1        1       1      2         //
0039 // TMatrixDSparse -          -        1        1       1      2         //
0040 //                                                                      //
0041 // TVector        2          3        3        3       3      4         //
0042 // TVectorF       -          2        2        2       3      4         //
0043 //                                                                      //
0044 // TVectorD       2          2        2        2       3      4         //
0045 //======================================================================//
0046 //                                                                      //
0047 // 4.00/a : (Jan 25 2004) introduced new classes/inheritance scheme,    //
0048 //          TMatrix now inherits from TMatrixF                          //
0049 //                                                                      //
0050 //          TMatrixF::TMatrixFBase                                      //
0051 //          TMatrixFSym::TMatrixFBase                                   //
0052 //          TMatrixD::TMatrixDBase                                      //
0053 //          TMatrixDSym::TMatrixDBase                                   //
0054 //                                                                      //
0055 // 4.00/b : (May 12 2004) introduced TMatrixDSparse and added new       //
0056 //          element fNRowIndex to TMatrixFBase and TMatrixDBase         //
0057 //          TMatrixDSparse::TMatrixDBase                                //
0058 //                                                                      //
0059 // 4.00/c : (May 27 2004) Used the TObject::fBits to store validity     //
0060 //           state for vectors and matrices                             //
0061 //                                                                      //
0062 // 5.05-1 :  templates TMatrixTBase,TMatrixT,TMatrixTSym and            //
0063 //           TMatrixTSparse were introduced, all versions were          //
0064 //           increased by 1 .                                           //
0065 //                                                                      //
0066 //======================================================================//
0067 
0068 #include "TError.h"
0069 #include "TObject.h"
0070 #include "TMathBase.h"
0071 #include "TMatrixFBasefwd.h"
0072 #include "TMatrixDBasefwd.h"
0073 #include "TVectorFfwd.h"
0074 #include "TVectorDfwd.h"
0075 
0076 #include <limits>
0077 
0078 template<class Element> class TVectorT;
0079 template<class Element> class TElementActionT;
0080 template<class Element> class TElementPosActionT;
0081 
0082 R__EXTERN Int_t gMatrixCheck;
0083 
0084 template<class Element> class TMatrixTBase : public TObject {
0085 
0086 private:
0087    Element *GetElements();  // This function is now obsolete (and is not implemented) you should use TMatrix::GetMatrixArray().
0088 
0089 protected:
0090    Int_t    fNrows;               // number of rows
0091    Int_t    fNcols;               // number of columns
0092    Int_t    fRowLwb;              // lower bound of the row index
0093    Int_t    fColLwb;              // lower bound of the col index
0094    Int_t    fNelems;              // number of elements in matrix
0095    Int_t    fNrowIndex;           // length of row index array (= fNrows+1), which is only used for sparse matrices
0096 
0097    Element  fTol;                 // sqrt(epsilon); epsilon is smallest number number so that  1+epsilon > 1
0098                                   //  fTol is used in matrix decomposition (like in inversion)
0099 
0100    Bool_t   fIsOwner;             //!default kTRUE, when Use array kFALSE
0101 
0102    static  void DoubleLexSort (Int_t n,Int_t *first,Int_t *second,Element *data);
0103    static  void IndexedLexSort(Int_t n,Int_t *first,Int_t swapFirst,
0104                                Int_t *second,Int_t swapSecond,Int_t *index);
0105 
0106    enum {kSizeMax = 25};          // size data container on stack, see New_m(),Delete_m()
0107    enum {kWorkMax = 100};         // size of work array's in several routines
0108 
0109    enum EMatrixStatusBits {
0110      kStatus = BIT(14) // set if matrix object is valid
0111    };
0112 
0113 public:
0114 
0115    TMatrixTBase():
0116      fNrows(0), fNcols(0), fRowLwb(0), fColLwb(0), fNelems(0), fNrowIndex(0),
0117      fTol(0), fIsOwner(kTRUE) { }
0118 
0119    ~TMatrixTBase() override {}
0120 
0121            inline       Int_t     GetRowLwb     () const { return fRowLwb; }
0122            inline       Int_t     GetRowUpb     () const { return fNrows+fRowLwb-1; }
0123            inline       Int_t     GetNrows      () const { return fNrows; }
0124            inline       Int_t     GetColLwb     () const { return fColLwb; }
0125            inline       Int_t     GetColUpb     () const { return fNcols+fColLwb-1; }
0126            inline       Int_t     GetNcols      () const { return fNcols; }
0127            inline       Int_t     GetNoElements () const { return fNelems; }
0128            inline       Element   GetTol        () const { return fTol; }
0129 
0130    virtual        const Element  *GetMatrixArray  () const = 0;
0131    virtual              Element  *GetMatrixArray  ()       = 0;
0132    virtual        const Int_t    *GetRowIndexArray() const = 0;
0133    virtual              Int_t    *GetRowIndexArray()       = 0;
0134    virtual        const Int_t    *GetColIndexArray() const = 0;
0135    virtual              Int_t    *GetColIndexArray()       = 0;
0136 
0137    virtual              TMatrixTBase<Element> &SetRowIndexArray(Int_t *data) = 0;
0138    virtual              TMatrixTBase<Element> &SetColIndexArray(Int_t *data) = 0;
0139    virtual              TMatrixTBase<Element> &SetMatrixArray  (const Element *data,Option_t *option="");
0140            inline       Element                SetTol          (Element tol);
0141 
0142    void   Clear      (Option_t *option="") override = 0;
0143 
0144    inline  void   Invalidate ()       { SetBit(kStatus); }
0145    inline  void   MakeValid  ()       { ResetBit(kStatus); }
0146    inline  Bool_t IsValid    () const { return !TestBit(kStatus); }
0147    inline  Bool_t IsOwner    () const { return fIsOwner; }
0148    virtual Bool_t IsSymmetric() const;
0149 
0150    virtual TMatrixTBase<Element> &GetSub(Int_t row_lwb,Int_t row_upb,Int_t col_lwb,Int_t col_upb,
0151                                          TMatrixTBase<Element> &target,Option_t *option="S") const = 0;
0152    virtual TMatrixTBase<Element> &SetSub(Int_t row_lwb,Int_t col_lwb,const TMatrixTBase<Element> &source) = 0;
0153 
0154    virtual void                   GetMatrix2Array(Element *data,Option_t *option="") const;
0155    virtual TMatrixTBase<Element> &InsertRow      (Int_t row,Int_t col,const Element *v,Int_t n = -1);
0156    virtual void                   ExtractRow     (Int_t row,Int_t col,      Element *v,Int_t n = -1) const;
0157 
0158    virtual TMatrixTBase<Element> &Shift          (Int_t row_shift,Int_t col_shift);
0159    virtual TMatrixTBase<Element> &ResizeTo       (Int_t nrows,Int_t ncols,Int_t nr_nonzeros=-1) = 0;
0160    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;
0161 
0162    virtual Double_t Determinant() const                          { AbstractMethod("Determinant()"); return 0.; }
0163    virtual void     Determinant(Double_t &d1,Double_t &d2) const { AbstractMethod("Determinant()"); d1 = 0.; d2 = 0.; }
0164 
0165    virtual TMatrixTBase<Element> &Zero       ();
0166    virtual TMatrixTBase<Element> &Abs        ();
0167    virtual TMatrixTBase<Element> &Sqr        ();
0168    virtual TMatrixTBase<Element> &Sqrt       ();
0169    virtual TMatrixTBase<Element> &UnitMatrix ();
0170 
0171    virtual TMatrixTBase<Element> &NormByDiag (const TVectorT<Element> &v,Option_t *option="D");
0172 
0173    virtual Element RowNorm    () const;
0174    virtual Element ColNorm    () const;
0175    virtual Element E2Norm     () const;
0176    inline  Element NormInf    () const { return RowNorm(); }
0177    inline  Element Norm1      () const { return ColNorm(); }
0178    virtual Int_t   NonZeros   () const;
0179    virtual Element Sum        () const;
0180    virtual Element Min        () const;
0181    virtual Element Max        () const;
0182 
0183    void Draw (Option_t *option="") override;       // *MENU*
0184    void Print(Option_t *name  ="") const override; // *MENU*
0185 
0186    virtual Element   operator()(Int_t rown,Int_t coln) const = 0;
0187    virtual Element  &operator()(Int_t rown,Int_t coln)       = 0;
0188 
0189    Bool_t operator==(Element val) const;
0190    Bool_t operator!=(Element val) const;
0191    Bool_t operator< (Element val) const;
0192    Bool_t operator<=(Element val) const;
0193    Bool_t operator> (Element val) const;
0194    Bool_t operator>=(Element val) const;
0195 
0196    virtual TMatrixTBase<Element> &Apply(const TElementActionT<Element>    &action);
0197    virtual TMatrixTBase<Element> &Apply(const TElementPosActionT<Element> &action);
0198 
0199    virtual TMatrixTBase<Element> &Randomize(Element alpha,Element beta,Double_t &seed);
0200 
0201    // make it public since it can be called by TMatrixTRow
0202    static Element & NaNValue();
0203 
0204    ClassDefOverride(TMatrixTBase,5) // Matrix base class (template)
0205 };
0206 
0207 #ifndef __CLING__
0208 // When building with -fmodules, it instantiates all pending instantiations,
0209 // instead of delaying them until the end of the translation unit.
0210 // We 'got away with' probably because the use and the definition of the
0211 // explicit specialization do not occur in the same TU.
0212 //
0213 // In case we are building with -fmodules, we need to forward declare the
0214 // specialization in order to compile the dictionary G__Matrix.cxx.
0215 template <> TClass *TMatrixTBase<double>::Class();
0216 #endif // __CLING__
0217 
0218 
0219 template<class Element> Element TMatrixTBase<Element>::SetTol(Element newTol)
0220 {
0221    const Element  oldTol = fTol;
0222    if (newTol >= 0.0)
0223       fTol = newTol;
0224    return oldTol;
0225 }
0226 
0227 inline namespace TMatrixTAutoloadOps {
0228 
0229 template<class Element> Bool_t  operator==   (const TMatrixTBase<Element>  &m1,const TMatrixTBase<Element>  &m2);
0230 template<class Element> Element E2Norm       (const TMatrixTBase<Element>  &m1,const TMatrixTBase<Element>  &m2);
0231 template<class Element1,class Element2>
0232                         Bool_t  AreCompatible(const TMatrixTBase<Element1> &m1,const TMatrixTBase<Element2> &m2,Int_t verbose=0);
0233 template<class Element> void    Compare      (const TMatrixTBase<Element>  &m1,const TMatrixTBase<Element>  &m2);
0234 
0235 // Service functions (useful in the verification code).
0236 // They print some detail info if the validation condition fails
0237 
0238 template<class Element> Bool_t VerifyMatrixValue   (const TMatrixTBase<Element> &m,Element val,
0239                                                     Int_t verbose,Element maxDevAllow);
0240 template<class Element> Bool_t VerifyMatrixValue   (const TMatrixTBase<Element> &m,Element val,Int_t verbose)
0241                                                                            { return VerifyMatrixValue(m,val,verbose,Element(0.)); }
0242 template<class Element> Bool_t VerifyMatrixValue   (const TMatrixTBase<Element> &m,Element val)
0243                                                                            { return VerifyMatrixValue(m,val,1,Element(0.)); }
0244 template<class Element> Bool_t VerifyMatrixIdentity(const TMatrixTBase<Element> &m1,const TMatrixTBase<Element> &m2,
0245                                                     Int_t verbose,Element maxDevAllow);
0246 template<class Element> Bool_t VerifyMatrixIdentity(const TMatrixTBase<Element> &m1,const TMatrixTBase<Element> &m2,Int_t verbose)
0247                                                                            { return VerifyMatrixIdentity(m1,m2,verbose,Element(0.)); }
0248 template<class Element> Bool_t VerifyMatrixIdentity(const TMatrixTBase<Element> &m1,const TMatrixTBase<Element> &m2)
0249                                                                            { return VerifyMatrixIdentity(m1,m2,1,Element(0.)); }
0250 
0251 } // inline namespace TMatrixTAutoloadOps
0252 #endif