home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / sources / misc / 4255 / tmti.cxx < prev   
Encoding:
C/C++ Source or Header  |  1993-01-11  |  5.1 KB  |  167 lines

  1.  
  2. //#define WANT_STREAM
  3.  
  4. #include "include.h"
  5.  
  6. #include "newmatap.h"
  7. //#include "newmatio.h"
  8.  
  9. void Print(const Matrix& X);
  10. void Print(const UpperTriangularMatrix& X);
  11. void Print(const DiagonalMatrix& X);
  12. void Print(const SymmetricMatrix& X);
  13. void Print(const LowerTriangularMatrix& X);
  14.  
  15. void Clean(Matrix&, Real);
  16.  
  17. void WillNotConverge()
  18. {
  19.    Matrix A(10,10);
  20.    Throw(ConvergenceException(A));
  21. }
  22.  
  23. void trymati()
  24. {
  25.    Tracer et("Eighteenth test of Matrix package");
  26.    Exception::PrintTrace(TRUE);
  27.    ProgramException::SetAction(0);           // turn off error messages
  28.    DataException::SetAction(0);
  29.    ConvergenceException::SetAction(0);
  30.    ColumnVector checks(14); checks = 1.0; checks(1) = 0.0;
  31.  
  32.    Try { WillNotConverge(); }
  33.    Catch(ConvergenceException) { checks(2) = 0; }
  34.    Catch(InternalException) { checks(1) = 1; }
  35.    Catch(ProgramException) { checks(1) = 1; }
  36.    Catch(DataException) { checks(1) = 1; }
  37.    Catch(SpaceException) { checks(1) = 1; }
  38.    CatchAndThrow;
  39.  
  40.    Try { Matrix M(10,10); SymmetricMatrix S = M; } 
  41.    Catch(ConvergenceException) { checks(1) = 1; }
  42.    Catch(InternalException) { checks(1) = 1; }
  43.    Catch(ProgramException) { checks(3) = 0; }
  44.    Catch(DataException) { checks(1) = 1; }
  45.    Catch(SpaceException) { checks(1) = 1; }
  46.    CatchAndThrow;
  47.  
  48.    Try { Matrix M(10,10); M(10,11) = 2.0; } 
  49.    Catch(ConvergenceException) { checks(1) = 1; }
  50.    Catch(InternalException) { checks(1) = 1; }
  51.    Catch(ProgramException) { checks(4) = 0; }
  52.    Catch(DataException) { checks(1) = 1; }
  53.    Catch(SpaceException) { checks(1) = 1; }
  54.    CatchAndThrow;
  55.  
  56.    Try { Matrix M(10,10); M = 0.0; M = M.i(); } 
  57.    Catch(ConvergenceException) { checks(1) = 1; }
  58.    Catch(InternalException) { checks(1) = 1; }
  59.    Catch(ProgramException) { checks(1) = 1; }
  60.    Catch(DataException) { checks(5) = 0; }
  61.    Catch(SpaceException) { checks(1) = 1; }
  62.    CatchAndThrow;
  63.  
  64.    Try { ColumnVector A(30), B(50);  A = 5; B = 3; FFT(A,B,A,B); } 
  65.    Catch(ConvergenceException) { checks(1) = 1; }
  66.    Catch(InternalException) { checks(1) = 1; }
  67.    Catch(ProgramException) { checks(6) = 0; }
  68.    Catch(DataException) { checks(1) = 1; }
  69.    Catch(SpaceException) { checks(1) = 1; }
  70.    CatchAndThrow;
  71.  
  72.    Try
  73.    {
  74.       ColumnVector A(30); A = 5; Matrix At = A.t();
  75.       DiagonalMatrix D;
  76.       SVD(At,D);
  77.    } 
  78.    Catch(ConvergenceException) { checks(1) = 1; }
  79.    Catch(InternalException) { checks(1) = 1; }
  80.    Catch(ProgramException) { checks(6) = 0; }
  81.    Catch(DataException) { checks(1) = 1; }
  82.    Catch(SpaceException) { checks(1) = 1; }
  83.    CatchAndThrow;
  84.  
  85.    Try { BandMatrix X(10,3,4); X(1,10) = 4.0; } 
  86.    Catch(ConvergenceException) { checks(1) = 1; }
  87.    Catch(InternalException) { checks(1) = 1; }
  88.    Catch(ProgramException) { checks(7) = 0; }
  89.    Catch(DataException) { checks(1) = 1; }
  90.    Catch(SpaceException) { checks(1) = 1; }
  91.    CatchAndThrow;
  92.  
  93.    Try
  94.    {
  95.       SymmetricMatrix S(10); S = 5;
  96.       LowerTriangularMatrix L = Cholesky(S);
  97.    } 
  98.    Catch(ConvergenceException) { checks(1) = 1; }
  99.    Catch(InternalException) { checks(1) = 1; }
  100.    Catch(ProgramException) { checks(1) = 1; }
  101.    Catch(DataException) { checks(8) = 0; }
  102.    Catch(SpaceException) { checks(1) = 1; }
  103.    CatchAndThrow;
  104.  
  105.    Try { BandMatrix M(10,3,5); M = 0.0; Matrix XM = M.i(); } 
  106.    Catch(ConvergenceException) { checks(1) = 1; }
  107.    Catch(InternalException) { checks(1) = 1; }
  108.    Catch(ProgramException) { checks(1) = 1; }
  109.    Catch(DataException) { checks(9) = 0; }
  110.    Catch(SpaceException) { checks(1) = 1; }
  111.    CatchAndThrow;
  112.  
  113.  
  114.    Try { ColumnVector X(10); ColumnVector Y; X = 5; X = X - Y; }
  115.    Catch(ConvergenceException) { checks(1) = 1; }
  116.    Catch(InternalException) { checks(1) = 1; }
  117.    Catch(ProgramException) { checks(10) = 0; }
  118.    Catch(DataException) { checks(1) = 1; }
  119.    Catch(SpaceException) { checks(1) = 1; }
  120.    CatchAndThrow;
  121.  
  122.    Try
  123.    {
  124.       UpperTriangularMatrix U(3); RowVector RV(3); RV = 10;
  125.       U.Row(2) = RV;
  126.    }
  127.    Catch(ConvergenceException) { checks(1) = 1; }
  128.    Catch(InternalException) { checks(1) = 1; }
  129.    Catch(ProgramException) { checks(11) = 0; }
  130.    Catch(DataException) { checks(1) = 1; }
  131.    Catch(SpaceException) { checks(1) = 1; }
  132.    CatchAndThrow;
  133.  
  134.    Try { DiagonalMatrix D(3); D << 12 << 13 << 14 << 15; }
  135.    Catch(ConvergenceException) { checks(1) = 1; }
  136.    Catch(InternalException) { checks(1) = 1; }
  137.    Catch(ProgramException) { checks(12) = 0; }
  138.    Catch(DataException) { checks(1) = 1; }
  139.    Catch(SpaceException) { checks(1) = 1; }
  140.    CatchAndThrow;
  141.  
  142.    Try { ColumnVector D(3); D << 12 << 13; D << 1 << 2 << 3; }
  143.    Catch(ConvergenceException) { checks(1) = 1; }
  144.    Catch(InternalException) { checks(1) = 1; }
  145.    Catch(ProgramException) { checks(13) = 0; }
  146.    Catch(DataException) { checks(1) = 1; }
  147.    Catch(SpaceException) { checks(1) = 1; }
  148.    CatchAndThrow;
  149.  
  150.  
  151.    Try {  { ColumnVector D(3); D << 12 << 13; }  }
  152.    Catch(ConvergenceException) { checks(1) = 1; }
  153.    Catch(InternalException) { checks(1) = 1; }
  154.    Catch(ProgramException) { checks(14) = 0; }
  155.    Catch(DataException) { checks(1) = 1; }
  156.    Catch(SpaceException) { checks(1) = 1; }
  157.    CatchAndThrow;
  158.  
  159.  
  160.    ProgramException::SetAction(1);           // restore error messages
  161.    DataException::SetAction(1);
  162.    ConvergenceException::SetAction(1);
  163.  
  164.    Print(checks);
  165.  
  166. }
  167.