home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / sources / misc / 4250 / newmatrc.h < prev    next >
Encoding:
C/C++ Source or Header  |  1993-01-11  |  4.9 KB  |  126 lines

  1. //$$ newmatrc.h              definition file for row/column classes
  2.  
  3. // Copyright (C) 1991,2,3: R B Davies
  4.  
  5. #ifndef MATRIXRC_LIB
  6. #define MATRIXRC_LIB 0
  7.  
  8. #include "controlw.h"
  9.  
  10.  
  11.  
  12. /************** classes MatrixRowCol, MatrixRow, MatrixCol *****************/
  13.  
  14. // Used for accessing the rows and columns of matrices
  15. // All matrix classes must provide routines for calculating matrix rows and
  16. // columns. Assume rows can be found very efficiently.
  17.  
  18. enum LSF { LoadOnEntry=1,StoreOnExit=2,IsACopy=4,DirectPart=8,StoreHere=16 };
  19.  
  20.  
  21. class LoadAndStoreFlag : public ControlWord
  22. {
  23. public:
  24.    LoadAndStoreFlag() {}
  25.    LoadAndStoreFlag(int i) : ControlWord(i) {}
  26.    LoadAndStoreFlag(LSF lsf) : ControlWord(lsf) {}
  27.    LoadAndStoreFlag(const ControlWord& cwx) : ControlWord(cwx) {}
  28.    FREE_CHECK(LoadAndStoreFlag)
  29. };
  30.  
  31. class MatrixRowCol
  32. // the row or column of a matrix
  33. {
  34. public:                                        // these are public to avoid
  35.                            // numerous friend statements
  36.    int length;                                 // row or column length
  37.    int skip;                                   // initial number of zeros
  38.    int storage;                                // number of stored elements
  39.    int rowcol;                                 // row or column number
  40.    GeneralMatrix* gm;                          // pointer to parent matrix
  41.    Real* store;                                // pointer to local storage
  42.                            //    less skip
  43.    LoadAndStoreFlag cw;                        // Load? Store? Is a Copy?
  44.    void IncrMat() { rowcol++; store += storage; }
  45.                            // used by NextRow
  46.    void IncrDiag() { rowcol++; skip++; }
  47.    void IncrUT() { rowcol++; storage--; store += storage; skip++; }
  48.    void IncrLT() { rowcol++; store += storage; storage++; }
  49.  
  50. public:
  51.    void Add(const MatrixRowCol&);              // add a row/col
  52.    void AddScaled(const MatrixRowCol&, Real);  // add a multiple of a row/col
  53.    void Add(const MatrixRowCol&, const MatrixRowCol&);
  54.                            // add two rows/cols
  55.    void Add(const MatrixRowCol&, Real);        // add a row/col
  56.    void Sub(const MatrixRowCol&);              // subtract a row/col
  57.    void Sub(const MatrixRowCol&, const MatrixRowCol&);
  58.                            // sub a row/col from another
  59.    void RevSub(const MatrixRowCol&);           // subtract from a row/col
  60.    void Copy(const MatrixRowCol&);             // copy a row/col
  61.    void CopyCheck(const MatrixRowCol&);        // ... check for data loss
  62.    void Copy(const Real*&);                    // copy from an array
  63.    void Copy(Real);                            // copy from constant
  64.    Real SumAbsoluteValue();                    // sum of absolute values
  65.    void Inject(const MatrixRowCol&);           // copy stored els of a row/col
  66.    void Negate(const MatrixRowCol&);           // change sign of a row/col
  67.    void Multiply(const MatrixRowCol&, Real);   // scale a row/col
  68.    friend Real DotProd(const MatrixRowCol&, const MatrixRowCol&);
  69.                            // sum of pairwise product
  70.    Real* operator()() { return store+skip; }   // pointer to first element
  71.    Real* Store() { return store; }
  72.    int Skip() { return skip; }                 // number of elements skipped
  73.    int Storage() { return storage; }           // number of elements stored
  74.    void Skip(int i) { skip=i; }
  75.    void Storage(int i) { storage=i; }
  76.    void SubRowCol(MatrixRowCol&, int, int) const;
  77.                            // get part of a row or column
  78.    MatrixRowCol() {}                           // to stop warning messages
  79.    ~MatrixRowCol();
  80.    FREE_CHECK(MatrixRowCol)
  81. };
  82.  
  83. class MatrixRow : public MatrixRowCol
  84. {
  85. public:
  86.    // bodies for these are inline at the end of this .h file
  87.    MatrixRow(GeneralMatrix*, LoadAndStoreFlag, int=0);
  88.                                                // extract a row
  89.    ~MatrixRow();
  90.    void Next();                                // get next row
  91.    FREE_CHECK(MatrixRow)
  92. };
  93.  
  94. class MatrixCol : public MatrixRowCol
  95. {
  96. public:
  97.    // bodies for these are inline at the end of this .h file
  98.    MatrixCol(GeneralMatrix*, LoadAndStoreFlag, int=0);
  99.                                                // extract a col
  100.    MatrixCol(GeneralMatrix*, Real*, LoadAndStoreFlag, int=0);
  101.                                                // store/retrieve a col
  102.    ~MatrixCol();
  103.    void Next();                                // get next row
  104.    FREE_CHECK(MatrixCol)
  105. };
  106.  
  107.  
  108. /**************************** inline bodies ****************************/
  109.  
  110. inline MatrixRow::MatrixRow(GeneralMatrix* gmx, LoadAndStoreFlag cwx, int row)
  111. { gm=gmx; cw=cwx; rowcol=row; gm->GetRow(*this); } 
  112.  
  113. inline void MatrixRow::Next() { gm->NextRow(*this); }
  114.  
  115. inline MatrixCol::MatrixCol(GeneralMatrix* gmx, LoadAndStoreFlag cwx, int col)
  116. { gm=gmx; cw=cwx; rowcol=col; gm->GetCol(*this); } 
  117.  
  118. inline MatrixCol::MatrixCol(GeneralMatrix* gmx, Real* r,
  119.    LoadAndStoreFlag cwx, int col)
  120. { gm=gmx; store=r; cw=cwx+StoreHere; rowcol=col; gm->GetCol(*this); } 
  121.  
  122. inline void MatrixCol::Next() { gm->NextCol(*this); }
  123.  
  124.  
  125. #endif
  126.