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