newmatrc.h
Go to the documentation of this file.
00001 //$$ newmatrc.h              definition file for row/column classes
00002 
00003 // Copyright (C) 1991,2,3,4,7: R B Davies
00004 
00005 #ifndef NEWMATRC_LIB
00006 #define NEWMATRC_LIB 0
00007 
00008 #ifdef use_namespace
00009 namespace NEWMAT {
00010 #endif
00011 
00012 #include "controlw.h"
00013 
00014 
00015 /************** classes MatrixRowCol, MatrixRow, MatrixCol *****************/
00016 
00017 // Used for accessing the rows and columns of matrices
00018 // All matrix classes must provide routines for calculating matrix rows and
00019 // columns. Assume rows can be found very efficiently.
00020 
00021 enum LSF { LoadOnEntry=1,StoreOnExit=2,DirectPart=4,StoreHere=8,HaveStore=16 };
00022 
00023 
00024 class LoadAndStoreFlag : public ControlWord
00025 {
00026 public:
00027    LoadAndStoreFlag() {}
00028    LoadAndStoreFlag(int i) : ControlWord(i) {}
00029    LoadAndStoreFlag(LSF lsf) : ControlWord(lsf) {}
00030    LoadAndStoreFlag(const ControlWord& cwx) : ControlWord(cwx) {}
00031 };
00032 
00033 class MatrixRowCol
00034 // the row or column of a matrix
00035 {
00036 public:                                        // these are public to avoid
00037                                                // numerous friend statements
00038    int length;                                 // row or column length
00039    int skip;                                   // initial number of zeros
00040    int storage;                                // number of stored elements
00041    int rowcol;                                 // row or column number
00042    GeneralMatrix* gm;                          // pointer to parent matrix
00043    Real* data;                                 // pointer to local storage
00044    LoadAndStoreFlag cw;                        // Load? Store? Is a Copy?
00045    void IncrMat() { rowcol++; data += storage; }   // used by NextRow
00046    void IncrDiag() { rowcol++; skip++; data++; }
00047    void IncrId() { rowcol++; skip++; }
00048    void IncrUT() { rowcol++; data += storage; storage--; skip++; }
00049    void IncrLT() { rowcol++; data += storage; storage++; }
00050 
00051 public:
00052    void Zero();                                // set elements to zero
00053    void Add(const MatrixRowCol&);              // add a row/col
00054    void AddScaled(const MatrixRowCol&, Real);  // add a multiple of a row/col
00055    void Add(const MatrixRowCol&, const MatrixRowCol&);
00056                                                // add two rows/cols
00057    void Add(const MatrixRowCol&, Real);        // add a row/col
00058    void NegAdd(const MatrixRowCol&, Real);     // Real - a row/col
00059    void Sub(const MatrixRowCol&);              // subtract a row/col
00060    void Sub(const MatrixRowCol&, const MatrixRowCol&);
00061                                                // sub a row/col from another
00062    void RevSub(const MatrixRowCol&);           // subtract from a row/col
00063    void ConCat(const MatrixRowCol&, const MatrixRowCol&);
00064                                                // concatenate two row/cols
00065    void Multiply(const MatrixRowCol&);         // multiply a row/col
00066    void Multiply(const MatrixRowCol&, const MatrixRowCol&);
00067                                                // multiply two row/cols
00068    void KP(const MatrixRowCol&, const MatrixRowCol&);
00069                                                // Kronecker Product two row/cols
00070    void Copy(const MatrixRowCol&);             // copy a row/col
00071    void CopyCheck(const MatrixRowCol&);        // ... check for data loss
00072    void Check(const MatrixRowCol&);            // just check for data loss
00073    void Check();                               // check full row/col present
00074    void Copy(const Real*&);                    // copy from an array
00075    void Copy(Real);                            // copy from constant
00076    void Add(Real);                             // add a constant
00077    void Multiply(Real);                        // multiply by constant
00078    Real SumAbsoluteValue();                    // sum of absolute values
00079    Real MaximumAbsoluteValue1(Real r, int& i); // maximum of absolute values
00080    Real MinimumAbsoluteValue1(Real r, int& i); // minimum of absolute values
00081    Real Maximum1(Real r, int& i);              // maximum
00082    Real Minimum1(Real r, int& i);              // minimum
00083    Real Sum();                                 // sum of values
00084    void Inject(const MatrixRowCol&);           // copy stored els of a row/col
00085    void Negate(const MatrixRowCol&);           // change sign of a row/col
00086    void Multiply(const MatrixRowCol&, Real);   // scale a row/col
00087    friend Real DotProd(const MatrixRowCol&, const MatrixRowCol&);
00088                                                // sum of pairwise product
00089    Real* Data() { return data; }
00090    int Skip() { return skip; }                 // number of elements skipped
00091    int Storage() { return storage; }           // number of elements stored
00092    int Length() { return length; }             // length of row or column
00093    void Skip(int i) { skip=i; }
00094    void Storage(int i) { storage=i; }
00095    void Length(int i) { length=i; }
00096    void SubRowCol(MatrixRowCol&, int, int) const;
00097                                                // get part of a row or column
00098    MatrixRowCol() {}                           // to stop warning messages
00099    ~MatrixRowCol();
00100    FREE_CHECK(MatrixRowCol)
00101 };
00102 
00103 class MatrixRow : public MatrixRowCol
00104 {
00105 public:
00106    // bodies for these are inline at the end of this .h file
00107    MatrixRow(GeneralMatrix*, LoadAndStoreFlag, int=0);
00108                                                // extract a row
00109    ~MatrixRow();
00110    void Next();                                // get next row
00111    FREE_CHECK(MatrixRow)
00112 };
00113 
00114 class MatrixCol : public MatrixRowCol
00115 {
00116 public:
00117    // bodies for these are inline at the end of this .h file
00118    MatrixCol(GeneralMatrix*, LoadAndStoreFlag, int=0);
00119                                                // extract a col
00120    MatrixCol(GeneralMatrix*, Real*, LoadAndStoreFlag, int=0);
00121                                                // store/retrieve a col
00122    ~MatrixCol();
00123    void Next();                                // get next row
00124    FREE_CHECK(MatrixCol)
00125 };
00126 
00127 // MatrixColX is an alternative to MatrixCol where the complete
00128 // column is stored externally
00129 
00130 class MatrixColX : public MatrixRowCol
00131 {
00132 public:
00133    // bodies for these are inline at the end of this .h file
00134    MatrixColX(GeneralMatrix*, Real*, LoadAndStoreFlag, int=0);
00135                                                // store/retrieve a col
00136    ~MatrixColX();
00137    void Next();                                // get next row
00138    Real* store;                                // pointer to local storage
00139                                                //    less skip
00140    FREE_CHECK(MatrixColX)
00141 };
00142 
00143 /**************************** inline bodies ****************************/
00144 
00145 inline MatrixRow::MatrixRow(GeneralMatrix* gmx, LoadAndStoreFlag cwx, int row)
00146 { gm=gmx; cw=cwx; rowcol=row; gm->GetRow(*this); }
00147 
00148 inline void MatrixRow::Next() { gm->NextRow(*this); }
00149 
00150 inline MatrixCol::MatrixCol(GeneralMatrix* gmx, LoadAndStoreFlag cwx, int col)
00151 { gm=gmx; cw=cwx; rowcol=col; gm->GetCol(*this); }
00152 
00153 inline MatrixCol::MatrixCol(GeneralMatrix* gmx, Real* r,
00154    LoadAndStoreFlag cwx, int col)
00155 { gm=gmx; data=r; cw=cwx+StoreHere; rowcol=col; gm->GetCol(*this); }
00156 
00157 inline MatrixColX::MatrixColX(GeneralMatrix* gmx, Real* r,
00158    LoadAndStoreFlag cwx, int col)
00159 { gm=gmx; store=data=r; cw=cwx+StoreHere; rowcol=col; gm->GetCol(*this); }
00160 
00161 
00162 inline void MatrixCol::Next() { gm->NextCol(*this); }
00163 
00164 inline void MatrixColX::Next() { gm->NextCol(*this); }
00165 
00166 #ifdef use_namespace
00167 }
00168 #endif
00169 
00170 #endif


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