File: test19b.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 (224 lines) | stat: -rw-r--r-- 6,135 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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
function test19b(fulltest)
%TEST19B test GrB_assign and GrB_*_setElement with many pending operations

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

fprintf ('\ntest19b: GrB_assign and setElement, many pending computations\n') ;

debug_status = stat ;
if (debug_status)
    % turn off malloc debugging for this test
    debug_off
end

if (nargin < 1)
    fulltest = 0 ;
end
if (fulltest)
    nt = 3000 ;
else
    nt = 2000 ;
end

for problem = 0:2

    clear Work Work2
    switch (problem)
        case 0
            Corig = sparse (5,5) ;
            d = 1 ;
            ntrials = 100 ;
        case 1
            Corig = sprandn (10,20,0.1) ;
            d = 0.3 ;
            ntrials = nt ;
        case 2
            Corig = sparse (rand (10, 20)) ;
            d = 0.3 ;
            ntrials = nt ;
    end

    rng ('default') ;
    [m n] = size (Corig) ;
    fprintf ('problem %d: C is %d-by-%d, # assign/setElement to do: %d\n', ...
        problem, m, n, ntrials) ;

    if (problem > 0)
        fprintf ('... please wait\n') ;
    end

    for k = 1:ntrials

        c = randi (10,1) ;
        if (c == 10)
            d = struct ('outp', 'replace') ;
        elseif (c == 9)
            d = struct ('outp', 'replace', 'mask', 'complement') ;
        elseif (c == 8)
            d = struct ('mask', 'complement') ;
        else
            d = [ ] ;
        end

        c = randi (3,1) ;
        switch (c)
            case 1
                accum = '' ;
            case 2
                accum = 'plus' ;
            case 3
                accum = 'second' ;
        end

        kind = 0 ;
        c = randi (12,1) ;
        if (c < 8)
            ni = randi (3,1) ;
            nj = randi (3,1) ;
            J = randperm (n, nj) ;
            I = randperm (m, ni) ;
            A = sprand (ni, nj, 0.3) ;
            scalar = 0 ;
        elseif (c == 8)
            % scalar expansion
            ni = 2 ;
            nj = 2 ;
            J = randperm (n, nj) ;
            I = randperm (m, ni) ;
            A = sparse (rand (1)) ;
            scalar = 1 ;
        elseif (c == 9)
            ni = 1 ;
            nj = 1 ;
            I = randperm (m,1) ;
            J = randperm (n,1) ;
            A = sparse (rand (1)) ;
            scalar = 0 ;
        elseif (c == 10)
            ni = 2 ;
            nj = 2 ;
            I = randperm (m,2) ;
            J = randperm (n,2) ;
            A = sparse (rand (2)) ;
            scalar = 0 ;
        elseif (c == 11)
            % column assign
            ni = randi (3,1) ;
            nj = 1 ;
            kind = 1 ;
            J = randperm (n, 1) ;
            I = randperm (m, ni) ;
            A = sprand (ni, 1, 0.3) ;
            scalar = 0 ;
        else % (c == 12)
            % row assign: A is a single *column* vector
            ni = 1 ;
            nj = randi (3,1) ;
            kind = 2 ;
            J = randperm (n, nj) ;
            I = randperm (m, 1) ;
            A = sprand (nj, 1, 0.3) ;
            scalar = 0 ;
        end

        c = randi (2,1) ;
        switch (c)
            case 1
                % no mask
                Mask = [ ] ;
            case 2
                density = rand (1) ;
                if (density < 0.8)
                    if (kind == 0)
                        % mask same size as C: Matrix or Vector assign
                        Mask = (sprand (m, n, 0.3) ~= 0) ;
                    elseif (kind == 1)
                        % mask same size as C(:,j): column assign
                        Mask = (sprand (m, 1, 0.3) ~= 0) ;
                    else % (kind == 2)
                        % mask same size as C(i,:)': row assign
                        Mask = (sprand (n, 1, 0.3) ~= 0) ;
                    end
                else
                    if (kind == 0)
                        % mask same size as C: Matrix or Vector assign
                        Mask = sparse (true (m, n)) ;
                    elseif (kind == 1)
                        % mask same size as C(:,j): column assign
                        Mask = sparse (true (m, 1)) ;
                    else % (kind == 2)
                        % mask same size as C(i,:)': row assign
                        Mask = sparse (true (n, 1)) ;
                    end

                end
        end

        Work (k).A = A ;
        Work (k).I = I ;
        Work (k).J = J ;
        Work (k).Mask = Mask ;
        Work (k).accum = accum ;
        Work (k).desc = d ;
        Work (k).scalar = scalar ;
        Work (k).kind = kind ;

        Work2 (k).A = A ;
        Work2 (k).I = uint64 (I-1) ;
        Work2 (k).J = uint64 (J-1) ;
        Work2 (k).Mask = Mask ;
        Work2 (k).accum = accum ;
        Work2 (k).desc = d ;
        Work2 (k).kind = kind ;

    end

    C3 = Corig ;

    for k = 1:ntrials
        J = Work (k).J ;
        I = Work (k).I ;
        A = Work (k).A ;
        M = Work (k).Mask ;
        accum = Work (k).accum ;
        d = Work (k).desc ;
        scalar = Work (k).scalar ;
        kind = Work (k).kind ;
        if (kind == 0)
            % matrix/vector assign
            C3 = GB_spec_assign (C3, M, accum, A, I, J, d, scalar) ;
        elseif (kind == 1)
            % col assign
            C3 = GB_spec_Col_assign (C3, M, accum, A, I, J, d) ;
        else % (kind == 2)
            % row assign
            C3 = GB_spec_Row_assign (C3, M, accum, A, I, J, d) ;
        end
    end

    % default sparsity
    C2 = GB_mex_assign (Corig, Work2) ; % WORK_ASSIGN
    GB_spec_compare (C2, C3) ;

    % with sparsity control
    for s = 0:15
        C2 = GB_mex_assign (Corig, Work2, [s s]) ;  % WORK_ASSIGN
        GB_spec_compare (C2, C3) ;
    end

    % default sparsity but both C and M sparse
    C2 = GB_mex_assign (Corig, Work2, [2 2]) ;  % WORK_ASSIGN
    GB_spec_compare (C2, C3) ;

    % default sparsity but C sparse and M bitmap/full
    C2 = GB_mex_assign (Corig, Work2, [2 8]) ;  % WORK_ASSIGN
    GB_spec_compare (C2, C3) ;

end

if (debug_status)
    debug_on
end
fprintf ('\ntest19b: all tests passed\n') ;