OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
newmatrm.h
Go to the documentation of this file.
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 
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++; }
44  friend void Rotate(RectMatrixCol&, RectMatrixCol&, Real, Real);
46 };
47 
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++; }
61 };
62 
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--; }
75  friend void Rotate(RectMatrixCol&, RectMatrixCol&, Real, Real);
77 };
78 
80 {
81 public:
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++; }
88 };
89 
90 
91 
92 
94  (const Matrix& M, int row, int skip, int length)
95  : RectMatrixRowCol( M.Store()+row*M.Ncols()+skip, length, 1, M.Ncols() ) {}
96 
97 inline RectMatrixRow::RectMatrixRow (const Matrix& M, int row)
98  : RectMatrixRowCol( M.Store()+row*M.Ncols(), M.Ncols(), 1, M.Ncols() ) {}
99 
101  (const Matrix& M, int skip, int col, int length)
102  : RectMatrixRowCol( M.Store()+col+skip*M.Ncols(), length, M.Ncols(), 1 ) {}
103 
104 inline RectMatrixCol::RectMatrixCol (const Matrix& M, int col)
105  : RectMatrixRowCol( M.Store()+col, M.Nrows(), M.Ncols(), 1 ) {}
106 
107 inline Real square(Real x) { return x*x; }
108 inline Real sign(Real x, Real y)
109  { return (y>=0) ? x : -x; } // assume x >=0
110 
111 
112 // Misc numerical things
113 
114 Real pythag(Real f, Real g, Real& c, Real& s);
115 
116 inline void GivensRotation(Real cGivens, Real sGivens, Real& x, Real& y)
117 {
118  // allow for possibility &x = &y
119  Real tmp0 = cGivens * x + sGivens * y;
120  Real tmp1 = -sGivens * x + cGivens * y;
121  x = tmp0; y = tmp1;
122 }
123 
124 inline void GivensRotationR(Real cGivens, Real sGivens, Real& x, Real& y)
125 {
126  // also change sign of y
127  // allow for possibility &x = &y
128  Real tmp0 = cGivens * x + sGivens * y;
129  Real tmp1 = sGivens * x - cGivens * y;
130  x = tmp0; y = tmp1;
131 }
132 
133 
134 
135 
136 
137 #ifdef use_namespace
138 }
139 #endif
140 
141 #endif
142 
143 // body file: newmatrm.cpp
144 
145 
ossim_uint32 x
void GivensRotation(Real cGivens, Real sGivens, Real &x, Real &y)
Definition: newmatrm.h:116
double Real
Definition: include.h:57
void GivensRotationR(Real cGivens, Real sGivens, Real &x, Real &y)
Definition: newmatrm.h:124
Real sign(Real x, Real y)
Definition: newmatrm.h:108
void Reset(Real *st, int nx, int sp, int sh)
Definition: newmatrm.h:29
ossim_uint32 y
Real square(Real x)
Definition: newmatrm.h:107
void Rotate(RectMatrixCol &U, RectMatrixCol &V, Real tau, Real s)
Definition: newmatrm.cpp:156
int Ncols() const
Definition: newmat.h:431
void Up()
Definition: newmatrm.h:72
#define FREE_CHECK(Class)
Definition: myexcept.h:316
Real & operator[](int i)
Definition: newmatrm.h:38
ossimRationalNumber operator*(ossim_int32 i, ossimRationalNumber &r)
Real pythag(Real f, Real g, Real &c, Real &s)
Definition: newmatrm.cpp:186
RectMatrixDiag(const DiagonalMatrix &D)
Definition: newmatrm.h:82
RectMatrixRow(const Matrix &, int, int, int)
Definition: newmatrm.h:94
RectMatrixCol(const Matrix &, int, int, int)
Definition: newmatrm.h:101
void ComplexScale(RectMatrixCol &U, RectMatrixCol &V, Real x, Real y)
Definition: newmatrm.cpp:132
os2<< "> n<< " > nendobj n
RectMatrixRowCol(Real *st, int nx, int sp, int sh)
Definition: newmatrm.h:27
Real & operator[](int i)
Definition: newmatrm.h:55
void DownDiag()
Definition: newmatrm.h:85
void Left()
Definition: newmatrm.h:73
Definition: newmat.h:543
void Left()
Definition: newmatrm.h:59
void UpDiag()
Definition: newmatrm.h:42
Real & First()
Definition: newmatrm.h:40
void DownDiag()
Definition: newmatrm.h:41
void Up()
Definition: newmatrm.h:58
Real * store
Definition: newmatrm.h:23
Real * Store() const
Definition: newmat.h:433
void Right()
Definition: newmatrm.h:57
void Down()
Definition: newmatrm.h:56
void UpDiag()
Definition: newmatrm.h:86
void Right()
Definition: newmatrm.h:71
void Down()
Definition: newmatrm.h:70
Real & operator[](int i)
Definition: newmatrm.h:84
Real SumSquare(const BaseMatrix &B)
Definition: newmat.h:1755