newmatrm.h
Go to the documentation of this file.
00001 
00002 
00003 
00006 
00007 // Copyright (C) 1991,2,3,4: R B Davies
00008 
00009 #ifndef NEWMATRM_LIB
00010 #define NEWMATRM_LIB 0
00011 
00012 #ifdef use_namespace
00013 namespace NEWMAT {
00014 #endif
00015 
00016 
00017 class RectMatrixCol;
00018 
00021 class RectMatrixRowCol
00022 {
00023 protected:
00024 #ifdef use_namespace              // to make namespace work
00025 public:
00026 #endif
00027    Real* store;                   // pointer to storage
00028    int n;                         // number of elements
00029    int spacing;                   // space between elements
00030    int shift;                     // space between cols or rows
00031    RectMatrixRowCol(Real* st, int nx, int sp, int sh)
00032       : store(st), n(nx), spacing(sp), shift(sh) {}
00033    void Reset(Real* st, int nx, int sp, int sh)
00034       { store=st; n=nx; spacing=sp; shift=sh; }
00035 public:
00036    Real operator*(const RectMatrixRowCol&) const;         // dot product
00037    void AddScaled(const RectMatrixRowCol&, Real);         // add scaled
00038    void Divide(const RectMatrixRowCol&, Real);            // scaling
00039    void Divide(Real);                                     // scaling
00040    void Negate();                                         // change sign
00041    void Zero();                                           // zero row col
00042    Real& operator[](int i) { return *(store+i*spacing); } // element
00043    Real SumSquare() const;                                // sum of squares
00044    Real& First() { return *store; }                       // get first element
00045    void DownDiag() { store += (shift+spacing); n--; }
00046    void UpDiag() { store -= (shift+spacing); n++; }
00047    friend void ComplexScale(RectMatrixCol&, RectMatrixCol&, Real, Real);
00048    friend void Rotate(RectMatrixCol&, RectMatrixCol&, Real, Real);
00049    FREE_CHECK(RectMatrixRowCol)
00050 };
00051 
00054 class RectMatrixRow : public RectMatrixRowCol
00055 {
00056 public:
00057    RectMatrixRow(const Matrix&, int, int, int);
00058    RectMatrixRow(const Matrix&, int);
00059    void Reset(const Matrix&, int, int, int);
00060    void Reset(const Matrix&, int);
00061    Real& operator[](int i) { return *(store+i); }
00062    void Down() { store += shift; }
00063    void Right() { store++; n--; }
00064    void Up() { store -= shift; }
00065    void Left() { store--; n++; }
00066    FREE_CHECK(RectMatrixRow)
00067 };
00068 
00071 class RectMatrixCol : public RectMatrixRowCol
00072 {
00073 public:
00074    RectMatrixCol(const Matrix&, int, int, int);
00075    RectMatrixCol(const Matrix&, int);
00076    void Reset(const Matrix&, int, int, int);
00077    void Reset(const Matrix&, int);
00078    void Down() { store += spacing; n--; }
00079    void Right() { store++; }
00080    void Up() { store -= spacing; n++; }
00081    void Left() { store--; }
00082    friend void ComplexScale(RectMatrixCol&, RectMatrixCol&, Real, Real);
00083    friend void Rotate(RectMatrixCol&, RectMatrixCol&, Real, Real);
00084    FREE_CHECK(RectMatrixCol)
00085 };
00086 
00089 class RectMatrixDiag : public RectMatrixRowCol
00090 {
00091 public:
00092    RectMatrixDiag(const DiagonalMatrix& D)
00093       : RectMatrixRowCol(D.Store(), D.Nrows(), 1, 1) {}
00094    Real& operator[](int i) { return *(store+i); }
00095    void DownDiag() { store++; n--; }
00096    void UpDiag() { store--; n++; }
00097    FREE_CHECK(RectMatrixDiag)
00098 };
00099 
00100 
00101 
00102 
00103 inline RectMatrixRow::RectMatrixRow
00104    (const Matrix& M, int row, int skip, int length)
00105    : RectMatrixRowCol( M.Store()+row*M.Ncols()+skip, length, 1, M.Ncols() ) {}
00106 
00107 inline RectMatrixRow::RectMatrixRow (const Matrix& M, int row)
00108    : RectMatrixRowCol( M.Store()+row*M.Ncols(), M.Ncols(), 1, M.Ncols() ) {}
00109 
00110 inline RectMatrixCol::RectMatrixCol
00111    (const Matrix& M, int skip, int col, int length)
00112    : RectMatrixRowCol( M.Store()+col+skip*M.Ncols(), length, M.Ncols(), 1 ) {}
00113 
00114 inline RectMatrixCol::RectMatrixCol (const Matrix& M, int col)
00115    : RectMatrixRowCol( M.Store()+col, M.Nrows(), M.Ncols(), 1 ) {}
00116 
00117 inline Real square(Real x) { return x*x; }
00118 inline Real sign(Real x, Real y)
00119    { return (y>=0) ? x : -x; }                    // assume x >=0
00120 
00121 
00122 // Misc numerical things
00123 
00124 Real pythag(Real f, Real g, Real& c, Real& s);
00125 
00126 inline void GivensRotation(Real cGivens, Real sGivens, Real& x, Real& y)
00127 {
00128    // allow for possibility &x = &y
00129    Real tmp0 = cGivens * x + sGivens * y;
00130    Real tmp1 = -sGivens * x + cGivens * y;
00131    x = tmp0; y = tmp1;
00132 }
00133    
00134 inline void GivensRotationR(Real cGivens, Real sGivens, Real& x, Real& y)
00135 {
00136    // also change sign of y
00137    // allow for possibility &x = &y
00138    Real tmp0 = cGivens * x + sGivens * y;
00139    Real tmp1 = sGivens * x - cGivens * y;
00140    x = tmp0; y = tmp1;
00141 }   
00142 
00143 
00144 
00145 
00146 
00147 #ifdef use_namespace
00148 }
00149 #endif
00150 
00151 #endif
00152 
00153 // body file: newmatrm.cpp
00154 
00155 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines


kni
Author(s): Neuronics AG (see AUTHORS.txt); ROS wrapper by Martin Günther
autogenerated on Tue May 28 2013 14:52:54