Homepage Demos Overview Downloads Tutorials Reference
Credits

newmat.h

Go to the documentation of this file.
00001 //$$ newmat.h           definition file for new version of matrix package
00002 
00003 // Copyright (C) 1991,2,3,4,7,2000,2,3: R B Davies
00004 
00005 #ifndef NEWMAT_LIB
00006 #define NEWMAT_LIB 0
00007 
00008 #include "include.h"
00009 
00010 #include "myexcept.h"
00011 
00012 
00013 #ifdef use_namespace
00014 namespace NEWMAT { using namespace RBD_COMMON; }
00015 namespace RBD_LIBRARIES { using namespace NEWMAT; }
00016 namespace NEWMAT {
00017 #endif
00018 
00019 //#define DO_REPORT                     // to activate REPORT
00020 
00021 #ifdef NO_LONG_NAMES
00022 #define UpperTriangularMatrix UTMatrix
00023 #define LowerTriangularMatrix LTMatrix
00024 #define SymmetricMatrix SMatrix
00025 #define DiagonalMatrix DMatrix
00026 #define BandMatrix BMatrix
00027 #define UpperBandMatrix UBMatrix
00028 #define LowerBandMatrix LBMatrix
00029 #define SymmetricBandMatrix SBMatrix
00030 #define BandLUMatrix BLUMatrix
00031 #endif
00032 
00033 // ************************** general utilities ****************************/
00034 
00035 class GeneralMatrix;
00036 
00037 void MatrixErrorNoSpace(const void*);                 // no space handler
00038 
00039 class LogAndSign
00040 // Return from LogDeterminant function
00041 //    - value of the log plus the sign (+, - or 0)
00042 {
00043    Real log_value;
00044    int sign;
00045 public:
00046    LogAndSign() { log_value=0.0; sign=1; }
00047    LogAndSign(Real);
00048    void operator*=(Real);
00049    void PowEq(int k);  // raise to power of k
00050    void ChangeSign() { sign = -sign; }
00051    Real LogValue() const { return log_value; }
00052    int Sign() const { return sign; }
00053    Real Value() const;
00054    FREE_CHECK(LogAndSign)
00055 };
00056 
00057 // the following class is for counting the number of times a piece of code
00058 // is executed. It is used for locating any code not executed by test
00059 // routines. Use turbo GREP locate all places this code is called and
00060 // check which ones are not accessed.
00061 // Somewhat implementation dependent as it relies on "cout" still being
00062 // present when ExeCounter objects are destructed.
00063 
00064 #ifdef DO_REPORT
00065 
00066 class ExeCounter
00067 {
00068    int line;                                    // code line number
00069    int fileid;                                  // file identifier
00070    long nexe;                                   // number of executions
00071    static int nreports;                         // number of reports
00072 public:
00073    ExeCounter(int,int);
00074    void operator++() { nexe++; }
00075    ~ExeCounter();                               // prints out reports
00076 };
00077 
00078 #endif
00079 
00080 
00081 // ************************** class MatrixType *****************************/
00082 
00083 // Is used for finding the type of a matrix resulting from the binary operations
00084 // +, -, * and identifying what conversions are permissible.
00085 // This class must be updated when new matrix types are added.
00086 
00087 class GeneralMatrix;                            // defined later
00088 class BaseMatrix;                               // defined later
00089 class MatrixInput;                              // defined later
00090 
00091 class MatrixType
00092 {
00093 public:
00094    enum Attribute {  Valid     = 1,
00095                      Diagonal  = 2,             // order of these is important
00096                      Symmetric = 4,
00097                      Band      = 8,
00098                      Lower     = 16,
00099                      Upper     = 32,
00100                      Square    = 64,
00101                      Skew      = 128,
00102                      LUDeco    = 256,
00103                      Ones      = 512 };
00104 
00105    enum            { US = 0,
00106                      UT = Valid + Upper + Square,
00107                      LT = Valid + Lower + Square,
00108                      Rt = Valid,
00109                      Sq = Valid + Square,
00110                      Sm = Valid + Symmetric + Square,
00111                      Sk = Valid + Skew + Square,
00112                      Dg = Valid + Diagonal + Band + Lower + Upper + Symmetric
00113                         + Square,
00114                      Id = Valid + Diagonal + Band + Lower + Upper + Symmetric
00115                         + Square + Ones,
00116                      RV = Valid,     //   do not separate out
00117                      CV = Valid,     //   vectors
00118                      BM = Valid + Band + Square,
00119                      UB = Valid + Band + Upper + Square,
00120                      LB = Valid + Band + Lower + Square,
00121                      SB = Valid + Band + Symmetric + Square,
00122                      Ct = Valid + LUDeco + Square,
00123                      BC = Valid + Band + LUDeco + Square,
00124                      Mask = ~Square
00125                    };
00126 
00127 
00128    static int nTypes() { return 12; }          // number of different types
00129                  // exclude Ct, US, BC
00130 public:
00131    int attribute;
00132    bool DataLossOK;                            // true if data loss is OK when
00133                                                // this represents a destination
00134 public:
00135    MatrixType () : DataLossOK(false) {}
00136    MatrixType (int i) : attribute(i), DataLossOK(false) {}
00137    MatrixType (int i, bool dlok) : attribute(i), DataLossOK(dlok) {}
00138    MatrixType (const MatrixType& mt)
00139       : attribute(mt.attribute), DataLossOK(mt.DataLossOK) {}
00140    void operator=(const MatrixType& mt)
00141       { attribute = mt.attribute; DataLossOK = mt.DataLossOK; }
00142    void SetDataLossOK() { DataLossOK = true; }
00143    int operator+() const { return attribute; }
00144    MatrixType operator+(MatrixType mt) const
00145       { return MatrixType(attribute & mt.attribute); }
00146    MatrixType operator*(const MatrixType&) const;
00147    MatrixType SP(const MatrixType&) const;
00148    MatrixType KP(const MatrixType&) const;
00149    MatrixType operator|(const MatrixType& mt) const
00150       { return MatrixType(attribute & mt.attribute & Valid); }
00151    MatrixType operator&(const MatrixType& mt) const
00152       { return MatrixType(attribute & mt.attribute & Valid); }
00153    bool operator>=(MatrixType mt) const
00154       { return ( attribute & ~mt.attribute & Mask ) == 0; }
00155    bool operator<(MatrixType mt) const         // for MS Visual C++ 4
00156       { return ( attribute & ~mt.attribute & Mask ) != 0; }
00157    bool operator==(MatrixType t) const
00158       { return (attribute == t.attribute); }
00159    bool operator!=(MatrixType t) const
00160       { return (attribute != t.attribute); }
00161    bool operator!() const { return (attribute & Valid) == 0; }
00162    MatrixType i() const;                       // type of inverse
00163    MatrixType t() const;                       // type of transpose
00164    MatrixType AddEqualEl() const               // Add constant to matrix
00165       { return MatrixType(attribute & (Valid + Symmetric + Square)); }
00166    MatrixType MultRHS() const;                 // type for rhs of multiply
00167    MatrixType sub() const                      // type of submatrix
00168       { return MatrixType(attribute & Valid); }
00169    MatrixType ssub() const                     // type of sym submatrix
00170       { return MatrixType(attribute); }        // not for selection matrix
00171    GeneralMatrix* New() const;                 // new matrix of given type
00172    GeneralMatrix* New(int,int,BaseMatrix*) const;
00173                                                // new matrix of given type
00174    const char* Value() const;                  // to print type
00175    friend bool Rectangular(MatrixType a, MatrixType b, MatrixType c);
00176    friend bool Compare(const MatrixType&, MatrixType&);
00177                                                // compare and check conv.
00178    bool IsBand() const { return (attribute & Band) != 0; }
00179    bool IsDiagonal() const { return (attribute & Diagonal) != 0; }
00180    bool IsSymmetric() const { return (attribute & Symmetric) != 0; }
00181    bool CannotConvert() const { return (attribute & LUDeco) != 0; }
00182                                                // used by operator== 
00183    FREE_CHECK(MatrixType)
00184 };
00185 
00186 
00187 // *********************** class MatrixBandWidth ***********************/
00188 
00189 class MatrixBandWidth
00190 {
00191 public:
00192    int lower;
00193    int upper;
00194    MatrixBandWidth(const int l, const int u) : lower(l), upper (u) {}
00195    MatrixBandWidth(const int i) : lower(i), upper(i) {}
00196    MatrixBandWidth operator+(const MatrixBandWidth&) const;
00197    MatrixBandWidth operator*(const MatrixBandWidth&) const;
00198    MatrixBandWidth minimum(const MatrixBandWidth&) const;
00199    MatrixBandWidth t() const { return MatrixBandWidth(upper,lower); }
00200    bool operator==(const MatrixBandWidth& bw) const
00201       { return (lower == bw.lower) && (upper == bw.upper); }
00202    bool operator!=(const MatrixBandWidth& bw) const { return !operator==(bw); }
00203    int Upper() const { return upper; }
00204    int Lower() const { return lower; }
00205    FREE_CHECK(MatrixBandWidth)
00206 };
00207 
00208 
00209 // ********************* Array length specifier ************************/
00210 
00211 // This class is introduced to avoid constructors such as
00212 //   ColumnVector(int)
00213 // being used for conversions
00214 
00215 class ArrayLengthSpecifier
00216 {
00217    int value;
00218 public:
00219    int Value() const { return value; }
00220    ArrayLengthSpecifier(int l) : value(l) {}
00221 };
00222 
00223 // ************************* Matrix routines ***************************/
00224 
00225 
00226 class MatrixRowCol;                             // defined later
00227 class MatrixRow;
00228 class MatrixCol;
00229 class MatrixColX;
00230 
00231 class GeneralMatrix;                            // defined later
00232 class AddedMatrix;
00233 class MultipliedMatrix;
00234 class SubtractedMatrix;
00235 class SPMatrix;
00236 class KPMatrix;
00237 class ConcatenatedMatrix;
00238 class StackedMatrix;
00239 class SolvedMatrix;
00240 class ShiftedMatrix;
00241 class NegShiftedMatrix;
00242 class ScaledMatrix;
00243 class TransposedMatrix;
00244 class ReversedMatrix;
00245 class NegatedMatrix;
00246 class InvertedMatrix;
00247 class RowedMatrix;
00248 class ColedMatrix;
00249 class DiagedMatrix;
00250 class MatedMatrix;
00251 class GetSubMatrix;
00252 class ReturnMatrix;
00253 class Matrix;
00254 class SquareMatrix;
00255 class nricMatrix;
00256 class RowVector;
00257 class ColumnVector;
00258 class SymmetricMatrix;
00259 class UpperTriangularMatrix;
00260 class LowerTriangularMatrix;
00261 class DiagonalMatrix;
00262 class CroutMatrix;
00263 class BandMatrix;
00264 class LowerBandMatrix;
00265 class UpperBandMatrix;
00266 class SymmetricBandMatrix;
00267 class LinearEquationSolver;
00268 class GenericMatrix;
00269 
00270 
00271 #define MatrixTypeUnSp 0
00272 //static MatrixType MatrixTypeUnSp(MatrixType::US);
00273 //            // AT&T needs this
00274 
00275 class BaseMatrix : public Janitor               // base of all matrix classes
00276 {
00277 protected:
00278    virtual int search(const BaseMatrix*) const = 0;
00279             // count number of times matrix
00280               // is referred to
00281 
00282 public:
00283    virtual GeneralMatrix* Evaluate(MatrixType mt=MatrixTypeUnSp) = 0;
00284             // evaluate temporary
00285    // for old version of G++
00286    //   virtual GeneralMatrix* Evaluate(MatrixType mt) = 0;
00287    //   GeneralMatrix* Evaluate() { return Evaluate(MatrixTypeUnSp); }
00288    AddedMatrix operator+(const BaseMatrix&) const;    // results of operations
00289    MultipliedMatrix operator*(const BaseMatrix&) const;
00290    SubtractedMatrix operator-(const BaseMatrix&) const;
00291    ConcatenatedMatrix operator|(const BaseMatrix&) const;
00292    StackedMatrix operator&(const BaseMatrix&) const;
00293    ShiftedMatrix operator+(Real) const;
00294    ScaledMatrix operator*(Real) const;
00295    ScaledMatrix operator/(Real) const;
00296    ShiftedMatrix operator-(Real) const;
00297    TransposedMatrix t() const;
00298 //   TransposedMatrix t;
00299    NegatedMatrix operator-() const;                   // change sign of elements
00300    ReversedMatrix Reverse() const;
00301    InvertedMatrix i() const;
00302 //   InvertedMatrix i;
00303    RowedMatrix AsRow() const;
00304    ColedMatrix AsColumn() const;
00305    DiagedMatrix AsDiagonal() const;
00306    MatedMatrix AsMatrix(int,int) const;
00307    GetSubMatrix SubMatrix(int,int,int,int) const;
00308    GetSubMatrix SymSubMatrix(int,int) const;
00309    GetSubMatrix Row(int) const;
00310    GetSubMatrix Rows(int,int) const;
00311    GetSubMatrix Column(int) const;
00312    GetSubMatrix Columns(int,int) const;
00313    Real AsScalar() const;                      // conversion of 1 x 1 matrix
00314    virtual LogAndSign LogDeterminant() const;
00315    Real Determinant() const;
00316    virtual Real SumSquare() const;
00317    Real NormFrobenius() const;
00318    virtual Real SumAbsoluteValue() const;
00319    virtual Real Sum() const;
00320    virtual Real MaximumAbsoluteValue() const;
00321    virtual Real MaximumAbsoluteValue1(int& i) const;
00322    virtual Real MaximumAbsoluteValue2(int& i, int& j) const;
00323    virtual Real MinimumAbsoluteValue() const;
00324    virtual Real MinimumAbsoluteValue1(int& i) const;
00325    virtual Real MinimumAbsoluteValue2(int& i, int& j) const;
00326    virtual Real Maximum() const;
00327    virtual Real Maximum1(int& i) const;
00328    virtual Real Maximum2(int& i, int& j) const;
00329    virtual Real Minimum() const;
00330    virtual Real Minimum1(int& i) const;
00331    virtual Real Minimum2(int& i, int& j) const;
00332    virtual Real Trace() const;
00333    Real Norm1() const;
00334    Real NormInfinity() const;
00335    virtual MatrixBandWidth BandWidth() const;  // bandwidths of band matrix
00336    virtual void CleanUp() {}                   // to clear store
00337    void IEQND() const;                         // called by ineq. ops
00338 //   virtual ReturnMatrix Reverse() const;       // reverse order of elements
00339 //protected:
00340 //   BaseMatrix() : t(this), i(this) {}
00341 
00342    friend class GeneralMatrix;
00343    friend class Matrix;
00344    friend class SquareMatrix;
00345    friend class nricMatrix;
00346    friend class RowVector;
00347    friend class ColumnVector;
00348    friend class SymmetricMatrix;
00349    friend class UpperTriangularMatrix;
00350    friend class LowerTriangularMatrix;
00351    friend class DiagonalMatrix;
00352    friend class CroutMatrix;
00353    friend class BandMatrix;
00354    friend class LowerBandMatrix;
00355    friend class UpperBandMatrix;
00356    friend class SymmetricBandMatrix;
00357    friend class AddedMatrix;
00358    friend class MultipliedMatrix;
00359    friend class SubtractedMatrix;
00360    friend class SPMatrix;
00361    friend class KPMatrix;
00362    friend class ConcatenatedMatrix;
00363    friend class StackedMatrix;
00364    friend class SolvedMatrix;
00365    friend class ShiftedMatrix;
00366    friend class NegShiftedMatrix;
00367    friend class ScaledMatrix;
00368    friend class TransposedMatrix;
00369    friend class ReversedMatrix;
00370    friend class NegatedMatrix;
00371    friend class InvertedMatrix;
00372    friend class RowedMatrix;
00373    friend class ColedMatrix;
00374    friend class DiagedMatrix;
00375    friend class MatedMatrix;
00376    friend class GetSubMatrix;
00377    friend class ReturnMatrix;
00378    friend class LinearEquationSolver;
00379    friend class GenericMatrix;
00380    NEW_DELETE(BaseMatrix)
00381 };
00382 
00383 
00384 // ***************************** working classes **************************/
00385 
00386 class GeneralMatrix : public BaseMatrix         // declarable matrix types
00387 {
00388    virtual GeneralMatrix* Image() const;        // copy of matrix
00389 protected:
00390    int tag;                                     // shows whether can reuse
00391    int nrows_value, ncols_value;                // dimensions
00392    int storage;                                 // total store required
00393    Real* store;                                 // point to store (0=not set)
00394    GeneralMatrix();                             // initialise with no store
00395    GeneralMatrix(ArrayLengthSpecifier);         // constructor getting store
00396    void Add(GeneralMatrix*, Real);              // sum of GM and Real
00397    void Add(Real);                              // add Real to this
00398    void NegAdd(GeneralMatrix*, Real);           // Real - GM
00399    void NegAdd(Real);                           // this = this - Real
00400    void Multiply(GeneralMatrix*, Real);         // product of GM and Real
00401    void Multiply(Real);                         // multiply this by Real
00402    void Negate(GeneralMatrix*);                 // change sign
00403    void Negate();                               // change sign
00404    void ReverseElements();                      // internal reverse of elements
00405    void ReverseElements(GeneralMatrix*);        // reverse order of elements
00406    void operator=(Real);                        // set matrix to constant
00407    Real* GetStore();                            // get store or copy
00408    GeneralMatrix* BorrowStore(GeneralMatrix*, MatrixType);
00409                                                 // temporarily access store
00410    void GetMatrix(const GeneralMatrix*);        // used by = and initialise
00411    void Eq(const BaseMatrix&, MatrixType);      // used by =
00412    void Eq(const GeneralMatrix&);               // version with no conversion
00413    void Eq(const BaseMatrix&, MatrixType, bool);// used by <<
00414    void Eq2(const BaseMatrix&, MatrixType);     // cut down version of Eq
00415    int search(const BaseMatrix*) const;
00416    virtual GeneralMatrix* Transpose(TransposedMatrix*, MatrixType);
00417    void CheckConversion(const BaseMatrix&);     // check conversion OK
00418    void ReSize(int, int, int);                  // change dimensions
00419    virtual short SimpleAddOK(const GeneralMatrix* /*gm*/) { return 0; }
00420              // see bandmat.cpp for explanation
00421    virtual void MiniCleanUp()
00422       { store = 0; storage = 0; nrows_value = 0; ncols_value = 0; tag = -1;}
00423              // CleanUp when the data array has already been deleted
00424    void PlusEqual(const GeneralMatrix& gm);
00425    void MinusEqual(const GeneralMatrix& gm);
00426    void PlusEqual(Real f);
00427    void MinusEqual(Real f);
00428    void swap(GeneralMatrix& gm);                // swap values
00429 public:
00430    GeneralMatrix* Evaluate(MatrixType mt=MatrixTypeUnSp);
00431    virtual MatrixType Type() const = 0;         // type of a matrix
00432    int Nrows() const { return nrows_value; }    // get dimensions
00433    int Ncols() const { return ncols_value; }
00434    int Storage() const { return storage; }
00435    Real* Store() const { return store; }
00436    // updated names
00437    int nrows() const { return nrows_value; }    // get dimensions
00438    int ncols() const { return ncols_value; }
00439    int size() const { return storage; }
00440    Real* data() { return store; }
00441    const Real* data() const { return store; }
00442    const Real* const_data() const { return store; }
00443    virtual ~GeneralMatrix();                    // delete store if set
00444    void tDelete();                              // delete if tag permits
00445    bool reuse();                                // true if tag allows reuse
00446    void Protect() { tag=-1; }                   // cannot delete or reuse
00447    int Tag() const { return tag; }
00448    bool IsZero() const;                         // test matrix has all zeros
00449    void Release() { tag=1; }                    // del store after next use
00450    void Release(int t) { tag=t; }               // del store after t accesses
00451    void ReleaseAndDelete() { tag=0; }           // delete matrix after use
00452    void operator<<(const Real*);                // assignment from an array
00453    void operator<<(const int*);                // assignment from an array
00454    void operator<<(const BaseMatrix& X)
00455       { Eq(X,this->Type(),true); }              // = without checking type
00456    void Inject(const GeneralMatrix&);           // copy stored els only
00457    void operator+=(const BaseMatrix&);
00458    void operator-=(const BaseMatrix&);
00459    void operator*=(const BaseMatrix&);
00460    void operator|=(const BaseMatrix&);
00461    void operator&=(const BaseMatrix&);
00462    void operator+=(Real);
00463    void operator-=(Real r) { operator+=(-r); }
00464    void operator*=(Real);
00465    void operator/=(Real r) { operator*=(1.0/r); }
00466    virtual GeneralMatrix* MakeSolver();         // for solving
00467    virtual void Solver(MatrixColX&, const MatrixColX&) {}
00468    virtual void GetRow(MatrixRowCol&) = 0;      // Get matrix row
00469    virtual void RestoreRow(MatrixRowCol&) {}    // Restore matrix row
00470    virtual void NextRow(MatrixRowCol&);         // Go to next row
00471    virtual void GetCol(MatrixRowCol&) = 0;      // Get matrix col
00472    virtual void GetCol(MatrixColX&) = 0;        // Get matrix col
00473    virtual void RestoreCol(MatrixRowCol&) {}    // Restore matrix col
00474    virtual void RestoreCol(MatrixColX&) {}      // Restore matrix col
00475    virtual void NextCol(MatrixRowCol&);         // Go to next col
00476    virtual void NextCol(MatrixColX&);           // Go to next col
00477    Real SumSquare() const;
00478    Real SumAbsoluteValue() const;
00479    Real Sum() const;
00480    Real MaximumAbsoluteValue1(int& i) const;
00481    Real MinimumAbsoluteValue1(int& i) const;
00482    Real Maximum1(int& i) const;
00483    Real Minimum1(int& i) const;
00484    Real MaximumAbsoluteValue() const;
00485    Real MaximumAbsoluteValue2(int& i, int& j) const;
00486    Real MinimumAbsoluteValue() const;
00487    Real MinimumAbsoluteValue2(int& i, int& j) const;
00488    Real Maximum() const;
00489    Real Maximum2(int& i, int& j) const;
00490    Real Minimum() const;
00491    Real Minimum2(int& i, int& j) const;
00492    LogAndSign LogDeterminant() const;
00493    virtual bool IsEqual(const GeneralMatrix&) const;
00494                                                 // same type, same values
00495    void CheckStore() const;                     // check store is non-zero
00496    virtual void SetParameters(const GeneralMatrix*) {}
00497                                                 // set parameters in GetMatrix
00498    operator ReturnMatrix() const;               // for building a ReturnMatrix
00499    ReturnMatrix ForReturn() const;
00500    virtual bool SameStorageType(const GeneralMatrix& A) const;
00501    virtual void ReSizeForAdd(const GeneralMatrix& A, const GeneralMatrix& B);
00502    virtual void ReSizeForSP(const GeneralMatrix& A, const GeneralMatrix& B);
00503    virtual void ReSize(const GeneralMatrix& A);
00504    MatrixInput operator<<(Real);                // for loading a list
00505    MatrixInput operator<<(int f);
00506 //   ReturnMatrix Reverse() const;                // reverse order of elements
00507    void CleanUp();                              // to clear store
00508 
00509    friend class Matrix;
00510    friend class SquareMatrix;
00511    friend class nricMatrix;
00512    friend class SymmetricMatrix;
00513    friend class UpperTriangularMatrix;
00514    friend class LowerTriangularMatrix;
00515    friend class DiagonalMatrix;
00516    friend class CroutMatrix;
00517    friend class RowVector;
00518    friend class ColumnVector;
00519    friend class BandMatrix;
00520    friend class LowerBandMatrix;
00521    friend class UpperBandMatrix;
00522    friend class SymmetricBandMatrix;
00523    friend class BaseMatrix;
00524    friend class AddedMatrix;
00525    friend class MultipliedMatrix;
00526    friend class SubtractedMatrix;
00527    friend class SPMatrix;
00528    friend class KPMatrix;
00529    friend class ConcatenatedMatrix;
00530    friend class StackedMatrix;
00531    friend class SolvedMatrix;
00532    friend class ShiftedMatrix;
00533    friend class NegShiftedMatrix;
00534    friend class ScaledMatrix;
00535    friend class TransposedMatrix;
00536    friend class ReversedMatrix;
00537    friend class NegatedMatrix;
00538    friend class InvertedMatrix;
00539    friend class RowedMatrix;
00540    friend class ColedMatrix;
00541    friend class DiagedMatrix;
00542    friend class MatedMatrix;
00543    friend class GetSubMatrix;
00544    friend class ReturnMatrix;
00545    friend class LinearEquationSolver;
00546    friend class GenericMatrix;
00547    NEW_DELETE(GeneralMatrix)
00548 };
00549 
00550 
00551 
00552 class Matrix : public GeneralMatrix             // usual rectangular matrix
00553 {
00554    GeneralMatrix* Image() const;                // copy of matrix
00555 public:
00556    Matrix() {}
00557    ~Matrix() {}
00558    Matrix(int, int);                            // standard declaration
00559    Matrix(const BaseMatrix&);                   // evaluate BaseMatrix
00560    void operator=(const BaseMatrix&);
00561    void operator=(Real f) { GeneralMatrix::operator=(f); }
00562    void operator=(const Matrix& m) { Eq(m); }
00563    MatrixType Type() const;
00564    Real& operator()(int, int);                  // access element
00565    Real& element(int, int);                     // access element
00566    Real operator()(int, int) const;            // access element
00567    Real element(int, int) const;               // access element
00568 #ifdef SETUP_C_SUBSCRIPTS
00569    Real* operator[](int m) { return store+m*ncols_value; }
00570    const Real* operator[](int m) const { return store+m*ncols_value; }
00571    // following for Numerical Recipes in C++
00572    Matrix(Real, int, int);
00573    Matrix(const Real*, int, int);
00574 #endif
00575    Matrix(const Matrix& gm) : GeneralMatrix() { GetMatrix(&gm); }
00576    GeneralMatrix* MakeSolver();
00577    Real Trace() const;
00578    void GetRow(MatrixRowCol&);
00579    void GetCol(MatrixRowCol&);
00580    void GetCol(MatrixColX&);
00581    void RestoreCol(MatrixRowCol&);
00582    void RestoreCol(MatrixColX&);
00583    void NextRow(MatrixRowCol&);
00584    void NextCol(MatrixRowCol&);
00585    void NextCol(MatrixColX&);
00586    virtual void ReSize(int,int);           // change dimensions
00587       // virtual so we will catch it being used in a vector called as a matrix
00588    void ReSize(const GeneralMatrix& A);
00589    Real MaximumAbsoluteValue2(int& i, int& j) const;
00590    Real MinimumAbsoluteValue2(int& i, int& j) const;
00591    Real Maximum2(int& i, int& j) const;
00592    Real Minimum2(int& i, int& j) const;
00593    void operator+=(const Matrix& M) { PlusEqual(M); }
00594    void operator-=(const Matrix& M) { MinusEqual(M); }
00595    void operator+=(Real f) { GeneralMatrix::Add(f); }
00596    void operator-=(Real f) { GeneralMatrix::Add(-f); }
00597    void swap(Matrix& gm) { GeneralMatrix::swap((GeneralMatrix&)gm); }
00598    friend Real DotProduct(const Matrix& A, const Matrix& B);
00599    NEW_DELETE(Matrix)
00600 };
00601 
00602 class SquareMatrix : public Matrix              // square matrix
00603 {
00604    GeneralMatrix* Image() const;                // copy of matrix
00605 public:
00606    SquareMatrix() {}
00607    ~SquareMatrix() {}
00608    SquareMatrix(ArrayLengthSpecifier);          // standard declaration
00609    SquareMatrix(const BaseMatrix&);             // evaluate BaseMatrix
00610    void operator=(const BaseMatrix&);
00611    void operator=(Real f) { GeneralMatrix::operator=(f); }
00612    void operator=(const SquareMatrix& m) { Eq(m); }
00613    void operator=(const Matrix& m);
00614    MatrixType Type() const;
00615    SquareMatrix(const SquareMatrix& gm) : Matrix() { GetMatrix(&gm); }
00616    SquareMatrix(const Matrix& gm);
00617    void ReSize(int);                            // change dimensions
00618    virtual void ReSize(int,int);                // change dimensions
00619       // virtual so we will catch it being used in a vector called as a matrix
00620    void ReSize(const GeneralMatrix& A);
00621    void operator+=(const Matrix& M) { PlusEqual(M); }
00622    void operator-=(const Matrix& M) { MinusEqual(M); }
00623    void operator+=(Real f) { GeneralMatrix::Add(f); }
00624    void operator-=(Real f) { GeneralMatrix::Add(-f); }
00625    void swap(SquareMatrix& gm) { GeneralMatrix::swap((GeneralMatrix&)gm); }
00626    NEW_DELETE(SquareMatrix)
00627 };
00628 
00629 class nricMatrix : public Matrix                // for use with Numerical
00630                                                 // Recipes in C
00631 {
00632    GeneralMatrix* Image() const;                // copy of matrix
00633    Real** row_pointer;                          // points to rows
00634    void MakeRowPointer();                       // build rowpointer
00635    void DeleteRowPointer();
00636 public:
00637    nricMatrix() {}
00638    nricMatrix(int m, int n)                     // standard declaration
00639       :  Matrix(m,n) { MakeRowPointer(); }
00640    nricMatrix(const BaseMatrix& bm)             // evaluate BaseMatrix
00641       :  Matrix(bm) { MakeRowPointer(); }
00642    void operator=(const BaseMatrix& bm)
00643       { DeleteRowPointer(); Matrix::operator=(bm); MakeRowPointer(); }
00644    void operator=(Real f) { GeneralMatrix::operator=(f); }
00645    void operator=(const nricMatrix& m)
00646       { DeleteRowPointer(); Eq(m); MakeRowPointer(); }
00647    void operator<<(const BaseMatrix& X)
00648       { DeleteRowPointer(); Eq(X,this->Type(),true); MakeRowPointer(); }
00649    nricMatrix(const nricMatrix& gm) : Matrix() { GetMatrix(&gm); MakeRowPointer(); }
00650    void ReSize(int m, int n)               // change dimensions
00651       { DeleteRowPointer(); Matrix::ReSize(m,n); MakeRowPointer(); }
00652    void ReSize(const GeneralMatrix& A);
00653    ~nricMatrix() { DeleteRowPointer(); }
00654    Real** nric() const { CheckStore(); return row_pointer-1; }
00655    void CleanUp();                                // to clear store
00656    void MiniCleanUp();
00657    void operator+=(const Matrix& M) { PlusEqual(M); }
00658    void operator-=(const Matrix& M) { MinusEqual(M); }
00659    void operator+=(Real f) { GeneralMatrix::Add(f); }
00660    void operator-=(Real f) { GeneralMatrix::Add(-f); }
00661    void swap(nricMatrix& gm);
00662    NEW_DELETE(nricMatrix)
00663 };
00664 
00665 class SymmetricMatrix : public GeneralMatrix
00666 {
00667    GeneralMatrix* Image() const;                // copy of matrix
00668 public:
00669    SymmetricMatrix() {}
00670    ~SymmetricMatrix() {}
00671    SymmetricMatrix(ArrayLengthSpecifier);
00672    SymmetricMatrix(const BaseMatrix&);
00673    void operator=(const BaseMatrix&);
00674    void operator=(Real f) { GeneralMatrix::operator=(f); }
00675    void operator=(const SymmetricMatrix& m) { Eq(m); }
00676    Real& operator()(int, int);                  // access element
00677    Real& element(int, int);                     // access element
00678    Real operator()(int, int) const;             // access element
00679    Real element(int, int) const;                // access element
00680 #ifdef SETUP_C_SUBSCRIPTS
00681    Real* operator[](int m) { return store+(m*(m+1))/2; }
00682    const Real* operator[](int m) const { return store+(m*(m+1))/2; }
00683 #endif
00684    MatrixType Type() const;
00685    SymmetricMatrix(const SymmetricMatrix& gm) : GeneralMatrix() { GetMatrix(&gm); }
00686    Real SumSquare() const;
00687    Real SumAbsoluteValue() const;
00688    Real Sum() const;
00689    Real Trace() const;
00690    void GetRow(MatrixRowCol&);
00691    void GetCol(MatrixRowCol&);
00692    void GetCol(MatrixColX&);
00693    void RestoreCol(MatrixRowCol&) {}
00694    void RestoreCol(MatrixColX&);
00695   GeneralMatrix* Transpose(TransposedMatrix*, MatrixType);
00696    void ReSize(int);                       // change dimensions
00697    void ReSize(const GeneralMatrix& A);
00698    void operator+=(const SymmetricMatrix& M) { PlusEqual(M); }
00699    void operator-=(const SymmetricMatrix& M) { MinusEqual(M); }
00700    void operator+=(Real f) { GeneralMatrix::Add(f); }
00701    void operator-=(Real f) { GeneralMatrix::Add(-f); }
00702    void swap(SymmetricMatrix& gm) { GeneralMatrix::swap((GeneralMatrix&)gm); }
00703    NEW_DELETE(SymmetricMatrix)
00704 };
00705 
00706 class UpperTriangularMatrix : public GeneralMatrix
00707 {
00708    GeneralMatrix* Image() const;                // copy of matrix
00709 public:
00710    UpperTriangularMatrix() {}
00711    ~UpperTriangularMatrix() {}
00712    UpperTriangularMatrix(ArrayLengthSpecifier);
00713    void operator=(const BaseMatrix&);
00714    void operator=(const UpperTriangularMatrix& m) { Eq(m); }
00715    UpperTriangularMatrix(const BaseMatrix&);
00716    UpperTriangularMatrix(const UpperTriangularMatrix& gm) : GeneralMatrix() { GetMatrix(&gm); }
00717    void operator=(Real f) { GeneralMatrix::operator=(f); }
00718    Real& operator()(int, int);                  // access element
00719    Real& element(int, int);                     // access element
00720    Real operator()(int, int) const;             // access element
00721    Real element(int, int) const;                // access element
00722 #ifdef SETUP_C_SUBSCRIPTS
00723    Real* operator[](int m) { return store+m*ncols_value-(m*(m+1))/2; }
00724    const Real* operator[](int m) const
00725       { return store+m*ncols_value-(m*(m+1))/2; }
00726 #endif
00727    MatrixType Type() const;
00728    GeneralMatrix* MakeSolver() { return this; } // for solving
00729    void Solver(MatrixColX&, const MatrixColX&);
00730    LogAndSign LogDeterminant() const;
00731    Real Trace() const;
00732    void GetRow(MatrixRowCol&);
00733    void GetCol(MatrixRowCol&);
00734    void GetCol(MatrixColX&);
00735    void RestoreCol(MatrixRowCol&);
00736    void RestoreCol(MatrixColX& c) { RestoreCol((MatrixRowCol&)c); }
00737    void NextRow(MatrixRowCol&);
00738    void ReSize(int);                       // change dimensions
00739    void ReSize(const GeneralMatrix& A);
00740    MatrixBandWidth BandWidth() const;
00741    void operator+=(const UpperTriangularMatrix& M) { PlusEqual(M); }
00742    void operator-=(const UpperTriangularMatrix& M) { MinusEqual(M); }
00743    void operator+=(Real f) { GeneralMatrix::operator+=(f); }
00744    void operator-=(Real f) { GeneralMatrix::operator-=(f); }
00745    void swap(UpperTriangularMatrix& gm)
00746       { GeneralMatrix::swap((GeneralMatrix&)gm); }
00747    NEW_DELETE(UpperTriangularMatrix)
00748 };
00749 
00750 class LowerTriangularMatrix : public GeneralMatrix
00751 {
00752    GeneralMatrix* Image() const;                // copy of matrix
00753 public:
00754    LowerTriangularMatrix() {}
00755    ~LowerTriangularMatrix() {}
00756    LowerTriangularMatrix(ArrayLengthSpecifier);
00757    LowerTriangularMatrix(const LowerTriangularMatrix& gm) : GeneralMatrix() { GetMatrix(&gm); }
00758    LowerTriangularMatrix(const BaseMatrix& M);
00759    void operator=(const BaseMatrix&);
00760    void operator=(Real f) { GeneralMatrix::operator=(f); }
00761    void operator=(const LowerTriangularMatrix& m) { Eq(m); }
00762    Real& operator()(int, int);                  // access element
00763    Real& element(int, int);                     // access element
00764    Real operator()(int, int) const;             // access element
00765    Real element(int, int) const;                // access element
00766 #ifdef SETUP_C_SUBSCRIPTS
00767    Real* operator[](int m) { return store+(m*(m+1))/2; }
00768    const Real* operator[](int m) const { return store+(m*(m+1))/2; }
00769 #endif
00770    MatrixType Type() const;
00771    GeneralMatrix* MakeSolver() { return this; } // for solving
00772    void Solver(MatrixColX&, const MatrixColX&);
00773    LogAndSign LogDeterminant() const;
00774    Real Trace() const;
00775    void GetRow(MatrixRowCol&);
00776    void GetCol(MatrixRowCol&);
00777    void GetCol(MatrixColX&);
00778    void RestoreCol(MatrixRowCol&);
00779    void RestoreCol(MatrixColX& c) { RestoreCol((MatrixRowCol&)c); }
00780    void NextRow(MatrixRowCol&);
00781    void ReSize(int);                       // change dimensions
00782    void ReSize(const GeneralMatrix& A);
00783    MatrixBandWidth BandWidth() const;
00784    void operator+=(const LowerTriangularMatrix& M) { PlusEqual(M); }
00785    void operator-=(const LowerTriangularMatrix& M) { MinusEqual(M); }
00786    void operator+=(Real f) { GeneralMatrix::operator+=(f); }
00787    void operator-=(Real f) { GeneralMatrix::operator-=(f); }
00788    void swap(LowerTriangularMatrix& gm)
00789       { GeneralMatrix::swap((GeneralMatrix&)gm); }
00790    NEW_DELETE(LowerTriangularMatrix)
00791 };
00792 
00793 class DiagonalMatrix : public GeneralMatrix
00794 {
00795    GeneralMatrix* Image() const;                // copy of matrix
00796 public:
00797    DiagonalMatrix() {}
00798    ~DiagonalMatrix() {}
00799    DiagonalMatrix(ArrayLengthSpecifier);
00800    DiagonalMatrix(const BaseMatrix&);
00801    DiagonalMatrix(const DiagonalMatrix& gm) : GeneralMatrix() { GetMatrix(&gm); }
00802    void operator=(const BaseMatrix&);
00803    void operator=(Real f) { GeneralMatrix::operator=(f); }
00804    void operator=(const DiagonalMatrix& m) { Eq(m); }
00805    Real& operator()(int, int);                  // access element
00806    Real& operator()(int);                       // access element
00807    Real operator()(int, int) const;             // access element
00808    Real operator()(int) const;
00809    Real& element(int, int);                     // access element
00810    Real& element(int);                          // access element
00811    Real element(int, int) const;                // access element
00812    Real element(int) const;                     // access element
00813 #ifdef SETUP_C_SUBSCRIPTS
00814    Real& operator[](int m) { return store[m]; }
00815    const Real& operator[](int m) const { return store[m]; }
00816 #endif
00817    MatrixType Type() const;
00818 
00819    LogAndSign LogDeterminant() const;
00820    Real Trace() const;
00821    void GetRow(MatrixRowCol&);
00822    void GetCol(MatrixRowCol&);
00823    void GetCol(MatrixColX&);
00824    void NextRow(MatrixRowCol&);
00825    void NextCol(MatrixRowCol&);
00826    void NextCol(MatrixColX&);
00827    GeneralMatrix* MakeSolver() { return this; } // for solving
00828    void Solver(MatrixColX&, const MatrixColX&);
00829    GeneralMatrix* Transpose(TransposedMatrix*, MatrixType);
00830    void ReSize(int);                       // change dimensions
00831    void ReSize(const GeneralMatrix& A);
00832    Real* nric() const
00833       { CheckStore(); return store-1; }         // for use by NRIC
00834    MatrixBandWidth BandWidth() const;
00835 //   ReturnMatrix Reverse() const;                // reverse order of elements
00836    void operator+=(const DiagonalMatrix& M) { PlusEqual(M); }
00837    void operator-=(const DiagonalMatrix& M) { MinusEqual(M); }
00838    void operator+=(Real f) { GeneralMatrix::operator+=(f); }
00839    void operator-=(Real f) { GeneralMatrix::operator-=(f); }
00840    void swap(DiagonalMatrix& gm)
00841       { GeneralMatrix::swap((GeneralMatrix&)gm); }
00842    NEW_DELETE(DiagonalMatrix)
00843 };
00844 
00845 class RowVector : public Matrix
00846 {
00847    GeneralMatrix* Image() const;                // copy of matrix
00848 public:
00849    RowVector() { nrows_value = 1; }
00850    ~RowVector() {}
00851    RowVector(ArrayLengthSpecifier n) : Matrix(1,n.Value()) {}
00852    RowVector(const BaseMatrix&);
00853    RowVector(const RowVector& gm) : Matrix() { GetMatrix(&gm); }
00854    void operator=(const BaseMatrix&);
00855    void operator=(Real f) { GeneralMatrix::operator=(f); }
00856    void operator=(const RowVector& m) { Eq(m); }
00857    Real& operator()(int);                       // access element
00858    Real& element(int);                          // access element
00859    Real operator()(int) const;                  // access element
00860    Real element(int) const;                     // access element
00861 #ifdef SETUP_C_SUBSCRIPTS
00862    Real& operator[](int m) { return store[m]; }
00863    const Real& operator[](int m) const { return store[m]; }
00864    // following for Numerical Recipes in C++
00865    RowVector(Real a, int n) : Matrix(a, 1, n) {}
00866    RowVector(const Real* a, int n) : Matrix(a, 1, n) {}
00867 #endif
00868    MatrixType Type() const;
00869    void GetCol(MatrixRowCol&);
00870    void GetCol(MatrixColX&);
00871    void NextCol(MatrixRowCol&);
00872    void NextCol(MatrixColX&);
00873    void RestoreCol(MatrixRowCol&) {}
00874    void RestoreCol(MatrixColX& c);
00875    GeneralMatrix* Transpose(TransposedMatrix*, MatrixType);
00876    void ReSize(int);                       // change dimensions
00877    void ReSize(int,int);                   // in case access is matrix
00878    void ReSize(const GeneralMatrix& A);
00879    Real* nric() const
00880       { CheckStore(); return store-1; }         // for use by NRIC
00881    void CleanUp();                              // to clear store
00882    void MiniCleanUp()
00883       { store = 0; storage = 0; nrows_value = 1; ncols_value = 0; tag = -1; }
00884    // friend ReturnMatrix GetMatrixRow(Matrix& A, int row);
00885    void operator+=(const Matrix& M) { PlusEqual(M); }
00886    void operator-=(const Matrix& M) { MinusEqual(M); }
00887    void operator+=(Real f) { GeneralMatrix::Add(f); }
00888    void operator-=(Real f) { GeneralMatrix::Add(-f); }
00889    void swap(RowVector& gm)
00890       { GeneralMatrix::swap((GeneralMatrix&)gm); }
00891    NEW_DELETE(RowVector)
00892 };
00893 
00894 class ColumnVector : public Matrix
00895 {
00896    GeneralMatrix* Image() const;                // copy of matrix
00897 public:
00898    ColumnVector() { ncols_value = 1; }
00899    ~ColumnVector() {}
00900    ColumnVector(ArrayLengthSpecifier n) : Matrix(n.Value(),1) {}
00901    ColumnVector(const BaseMatrix&);
00902    ColumnVector(const ColumnVector& gm) : Matrix() { GetMatrix(&gm); }
00903    void operator=(const BaseMatrix&);
00904    void operator=(Real f) { GeneralMatrix::operator=(f); }
00905    void operator=(const ColumnVector& m) { Eq(m); }
00906    Real& operator()(int);                       // access element
00907    Real& element(int);                          // access element
00908    Real operator()(int) const;                  // access element
00909    Real element(int) const;                     // access element
00910 #ifdef SETUP_C_SUBSCRIPTS
00911    Real& operator[](int m) { return store[m]; }
00912    const Real& operator[](int m) const { return store[m]; }
00913    // following for Numerical Recipes in C++
00914    ColumnVector(Real a, int m) : Matrix(a, m, 1) {}
00915    ColumnVector(const Real* a, int m) : Matrix(a, m, 1) {}
00916 #endif
00917    MatrixType Type() const;
00918    GeneralMatrix* Transpose(TransposedMatrix*, MatrixType);
00919    void ReSize(int);                       // change dimensions
00920    void ReSize(int,int);                   // in case access is matrix
00921    void ReSize(const GeneralMatrix& A);
00922    Real* nric() const
00923       { CheckStore(); return store-1; }         // for use by NRIC
00924    void CleanUp();                              // to clear store
00925    void MiniCleanUp()
00926       { store = 0; storage = 0; nrows_value = 0; ncols_value = 1; tag = -1; }
00927 //   ReturnMatrix Reverse() const;                // reverse order of elements
00928    void operator+=(const Matrix& M) { PlusEqual(M); }
00929    void operator-=(const Matrix& M) { MinusEqual(M); }
00930    void operator+=(Real f) { GeneralMatrix::Add(f); }
00931    void operator-=(Real f) { GeneralMatrix::Add(-f); }
00932    void swap(ColumnVector& gm)
00933       { GeneralMatrix::swap((GeneralMatrix&)gm); }
00934    NEW_DELETE(ColumnVector)
00935 };
00936 
00937 class CroutMatrix : public GeneralMatrix        // for LU decomposition
00938 {
00939    int* indx;
00940    bool d;
00941    bool sing;
00942    void ludcmp();
00943    void operator=(const CroutMatrix& /*m*/) {}     // not allowed
00944 public:
00945    CroutMatrix(const BaseMatrix&);
00946    MatrixType Type() const;
00947    void lubksb(Real*, int=0);
00948    ~CroutMatrix();
00949    GeneralMatrix* MakeSolver() { return this; } // for solving
00950    LogAndSign LogDeterminant() const;
00951    void Solver(MatrixColX&, const MatrixColX&);
00952    void GetRow(MatrixRowCol&);
00953    void GetCol(MatrixRowCol&);
00954    void GetCol(MatrixColX& c) { GetCol((MatrixRowCol&)c); }
00955    void CleanUp();                                // to clear store
00956    void MiniCleanUp();
00957    bool IsEqual(const GeneralMatrix&) const;
00958    bool IsSingular() const { return sing; }
00959    void swap(CroutMatrix& gm);
00960    NEW_DELETE(CroutMatrix)
00961 };
00962 
00963 // ***************************** band matrices ***************************/
00964 
00965 class BandMatrix : public GeneralMatrix         // band matrix
00966 {
00967    GeneralMatrix* Image() const;                // copy of matrix
00968 protected:
00969    void CornerClear() const;                    // set unused elements to zero
00970    short SimpleAddOK(const GeneralMatrix* gm);
00971 public:
00972    int lower, upper;                            // band widths
00973    BandMatrix() { lower=0; upper=0; CornerClear(); }
00974    ~BandMatrix() {}
00975    BandMatrix(int n,int lb,int ub) { ReSize(n,lb,ub); CornerClear(); }
00976                                                 // standard declaration
00977    BandMatrix(const BaseMatrix&);               // evaluate BaseMatrix
00978    void operator=(const BaseMatrix&);
00979    void operator=(Real f) { GeneralMatrix::operator=(f); }
00980    void operator=(const BandMatrix& m) { Eq(m); }
00981    MatrixType Type() const;
00982    Real& operator()(int, int);                  // access element
00983    Real& element(int, int);                     // access element
00984    Real operator()(int, int) const;             // access element
00985    Real element(int, int) const;                // access element
00986 #ifdef SETUP_C_SUBSCRIPTS
00987    Real* operator[](int m) { return store+(upper+lower)*m+lower; }
00988    const Real* operator[](int m) const { return store+(upper+lower)*m+lower; }
00989 #endif
00990    BandMatrix(const BandMatrix& gm) : GeneralMatrix() { GetMatrix(&gm); }
00991    LogAndSign LogDeterminant() const;
00992    GeneralMatrix* MakeSolver();
00993    Real Trace() const;
00994    Real SumSquare() const { CornerClear(); return GeneralMatrix::SumSquare(); }
00995    Real SumAbsoluteValue() const
00996       { CornerClear(); return GeneralMatrix::SumAbsoluteValue(); }
00997    Real Sum() const
00998       { CornerClear(); return GeneralMatrix::Sum(); }
00999    Real MaximumAbsoluteValue() const
01000       { CornerClear(); return GeneralMatrix::MaximumAbsoluteValue(); }
01001    Real MinimumAbsoluteValue() const
01002       { int i, j; return GeneralMatrix::MinimumAbsoluteValue2(i, j); }
01003    Real Maximum() const { int i, j; return GeneralMatrix::Maximum2(i, j); }
01004    Real Minimum() const { int i, j; return GeneralMatrix::Minimum2(i, j); }
01005    void GetRow(MatrixRowCol&);
01006    void GetCol(MatrixRowCol&);
01007    void GetCol(MatrixColX&);
01008    void RestoreCol(MatrixRowCol&);
01009    void RestoreCol(MatrixColX& c) { RestoreCol((MatrixRowCol&)c); }
01010    void NextRow(MatrixRowCol&);
01011    virtual void ReSize(int, int, int);             // change dimensions
01012    void ReSize(const GeneralMatrix& A);
01013    bool SameStorageType(const GeneralMatrix& A) const;
01014    void ReSizeForAdd(const GeneralMatrix& A, const GeneralMatrix& B);
01015    void ReSizeForSP(const GeneralMatrix& A, const GeneralMatrix& B);
01016    MatrixBandWidth BandWidth() const;
01017    void SetParameters(const GeneralMatrix*);
01018    MatrixInput operator<<(Real);                // will give error
01019    MatrixInput operator<<(int f);
01020    void operator<<(const Real* r);              // will give error
01021    void operator<<(const int* r);               // will give error
01022       // the next is included because Zortech and Borland
01023       // cannot find the copy in GeneralMatrix
01024    void operator<<(const BaseMatrix& X) { GeneralMatrix::operator<<(X); }
01025    void swap(BandMatrix& gm);
01026    NEW_DELETE(BandMatrix)
01027 };
01028 
01029 class UpperBandMatrix : public BandMatrix       // upper band matrix
01030 {
01031    GeneralMatrix* Image() const;                // copy of matrix
01032 public:
01033    UpperBandMatrix() {}
01034    ~UpperBandMatrix() {}
01035    UpperBandMatrix(int n, int ubw)              // standard declaration
01036       : BandMatrix(n, 0, ubw) {}
01037    UpperBandMatrix(const BaseMatrix&);          // evaluate BaseMatrix
01038    void operator=(const BaseMatrix&);
01039    void operator=(Real f) { GeneralMatrix::operator=(f); }
01040    void operator=(const UpperBandMatrix& m) { Eq(m); }
01041    MatrixType Type() const;
01042    UpperBandMatrix(const UpperBandMatrix& gm) : BandMatrix() { GetMatrix(&gm); }
01043    GeneralMatrix* MakeSolver() { return this; }
01044    void Solver(MatrixColX&, const MatrixColX&);
01045    LogAndSign LogDeterminant() const;
01046    void ReSize(int, int, int);             // change dimensions
01047    void ReSize(int n,int ubw)              // change dimensions
01048       { BandMatrix::ReSize(n,0,ubw); }
01049    void ReSize(const GeneralMatrix& A) { BandMatrix::ReSize(A); }
01050    Real& operator()(int, int);
01051    Real operator()(int, int) const;
01052    Real& element(int, int);
01053    Real element(int, int) const;
01054 #ifdef SETUP_C_SUBSCRIPTS
01055    Real* operator[](int m) { return store+upper*m; }
01056    const Real* operator[](int m) const { return store+upper*m; }
01057 #endif
01058    void swap(UpperBandMatrix& gm)
01059       { BandMatrix::swap((BandMatrix&)gm); }
01060    NEW_DELETE(UpperBandMatrix)
01061 };
01062 
01063 class LowerBandMatrix : public BandMatrix       // upper band matrix
01064 {
01065    GeneralMatrix* Image() const;                // copy of matrix
01066 public:
01067    LowerBandMatrix() {}
01068    ~LowerBandMatrix() {}
01069    LowerBandMatrix(int n, int lbw)              // standard declaration
01070       : BandMatrix(n, lbw, 0) {}
01071    LowerBandMatrix(const BaseMatrix&);          // evaluate BaseMatrix
01072    void operator=(const BaseMatrix&);
01073    void operator=(Real f) { GeneralMatrix::operator=(f); }
01074    void operator=(const LowerBandMatrix& m) { Eq(m); }
01075    MatrixType Type() const;
01076    LowerBandMatrix(const LowerBandMatrix& gm) : BandMatrix() { GetMatrix(&gm); }
01077    GeneralMatrix* MakeSolver() { return this; }
01078    void Solver(MatrixColX&, const MatrixColX&);
01079    LogAndSign LogDeterminant() const;
01080    void ReSize(int, int, int);             // change dimensions
01081    void ReSize(int n,int lbw)             // change dimensions
01082       { BandMatrix::ReSize(n,lbw,0); }
01083    void ReSize(const GeneralMatrix& A) { BandMatrix::ReSize(A); }
01084    Real& operator()(int, int);
01085    Real operator()(int, int) const;
01086    Real& element(int, int);
01087    Real element(int, int) const;
01088 #ifdef SETUP_C_SUBSCRIPTS
01089    Real* operator[](int m) { return store+lower*(m+1); }
01090    const Real* operator[](int m) const { return store+lower*(m+1); }
01091 #endif
01092    void swap(LowerBandMatrix& gm)
01093       { BandMatrix::swap((BandMatrix&)gm); }
01094    NEW_DELETE(LowerBandMatrix)
01095 };
01096 
01097 class SymmetricBandMatrix : public GeneralMatrix
01098 {
01099    GeneralMatrix* Image() const;                // copy of matrix
01100    void CornerClear() const;                    // set unused elements to zero
01101    short SimpleAddOK(const GeneralMatrix* gm);
01102 public:
01103    int lower;                                   // lower band width
01104    SymmetricBandMatrix() { lower=0; CornerClear(); }
01105    ~SymmetricBandMatrix() {}
01106    SymmetricBandMatrix(int n, int lb) { ReSize(n,lb); CornerClear(); }
01107    SymmetricBandMatrix(const BaseMatrix&);
01108    void operator=(const BaseMatrix&);
01109    void operator=(Real f) { GeneralMatrix::operator=(f); }
01110    void operator=(const SymmetricBandMatrix& m) { Eq(m); }
01111    Real& operator()(int, int);                  // access element
01112    Real& element(int, int);                     // access element
01113    Real operator()(int, int) const;             // access element
01114    Real element(int, int) const;                // access element
01115 #ifdef SETUP_C_SUBSCRIPTS
01116    Real* operator[](int m) { return store+lower*(m+1); }
01117    const Real* operator[](int m) const { return store+lower*(m+1); }
01118 #endif
01119    MatrixType Type() const;
01120    SymmetricBandMatrix(const SymmetricBandMatrix& gm) : GeneralMatrix() { GetMatrix(&gm); }
01121    GeneralMatrix* MakeSolver();
01122    Real SumSquare() const;
01123    Real SumAbsoluteValue() const;
01124    Real Sum() const;
01125    Real MaximumAbsoluteValue() const
01126       { CornerClear(); return GeneralMatrix::MaximumAbsoluteValue(); }
01127    Real MinimumAbsoluteValue() const
01128       { int i, j; return GeneralMatrix::MinimumAbsoluteValue2(i, j); }
01129    Real Maximum() const { int i, j; return GeneralMatrix::Maximum2(i, j); }
01130    Real Minimum() const { int i, j; return GeneralMatrix::Minimum2(i, j); }
01131    Real Trace() const;
01132    LogAndSign LogDeterminant() const;
01133    void GetRow(MatrixRowCol&);
01134    void GetCol(MatrixRowCol&);
01135    void GetCol(MatrixColX&);
01136    void RestoreCol(MatrixRowCol&) {}
01137    void RestoreCol(MatrixColX&);
01138    GeneralMatrix* Transpose(TransposedMatrix*, MatrixType);
01139    void ReSize(int,int);                       // change dimensions
01140    void ReSize(const GeneralMatrix& A);
01141    bool SameStorageType(const GeneralMatrix& A) const;
01142    void ReSizeForAdd(const GeneralMatrix& A, const GeneralMatrix& B);
01143    void ReSizeForSP(const GeneralMatrix& A, const GeneralMatrix& B);
01144    MatrixBandWidth BandWidth() const;
01145    void SetParameters(const GeneralMatrix*);
01146    void operator<<(const Real* r);              // will give error
01147    void operator<<(const int* r);               // will give error
01148    void operator<<(const BaseMatrix& X) { GeneralMatrix::operator<<(X); }
01149    void swap(SymmetricBandMatrix& gm);
01150    NEW_DELETE(SymmetricBandMatrix)
01151 };
01152 
01153 class BandLUMatrix : public GeneralMatrix
01154 // for LU decomposition of band matrix
01155 {
01156    int* indx;
01157    bool d;
01158    bool sing;                                   // true if singular
01159    Real* store2;
01160    int storage2;
01161    void ludcmp();
01162    int m1,m2;                                   // lower and upper
01163    void operator=(const BandLUMatrix& /*m*/) {}     // no allowed
01164 public:
01165    BandLUMatrix(const BaseMatrix&);
01166    MatrixType Type() const;
01167    void lubksb(Real*, int=0);
01168    ~BandLUMatrix();
01169    GeneralMatrix* MakeSolver() { return this; } // for solving
01170    LogAndSign LogDeterminant() const;
01171    void Solver(MatrixColX&, const MatrixColX&);
01172    void GetRow(MatrixRowCol&);
01173    void GetCol(MatrixRowCol&);
01174    void GetCol(MatrixColX& c) { GetCol((MatrixRowCol&)c); }
01175    void CleanUp();                                // to clear store
01176    void MiniCleanUp();
01177    bool IsEqual(const GeneralMatrix&) const;
01178    bool IsSingular() const { return sing; }
01179    void swap(BandLUMatrix& gm);
01180    NEW_DELETE(BandLUMatrix)
01181 };
01182 
01183 // ************************** special matrices ****************************
01184 
01185 class IdentityMatrix : public GeneralMatrix
01186 {
01187    GeneralMatrix* Image() const;          // copy of matrix
01188 public:
01189    IdentityMatrix() {}
01190    ~IdentityMatrix() {}
01191    IdentityMatrix(ArrayLengthSpecifier n) : GeneralMatrix(1)
01192       { nrows_value = ncols_value = n.Value(); *store = 1; }
01193    IdentityMatrix(const IdentityMatrix& gm) : GeneralMatrix() { GetMatrix(&gm); }
01194    IdentityMatrix(const BaseMatrix&);
01195    void operator=(const BaseMatrix&);
01196    void operator=(const IdentityMatrix& m) { Eq(m); }
01197    void operator=(Real f) { GeneralMatrix::operator=(f); }
01198    MatrixType Type() const;
01199 
01200    LogAndSign LogDeterminant() const;
01201    Real Trace() const;
01202    Real SumSquare() const;
01203    Real SumAbsoluteValue() const;
01204    Real Sum() const { return Trace(); }
01205    void GetRow(MatrixRowCol&);
01206    void GetCol(MatrixRowCol&);
01207    void GetCol(MatrixColX&);
01208    void NextRow(MatrixRowCol&);
01209    void NextCol(MatrixRowCol&);
01210    void NextCol(MatrixColX&);
01211    GeneralMatrix* MakeSolver() { return this; } // for solving
01212    void Solver(MatrixColX&, const MatrixColX&);
01213    GeneralMatrix* Transpose(TransposedMatrix*, MatrixType);
01214    void ReSize(int n);
01215    void ReSize(const GeneralMatrix& A);
01216    MatrixBandWidth BandWidth() const;
01217 //   ReturnMatrix Reverse() const;                // reverse order of elements
01218    void swap(IdentityMatrix& gm)
01219       { GeneralMatrix::swap((GeneralMatrix&)gm); }
01220    NEW_DELETE(IdentityMatrix)
01221 };
01222 
01223 
01224 
01225 
01226 // ************************** GenericMatrix class ************************/
01227 
01228 class GenericMatrix : public BaseMatrix
01229 {
01230    GeneralMatrix* gm;
01231    int search(const BaseMatrix* bm) const;
01232    friend class BaseMatrix;
01233 public:
01234    GenericMatrix() : gm(0) {}
01235    GenericMatrix(const BaseMatrix& bm)
01236       { gm = ((BaseMatrix&)bm).Evaluate(); gm = gm->Image(); }
01237    GenericMatrix(const GenericMatrix& bm) : BaseMatrix()
01238       { gm = bm.gm->Image(); }
01239    void operator=(const GenericMatrix&);
01240    void operator=(const BaseMatrix&);
01241    void operator+=(const BaseMatrix&);
01242    void operator-=(const BaseMatrix&);
01243    void operator*=(const BaseMatrix&);
01244    void operator|=(const BaseMatrix&);
01245    void operator&=(const BaseMatrix&);
01246    void operator+=(Real);
01247    void operator-=(Real r) { operator+=(-r); }
01248    void operator*=(Real);
01249    void operator/=(Real r) { operator*=(1.0/r); }
01250    ~GenericMatrix() { delete gm; }
01251    void CleanUp() { delete gm; gm = 0; }
01252    void Release() { gm->Release(); }
01253    GeneralMatrix* Evaluate(MatrixType = MatrixTypeUnSp);
01254    MatrixBandWidth BandWidth() const;
01255    void swap(GenericMatrix& x);
01256    NEW_DELETE(GenericMatrix)
01257 };
01258 
01259 // *************************** temporary classes *************************/
01260 
01261 class MultipliedMatrix : public BaseMatrix
01262 {
01263 protected:
01264    // if these union statements cause problems, simply remove them
01265    // and declare the items individually
01266    union { const BaseMatrix* bm1; GeneralMatrix* gm1; };
01267               // pointers to summands
01268    union { const BaseMatrix* bm2; GeneralMatrix* gm2; };
01269    MultipliedMatrix(const BaseMatrix* bm1x, const BaseMatrix* bm2x)
01270       : bm1(bm1x),bm2(bm2x) {}
01271    int search(const BaseMatrix*) const;
01272    friend class BaseMatrix;
01273    friend class GeneralMatrix;
01274    friend class GenericMatrix;
01275 public:
01276    MultipliedMatrix(const MultipliedMatrix& mm) // needed a copy constructor to silence gcc4 warning
01277       : BaseMatrix(mm), bm1(mm.bm1),bm2(mm.bm2) {}
01278    ~MultipliedMatrix() {}
01279    GeneralMatrix* Evaluate(MatrixType mt=MatrixTypeUnSp);
01280    MatrixBandWidth BandWidth() const;
01281    NEW_DELETE(MultipliedMatrix)
01282 };
01283 
01284 class AddedMatrix : public MultipliedMatrix
01285 {
01286 protected:
01287    AddedMatrix(const BaseMatrix* bm1x, const BaseMatrix* bm2x)
01288       : MultipliedMatrix(bm1x,bm2x) {}
01289 
01290    friend class BaseMatrix;
01291    friend class GeneralMatrix;
01292    friend class GenericMatrix;
01293 public:
01294    ~AddedMatrix() {}
01295    GeneralMatrix* Evaluate(MatrixType mt=MatrixTypeUnSp);
01296    MatrixBandWidth BandWidth() const;
01297    NEW_DELETE(AddedMatrix)
01298 };
01299 
01300 class SPMatrix : public AddedMatrix
01301 {
01302 protected:
01303    SPMatrix(const BaseMatrix* bm1x, const BaseMatrix* bm2x)
01304       : AddedMatrix(bm1x,bm2x) {}
01305 
01306    friend class BaseMatrix;
01307    friend class GeneralMatrix;
01308    friend class GenericMatrix;
01309 public:
01310    ~SPMatrix() {}
01311    GeneralMatrix* Evaluate(MatrixType mt=MatrixTypeUnSp);
01312    MatrixBandWidth BandWidth() const;
01313 
01314    friend SPMatrix SP(const BaseMatrix&, const BaseMatrix&);
01315 
01316    NEW_DELETE(SPMatrix)
01317 };
01318 
01319 class KPMatrix : public MultipliedMatrix
01320 {
01321 protected:
01322    KPMatrix(const BaseMatrix* bm1x, const BaseMatrix* bm2x)
01323       : MultipliedMatrix(bm1x,bm2x) {}
01324 
01325    friend class BaseMatrix;
01326    friend class GeneralMatrix;
01327    friend class GenericMatrix;
01328 public:
01329    ~KPMatrix() {}
01330    MatrixBandWidth BandWidth() const;
01331    GeneralMatrix* Evaluate(MatrixType mt=MatrixTypeUnSp);
01332    friend KPMatrix KP(const BaseMatrix&, const BaseMatrix&);
01333    NEW_DELETE(KPMatrix)
01334 };
01335 
01336 class ConcatenatedMatrix : public MultipliedMatrix
01337 {
01338 protected:
01339    ConcatenatedMatrix(const BaseMatrix* bm1x, const BaseMatrix* bm2x)
01340       : MultipliedMatrix(bm1x,bm2x) {}
01341 
01342    friend class BaseMatrix;
01343    friend class GeneralMatrix;
01344    friend class GenericMatrix;
01345 public:
01346    ~ConcatenatedMatrix() {}
01347    MatrixBandWidth BandWidth() const;
01348    GeneralMatrix* Evaluate(MatrixType mt=MatrixTypeUnSp);
01349    NEW_DELETE(ConcatenatedMatrix)
01350 };
01351 
01352 class StackedMatrix : public ConcatenatedMatrix
01353 {
01354 protected:
01355    StackedMatrix(const BaseMatrix* bm1x, const BaseMatrix* bm2x)
01356       : ConcatenatedMatrix(bm1x,bm2x) {}
01357 
01358    friend class BaseMatrix;
01359    friend class GeneralMatrix;
01360    friend class GenericMatrix;
01361 public:
01362    ~StackedMatrix() {}
01363    GeneralMatrix* Evaluate(MatrixType mt=MatrixTypeUnSp);
01364    NEW_DELETE(StackedMatrix)
01365 };
01366 
01367 class SolvedMatrix : public MultipliedMatrix
01368 {
01369    SolvedMatrix(const BaseMatrix* bm1x, const BaseMatrix* bm2x)
01370       : MultipliedMatrix(bm1x,bm2x) {}
01371    friend class BaseMatrix;
01372    friend class InvertedMatrix;                        // for operator*
01373 public:
01374    ~SolvedMatrix() {}
01375    GeneralMatrix* Evaluate(MatrixType mt=MatrixTypeUnSp);
01376    MatrixBandWidth BandWidth() const;
01377    NEW_DELETE(SolvedMatrix)
01378 };
01379 
01380 class SubtractedMatrix : public AddedMatrix
01381 {
01382    SubtractedMatrix(const BaseMatrix* bm1x, const BaseMatrix* bm2x)
01383       : AddedMatrix(bm1x,bm2x) {}
01384    friend class BaseMatrix;
01385    friend class GeneralMatrix;
01386    friend class GenericMatrix;
01387 public:
01388    ~SubtractedMatrix() {}
01389    GeneralMatrix* Evaluate(MatrixType mt=MatrixTypeUnSp);
01390    NEW_DELETE(SubtractedMatrix)
01391 };
01392 
01393 class ShiftedMatrix : public BaseMatrix
01394 {
01395 protected:
01396    union { const BaseMatrix* bm; GeneralMatrix* gm; };
01397    Real f;
01398    ShiftedMatrix(const BaseMatrix* bmx, Real fx) : bm(bmx),f(fx) {}
01399    int search(const BaseMatrix*) const;
01400    friend class BaseMatrix;
01401    friend class GeneralMatrix;
01402    friend class GenericMatrix;
01403 public:
01404    ~ShiftedMatrix() {}
01405    GeneralMatrix* Evaluate(MatrixType mt=MatrixTypeUnSp);
01406    friend ShiftedMatrix operator+(Real f, const BaseMatrix& BM);
01407    NEW_DELETE(ShiftedMatrix)
01408 };
01409 
01410 class NegShiftedMatrix : public ShiftedMatrix
01411 {
01412 protected:
01413    NegShiftedMatrix(Real fx, const BaseMatrix* bmx) : ShiftedMatrix(bmx,fx) {}
01414    friend class BaseMatrix;
01415    friend class GeneralMatrix;
01416    friend class GenericMatrix;
01417 public:
01418    ~NegShiftedMatrix() {}
01419    GeneralMatrix* Evaluate(MatrixType mt=MatrixTypeUnSp);
01420    friend NegShiftedMatrix operator-(Real, const BaseMatrix&);
01421    NEW_DELETE(NegShiftedMatrix)
01422 };
01423 
01424 class ScaledMatrix : public ShiftedMatrix
01425 {
01426    ScaledMatrix(const BaseMatrix* bmx, Real fx) : ShiftedMatrix(bmx,fx) {}
01427    friend class BaseMatrix;
01428    friend class GeneralMatrix;
01429    friend class GenericMatrix;
01430 public:
01431    ~ScaledMatrix() {}
01432    GeneralMatrix* Evaluate(MatrixType mt=MatrixTypeUnSp);
01433    MatrixBandWidth BandWidth() const;
01434    friend ScaledMatrix operator*(Real f, const BaseMatrix& BM);
01435    NEW_DELETE(ScaledMatrix)
01436 };
01437 
01438 class NegatedMatrix : public BaseMatrix
01439 {
01440 protected:
01441    union { const BaseMatrix* bm; GeneralMatrix* gm; };
01442    NegatedMatrix(const BaseMatrix* bmx) : bm(bmx) {}
01443    int search(const BaseMatrix*) const;
01444 private:
01445    friend class BaseMatrix;
01446 public:
01447    ~NegatedMatrix() {}
01448    GeneralMatrix* Evaluate(MatrixType mt=MatrixTypeUnSp);
01449    MatrixBandWidth BandWidth() const;
01450    NEW_DELETE(NegatedMatrix)
01451 };
01452 
01453 class TransposedMatrix : public NegatedMatrix
01454 {
01455    TransposedMatrix(const BaseMatrix* bmx) : NegatedMatrix(bmx) {}
01456    friend class BaseMatrix;
01457 public:
01458    ~TransposedMatrix() {}
01459    GeneralMatrix* Evaluate(MatrixType mt=MatrixTypeUnSp);
01460    MatrixBandWidth BandWidth() const;
01461    NEW_DELETE(TransposedMatrix)
01462 };
01463 
01464 class ReversedMatrix : public NegatedMatrix
01465 {
01466    ReversedMatrix(const BaseMatrix* bmx) : NegatedMatrix(bmx) {}
01467    friend class BaseMatrix;
01468 public:
01469    ~ReversedMatrix() {}
01470    GeneralMatrix* Evaluate(MatrixType mt=MatrixTypeUnSp);
01471    NEW_DELETE(ReversedMatrix)
01472 };
01473 
01474 class InvertedMatrix : public NegatedMatrix
01475 {
01476    InvertedMatrix(const BaseMatrix* bmx) : NegatedMatrix(bmx) {}
01477 public:
01478    ~InvertedMatrix() {}
01479    SolvedMatrix operator*(const BaseMatrix&) const;       // inverse(A) * B
01480    ScaledMatrix operator*(Real t) const { return BaseMatrix::operator*(t); }
01481    friend class BaseMatrix;
01482    GeneralMatrix* Evaluate(MatrixType mt=MatrixTypeUnSp);
01483    MatrixBandWidth BandWidth() const;
01484    NEW_DELETE(InvertedMatrix)
01485 };
01486 
01487 class RowedMatrix : public NegatedMatrix
01488 {
01489    RowedMatrix(const BaseMatrix* bmx) : NegatedMatrix(bmx) {}
01490    friend class BaseMatrix;
01491 public:
01492    ~RowedMatrix() {}
01493    GeneralMatrix* Evaluate(MatrixType mt=MatrixTypeUnSp);
01494    MatrixBandWidth BandWidth() const;
01495    NEW_DELETE(RowedMatrix)
01496 };
01497 
01498 class ColedMatrix : public NegatedMatrix
01499 {
01500    ColedMatrix(const BaseMatrix* bmx) : NegatedMatrix(bmx) {}
01501    friend class BaseMatrix;
01502 public:
01503    ~ColedMatrix() {}
01504    GeneralMatrix* Evaluate(MatrixType mt=MatrixTypeUnSp);
01505    MatrixBandWidth BandWidth() const;
01506    NEW_DELETE(ColedMatrix)
01507 };
01508 
01509 class DiagedMatrix : public NegatedMatrix
01510 {
01511    DiagedMatrix(const BaseMatrix* bmx) : NegatedMatrix(bmx) {}
01512    friend class BaseMatrix;
01513 public:
01514    ~DiagedMatrix() {}
01515    GeneralMatrix* Evaluate(MatrixType mt=MatrixTypeUnSp);
01516    MatrixBandWidth BandWidth() const;
01517    NEW_DELETE(DiagedMatrix)
01518 };
01519 
01520 class MatedMatrix : public NegatedMatrix
01521 {
01522    int nr, nc;
01523    MatedMatrix(const BaseMatrix* bmx, int nrx, int ncx)
01524       : NegatedMatrix(bmx), nr(nrx), nc(ncx) {}
01525    friend class BaseMatrix;
01526 public:
01527    ~MatedMatrix() {}
01528    GeneralMatrix* Evaluate(MatrixType mt=MatrixTypeUnSp);
01529    MatrixBandWidth BandWidth() const;
01530    NEW_DELETE(MatedMatrix)
01531 };
01532 
01533 class ReturnMatrix : public BaseMatrix    // for matrix return
01534 {
01535    GeneralMatrix* gm;
01536    int search(const BaseMatrix*) const;
01537 public:
01538    ~ReturnMatrix() {}
01539    GeneralMatrix* Evaluate(MatrixType mt=MatrixTypeUnSp);
01540    friend class BaseMatrix;
01541    ReturnMatrix(const ReturnMatrix& tm) : BaseMatrix(), gm(tm.gm) {}
01542    ReturnMatrix(const GeneralMatrix* gmx) : gm((GeneralMatrix*&)gmx) {}
01543 //   ReturnMatrix(GeneralMatrix&);
01544    MatrixBandWidth BandWidth() const;
01545    NEW_DELETE(ReturnMatrix)
01546 };
01547 
01548 
01549 // ************************** submatrices ******************************/
01550 
01551 class GetSubMatrix : public NegatedMatrix
01552 {
01553    int row_skip;
01554    int row_number;
01555    int col_skip;
01556    int col_number;
01557    bool IsSym;
01558 
01559    GetSubMatrix
01560       (const BaseMatrix* bmx, int rs, int rn, int cs, int cn, bool is)
01561       : NegatedMatrix(bmx),
01562       row_skip(rs), row_number(rn), col_skip(cs), col_number(cn), IsSym(is) {}
01563    void SetUpLHS();
01564    friend class BaseMatrix;
01565 public:
01566    GetSubMatrix(const GetSubMatrix& g)
01567       : NegatedMatrix(g.bm), row_skip(g.row_skip), row_number(g.row_number),
01568       col_skip(g.col_skip), col_number(g.col_number), IsSym(g.IsSym) {}
01569    ~GetSubMatrix() {}
01570    GeneralMatrix* Evaluate(MatrixType mt=MatrixTypeUnSp);
01571    void operator=(const BaseMatrix&);
01572    void operator+=(const BaseMatrix&);
01573    void operator-=(const BaseMatrix&);
01574    void operator=(const GetSubMatrix& m) { operator=((const BaseMatrix&)m); }
01575    void operator<<(const BaseMatrix&);
01576    void operator<<(const Real*);                // copy from array
01577    void operator<<(const int*);                 // copy from array
01578    MatrixInput operator<<(Real);                // for loading a list
01579    MatrixInput operator<<(int f);
01580    void operator=(Real);                        // copy from constant
01581    void operator+=(Real);                       // add constant
01582    void operator-=(Real r) { operator+=(-r); }  // subtract constant
01583    void operator*=(Real);                       // multiply by constant
01584    void operator/=(Real r) { operator*=(1.0/r); } // divide by constant
01585    void Inject(const GeneralMatrix&);           // copy stored els only
01586    MatrixBandWidth BandWidth() const;
01587    NEW_DELETE(GetSubMatrix)
01588 };
01589 
01590 // ******************** linear equation solving ****************************/
01591 
01592 class LinearEquationSolver : public BaseMatrix
01593 {
01594    GeneralMatrix* gm;
01595    int search(const BaseMatrix*) const { return 0; }
01596    friend class BaseMatrix;
01597 public:
01598    LinearEquationSolver(const BaseMatrix& bm);
01599    ~LinearEquationSolver() { delete gm; }
01600    void CleanUp() { delete gm; } 
01601    GeneralMatrix* Evaluate(MatrixType) { return gm; }
01602    // probably should have an error message if MatrixType != UnSp
01603    NEW_DELETE(LinearEquationSolver)
01604 };
01605 
01606 // ************************** matrix input *******************************/
01607 
01608 class MatrixInput          // for reading a list of values into a matrix
01609                            // the difficult part is detecting a mismatch
01610                            // in the number of elements
01611 {
01612    int n;                  // number values still to be read
01613    Real* r;                // pointer to next location to be read to
01614 public:
01615    MatrixInput(const MatrixInput& mi) : n(mi.n), r(mi.r) {}
01616    MatrixInput(int nx, Real* rx) : n(nx), r(rx) {}
01617    ~MatrixInput();
01618    MatrixInput operator<<(Real);
01619    MatrixInput operator<<(int f);
01620    friend class GeneralMatrix;
01621 };
01622 
01623 
01624 
01625 // **************** a very simple integer array class ********************/
01626 
01627 // A minimal array class to imitate a C style array but giving dynamic storage
01628 // mostly intended for internal use by newmat
01629 
01630 class SimpleIntArray : public Janitor
01631 {
01632 protected:
01633    int* a;                    // pointer to the array
01634    int n;                     // length of the array
01635 public:
01636    SimpleIntArray(int xn);    // build an array length xn
01637    SimpleIntArray() : a(0), n(0) {}  // build an array length 0
01638    ~SimpleIntArray();         // return the space to memory
01639    int& operator[](int i);    // access element of the array - start at 0
01640    int operator[](int i) const;
01641             // access element of constant array
01642    void operator=(int ai);    // set the array equal to a constant
01643    void operator=(const SimpleIntArray& b);
01644             // copy the elements of an array
01645    SimpleIntArray(const SimpleIntArray& b);
01646             // make a new array equal to an existing one
01647    int Size() const { return n; }
01648             // return the size of the array
01649    int size() const { return n; }
01650             // return the size of the array
01651    int* Data() { return a; }  // pointer to the data
01652    const int* Data() const { return a; }  // pointer to the data
01653    int* data() { return a; }  // pointer to the data
01654    const int* data() const { return a; }  // pointer to the data
01655    const int* const_data() const { return a; }  // pointer to the data
01656    void ReSize(int i, bool keep = false);
01657                               // change length, keep data if keep = true
01658    void resize(int i, bool keep = false) { ReSize(i, keep); }
01659                               // change length, keep data if keep = true
01660    void CleanUp() { ReSize(0); }
01661    NEW_DELETE(SimpleIntArray)
01662 };
01663 
01664 // ********************** C subscript classes ****************************
01665 
01666 class RealStarStar
01667 {
01668    Real** a;
01669 public:
01670    RealStarStar(Matrix& A);
01671    ~RealStarStar() { delete [] a; }
01672    operator Real**() { return a; }
01673 };
01674 
01675 class ConstRealStarStar
01676 {
01677    const Real** a;
01678 public:
01679    ConstRealStarStar(const Matrix& A);
01680    ~ConstRealStarStar() { delete [] a; }
01681    operator const Real**() { return a; }
01682 };
01683 
01684 // *************************** exceptions ********************************/
01685 
01686 class NPDException : public Runtime_error     // Not positive definite
01687 {
01688 public:
01689    static unsigned long Select;          // for identifying exception
01690    NPDException(const GeneralMatrix&);
01691 };
01692 
01693 class ConvergenceException : public Runtime_error
01694 {
01695 public:
01696    static unsigned long Select;          // for identifying exception
01697    ConvergenceException(const GeneralMatrix& A);
01698    ConvergenceException(const char* c);
01699 };
01700 
01701 class SingularException : public Runtime_error
01702 {
01703 public:
01704    static unsigned long Select;          // for identifying exception
01705    SingularException(const GeneralMatrix& A);
01706 };
01707 
01708 class OverflowException : public Runtime_error
01709 {
01710 public:
01711    static unsigned long Select;          // for identifying exception
01712    OverflowException(const char* c);
01713 };
01714 
01715 class ProgramException : public Logic_error
01716 {
01717 protected:
01718    ProgramException();
01719 public:
01720    static unsigned long Select;          // for identifying exception
01721    ProgramException(const char* c);
01722    ProgramException(const char* c, const GeneralMatrix&);
01723    ProgramException(const char* c, const GeneralMatrix&, const GeneralMatrix&);
01724    ProgramException(const char* c, MatrixType, MatrixType);
01725 };
01726 
01727 class IndexException : public Logic_error
01728 {
01729 public:
01730    static unsigned long Select;          // for identifying exception
01731    IndexException(int i, const GeneralMatrix& A);
01732    IndexException(int i, int j, const GeneralMatrix& A);
01733    // next two are for access via element function
01734    IndexException(int i, const GeneralMatrix& A, bool);
01735    IndexException(int i, int j, const GeneralMatrix& A, bool);
01736 };
01737 
01738 class VectorException : public Logic_error    // cannot convert to vector
01739 {
01740 public:
01741    static unsigned long Select;          // for identifying exception
01742    VectorException();
01743    VectorException(const GeneralMatrix& A);
01744 };
01745 
01746 class NotSquareException : public Logic_error
01747 {
01748 public:
01749    static unsigned long Select;          // for identifying exception
01750    NotSquareException(const GeneralMatrix& A);
01751    NotSquareException();
01752 };
01753 
01754 class SubMatrixDimensionException : public Logic_error
01755 {
01756 public:
01757    static unsigned long Select;          // for identifying exception
01758    SubMatrixDimensionException();
01759 };
01760 
01761 class IncompatibleDimensionsException : public Logic_error
01762 {
01763 public:
01764    static unsigned long Select;          // for identifying exception
01765    IncompatibleDimensionsException();
01766    IncompatibleDimensionsException(const GeneralMatrix&, const GeneralMatrix&);
01767 };
01768 
01769 class NotDefinedException : public Logic_error
01770 {
01771 public:
01772    static unsigned long Select;          // for identifying exception
01773    NotDefinedException(const char* op, const char* matrix);
01774 };
01775 
01776 class CannotBuildException : public Logic_error
01777 {
01778 public:
01779    static unsigned long Select;          // for identifying exception
01780    CannotBuildException(const char* matrix);
01781 };
01782 
01783 
01784 class InternalException : public Logic_error
01785 {
01786 public:
01787    static unsigned long Select;          // for identifying exception
01788    InternalException(const char* c);
01789 };
01790 
01791 // ************************ functions ************************************ //
01792 
01793 bool operator==(const GeneralMatrix& A, const GeneralMatrix& B);
01794 bool operator==(const BaseMatrix& A, const BaseMatrix& B);
01795 inline bool operator!=(const GeneralMatrix& A, const GeneralMatrix& B)
01796    { return ! (A==B); }
01797 inline bool operator!=(const BaseMatrix& A, const BaseMatrix& B)
01798    { return ! (A==B); }
01799 
01800    // inequality operators are dummies included for compatibility
01801    // with STL. They throw an exception if actually called.
01802 inline bool operator<=(const BaseMatrix& A, const BaseMatrix&)
01803    { A.IEQND(); return true; }
01804 inline bool operator>=(const BaseMatrix& A, const BaseMatrix&)
01805    { A.IEQND(); return true; }
01806 inline bool operator<(const BaseMatrix& A, const BaseMatrix&)
01807    { A.IEQND(); return true; }
01808 inline bool operator>(const BaseMatrix& A, const BaseMatrix&)
01809    { A.IEQND(); return true; }
01810 
01811 bool IsZero(const BaseMatrix& A);
01812 
01813 Matrix CrossProduct(const Matrix& A, const Matrix& B);
01814 ReturnMatrix CrossProductRows(const Matrix& A, const Matrix& B);
01815 ReturnMatrix CrossProductColumns(const Matrix& A, const Matrix& B);
01816 
01817 
01818 // ********************* inline functions ******************************** //
01819 
01820 
01821 inline LogAndSign LogDeterminant(const BaseMatrix& B)
01822    { return B.LogDeterminant(); }
01823 inline Real Determinant(const BaseMatrix& B)
01824    { return B.Determinant(); }
01825 inline Real SumSquare(const BaseMatrix& B) { return B.SumSquare(); }
01826 inline Real NormFrobenius(const BaseMatrix& B) { return B.NormFrobenius(); }
01827 inline Real Trace(const BaseMatrix& B) { return B.Trace(); }
01828 inline Real SumAbsoluteValue(const BaseMatrix& B)
01829    { return B.SumAbsoluteValue(); }
01830 inline Real Sum(const BaseMatrix& B)
01831    { return B.Sum(); }
01832 inline Real MaximumAbsoluteValue(const BaseMatrix& B)
01833    { return B.MaximumAbsoluteValue(); }
01834 inline Real MinimumAbsoluteValue(const BaseMatrix& B)
01835    { return B.MinimumAbsoluteValue(); }
01836 inline Real Maximum(const BaseMatrix& B) { return B.Maximum(); }
01837 inline Real Minimum(const BaseMatrix& B) { return B.Minimum(); }
01838 inline Real Norm1(const BaseMatrix& B) { return B.Norm1(); }
01839 inline Real Norm1(RowVector& RV) { return RV.MaximumAbsoluteValue(); }
01840 inline Real NormInfinity(const BaseMatrix& B) { return B.NormInfinity(); }
01841 inline Real NormInfinity(ColumnVector& CV)
01842    { return CV.MaximumAbsoluteValue(); }
01843 inline bool IsZero(const GeneralMatrix& A) { return A.IsZero(); }
01844 
01845 
01846 inline MatrixInput MatrixInput::operator<<(int f) { return *this << (Real)f; }
01847 inline MatrixInput GeneralMatrix::operator<<(int f) { return *this << (Real)f; }
01848 inline MatrixInput BandMatrix::operator<<(int f) { return *this << (Real)f; }
01849 inline MatrixInput GetSubMatrix::operator<<(int f) { return *this << (Real)f; }
01850 
01851 inline void swap(Matrix& A, Matrix& B) { A.swap(B); }
01852 inline void swap(SquareMatrix& A, SquareMatrix& B) { A.swap(B); }
01853 inline void swap(nricMatrix& A, nricMatrix& B) { A.swap(B); }
01854 inline void swap(UpperTriangularMatrix& A, UpperTriangularMatrix& B)
01855    { A.swap(B); }
01856 inline void swap(LowerTriangularMatrix& A, LowerTriangularMatrix& B)
01857    { A.swap(B); }
01858 inline void swap(SymmetricMatrix& A, SymmetricMatrix& B) { A.swap(B); }
01859 inline void swap(DiagonalMatrix& A, DiagonalMatrix& B) { A.swap(B); }
01860 inline void swap(RowVector& A, RowVector& B) { A.swap(B); }
01861 inline void swap(ColumnVector& A, ColumnVector& B) { A.swap(B); }
01862 inline void swap(CroutMatrix& A, CroutMatrix& B) { A.swap(B); }
01863 inline void swap(BandMatrix& A, BandMatrix& B) { A.swap(B); }
01864 inline void swap(UpperBandMatrix& A, UpperBandMatrix& B) { A.swap(B); }
01865 inline void swap(LowerBandMatrix& A, LowerBandMatrix& B) { A.swap(B); }
01866 inline void swap(SymmetricBandMatrix& A, SymmetricBandMatrix& B) { A.swap(B); }
01867 inline void swap(BandLUMatrix& A, BandLUMatrix& B) { A.swap(B); }
01868 inline void swap(IdentityMatrix& A, IdentityMatrix& B) { A.swap(B); }
01869 inline void swap(GenericMatrix& A, GenericMatrix& B) { A.swap(B); }
01870 
01871 
01872 #ifdef OPT_COMPATIBLE                    // for compatibility with opt++
01873 
01874 inline Real Norm2(const ColumnVector& CV) { return CV.NormFrobenius(); }
01875 inline Real Dot(ColumnVector& CV1, ColumnVector& CV2)
01876    { return DotProduct(CV1, CV2); }
01877 
01878 #endif
01879 
01880 
01881 #ifdef use_namespace
01882 }
01883 #endif
01884 
01885 
01886 #endif
01887 
01888 // body file: newmat1.cpp
01889 // body file: newmat2.cpp
01890 // body file: newmat3.cpp
01891 // body file: newmat4.cpp
01892 // body file: newmat5.cpp
01893 // body file: newmat6.cpp
01894 // body file: newmat7.cpp
01895 // body file: newmat8.cpp
01896 // body file: newmatex.cpp
01897 // body file: bandmat.cpp
01898 // body file: submat.cpp
01899 
01900 
01901 
01902 
01903 
01904 
01905 

newmat11b
Generated Tue Aug 16 16:32:01 2005 by Doxygen 1.4.4