1function test04 2%TEST04 test and demo for accumulator/mask and transpose 3 4% SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2021, All Rights Reserved. 5% SPDX-License-Identifier: Apache-2.0 6 7fprintf ('\n-------------------- simple mask and transpose tests\n') ; 8 9rng ('default') ; 10C = rand (4) 11Z = magic (4) 12Mask = mod (Z,2) == 0 13 14for C_replace = [false true] 15 for Mask_comp = [false true] 16 fprintf ('Use Mask. C_replace: %d Mask_comp: %d\n', ... 17 C_replace, Mask_comp) ; 18 Cresult = GB_spec_mask (C, Mask, Z, C_replace, Mask_comp) ; 19 % C2 = apply_mask_sparse (C, Z, Mask, C_replace, Mask_comp) ; 20 % assert (isequal (Cresult, C2)) 21 22 D = [ ] ; 23 if (Mask_comp) 24 D.mask = 'complement' ; 25 end 26 if (C_replace) 27 D.outp = 'replace' ; 28 end 29 30 A = Z ; 31 fprintf ('C3 <Mask> = C + A'' :\n') ; 32 C3 = GB_spec_transpose (C, Mask, 'plus', A, D) ; 33 C5 = GB_mex_transpose (sparse(C), sparse(Mask), 'plus', sparse(A), D); 34 assert (isequal (C3.matrix, C5.matrix)) 35 36 end 37end 38 39for C_replace = [false true] 40 for Mask_comp = [false true] 41 fprintf ('No Mask. C_replace: %d Mask_comp: %d\n', ... 42 C_replace, Mask_comp) ; 43 Cresult = GB_spec_mask (C, [ ], Z, C_replace, Mask_comp) ; 44 % C2 = apply_mask_sparse (C, Z, [ ], C_replace, Mask_comp) ; 45 % assert (isequal (Cresult, C2)) 46 47 D = [ ] ; 48 if (Mask_comp) 49 D.mask = 'complement' ; 50 end 51 if (C_replace) 52 D.outp = 'replace' ; 53 end 54 55 A = Z ; 56 fprintf ('C3 <no mask complement:%d replace:%d> = C + A'' :\n', ... 57 Mask_comp, C_replace) ; 58D 59 C3 = GB_spec_transpose (C, [ ], 'plus', A, D) ; 60 C5 = GB_mex_transpose (sparse(C), [ ], 'plus', sparse(A), D); 61 assert (isequal (C3.matrix, C5.matrix)) 62 end 63end 64 65fprintf ('\ntest04: all tests passed\n') ; 66 67