newmat.h

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

Generated on 6 Apr 2011 for Slicer3 by  doxygen 1.6.1