1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
|
function test75b
%TEST75B GrB_mxm and GrB_vxm on all semirings (shorter test than test75)
% SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2022, All Rights Reserved.
% SPDX-License-Identifier: Apache-2.0
[binops, ~, add_ops, types, ~, ~] = GB_spec_opsall ;
% mult_ops = binops.positional
mult_ops = binops.all ;
types = types.all ;
% cstart = grb_get_coverage ;
% fprintf ('coverage start: %d\n', cstart) ;
% cc = zeros (15,1) ;
rng ('default') ;
m = 200 ;
n = 5 ;
A_sparse = sprandn (m, n, 0.1) ;
A_sparse (:,3) = 0 ;
A_sparse (2,3) = 1.7 ;
A_sparse (18,3) = 2.2 ;
A_sparse (:,1:2) = sparse (rand (m,2)) ;
A_sparse (1,1) = 0;
A_sparse (18,1) = 0;
A_sparse (:,5) = 0 ;
A_sparse (1,5) = 11 ;
A_sparse (2,5) = 23 ;
A_sparse (18,5) = 33 ;
B_sparse = sprandn (m, n, 0.1) ;
B_sparse (:,1) = 0 ;
B_sparse (1,1) = 3 ;
B_sparse (18,1) = 2 ;
B_sparse (:,[2 n]) = sparse (rand (m,2)) ;
B_sparse (3,2) = 0 ;
B_sparse (18,2) = 0 ;
A_sparse (:,3) = 0 ;
B_sparse (2,1) = 7 ;
B_sparse (18,1) = 8 ;
B_sparse (19,1) = 9 ;
x_sparse = sparse (rand (m,1)) ;
x_sparse (99) = 0 ;
y_sparse = sparse (zeros (m,1)) ;
y_sparse (99) = 1 ;
A.matrix = A_sparse ;
A.class = 'see below' ;
A.pattern = logical (spones (A_sparse)) ;
B.matrix = B_sparse ;
B.class = 'see below' ;
B.pattern = logical (spones (B_sparse)) ;
X.matrix = x_sparse ;
X.class = 'see below' ;
X.pattern = logical (spones (x_sparse)) ;
Y.matrix = y_sparse ;
Y.class = 'see below' ;
Y.pattern = logical (spones (y_sparse)) ;
fprintf ('\n-------------- GrB_mxm, vxm (dot product) on all semirings\n') ;
Cin = sparse (n, n) ;
Din = 10 * sparse (rand (n, n)) ;
D.matrix = Din ;
D.class = 'see below' ;
D.pattern = true (n,n) ;
Xin = sparse (n, 1) ;
Mask = sparse (ones (n,n)) ;
mask = sparse (ones (n,1)) ;
dnn = struct ;
dtn = struct ( 'inp0', 'tran' ) ;
dtn_dot = struct ( 'inp0', 'tran', 'axb', 'dot' ) ;
dtn_saxpy = struct ( 'inp0', 'tran', 'axb', 'saxpy' ) ;
dnt = struct ( 'inp1', 'tran' ) ;
dtt = struct ( 'inp0', 'tran', 'inp1', 'tran' ) ;
n_semirings = 0 ;
% ccall = zeros (1,15) ;
for k1 = 1:length(mult_ops)
mulop = mult_ops {k1} ;
fprintf ('\n%-10s ', mulop) ;
for k2 = 1:length(add_ops)
addop = add_ops {k2} ;
for k3 = 1:length (types)
type = types {k3} ;
semiring.multiply = mulop ;
semiring.add = addop ;
semiring.class = type ;
% create the semiring. some are not valid because the or,and,xor,eq
% monoids can only be used when z is boolean for z=mult(x,y).
try
[mult_op add_op id] = GB_spec_semiring (semiring) ;
[mult_opname mult_optype ztype xtype ytype] = GB_spec_operator (mult_op) ;
[ add_opname add_optype] = GB_spec_operator (add_op) ;
identity = GB_spec_identity (semiring.add, add_optype) ;
catch
continue
end
A.class = type ;
B.class = type ;
X.class = type ;
Y.class = type ;
D.class = add_op.optype ;
n_semirings = n_semirings + 1 ;
fprintf ('.') ;
% C += A'*B, C dense, typecasting of C
% (test coverage: 96)
C1 = GB_mex_mxm (Din, [ ], add_op, semiring, A, B, dtn_dot) ;
C2 = GB_spec_mxm (Din, [ ], add_op, semiring, A, B, dtn) ;
GB_spec_compare (C1, C2, id) ;
% C += A'*B, C sparse, no typecasting of C
% (test coverage: 1,234)
C1 = GB_mex_mxm (D, [ ], add_op, semiring, A, B, dtn_dot) ;
C2 = GB_spec_mxm (D, [ ], add_op, semiring, A, B, dtn) ;
GB_spec_compare (C1, C2, id) ;
% X = u*A, with mask (test coverage: 12)
C1 = GB_mex_vxm (Xin, mask, [ ], semiring, X, A, [ ]) ;
C2 = GB_spec_vxm (Xin, mask, [ ], semiring, X, A, [ ]) ;
GB_spec_compare (C1, C2, id) ;
end
end
end
fprintf ('\nsemirings tested: %d\n', n_semirings) ;
fprintf ('\ntest75b: all tests passed\n') ;
|