1function test185
2%TEST185 test dot4 for all sparsity formats
3% GB_AxB_dot4 computes C+=A'*B when C is dense.
4
5% SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2021, All Rights Reserved.
6% SPDX-License-Identifier: Apache-2.0
7
8fprintf ('test185 -------------------- C+=A''*B when C is dense\n') ;
9
10rng ('default') ;
11GrB.burble (0) ;
12
13semiring.add = 'plus' ;
14semiring.multiply = 'times' ;
15semiring.class = 'double' ;
16
17plus_pair.add = 'plus' ;
18plus_pair.multiply = 'pair' ;
19plus_pair.class = 'double' ;
20
21add_op = 'plus' ;
22dtn_dot = struct ('axb', 'dot', 'inp0', 'tran') ;
23dtn_sax = struct ('axb', 'saxpy', 'inp0', 'tran') ;
24
25n = 20 ;
26C = GB_spec_random (n, n, inf, 1, 'double') ;
27C0 = sparse (n, n) ;
28maxerr = 0 ;
29
30M = sparse (rand (n, n) > 0.5) ;
31
32for da = [0.01 0.1 .5 0.9 inf]
33    A = GB_spec_random (n, n, da, 1, 'double') ;
34
35    for db = [0.01 0.1 .5 0.9 inf]
36        B = GB_spec_random (n, n, db, 1, 'double') ;
37
38        for A_sparsity = [1 2 4 8]
39            fprintf ('.') ;
40
41            for B_sparsity = [1 2 4 8]
42                A.sparsity = A_sparsity ;
43                B.sparsity = B_sparsity ;
44
45                % C2 = C + A'*B using dot4
46                C2 = GB_mex_mxm  (C, [ ], add_op, semiring, A, B, dtn_dot) ;
47                C1 = GB_spec_mxm (C, [ ], add_op, semiring, A, B, dtn_dot) ;
48                GB_spec_compare (C1, C2) ;
49                C3 = C.matrix + (A.matrix)'*B.matrix ;
50                err = norm (C3 - C2.matrix, 1) ;
51                maxerr = max (maxerr, err) ;
52                assert (err < 1e-12) ;
53
54                % C2 = A'*B using dot2/dot3
55                C2 = GB_mex_mxm  (C0, [ ], [ ], semiring, A, B, dtn_dot) ;
56                C1 = GB_spec_mxm (C0, [ ], [ ], semiring, A, B, dtn_dot) ;
57                GB_spec_compare (C1, C2) ;
58                C3 = (A.matrix)'*B.matrix ;
59                err = norm (C3 - C2.matrix, 1) ;
60                maxerr = max (maxerr, err) ;
61                assert (err < 1e-12) ;
62
63                % C2 = C + A'*B using saxpy
64                C2 = GB_mex_mxm  (C, [ ], add_op, semiring, A, B, dtn_sax) ;
65                C1 = GB_spec_mxm (C, [ ], add_op, semiring, A, B, dtn_sax) ;
66                GB_spec_compare (C1, C2) ;
67                C3 = C.matrix + (A.matrix)'*B.matrix ;
68                err = norm (C3 - C2.matrix, 1) ;
69                maxerr = max (maxerr, err) ;
70                assert (err < 1e-12) ;
71
72                % C2 = C + spones(A)'*spones(B) using dot4
73                C2 = GB_mex_mxm  (C, [ ], add_op, plus_pair, A, B, dtn_dot) ;
74                C1 = GB_spec_mxm (C, [ ], add_op, plus_pair, A, B, dtn_dot) ;
75                GB_spec_compare (C1, C2) ;
76                C3 = C.matrix + spones (A.matrix)' * spones (B.matrix) ;
77                err = norm (C3 - C2.matrix, 1) ;
78                maxerr = max (maxerr, err) ;
79                assert (err < 1e-12) ;
80
81                % C2 = spones(A)'*spones(B) using dot2/dot3
82                C2 = GB_mex_mxm  (C0, [ ], [ ], plus_pair, A, B, dtn_dot) ;
83                C1 = GB_spec_mxm (C0, [ ], [ ], plus_pair, A, B, dtn_dot) ;
84                GB_spec_compare (C1, C2) ;
85                C3 = spones (A.matrix)' * spones (B.matrix) ;
86                err = norm (C3 - C2.matrix, 1) ;
87                maxerr = max (maxerr, err) ;
88                assert (err < 1e-12) ;
89
90            end
91        end
92    end
93end
94
95fprintf ('\n') ;
96GrB.burble (0) ;
97fprintf ('maxerr: %g\n', maxerr) ;
98fprintf ('test185: all tests passed\n') ;
99
100