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


rl_agent
Author(s): Todd Hester
autogenerated on Thu Jun 6 2019 22:00:13