/************************************************************************* Testing Schur decomposition subroutine *************************************************************************/ bool testschur(bool silent) { bool result; ap::real_2d_array a; int n; int maxn; int i; int j; int pass; int passcount; bool waserrors; bool errstruct; bool wfailed; double materr; double orterr; double threshold; materr = 0; orterr = 0; errstruct = false; wfailed = false; waserrors = false; maxn = 70; passcount = 1; threshold = 5*100*ap::machineepsilon; a.setbounds(0, maxn-1, 0, maxn-1); // // zero matrix, several cases // for(i = 0; i <= maxn-1; i++) { for(j = 0; j <= maxn-1; j++) { a(i,j) = 0; } } for(n = 1; n <= maxn; n++) { if( n>30&&n%2==0 ) { continue; } testschurproblem(a, n, materr, orterr, errstruct, wfailed); } // // Dense matrix // for(pass = 1; pass <= passcount; pass++) { for(n = 1; n <= maxn; n++) { if( n>30&&n%2==0 ) { continue; } for(i = 0; i <= n-1; i++) { for(j = 0; j <= n-1; j++) { a(i,j) = 2*ap::randomreal()-1; } } testschurproblem(a, n, materr, orterr, errstruct, wfailed); } } // // Sparse matrices, very sparse matrices, incredible sparse matrices // for(pass = 1; pass <= 1; pass++) { for(n = 1; n <= maxn; n++) { if( n>30&&n%3!=0 ) { continue; } fillsparsea(a, n, 0.8); testschurproblem(a, n, materr, orterr, errstruct, wfailed); fillsparsea(a, n, 0.9); testschurproblem(a, n, materr, orterr, errstruct, wfailed); fillsparsea(a, n, 0.95); testschurproblem(a, n, materr, orterr, errstruct, wfailed); fillsparsea(a, n, 0.997); testschurproblem(a, n, materr, orterr, errstruct, wfailed); } } // // report // waserrors = ap::fp_greater(materr,threshold)||ap::fp_greater(orterr,threshold)||errstruct||wfailed; if( !silent ) { printf("TESTING SCHUR DECOMPOSITION\n"); printf("Schur decomposition error: %5.3le\n", double(materr)); printf("Schur orthogonality error: %5.3le\n", double(orterr)); printf("T matrix structure: "); if( !errstruct ) { printf("OK\n"); } else { printf("FAILED\n"); } printf("Always converged: "); if( !wfailed ) { printf("OK\n"); } else { printf("FAILED\n"); } printf("Threshold: %5.3le\n", double(threshold)); if( waserrors ) { printf("TEST FAILED\n"); } else { printf("TEST PASSED\n"); } printf("\n\n"); } result = !waserrors; return result; }
/************************************************************************* Main unittest subroutine *************************************************************************/ bool testlq(bool silent) { bool result; int shortmn; int maxmn; int gpasscount; ap::real_2d_array a; int m; int n; int gpass; int i; int j; bool waserrors; decomperrors = false; othererrors = false; structerrors = false; waserrors = false; shortmn = 5; maxmn = 15; gpasscount = 5; threshold = 5*100*ap::machineepsilon; a.setbounds(0, maxmn-1, 0, maxmn-1); // // Different problems // for(gpass = 1; gpass <= gpasscount; gpass++) { // // zero matrix, several cases // for(i = 0; i <= maxmn-1; i++) { for(j = 0; j <= maxmn-1; j++) { a(i,j) = 0; } } for(i = 1; i <= maxmn; i++) { for(j = 1; j <= maxmn; j++) { testproblem(a, i, j); } } // // Long dense matrix // for(i = 0; i <= maxmn-1; i++) { for(j = 0; j <= shortmn-1; j++) { a(i,j) = 2*ap::randomreal()-1; } } for(i = shortmn+1; i <= maxmn; i++) { testproblem(a, i, shortmn); } for(i = 0; i <= shortmn-1; i++) { for(j = 0; j <= maxmn-1; j++) { a(i,j) = 2*ap::randomreal()-1; } } for(j = shortmn+1; j <= maxmn; j++) { testproblem(a, shortmn, j); } // // Dense matrices // for(m = 1; m <= maxmn; m++) { for(n = 1; n <= maxmn; n++) { for(i = 0; i <= m-1; i++) { for(j = 0; j <= n-1; j++) { a(i,j) = 2*ap::randomreal()-1; } } testproblem(a, m, n); } } // // Sparse matrices, very sparse matrices, incredible sparse matrices // for(m = 1; m <= maxmn; m++) { for(n = 1; n <= maxmn; n++) { fillsparsea(a, m, n, 0.8); testproblem(a, m, n); fillsparsea(a, m, n, 0.9); testproblem(a, m, n); fillsparsea(a, m, n, 0.95); testproblem(a, m, n); } } } // // report // waserrors = structerrors||decomperrors||othererrors; if( !silent ) { printf("TESTING RMatrixLQ\n"); printf("STRUCTURAL ERRORS: "); if( !structerrors ) { printf("OK\n"); } else { printf("FAILED\n"); } printf("DECOMPOSITION ERRORS: "); if( !decomperrors ) { printf("OK\n"); } else { printf("FAILED\n"); } printf("OTHER ERRORS: "); if( !othererrors ) { printf("OK\n"); } else { printf("FAILED\n"); } if( waserrors ) { printf("TEST FAILED\n"); } else { printf("TEST PASSED\n"); } printf("\n\n"); } result = !waserrors; return result; }
/************************************************************************* Main unittest subroutine *************************************************************************/ bool testcdet(bool silent) { bool result; int maxn; int gpasscount; double threshold; ap::complex_2d_array a; int n; int gpass; int i; int j; bool waserrors; deterrors = false; waserrors = false; maxn = 8; gpasscount = 5; threshold = 5*100*ap::machineepsilon; a.setbounds(0, maxn-1, 0, maxn-1); // // Different problems // for(gpass = 1; gpass <= gpasscount; gpass++) { // // zero matrix, several cases // for(i = 0; i <= maxn-1; i++) { for(j = 0; j <= maxn-1; j++) { a(i,j) = 0; } } for(i = 1; i <= maxn; i++) { testproblem(a, i); } // // Dense matrices // for(n = 1; n <= maxn; n++) { for(i = 0; i <= n-1; i++) { for(j = 0; j <= n-1; j++) { a(i,j).x = 2*ap::randomreal()-1; a(i,j).y = 2*ap::randomreal()-1; } } testproblem(a, n); } // // Sparse matrices, very sparse matrices, incredible sparse matrices // for(n = 1; n <= maxn; n++) { fillsparsea(a, n, n, 0.8); testproblem(a, n); fillsparsea(a, n, n, 0.9); testproblem(a, n); fillsparsea(a, n, n, 0.95); testproblem(a, n); } } // // report // waserrors = deterrors; if( !silent ) { printf("TESTING DET\n"); if( waserrors ) { printf("TEST FAILED\n"); } else { printf("TEST PASSED\n"); } printf("\n\n"); } result = !waserrors; return result; }
bool testnonsymmetricevd(bool silent) { bool result; ap::real_2d_array a; int n; int i; int j; int gpass; bool waserrors; bool wfailed; double vecerr; double valonlydiff; double threshold; vecerr = 0; valonlydiff = 0; wfailed = false; waserrors = false; threshold = 1000*ap::machineepsilon; // // First set: N = 1..10 // for(n = 1; n <= 10; n++) { a.setbounds(0, n-1, 0, n-1); // // zero matrix // for(i = 0; i <= n-1; i++) { for(j = 0; j <= n-1; j++) { a(i,j) = 0; } } testnsevdproblem(a, n, vecerr, valonlydiff, wfailed); // // Dense and sparse matrices // for(gpass = 1; gpass <= 1; gpass++) { // // Dense matrix // for(i = 0; i <= n-1; i++) { for(j = 0; j <= n-1; j++) { a(i,j) = 2*ap::randomreal()-1; } } testnsevdproblem(a, n, vecerr, valonlydiff, wfailed); // // Very matrix // fillsparsea(a, n, 0.98); testnsevdproblem(a, n, vecerr, valonlydiff, wfailed); // // Incredible sparse matrix // fillsparsea(a, n, 0.995); testnsevdproblem(a, n, vecerr, valonlydiff, wfailed); } } // // Second set: N = 70..72 // for(n = 70; n <= 72; n++) { a.setbounds(0, n-1, 0, n-1); // // zero matrix // for(i = 0; i <= n-1; i++) { for(j = 0; j <= n-1; j++) { a(i,j) = 0; } } testnsevdproblem(a, n, vecerr, valonlydiff, wfailed); // // Dense and sparse matrices // for(gpass = 1; gpass <= 1; gpass++) { // // Dense matrix // for(i = 0; i <= n-1; i++) { for(j = 0; j <= n-1; j++) { a(i,j) = 2*ap::randomreal()-1; } } testnsevdproblem(a, n, vecerr, valonlydiff, wfailed); // // Very matrix // fillsparsea(a, n, 0.98); testnsevdproblem(a, n, vecerr, valonlydiff, wfailed); // // Incredible sparse matrix // fillsparsea(a, n, 0.995); testnsevdproblem(a, n, vecerr, valonlydiff, wfailed); } } // // report // waserrors = valonlydiff>1000*threshold||vecerr>threshold||wfailed; if( !silent ) { printf("TESTING NONSYMMETTRIC EVD\n"); printf("Av-lambdav error: %5.3le\n", double(vecerr)); printf("Values only difference: %5.3le\n", double(valonlydiff)); printf("Always converged: "); if( !wfailed ) { printf("YES\n"); } else { printf("NO\n"); } printf("Threshold: %5.3le\n", double(threshold)); if( waserrors ) { printf("TEST FAILED\n"); } else { printf("TEST PASSED\n"); } printf("\n\n"); } result = !waserrors; return result; }
/************************************************************************* Main unittest subroutine *************************************************************************/ bool tesths(bool silent) { bool result; int maxn; int gpasscount; ap::real_2d_array a; int n; int gpass; int i; int j; bool waserrors; decomperrors = false; properrors = false; threshold = 5*100*ap::machineepsilon; waserrors = false; maxn = 10; gpasscount = 30; // // Different problems // for(n = 1; n <= maxn; n++) { a.setbounds(0, n-1, 0, n-1); for(gpass = 1; gpass <= gpasscount; gpass++) { // // zero matrix, several cases // for(i = 0; i <= n-1; i++) { for(j = 0; j <= n-1; j++) { a(i,j) = 0; } } testproblem(a, n); // // Dense matrices // for(i = 0; i <= n-1; i++) { for(j = 0; j <= n-1; j++) { a(i,j) = 2*ap::randomreal()-1; } } testproblem(a, n); // // Sparse matrices, very sparse matrices, incredible sparse matrices // fillsparsea(a, n, n, 0.8); testproblem(a, n); fillsparsea(a, n, n, 0.9); testproblem(a, n); fillsparsea(a, n, n, 0.95); testproblem(a, n); } } // // report // waserrors = decomperrors||properrors; if( !silent ) { printf("TESTING 2HESSENBERG\n"); printf("DECOMPOSITION ERRORS "); if( decomperrors ) { printf("FAILED\n"); } else { printf("OK\n"); } printf("MATRIX PROPERTIES "); if( properrors ) { printf("FAILED\n"); } else { printf("OK\n"); } if( waserrors ) { printf("TEST FAILED\n"); } else { printf("TEST PASSED\n"); } printf("\n\n"); } result = !waserrors; return result; }