newmatex.cpp
Go to the documentation of this file.
00001 
00002 
00003 
00004 // Copyright (C) 1992,3,4,7: R B Davies
00005 
00006 #define WANT_STREAM                  // include.h will get stream fns
00007 
00008 #include "include.h"                 // include standard files
00009 #include "newmat.h"
00010 
00011 #ifdef use_namespace
00012 namespace NEWMAT {
00013 #endif
00014 
00015 unsigned long OverflowException::Select;
00016 unsigned long SingularException::Select;
00017 unsigned long NPDException::Select;
00018 unsigned long ConvergenceException::Select;
00019 unsigned long ProgramException::Select;
00020 unsigned long IndexException::Select;
00021 unsigned long VectorException::Select;
00022 unsigned long NotSquareException::Select;
00023 unsigned long SubMatrixDimensionException::Select;
00024 unsigned long IncompatibleDimensionsException::Select;
00025 unsigned long NotDefinedException::Select;
00026 unsigned long CannotBuildException::Select;
00027 unsigned long InternalException::Select;
00028 
00029 
00030 
00031 static void MatrixDetails(const GeneralMatrix& A)
00032 // write matrix details to Exception buffer
00033 {
00034    MatrixBandWidth bw = A.bandwidth();
00035    int ubw = bw.upper_val; int lbw = bw.lower_val;
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 IncompatibleDimensionsException::IncompatibleDimensionsException
00195    (const GeneralMatrix& A)
00196       : Logic_error()
00197 {
00198    Select = BaseException::Select;
00199    AddMessage("detected by Newmat: incompatible dimensions\n\n");
00200    MatrixDetails(A);
00201    Tracer::AddTrace();
00202 }
00203 
00204 NotDefinedException::NotDefinedException(const char* op, const char* matrix)
00205    : Logic_error()
00206 {
00207    Select = BaseException::Select;
00208    AddMessage("detected by Newmat: ");
00209    AddMessage(op);
00210    AddMessage(" not defined for ");
00211    AddMessage(matrix);
00212    AddMessage("\n\n");
00213    Tracer::AddTrace();
00214 }
00215 
00216 CannotBuildException::CannotBuildException(const char* matrix)
00217    : Logic_error()
00218 {
00219    Select = BaseException::Select;
00220    AddMessage("detected by Newmat: cannot build matrix type ");
00221    AddMessage(matrix); AddMessage("\n\n");
00222    Tracer::AddTrace();
00223 }
00224 
00225 IndexException::IndexException(int i, const GeneralMatrix& A)
00226    : Logic_error()
00227 {
00228    Select = BaseException::Select;
00229    AddMessage("detected by Newmat: index error: requested index = ");
00230    AddInt(i); AddMessage("\n\n");
00231    MatrixDetails(A);
00232    Tracer::AddTrace();
00233 }
00234 
00235 IndexException::IndexException(int i, int j, const GeneralMatrix& A)
00236    : Logic_error()
00237 {
00238    Select = BaseException::Select;
00239    AddMessage("detected by Newmat: index error: requested indices = ");
00240    AddInt(i); AddMessage(", "); AddInt(j);
00241    AddMessage("\n\n");
00242    MatrixDetails(A);
00243    Tracer::AddTrace();
00244 }
00245 
00246 
00247 IndexException::IndexException(int i, const GeneralMatrix& A, bool)
00248    : Logic_error()
00249 {
00250    Select = BaseException::Select;
00251    AddMessage("detected by Newmat: element error: requested index (wrt 0) = ");
00252    AddInt(i);
00253    AddMessage("\n\n");
00254    MatrixDetails(A);
00255    Tracer::AddTrace();
00256 }
00257 
00258 IndexException::IndexException(int i, int j, const GeneralMatrix& A, bool)
00259    : Logic_error()
00260 {
00261    Select = BaseException::Select;
00262    AddMessage(
00263       "detected by Newmat: element error: requested indices (wrt 0) = ");
00264    AddInt(i); AddMessage(", "); AddInt(j);
00265    AddMessage("\n\n");
00266    MatrixDetails(A);
00267    Tracer::AddTrace();
00268 }
00269 
00270 InternalException::InternalException(const char* c) : Logic_error()
00271 {
00272    Select = BaseException::Select;
00273    AddMessage("internal error detected by Newmat: please inform author\n");
00274    AddMessage(c); AddMessage("\n\n");
00275    Tracer::AddTrace();
00276 }
00277 
00278 
00279 
00280 
00281 /************************* ExeCounter functions *****************************/
00282 
00283 #ifdef DO_REPORT
00284 
00285 int ExeCounter::nreports;                      // will be set to zero
00286 
00287 ExeCounter::ExeCounter(int xl, int xf) : line(xl), fileid(xf), nexe(0) {}
00288 
00289 ExeCounter::~ExeCounter()
00290 {
00291    nreports++;
00292    cout << "REPORT  " << setw(6) << nreports << "  "
00293       << setw(6) << fileid << "  " << setw(6) << line
00294       << "  " << setw(6) << nexe << "\n";
00295 }
00296 
00297 #endif
00298 
00299 /**************************** error handler *******************************/
00300 
00301 void MatrixErrorNoSpace(const void* v) { if (!v) Throw(Bad_alloc()); }
00302 // throw exception if v is null
00303 
00304 
00305 
00306 
00307 /************************* miscellanous errors ***************************/
00308 
00309 
00310 void CroutMatrix::GetRow(MatrixRowCol&)
00311    { Throw(NotDefinedException("GetRow","Crout")); }
00312 void CroutMatrix::GetCol(MatrixRowCol&)
00313    { Throw(NotDefinedException("GetCol","Crout")); }
00314 void BandLUMatrix::GetRow(MatrixRowCol&)
00315    { Throw(NotDefinedException("GetRow","BandLUMatrix")); }
00316 void BandLUMatrix::GetCol(MatrixRowCol&)
00317    { Throw(NotDefinedException("GetCol","BandLUMatrix")); }
00318 void BaseMatrix::IEQND() const
00319    { Throw(NotDefinedException("inequalities", "matrices")); }
00320 
00321 
00322 #ifdef use_namespace
00323 }
00324 #endif
00325 


kni
Author(s): Neuronics AG (see AUTHORS.txt); ROS wrapper by Martin Günther
autogenerated on Mon Oct 6 2014 10:45:33