1function test62 2%TEST62 test GrB_apply 3 4% SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2021, All Rights Reserved. 5% SPDX-License-Identifier: Apache-2.0 6 7fprintf ('\n ------------ testing GrB_apply\n') ; 8 9rng ('default') 10 11[binops, unary_ops, ~, types, ~, ~] = GB_spec_opsall ; 12ops = unary_ops.all ; 13accum_ops = binops.all ; 14types = types.all ; 15 16dt = struct ('inp0', 'tran') ; 17 18% type of the matrix C 19for k1 = 1:length (types) 20 ctype = types {k1} ; 21 fprintf ('\n%s', ctype) ; 22 23 % type of the matrix A 24 for k2 = 1:length (types) 25 atype = types {k2} ; 26 27 % create a matrix 28 for m = [1 10 25] 29 for n = [1 10 25] 30 fprintf ('.') ; 31 clear A 32 A.matrix = sprandn (m, n, 0.1) ; 33 A.class = atype ; 34 35 Mask = (sprandn (m, n, 0.1) ~= 0) ; 36 MaskT = Mask' ; 37 38 clear B 39 B.matrix = sprandn (m*n, 1, 0.1) ; 40 B.class = atype ; 41 42 mask = (sprandn (m*n, 1, 0.1) ~= 0) ; 43 44 clear Cin 45 Cin.matrix = sprandn (m, n, 0.1) ; 46 Cin.class = ctype ; 47 48 clear CinT 49 CinT.matrix = Cin.matrix' ; 50 CinT.class = ctype ; 51 52 clear Cin2 53 Cin2.matrix = sprandn (m*n, 1, 0.1) ; 54 Cin2.class = ctype ; 55 56 % unary operator 57 for k3 = 1:length(ops) 58 unary_op = ops {k3} ; 59 ntypes = 1;length (types) ; 60 % fprintf ('unary: %s\n', unary_op) ; 61 % unary operator type 62 for k4 = ntypes 63 clear unary 64 if (~isempty (unary_op)) 65 unary_type = types {k4} ; 66 unary.opname = unary_op ; 67 unary.optype = unary_type ; 68 else 69 unary = '' ; 70 unary_type = '' ; 71 end 72 73 try 74 GB_spec_operator (unary_op) ; 75 catch 76 continue 77 end 78 79 % accum operator 80 for k5 = 0:length(accum_ops) 81 if (k5 == 0) 82 accum_op = '' ; 83 ntypes = 1 ; 84 else 85 accum_op = accum_ops {k5} ; 86 ntypes = 1;length (types) ; 87 end 88 % accum operator type 89 for k6 = ntypes 90 clear accum 91 if (~isempty (accum_op)) 92 accum_type = types {k6} ; 93 accum.opname = accum_op ; 94 accum.optype = accum_type ; 95 else 96 accum = '' ; 97 accum_type = '' ; 98 end 99 100 if (GB_spec_is_positional (accum)) 101 continue ; 102 end 103 104 try 105 GB_spec_operator (accum) ; 106 catch 107 continue 108 end 109 110 % apply to A, no mask 111 C1 = GB_mex_apply (Cin, [ ], accum, unary, A, [ ]) ; 112 C2 = GB_spec_apply (Cin, [ ], accum, unary, A, [ ]) ; 113 GB_spec_compare (C1, C2) ; 114 115 % apply to A', no mask 116 C2 = GB_spec_apply (CinT, [ ], accum, unary, A, dt) ; 117 C1 = GB_mex_apply (CinT, [ ], accum, unary, A, dt) ; 118 GB_spec_compare (C1, C2) ; 119 120 % apply to vector B, no mask 121 C1 = GB_mex_apply (Cin2, [ ], accum, unary, B, [ ]) ; 122 C2 = GB_spec_apply (Cin2, [ ], accum, unary, B, [ ]) ; 123 GB_spec_compare (C1, C2) ; 124 125 % apply to A, with mask 126 C1 = GB_mex_apply (Cin, Mask, accum, unary, A, [ ]) ; 127 C2 = GB_spec_apply (Cin, Mask, accum, unary, A, [ ]) ; 128 GB_spec_compare (C1, C2) ; 129 130 % apply to A', with mask 131 C1 = GB_mex_apply (CinT, MaskT, accum, unary, A, dt) ; 132 C2 = GB_spec_apply (CinT, MaskT, accum, unary, A, dt) ; 133 GB_spec_compare (C1, C2) ; 134 135 % apply to vector B, with mask 136 C1 = GB_mex_apply (Cin2, mask, accum, unary, B, [ ]) ; 137 C2 = GB_spec_apply (Cin2, mask, accum, unary, B, [ ]) ; 138 GB_spec_compare (C1, C2) ; 139 140 end 141 end 142 end 143 end 144 end 145 end 146 end 147end 148 149fprintf ('\ntest62: all tests passed\n') ; 150 151