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