From afb044c23ed7304ddeefd842531941ea64646b8e Mon Sep 17 00:00:00 2001 From: NormannR Date: Tue, 4 Oct 2022 22:37:40 +0200 Subject: [PATCH] Fix cycle reduction: (i) making the norms consistent between cycle_reduction and its test; (ii) remove hard errors in cycle_reduction Fortran and Matlab routines --- matlab/missing/mex/cycle_reduction/cycle_reduction.m | 2 +- mex/sources/cycle_reduction/mexFunction.f08 | 2 +- tests/cyclereduction.m | 10 +++++----- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/matlab/missing/mex/cycle_reduction/cycle_reduction.m b/matlab/missing/mex/cycle_reduction/cycle_reduction.m index 18ba3637f..8f33c04c4 100644 --- a/matlab/missing/mex/cycle_reduction/cycle_reduction.m +++ b/matlab/missing/mex/cycle_reduction/cycle_reduction.m @@ -108,7 +108,7 @@ if (nargin == 5 && ~isempty(ch) ) if (res > cvg_tol) info(1) = 403 info(2) = log(res) - error(['The norm of the residual is ' num2str(res) ' whereas the tolerance criterion is ' num2str(cvg_tol)]); + dprintf('The norm of the residual is %s whereas the tolerance criterion is %s', num2str(res), num2str(cvg_tol)); end end diff --git a/mex/sources/cycle_reduction/mexFunction.f08 b/mex/sources/cycle_reduction/mexFunction.f08 index 1f9238fdd..cf39944f1 100644 --- a/mex/sources/cycle_reduction/mexFunction.f08 +++ b/mex/sources/cycle_reduction/mexFunction.f08 @@ -99,7 +99,7 @@ loop: do info(2) = log(residual) write (cvg_tol_str,"(es8.2)") cvg_tol write (residual_str,"(es8.2)") residual - call mexErrMsgTxt("The norm of the residual is "& + call mexPrintf("The norm of the residual is "& &// trim(residual_str) // & &", whereas the tolerance criterion is " & // trim(cvg_tol_str) // "." ) diff --git a/tests/cyclereduction.m b/tests/cyclereduction.m index 211e591cc..c8c09db68 100644 --- a/tests/cyclereduction.m +++ b/tests/cyclereduction.m @@ -54,8 +54,8 @@ tElapsed1 = 0.; try tic; [X1,info] = cycle_reduction_matlab(C,B,A,cvg_tol,[0.]); tElapsed1 = toc; disp(['Elapsed time for the Matlab cycle reduction algorithm is: ' num2str(tElapsed1) ' (n=' int2str(n) ').']) - R = C+B*X1+A*X1*X1; - if (max(abs(R(:))) > cvg_tol) + R = norm(C+B*X1+A*X1*X1,1); + if (R > cvg_tol) testFailed = testFailed+1; if debug dprintf('Matlab cycle_reduction solution is wrong') @@ -74,8 +74,8 @@ tElapsed2 = 0.; try tic; [X2,info] = cycle_reduction(C,B,A,cvg_tol,[0.]); tElapsed2 = toc; disp(['Elapsed time for the Fortran cycle reduction algorithm is: ' num2str(tElapsed2) ' (n=' int2str(n) ').']) - R = C+B*X2+A*X2*X2; - if (max(abs(R(:))) > cvg_tol) + R = norm(C+B*X2+A*X2*X2,1); + if (R > cvg_tol) testFailed = testFailed+1; if debug dprintf('Fortran cycle_reduction solution is wrong') @@ -90,7 +90,7 @@ end % 3. Compare solutions of the Fortran and Matlab routines NumberOfTests = NumberOfTests+1; -if (max(abs(X1(:) - X2(:))) > cvg_tol) +if (norm(X1 - X2, 1) > cvg_tol) testFailed = testFailed+1; if debug dprintf('Fortran and Matlab cycle reduction solutions differ');