// @(#)root/matrix:$Id$
// Authors: Fons Rademakers, Eddy Offermann   Dec 2003

/*************************************************************************
 * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

#ifndef ROOT_TDecompBase
#define ROOT_TDecompBase

///////////////////////////////////////////////////////////////////////////
//                                                                       //
// Decomposition Base class                                              //
//                                                                       //
// This class forms the base for all the decompositions methods in the   //
// linear algebra package .                                              //
//                                                                       //
///////////////////////////////////////////////////////////////////////////

#include <limits>

#ifndef ROOT_TMatrixD
#include "TMatrixD.h"
#endif
#ifndef ROOT_TMatrixDUtils
#include "TMatrixDUtils.h"
#endif
#ifndef ROOT_TVectorD
#include "TVectorD.h"
#endif

class TDecompBase : public TObject
{
protected :
   Double_t fTol;       // sqrt(epsilon); epsilon is smallest number number so that  1+epsilon > 1
   Double_t fDet1;      // determinant mantissa
   Double_t fDet2;      // determinant exponent for powers of 2
   Double_t fCondition; // matrix condition number
   Int_t    fRowLwb;    // Row    lower bound of decomposed matrix
   Int_t    fColLwb;    // Column lower bound of decomposed matrix

   void          ResetStatus() { for (Int_t i = 14; i < 22; i++) ResetBit(BIT(i)); }
   Int_t         Hager      (Double_t& est,Int_t iter=5);
   static  void  DiagProd   (const TVectorD &diag,Double_t tol,Double_t &d1,Double_t &d2);

   virtual const TMatrixDBase &GetDecompMatrix() const = 0;

   enum EMatrixDecompStat {
      kInit       = BIT(14),
      kPatternSet = BIT(15),
      kValuesSet  = BIT(16),
      kMatrixSet  = BIT(17),
      kDecomposed = BIT(18),
      kDetermined = BIT(19),
      kCondition  = BIT(20),
      kSingular   = BIT(21)
   };

   enum {kWorkMax = 100}; // size of work array's in several routines

public :
   TDecompBase();
   TDecompBase(const TDecompBase &another);
   virtual ~TDecompBase() {};

   inline  Double_t GetTol       () const { return fTol; }
   inline  Double_t GetDet1      () const { return fDet1; }
   inline  Double_t GetDet2      () const { return fDet2; }
   inline  Double_t GetCondition () const { return fCondition; }
   virtual Int_t    GetNrows     () const = 0;
   virtual Int_t    GetNcols     () const = 0;
   Int_t            GetRowLwb    () const { return fRowLwb; }
   Int_t            GetColLwb    () const { return fColLwb; }
   inline Double_t  SetTol       (Double_t tol);

   virtual Double_t Condition  ();
   virtual void     Det        (Double_t &d1,Double_t &d2);
   virtual Bool_t   Decompose  ()                             = 0;
   virtual Bool_t   Solve      (      TVectorD &b)            = 0;
   virtual TVectorD Solve      (const TVectorD& b,Bool_t &ok) = 0;
   virtual Bool_t   Solve      (      TMatrixDColumn& b)      = 0;
   virtual Bool_t   TransSolve (      TVectorD &b)            = 0;
   virtual TVectorD TransSolve (const TVectorD &b,Bool_t &ok) = 0;
   virtual Bool_t   TransSolve (      TMatrixDColumn& b)      = 0;

   virtual Bool_t   MultiSolve (TMatrixD &B);

   void Print(Option_t *opt="") const;

   TDecompBase &operator= (const TDecompBase &source);

   ClassDef(TDecompBase,2) // Matrix Decomposition Base
};

Double_t TDecompBase::SetTol(Double_t newTol) 
{
   const Double_t oldTol = fTol; 
   if (newTol >= 0.0) 
      fTol = newTol; 
   return oldTol; 
}

Bool_t DefHouseHolder  (const TVectorD &vc,Int_t     lp,Int_t     l,Double_t &up,Double_t &b,Double_t tol=0.0);
void   ApplyHouseHolder(const TVectorD &vc,Double_t  up,Double_t  b,Int_t     lp,Int_t     l,TMatrixDRow &cr);
void   ApplyHouseHolder(const TVectorD &vc,Double_t  up,Double_t  b,Int_t     lp,Int_t     l,TMatrixDColumn &cc);
void   ApplyHouseHolder(const TVectorD &vc,Double_t  up,Double_t  b,Int_t     lp,Int_t     l,TVectorD &cv);
void   DefGivens       (      Double_t  v1,Double_t  v2,Double_t &c,Double_t &s);
void   DefAplGivens    (      Double_t &v1,Double_t &v2,Double_t &c,Double_t &s);
void   ApplyGivens     (      Double_t &z1,Double_t &z2,Double_t  c,Double_t  s);

#endif
 TDecompBase.h:1
 TDecompBase.h:2
 TDecompBase.h:3
 TDecompBase.h:4
 TDecompBase.h:5
 TDecompBase.h:6
 TDecompBase.h:7
 TDecompBase.h:8
 TDecompBase.h:9
 TDecompBase.h:10
 TDecompBase.h:11
 TDecompBase.h:12
 TDecompBase.h:13
 TDecompBase.h:14
 TDecompBase.h:15
 TDecompBase.h:16
 TDecompBase.h:17
 TDecompBase.h:18
 TDecompBase.h:19
 TDecompBase.h:20
 TDecompBase.h:21
 TDecompBase.h:22
 TDecompBase.h:23
 TDecompBase.h:24
 TDecompBase.h:25
 TDecompBase.h:26
 TDecompBase.h:27
 TDecompBase.h:28
 TDecompBase.h:29
 TDecompBase.h:30
 TDecompBase.h:31
 TDecompBase.h:32
 TDecompBase.h:33
 TDecompBase.h:34
 TDecompBase.h:35
 TDecompBase.h:36
 TDecompBase.h:37
 TDecompBase.h:38
 TDecompBase.h:39
 TDecompBase.h:40
 TDecompBase.h:41
 TDecompBase.h:42
 TDecompBase.h:43
 TDecompBase.h:44
 TDecompBase.h:45
 TDecompBase.h:46
 TDecompBase.h:47
 TDecompBase.h:48
 TDecompBase.h:49
 TDecompBase.h:50
 TDecompBase.h:51
 TDecompBase.h:52
 TDecompBase.h:53
 TDecompBase.h:54
 TDecompBase.h:55
 TDecompBase.h:56
 TDecompBase.h:57
 TDecompBase.h:58
 TDecompBase.h:59
 TDecompBase.h:60
 TDecompBase.h:61
 TDecompBase.h:62
 TDecompBase.h:63
 TDecompBase.h:64
 TDecompBase.h:65
 TDecompBase.h:66
 TDecompBase.h:67
 TDecompBase.h:68
 TDecompBase.h:69
 TDecompBase.h:70
 TDecompBase.h:71
 TDecompBase.h:72
 TDecompBase.h:73
 TDecompBase.h:74
 TDecompBase.h:75
 TDecompBase.h:76
 TDecompBase.h:77
 TDecompBase.h:78
 TDecompBase.h:79
 TDecompBase.h:80
 TDecompBase.h:81
 TDecompBase.h:82
 TDecompBase.h:83
 TDecompBase.h:84
 TDecompBase.h:85
 TDecompBase.h:86
 TDecompBase.h:87
 TDecompBase.h:88
 TDecompBase.h:89
 TDecompBase.h:90
 TDecompBase.h:91
 TDecompBase.h:92
 TDecompBase.h:93
 TDecompBase.h:94
 TDecompBase.h:95
 TDecompBase.h:96
 TDecompBase.h:97
 TDecompBase.h:98
 TDecompBase.h:99
 TDecompBase.h:100
 TDecompBase.h:101
 TDecompBase.h:102
 TDecompBase.h:103
 TDecompBase.h:104
 TDecompBase.h:105
 TDecompBase.h:106
 TDecompBase.h:107
 TDecompBase.h:108
 TDecompBase.h:109
 TDecompBase.h:110
 TDecompBase.h:111
 TDecompBase.h:112
 TDecompBase.h:113
 TDecompBase.h:114
 TDecompBase.h:115