Virtual U.org
Get Personal Training on VU Today
    
Top shadow
 
 register/help
User Name:

Password:

NEWMATRC.H Source File
Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

NEWMATRC.H

Go to the documentation of this file.
00001 //Owner: Fred
00002 //$$ newmatrc.h              definition file for row/column classes
00003 
00004 // Copyright (C) 1991,2,3,4,7: R B Davies
00005 
00006 #ifndef NEWMATRC_LIB
00007 #define NEWMATRC_LIB 0
00008 
00009 #ifdef use_namespace
00010 namespace NEWMAT {
00011 #endif
00012 
00013 #include "controlw.h"
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 
00024     class LoadAndStoreFlag : public ControlWord {
00025     public:
00026         LoadAndStoreFlag() {}
00027         LoadAndStoreFlag(int i) : ControlWord(i) {}
00028         LoadAndStoreFlag(LSF lsf) : ControlWord(lsf) {}
00029         LoadAndStoreFlag(const ControlWord& cwx) : ControlWord(cwx) {}
00030     };
00031 
00033     class MatrixRowCol {
00034         // the row or column of a matrix
00035     public:                                       // these are public to avoid
00036         // numerous friend statements
00037         int length;                                 // row or column length
00038         int skip;                                   // initial number of zeros
00039         int storage;                                // number of stored elements
00040         int rowcol;                                 // row or column number
00041         GeneralMatrix* gm;                          // pointer to parent matrix
00042         Real* data;                                 // pointer to local storage
00043         LoadAndStoreFlag cw;                        // Load? Store? Is a Copy?
00044         void IncrMat() { rowcol++; data += storage; }
00045         // used by NextRow
00046         void IncrDiag() { rowcol++; skip++; data++; }
00047         void IncrUT()
00048             { rowcol++; data += storage; storage--; skip++; }
00049         void IncrLT() { rowcol++; data += storage; storage++; }
00050 
00051     public:
00052         void Add(const MatrixRowCol&);              // add a row/col
00053         void AddScaled(const MatrixRowCol&, Real);  // add a multiple of a row/col
00054         void Add(const MatrixRowCol&, const MatrixRowCol&);
00055         // add two rows/cols
00056         void Add(const MatrixRowCol&, Real);        // add a row/col
00057         void NegAdd(const MatrixRowCol&, Real);     // Real - a row/col
00058         void Sub(const MatrixRowCol&);              // subtract a row/col
00059         void Sub(const MatrixRowCol&, const MatrixRowCol&);
00060         // sub a row/col from another
00061         void RevSub(const MatrixRowCol&);           // subtract from a row/col
00062         void ConCat(const MatrixRowCol&, const MatrixRowCol&);
00063         // concatenate two row/cols
00064         void Multiply(const MatrixRowCol&);         // multiply a row/col
00065         void Multiply(const MatrixRowCol&, const MatrixRowCol&);
00066         // multiply two row/cols
00067         void Copy(const MatrixRowCol&);             // copy a row/col
00068         void CopyCheck(const MatrixRowCol&);        // ... check for data loss
00069         void Check(const MatrixRowCol&);            // just check for data loss
00070         void Check();                               // check full row/col present
00071         void Copy(const Real*&);                    // copy from an array
00072         void Copy(Real);                            // copy from constant
00073         void Add(Real);                             // add a constant
00074         void Multiply(Real);                        // multiply by constant
00075         Real SumAbsoluteValue();                    // sum of absolute values
00076         Real Sum();                                 // sum of values
00077         void Inject(const MatrixRowCol&);           // copy stored els of a row/col
00078         void Negate(const MatrixRowCol&);           // change sign of a row/col
00079         void Multiply(const MatrixRowCol&, Real);   // scale a row/col
00080         friend Real DotProd(const MatrixRowCol&, const MatrixRowCol&);
00081         // sum of pairwise product
00082         Real* Data() { return data; }
00083         int Skip() {                                // number of elements skipped
00084             return skip;
00085         }
00086         int Storage() {                             // number of elements stored
00087             return storage;
00088         }
00089         int Length() {                              // length of row or column
00090             return length;
00091         }
00092         void Skip(int i) { skip=i; }
00093         void Storage(int i) { storage=i; }
00094         void Length(int i) { length=i; }
00095         void SubRowCol(MatrixRowCol&, int, int) const;
00096         // get part of a row or column
00097         MatrixRowCol() {                            // to stop warning messages
00098         }
00099         ~MatrixRowCol();
00100         FREE_CHECK(MatrixRowCol)
00101             };
00102 
00104     class MatrixRow : public MatrixRowCol {
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 
00115     class MatrixCol : public MatrixRowCol {
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 
00132     class MatrixColX : public MatrixRowCol {
00133     public:
00134         // bodies for these are inline at the end of this .h file
00135         MatrixColX(GeneralMatrix*, Real*, LoadAndStoreFlag, int=0);
00136         // store/retrieve a col
00137         ~MatrixColX();
00138         void Next();                                // get next row
00139         Real* store;                                // pointer to local storage
00140         //    less skip
00141         FREE_CHECK(MatrixColX)
00142             };
00143 
00144     /**************************** inline bodies ****************************/
00145 
00146     inline MatrixRow::MatrixRow(GeneralMatrix* gmx, LoadAndStoreFlag cwx, int row)
00147     { gm=gmx; cw=cwx; rowcol=row; gm->GetRow(*this); }
00148 
00149     inline void MatrixRow::Next() { gm->NextRow(*this); }
00150 
00151     inline MatrixCol::MatrixCol(GeneralMatrix* gmx, LoadAndStoreFlag cwx, int col)
00152     { gm=gmx; cw=cwx; rowcol=col; gm->GetCol(*this); }
00153 
00154     inline MatrixCol::MatrixCol(GeneralMatrix* gmx, Real* r,
00155                                 LoadAndStoreFlag cwx, int col)
00156     { gm=gmx; data=r; cw=cwx+StoreHere; rowcol=col; gm->GetCol(*this); }
00157 
00158     inline MatrixColX::MatrixColX(GeneralMatrix* gmx, Real* r,
00159                                   LoadAndStoreFlag cwx, int col)
00160     { gm=gmx; store=data=r; cw=cwx+StoreHere; rowcol=col; gm->GetCol(*this); }
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 #endif

Generated on Fri Aug 23 01:37:11 2002 for VirtualU by doxygen1.2.17