1function test162
2%TEST162 test C<M>=A*B with very sparse M
3
4% SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2021, All Rights Reserved.
5% SPDX-License-Identifier: Apache-2.0
6
7semiring.add = 'plus' ;
8semiring.multiply = 'times' ;
9semiring.class = 'double' ;
10
11rng ('default') ;
12
13d = 0.02 ;
14n = 1000 ;
15A = sprand (n, n, d) ;
16A (1:257,1) = rand (257, 1) ;
17B = sprand (n, n, d) ;
18B (1,1) = 1 ;
19M = logical (sprand (n, n, 0.002)) ;
20Cin = sparse (n, n) ;
21
22C1 = double (M) .* (A*B) ;
23C2 = GB_mex_mxm (Cin, M, [ ], semiring, A, B, [ ]) ;
24GB_spec_compare (C1, C2) ;
25
26clear A B M
27n = 80 ;
28A.matrix = sparse (rand (n)) ; A.sparsity = 4 ;    % A is bitmap
29B.matrix = sparse (rand (n)) ; B.sparsity = 4 ;    % B is bitmap
30M.matrix = logical (sprand (n, n, 0.5)) ; M.sparsity = 2 ;  % M is sparse
31desc.mask = 'complement' ;
32
33Cin = sparse (n, n) ;
34C1 = double (~(M.matrix)) .* (A.matrix*B.matrix) ;
35C2 = GB_mex_mxm  (Cin, M, [ ], semiring, A, B, desc) ;
36GB_spec_compare (C1, C2) ;
37
38M.sparsity = 4 ; % make M bitmap
39M.matrix (1:64, 1:64) = 0 ; % clear the leading 64-by-64 tile
40C1 = double (M.matrix) .* (A.matrix*B.matrix) ;
41C2 = GB_mex_mxm  (Cin, M, [ ], semiring, A, B, [ ]) ;
42GB_spec_compare (C1, C2) ;
43
44fprintf ('test162: all tests passed\n') ;
45
46