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


kni
Author(s): Martin Günther
autogenerated on Thu Jun 6 2019 21:42:34