1function test77 (fulltest) 2%TEST77 test GrB_kronecker 3 4% SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2021, All Rights Reserved. 5% SPDX-License-Identifier: Apache-2.0 6 7% TODO: this test takes too long; cut it down 8 9[binops, ~, ~, types, ~, ~] = GB_spec_opsall ; 10binops = binops.all ; 11types = types.all ; 12 13if (nargin < 1) 14 fulltest = 0 ; 15end 16 17if (fulltest) 18 fprintf ('--------------lengthy tests of GrB_kronecker\n') ; 19 k1test = 1:length(types) ; 20else 21 fprintf ('--------------quick tests of GrB_kronecker\n') ; 22 k1test = [4 5 10 11] ; 23end 24 25rng ('default') ; 26 27dnn = struct ; 28dtn = struct ( 'inp0', 'tran' ) ; 29dnt = struct ( 'inp1', 'tran' ) ; 30dtt = struct ( 'inp0', 'tran', 'inp1', 'tran' ) ; 31 32n_semirings = 0 ; 33for k1 = k1test 34 type = types {k1} ; 35 36 fprintf ('\n%s:\n', type) ; 37 38 if (fulltest) 39 k2test = 1:length(binops) ; 40 else 41 k2test = [44:51 44 4 7] ; 42 end 43 44 for k2 = k2test 45 46 binop = binops {k2} ; 47 op.opname = binop ; 48 op.optype = type ; 49 if (GB_spec_is_positional (op.opname)) 50 if (~(isequal (type, 'int32') || isequal (type, 'int64'))) 51 continue 52 end 53 end 54 55 try 56 GB_spec_operator (op) ; 57 catch 58 continue 59 end 60 61 fprintf ('\n binary op: [ %s %s ] ', binop, type) ; 62 63 for k4 = [0 randi([0,length(binops)], 1, 3)] % 0:length(binops) 64 65 clear accum 66 if (k4 == 0) 67 accum = '' ; 68 ntypes = 1 ; 69 fprintf ('\n accum: [ none ]') ; 70 else 71 if (GB_spec_is_positional (op.opname)) 72 continue ; 73 end 74 accum.opname = binops {k4} ; 75 if (GB_spec_is_positional (accum.opname)) 76 continue ; 77 end 78 ntypes = length (types) ; 79 fprintf ('\n accum: %s ', accum.opname) ; 80 end 81 82 for k5 = randi ([1 ntypes], 1, 3) % ntypes 83 84 if (k4 > 0) 85 accum.optype = types {k5} ; 86 end 87 88 if (GB_spec_is_positional (accum)) 89 continue ; 90 end 91 92 try 93 GB_spec_operator (accum) ; 94 catch 95 continue 96 end 97 98 if (~isempty (accum)) 99 fprintf ('%s ', accum.optype) ; 100 end 101 102 for Mask_complement = [false true] 103 104 if (Mask_complement) 105 dnn.mask = 'complement' ; 106 dtn.mask = 'complement' ; 107 dnt.mask = 'complement' ; 108 dtt.mask = 'complement' ; 109 else 110 dnn.mask = 'default' ; 111 dtn.mask = 'default' ; 112 dnt.mask = 'default' ; 113 dtt.mask = 'default' ; 114 end 115 116 for C_replace = [false true] 117 118 if (C_replace) 119 dnn.outp = 'replace' ; 120 dtn.outp = 'replace' ; 121 dnt.outp = 'replace' ; 122 dtt.outp = 'replace' ; 123 else 124 dnn.outp = 'default' ; 125 dtn.outp = 'default' ; 126 dnt.outp = 'default' ; 127 dtt.outp = 'default' ; 128 end 129 130 % try some matrices 131 for am = 5 % % Was [1 5 10 ] 132 for an = 3 % [1 10 ] % Was [ 1 5 10 ] 133 for bm = 4 % % Was [1 4 9 ] 134 for bn = 2 % % Was [1 4 9 ] 135 fprintf ('.') ; 136 137 Ax= sparse (100 * sprandn (am,an, 0.5)); 138 Bx= sparse (100 * sprandn (bm,bn, 0.5)); 139 cm = am * bm ; 140 cn = an * bn ; 141 Cx= sparse (100 * sprandn (cm,cn, 0.2)); 142 Mask = sprandn (cm,cn,0.2) ~= 0 ; 143 AT = Ax' ; 144 BT = Bx' ; 145 146 for A_is_hyper = 0:1 147 for A_is_csc = 0:1 148 for B_is_hyper = 0:1 149 for B_is_csc = 0:1 150 for C_is_hyper = 0:1 151 for C_is_csc = 0:1 152 153 clear A 154 A.matrix = Ax ; 155 A.is_hyper = A_is_hyper ; 156 A.is_csc = A_is_csc ; 157 158 clear B 159 B.matrix = Bx ; 160 B.is_hyper = B_is_hyper ; 161 B.is_csc = B_is_csc ; 162 163 clear C 164 C.matrix = Cx ; 165 C.is_hyper = C_is_hyper ; 166 C.is_csc = C_is_csc ; 167 168 %--------------------------------------- 169 % kron(A,B) 170 %--------------------------------------- 171 172 % C = kron(A,B) 173 C0 = GB_spec_kron (C, [ ], accum, op, A, B, dnn); 174 C1 = GB_mex_kron (C, [ ], accum, op, A, B, dnn); 175 GB_spec_compare (C0, C1) ; 176 177 % C = kron(A,B) with Mask 178 C0 = GB_spec_kron (C, Mask, accum, op, A, B, dnn); 179 C1 = GB_mex_kron (C, Mask, accum, op, A, B, dnn); 180 GB_spec_compare (C0, C1) ; 181 182 %--------------------------------------- 183 % kron(A',B) 184 %--------------------------------------- 185 186 % C = kron(A',B), no Mask 187 C0 = GB_spec_kron (C, [ ], accum, op, AT, B, dtn); 188 C1 = GB_mex_kron (C, [ ], accum, op, AT, B, dtn); 189 GB_spec_compare (C0, C1) ; 190 191 % C = kron(A',B), with Mask 192 C0 = GB_spec_kron (C, Mask, accum, op, AT, B, dtn); 193 C1 = GB_mex_kron (C, Mask, accum, op, AT, B, dtn); 194 GB_spec_compare (C0, C1) ; 195 196 %--------------------------------------- 197 % kron(A,B') 198 %--------------------------------------- 199 200 % no mask 201 C0 = GB_spec_kron (C, [ ], accum, op, A, BT, dnt); 202 C1 = GB_mex_kron (C, [ ], accum, op, A, BT, dnt); 203 GB_spec_compare (C0, C1) ; 204 205 % with mask 206 C0 = GB_spec_kron (C, Mask, accum, op, A, BT, dnt); 207 C1 = GB_mex_kron (C, Mask, accum, op, A, BT, dnt); 208 GB_spec_compare (C0, C1) ; 209 210 %--------------------------------------- 211 % kron(A',B') 212 %--------------------------------------- 213 214 % no Mask 215 C0 = GB_spec_kron (C, [ ], accum, op, AT, BT, dtt); 216 C1 = GB_mex_kron (C, [ ], accum, op, AT, BT, dtt); 217 GB_spec_compare (C0, C1) ; 218 219 % with mask 220 C0 = GB_spec_kron (C, Mask, accum, op, AT, BT, dtt); 221 C1 = GB_mex_kron (C, Mask, accum, op, AT, BT, dtt); 222 GB_spec_compare (C0, C1) ; 223 224 end 225 end 226 end 227 end 228 end 229 end 230 231end 232end 233end 234end 235end 236end 237end 238end 239end 240end 241 242fprintf ('\ntest77: all tests passed\n') ; 243 244