home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / n / newmat06.zip / NEWMAT.H < prev    next >
C/C++ Source or Header  |  1992-12-02  |  44KB  |  1,269 lines

  1. //$$ newmat.h           definition file for new version of matrix package
  2.  
  3. // Copyright (C) 1991,2: R B Davies
  4.  
  5. #ifndef MATRIX_LIB
  6. #define MATRIX_LIB 0
  7.  
  8. #ifdef NO_LONG_NAMES
  9. #define UpperTriangularMatrix UTMatrix
  10. #define LowerTriangularMatrix LTMatrix
  11. #define SymmetricMatrix SMatrix
  12. #define DiagonalMatrix DMatrix
  13. #endif
  14.  
  15. #ifndef TEMPS_DESTROYED_QUICKLY
  16. #define ReturnMatrix ReturnMatrixX
  17. #else
  18. #define ReturnMatrix ReturnMatrixX&
  19. #endif
  20.  
  21. #include "boolean.h"
  22. #include "except.h"
  23.  
  24. /**************************** general utilities ****************************/
  25.  
  26. class GeneralMatrix;
  27. void MatrixErrorNoSpace(void*);                 // no space handler
  28.  
  29. class LogAndSign
  30. // Return from LogDeterminant function
  31. //    - value of the log plus the sign (+, - or 0)
  32. {
  33.    Real log_value;
  34.    int sign;
  35. public:
  36.    LogAndSign() { log_value=0.0; sign=1; }
  37.    LogAndSign(Real);
  38.    void operator*=(Real);
  39.    void ChangeSign() { sign = -sign; }
  40.    Real LogValue() const { return log_value; }
  41.    int Sign() const { return sign; }
  42.    Real Value() const;
  43.    FREE_CHECK(LogAndSign)
  44. };
  45.  
  46. // the following class is for counting the number of times a piece of code
  47. // is executed. It is used for locating any code not executed by test
  48. // routines. Use turbo GREP locate all places this code is called and
  49. // check which ones are not accessed.
  50. // Somewhat implementation dependent as it relies on "cout" still being
  51. // present when ExeCounter objects are destructed.
  52.  
  53. class ExeCounter
  54. {
  55.    int line;                                    // code line number
  56.    int fileid;                                  // file identifier
  57.    long nexe;                                   // number of executions
  58.    static int nreports;                         // number of reports
  59. public:
  60.    ExeCounter(int,int);
  61.    void operator++() { nexe++; }
  62.    ~ExeCounter();                               // prints out reports
  63. };
  64.  
  65.  
  66. /**************************** class MatrixType *****************************/
  67.  
  68. // Is used for finding the type of a matrix resulting from the binary operations
  69. // +, -, * and identifying what conversions are permissible.
  70. // This class must be updated when new matrix types are added.
  71.  
  72. class GeneralMatrix;                            // defined later
  73. class BaseMatrix;                               // defined later
  74.  
  75. class MatrixType
  76. {
  77. public:
  78.    enum Attribute {  Valid     = 1,
  79.                      Symmetric = 2,
  80.                      Band      = 4,
  81.                      Upper     = 8,
  82.                      Lower     = 16,
  83.                      LUDeco    = 32,
  84.                      OneRow    = 64,
  85.                      OneCol    = 128 };
  86.  
  87.    enum            { US = 0,
  88.                      UT = Valid + Upper,
  89.                      LT = Valid + Lower,
  90.                      Rt = Valid,
  91.                      Sm = Valid + Symmetric,
  92.                      Dg = Valid + Band + Lower + Upper + Symmetric,
  93.              RV = Valid + OneRow,
  94.              CV = Valid + OneCol,
  95.              BM = Valid + Band,
  96.              UB = Valid + Band + Upper,
  97.              LB = Valid + Band + Lower,
  98.              SB = Valid + Band + Symmetric,
  99.              Ct = Valid + LUDeco,
  100.              BC = Valid + Band + LUDeco,
  101.                    };
  102.  
  103.    enum { USX,UTX,LTX,RtX,SmX,DgX,RVX,CVX,BMX,UBX,LBX,SBX,CtX,BCX };
  104.  
  105.    static nTypes() { return 11; }              // number of different types
  106.                            // exclude Ct, US, BC
  107. public:
  108.    int attribute;
  109. public:
  110.    MatrixType operator+(const MatrixType& t) const;
  111.    MatrixType operator*(const MatrixType&) const;
  112.    Boolean operator>=(const MatrixType& t) const;
  113.    Boolean operator==(const MatrixType& t) const
  114.       { return (attribute == t.attribute); }
  115.    Boolean operator!=(const MatrixType& t) const { return !operator==(t); }
  116.    Boolean operator!() const { return (attribute & Valid) == 0; }
  117.    MatrixType i() const;                       // type of inverse
  118.    MatrixType t() const;                       // type of transpose
  119.    MatrixType AddEqualEl() const;              // Add constant to matrix
  120.    MatrixType MultRHS() const;                 // type for rhs of multiply
  121.    MatrixType sub() const;                     // type of submatrix
  122.    MatrixType ssub() const;                    // type of sym submatrix
  123. //   MatrixType (Type tx) : attribute((int)tx) {}
  124. //                           // (& doesn't work with AT&T)
  125.    MatrixType () {}
  126.    MatrixType (int i) : attribute(i) {}
  127.    GeneralMatrix* New() const;                 // new matrix of given type
  128.    GeneralMatrix* New(int,int,BaseMatrix*) const;
  129.                                                // new matrix of given type
  130.    operator char*() const;                     // for printing type
  131.    int BestFit() const;
  132.    FREE_CHECK(MatrixType)
  133. };
  134.  
  135. void TestTypeAdd();                            // test +
  136. void TestTypeMult();                           // test *
  137. void TestTypeOrder();                          // test >=
  138.  
  139.  
  140. /************************* class MatrixBandWidth ***********************/
  141.  
  142. class MatrixBandWidth
  143. {
  144. public:
  145.    int lower;
  146.    int upper;
  147.    MatrixBandWidth(const int l, const int u) : lower(l), upper (u) {}
  148.    MatrixBandWidth(const int i) : lower(i), upper(i) {}
  149.    MatrixBandWidth operator+(const MatrixBandWidth&) const;
  150.    MatrixBandWidth operator*(const MatrixBandWidth&) const;
  151.    MatrixBandWidth t() const { return MatrixBandWidth(upper,lower); }
  152.    Boolean operator==(const MatrixBandWidth& bw) const
  153.       { return (lower == bw.lower) && (upper == bw.upper); }
  154.    FREE_CHECK(MatrixBandWidth)
  155. };
  156.  
  157.  
  158. /*********************** Array length specifier ************************/
  159.  
  160. // This class is introduced to avoid constructors such as
  161. //   ColumnVector(int)
  162. // being used for conversions
  163.  
  164. class ArrayLengthSpecifier
  165. {
  166.    int value;
  167. public:
  168.    int Value() const { return value; }
  169.    ArrayLengthSpecifier(int l) : value(l) {}
  170.    FREE_CHECK(ArrayLengthSpecifier)
  171. };
  172.  
  173.  
  174. /*************************** Matrix routines ***************************/
  175.  
  176.  
  177. class MatrixRowCol;                             // defined later
  178. class MatrixRow;
  179. class MatrixCol;
  180.  
  181. class GeneralMatrix;                            // defined later
  182. class AddedMatrix;
  183. class MultipliedMatrix;
  184. class SubtractedMatrix;
  185. class SolvedMatrix;
  186. class ShiftedMatrix;
  187. class ScaledMatrix;
  188. class TransposedMatrix;
  189. class NegatedMatrix;
  190. class InvertedMatrix;
  191. class RowedMatrix;
  192. class ColedMatrix;
  193. class DiagedMatrix;
  194. class MatedMatrix;
  195. class GetSubMatrix;
  196. class ConstMatrix;
  197. class ReturnMatrixX;
  198. class Matrix;
  199. class nricMatrix;
  200. class RowVector;
  201. class ColumnVector;
  202. class SymmetricMatrix;
  203. class UpperTriangularMatrix;
  204. class LowerTriangularMatrix;
  205. class DiagonalMatrix;
  206. class CroutMatrix;
  207. class BandMatrix;
  208. class LowerBandMatrix;
  209. class UpperBandMatrix;
  210. class SymmetricBandMatrix;
  211. class LinearEquationSolver;
  212.  
  213. static MatrixType MatrixTypeUnSp(MatrixType::US);
  214.                         // AT&T needs this
  215.  
  216. class BaseMatrix : public Janitor               // base of all matrix classes
  217. {
  218. protected:
  219. //   BaseMatrix() {}
  220.    virtual ~BaseMatrix() {}
  221.    virtual int search(const BaseMatrix*) const = 0;
  222.                         // count number of times matrix
  223.                         // is referred to
  224.    virtual MatrixType Type() const = 0;         // type of a matrix
  225. //   virtual int NrowsV()  const = 0;
  226. //   virtual int NcolsV()  const = 0;
  227. public:
  228. #ifndef GXX
  229.    virtual GeneralMatrix* Evaluate(MatrixType mt=MatrixTypeUnSp) = 0;
  230.                         // evaluate temporary
  231. #else
  232.    virtual GeneralMatrix* Evaluate(MatrixType mt) = 0;
  233.    GeneralMatrix* Evaluate() { return Evaluate(MatrixTypeUnSp); }
  234. #endif
  235. //   void MatrixParameters(int& nr, int& nc, MatrixType& mt)
  236. //      { nr = NrowsV(); nc = NcolsV(); mt = Type(); }
  237. #ifndef TEMPS_DESTROYED_QUICKLY
  238.    AddedMatrix operator+(const BaseMatrix&) const;    // results of operations
  239.    MultipliedMatrix operator*(const BaseMatrix&) const;
  240.    SubtractedMatrix operator-(const BaseMatrix&) const;
  241.    ShiftedMatrix operator+(Real) const;
  242.    ScaledMatrix operator*(Real) const;
  243.    ScaledMatrix operator/(Real) const;
  244.    ShiftedMatrix operator-(Real) const;
  245.    TransposedMatrix t() const;
  246. //   TransposedMatrix t;
  247.    NegatedMatrix operator-() const;                   // change sign of elements
  248.    InvertedMatrix i() const;
  249. //   InvertedMatrix i;
  250.    RowedMatrix AsRow() const;
  251.    ColedMatrix AsColumn() const;
  252.    DiagedMatrix AsDiagonal() const;
  253.    MatedMatrix AsMatrix(int,int) const;
  254.    GetSubMatrix SubMatrix(int,int,int,int) const;
  255.    GetSubMatrix SymSubMatrix(int,int) const;
  256.    GetSubMatrix Row(int) const;
  257.    GetSubMatrix Rows(int,int) const;
  258.    GetSubMatrix Column(int) const;
  259.    GetSubMatrix Columns(int,int) const;
  260. #else
  261.    AddedMatrix& operator+(const BaseMatrix&) const;    // results of operations
  262.    MultipliedMatrix& operator*(const BaseMatrix&) const;
  263.    SubtractedMatrix& operator-(const BaseMatrix&) const;
  264.    ShiftedMatrix& operator+(Real) const;
  265.    ScaledMatrix& operator*(Real) const;
  266.    ScaledMatrix& operator/(Real) const;
  267.    ShiftedMatrix& operator-(Real) const;
  268.    TransposedMatrix& t() const;
  269. //   TransposedMatrix& t;
  270.    NegatedMatrix& operator-() const;                   // change sign of elements
  271.    InvertedMatrix& i() const;
  272. //   InvertedMatrix& i;
  273.    RowedMatrix& AsRow() const;
  274.    ColedMatrix& AsColumn() const;
  275.    DiagedMatrix& AsDiagonal() const;
  276.    MatedMatrix& AsMatrix(int,int) const;
  277.    GetSubMatrix& SubMatrix(int,int,int,int) const;
  278.    GetSubMatrix& SymSubMatrix(int,int) const;
  279.    GetSubMatrix& Row(int) const;
  280.    GetSubMatrix& Rows(int,int) const;
  281.    GetSubMatrix& Column(int) const;
  282.    GetSubMatrix& Columns(int,int) const;
  283. #endif
  284.    Real AsScalar() const;                      // conversion of 1 x 1 matrix
  285.    virtual LogAndSign LogDeterminant() const;
  286.    virtual Real SumSquare() const;
  287.    virtual Real SumAbsoluteValue() const;
  288.    virtual Real MaximumAbsoluteValue() const;
  289.    virtual Real Trace() const;
  290.    Real Norm1() const;
  291.    Real NormInfinity() const;
  292.    virtual MatrixBandWidth BandWidth() const;  // bandwidths of band matrix
  293.    virtual void CleanUp() {}                     // to clear store
  294. //protected:
  295. //   BaseMatrix() : t(this), i(this) {}
  296.  
  297.    friend GeneralMatrix;
  298.    friend Matrix;
  299.    friend nricMatrix;
  300.    friend RowVector;
  301.    friend ColumnVector;
  302.    friend SymmetricMatrix;
  303.    friend UpperTriangularMatrix;
  304.    friend LowerTriangularMatrix;
  305.    friend DiagonalMatrix;
  306.    friend CroutMatrix;
  307.    friend BandMatrix;
  308.    friend LowerBandMatrix;
  309.    friend UpperBandMatrix;
  310.    friend SymmetricBandMatrix;
  311.    friend AddedMatrix;
  312.    friend MultipliedMatrix;
  313.    friend SubtractedMatrix;
  314.    friend SolvedMatrix;
  315.    friend ShiftedMatrix;
  316.    friend ScaledMatrix;
  317.    friend TransposedMatrix;
  318.    friend NegatedMatrix;
  319.    friend InvertedMatrix;
  320.    friend RowedMatrix;
  321.    friend ColedMatrix;
  322.    friend DiagedMatrix;
  323.    friend MatedMatrix;
  324.    friend GetSubMatrix;
  325.    friend ConstMatrix;
  326.    friend ReturnMatrixX;
  327.    friend LinearEquationSolver;
  328.    NEW_DELETE(BaseMatrix)
  329. };
  330.  
  331.  
  332. /******************************* working classes **************************/
  333.  
  334. class GeneralMatrix : public BaseMatrix         // declarable matrix types
  335. {
  336. protected:
  337.    int tag;                                     // shows whether can reuse
  338.    int nrows, ncols;                            // dimensions
  339.    int storage;                                 // total store required
  340.    Real* store;                                 // point to store (0=not set)
  341.    GeneralMatrix();                             // initialise with no store
  342.    GeneralMatrix(ArrayLengthSpecifier);         // constructor getting store
  343.    void Add(GeneralMatrix*, Real);              // sum of GM and Real
  344.    void Add(Real);                              // add Real to this
  345.    void Multiply(GeneralMatrix*, Real);         // product of GM and Real
  346.    void Multiply(Real);                         // multiply this by Real
  347.    void Negate(GeneralMatrix*);                 // change sign
  348.    void Negate();                               // change sign
  349.    void operator=(Real);                        // set matrix to constant
  350.    Real* GetStore();                            // get store or copy
  351.    GeneralMatrix* BorrowStore(GeneralMatrix*, MatrixType);
  352.                                                 // temporarily access store
  353.    void GetMatrix(const GeneralMatrix*);        // used by = and initialise
  354.    void Eq(const BaseMatrix&, MatrixType);      // used by =
  355.    int search(const BaseMatrix*) const;
  356.    virtual GeneralMatrix* Transpose(TransposedMatrix*, MatrixType);
  357.    void CheckConversion(const BaseMatrix&);     // check conversion OK
  358.    void ReDimension(int, int, int);             // change dimensions
  359. //   int NrowsV() const;                          // get dimensions
  360. //   int NcolsV() const;                          // virtual version
  361. public:
  362.    GeneralMatrix* Evaluate(MatrixType);
  363.    MatrixType Type() const = 0;                 // type of a matrix
  364.    int Nrows() const { return nrows; }          // get dimensions
  365.    int Ncols() const { return ncols; }
  366.    int Storage() const { return storage; }
  367.    Real* Store() const { return store; }
  368.    virtual ~GeneralMatrix();                    // delete store if set
  369.    void tDelete();                              // delete if tag permits
  370.    Boolean reuse();                                // TRUE if tag allows reuse
  371.    void Protect() { tag=-1; }                   // can't delete or reuse
  372.    int Tag() const { return tag; }
  373.    Boolean IsZero() const;                         // test matrix has all zeros
  374.    void Release() { tag=1; }                    // del store after next use
  375.    void Release(int t) { tag=t; }               // del store after t accesses
  376.    void ReleaseAndDelete() { tag=0; }           // delete matrix after use
  377.    void operator<<(const Real*);                // assignment from an array
  378.    void operator<<(const BaseMatrix& X) { Eq(X,this->Type()); }
  379.                                                 // = without checking type
  380.    void Inject(const GeneralMatrix&);           // copy stored els only
  381.    virtual GeneralMatrix* MakeSolver();         // for solving
  382.    virtual void Solver(MatrixRowCol&, const MatrixRowCol&) {}
  383.    virtual void GetRow(MatrixRowCol&) = 0;      // Get matrix row
  384.    virtual void RestoreRow(MatrixRowCol&) {}    // Restore matrix row
  385.    virtual void NextRow(MatrixRowCol&);         // Go to next row
  386.    virtual void GetCol(MatrixRowCol&) = 0;      // Get matrix col
  387.    virtual void RestoreCol(MatrixRowCol&) {}    // Restore matrix col
  388.    virtual void NextCol(MatrixRowCol&);         // Go to next col
  389.    Real SumSquare() const;
  390.    Real SumAbsoluteValue() const;
  391.    Real MaximumAbsoluteValue() const;
  392.    LogAndSign LogDeterminant() const;
  393. #ifndef TEMPS_DESTROYED_QUICKLY
  394.    ConstMatrix c() const;                       // to access constant matrices
  395. #else
  396.    ConstMatrix& c() const;                      // to access constant matrices
  397. #endif
  398.    void CheckStore() const;                     // check store is non-zero
  399.    virtual void SetParameters(const GeneralMatrix*) {}
  400.                                                 // set parameters in GetMatrix
  401. #ifndef TEMPS_DESTROYED_QUICKLY
  402.    operator ReturnMatrixX() const;              // for building a ReturnMatrix
  403. #else
  404.    operator ReturnMatrixX&() const;             // for building a ReturnMatrix
  405. #endif
  406.    void CleanUp();                                // to clear store
  407.  
  408.    friend Matrix;
  409.    friend nricMatrix;
  410.    friend SymmetricMatrix;
  411.    friend UpperTriangularMatrix;
  412.    friend LowerTriangularMatrix;
  413.    friend DiagonalMatrix;
  414.    friend CroutMatrix;
  415.    friend RowVector;
  416.    friend ColumnVector;
  417.    friend BandMatrix;
  418.    friend LowerBandMatrix;
  419.    friend UpperBandMatrix;
  420.    friend SymmetricBandMatrix;
  421.    friend BaseMatrix;
  422.    friend AddedMatrix;
  423.    friend MultipliedMatrix;
  424.    friend SubtractedMatrix;
  425.    friend SolvedMatrix;
  426.    friend ShiftedMatrix;
  427.    friend ScaledMatrix;
  428.    friend TransposedMatrix;
  429.    friend NegatedMatrix;
  430.    friend InvertedMatrix;
  431.    friend RowedMatrix;
  432.    friend ColedMatrix;
  433.    friend DiagedMatrix;
  434.    friend MatedMatrix;
  435.    friend GetSubMatrix;
  436.    friend ConstMatrix;
  437.    friend ReturnMatrixX;
  438.    friend LinearEquationSolver;
  439.    NEW_DELETE(GeneralMatrix)
  440. };
  441.  
  442. class Matrix : public GeneralMatrix             // usual rectangular matrix
  443. {
  444. public:
  445.    Matrix() {}
  446.    Matrix(int, int);                            // standard declaration
  447.    Matrix(const BaseMatrix&);                   // evaluate BaseMatrix
  448.    void operator=(const BaseMatrix&);
  449.    void operator=(Real f) { GeneralMatrix::operator=(f); }
  450.    MatrixType Type() const;
  451.    Real& operator()(int, int);                  // access element
  452.    Real& element(int, int);                     // access element
  453.    Matrix(const Matrix& gm) { GetMatrix(&gm); }
  454. #ifndef __ZTC__
  455.    Real operator()(int, int) const;             // access element
  456. #endif
  457.    GeneralMatrix* MakeSolver();
  458.    Real Trace() const;
  459.    void GetRow(MatrixRowCol&);
  460.    void GetCol(MatrixRowCol&);
  461.    void RestoreCol(MatrixRowCol&);
  462.    void NextRow(MatrixRowCol&);
  463.    void NextCol(MatrixRowCol&);
  464.    void ReDimension(int,int);                   // change dimensions
  465.    NEW_DELETE(Matrix)
  466. };
  467.  
  468. class nricMatrix : public Matrix                // for use with Numerical
  469.                                                 // Recipes in C
  470. {
  471.    Real** row_pointer;                          // points to rows
  472.    void MakeRowPointer();                       // build rowpointer
  473.    void DeleteRowPointer();
  474. public:
  475.    nricMatrix() {}
  476.    nricMatrix(int m, int n)                     // standard declaration
  477.       :  Matrix(m,n) { MakeRowPointer(); }
  478.    nricMatrix(const BaseMatrix& bm)             // evaluate BaseMatrix
  479.       :  Matrix(bm) { MakeRowPointer(); }
  480.    void operator=(const BaseMatrix& bm)
  481.       { DeleteRowPointer(); Matrix::operator=(bm); MakeRowPointer(); }
  482.    void operator=(Real f) { GeneralMatrix::operator=(f); }
  483.    void operator<<(const BaseMatrix& X)
  484.       { DeleteRowPointer(); Eq(X,this->Type()); MakeRowPointer(); }
  485.    nricMatrix(const nricMatrix& gm) { GetMatrix(&gm); MakeRowPointer(); }
  486.    void ReDimension(int m, int n)               // change dimensions
  487.       { DeleteRowPointer(); Matrix::ReDimension(m,n); MakeRowPointer(); }
  488.    ~nricMatrix() { DeleteRowPointer(); }
  489. #ifndef __ZTC__
  490.    Real** nric() const { CheckStore(); return row_pointer-1; }
  491. #endif
  492.    void CleanUp();                                // to clear store
  493.    NEW_DELETE(nricMatrix)
  494. };
  495.  
  496. class SymmetricMatrix : public GeneralMatrix
  497. {
  498. public:
  499.    SymmetricMatrix() {}
  500.    SymmetricMatrix(ArrayLengthSpecifier);
  501.    SymmetricMatrix(const BaseMatrix&);
  502.    void operator=(const BaseMatrix&);
  503.    void operator=(Real f) { GeneralMatrix::operator=(f); }
  504.    Real& operator()(int, int);                  // access element
  505.    Real& element(int, int);                     // access element
  506.    MatrixType Type() const;
  507.    SymmetricMatrix(const SymmetricMatrix& gm) { GetMatrix(&gm); }
  508. #ifndef __ZTC__
  509.    Real operator()(int, int) const;             // access element
  510. #endif
  511.    Real SumSquare() const;
  512.    Real SumAbsoluteValue() const;
  513.    Real Trace() const;
  514.    void GetRow(MatrixRowCol&);
  515.    void GetCol(MatrixRowCol&);
  516.    GeneralMatrix* Transpose(TransposedMatrix*, MatrixType);
  517.    void ReDimension(int);                       // change dimensions
  518.    NEW_DELETE(SymmetricMatrix)
  519. };
  520.  
  521. class UpperTriangularMatrix : public GeneralMatrix
  522. {
  523. public:
  524.    UpperTriangularMatrix() {}
  525.    UpperTriangularMatrix(ArrayLengthSpecifier);
  526.    void operator=(const BaseMatrix&);
  527.    UpperTriangularMatrix(const BaseMatrix&);
  528.    UpperTriangularMatrix(const UpperTriangularMatrix& gm) { GetMatrix(&gm); }
  529. #ifndef __ZTC__
  530.    Real operator()(int, int) const;             // access element
  531. #endif
  532.    void operator=(Real f) { GeneralMatrix::operator=(f); }
  533.    Real& operator()(int, int);                  // access element
  534.    Real& element(int, int);                     // access element
  535.    MatrixType Type() const;
  536.    GeneralMatrix* MakeSolver() { return this; } // for solving
  537.    void Solver(MatrixRowCol&, const MatrixRowCol&);
  538.    LogAndSign LogDeterminant() const;
  539.    Real Trace() const;
  540.    void GetRow(MatrixRowCol&);
  541.    void GetCol(MatrixRowCol&);
  542.    void RestoreCol(MatrixRowCol&);
  543.    void NextRow(MatrixRowCol&);
  544.    void ReDimension(int);                       // change dimensions
  545.    NEW_DELETE(UpperTriangularMatrix)
  546. };
  547.  
  548. class LowerTriangularMatrix : public GeneralMatrix
  549. {
  550. public:
  551.    LowerTriangularMatrix() {}
  552.    LowerTriangularMatrix(ArrayLengthSpecifier);
  553.    LowerTriangularMatrix(const LowerTriangularMatrix& gm) { GetMatrix(&gm); }
  554. #ifndef __ZTC__
  555.    Real operator()(int, int) const;             // access element
  556. #endif
  557.    LowerTriangularMatrix(const BaseMatrix& M);
  558.    void operator=(const BaseMatrix&);
  559.    void operator=(Real f) { GeneralMatrix::operator=(f); }
  560.    Real& operator()(int, int);                  // access element
  561.    Real& element(int, int);                     // access element
  562.    MatrixType Type() const;
  563.    GeneralMatrix* MakeSolver() { return this; } // for solving
  564.    void Solver(MatrixRowCol&, const MatrixRowCol&);
  565.    LogAndSign LogDeterminant() const;
  566.    Real Trace() const;
  567.    void GetRow(MatrixRowCol&);
  568.    void GetCol(MatrixRowCol&);
  569.    void RestoreCol(MatrixRowCol&);
  570.    void NextRow(MatrixRowCol&);
  571.    void ReDimension(int);                       // change dimensions
  572.    NEW_DELETE(LowerTriangularMatrix)
  573. };
  574.  
  575. class DiagonalMatrix : public GeneralMatrix
  576. {
  577. public:
  578.    DiagonalMatrix() {}
  579.    DiagonalMatrix(ArrayLengthSpecifier);
  580.    DiagonalMatrix(const BaseMatrix&);
  581.    DiagonalMatrix(const DiagonalMatrix& gm) { GetMatrix(&gm); }
  582. #ifndef __ZTC__
  583.    Real operator()(int, int) const;             // access element
  584.    Real operator()(int) const;
  585. #endif
  586.    void operator=(const BaseMatrix&);
  587.    void operator=(Real f) { GeneralMatrix::operator=(f); }
  588.    Real& operator()(int, int);                  // access element
  589.    Real& operator()(int);                       // access element
  590.    Real& element(int, int);                     // access element
  591.    Real& element(int);                          // access element
  592.    MatrixType Type() const;
  593.  
  594.    LogAndSign LogDeterminant() const;
  595.    Real Trace() const;
  596.    void GetRow(MatrixRowCol&);
  597.    void GetCol(MatrixRowCol&);
  598.    void NextRow(MatrixRowCol&);
  599.    void NextCol(MatrixRowCol&);
  600.    GeneralMatrix* MakeSolver() { return this; } // for solving
  601.    void Solver(MatrixRowCol&, const MatrixRowCol&);
  602.    GeneralMatrix* Transpose(TransposedMatrix*, MatrixType);
  603.    void ReDimension(int);                       // change dimensions
  604. #ifndef __ZTC__
  605.    Real* nric() const
  606.       { CheckStore(); return store-1; }         // for use by NRIC
  607. #endif
  608.    MatrixBandWidth BandWidth() const;
  609.    NEW_DELETE(DiagonalMatrix)
  610. };
  611.  
  612. class RowVector : public Matrix
  613. {
  614. public:
  615.    RowVector() {}
  616.    RowVector(ArrayLengthSpecifier n) : Matrix(1,n.Value()) {}
  617.    RowVector(const BaseMatrix&);
  618.    RowVector(const RowVector& gm) { GetMatrix(&gm); }
  619. #ifndef __ZTC__
  620.    Real operator()(int) const;                  // access element
  621. #endif
  622.    void operator=(const BaseMatrix&);
  623.    void operator=(Real f) { GeneralMatrix::operator=(f); }
  624.    Real& operator()(int);                       // access element
  625.    Real& element(int);                          // access element
  626.    MatrixType Type() const;
  627.    void GetCol(MatrixRowCol&);
  628.    void NextCol(MatrixRowCol&);
  629.    void RestoreCol(MatrixRowCol&);
  630.    GeneralMatrix* Transpose(TransposedMatrix*, MatrixType);
  631.    void ReDimension(int);                       // change dimensions
  632. #ifndef __ZTC__
  633.    Real* nric() const
  634.       { CheckStore(); return store-1; }         // for use by NRIC
  635. #endif
  636.    void CleanUp();                                // to clear store
  637.    NEW_DELETE(RowVector)
  638. };
  639.  
  640. class ColumnVector : public Matrix
  641. {
  642. public:
  643.    ColumnVector() {}
  644.    ColumnVector(ArrayLengthSpecifier n) : Matrix(n.Value(),1) {}
  645.    ColumnVector(const BaseMatrix&);
  646.    ColumnVector(const ColumnVector& gm) { GetMatrix(&gm); }
  647. #ifndef __ZTC__
  648.    Real operator()(int) const;                  // access element
  649. #endif
  650.    void operator=(const BaseMatrix&);
  651.    void operator=(Real f) { GeneralMatrix::operator=(f); }
  652.    Real& operator()(int);                       // access element
  653.    Real& element(int);                          // access element
  654.    MatrixType Type() const;
  655.    GeneralMatrix* Transpose(TransposedMatrix*, MatrixType);
  656.    void ReDimension(int);                       // change dimensions
  657. #ifndef __ZTC__
  658.    Real* nric() const
  659.       { CheckStore(); return store-1; }         // for use by NRIC
  660. #endif
  661.    void CleanUp();                                // to clear store
  662.    NEW_DELETE(ColumnVector)
  663. };
  664.  
  665. class CroutMatrix : public GeneralMatrix        // for LU decomposition
  666. {
  667.    int* indx;
  668.    Boolean d;
  669.    Boolean sing;
  670.    void ludcmp();
  671. public:
  672.    CroutMatrix(const BaseMatrix&);
  673.    MatrixType Type() const;
  674.    void lubksb(Real*, int=0);
  675.    ~CroutMatrix();
  676.    GeneralMatrix* MakeSolver() { return this; } // for solving
  677.    LogAndSign LogDeterminant() const;
  678.    void Solver(MatrixRowCol&, const MatrixRowCol&);
  679.    void GetRow(MatrixRowCol&);
  680.    void GetCol(MatrixRowCol&);
  681.    void operator=(const BaseMatrix&);
  682.    void CleanUp();                                // to clear store
  683.    NEW_DELETE(CroutMatrix)
  684. };
  685.  
  686. /******************************* band matrices ***************************/
  687.  
  688. class BandMatrix : public GeneralMatrix         // band matrix
  689. {
  690. protected:
  691.    void CornerClear() const;                    // set unused elements to zero
  692. public:
  693.    int lower, upper;                            // band widths
  694.    BandMatrix() { lower=0; upper=0; CornerClear(); }
  695.    BandMatrix(int n,int lb,int ub) { ReDimension(n,lb,ub); CornerClear(); }
  696.                                                 // standard declaration
  697.    BandMatrix(const BaseMatrix&);               // evaluate BaseMatrix
  698.    void operator=(const BaseMatrix&);
  699.    void operator=(Real f) { GeneralMatrix::operator=(f); }
  700.    MatrixType Type() const;
  701.    Real& operator()(int, int);                  // access element
  702.    Real& element(int, int);                     // access element
  703.    BandMatrix(const BandMatrix& gm) { GetMatrix(&gm); }
  704. #ifndef __ZTC__
  705.    Real operator()(int, int) const;             // access element
  706. #endif
  707.    LogAndSign LogDeterminant() const;
  708.    GeneralMatrix* MakeSolver();
  709.    Real Trace() const;
  710.    Real SumSquare() const { CornerClear(); return GeneralMatrix::SumSquare(); }
  711.    Real SumAbsoluteValue() const
  712.       { CornerClear(); return GeneralMatrix::SumAbsoluteValue(); }
  713.    Real MaximumAbsoluteValue() const
  714.       { CornerClear(); return GeneralMatrix::MaximumAbsoluteValue(); }
  715.    void GetRow(MatrixRowCol&);
  716.    void GetCol(MatrixRowCol&);
  717.    void RestoreCol(MatrixRowCol&);
  718.    void NextRow(MatrixRowCol&);
  719.    void ReDimension(int, int, int);             // change dimensions
  720.    MatrixBandWidth BandWidth() const;
  721.    void SetParameters(const GeneralMatrix*);
  722.    NEW_DELETE(BandMatrix)
  723. };
  724.  
  725. class UpperBandMatrix : public BandMatrix       // upper band matrix
  726. {
  727. public:
  728.    UpperBandMatrix() {}
  729.    UpperBandMatrix(int n, int ubw)              // standard declaration
  730.       : BandMatrix(n, 0, ubw) {}
  731.    UpperBandMatrix(const BaseMatrix&);          // evaluate BaseMatrix
  732.    void operator=(const BaseMatrix&);
  733.    void operator=(Real f) { GeneralMatrix::operator=(f); }
  734.    MatrixType Type() const;
  735.    UpperBandMatrix(const UpperBandMatrix& gm) { GetMatrix(&gm); }
  736.    GeneralMatrix* MakeSolver() { return this; }
  737.    void Solver(MatrixRowCol&, const MatrixRowCol&);
  738.    LogAndSign LogDeterminant() const;
  739.    void ReDimension(int n,int ubw)              // change dimensions
  740.       { BandMatrix::ReDimension(n,0,ubw); }
  741.    Real& operator()(int, int);
  742.    Real& element(int, int);
  743.    NEW_DELETE(UpperBandMatrix)
  744. };
  745.  
  746. class LowerBandMatrix : public BandMatrix       // upper band matrix
  747. {
  748. public:
  749.    LowerBandMatrix() {}
  750.    LowerBandMatrix(int n, int lbw)              // standard declaration
  751.       : BandMatrix(n, lbw, 0) {}
  752.    LowerBandMatrix(const BaseMatrix&);          // evaluate BaseMatrix
  753.    void operator=(const BaseMatrix&);
  754.    void operator=(Real f) { GeneralMatrix::operator=(f); }
  755.    MatrixType Type() const;
  756.    LowerBandMatrix(const LowerBandMatrix& gm) { GetMatrix(&gm); }
  757.    GeneralMatrix* MakeSolver() { return this; }
  758.    void Solver(MatrixRowCol&, const MatrixRowCol&);
  759.    LogAndSign LogDeterminant() const;
  760.    void ReDimension(int n,int lbw)             // change dimensions
  761.       { BandMatrix::ReDimension(n,lbw,0); }
  762.    Real& operator()(int, int);
  763.    Real& element(int, int);
  764.    NEW_DELETE(LowerBandMatrix)
  765. };
  766.  
  767. class SymmetricBandMatrix : public GeneralMatrix
  768. {
  769.    void CornerClear() const;                    // set unused elements to zero
  770. public:
  771.    int lower;                                   // lower band width
  772.    SymmetricBandMatrix() { lower=0; CornerClear(); }
  773.    SymmetricBandMatrix(int n, int lb) { ReDimension(n,lb); CornerClear(); }
  774.    SymmetricBandMatrix(const BaseMatrix&);
  775.    void operator=(const BaseMatrix&);
  776.    void operator=(Real f) { GeneralMatrix::operator=(f); }
  777.    Real& operator()(int, int);                  // access element
  778.    Real& element(int, int);                     // access element
  779.    MatrixType Type() const;
  780.    SymmetricBandMatrix(const SymmetricBandMatrix& gm) { GetMatrix(&gm); }
  781. #ifndef __ZTC__
  782.    Real operator()(int, int) const;             // access element
  783. #endif
  784.    GeneralMatrix* MakeSolver();
  785.    Real SumSquare() const;
  786.    Real SumAbsoluteValue() const;
  787.    Real MaximumAbsoluteValue() const
  788.       { CornerClear(); return GeneralMatrix::MaximumAbsoluteValue(); }
  789.    Real Trace() const;
  790.    LogAndSign LogDeterminant() const;
  791.    void GetRow(MatrixRowCol&);
  792.    void GetCol(MatrixRowCol&);
  793.    GeneralMatrix* Transpose(TransposedMatrix*, MatrixType);
  794.    void ReDimension(int,int);                       // change dimensions
  795.    MatrixBandWidth BandWidth() const;
  796.    void SetParameters(const GeneralMatrix*);
  797.    NEW_DELETE(SymmetricBandMatrix)
  798. };
  799.  
  800. class BandLUMatrix : public GeneralMatrix
  801. // for LU decomposition of band matrix
  802. {
  803.    int* indx;
  804.    Boolean d;
  805.    Boolean sing;                                   // TRUE if singular
  806.    Real* store2;
  807.    int storage2;
  808.    void ludcmp();
  809.    int m1,m2;                                   // lower and upper
  810. public:
  811.    BandLUMatrix(const BaseMatrix&);
  812.    MatrixType Type() const;
  813.    void lubksb(Real*, int=0);
  814.    ~BandLUMatrix();
  815.    GeneralMatrix* MakeSolver() { return this; } // for solving
  816.    LogAndSign LogDeterminant() const;
  817.    void Solver(MatrixRowCol&, const MatrixRowCol&);
  818.    void GetRow(MatrixRowCol&);
  819.    void GetCol(MatrixRowCol&);
  820.    void operator=(const BaseMatrix&);
  821.    NEW_DELETE(BandLUMatrix)
  822.    void CleanUp();                                // to clear store
  823. };
  824.  
  825.  
  826. /***************************** temporary classes *************************/
  827.  
  828. class MultipliedMatrix : public BaseMatrix
  829. {
  830. protected:
  831.    union { const BaseMatrix* bm1; GeneralMatrix* gm1; };
  832.                           // pointers to summands
  833.    union { const BaseMatrix* bm2; GeneralMatrix* gm2; };
  834.    MultipliedMatrix(const BaseMatrix* bm1x, const BaseMatrix* bm2x)
  835.       : bm1(bm1x),bm2(bm2x) {}
  836.    int search(const BaseMatrix*) const;
  837. //   int NrowsV() const;
  838. //   int NcolsV() const;
  839.    MatrixType Type() const;
  840.    friend BaseMatrix;
  841. public:
  842.    GeneralMatrix* Evaluate(MatrixType);
  843.    MatrixBandWidth BandWidth() const;
  844.    NEW_DELETE(MultipliedMatrix)
  845. };
  846.  
  847. class AddedMatrix : public MultipliedMatrix
  848. {
  849. protected:
  850.    AddedMatrix(const BaseMatrix* bm1x, const BaseMatrix* bm2x)
  851.       : MultipliedMatrix(bm1x,bm2x) {}
  852.  
  853. private:
  854.    MatrixType Type() const;
  855.    friend BaseMatrix;
  856. public:
  857.    GeneralMatrix* Evaluate(MatrixType);
  858.    MatrixBandWidth BandWidth() const;
  859. #ifdef GXX
  860.    void SelectVersion(MatrixType, int&, int&) const;
  861. #else
  862.    void SelectVersion(MatrixType, Boolean&, Boolean&) const;
  863. #endif
  864.    NEW_DELETE(AddedMatrix)
  865. };
  866.  
  867. class SolvedMatrix : public MultipliedMatrix
  868. {
  869.    SolvedMatrix(const BaseMatrix* bm1x, const BaseMatrix* bm2x)
  870.       : MultipliedMatrix(bm1x,bm2x) {}
  871.    MatrixType Type() const;
  872.    friend BaseMatrix;
  873.    friend InvertedMatrix;                        // for operator*
  874. public:
  875.    GeneralMatrix* Evaluate(MatrixType);
  876.    MatrixBandWidth BandWidth() const;
  877.    NEW_DELETE(SolvedMatrix)
  878. };
  879.  
  880. class SubtractedMatrix : public AddedMatrix
  881. {
  882.    SubtractedMatrix(const BaseMatrix* bm1x, const BaseMatrix* bm2x)
  883.       : AddedMatrix(bm1x,bm2x) {}
  884.    MatrixType Type() const;
  885.    friend BaseMatrix;
  886. public:
  887.    GeneralMatrix* Evaluate(MatrixType);
  888.    NEW_DELETE(SubtractedMatrix)
  889. };
  890.  
  891. class ShiftedMatrix : public BaseMatrix
  892. {
  893. protected:
  894.    Real f;
  895.    union { const BaseMatrix* bm; GeneralMatrix* gm; };
  896.    ShiftedMatrix(const BaseMatrix* bmx, Real fx) : bm(bmx),f(fx) {}
  897.    int search(const BaseMatrix*) const;
  898. //   int NrowsV() const;
  899. //   int NcolsV() const;
  900. private:
  901.    MatrixType Type() const;
  902.    friend BaseMatrix;
  903. public:
  904.    GeneralMatrix* Evaluate(MatrixType);
  905.    NEW_DELETE(ShiftedMatrix)
  906. };
  907.  
  908. class ScaledMatrix : public ShiftedMatrix
  909. {
  910.    ScaledMatrix(const BaseMatrix* bmx, Real fx) : ShiftedMatrix(bmx,fx) {}
  911.    MatrixType Type() const;
  912.    friend BaseMatrix;
  913. public:
  914.    GeneralMatrix* Evaluate(MatrixType);
  915.    MatrixBandWidth BandWidth() const;
  916.    NEW_DELETE(ScaledMatrix)
  917. };
  918.  
  919. class NegatedMatrix : public BaseMatrix
  920. {
  921. protected:
  922.    union { const BaseMatrix* bm; GeneralMatrix* gm; };
  923.    NegatedMatrix(const BaseMatrix* bmx) : bm(bmx) {}
  924.    int search(const BaseMatrix*) const;
  925. //   int NrowsV() const;
  926. //   int NcolsV() const;
  927. private:
  928.    MatrixType Type() const;
  929.    friend BaseMatrix;
  930. public:
  931.    GeneralMatrix* Evaluate(MatrixType);
  932.    MatrixBandWidth BandWidth() const;
  933.    NEW_DELETE(NegatedMatrix)
  934. };
  935.  
  936. class TransposedMatrix : public NegatedMatrix
  937. {
  938.    TransposedMatrix(const BaseMatrix* bmx) : NegatedMatrix(bmx) {}
  939. //   int NrowsV() const;
  940. //   int NcolsV() const;
  941.    MatrixType Type() const;
  942.    friend BaseMatrix;
  943. public:
  944.    GeneralMatrix* Evaluate(MatrixType);
  945.    MatrixBandWidth BandWidth() const;
  946.    NEW_DELETE(TransposedMatrix)
  947. };
  948.  
  949. class InvertedMatrix : public NegatedMatrix
  950. {
  951.    InvertedMatrix(const BaseMatrix* bmx) : NegatedMatrix(bmx) {}
  952.    MatrixType Type() const;
  953. public:
  954. #ifndef TEMPS_DESTROYED_QUICKLY
  955.    SolvedMatrix operator*(const BaseMatrix&) const;       // inverse(A) * B
  956. #else
  957.    SolvedMatrix& operator*(const BaseMatrix&) const;       // inverse(A) * B
  958. #endif
  959.    friend BaseMatrix;
  960.    GeneralMatrix* Evaluate(MatrixType);
  961.    MatrixBandWidth BandWidth() const;
  962.    NEW_DELETE(InvertedMatrix)
  963. };
  964.  
  965. class RowedMatrix : public NegatedMatrix
  966. {
  967.    MatrixType Type() const;
  968. //   int NrowsV() const;
  969. //   int NcolsV() const;
  970.    RowedMatrix(const BaseMatrix* bmx) : NegatedMatrix(bmx) {}
  971.    friend BaseMatrix;
  972. public:
  973.    GeneralMatrix* Evaluate(MatrixType);
  974.    MatrixBandWidth BandWidth() const;
  975.    NEW_DELETE(RowedMatrix)
  976. };
  977.  
  978. class ColedMatrix : public NegatedMatrix
  979. {
  980.    MatrixType Type() const;
  981. //   int NrowsV() const;
  982. //   int NcolsV() const;
  983.    ColedMatrix(const BaseMatrix* bmx) : NegatedMatrix(bmx) {}
  984.    friend BaseMatrix;
  985. public:
  986.    GeneralMatrix* Evaluate(MatrixType);
  987.    MatrixBandWidth BandWidth() const;
  988.    NEW_DELETE(ColedMatrix)
  989. };
  990.  
  991. class DiagedMatrix : public NegatedMatrix
  992. {
  993.    MatrixType Type() const;
  994. //   int NrowsV() const;
  995. //   int NcolsV() const;
  996.    DiagedMatrix(const BaseMatrix* bmx) : NegatedMatrix(bmx) {}
  997.    friend BaseMatrix;
  998. public:
  999.    GeneralMatrix* Evaluate(MatrixType);
  1000.    MatrixBandWidth BandWidth() const;
  1001.    NEW_DELETE(DiagedMatrix)
  1002. };
  1003.  
  1004. class MatedMatrix : public NegatedMatrix
  1005. {
  1006.    int nr, nc;
  1007.    MatrixType Type() const;
  1008. //   int NrowsV() const;
  1009. //   int NcolsV() const;
  1010.    MatedMatrix(const BaseMatrix* bmx, int nrx, int ncx)
  1011.       : NegatedMatrix(bmx), nr(nrx), nc(ncx) {}
  1012.    friend BaseMatrix;
  1013. public:
  1014.    GeneralMatrix* Evaluate(MatrixType);
  1015.    MatrixBandWidth BandWidth() const;
  1016.    NEW_DELETE(MatedMatrix)
  1017. };
  1018.  
  1019. class ConstMatrix : public BaseMatrix
  1020. {
  1021.    const GeneralMatrix* cgm;
  1022.    MatrixType Type() const;
  1023. //   int NrowsV() const;
  1024. //   int NcolsV() const;
  1025.    int search(const BaseMatrix*) const;
  1026.    ConstMatrix(const GeneralMatrix* cgmx) : cgm(cgmx) {}
  1027.    friend BaseMatrix;
  1028.    friend GeneralMatrix;
  1029. public:
  1030.    GeneralMatrix* Evaluate(MatrixType);
  1031.    MatrixBandWidth BandWidth() const;
  1032.    NEW_DELETE(ConstMatrix)
  1033. };
  1034.  
  1035. class ReturnMatrixX : public BaseMatrix    // for matrix return
  1036. {
  1037.    GeneralMatrix* gm;
  1038.    MatrixType Type() const;
  1039. //   int NrowsV() const;
  1040. //   int NcolsV() const;
  1041.    int search(const BaseMatrix*) const;
  1042. public:
  1043.    GeneralMatrix* Evaluate(MatrixType);
  1044.    friend BaseMatrix;
  1045. #ifdef TEMPS_DESTROYED_QUICKLY
  1046.    ReturnMatrixX(const ReturnMatrixX& tm);
  1047. #else
  1048.    ReturnMatrixX(const ReturnMatrixX& tm) : gm(tm.gm) {}
  1049. #endif
  1050.    ReturnMatrixX(const GeneralMatrix* gmx) : gm((GeneralMatrix*&)gmx) {}
  1051. //   ReturnMatrixX(GeneralMatrix&);
  1052.    MatrixBandWidth BandWidth() const;
  1053.    NEW_DELETE(ReturnMatrixX)
  1054. };
  1055.  
  1056.  
  1057. /**************************** submatrices ******************************/
  1058.  
  1059. class GetSubMatrix : public NegatedMatrix
  1060. {
  1061.    int row_skip;
  1062.    int row_number;
  1063.    int col_skip;
  1064.    int col_number;
  1065.    MatrixType mt;
  1066.  
  1067.    GetSubMatrix
  1068.       (const BaseMatrix* bmx, int rs, int rn, int cs, int cn, MatrixType mtx)
  1069.       : NegatedMatrix(bmx),
  1070.       row_skip(rs), row_number(rn), col_skip(cs), col_number(cn), mt(mtx) {}
  1071.    GetSubMatrix(const GetSubMatrix& g)
  1072.       : NegatedMatrix(g.bm), row_skip(g.row_skip), row_number(g.row_number),
  1073.       col_skip(g.col_skip), col_number(g.col_number), mt(g.mt) {}
  1074.    void SetUpLHS();
  1075.    MatrixType Type() const;
  1076. //   int NrowsV() const;
  1077. //   int NcolsV() const;
  1078.    friend BaseMatrix;
  1079. public:
  1080.    GeneralMatrix* Evaluate(MatrixType);
  1081.    void operator=(const BaseMatrix&);
  1082.    void operator<<(const BaseMatrix&);
  1083.    void operator<<(const Real*);                // copy from array
  1084.    void operator<<(Real);                       // copy from constant
  1085.    void Inject(const GeneralMatrix&);           // copy stored els only
  1086.    MatrixBandWidth BandWidth() const;
  1087.    NEW_DELETE(GetSubMatrix)
  1088. };
  1089.  
  1090.  
  1091. /***************************** exceptions ********************************/
  1092.  
  1093. class MatrixDetails
  1094. {
  1095.    MatrixType type;
  1096.    int nrows;
  1097.    int ncols;
  1098.    int ubw;
  1099.    int lbw;
  1100. public:
  1101.    MatrixDetails(const GeneralMatrix& A);
  1102.    void PrintOut();
  1103. };
  1104.    
  1105.  
  1106.  
  1107. class SpaceException : public Exception
  1108. {
  1109. public:
  1110.    static long st_type() { return 2; }
  1111.    long type() const { return 2; }
  1112.    static int action;
  1113.    SpaceException();
  1114.    static void SetAction(int a) { action=a; }
  1115. };
  1116.  
  1117.  
  1118. class MatrixException : public Exception
  1119. {
  1120. public:
  1121.    static long st_type() { return 3; }
  1122.    long type() const { return 3; }
  1123.    MatrixException(int);
  1124.    MatrixException(int, const GeneralMatrix&);
  1125.    MatrixException(int, const GeneralMatrix&, const GeneralMatrix&);
  1126. };
  1127.  
  1128. class DataException : public MatrixException
  1129. {
  1130. public:
  1131.    static long st_type() { return 3*53; }
  1132.    long type() const { return 3*53; }
  1133.    static int action;
  1134.    DataException(const GeneralMatrix& A);
  1135.    static void SetAction(int a) { action=a; }
  1136. };
  1137.  
  1138. class SingularException : public DataException
  1139. {
  1140. public:
  1141.    static long st_type() { return 3*53*109; }
  1142.    long type() const { return 3*53*109; }
  1143.    SingularException(const GeneralMatrix& A);
  1144. };
  1145.  
  1146. class NPDException : public DataException     // Not positive definite
  1147. {
  1148. public:
  1149.    static long st_type() { return 3*53*113; }
  1150.    long type() const { return 3*53*113; }
  1151.    NPDException(const GeneralMatrix&);
  1152. };
  1153.  
  1154. class ConvergenceException : public MatrixException
  1155. {
  1156. public:
  1157.    static long st_type() { return 3*59; }
  1158.    long type() const { return 3*59; }
  1159.    static int action;
  1160.    ConvergenceException(const GeneralMatrix& A);
  1161.    static void SetAction(int a) { action=a; }
  1162. };
  1163.  
  1164. class ProgramException : public MatrixException
  1165. {
  1166. public:
  1167.    static long st_type() { return 3*61; }
  1168.    long type() const { return 3*61; }
  1169.    static int action;
  1170.    ProgramException(char* c);
  1171.    ProgramException(char* c, const GeneralMatrix&);
  1172.    ProgramException(char* c, const GeneralMatrix&, const GeneralMatrix&);
  1173.    ProgramException();
  1174.    ProgramException(const GeneralMatrix&);
  1175.    static void SetAction(int a) { action=a; }
  1176. };
  1177.  
  1178. class IndexException : public ProgramException
  1179. {
  1180. public:
  1181.    static long st_type() { return 3*61*101; }
  1182.    long type() const { return 3*61*101; }
  1183.    IndexException(int i, const GeneralMatrix& A);
  1184.    IndexException(int i, int j, const GeneralMatrix& A);
  1185.    // next two are for access via element function
  1186.    IndexException(int i, const GeneralMatrix& A, Boolean);
  1187.    IndexException(int i, int j, const GeneralMatrix& A, Boolean);
  1188. };
  1189.  
  1190. class VectorException : public ProgramException    // can't convert to vector
  1191. {
  1192. public:
  1193.    static long st_type() { return 3*61*107; }
  1194.    long type() const { return 3*61*107; }
  1195.    VectorException();
  1196.    VectorException(const GeneralMatrix& A);
  1197. };
  1198.  
  1199. class NotSquareException : public ProgramException
  1200. {
  1201. public:
  1202.    static long st_type() { return 3*61*109; }
  1203.    long type() const { return 3*61*109; }
  1204.    NotSquareException(const GeneralMatrix& A);
  1205. };
  1206.  
  1207. class SubMatrixDimensionException : public ProgramException
  1208. {
  1209. public:
  1210.    static long st_type() { return 3*61*113; }
  1211.    long type() const { return 3*61*113; }
  1212.    SubMatrixDimensionException();
  1213. };
  1214.  
  1215. class IncompatibleDimensionsException : public ProgramException
  1216. {
  1217. public:
  1218.    static long st_type() { return 3*61*127; }
  1219.    long type() const { return 3*61*127; }
  1220.    IncompatibleDimensionsException();
  1221. };
  1222.  
  1223. class NotDefinedException : public ProgramException
  1224. {
  1225. public:
  1226.    static long st_type() { return 3*61*131; }
  1227.    long type() const { return 3*61*131; }
  1228.    NotDefinedException(char* op, char* matrix);
  1229. };
  1230.  
  1231. class CannotBuildException : public ProgramException
  1232. {
  1233. public:
  1234.    static long st_type() { return 3*61*137; }
  1235.    long type() const { return 3*61*137; }
  1236.    CannotBuildException(char* matrix);
  1237. };
  1238.  
  1239.  
  1240. class InternalException : public MatrixException
  1241. {
  1242. public:
  1243.    static long st_type() { return 3*67; }
  1244.    long type() const { return 3*67; }
  1245.    static int action;
  1246.    InternalException(char* c);
  1247.    static void SetAction(int a) { action=a; }
  1248. };
  1249.  
  1250.  
  1251. /***************************** functions ***********************************/
  1252.  
  1253.  
  1254. inline LogAndSign LogDeterminant(const BaseMatrix& B)
  1255.    { return B.LogDeterminant(); }
  1256. inline Real SumSquare(const BaseMatrix& B) { return B.SumSquare(); }
  1257. inline Real Trace(const BaseMatrix& B) { return B.Trace(); }
  1258. inline Real SumAbsoluteValue(const BaseMatrix& B)
  1259.    { return B.SumAbsoluteValue(); }
  1260. inline Real MaximumAbsoluteValue(const BaseMatrix& B)
  1261.    { return B.MaximumAbsoluteValue(); }
  1262. inline Real Norm1(const BaseMatrix& B) { return B.Norm1(); }
  1263. inline Real Norm1(RowVector& RV) { return RV.MaximumAbsoluteValue(); }
  1264. inline Real NormInfinity(const BaseMatrix& B) { return B.NormInfinity(); }
  1265. inline Real NormInfinity(ColumnVector& CV)
  1266.    { return CV.MaximumAbsoluteValue(); } 
  1267.  
  1268. #endif
  1269.