Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/branches/oggPlayer/src/lib/newmat/newmatex.cpp @ 4603

Last change on this file since 4603 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: 8.4 KB
Line 
1//$$ newmatex.cpp                    Exception handler
2
3// Copyright (C) 1992,3,4,7: R B Davies
4
5#define WANT_STREAM                  // include.h will get stream fns
6
7#include "include.h"                 // include standard files
8#include "newmat.h"
9
10#ifdef use_namespace
11namespace NEWMAT {
12#endif
13
14unsigned long OverflowException::Select;
15unsigned long SingularException::Select;
16unsigned long NPDException::Select;
17unsigned long ConvergenceException::Select;
18unsigned long ProgramException::Select;
19unsigned long IndexException::Select;
20unsigned long VectorException::Select;
21unsigned long NotSquareException::Select;
22unsigned long SubMatrixDimensionException::Select;
23unsigned long IncompatibleDimensionsException::Select;
24unsigned long NotDefinedException::Select;
25unsigned long CannotBuildException::Select;
26unsigned long InternalException::Select;
27
28
29
30static void MatrixDetails(const GeneralMatrix& A)
31// write matrix details to Exception buffer
32{
33   MatrixBandWidth bw = A.BandWidth(); int ubw = bw.upper; int lbw = bw.lower;
34   Exception::AddMessage("MatrixType = ");
35   Exception::AddMessage(A.Type().Value());
36   Exception::AddMessage("  # Rows = "); Exception::AddInt(A.Nrows());
37   Exception::AddMessage("; # Cols = "); Exception::AddInt(A.Ncols());
38   if (lbw >=0)
39      { Exception::AddMessage("; lower BW = "); Exception::AddInt(lbw); }
40   if (ubw >=0)
41      { Exception::AddMessage("; upper BW = "); Exception::AddInt(ubw); }
42   Exception::AddMessage("\n");
43}
44
45NPDException::NPDException(const GeneralMatrix& A)
46   : Runtime_error()
47{
48   Select = Exception::Select;
49   AddMessage("detected by Newmat: matrix not positive definite\n\n");
50   MatrixDetails(A);
51   Tracer::AddTrace();
52}
53
54SingularException::SingularException(const GeneralMatrix& A)
55   : Runtime_error()
56{
57   Select = Exception::Select;
58   AddMessage("detected by Newmat: matrix is singular\n\n");
59   MatrixDetails(A);
60   Tracer::AddTrace();
61}
62
63ConvergenceException::ConvergenceException(const GeneralMatrix& A)
64   : Runtime_error()
65{
66   Select = Exception::Select;
67   AddMessage("detected by Newmat: process fails to converge\n\n");
68   MatrixDetails(A);
69   Tracer::AddTrace();
70}
71
72ConvergenceException::ConvergenceException(const char* c) : Runtime_error()
73{
74   Select = Exception::Select;
75   AddMessage("detected by Newmat: ");
76   AddMessage(c); AddMessage("\n\n");
77   if (c) Tracer::AddTrace();
78}
79
80OverflowException::OverflowException(const char* c) : Runtime_error()
81{
82   Select = Exception::Select;
83   AddMessage("detected by Newmat: ");
84   AddMessage(c); AddMessage("\n\n");
85   if (c) Tracer::AddTrace();
86}
87
88ProgramException::ProgramException(const char* c) : Logic_error()
89{
90   Select = Exception::Select;
91   AddMessage("detected by Newmat: ");
92   AddMessage(c); AddMessage("\n\n");
93   if (c) Tracer::AddTrace();
94}
95
96ProgramException::ProgramException(const char* c, const GeneralMatrix& A)
97   : Logic_error()
98{
99   Select = Exception::Select;
100   AddMessage("detected by Newmat: ");
101   AddMessage(c); AddMessage("\n\n");
102   MatrixDetails(A);
103   if (c) Tracer::AddTrace();
104}
105
106ProgramException::ProgramException(const char* c, const GeneralMatrix& A,
107   const GeneralMatrix& B) : Logic_error()
108{
109   Select = Exception::Select;
110   AddMessage("detected by Newmat: ");
111   AddMessage(c); AddMessage("\n\n");
112   MatrixDetails(A); MatrixDetails(B);
113   if (c) Tracer::AddTrace();
114}
115
116ProgramException::ProgramException(const char* c, MatrixType a, MatrixType b)
117   : Logic_error()
118{
119   Select = Exception::Select;
120   AddMessage("detected by Newmat: ");
121   AddMessage(c); AddMessage("\nMatrixTypes = ");
122   AddMessage(a.Value()); AddMessage("; ");
123   AddMessage(b.Value()); AddMessage("\n\n");
124   if (c) Tracer::AddTrace();
125}
126
127VectorException::VectorException() : Logic_error()
128{
129   Select = Exception::Select;
130   AddMessage("detected by Newmat: cannot convert matrix to vector\n\n");
131   Tracer::AddTrace();
132}
133
134VectorException::VectorException(const GeneralMatrix& A)
135   : Logic_error()
136{
137   Select = Exception::Select;
138   AddMessage("detected by Newmat: cannot convert matrix to vector\n\n");
139   MatrixDetails(A);
140   Tracer::AddTrace();
141}
142
143NotSquareException::NotSquareException(const GeneralMatrix& A)
144   : Logic_error()
145{
146   Select = Exception::Select;
147   AddMessage("detected by Newmat: matrix is not square\n\n");
148   MatrixDetails(A);
149   Tracer::AddTrace();
150}
151
152SubMatrixDimensionException::SubMatrixDimensionException()
153   : Logic_error()
154{
155   Select = Exception::Select;
156   AddMessage("detected by Newmat: incompatible submatrix dimension\n\n");
157   Tracer::AddTrace();
158}
159
160IncompatibleDimensionsException::IncompatibleDimensionsException()
161   : Logic_error()
162{
163   Select = Exception::Select;
164   AddMessage("detected by Newmat: incompatible dimensions\n\n");
165   Tracer::AddTrace();
166}
167
168IncompatibleDimensionsException::IncompatibleDimensionsException
169   (const GeneralMatrix& A, const GeneralMatrix& B)
170      : Logic_error()
171{
172   Select = Exception::Select;
173   AddMessage("detected by Newmat: incompatible dimensions\n\n");
174   MatrixDetails(A); MatrixDetails(B);
175   Tracer::AddTrace();
176}
177
178NotDefinedException::NotDefinedException(const char* op, const char* matrix)
179   : Logic_error()
180{
181   Select = Exception::Select;
182   AddMessage("detected by Newmat: ");
183   AddMessage(op);
184   AddMessage(" not defined for ");
185   AddMessage(matrix);
186   AddMessage("\n\n");
187   Tracer::AddTrace();
188}
189
190CannotBuildException::CannotBuildException(const char* matrix)
191   : Logic_error()
192{
193   Select = Exception::Select;
194   AddMessage("detected by Newmat: cannot build matrix type ");
195   AddMessage(matrix); AddMessage("\n\n");
196   Tracer::AddTrace();
197}
198
199IndexException::IndexException(int i, const GeneralMatrix& A)
200   : Logic_error()
201{
202   Select = Exception::Select;
203   AddMessage("detected by Newmat: index error: requested index = ");
204   AddInt(i); AddMessage("\n\n");
205   MatrixDetails(A);
206   Tracer::AddTrace();
207}
208
209IndexException::IndexException(int i, int j, const GeneralMatrix& A)
210   : Logic_error()
211{
212   Select = Exception::Select;
213   AddMessage("detected by Newmat: index error: requested indices = ");
214   AddInt(i); AddMessage(", "); AddInt(j);
215   AddMessage("\n\n");
216   MatrixDetails(A);
217   Tracer::AddTrace();
218}
219
220
221IndexException::IndexException(int i, const GeneralMatrix& A, bool)
222   : Logic_error()
223{
224   Select = Exception::Select;
225   AddMessage("detected by Newmat: element error: requested index (wrt 0) = ");
226   AddInt(i);
227   AddMessage("\n\n");
228   MatrixDetails(A);
229   Tracer::AddTrace();
230}
231
232IndexException::IndexException(int i, int j, const GeneralMatrix& A, bool)
233   : Logic_error()
234{
235   Select = Exception::Select;
236   AddMessage(
237      "detected by Newmat: element error: requested indices (wrt 0) = ");
238   AddInt(i); AddMessage(", "); AddInt(j);
239   AddMessage("\n\n");
240   MatrixDetails(A);
241   Tracer::AddTrace();
242}
243
244InternalException::InternalException(const char* c) : Logic_error()
245{
246   Select = Exception::Select;
247   AddMessage("internal error detected by Newmat: please inform author\n");
248   AddMessage(c); AddMessage("\n\n");
249   Tracer::AddTrace();
250}
251
252
253
254
255/************************* ExeCounter functions *****************************/
256
257#ifdef DO_REPORT
258
259int ExeCounter::nreports;                      // will be set to zero
260
261ExeCounter::ExeCounter(int xl, int xf) : line(xl), fileid(xf), nexe(0) {}
262
263ExeCounter::~ExeCounter()
264{
265   nreports++;
266   cout << "REPORT  " << setw(6) << nreports << "  "
267      << setw(6) << fileid << "  " << setw(6) << line
268      << "  " << setw(6) << nexe << "\n";
269}
270
271#endif
272
273/**************************** error handler *******************************/
274
275void MatrixErrorNoSpace(void* v) { if (!v) Throw(Bad_alloc()); }
276// throw exception if v is null
277
278
279
280
281/************************* miscellanous errors ***************************/
282
283
284void CroutMatrix::GetRow(MatrixRowCol&)
285   { Throw(NotDefinedException("GetRow","Crout")); }
286void CroutMatrix::GetCol(MatrixRowCol&)
287   { Throw(NotDefinedException("GetCol","Crout")); }
288void CroutMatrix::operator=(const BaseMatrix&)
289   { Throw(NotDefinedException("=","Crout")); }
290void BandLUMatrix::GetRow(MatrixRowCol&)
291   { Throw(NotDefinedException("GetRow","BandLUMatrix")); }
292void BandLUMatrix::GetCol(MatrixRowCol&)
293   { Throw(NotDefinedException("GetCol","BandLUMatrix")); }
294void BandLUMatrix::operator=(const BaseMatrix&)
295   { Throw(NotDefinedException("=","BandLUMatrix")); }
296void BaseMatrix::IEQND() const
297   { Throw(NotDefinedException("inequalities", "matrices")); }
298#ifdef TEMPS_DESTROYED_QUICKLY_R
299   ReturnMatrixX::ReturnMatrixX(const ReturnMatrixX& tm)
300     : gm(tm.gm) { Throw(ProgramException("ReturnMatrixX error")); }
301#endif
302
303
304#ifdef use_namespace
305}
306#endif
307
Note: See TracBrowser for help on using the repository browser.