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 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
|
function test186 (dohack)
%TEST186 test saxpy for all sparsity formats
% SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2022, All Rights Reserved.
% SPDX-License-Identifier: Apache-2.0
fprintf ('test186 --------------- C<!M>A*B for all sparsity formats\n') ;
rng ('default') ;
% save current global settings, then modify them
save = GB_mex_hack ;
hack = save ;
if (nargin < 1)
dohack = 2 ;
end
hack (1) = dohack ; % modify "very_costly" in GxB_AxB_saxpy3_slice_balanced
GB_mex_hack (hack) ;
load west0479 ;
A.matrix = west0479 ;
A.class = 'double' ;
A.pattern = logical (spones (A.matrix)) ;
m = size (A.matrix, 1) ;
semiring.add = 'plus' ;
semiring.multiply = 'times' ;
semiring.class = 'double' ;
any_pair.add = 'any' ;
any_pair.multiply = 'pair' ; % same as oneb
any_pair.class = 'double' ;
C0 = sparse (m, 1) ;
maxerr = 0 ;
M = sparse (rand (m, 1) > 0.5) ;
desc.mask = 'complement' ;
B = GB_spec_random (m, 1, 0.5, 1, 'double') ;
B2 = B ;
B2.class = 'single' ;
% using fine atomic tasks when A is sparse and B is bitmap
for A_sparsity = [1 2 4 8]
for B_sparsity = [1 2 4 8]
A.sparsity = A_sparsity ;
B.sparsity = B_sparsity ;
B2.sparsity = B_sparsity ;
% C2<!M> = A*B using the conventional semiring
C3 = double (~M) .* (A.matrix * B.matrix) ;
C2 = GB_mex_mxm (C0, M, [ ], semiring, A, B, desc) ;
err = norm (C3 - C2.matrix, 1) / norm (C3, 1) ;
maxerr = max (maxerr, err) ;
assert (err < 1e-12) ;
% C2<!M> = A*single(B) to force typecasting
C1 = GB_mex_mxm (C0, M, [ ], semiring, A, B2, desc) ;
err = norm (C3 - C1.matrix, 1) / norm (C3, 1) ;
maxerr = max (maxerr, err) ;
assert (err < 1e-6) ;
% C2<!M> = A*B using the any-pair semiring
C3 = spones (C3) ;
C2 = GB_mex_mxm (C0, M, [ ], any_pair, A, B, desc) ;
err = norm (C3 - C2.matrix, 1) / norm (C3, 1) ;
maxerr = max (maxerr, err) ;
assert (err < 1e-12) ;
end
end
B3 = GB_spec_random (m, 3, 0.5, 1, 'double') ;
M3 = sparse (rand (m, 3) > 0.5) ;
C03 = sparse (m, 3) ;
% using fine non-atomic tasks when A is sparse and B is bitmap
A.matrix = sprand (m, m, 0.8) ;
A.pattern = logical (spones (A.matrix)) ;
for A_sparsity = [1 2 4 8]
for B_sparsity = [1 2 4 8]
A.sparsity = A_sparsity ;
B.sparsity = B_sparsity ;
B3.sparsity = B_sparsity ;
fprintf ('.') ;
% C2<!M> = A*B using the conventional semiring
C3 = double (~M) .* (A.matrix * B.matrix) ;
C2 = GB_mex_mxm (C0, M, [ ], semiring, A, B, desc) ;
err = norm (C3 - C2.matrix, 1) / norm (C3, 1) ;
maxerr = max (maxerr, err) ;
assert (err < 1e-12) ;
% C2<!M> = A*B using the any-pair semiring
C3 = spones (C3) ;
C2 = GB_mex_mxm (C0, M, [ ], any_pair, A, B, desc) ;
err = norm (C3 - C2.matrix, 1) / norm (C3, 1) ;
maxerr = max (maxerr, err) ;
assert (err < 1e-12) ;
% C2<!M3> = A*B3 using the conventional semiring
C3 = double (~M3) .* (A.matrix * B3.matrix) ;
C2 = GB_mex_mxm (C03, M3, [ ], semiring, A, B3, desc) ;
err = norm (C3 - C2.matrix, 1) / norm (C3, 1) ;
maxerr = max (maxerr, err) ;
assert (err < 1e-12) ;
end
end
% restore global settings
GrB.burble (0) ;
GB_mex_hack (save) ;
fprintf ('\n') ;
fprintf ('maxerr: %g\n', maxerr) ;
fprintf ('test186: all tests passed\n') ;
|