Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/trunk/src/util/newmat/newmatrc.h @ 4565

Last change on this file since 4565 was 4565, checked in by patrick, 19 years ago

orxonox/trunk: added the newmat library to the project. needs some translation in directory, temp under util/newmat. is needed by the collision detection engine to perform lin alg operations such as eigenvector decomposition. perhaps we will make our own library to do that later.

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