source: ntrip/trunk/BNS/newmat/newmatrc.h@ 2172

Last change on this file since 2172 was 810, checked in by mervart, 17 years ago

* empty log message *

File size: 7.4 KB
Line 
1/// \ingroup newmat
2///@{
3
4/// \file newmatrc.h
5/// Header file for row/column classes
6
7// Copyright (C) 1991,2,3,4,7: R B Davies
8
9#ifndef NEWMATRC_LIB
10#define NEWMATRC_LIB 0
11
12#ifdef use_namespace
13namespace NEWMAT {
14#endif
15
16#include "controlw.h"
17
18
19/************** classes MatrixRowCol, MatrixRow, MatrixCol *****************/
20
21// Used for accessing the rows and columns of matrices
22// All matrix classes must provide routines for calculating matrix rows and
23// columns. Assume rows can be found very efficiently.
24
25enum LSF { LoadOnEntry=1,StoreOnExit=2,DirectPart=4,StoreHere=8,HaveStore=16 };
26
27
28/// Option for accessing row or column.
29/// \internal
30class LoadAndStoreFlag : public ControlWord
31{
32public:
33 LoadAndStoreFlag() {}
34 LoadAndStoreFlag(int i) : ControlWord(i) {}
35 LoadAndStoreFlag(LSF lsf) : ControlWord(lsf) {}
36 LoadAndStoreFlag(const ControlWord& cwx) : ControlWord(cwx) {}
37};
38
39
40/// Access a row or column of a matrix.
41/// \internal
42class MatrixRowCol
43{
44public: // these are public to avoid
45 // numerous friend statements
46 int length; // row or column length
47 int skip; // initial number of zeros
48 int storage; // number of stored elements
49 int rowcol; // row or column number
50 GeneralMatrix* gm; // pointer to parent matrix
51 Real* data; // pointer to local storage
52 LoadAndStoreFlag cw; // Load? Store? Is a Copy?
53 void IncrMat() { rowcol++; data += storage; } // used by NextRow
54 void IncrDiag() { rowcol++; skip++; data++; }
55 void IncrId() { rowcol++; skip++; }
56 void IncrUT() { rowcol++; data += storage; storage--; skip++; }
57 void IncrLT() { rowcol++; data += storage; storage++; }
58
59public:
60 void Zero(); // set elements to zero
61 void Add(const MatrixRowCol&); // add a row/col
62 void AddScaled(const MatrixRowCol&, Real); // add a multiple of a row/col
63 void Add(const MatrixRowCol&, const MatrixRowCol&);
64 // add two rows/cols
65 void Add(const MatrixRowCol&, Real); // add a row/col
66 void NegAdd(const MatrixRowCol&, Real); // Real - a row/col
67 void Sub(const MatrixRowCol&); // subtract a row/col
68 void Sub(const MatrixRowCol&, const MatrixRowCol&);
69 // sub a row/col from another
70 void RevSub(const MatrixRowCol&); // subtract from a row/col
71 void ConCat(const MatrixRowCol&, const MatrixRowCol&);
72 // concatenate two row/cols
73 void Multiply(const MatrixRowCol&); // multiply a row/col
74 void Multiply(const MatrixRowCol&, const MatrixRowCol&);
75 // multiply two row/cols
76 void KP(const MatrixRowCol&, const MatrixRowCol&);
77 // Kronecker Product two row/cols
78 void Copy(const MatrixRowCol&); // copy a row/col
79 void CopyCheck(const MatrixRowCol&); // ... check for data loss
80 void Check(const MatrixRowCol&); // just check for data loss
81 void Check(); // check full row/col present
82 void Copy(const double*&); // copy from an array
83 void Copy(const float*&); // copy from an array
84 void Copy(const int*&); // copy from an array
85 void Copy(Real); // copy from constant
86 void Add(Real); // add a constant
87 void Multiply(Real); // multiply by constant
88 Real SumAbsoluteValue(); // sum of absolute values
89 Real MaximumAbsoluteValue1(Real r, int& i); // maximum of absolute values
90 Real MinimumAbsoluteValue1(Real r, int& i); // minimum of absolute values
91 Real Maximum1(Real r, int& i); // maximum
92 Real Minimum1(Real r, int& i); // minimum
93 Real Sum(); // sum of values
94 void Inject(const MatrixRowCol&); // copy stored els of a row/col
95 void Negate(const MatrixRowCol&); // change sign of a row/col
96 void Multiply(const MatrixRowCol&, Real); // scale a row/col
97 friend Real DotProd(const MatrixRowCol&, const MatrixRowCol&);
98 // sum of pairwise product
99 Real* Data() { return data; }
100 int Skip() { return skip; } // number of elements skipped
101 int Storage() { return storage; } // number of elements stored
102 int Length() { return length; } // length of row or column
103 void Skip(int i) { skip=i; }
104 void Storage(int i) { storage=i; }
105 void Length(int i) { length=i; }
106 void SubRowCol(MatrixRowCol&, int, int) const;
107 // get part of a row or column
108 MatrixRowCol() {} // to stop warning messages
109 ~MatrixRowCol();
110 FREE_CHECK(MatrixRowCol)
111};
112
113/// Access a row of a matrix.
114/// \internal
115class MatrixRow : public MatrixRowCol
116{
117public:
118 // bodies for these are inline at the end of this .h file
119 MatrixRow(GeneralMatrix*, LoadAndStoreFlag, int=0);
120 // extract a row
121 ~MatrixRow();
122 void Next(); // get next row
123 FREE_CHECK(MatrixRow)
124};
125
126/// Access a column of a matrix.
127/// \internal
128class MatrixCol : public MatrixRowCol
129{
130public:
131 // bodies for these are inline at the end of this .h file
132 MatrixCol(GeneralMatrix*, LoadAndStoreFlag, int=0);
133 // extract a col
134 MatrixCol(GeneralMatrix*, Real*, LoadAndStoreFlag, int=0);
135 // store/retrieve a col
136 ~MatrixCol();
137 void Next(); // get next column
138 FREE_CHECK(MatrixCol)
139};
140
141/// Alternative to MatrixCol where the complete column is stored externally.
142/// \internal
143class MatrixColX : public MatrixRowCol
144{
145public:
146 // bodies for these are inline at the end of this .h file
147 MatrixColX(GeneralMatrix*, Real*, LoadAndStoreFlag, int=0);
148 // store/retrieve a col
149 ~MatrixColX();
150 void Next(); // get next row
151 Real* store; // pointer to local storage
152 // less skip
153 FREE_CHECK(MatrixColX)
154};
155
156/**************************** inline bodies ****************************/
157
158inline MatrixRow::MatrixRow(GeneralMatrix* gmx, LoadAndStoreFlag cwx, int row)
159{ gm=gmx; cw=cwx; rowcol=row; gm->GetRow(*this); }
160
161inline void MatrixRow::Next() { gm->NextRow(*this); }
162
163inline MatrixCol::MatrixCol(GeneralMatrix* gmx, LoadAndStoreFlag cwx, int col)
164{ gm=gmx; cw=cwx; rowcol=col; gm->GetCol(*this); }
165
166inline MatrixCol::MatrixCol(GeneralMatrix* gmx, Real* r,
167 LoadAndStoreFlag cwx, int col)
168{ gm=gmx; data=r; cw=cwx+StoreHere; rowcol=col; gm->GetCol(*this); }
169
170inline MatrixColX::MatrixColX(GeneralMatrix* gmx, Real* r,
171 LoadAndStoreFlag cwx, int col)
172{ gm=gmx; store=data=r; cw=cwx+StoreHere; rowcol=col; gm->GetCol(*this); }
173
174
175inline void MatrixCol::Next() { gm->NextCol(*this); }
176
177inline void MatrixColX::Next() { gm->NextCol(*this); }
178
179#ifdef use_namespace
180}
181#endif
182
183#endif
184
185
186///@}
Note: See TracBrowser for help on using the repository browser.