1function test29 2%TEST29 GrB_reduce with zombies 3 4% SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2021, All Rights Reserved. 5% SPDX-License-Identifier: Apache-2.0 6 7[~, ~, add_ops, types, ~, ~] = GB_spec_opsall ; 8types = types.all ; 9 10fprintf ('\ntest29: ----------------- GrB_reduce with zombies\n') ; 11 12for m = [1 5 10] 13 for n = [1 5 10] 14 15 fprintf ('.') ; 16 rng ('default') ; 17 18 for k3 = 1:length (types) 19 atype = types {k3} ; 20 21 for builtin = 0:1 22 GB_builtin_complex_set (builtin) ; 23 24 clear C 25 C.matrix = 100 * sparse (rand (m,n)) ; 26 C.class = atype ; 27 C.pattern = logical (spones (C.matrix)) ; 28 29 for A_is_hyper = 0:1 30 for A_is_csc = 0:1 31 32 A = GB_spec_random (m,n,0.1,100,atype, A_is_csc, A_is_hyper) ; 33 34 for kk4 = 1:length(add_ops) 35 36 op = add_ops {kk4} ; 37 38 if (~builtin) 39 % no user-defined Complex_any_monoid 40 if (contains (atype, 'complex')) 41 if (isequal (op, 'any')) 42 continue ; 43 end 44 end 45 end 46 47 try 48 GB_spec_operator (op, atype) ; 49 GB_builtin_complex_set (1) ; 50 cin = GB_spec_identity (op, atype) ; 51 GB_builtin_complex_set (builtin) ; 52 catch 53 continue 54 end 55 56 if (isempty (cin)) 57 GB_builtin_complex_set (1) ; 58 cin = GB_mex_cast (0, atype) ; 59 GB_builtin_complex_set (builtin) ; 60 end 61 62 [C3,c1,c3] = GB_mex_subassign (C, [ ], [ ], A, ... 63 [ ], [ ], [ ], op) ; 64 c2 = GB_mex_reduce_to_scalar (cin, '', op, C3) ; 65 66 if (isequal (op, 'any')) 67 [i,j,x] = find (C3.matrix) ; 68 if (length (x) == 0) 69 assert (c1 == 0) ; 70 assert (c2 == 0) ; 71 else 72 assert (any (c1 == x)) ; 73 assert (any (c2 == x)) ; 74 end 75 elseif (isfloat (c1)) 76 assert (isequal (c1,c2) || ... 77 (abs (c1-c2) <= 8 * eps (c2))) ; 78 else 79 assert (isequal (c1,c2)) 80 end 81 82 if (~builtin) 83 % optype is double, which can't be used to 84 % reduce the user-defined type 'Complex' 85 if (contains (atype, 'complex')) 86 continue ; 87 end 88 end 89 90 op_plus.opname = 'plus' ; 91 op_plus.optype = 'double' ; 92 c4 = GB_mex_reduce_to_scalar (0, '', op_plus, C3) ; 93 if (isfloat (c3)) 94 assert (isequal (c3,c4) || ... 95 (abs (c3-c4) <= 8 * eps (c4))) ; 96 else 97 assert (isequal (c3,c4)) 98 end 99 100 end 101 end 102 end 103 end 104 end 105 end 106end 107 108GB_builtin_complex_set (1) ; 109 110fprintf ('\ntest29: all tests passed\n') ; 111 112