File: test242.m

package info (click to toggle)
suitesparse-graphblas 7.4.0%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 67,112 kB
  • sloc: ansic: 1,072,243; cpp: 8,081; sh: 512; makefile: 506; asm: 369; python: 125; awk: 10
file content (160 lines) | stat: -rw-r--r-- 5,159 bytes parent folder | download | duplicates (3)
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
149
150
151
152
153
154
155
156
157
158
159
160
function test242
%TEST242 test GxB_Iterator for matrices

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

rng ('default') ;
[~, ~, ~, types, ~, ~] = GB_spec_opsall ;
types = types.all ;
ntypes = length (types) ;

m = 20 ;
n = 30 ;
GB_builtin_complex_set (true) ;

% yin is dense and all zero
yin.matrix = sparse (zeros (m, 1)) ;
yin.pattern = true (m, 1) ;

for k = 1:(ntypes + 1)

    if (k == ntypes + 1)
        % user-defined double complex
        GB_builtin_complex_set (false) ;
        type = 'double complex'  ;
        fprintf ('\nComplex (UDT):\n') ;
    else
        % built-in types
        type = types {k}  ;
        fprintf ('\n%s:\n', type) ;
    end
    
    if (test_contains (type, 'single'))
        tol = 1e-5 ;
    elseif (test_contains (type, 'double'))
        tol = 1e-14 ;
    else
        tol = 0 ;
    end

    A = [ ] ;

    if (isequal (type, 'bool'))
        accum.opname = 'lor' ;
        semiring.add = 'lor' ;
        semiring.multiply = 'land' ;
    else
        accum.opname = 'plus' ;
        semiring.add = 'plus' ;
        semiring.multiply = 'times' ;
    end
    accum.optype = type ;
    semiring.class = type ;

    for sparsity = [1 2 4 8]

        if (sparsity == 8)
            fprintf ('full') ;
            ntrials = 1 ;
        elseif (sparsity == 4)
            fprintf ('bitmap') ;
            ntrials = 51 ;
        elseif (sparsity == 2)
            fprintf ('sparse') ;
            ntrials = 51 ;
        elseif (sparsity == 1)
            fprintf ('hyper') ;
            ntrials = 51 ;
        end

        for trial = 1:ntrials

            fprintf ('.') ;
            if (sparsity == 8 || trial == ntrials)
                A = GB_spec_random (m, n, inf, 100, type) ;
            else
                d = trial / 200 ;
                A = GB_spec_random (m, n, d, 100, type) ;
            end
            A.sparsity = sparsity ;

            % x must be full
            x = GB_spec_random (n, 1, inf, 2, type) ;
            x.sparsity = 8 ;

            % yin is empty
            yin.class = type ;
            yin.iso = false ;

            y0 = GB_spec_mxv (yin, [ ], accum, semiring, A, x, [ ]) ;

            % CSR with row iterator
            A.is_csc = false ;
            y1 = GB_mex_mxv_iterator (A, x, 0) ;    % with macros
            GB_spec_compare (y0, y1, 0, tol) ;
            y1 = GB_mex_mxv_iterator (A, x, 0+8) ;  % with functions
            GB_spec_compare (y0, y1, 0, tol) ;

            % CSR with entry iterator
            y1 = GB_mex_mxv_iterator (A, x, 2) ;    % with macros
            GB_spec_compare (y0, y1, 0, tol) ;
            y1 = GB_mex_mxv_iterator (A, x, 2+8) ;  % with functions
            GB_spec_compare (y0, y1, 0, tol) ;

            % CSR with row iterator: backwards kseek
            y1 = GB_mex_mxv_iterator (A, x, 3) ;    % with macros
            GB_spec_compare (y0, y1, 0, tol) ;
            y1 = GB_mex_mxv_iterator (A, x, 3+8) ;  % with functions
            GB_spec_compare (y0, y1, 0, tol) ;

            % CSR with row iterator: with seekRow
            y1 = GB_mex_mxv_iterator (A, x, 5) ;    % with macros
            GB_spec_compare (y0, y1, 0, tol) ;
            y1 = GB_mex_mxv_iterator (A, x, 5+8) ;  % with functions
            GB_spec_compare (y0, y1, 0, tol) ;

            % CSR with entry iterator, seek
            y1 = GB_mex_mxv_iterator (A, x, 7) ;    % with macros
            GB_spec_compare (y0, y1, 0, tol) ;
            y1 = GB_mex_mxv_iterator (A, x, 7+8) ;  % with functions
            GB_spec_compare (y0, y1, 0, tol) ;

            % CSC with col iterator
            A.is_csc = true ;
            y1 = GB_mex_mxv_iterator (A, x, 1) ;    % with macros
            GB_spec_compare (y0, y1, 0, tol) ;
            y1 = GB_mex_mxv_iterator (A, x, 1+8) ;  % with functions
            GB_spec_compare (y0, y1, 0, tol) ;

            % CSC with entry iterator
            y1 = GB_mex_mxv_iterator (A, x, 2) ;    % with macros
            GB_spec_compare (y0, y1, 0, tol) ;
            y1 = GB_mex_mxv_iterator (A, x, 2+8) ;  % with functions
            GB_spec_compare (y0, y1, 0, tol) ;

            % CSC with col iterator: backwards kseek
            y1 = GB_mex_mxv_iterator (A, x, 4) ;    % with macros
            GB_spec_compare (y0, y1, 0, tol) ;
            y1 = GB_mex_mxv_iterator (A, x, 4+8) ;  % with functions
            GB_spec_compare (y0, y1, 0, tol) ;

            % CSC with col iterator: with seekCol
            y1 = GB_mex_mxv_iterator (A, x, 6) ;    % with macros
            GB_spec_compare (y0, y1, 0, tol) ;
            y1 = GB_mex_mxv_iterator (A, x, 6+8) ;  % with functions
            GB_spec_compare (y0, y1, 0, tol) ;

            % CSC with entry iterator, seek
            y1 = GB_mex_mxv_iterator (A, x, 7) ;    % with macros
            GB_spec_compare (y0, y1, 0, tol) ;
            y1 = GB_mex_mxv_iterator (A, x, 7+8) ;  % with functions
            GB_spec_compare (y0, y1, 0, tol) ;

        end
        fprintf ('\n') ;
    end
end
GB_builtin_complex_set (true) ;
fprintf ('\ntest242: all tests passed\n') ;