Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

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(const int*&);                     // copy from an array
00076    void Copy(Real);                            // copy from constant
00077    void Add(Real);                             // add a constant
00078    void Multiply(Real);                        // multiply by constant
00079    Real SumAbsoluteValue();                    // sum of absolute values
00080    Real MaximumAbsoluteValue1(Real r, int& i); // maximum of absolute values
00081    Real MinimumAbsoluteValue1(Real r, int& i); // minimum of absolute values
00082    Real Maximum1(Real r, int& i);              // maximum
00083    Real Minimum1(Real r, int& i);              // minimum
00084    Real Sum();                                 // sum of values
00085    void Inject(const MatrixRowCol&);           // copy stored els of a row/col
00086    void Negate(const MatrixRowCol&);           // change sign of a row/col
00087    void Multiply(const MatrixRowCol&, Real);   // scale a row/col
00088    friend Real DotProd(const MatrixRowCol&, const MatrixRowCol&);
00089                                                // sum of pairwise product
00090    Real* Data() { return data; }
00091    int Skip() { return skip; }                 // number of elements skipped
00092    int Storage() { return storage; }           // number of elements stored
00093    int Length() { return length; }             // length of row or column
00094    void Skip(int i) { skip=i; }
00095    void Storage(int i) { storage=i; }
00096    void Length(int i) { length=i; }
00097    void SubRowCol(MatrixRowCol&, int, int) const;
00098                  // get part of a row or column
00099    MatrixRowCol() {}                           // to stop warning messages
00100    ~MatrixRowCol();
00101    FREE_CHECK(MatrixRowCol)
00102 };
00103 
00104 class MatrixRow : public MatrixRowCol
00105 {
00106 public:
00107    // bodies for these are inline at the end of this .h file
00108    MatrixRow(GeneralMatrix*, LoadAndStoreFlag, int=0);
00109                                                // extract a row
00110    ~MatrixRow();
00111    void Next();                                // get next row
00112    FREE_CHECK(MatrixRow)
00113 };
00114 
00115 class MatrixCol : public MatrixRowCol
00116 {
00117 public:
00118    // bodies for these are inline at the end of this .h file
00119    MatrixCol(GeneralMatrix*, LoadAndStoreFlag, int=0);
00120                                                // extract a col
00121    MatrixCol(GeneralMatrix*, Real*, LoadAndStoreFlag, int=0);
00122                                                // store/retrieve a col
00123    ~MatrixCol();
00124    void Next();                                // get next row
00125    FREE_CHECK(MatrixCol)
00126 };
00127 
00128 // MatrixColX is an alternative to MatrixCol where the complete
00129 // column is stored externally
00130 
00131 class MatrixColX : public MatrixRowCol
00132 {
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 
00163 inline void MatrixCol::Next() { gm->NextCol(*this); }
00164 
00165 inline void MatrixColX::Next() { gm->NextCol(*this); }
00166 
00167 #ifdef use_namespace
00168 }
00169 #endif
00170 
00171 #endif

newmat11b
Generated Mon May 9 04:54:18 2016 by Doxygen 1.6.3