1function test125 2%TEST125 test GrB_mxm: row and column scaling 3% all built-in semirings, no typecast, no mask 4 5% SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2021, All Rights Reserved. 6% SPDX-License-Identifier: Apache-2.0 7 8[binops, ~, add_ops, types, ~, ~] = GB_spec_opsall ; 9% mult_ops = binops.positional ; 10mult_ops = binops.all ; 11types = types.all ; 12 13if (nargin < 1) 14 fulltest = 1 ; 15end 16 17if (fulltest) 18 fprintf ('-------------- GrB_mxm on all semirings (row,col scale)\n') ; 19 n_semirings_max = inf ; 20else 21 fprintf ('quick test of GrB_mxm (dot product method)\n') ; 22 n_semirings_max = 1 ; 23end 24 25dnn = struct ; 26dtn = struct ( 'inp0', 'tran' ) ; 27dnt = struct ( 'inp1', 'tran' ) ; 28dtt = struct ( 'inp0', 'tran', 'inp1', 'tran' ) ; 29 30ntrials = 0 ; 31 32rng ('default') ; 33 34n = 10 ; 35 36n_semirings = 0 ; 37A = GB_spec_random (n,n,0.3,100,'none') ; 38clear B 39B1matrix = spdiags (3 * rand (n,1), 0, n, n) ; 40B.matrix = B1matrix ; 41B.class = 'none' ; 42B.pattern = logical (spones (B1matrix)) ; 43 44C = GB_spec_random (n,n,0.3,100,'none') ; 45M = spones (sprandn (n, n, 0.3)) ; 46 47for k1 = 1:length(mult_ops) 48 mulop = mult_ops {k1} ; 49 if (fulltest) 50 fprintf ('\n%-10s ', mulop) ; 51 end 52 nmult_semirings = 0 ; 53 54 for k2 = 1:length(add_ops) 55 addop = add_ops {k2} ; 56 if (fulltest) 57 fprintf ('.') ; 58 end 59 60 for k3 = 1:length (types) 61 type = types {k3} ; 62 63 semiring.multiply = mulop ; 64 semiring.add = addop ; 65 semiring.class = type ; 66 67 % semiring 68 69 % create the semiring. some are not valid because the 70 % or,and,xor monoids can only be used when z is boolean for 71 % z=mult(x,y). 72 try 73 [mult_op add_op id] = GB_spec_semiring (semiring) ; 74 [mult_opname mult_optype ztype xtype ytype] = ... 75 GB_spec_operator (mult_op) ; 76 [ add_opname add_optype] = GB_spec_operator (add_op) ; 77 identity = GB_spec_identity (semiring.add, add_optype) ; 78 catch 79 continue 80 end 81 82 if (n_semirings+1 > n_semirings_max) 83 fprintf ('\ntest125: all quick tests passed\n') ; 84 return ; 85 end 86 87 n_semirings = n_semirings + 1 ; 88 nmult_semirings = nmult_semirings + 1 ; 89 A.class = type ; 90 B.class = type ; 91 C.class = type ; 92 93 % C = A*B 94 C1 = GB_mex_mxm (C, [ ], [ ], semiring, A, B, dnn); 95 C0 = GB_spec_mxm (C, [ ], [ ], semiring, A, B, dnn); 96 GB_spec_compare (C0, C1, identity) ; 97 98 % C = B*A 99 C1 = GB_mex_mxm (C, [ ], [ ], semiring, B, A, dnn); 100 C0 = GB_spec_mxm (C, [ ], [ ], semiring, B, A, dnn); 101 GB_spec_compare (C0, C1, identity) ; 102 103 % dump the semiring list to compare with Source/Generated 104 switch (xtype) 105 case { 'logical' } 106 xtype = 'bool' ; 107 case { 'single complex' } 108 xtype = 'fc32' ; 109 case { 'double complex' } 110 xtype = 'fc64' ; 111 case { 'single' } 112 xtype = 'fp32' ; 113 case { 'double' } 114 xtype = 'fp64' ; 115 end 116 117 switch (add_opname) 118 case { 'xor' } 119 add_opname = 'lxor' ; 120 case { 'or' } 121 add_opname = 'lor' ; 122 case { 'and' } 123 add_opname = 'land' ; 124 end 125 126 switch (mult_opname) 127 case { 'xor' } 128 mult_opname = 'lxor' ; 129 case { 'or' } 130 mult_opname = 'lor' ; 131 case { 'and' } 132 mult_opname = 'land' ; 133 case { 'pair' } 134 switch (add_opname) 135 case { 'eq', 'land', 'lor', 'min', 'max', 'times' } 136 add_opname = 'any' ; 137 end 138 end 139 140% This should produce a list of all files in Source/Generated. 141% fprintf ('GB_AxB__%s_%s_%s.c\n', ... 142% add_opname, mult_opname, xtype) ; 143 144 end 145 end 146 fprintf (' %4d', nmult_semirings) ; 147end 148 149fprintf ('\nsemirings tested: %d\n', n_semirings) ; 150fprintf ('\ntest125: all tests passed\n') ; 151 152