File: test141.m

package info (click to toggle)
suitesparse 1%3A7.10.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, trixie
  • size: 254,920 kB
  • sloc: ansic: 1,134,743; cpp: 46,133; makefile: 4,875; fortran: 2,087; java: 1,826; sh: 996; ruby: 725; python: 495; asm: 371; sed: 166; awk: 44
file content (133 lines) | stat: -rw-r--r-- 3,688 bytes parent folder | download | duplicates (2)
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
function test141
%TEST141 test GrB_eWiseAdd (all types and operators) for dense matrices

% SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2025, All Rights Reserved.
% SPDX-License-Identifier: Apache-2.0

[binops, ~, ~, types, ~, ~] = GB_spec_opsall ;
binops = binops.all ;
types = types.all ;

fprintf ('test141 ------------ GrB_eWiseAdd with dense matrices\n') ;

m = 5 ;
n = 5 ;

rng ('default') ;

M = sprand (m, n, 0.5) ;

Amat2 = 2 * sparse (rand (m,n)) ;
Bmat2 = 2 * sparse (rand (m,n)) ;
Cmat2 = 2 * sparse (rand (m,n)) ;

Amat = 50 * sparse (rand (m,n)) ;
Bmat = 50 * sparse (rand (m,n)) ;
Cmat = 50 * sparse (rand (m,n)) ;

Emat = sprand (m, n, 0.5) ;
Smat = sparse (m,n) ;
desc.mask = 'structural' ;

A.matrix = Amat ; A.class = 'see below' ;
B.matrix = Bmat ; B.class = 'see below' ;
C.matrix = Cmat ; C.class = 'see below' ;
S.matrix = Smat ; S.class = 'see below' ;
E.matrix = Emat ; E.class = 'see below' ;

A.sparsity = 8 ;
B.sparsity = 8 ;
C.sparsity = 8 ;

for k2 = 1:length(binops)
    binop = binops {k2}  ;
    if (isequal (binop, 'pow'))
        continue ;
    end
    fprintf ('\n%-10s ', binop) ;

    for k1 = 1:length (types)
        type = types {k1}  ;
        op.opname = binop ;
        op.optype = type ;

        try
            GB_spec_operator (op) ;
        catch
            continue ;
        end

        fprintf ('.') ;

        switch (binop)
            % domain is ok, but limit it to avoid integer typecast
            % failures from O(eps) errors, or overflow to inf
            case { 'ldexp', 'pow' }
                A.matrix = Amat2 ;
                B.matrix = Bmat2 ;
                C.matrix = Cmat2 ;
            otherwise
                % no change
        end

        A.class = type ;
        B.class = type ;
        E.class = type ;

        if (k2 > 20)
            % eq, ne, gt, lt, ge, le
            S.class = 'logical' ;
            C.class = 'logical' ;
        else
            S.class = type ;
            C.class = type ;
        end

        id = test_cast (0, type) ;

        %---------------------------------------
        % C = A+B
        %---------------------------------------

        C0 = GB_spec_Matrix_eWiseAdd (S, [ ], [ ], op, A, B, [ ]) ;
        C1 = GB_mex_Matrix_eWiseAdd  (S, [ ], [ ], op, A, B, [ ]) ;
        GB_spec_compare (C0, C1, id) ;

        %---------------------------------------
        % C<M> = A+B, both A and B dense
        %---------------------------------------

        C0 = GB_spec_Matrix_eWiseAdd (S, M, [ ], op, A, B, desc) ;
        C1 = GB_mex_Matrix_eWiseAdd  (S, M, [ ], op, A, B, desc) ;
        GB_spec_compare (C0, C1, id) ;

        %---------------------------------------
        % C<M> = A+E, A dense, E sparse
        %---------------------------------------

        C0 = GB_spec_Matrix_eWiseAdd (S, M, [ ], op, A, E, desc) ;
        C1 = GB_mex_Matrix_eWiseAdd  (S, M, [ ], op, A, E, desc) ;
        GB_spec_compare (C0, C1, id) ;

        %---------------------------------------
        % C<M> = E+A, A dense, E sparse
        %---------------------------------------

        C0 = GB_spec_Matrix_eWiseAdd (S, M, [ ], op, E, A, desc) ;
        C1 = GB_mex_Matrix_eWiseAdd  (S, M, [ ], op, E, A, desc) ;
        GB_spec_compare (C0, C1, id) ;

        %---------------------------------------
        % C += A+B
        %---------------------------------------

        if (~GB_spec_is_positional (op))
            C0 = GB_spec_Matrix_eWiseAdd (C, [ ], op, op, A, B, [ ]) ;
            C1 = GB_mex_Matrix_eWiseAdd  (C, [ ], op, op, A, B, [ ]) ;
            GB_spec_compare (C0, C1, id) ;
        end
    end
end

fprintf ('\ntest141: all tests passed\n') ;