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
|
function test143
%TEST143 test special cases for C<!M>=A*B and C<M>=A*B
% SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2022, All Rights Reserved.
% SPDX-License-Identifier: Apache-2.0
fprintf ('test143 ----------------------------- A*B special cases\n') ;
rng ('default') ;
n = 3000 ;
d = 0.001 ;
A = sprand (n, n, d) ;
semiring.add = 'plus' ;
semiring.multiply = 'times' ;
semiring.class = 'double' ;
% coarse Gustavson tasks, C<!M>=A*B, C(:,j) very sparse compared to M(:,j)
S = sparse (n, n) ;
M = logical (sprand (n, n, 0.01)) ;
M (:,1) = 1 ;
B = sprand (n, n, d) ;
C2 = GB_mex_mxm (S, M, [ ], semiring, A, B, struct ('mask', 'complement')) ;
C = (A*B) .* double (~M) ;
assert (nnz (C) > 0) ;
err = norm (C - C2.matrix, 1) ;
assert (err < 1e-12) ;
fprintf ('.') ;
%----------------------------------------
desc = struct ('axb', 'hash', 'mask', 'complement') ;
%----------------------------------------
% coarse hash tasks, C<!M>=A*B
S = sparse (n, n) ;
M = logical (sprand (n, n, 0.01)) ;
B = sprand (n, n, d) ;
C2 = GB_mex_mxm (S, M, [ ], semiring, A, B, desc) ;
C = (A*B) .* double (~M) ;
assert (nnz (C) > 0) ;
err = norm (C - C2.matrix, 1) ;
assert (err < 1e-12) ;
fprintf ('.') ;
% fine hash tasks, C<!M>=A*B
S = sparse (n, 1) ;
M = logical (sprand (n, 1, 0.01)) ;
B = sprand (n, 1, d) ;
C2 = GB_mex_mxm (S, M, [ ], semiring, A, B, desc) ;
C = (A*B) .* double (~M) ;
assert (nnz (C) > 0) ;
err = norm (C - C2.matrix, 1) ;
assert (err < 1e-12) ;
fprintf ('.') ;
%----------------------------------------
desc = struct ('axb', 'hash') ;
%----------------------------------------
% coarse hash tasks, C<M>=A*B
S = sparse (n, n) ;
M = logical (sprand (n, n, 0.01)) ;
B = sprand (n, n, d) ;
C2 = GB_mex_mxm (S, M, [ ], semiring, A, B, desc) ;
C = (A*B) .* double (M) ;
assert (nnz (C) > 0) ;
err = norm (C - C2.matrix, 1) ;
assert (err < 1e-12) ;
fprintf ('.') ;
% fine hash tasks, C<M>=A*B
S = sparse (n, 1) ;
M = logical (sprand (n, 1, 0.01)) ;
B = sprand (n, 1, d) ;
M (1:3) = 1 ;
A (1:3,1:3) = rand (3) ;
B (1:3) = rand (3,1) ;
C = (A*B) .* double (M) ;
assert (nnz (C) > 0) ;
C2 = GB_mex_mxm (S, M, [ ], semiring, A, B, desc) ;
err = norm (C - C2.matrix, 1) ;
assert (err < 1e-12) ;
fprintf ('.') ;
%----------------------------------------
fprintf (' please wait: ') ;
m = 10e6 ;
A = sprand (m, n, d) ;
[save save_chunk] = nthreads_get ;
nthreads_set (4, 1) ;
%----------------------------------------
fprintf (':') ;
% fine hash tasks, C=A*B
S = sparse (m, 1) ;
B = sprand (n, 1, d) ;
B (1:100, 1) = rand (100, 1) ;
fprintf (':') ;
C = (A*B) ;
assert (nnz (C) > 0) ;
fprintf (':') ;
C2 = GB_mex_mxm (S, [ ], [ ], semiring, A, B, desc) ;
err = norm (C - C2.matrix, 1) ;
assert (err < 1e-12) ;
fprintf ('.') ;
nthreads_set (save, save_chunk) ;
fprintf ('\ntest143: all tests passed\n') ;
|