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
|
function test185
%TEST185 test dot4 for all sparsity formats
% GB_AxB_dot4 computes C+=A'*B when C is dense.
% SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2022, All Rights Reserved.
% SPDX-License-Identifier: Apache-2.0
fprintf ('test185 -------------------- C+=A''*B when C is dense\n') ;
rng ('default') ;
GrB.burble (0) ;
semiring.add = 'plus' ;
semiring.multiply = 'times' ;
semiring.class = 'double' ;
plus_pair.add = 'plus' ;
plus_pair.multiply = 'oneb' ; % same as pair
plus_pair.class = 'double' ;
add_op = 'plus' ;
dtn_dot = struct ('axb', 'dot', 'inp0', 'tran') ;
dtn_sax = struct ('axb', 'saxpy', 'inp0', 'tran') ;
n = 20 ;
C = GB_spec_random (n, n, inf, 1, 'double') ;
C0 = sparse (n, n) ;
maxerr = 0 ;
M = sparse (rand (n, n) > 0.5) ;
for da = [0.01 0.1 .5 0.9 inf]
A = GB_spec_random (n, n, da, 1, 'double') ;
for db = [0.01 0.1 .5 0.9 inf]
B = GB_spec_random (n, n, db, 1, 'double') ;
for A_sparsity = [1 2 4 8]
fprintf ('.') ;
for B_sparsity = [1 2 4 8]
A.sparsity = A_sparsity ;
B.sparsity = B_sparsity ;
% C2 = C + A'*B using dot4
C2 = GB_mex_mxm (C, [ ], add_op, semiring, A, B, dtn_dot) ;
C1 = GB_spec_mxm (C, [ ], add_op, semiring, A, B, dtn_dot) ;
GB_spec_compare (C1, C2) ;
C3 = C.matrix + (A.matrix)'*B.matrix ;
err = norm (C3 - C2.matrix, 1) ;
maxerr = max (maxerr, err) ;
assert (err < 1e-12) ;
% C2 = A'*B using dot2/dot3
C2 = GB_mex_mxm (C0, [ ], [ ], semiring, A, B, dtn_dot) ;
C1 = GB_spec_mxm (C0, [ ], [ ], semiring, A, B, dtn_dot) ;
GB_spec_compare (C1, C2) ;
C3 = (A.matrix)'*B.matrix ;
err = norm (C3 - C2.matrix, 1) ;
maxerr = max (maxerr, err) ;
assert (err < 1e-12) ;
% C2 = C + A'*B using saxpy
C2 = GB_mex_mxm (C, [ ], add_op, semiring, A, B, dtn_sax) ;
C1 = GB_spec_mxm (C, [ ], add_op, semiring, A, B, dtn_sax) ;
GB_spec_compare (C1, C2) ;
C3 = C.matrix + (A.matrix)'*B.matrix ;
err = norm (C3 - C2.matrix, 1) ;
maxerr = max (maxerr, err) ;
assert (err < 1e-12) ;
% C2 = C + spones(A)'*spones(B) using dot4
C2 = GB_mex_mxm (C, [ ], add_op, plus_pair, A, B, dtn_dot) ;
C1 = GB_spec_mxm (C, [ ], add_op, plus_pair, A, B, dtn_dot) ;
GB_spec_compare (C1, C2) ;
C3 = C.matrix + spones (A.matrix)' * spones (B.matrix) ;
err = norm (C3 - C2.matrix, 1) ;
maxerr = max (maxerr, err) ;
assert (err < 1e-12) ;
% C2 = spones(A)'*spones(B) using dot2/dot3
C2 = GB_mex_mxm (C0, [ ], [ ], plus_pair, A, B, dtn_dot) ;
C1 = GB_spec_mxm (C0, [ ], [ ], plus_pair, A, B, dtn_dot) ;
GB_spec_compare (C1, C2) ;
C3 = spones (A.matrix)' * spones (B.matrix) ;
err = norm (C3 - C2.matrix, 1) ;
maxerr = max (maxerr, err) ;
assert (err < 1e-12) ;
end
end
end
end
fprintf ('\n') ;
GrB.burble (0) ;
fprintf ('maxerr: %g\n', maxerr) ;
fprintf ('test185: all tests passed\n') ;
|