1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
|
function SLIP_test
%SLIP_test: run a set of tests for SLIP_backslash
%
% Usage: SLIP_test
%
% See also SLIP_install, SLIP_backslash, SLIP_demo.
% SLIP_LU: (c) 2019-2020, Chris Lourenco, Jinhao Chen, Erick Moreno-Centeno,
% Timothy A. Davis, Texas A&M University. All Rights Reserved. See
% SLIP_LU/License for the license.
maxerr = 0 ;
rng ('default') ;
fprintf ('Testing SLIP_backslash: ') ;
% First, check if we can use a real life sparse matrix via ssget
if (exist ('ssget') ~= 0)
fprintf ('. (please wait) ') ;
% 159 is a square SPD matrix
prob = ssget(159);
A = prob.A;
[m n] = size(A);
b = rand(m, 1);
fprintf ('.') ;
x = SLIP_backslash(A,b);
x2 = A\b;
err = norm(x-x2)/norm(x);
maxerr = max (maxerr, err) ;
% now convert to an integer problem (x will not be integer)
A = floor (2^20 * A) ;
b = floor (2^20 * b) ;
fprintf ('.') ;
x = SLIP_backslash (A, b) ;
x2 = A\b;
err = norm(x-x2)/norm(x);
maxerr = max (maxerr, err) ;
fprintf ('.') ;
end
orderings = { 'none', 'colamd', 'amd' } ;
pivotings = { 'smallest', 'diagonal', 'first', ...
'tol smallest', 'tol largest', 'largest' } ;
for n = [1 10 100]
for density = [0.001 0.05 0.5 1]
% construct a well-conditioned problem to solve
A = sprand(n,n,density);
A = A+A' + n * speye (n) ;
b = rand(n,1);
for korder = 1:length (orderings)
for kpiv = 1:length (pivotings)
for tol = [0.1 0.5]
clear option
option.order = orderings {korder} ;
option.pivot = pivotings {kpiv} ;
option.tol = tol ;
fprintf ('.') ;
x = SLIP_backslash(A,b, option);
x2 = A\b;
err = norm(x-x2)/norm(x);
maxerr = max (maxerr, err) ;
% now convert to an integer problem (x will not be integer)
A = floor (2^20 * A) ;
b = floor (2^20 * b) ;
x = SLIP_backslash(A,b, option);
x2 = A\b;
err = norm(x-x2)/norm(x);
maxerr = max (maxerr, err) ;
end
end
end
end
end
fprintf ('\nmaxerr: %g\n', maxerr) ;
if (maxerr < 1e-6)
fprintf('\nTesting complete, installation successful\n')
else
error ('SLIP_backslash:test', '\nTesting failure! error too high\n')
end
|