newmatrm.h
Go to the documentation of this file.
00001 //$$newmatrm.h                            rectangular matrix operations
00002 
00003 // Copyright (C) 1991,2,3,4: R B Davies
00004 
00005 #ifndef NEWMATRM_LIB
00006 #define NEWMATRM_LIB 0
00007 
00008 #ifdef use_namespace
00009 namespace NEWMAT {
00010 #endif
00011 
00012 // operations on rectangular matrices
00013 
00014 class RectMatrixCol;
00015 
00016 class RectMatrixRowCol
00017 // a class for accessing rows and columns of rectangular matrices
00018 {
00019 protected:
00020 #ifdef use_namespace              // to make namespace work
00021 public:
00022 #endif
00023    Real* store;                   // pointer to storage
00024    int n;                         // number of elements
00025    int spacing;                   // space between elements
00026    int shift;                     // space between cols or rows
00027    RectMatrixRowCol(Real* st, int nx, int sp, int sh)
00028       : store(st), n(nx), spacing(sp), shift(sh) {}
00029    void Reset(Real* st, int nx, int sp, int sh)
00030       { store=st; n=nx; spacing=sp; shift=sh; }
00031 public:
00032    Real operator*(const RectMatrixRowCol&) const;         // dot product
00033    void AddScaled(const RectMatrixRowCol&, Real);         // add scaled
00034    void Divide(const RectMatrixRowCol&, Real);            // scaling
00035    void Divide(Real);                                     // scaling
00036    void Negate();                                         // change sign
00037    void Zero();                                           // zero row col
00038    Real& operator[](int i) { return *(store+i*spacing); } // element
00039    Real SumSquare() const;                                // sum of squares
00040    Real& First() { return *store; }                       // get first element
00041    void DownDiag() { store += (shift+spacing); n--; }
00042    void UpDiag() { store -= (shift+spacing); n++; }
00043    friend void ComplexScale(RectMatrixCol&, RectMatrixCol&, Real, Real);
00044    friend void Rotate(RectMatrixCol&, RectMatrixCol&, Real, Real);
00045    FREE_CHECK(RectMatrixRowCol)
00046 };
00047 
00048 class RectMatrixRow : public RectMatrixRowCol
00049 {
00050 public:
00051    RectMatrixRow(const Matrix&, int, int, int);
00052    RectMatrixRow(const Matrix&, int);
00053    void Reset(const Matrix&, int, int, int);
00054    void Reset(const Matrix&, int);
00055    Real& operator[](int i) { return *(store+i); }
00056    void Down() { store += shift; }
00057    void Right() { store++; n--; }
00058    void Up() { store -= shift; }
00059    void Left() { store--; n++; }
00060    FREE_CHECK(RectMatrixRow)
00061 };
00062 
00063 class RectMatrixCol : public RectMatrixRowCol
00064 {
00065 public:
00066    RectMatrixCol(const Matrix&, int, int, int);
00067    RectMatrixCol(const Matrix&, int);
00068    void Reset(const Matrix&, int, int, int);
00069    void Reset(const Matrix&, int);
00070    void Down() { store += spacing; n--; }
00071    void Right() { store++; }
00072    void Up() { store -= spacing; n++; }
00073    void Left() { store--; }
00074    friend void ComplexScale(RectMatrixCol&, RectMatrixCol&, Real, Real);
00075    friend void Rotate(RectMatrixCol&, RectMatrixCol&, Real, Real);
00076    FREE_CHECK(RectMatrixCol)
00077 };
00078 
00079 class RectMatrixDiag : public RectMatrixRowCol
00080 {
00081 public:
00082    RectMatrixDiag(const DiagonalMatrix& D)
00083       : RectMatrixRowCol(D.Store(), D.Nrows(), 1, 1) {}
00084    Real& operator[](int i) { return *(store+i); }
00085    void DownDiag() { store++; n--; }
00086    void UpDiag() { store--; n++; }
00087    FREE_CHECK(RectMatrixDiag)
00088 };
00089 
00090 
00091 inline RectMatrixRow::RectMatrixRow
00092    (const Matrix& M, int row, int skip, int length)
00093    : RectMatrixRowCol( M.Store()+row*M.Ncols()+skip, length, 1, M.Ncols() ) {}
00094 
00095 inline RectMatrixRow::RectMatrixRow (const Matrix& M, int row)
00096    : RectMatrixRowCol( M.Store()+row*M.Ncols(), M.Ncols(), 1, M.Ncols() ) {}
00097 
00098 inline RectMatrixCol::RectMatrixCol
00099    (const Matrix& M, int skip, int col, int length)
00100    : RectMatrixRowCol( M.Store()+col+skip*M.Ncols(), length, M.Ncols(), 1 ) {}
00101 
00102 inline RectMatrixCol::RectMatrixCol (const Matrix& M, int col)
00103    : RectMatrixRowCol( M.Store()+col, M.Nrows(), M.Ncols(), 1 ) {}
00104 
00105 inline Real square(Real x) { return x*x; }
00106 inline Real sign(Real x, Real y)
00107    { return (y>=0) ? x : -x; }                    // assume x >=0
00108 
00109 
00110 
00111 
00112 
00113 
00114 #ifdef use_namespace
00115 }
00116 #endif
00117 
00118 #endif
00119 
00120 // body file: newmatrm.cpp
00121 
00122 


rl_agent
Author(s): Todd Hester
autogenerated on Thu Jun 6 2019 22:00:13