"Fossies" - the Fresh Open Source Software Archive

Member "heaplayers-351/benchmarks/roboop/newmat/newmatrm.h" (17 Oct 2003, 3903 Bytes) of package /linux/misc/old/heaplayers_3_5_1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "newmatrm.h" see the Fossies "Dox" file reference documentation.

    1 //$$newmatrm.h                            rectangular matrix operations
    2 
    3 // Copyright (C) 1991,2,3,4: R B Davies
    4 
    5 #ifndef NEWMATRM_LIB
    6 #define NEWMATRM_LIB 0
    7 
    8 #ifdef use_namespace
    9 namespace NEWMAT {
   10 #endif
   11 
   12 // operations on rectangular matrices
   13 
   14 class RectMatrixCol;
   15 
   16 class RectMatrixRowCol
   17 // a class for accessing rows and columns of rectangular matrices
   18 {
   19 protected:
   20 #ifdef use_namespace              // to make namespace work
   21 public:
   22 #endif
   23    Real* store;                   // pointer to storage
   24    int n;                         // number of elements
   25    int spacing;                   // space between elements
   26    int shift;                     // space between cols or rows
   27    RectMatrixRowCol(Real* st, int nx, int sp, int sh)
   28       : store(st), n(nx), spacing(sp), shift(sh) {}
   29    void Reset(Real* st, int nx, int sp, int sh)
   30       { store=st; n=nx; spacing=sp; shift=sh; }
   31 public:
   32    Real operator*(const RectMatrixRowCol&) const;         // dot product
   33    void AddScaled(const RectMatrixRowCol&, Real);         // add scaled
   34    void Divide(const RectMatrixRowCol&, Real);            // scaling
   35    void Divide(Real);                                     // scaling
   36    void Negate();                                         // change sign
   37    void Zero();                                           // zero row col
   38    Real& operator[](int i) { return *(store+i*spacing); } // element
   39    Real SumSquare() const;                                // sum of squares
   40    Real& First() { return *store; }                       // get first element
   41    void DownDiag() { store += (shift+spacing); n--; }
   42    void UpDiag() { store -= (shift+spacing); n++; }
   43    friend void ComplexScale(RectMatrixCol&, RectMatrixCol&, Real, Real);
   44    friend void Rotate(RectMatrixCol&, RectMatrixCol&, Real, Real);
   45    FREE_CHECK(RectMatrixRowCol)
   46 };
   47 
   48 class RectMatrixRow : public RectMatrixRowCol
   49 {
   50 public:
   51    RectMatrixRow(const Matrix&, int, int, int);
   52    RectMatrixRow(const Matrix&, int);
   53    void Reset(const Matrix&, int, int, int);
   54    void Reset(const Matrix&, int);
   55    Real& operator[](int i) { return *(store+i); }
   56    void Down() { store += shift; }
   57    void Right() { store++; n--; }
   58    void Up() { store -= shift; }
   59    void Left() { store--; n++; }
   60    FREE_CHECK(RectMatrixRow)
   61 };
   62 
   63 class RectMatrixCol : public RectMatrixRowCol
   64 {
   65 public:
   66    RectMatrixCol(const Matrix&, int, int, int);
   67    RectMatrixCol(const Matrix&, int);
   68    void Reset(const Matrix&, int, int, int);
   69    void Reset(const Matrix&, int);
   70    void Down() { store += spacing; n--; }
   71    void Right() { store++; }
   72    void Up() { store -= spacing; n++; }
   73    void Left() { store--; }
   74    friend void ComplexScale(RectMatrixCol&, RectMatrixCol&, Real, Real);
   75    friend void Rotate(RectMatrixCol&, RectMatrixCol&, Real, Real);
   76    FREE_CHECK(RectMatrixCol)
   77 };
   78 
   79 class RectMatrixDiag : public RectMatrixRowCol
   80 {
   81 public:
   82    RectMatrixDiag(const DiagonalMatrix& D)
   83       : RectMatrixRowCol(D.Store(), D.Nrows(), 1, 1) {}
   84    Real& operator[](int i) { return *(store+i); }
   85    void DownDiag() { store++; n--; }
   86    void UpDiag() { store--; n++; }
   87    FREE_CHECK(RectMatrixDiag)
   88 };
   89 
   90 
   91 inline RectMatrixRow::RectMatrixRow
   92    (const Matrix& M, int row, int skip, int length)
   93    : RectMatrixRowCol( M.Store()+row*M.Ncols()+skip, length, 1, M.Ncols() ) {}
   94 
   95 inline RectMatrixRow::RectMatrixRow (const Matrix& M, int row)
   96    : RectMatrixRowCol( M.Store()+row*M.Ncols(), M.Ncols(), 1, M.Ncols() ) {}
   97 
   98 inline RectMatrixCol::RectMatrixCol
   99    (const Matrix& M, int skip, int col, int length)
  100    : RectMatrixRowCol( M.Store()+col+skip*M.Ncols(), length, M.Ncols(), 1 ) {}
  101 
  102 inline RectMatrixCol::RectMatrixCol (const Matrix& M, int col)
  103    : RectMatrixRowCol( M.Store()+col, M.Nrows(), M.Ncols(), 1 ) {}
  104 
  105 inline Real square(Real x) { return x*x; }
  106 inline Real sign(Real x, Real y)
  107    { return (y>=0) ? x : -x; }                    // assume x >=0
  108 
  109 #ifdef use_namespace
  110 }
  111 #endif
  112 
  113 #endif