newmatex.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005 #ifndef WANT_STREAM
00006 #define WANT_STREAM // include.h will get stream fns
00007 #endif
00008
00009 #include "include.h"
00010 #include "newmat.h"
00011
00012 #ifdef use_namespace
00013 namespace NEWMAT {
00014 #endif
00015
00016 unsigned long OverflowException::Select;
00017 unsigned long SingularException::Select;
00018 unsigned long NPDException::Select;
00019 unsigned long ConvergenceException::Select;
00020 unsigned long ProgramException::Select;
00021 unsigned long IndexException::Select;
00022 unsigned long VectorException::Select;
00023 unsigned long NotSquareException::Select;
00024 unsigned long SubMatrixDimensionException::Select;
00025 unsigned long IncompatibleDimensionsException::Select;
00026 unsigned long NotDefinedException::Select;
00027 unsigned long CannotBuildException::Select;
00028 unsigned long InternalException::Select;
00029
00030
00031
00032 static void MatrixDetails(const GeneralMatrix& A)
00033
00034 {
00035 MatrixBandWidth bw = A.BandWidth(); int ubw = bw.upper; int lbw = bw.lower;
00036 BaseException::AddMessage("MatrixType = ");
00037 BaseException::AddMessage(A.Type().Value());
00038 BaseException::AddMessage(" # Rows = "); BaseException::AddInt(A.Nrows());
00039 BaseException::AddMessage("; # Cols = "); BaseException::AddInt(A.Ncols());
00040 if (lbw >=0)
00041 {
00042 BaseException::AddMessage("; lower BW = ");
00043 BaseException::AddInt(lbw);
00044 }
00045 if (ubw >=0)
00046 {
00047 BaseException::AddMessage("; upper BW = ");
00048 BaseException::AddInt(ubw);
00049 }
00050 BaseException::AddMessage("\n");
00051 }
00052
00053 NPDException::NPDException(const GeneralMatrix& A)
00054 : Runtime_error()
00055 {
00056 Select = BaseException::Select;
00057 AddMessage("detected by Newmat: matrix not positive definite\n\n");
00058 MatrixDetails(A);
00059 Tracer::AddTrace();
00060 }
00061
00062 SingularException::SingularException(const GeneralMatrix& A)
00063 : Runtime_error()
00064 {
00065 Select = BaseException::Select;
00066 AddMessage("detected by Newmat: matrix is singular\n\n");
00067 MatrixDetails(A);
00068 Tracer::AddTrace();
00069 }
00070
00071 ConvergenceException::ConvergenceException(const GeneralMatrix& A)
00072 : Runtime_error()
00073 {
00074 Select = BaseException::Select;
00075 AddMessage("detected by Newmat: process fails to converge\n\n");
00076 MatrixDetails(A);
00077 Tracer::AddTrace();
00078 }
00079
00080 ConvergenceException::ConvergenceException(const char* c) : Runtime_error()
00081 {
00082 Select = BaseException::Select;
00083 AddMessage("detected by Newmat: ");
00084 AddMessage(c); AddMessage("\n\n");
00085 if (c) Tracer::AddTrace();
00086 }
00087
00088 OverflowException::OverflowException(const char* c) : Runtime_error()
00089 {
00090 Select = BaseException::Select;
00091 AddMessage("detected by Newmat: ");
00092 AddMessage(c); AddMessage("\n\n");
00093 if (c) Tracer::AddTrace();
00094 }
00095
00096 ProgramException::ProgramException(const char* c) : Logic_error()
00097 {
00098 Select = BaseException::Select;
00099 AddMessage("detected by Newmat: ");
00100 AddMessage(c); AddMessage("\n\n");
00101 if (c) Tracer::AddTrace();
00102 }
00103
00104 ProgramException::ProgramException(const char* c, const GeneralMatrix& A)
00105 : Logic_error()
00106 {
00107 Select = BaseException::Select;
00108 AddMessage("detected by Newmat: ");
00109 AddMessage(c); AddMessage("\n\n");
00110 MatrixDetails(A);
00111 if (c) Tracer::AddTrace();
00112 }
00113
00114 ProgramException::ProgramException(const char* c, const GeneralMatrix& A,
00115 const GeneralMatrix& B) : Logic_error()
00116 {
00117 Select = BaseException::Select;
00118 AddMessage("detected by Newmat: ");
00119 AddMessage(c); AddMessage("\n\n");
00120 MatrixDetails(A); MatrixDetails(B);
00121 if (c) Tracer::AddTrace();
00122 }
00123
00124 ProgramException::ProgramException(const char* c, MatrixType a, MatrixType b)
00125 : Logic_error()
00126 {
00127 Select = BaseException::Select;
00128 AddMessage("detected by Newmat: ");
00129 AddMessage(c); AddMessage("\nMatrixTypes = ");
00130 AddMessage(a.Value()); AddMessage("; ");
00131 AddMessage(b.Value()); AddMessage("\n\n");
00132 if (c) Tracer::AddTrace();
00133 }
00134
00135 VectorException::VectorException() : Logic_error()
00136 {
00137 Select = BaseException::Select;
00138 AddMessage("detected by Newmat: cannot convert matrix to vector\n\n");
00139 Tracer::AddTrace();
00140 }
00141
00142 VectorException::VectorException(const GeneralMatrix& A)
00143 : Logic_error()
00144 {
00145 Select = BaseException::Select;
00146 AddMessage("detected by Newmat: cannot convert matrix to vector\n\n");
00147 MatrixDetails(A);
00148 Tracer::AddTrace();
00149 }
00150
00151 NotSquareException::NotSquareException(const GeneralMatrix& A)
00152 : Logic_error()
00153 {
00154 Select = BaseException::Select;
00155 AddMessage("detected by Newmat: matrix is not square\n\n");
00156 MatrixDetails(A);
00157 Tracer::AddTrace();
00158 }
00159
00160 NotSquareException::NotSquareException()
00161 : Logic_error()
00162 {
00163 Select = BaseException::Select;
00164 AddMessage("detected by Newmat: matrix is not square\n\n");
00165 Tracer::AddTrace();
00166 }
00167
00168 SubMatrixDimensionException::SubMatrixDimensionException()
00169 : Logic_error()
00170 {
00171 Select = BaseException::Select;
00172 AddMessage("detected by Newmat: incompatible submatrix dimension\n\n");
00173 Tracer::AddTrace();
00174 }
00175
00176 IncompatibleDimensionsException::IncompatibleDimensionsException()
00177 : Logic_error()
00178 {
00179 Select = BaseException::Select;
00180 AddMessage("detected by Newmat: incompatible dimensions\n\n");
00181 Tracer::AddTrace();
00182 }
00183
00184 IncompatibleDimensionsException::IncompatibleDimensionsException
00185 (const GeneralMatrix& A, const GeneralMatrix& B)
00186 : Logic_error()
00187 {
00188 Select = BaseException::Select;
00189 AddMessage("detected by Newmat: incompatible dimensions\n\n");
00190 MatrixDetails(A); MatrixDetails(B);
00191 Tracer::AddTrace();
00192 }
00193
00194 NotDefinedException::NotDefinedException(const char* op, const char* matrix)
00195 : Logic_error()
00196 {
00197 Select = BaseException::Select;
00198 AddMessage("detected by Newmat: ");
00199 AddMessage(op);
00200 AddMessage(" not defined for ");
00201 AddMessage(matrix);
00202 AddMessage("\n\n");
00203 Tracer::AddTrace();
00204 }
00205
00206 CannotBuildException::CannotBuildException(const char* matrix)
00207 : Logic_error()
00208 {
00209 Select = BaseException::Select;
00210 AddMessage("detected by Newmat: cannot build matrix type ");
00211 AddMessage(matrix); AddMessage("\n\n");
00212 Tracer::AddTrace();
00213 }
00214
00215 IndexException::IndexException(int i, const GeneralMatrix& A)
00216 : Logic_error()
00217 {
00218 Select = BaseException::Select;
00219 AddMessage("detected by Newmat: index error: requested index = ");
00220 AddInt(i); AddMessage("\n\n");
00221 MatrixDetails(A);
00222 Tracer::AddTrace();
00223 }
00224
00225 IndexException::IndexException(int i, int j, const GeneralMatrix& A)
00226 : Logic_error()
00227 {
00228 Select = BaseException::Select;
00229 AddMessage("detected by Newmat: index error: requested indices = ");
00230 AddInt(i); AddMessage(", "); AddInt(j);
00231 AddMessage("\n\n");
00232 MatrixDetails(A);
00233 Tracer::AddTrace();
00234 }
00235
00236
00237 IndexException::IndexException(int i, const GeneralMatrix& A, bool)
00238 : Logic_error()
00239 {
00240 Select = BaseException::Select;
00241 AddMessage("detected by Newmat: element error: requested index (wrt 0) = ");
00242 AddInt(i);
00243 AddMessage("\n\n");
00244 MatrixDetails(A);
00245 Tracer::AddTrace();
00246 }
00247
00248 IndexException::IndexException(int i, int j, const GeneralMatrix& A, bool)
00249 : Logic_error()
00250 {
00251 Select = BaseException::Select;
00252 AddMessage(
00253 "detected by Newmat: element error: requested indices (wrt 0) = ");
00254 AddInt(i); AddMessage(", "); AddInt(j);
00255 AddMessage("\n\n");
00256 MatrixDetails(A);
00257 Tracer::AddTrace();
00258 }
00259
00260 InternalException::InternalException(const char* c) : Logic_error()
00261 {
00262 Select = BaseException::Select;
00263 AddMessage("internal error detected by Newmat: please inform author\n");
00264 AddMessage(c); AddMessage("\n\n");
00265 Tracer::AddTrace();
00266 }
00267
00268
00269
00270
00271
00272
00273 #ifdef DO_REPORT
00274
00275 int ExeCounter::nreports;
00276
00277 ExeCounter::ExeCounter(int xl, int xf) : line(xl), fileid(xf), nexe(0) {}
00278
00279 ExeCounter::~ExeCounter()
00280 {
00281 nreports++;
00282 cout << "REPORT " << setw(6) << nreports << " "
00283 << setw(6) << fileid << " " << setw(6) << line
00284 << " " << setw(6) << nexe << "\n";
00285 }
00286
00287 #endif
00288
00289
00290
00291 void MatrixErrorNoSpace(const void* v) { if (!v) Throw(Bad_alloc()); }
00292
00293
00294
00295
00296
00297
00298
00299
00300 void CroutMatrix::GetRow(MatrixRowCol&)
00301 { Throw(NotDefinedException("GetRow","Crout")); }
00302 void CroutMatrix::GetCol(MatrixRowCol&)
00303 { Throw(NotDefinedException("GetCol","Crout")); }
00304 void BandLUMatrix::GetRow(MatrixRowCol&)
00305 { Throw(NotDefinedException("GetRow","BandLUMatrix")); }
00306 void BandLUMatrix::GetCol(MatrixRowCol&)
00307 { Throw(NotDefinedException("GetCol","BandLUMatrix")); }
00308 void BaseMatrix::IEQND() const
00309 { Throw(NotDefinedException("inequalities", "matrices")); }
00310
00311
00312 #ifdef use_namespace
00313 }
00314 #endif
00315