Virtual U.org
Get Personal Training on VU Today
    
Top shadow
 
 register/help
User Name:

Password:

NEWMATEX.CPP Source File
Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

NEWMATEX.CPP

Go to the documentation of this file.
00001 //Owner: Fred
00002 //$$ newmatex.cpp                    Exception handler
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     static void MatrixDetails(const GeneralMatrix& A) {
00030         // write matrix details to Exception buffer
00031         MatrixBandWidth bw = A.BandWidth(); int ubw = bw.upper; int lbw = bw.lower;
00032         Exception::AddMessage("MatrixType = ");
00033         Exception::AddMessage(A.Type().Value());
00034         Exception::AddMessage("  # Rows = "); Exception::AddInt(A.Nrows());
00035         Exception::AddMessage("; # Cols = "); Exception::AddInt(A.Ncols());
00036         if (lbw >=0)
00037         { Exception::AddMessage("; lower BW = "); Exception::AddInt(lbw); }
00038         if (ubw >=0)
00039         { Exception::AddMessage("; upper BW = "); Exception::AddInt(ubw); }
00040         Exception::AddMessage("\n");
00041     }
00042 
00043     NPDException::NPDException(const GeneralMatrix& A)
00044         : Runtime_error() {
00045         Select = Exception::Select;
00046         AddMessage("detected by Newmat: matrix not positive definite\n\n");
00047         MatrixDetails(A);
00048         Tracer::AddTrace();
00049     }
00050 
00051     SingularException::SingularException(const GeneralMatrix& A)
00052         : Runtime_error() {
00053         Select = Exception::Select;
00054         AddMessage("detected by Newmat: matrix is singular\n\n");
00055         MatrixDetails(A);
00056         Tracer::AddTrace();
00057     }
00058 
00059     ConvergenceException::ConvergenceException(const GeneralMatrix& A)
00060         : Runtime_error() {
00061         Select = Exception::Select;
00062         AddMessage("detected by Newmat: process fails to converge\n\n");
00063         MatrixDetails(A);
00064         Tracer::AddTrace();
00065     }
00066 
00067     ConvergenceException::ConvergenceException(const char* c) : Runtime_error() {
00068         Select = Exception::Select;
00069         AddMessage("detected by Newmat: ");
00070         AddMessage(c); AddMessage("\n\n");
00071         if (c) Tracer::AddTrace();
00072     }
00073 
00074     OverflowException::OverflowException(const char* c) : Runtime_error() {
00075         Select = Exception::Select;
00076         AddMessage("detected by Newmat: ");
00077         AddMessage(c); AddMessage("\n\n");
00078         if (c) Tracer::AddTrace();
00079     }
00080 
00081     ProgramException::ProgramException(const char* c) : Logic_error() {
00082         Select = Exception::Select;
00083         AddMessage("detected by Newmat: ");
00084         AddMessage(c); AddMessage("\n\n");
00085         if (c) Tracer::AddTrace();
00086     }
00087 
00088     ProgramException::ProgramException(const char* c, const GeneralMatrix& A)
00089         : Logic_error() {
00090         Select = Exception::Select;
00091         AddMessage("detected by Newmat: ");
00092         AddMessage(c); AddMessage("\n\n");
00093         MatrixDetails(A);
00094         if (c) Tracer::AddTrace();
00095     }
00096 
00097     ProgramException::ProgramException(const char* c, const GeneralMatrix& A,
00098                                        const GeneralMatrix& B) : Logic_error() {
00099         Select = Exception::Select;
00100         AddMessage("detected by Newmat: ");
00101         AddMessage(c); AddMessage("\n\n");
00102         MatrixDetails(A); MatrixDetails(B);
00103         if (c) Tracer::AddTrace();
00104     }
00105 
00106     ProgramException::ProgramException(const char* c, MatrixType a, MatrixType b)
00107         : Logic_error() {
00108         Select = Exception::Select;
00109         AddMessage("detected by Newmat: ");
00110         AddMessage(c); AddMessage("\nMatrixTypes = ");
00111         AddMessage(a.Value()); AddMessage("; ");
00112         AddMessage(b.Value()); AddMessage("\n\n");
00113         if (c) Tracer::AddTrace();
00114     }
00115 
00116     VectorException::VectorException() : Logic_error() {
00117         Select = Exception::Select;
00118         AddMessage("detected by Newmat: can't convert matrix to vector\n\n");
00119         Tracer::AddTrace();
00120     }
00121 
00122     VectorException::VectorException(const GeneralMatrix& A)
00123         : Logic_error() {
00124         Select = Exception::Select;
00125         AddMessage("detected by Newmat: can't convert matrix to vector\n\n");
00126         MatrixDetails(A);
00127         Tracer::AddTrace();
00128     }
00129 
00130     NotSquareException::NotSquareException(const GeneralMatrix& A)
00131         : Logic_error() {
00132         Select = Exception::Select;
00133         AddMessage("detected by Newmat: matrix is not square\n\n");
00134         MatrixDetails(A);
00135         Tracer::AddTrace();
00136     }
00137 
00138     SubMatrixDimensionException::SubMatrixDimensionException()
00139         : Logic_error() {
00140         Select = Exception::Select;
00141         AddMessage("detected by Newmat: incompatible submatrix dimension\n\n");
00142         Tracer::AddTrace();
00143     }
00144 
00145     IncompatibleDimensionsException::IncompatibleDimensionsException()
00146         : Logic_error() {
00147         Select = Exception::Select;
00148         AddMessage("detected by Newmat: incompatible dimensions\n\n");
00149         Tracer::AddTrace();
00150     }
00151 
00152     IncompatibleDimensionsException::IncompatibleDimensionsException
00153     (const GeneralMatrix& A, const GeneralMatrix& B)
00154         : Logic_error() {
00155         Select = Exception::Select;
00156         AddMessage("detected by Newmat: incompatible dimensions\n\n");
00157         MatrixDetails(A); MatrixDetails(A); MatrixDetails(B);
00158         Tracer::AddTrace();
00159     }
00160 
00161     NotDefinedException::NotDefinedException(const char* op, const char* matrix)
00162         : Logic_error() {
00163         Select = Exception::Select;
00164         AddMessage("detected by Newmat: ");
00165         AddMessage(op);
00166         AddMessage(" not defined for ");
00167         AddMessage(matrix);
00168         AddMessage("\n\n");
00169         Tracer::AddTrace();
00170     }
00171 
00172     CannotBuildException::CannotBuildException(const char* matrix)
00173         : Logic_error() {
00174         Select = Exception::Select;
00175         AddMessage("detected by Newmat: can't build matrix type ");
00176         AddMessage(matrix); AddMessage("\n\n");
00177         Tracer::AddTrace();
00178     }
00179 
00180     IndexException::IndexException(int i, const GeneralMatrix& A)
00181         : Logic_error() {
00182         Select = Exception::Select;
00183         AddMessage("detected by Newmat: index error: requested index = ");
00184         AddInt(i); AddMessage("\n\n");
00185         MatrixDetails(A);
00186         Tracer::AddTrace();
00187     }
00188 
00189     IndexException::IndexException(int i, int j, const GeneralMatrix& A)
00190         : Logic_error() {
00191         Select = Exception::Select;
00192         AddMessage("detected by Newmat: index error: requested indices = ");
00193         AddInt(i); AddMessage(", "); AddInt(j);
00194         AddMessage("\n\n");
00195         MatrixDetails(A);
00196         Tracer::AddTrace();
00197     }
00198 
00199     IndexException::IndexException(int i, const GeneralMatrix& A, bool)
00200         : Logic_error() {
00201         Select = Exception::Select;
00202         AddMessage("detected by Newmat: element error: requested index (wrt 0) = ");
00203         AddInt(i);
00204         AddMessage("\n\n");
00205         MatrixDetails(A);
00206         Tracer::AddTrace();
00207     }
00208 
00209     IndexException::IndexException(int i, int j, const GeneralMatrix& A, bool)
00210         : Logic_error() {
00211         Select = Exception::Select;
00212         AddMessage(
00213             "detected by Newmat: element error: requested indices (wrt 0) = ");
00214         AddInt(i); AddMessage(", "); AddInt(j);
00215         AddMessage("\n\n");
00216         MatrixDetails(A);
00217         Tracer::AddTrace();
00218     }
00219 
00220     InternalException::InternalException(const char* c) : Logic_error() {
00221         Select = Exception::Select;
00222         AddMessage("internal error detected by Newmat: please inform author\n");
00223         AddMessage(c); AddMessage("\n\n");
00224         Tracer::AddTrace();
00225     }
00226 
00227     /************************* ExeCounter functions *****************************/
00228 
00229 #ifdef DO_REPORT
00230 
00231     int ExeCounter::nreports;                       // will be set to zero
00232 
00233     ExeCounter::ExeCounter(int xl, int xf) : line(xl), fileid(xf), nexe(0) {}
00234 
00235     ExeCounter::~ExeCounter() {
00236         nreports++;
00237         cout << "REPORT  " << setw(6) << nreports << "  "
00238              << setw(6) << fileid << "  " << setw(6) << line
00239              << "  " << setw(6) << nexe << "\n";
00240     }
00241 #endif
00242 
00243     /**************************** error handler *******************************/
00244 
00245     void MatrixErrorNoSpace(void* v) { if (!v) Throw(Bad_alloc()); }
00246     // throw exception if v is null
00247 
00248     /************************* miscellanous errors ***************************/
00249 
00250     void CroutMatrix::GetRow(MatrixRowCol&)
00251     { Throw(NotDefinedException("GetRow","Crout")); }
00252     void CroutMatrix::GetCol(MatrixRowCol&)
00253     { Throw(NotDefinedException("GetCol","Crout")); }
00254     void CroutMatrix::operator=(const BaseMatrix&)
00255     { Throw(NotDefinedException("=","Crout")); }
00256     void BandLUMatrix::GetRow(MatrixRowCol&)
00257     { Throw(NotDefinedException("GetRow","BandLUMatrix")); }
00258     void BandLUMatrix::GetCol(MatrixRowCol&)
00259     { Throw(NotDefinedException("GetCol","BandLUMatrix")); }
00260     void BandLUMatrix::operator=(const BaseMatrix&)
00261     { Throw(NotDefinedException("=","BandLUMatrix")); }
00262     void BaseMatrix::IEQND() const
00263     { Throw(NotDefinedException("inequalities", "matrices")); }
00264 #ifdef TEMPS_DESTROYED_QUICKLY_R
00265     ReturnMatrixX::ReturnMatrixX(const ReturnMatrixX& tm)
00266         : gm(tm.gm) { Throw(ProgramException("ReturnMatrixX error")); }
00267 #endif
00268 
00269 #ifdef use_namespace
00270 }
00271 #endif

Generated on Fri Aug 23 01:37:10 2002 for VirtualU by doxygen1.2.17