1function test152
2%TEST152 test C = A+B for dense A, B, and C
3
4% SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2021, All Rights Reserved.
5% SPDX-License-Identifier: Apache-2.0
6
7fprintf ('\ntest152: test binops with C=A+B, all dense\n') ;
8
9rng ('default') ;
10
11[binops, ~, ~, types, ~, ~,] = GB_spec_opsall ;
12types = types.all ;
13binops = binops.all ;
14
15n = 5 ;
16
17Amat5 = 5 * sparse (rand (n)) ;
18Bmat5 = 5 * sparse (rand (n)) ;
19Amat5 (1,1) = 1 ;
20Bmat5 (1,1) = 1 ;
21Amat = 20 * Amat5 ;
22Bmat = 20 * Bmat5 ;
23
24C.matrix = sparse (ones (n)) ;
25C.pattern = sparse (true (n)) ;
26A.pattern = sparse (true (n)) ;
27B.pattern = sparse (true (n)) ;
28
29for k1 = 1:length (binops)
30    opname = binops {k1} ;
31    fprintf ('\n%-14s ', opname) ;
32
33    for k2 = 1:length (types)
34        type = types {k2} ;
35        op.opname = opname ;
36        op.optype = type ;
37
38        try
39            [rename optype ztype xtype ytype] = GB_spec_operator (op) ;
40        catch me
41            continue ;
42        end
43
44        A.class = xtype ;
45        B.class = ytype ;
46        C.class = ztype ;
47
48        switch (opname)
49            case { 'atan2', 'pow' }
50                A.matrix = Amat5 ;
51                B.matrix = Bmat5 ;
52            otherwise
53                A.matrix = Amat5 ;
54                B.matrix = Bmat5 ;
55        end
56
57        if (isequal (opname, 'bitshift') || isequal (opname, 'bshift'))
58            B.class = 'int8' ;
59        end
60
61        if (contains (type, 'single'))
62            tol = 1e-5 ;
63        elseif (contains (type, 'double'))
64            tol = 1e-12 ;
65        else
66            tol = 0 ;
67        end
68
69        fprintf ('.') ;
70
71        C1 = GB_spec_Matrix_eWiseAdd (C, [ ], [ ], op, A, B, [ ]) ;
72        C2 = GB_mex_Matrix_eWiseAdd  (C, [ ], [ ], op, A, B, [ ]) ;
73        GB_spec_compare (C1, C2, 0, tol) ;
74
75    end
76end
77
78fprintf ('\ntest152: all tests passed\n') ;
79
80