newmatrc.h

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 double*&);                  // copy from an array
00075    void Copy(const float*&);                   // copy from an array
00076    void Copy(const int*&);                     // copy from an array
00077    void Copy(Real);                            // copy from constant
00078    void Add(Real);                             // add a constant
00079    void Multiply(Real);                        // multiply by constant
00080    Real SumAbsoluteValue();                    // sum of absolute values
00081    Real MaximumAbsoluteValue1(Real r, int& i); // maximum of absolute values
00082    Real MinimumAbsoluteValue1(Real r, int& i); // minimum of absolute values
00083    Real Maximum1(Real r, int& i);              // maximum
00084    Real Minimum1(Real r, int& i);              // minimum
00085    Real Sum();                                 // sum of values
00086    void Inject(const MatrixRowCol&);           // copy stored els of a row/col
00087    void Negate(const MatrixRowCol&);           // change sign of a row/col
00088    void Multiply(const MatrixRowCol&, Real);   // scale a row/col
00089    friend Real DotProd(const MatrixRowCol&, const MatrixRowCol&);
00090                                                // sum of pairwise product
00091    Real* Data() { return data; }
00092    int Skip() { return skip; }                 // number of elements skipped
00093    int Storage() { return storage; }           // number of elements stored
00094    int Length() { return length; }             // length of row or column
00095    void Skip(int i) { skip=i; }
00096    void Storage(int i) { storage=i; }
00097    void Length(int i) { length=i; }
00098    void SubRowCol(MatrixRowCol&, int, int) const;
00099                                                // get part of a row or column
00100    MatrixRowCol() {}                           // to stop warning messages
00101    ~MatrixRowCol();
00102    FREE_CHECK(MatrixRowCol)
00103 };
00104 
00105 class MatrixRow : public MatrixRowCol
00106 {
00107 public:
00108    // bodies for these are inline at the end of this .h file
00109    MatrixRow(GeneralMatrix*, LoadAndStoreFlag, int=0);
00110                                                // extract a row
00111    ~MatrixRow();
00112    void Next();                                // get next row
00113    FREE_CHECK(MatrixRow)
00114 };
00115 
00116 class MatrixCol : public MatrixRowCol
00117 {
00118 public:
00119    // bodies for these are inline at the end of this .h file
00120    MatrixCol(GeneralMatrix*, LoadAndStoreFlag, int=0);
00121                                                // extract a col
00122    MatrixCol(GeneralMatrix*, Real*, LoadAndStoreFlag, int=0);
00123                                                // store/retrieve a col
00124    ~MatrixCol();
00125    void Next();                                // get next row
00126    FREE_CHECK(MatrixCol)
00127 };
00128 
00129 // MatrixColX is an alternative to MatrixCol where the complete
00130 // column is stored externally
00131 
00132 class MatrixColX : public MatrixRowCol
00133 {
00134 public:
00135    // bodies for these are inline at the end of this .h file
00136    MatrixColX(GeneralMatrix*, Real*, LoadAndStoreFlag, int=0);
00137                                                // store/retrieve a col
00138    ~MatrixColX();
00139    void Next();                                // get next row
00140    Real* store;                                // pointer to local storage
00141                                                //    less skip
00142    FREE_CHECK(MatrixColX)
00143 };
00144 
00145 /**************************** inline bodies ****************************/
00146 
00147 inline MatrixRow::MatrixRow(GeneralMatrix* gmx, LoadAndStoreFlag cwx, int row)
00148 { gm=gmx; cw=cwx; rowcol=row; gm->GetRow(*this); }
00149 
00150 inline void MatrixRow::Next() { gm->NextRow(*this); }
00151 
00152 inline MatrixCol::MatrixCol(GeneralMatrix* gmx, LoadAndStoreFlag cwx, int col)
00153 { gm=gmx; cw=cwx; rowcol=col; gm->GetCol(*this); }
00154 
00155 inline MatrixCol::MatrixCol(GeneralMatrix* gmx, Real* r,
00156    LoadAndStoreFlag cwx, int col)
00157 { gm=gmx; data=r; cw=cwx+StoreHere; rowcol=col; gm->GetCol(*this); }
00158 
00159 inline MatrixColX::MatrixColX(GeneralMatrix* gmx, Real* r,
00160    LoadAndStoreFlag cwx, int col)
00161 { gm=gmx; store=data=r; cw=cwx+StoreHere; rowcol=col; gm->GetCol(*this); }
00162 
00163 
00164 inline void MatrixCol::Next() { gm->NextCol(*this); }
00165 
00166 inline void MatrixColX::Next() { gm->NextCol(*this); }
00167 
00168 #ifdef use_namespace
00169 }
00170 #endif
00171 
00172 #endif
Generated on Mon Jan 24 12:04:37 2011 for FASTlib by  doxygen 1.6.3