Go to the documentation of this file.00001
00002
00003
00006
00007
00008 #define WANT_STREAM
00009
00010 #include "newmatap.h"
00011 #include "newmatio.h"
00012
00013 #ifdef use_namespace
00014 using namespace RBD_LIBRARIES;
00015 #endif
00016
00017
00018
00019
00020
00021
00022
00023 int main()
00024 {
00025
00026
00027
00028 Real* s1; Real* s2; Real* s3; Real* s4;
00029
00030 cout << "\nThis tests the exception system, so you will get\n" <<
00031 "a long list of error messages\n\n";
00032 cout << "\nPrint a real number (may help lost memory test): "
00033 << 3.14159265 << "\n";
00034
00035 Try { Throw(BaseException("Just a dummy\n")); }
00036 CatchAll {};
00037 { Matrix A1(40,200); s1 = A1.data(); }
00038 { Matrix A1(1,1); s3 = A1.data(); }
00039 {
00040 Tracer et("Test");
00041
00042 Try
00043 {
00044 Tracer et("Try block");
00045
00046
00047
00048 cout << "-----------------------------------------\n\n";
00049 Matrix A(2,3), B(4,5); A = 1; B = 2;
00050 cout << "Incompatible dimensions\n";
00051 et.ReName("Block A");
00052 Try { Matrix C = A + B; }
00053 CatchAll { cout << BaseException::what() << endl; }
00054 cout << "-----------------------------------------\n\n";
00055
00056 cout << "Bad index\n";
00057 et.ReName("Block B");
00058 Try { Real f = A(3,3); cout << f << endl; }
00059 CatchAll { cout << BaseException::what() << endl; }
00060 cout << "-----------------------------------------\n\n";
00061
00062 cout << "Illegal conversion\n";
00063 et.ReName("Block C");
00064 Try { UpperTriangularMatrix U = A; }
00065 CatchAll { cout << BaseException::what() << endl; }
00066 cout << "-----------------------------------------\n\n";
00067
00068 cout << "Invert non-square matrix - 1\n";
00069 et.ReName("Block D");
00070 Try { CroutMatrix X = A; }
00071 CatchAll { cout << BaseException::what() << endl; }
00072 cout << "-----------------------------------------\n\n";
00073
00074 cout << "Invert non-square matrix - 2\n";
00075 et.ReName("Block E");
00076 Try { Matrix X = A.i(); }
00077 CatchAll { cout << BaseException::what() << endl; }
00078 cout << "-----------------------------------------\n\n";
00079
00080 cout << "Non 1x1 matrix to scalar\n";
00081 et.ReName("Block F");
00082 Try { Real f = A.as_scalar(); cout << f << endl; }
00083 CatchAll { cout << BaseException::what() << endl; }
00084 cout << "-----------------------------------------\n\n";
00085
00086 cout << "Matrix to vector\n";
00087 et.ReName("Block G");
00088 Try { ColumnVector CV = A;}
00089 CatchAll { cout << BaseException::what() << endl; }
00090 cout << "-----------------------------------------\n\n";
00091
00092 cout << "Invert singular matrix\n";
00093 et.ReName("Block H");
00094 Try { Matrix X(2,2); X<<1<<2<<2<<4; X = X.i(); }
00095 CatchAll { cout << BaseException::what() << endl; }
00096 cout << "-----------------------------------------\n\n";
00097
00098 cout << "SubMatrix error\n";
00099 et.ReName("Block I");
00100 Try { Matrix X = A.Row(3); }
00101 CatchAll { cout << BaseException::what() << endl; }
00102 cout << "-----------------------------------------\n\n";
00103
00104 cout << "SubMatrix error\n";
00105 et.ReName("Block J");
00106 Try { Matrix X = A.Row(0); }
00107 CatchAll { cout << BaseException::what() << endl; }
00108 cout << "-----------------------------------------\n\n";
00109
00110 cout << "Cholesky error\n";
00111 et.ReName("Block K");
00112 Try
00113 {
00114 SymmetricMatrix SM(50); SM = 10;
00115 LowerTriangularMatrix L = Cholesky(SM);
00116 }
00117 CatchAll { cout << BaseException::what() << endl; }
00118 cout << "-----------------------------------------\n\n";
00119
00120 cout << "Inequality error\n";
00121 et.ReName("Block L");
00122 Try
00123 {
00124 Matrix A(10,10), B(10,10); A = 10; B = 20;
00125 if ( A < B) A = B;
00126 }
00127 CatchAll { cout << BaseException::what() << endl; }
00128 cout << "-----------------------------------------\n\n";
00129
00130 cout << "Maximum of empty matrix\n";
00131 et.ReName("Block M");
00132 Try
00133 {
00134 Matrix A(10,20); A = 5; Matrix B=A.Rows(6,5);
00135 maximum_absolute_value(B);
00136 }
00137 CatchAll { cout << BaseException::what() << endl; }
00138 cout << "-----------------------------------------\n\n";
00139
00140 cout << "Incorrectly ReSizing band matrix\n";
00141 et.ReName("Block N");
00142 Try
00143 {
00144 BandMatrix A(20,5,3); A = 5; UpperBandMatrix B;
00145 B.resize(A);
00146 }
00147 CatchAll { cout << BaseException::what() << endl; }
00148 cout << "-----------------------------------------\n\n";
00149
00150 cout << "Incorrectly resizing symmetric band matrix\n";
00151 et.ReName("Block M");
00152 Try
00153 {
00154 BandMatrix A(20,5,3); A = 5; SymmetricBandMatrix B;
00155 B.ReSize(A);
00156 }
00157 CatchAll { cout << BaseException::what() << endl; }
00158 cout << "-----------------------------------------\n\n";
00159
00160 cout << "ReSize CroutMatrix\n";
00161 et.ReName("Block O");
00162 Try
00163 {
00164 Matrix A(3,3); A = 0; A(1,1) = A(2,2) = A(3,3) = 1;
00165 CroutMatrix B = A;
00166 B.resize(A);
00167 }
00168 CatchAll { cout << BaseException::what() << endl; }
00169 cout << "-----------------------------------------\n\n";
00170
00171 cout << "Manipulate CroutMatrix\n";
00172 et.ReName("Block P");
00173 Try
00174 {
00175 Matrix A(3,3); A = 0; A(1,1) = A(2,2) = A(3,3) = 1;
00176 CroutMatrix B = A;
00177 Matrix C = B;
00178 }
00179 CatchAll { cout << BaseException::what() << endl; }
00180 cout << "-----------------------------------------\n\n";
00181
00182 cout << "Manipulate BandLUMatrix\n";
00183 et.ReName("Block Q");
00184 Try
00185 {
00186 SymmetricBandMatrix A(3,1); A = 0; A(1,1) = A(2,2) = A(3,3) = 1;
00187 BandLUMatrix B = A;
00188 Matrix C = B;
00189 }
00190 CatchAll { cout << BaseException::what() << endl; }
00191 cout << "-----------------------------------------\n\n";
00192
00193
00194 }
00195 CatchAll { cout << "\nException generated in test program\n\n"; }
00196 }
00197
00198 cout << "\nEnd test\n";
00199 { Matrix A1(40,200); s2 = A1.data(); }
00200 cout << "\n(The following memory checks are probably not valid with all\n";
00201 cout << "compilers - see documentation)\n";
00202 cout << "\nChecking for lost memory (large block): "
00203 << (unsigned long)s1 << " " << (unsigned long)s2 << " ";
00204 if (s1 != s2) cout << " - see section 2.8\n"; else cout << " - ok\n";
00205 { Matrix A1(1,1); s4 = A1.data(); }
00206 cout << "\nChecking for lost memory (small block): "
00207 << (unsigned long)s3 << " " << (unsigned long)s4 << " ";
00208 if (s3 != s4) cout << " - see section 2.8\n\n"; else cout << " - ok\n\n";
00209
00210
00211 #ifdef DO_FREE_CHECK
00212 FreeCheck::Status();
00213 #endif
00214
00215
00216
00217 return 0;
00218 }
00219