47 #include "../epetra_test_err.h"
79 int main(
int argc,
char *argv[]) {
86 if((argv[1][0] ==
'-') && (argv[1][1] ==
'v'))
88 if((argv[1][0] ==
'-') && (argv[1][1] ==
'd')) {
99 MPI_Init(&argc,&argv);
105 if (verbose && Comm.
MyPID()==0)
170 if(verbose)
printHeading(
"Testing other matrix functions");
178 if(verbose) cout <<
"calling one norm" << endl;
180 if(debug) cout <<
"m1.OneNorm() = " << onenorm << endl;
182 if(verbose) cout <<
"calling infinity norm" << endl;
184 if(debug) cout <<
"m1.InfNorm() = " << infnorm << endl;
186 if(verbose) cout <<
"calling random" << endl;
188 if(debug)
printMat(
"m2 (before)",m2);
190 if(debug)
printMat(
"m2 (after)",m2);
192 if(verbose) cout <<
"Checked OK." << endl;
201 const int m1rows = 5;
202 const int m1cols = 4;
203 const int m1arows = 4;
204 const int m1acols = 6;
205 const int m2rows = 2;
206 const int m2cols = 7;
207 const int m3rows = 8;
208 const int m3cols = 3;
209 const int m3Rrows = 5;
210 const int m3Rcols = 2;
214 if(verbose)
printHeading(
"Testing matrix constructors");
216 if(verbose) cout <<
"default constructor" << endl;
219 if(verbose) cout <<
"shaping" << endl;
220 m1.
Shape(m1rows, m1cols);
222 for(
int i = 0; i < m1rows; i++)
223 for(
int j = 0; j < m1cols; j++)
228 if(verbose) cout <<
"Checked OK." << endl;
230 if(verbose) cout <<
"\nmanually setting values" << endl;
232 for(
int i = 0; i < m1rows; i++)
233 for(
int j = 0; j < m1cols; j++)
234 m1(i,j) = m1rand[i*m1cols + j];
235 for(
int i = 0; i < m1rows; i++)
236 for(
int j = 0; j < m1cols; j++)
245 if(verbose) cout <<
"Checked OK." << endl;
248 if(verbose) cout <<
"\nshaped constructor" << endl;
257 if(verbose) cout <<
"Checked OK." << endl;
260 if(verbose) cout <<
"\nuser data constructor (view)" << endl;
262 if(debug)
printArray(m2rand, m2rows * m2cols);
272 if(verbose) cout <<
"Checked OK." << endl;
275 if(verbose) cout <<
"\nchanging value, checking for correct behavior" << endl;
276 int* m2randcopy =
new int[m2rows * m2cols];
277 for(
int i = 0; i < m2rows * m2cols; i++)
278 m2randcopy[i] = m2rand[i];
279 m2(0,4) = m2(0,4) + 1;
280 m2randcopy[4 * m2rows] = m2randcopy[4 * m2rows] + 1;
281 for(
int i = 0; i < m2rows * m2cols; i++)
291 if(verbose) cout <<
"Checked OK." << endl;
294 if(verbose) cout <<
"\nuser data constructor (copy)" << endl;
296 if(debug)
printArray(m3rand, m3rows * m3cols);
297 int* m3randcopy =
new int[m3rows * m3cols];
298 for(
int i = 0; i < m3rows * m3cols; i++)
299 m3randcopy[i] = m3rand[i];
302 if(verbose) cout <<
"checking to see if data initialized correctly" << endl;
308 for(
int i = 0; i < m3rows; i++)
309 for(
int j = 0; j < m3cols; j++)
313 if(verbose) cout <<
"Checked OK." << endl;
316 if(verbose) cout <<
"\nmodifying entry" << endl;
317 m3[1][5] = m3[1][5] + 3;
318 for(
int i = 0; i < m3rows * m3cols; i++)
320 m3rand[13] = m3rand[13] + 3;
321 for(
int i = 0; i < m3rows; i++)
322 for(
int j = 0; j < m3cols; j++)
330 if(verbose) cout <<
"Checked OK." << endl;
333 if(verbose) cout <<
"\nreshaping" << endl;
338 for(
int i = 0; i < m3Rrows; i++)
339 for(
int j = 0; j < m3Rcols; j++)
347 if(verbose) cout <<
"Checked OK." << endl;
350 if(verbose) cout <<
"\nChecking pointer on zero-sized matrix" << endl;
351 int* before = m3.
A();
352 if(verbose) cout <<
"Reshaping to (4,0)" << endl;
353 if(debug) cout <<
"Before = " << before << endl;
358 if(debug) cout <<
"After = " << after << endl;
361 if(verbose) cout <<
"Shaping to (0,3)" << endl;
362 if(debug) cout <<
"Before = " << before << endl;
367 if(debug) cout <<
"After = " << after << endl;
370 if(verbose) cout <<
"Checked OK." << endl;
379 const int m1rows = 5;
380 const int m1cols = 4;
381 const int m2rows = 2;
382 const int m2cols = 6;
386 if(verbose)
printHeading(
"Testing matrix copy constructors");
388 if(verbose) cout <<
"checking copy constructor (view)" << endl;
390 if(debug)
printArray(m1rand, m1rows * m1cols);
393 cout <<
"original matrix:" << endl;
398 cout <<
"clone matrix:" << endl;
401 if(verbose) cout <<
"making sure signatures match" << endl;
406 if(verbose) cout <<
"Checked OK." << endl;
409 if(verbose) cout <<
"\nchecking copy constructor (copy)" << endl;
411 if(debug)
printArray(m2rand, m2rows * m2cols);
414 cout <<
"original matrix:" << endl;
419 cout <<
"clone matrix:" << endl;
422 if(verbose) cout <<
"checking that signatures match" << endl;
426 if(verbose) cout <<
"Checked OK." << endl;
429 if(verbose) cout <<
"\nmodifying entry in m2, m2clone should be unchanged" << endl;
433 cout <<
"orig:" << endl;
435 cout <<
"clone:" << endl;
441 if(verbose) cout <<
"Checked OK." << endl;
455 if(verbose)
printHeading(
"Testing matrix error-reporting.\nExpect error messages if EPETRA_NO_ERROR_REPORTS is not defined.");
460 if(verbose) cout <<
"Checking Epetra_IntSerialDenseMatrix(-1, 6) - invalid rows";
467 if(verbose) cout <<
"Checked OK." << endl;
472 if(verbose) cout <<
"\nChecking Epetra_IntSerialDenseMatrix(3, -5) - invalid cols";
479 if(verbose) cout <<
"Checked OK." << endl;
487 if(verbose) cout <<
"\nChecking Epetra_IntSerialDenseMatrix(Copy, int*, -1, 2, 2) - invalid lda";
494 if(verbose) cout <<
"Checked OK." << endl;
499 if(verbose) cout <<
"\nChecking Epetra_IntSerialDenseMatrix(Copy, int*, 3, -2, 3) - invalid rows";
506 if(verbose) cout <<
"Checked OK." << endl;
511 if(verbose) cout <<
"\nChecking Epetra_IntSerialDenseMatrix(Copy, int*, 4, 4, -4) - invalid cols";
518 if(verbose) cout <<
"Checked OK." << endl;
526 if(verbose) cout <<
"\nChecking Epetra_IntSerialDenseMatrix(Copy, 0, 5, 5, 5) - null pointer";
533 if(verbose) cout <<
"Checked OK." << endl;
539 if(verbose) cout <<
"\nChecking Shape(-2, 2) - invalid rows" << endl;
540 ierr = m1.
Shape(-2, 2);
543 if(verbose) cout <<
"Checked OK." << endl;
544 if(verbose) cout <<
"\nChecking Shape(3, -2) - invalid cols" << endl;
545 ierr = m1.
Shape(3, -2);
548 if(verbose) cout <<
"Checked OK." << endl;
552 if(verbose) cout <<
"\nChecking Reshape(-4, 3) - invalid rows" << endl;
556 if(verbose) cout <<
"Checked OK." << endl;
557 if(verbose) cout <<
"\nChecking Reshape(4, -3) - invalid cols" << endl;
561 if(verbose) cout <<
"Checked OK." << endl;
563 #ifdef HAVE_EPETRA_ARRAY_BOUNDS_CHECK // only test op() and op[] exceptions if macro is defined.
571 if(verbose) cout <<
"\nChecking operator () - row index too high";
578 if(verbose) cout <<
"Checked OK." << endl;
583 if(verbose) cout <<
"\nChecking operator () - col index too high";
590 if(verbose) cout <<
"Checked OK." << endl;
597 if(verbose) cout <<
"\nChecking operator () - row index too low";
604 if(verbose) cout <<
"Checked OK." << endl;
609 if(verbose) cout <<
"\nChecking operator () - col index too low";
616 if(verbose) cout <<
"Checked OK." << endl;
623 if(verbose) cout <<
"\nChecking operator [] - col index too high";
630 if(verbose) cout <<
"Checked OK." << endl;
636 if(verbose) cout <<
"\nChecking operator [] - col index too low";
643 if(verbose) cout <<
"Checked OK." << endl;
647 #endif // end of HAVE_EPETRA_ARRAY_BOUNDS_CHECK conditional
654 if(verbose) cout <<
"\nChecking op = - assigning ISDV to ISDM";
661 if(verbose) cout <<
"Checked OK." << endl;
664 if (matrix != NULL)
delete matrix;
682 if(verbose) cout <<
"Checking copy->copy (new alloc)" << endl;
687 cout <<
"before assignment:" << endl;
693 cout <<
"after assignment:" << endl;
703 if(verbose) cout <<
"Checked OK." << endl;
709 if(verbose) cout <<
"\nChecking copy->copy (no alloc)" << endl;
714 int* origA = lhs.
A();
715 int origLDA = lhs.
LDA();
717 cout <<
"before assignment:" << endl;
723 cout <<
"after assignment:" << endl;
739 if(verbose) cout <<
"Checked OK." << endl;
745 if(verbose) cout <<
"\nChecking view->copy" << endl;
751 cout <<
"before assignment:" << endl;
757 cout <<
"after assignment:" << endl;
768 if(verbose) cout <<
"Checked OK." << endl;
774 if(verbose) cout <<
"\nChecking copy->view" << endl;
779 cout <<
"before assignment:" << endl;
785 cout <<
"after assignment:" << endl;
795 if(verbose) cout <<
"Checked OK." << endl;
801 if(verbose) cout <<
"\nChecking view->view" << endl;
807 cout <<
"before assignment:" << endl;
813 cout <<
"after assignment:" << endl;
824 if(verbose) cout <<
"Checked OK." << endl;
830 if(verbose) cout <<
"\nChecking CrsGraph's usage of MakeViewOf" << endl;
836 cout <<
"before assignment:" << endl;
842 cout <<
"after assignment:" << endl;
857 if(verbose) cout <<
"Checked OK." << endl;
871 if(verbose)
printHeading(
"Testing other vector functions");
879 if(verbose) cout <<
"calling one norm" << endl;
881 if(debug) cout <<
"v1.OneNorm() = " << onenorm << endl;
883 if(verbose) cout <<
"calling infinity norm" << endl;
885 if(debug) cout <<
"v1.InfNorm() = " << infnorm << endl;
887 if(verbose) cout <<
"calling random" << endl;
889 if(debug)
printMat(
"v2 (before)",v2);
891 if(debug)
printMat(
"v2 (after)",v2);
893 if(verbose) cout <<
"Checked OK (I think)." << endl;
901 const int v1size = 5;
902 const int v1asize = 15;
903 const int v2size = 10;
904 const int v3size = 8;
905 const int v3resize = 5;
909 if(verbose)
printHeading(
"Testing vector constructors");
911 if(verbose) cout <<
"default constructor" << endl;
914 if(verbose) cout <<
"sizing" << endl;
917 for(
int i = 0; i < v1size; i++) {
923 if(verbose) cout <<
"Checked OK." << endl;
925 if(verbose) cout <<
"\nmanually setting values" << endl;
927 for(
int i = 0; i < v1size; i++)
929 for(
int i = 0; i < v1size; i++)
938 if(verbose) cout <<
"Checked OK." << endl;
941 if(verbose) cout <<
"\nsized constructor" << endl;
948 if(verbose) cout <<
"Checked OK." << endl;
951 if(verbose) cout <<
"\nuser data constructor (view)" << endl;
961 if(verbose) cout <<
"Checked OK." << endl;
964 if(verbose) cout <<
"\nchanging value, checking for correct behavior" << endl;
965 int* v2randcopy =
new int[v2size];
966 for(
int i = 0; i < v2size; i++)
967 v2randcopy[i] = v2rand[i];
969 v2randcopy[4] = v2randcopy[4] +1;
970 for(
int i = 0; i < v2size; i++)
980 if(verbose) cout <<
"Checked OK." << endl;
983 if(verbose) cout <<
"\nuser data constructor (copy)" << endl;
986 int* v3randcopy =
new int[v3size];
987 for(
int i = 0; i < v3size; i++)
988 v3randcopy[i] = v3rand[i];
991 if(verbose) cout <<
"checking to see if data initialized correctly" << endl;
995 for(
int i = 0; i < v3size; i++)
999 if(verbose) cout <<
"Checked OK." << endl;
1002 if(verbose) cout <<
"\nmodifying entry" << endl;
1004 for(
int i = 0; i < v3size; i++)
1006 v3rand[5] = v3rand[5] + 3;
1007 for(
int i = 0; i < v3size; i++)
1015 if(verbose) cout <<
"Checked OK." << endl;
1018 if(verbose) cout <<
"\nresizing" << endl;
1021 for(
int i = 0; i < v3resize; i++)
1025 delete[] v3randcopy;
1028 if(verbose) cout <<
"Checked OK." << endl;
1031 if(verbose) cout <<
"\nChecking pointer on zero-sized vector" << endl;
1032 int* before = v3.
Values();
1033 if(verbose) cout <<
"Resizing to 0" << endl;
1034 if(debug) cout <<
"Before = " << before << endl;
1037 int* after = v3.
Values();
1039 if(debug) cout <<
"After = " << after << endl;
1042 if(verbose) cout <<
"Sizing to 0" << endl;
1043 if(debug) cout <<
"Before = " << before << endl;
1048 if(debug) cout <<
"After = " << after << endl;
1051 if(verbose) cout <<
"Checked OK." << endl;
1059 const int v1size = 15;
1060 const int v2size = 12;
1064 if(verbose)
printHeading(
"Testing vector copy constructors");
1066 if(verbose) cout <<
"checking copy constructor (view)" << endl;
1071 cout <<
"original vector:" << endl;
1076 cout <<
"clone vector:" << endl;
1079 if(verbose) cout <<
"making sure signatures match" << endl;
1084 if(verbose) cout <<
"Checked OK." << endl;
1087 if(verbose) cout <<
"\nchecking copy constructor (copy)" << endl;
1092 cout <<
"original vector:" << endl;
1097 cout <<
"clone vector:" << endl;
1100 if(verbose) cout <<
"checking that signatures match" << endl;
1104 if(verbose) cout <<
"Checked OK." << endl;
1107 if(verbose) cout <<
"\nmodifying entry in v2, v2clone should be unchanged" << endl;
1111 cout <<
"orig:" << endl;
1113 cout <<
"clone:" << endl;
1119 if(verbose) cout <<
"Checked OK." << endl;
1138 if(verbose) cout <<
"Checking copy->copy (new alloc)" << endl;
1143 cout <<
"before assignment:" << endl;
1149 cout <<
"after assignment:" << endl;
1159 if(verbose) cout <<
"Checked OK." << endl;
1165 if(verbose) cout <<
"\nChecking copy->copy (no alloc)" << endl;
1170 int* origA = lhs.
A();
1171 int origLDA = lhs.
LDA();
1173 cout <<
"before assignment:" << endl;
1179 cout <<
"after assignment:" << endl;
1195 if(verbose) cout <<
"Checked OK." << endl;
1201 if(verbose) cout <<
"\nChecking view->copy" << endl;
1207 cout <<
"before assignment:" << endl;
1213 cout <<
"after assignment:" << endl;
1224 if(verbose) cout <<
"Checked OK." << endl;
1230 if(verbose) cout <<
"\nChecking copy->view" << endl;
1235 cout <<
"before assignment:" << endl;
1241 cout <<
"after assignment:" << endl;
1251 if(verbose) cout <<
"Checked OK." << endl;
1257 if(verbose) cout <<
"\nChecking view->view" << endl;
1263 cout <<
"before assignment:" << endl;
1269 cout <<
"after assignment:" << endl;
1280 if(verbose) cout <<
"Checked OK." << endl;
1286 if(verbose) cout <<
"\nChecking CrsGraph's usage of MakeViewOf" << endl;
1292 cout <<
"before assignment:" << endl;
1298 cout <<
"after assignment:" << endl;
1313 if(verbose) cout <<
"Checked OK." << endl;
1324 bool caught =
false;
1328 if(verbose)
printHeading(
"Testing vector error-reporting.\nExpect error messages if EPETRA_NO_ERROR_REPORTS is not defined.");
1332 if(verbose) cout <<
"Checking Epetra_IntSerialDenseVector(-1)";
1339 if(verbose) cout <<
"Checked OK." << endl;
1346 if(verbose) cout <<
"\nChecking Epetra_IntSerialDenseVector(Copy, int*, -3)";
1353 if(verbose) cout <<
"Checked OK." << endl;
1360 if(verbose) cout <<
"\nChecking Epetra_IntSerialDenseVector(Copy, 0, 5)";
1367 if(verbose) cout <<
"Checked OK." << endl;
1372 if(verbose) cout <<
"\nChecking Size(-2)" << endl;
1377 if(verbose) cout <<
"Checked OK." << endl;
1380 if(verbose) cout <<
"\nChecking Resize(-4)" << endl;
1385 if(verbose) cout <<
"Checked OK." << endl;
1387 #ifdef HAVE_EPETRA_ARRAY_BOUNDS_CHECK // only test op() and op[] exceptions if macro is defined.
1393 if(verbose) cout <<
"\nChecking operator () - index too high";
1400 if(verbose) cout <<
"Checked OK." << endl;
1406 if(verbose) cout <<
"\nChecking operator () - index too low";
1413 if(verbose) cout <<
"Checked OK." << endl;
1419 if(verbose) cout <<
"\nChecking operator [] - index too high";
1426 if(verbose) cout <<
"Checked OK." << endl;
1432 if(verbose) cout <<
"\nChecking operator [] - index too low";
1439 if(verbose) cout <<
"Checked OK." << endl;
1443 #endif // end of HAVE_EPETRA_ARRAY_BOUNDS_CHECK conditional
1446 if (vector != NULL)
delete vector;
1463 if((a.
M() != b.
M() )||
1465 (a.
CV() != b.
CV() ))
1477 const int m = a.
M();
1478 const int n = a.
N();
1479 for(
int i = 0; i < m; i++)
1480 for(
int j = 0; j <
n; j++) {
1481 if(a(i,j) != b(i,j))
1496 int orig_a = a(r,c);
1497 int new_value = a(r,c) + 1;
1498 if(b(r,c) == new_value)
1502 if(b(r,c) == new_value)
1514 int* array =
new int[length];
1515 for(
int i = 0; i < length; i++)
1524 const int maxint = 100;
1526 const double a = 16807.0;
1527 const double BigInt = 2147483647.0;
1528 double seed = rand();
1530 seed = fmod(a * seed, BigInt);
1532 double randdouble = (seed / BigInt);
1533 int randint = int(randdouble * maxint);
1540 cout <<
"user array (size " << length <<
"): ";
1541 for(
int i = 0; i < length; i++)
1542 cout << array[i] <<
" ";
1549 cout <<
"*** " << name <<
" ***" << endl;
1557 cout <<
"\n==================================================================\n";
1558 cout << heading << endl;
1559 cout <<
"==================================================================\n";