Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

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 
00092 
00093 inline RectMatrixRow::RectMatrixRow
00094    (const Matrix& M, int row, int skip, int length)
00095    : RectMatrixRowCol( M.Store()+row*M.Ncols()+skip, length, 1, M.Ncols() ) {}
00096 
00097 inline RectMatrixRow::RectMatrixRow (const Matrix& M, int row)
00098    : RectMatrixRowCol( M.Store()+row*M.Ncols(), M.Ncols(), 1, M.Ncols() ) {}
00099 
00100 inline RectMatrixCol::RectMatrixCol
00101    (const Matrix& M, int skip, int col, int length)
00102    : RectMatrixRowCol( M.Store()+col+skip*M.Ncols(), length, M.Ncols(), 1 ) {}
00103 
00104 inline RectMatrixCol::RectMatrixCol (const Matrix& M, int col)
00105    : RectMatrixRowCol( M.Store()+col, M.Nrows(), M.Ncols(), 1 ) {}
00106 
00107 inline Real square(Real x) { return x*x; }
00108 inline Real sign(Real x, Real y)
00109    { return (y>=0) ? x : -x; }                    // assume x >=0
00110 
00111 
00112 // Misc numerical things
00113 
00114 Real pythag(Real f, Real g, Real& c, Real& s);
00115 
00116 inline void GivensRotation(Real cGivens, Real sGivens, Real& x, Real& y)
00117 {
00118    // allow for possibility &x = &y
00119    Real tmp0 = cGivens * x + sGivens * y;
00120    Real tmp1 = -sGivens * x + cGivens * y;
00121    x = tmp0; y = tmp1;
00122 }
00123    
00124 inline void GivensRotationR(Real cGivens, Real sGivens, Real& x, Real& y)
00125 {
00126    // also change sign of y
00127    // allow for possibility &x = &y
00128    Real tmp0 = cGivens * x + sGivens * y;
00129    Real tmp1 = sGivens * x - cGivens * y;
00130    x = tmp0; y = tmp1;
00131 }   
00132 
00133 
00134 
00135 
00136 
00137 #ifdef use_namespace
00138 }
00139 #endif
00140 
00141 #endif
00142 
00143 // body file: newmatrm.cpp
00144 
00145 

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