1function test143 2%TEST143 test special cases for C<!M>=A*B and C<M>=A*B 3 4% SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2021, All Rights Reserved. 5% SPDX-License-Identifier: Apache-2.0 6 7fprintf ('test143 ----------------------------- A*B special cases\n') ; 8 9rng ('default') ; 10 11n = 3000 ; 12d = 0.001 ; 13A = sprand (n, n, d) ; 14 15semiring.add = 'plus' ; 16semiring.multiply = 'times' ; 17semiring.class = 'double' ; 18 19% coarse Gustavson tasks, C<!M>=A*B, C(:,j) very sparse compared to M(:,j) 20S = sparse (n, n) ; 21M = logical (sprand (n, n, 0.01)) ; 22M (:,1) = 1 ; 23B = sprand (n, n, d) ; 24C2 = GB_mex_mxm (S, M, [ ], semiring, A, B, struct ('mask', 'complement')) ; 25C = (A*B) .* double (~M) ; 26assert (nnz (C) > 0) ; 27err = norm (C - C2.matrix, 1) ; 28assert (err < 1e-12) ; 29fprintf ('.') ; 30 31%---------------------------------------- 32desc = struct ('axb', 'hash', 'mask', 'complement') ; 33%---------------------------------------- 34 35% coarse hash tasks, C<!M>=A*B 36S = sparse (n, n) ; 37M = logical (sprand (n, n, 0.01)) ; 38B = sprand (n, n, d) ; 39C2 = GB_mex_mxm (S, M, [ ], semiring, A, B, desc) ; 40C = (A*B) .* double (~M) ; 41assert (nnz (C) > 0) ; 42err = norm (C - C2.matrix, 1) ; 43assert (err < 1e-12) ; 44fprintf ('.') ; 45 46% fine hash tasks, C<!M>=A*B 47S = sparse (n, 1) ; 48M = logical (sprand (n, 1, 0.01)) ; 49B = sprand (n, 1, d) ; 50C2 = GB_mex_mxm (S, M, [ ], semiring, A, B, desc) ; 51C = (A*B) .* double (~M) ; 52assert (nnz (C) > 0) ; 53err = norm (C - C2.matrix, 1) ; 54assert (err < 1e-12) ; 55fprintf ('.') ; 56 57%---------------------------------------- 58desc = struct ('axb', 'hash') ; 59%---------------------------------------- 60 61% coarse hash tasks, C<M>=A*B 62S = sparse (n, n) ; 63M = logical (sprand (n, n, 0.01)) ; 64B = sprand (n, n, d) ; 65C2 = GB_mex_mxm (S, M, [ ], semiring, A, B, desc) ; 66C = (A*B) .* double (M) ; 67assert (nnz (C) > 0) ; 68err = norm (C - C2.matrix, 1) ; 69assert (err < 1e-12) ; 70fprintf ('.') ; 71 72% fine hash tasks, C<M>=A*B 73S = sparse (n, 1) ; 74M = logical (sprand (n, 1, 0.01)) ; 75B = sprand (n, 1, d) ; 76M (1:3) = 1 ; 77A (1:3,1:3) = rand (3) ; 78B (1:3) = rand (3,1) ; 79C = (A*B) .* double (M) ; 80assert (nnz (C) > 0) ; 81C2 = GB_mex_mxm (S, M, [ ], semiring, A, B, desc) ; 82err = norm (C - C2.matrix, 1) ; 83assert (err < 1e-12) ; 84fprintf ('.') ; 85 86%---------------------------------------- 87fprintf (' please wait: ') ; 88m = 10e6 ; 89A = sprand (m, n, d) ; 90[save save_chunk] = nthreads_get ; 91nthreads_set (4, 1) ; 92%---------------------------------------- 93fprintf (':') ; 94 95% fine hash tasks, C=A*B 96S = sparse (m, 1) ; 97B = sprand (n, 1, d) ; 98B (1:100, 1) = rand (100, 1) ; 99fprintf (':') ; 100C = (A*B) ; 101assert (nnz (C) > 0) ; 102fprintf (':') ; 103C2 = GB_mex_mxm (S, [ ], [ ], semiring, A, B, desc) ; 104err = norm (C - C2.matrix, 1) ; 105assert (err < 1e-12) ; 106fprintf ('.') ; 107 108nthreads_set (save, save_chunk) ; 109fprintf ('\ntest143: all tests passed\n') ; 110 111