Virtual U.org
Get Personal Training on VU Today
    
Top shadow
 
 register/help
User Name:

Password:

NEWMATRM.H Source File
Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

NEWMATRM.H

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

Generated on Fri Aug 23 01:37:11 2002 for VirtualU by doxygen1.2.17