File: test19.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 (194 lines) | stat: -rw-r--r-- 4,864 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
function test19(fulltest)
%TEST19 test GxB_subassign and GrB_*_setElement with many pending operations

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

if (nargin < 1)
    fulltest = 0 ;
end
if (fulltest)
    nt = 3000 ;
else
    % check if malloc debugging is enabled
    debug_status = stat ;
    if (debug_status)
        % exhaustive malloc debugging
        nt = 50 ; % was 500, which takes too long
    else
        nt = 500 ;
    end
end

fprintf ('\nGxB_subassign and setElement test, many pending computations\n') ;

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 (10,1) ;
%       if (c == 10)
%           d = struct ('outp', 'replace') ;
%       else
%           d = [ ] ;
%       end

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

        c = randi (10,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 ;
        else
            ni = 2 ;
            nj = 2 ;
            I = randperm (m,2) ;
            J = randperm (n,2) ;
            A = sparse (rand (2)) ;
            scalar = 0 ;
        end

        c = randi (2,1) ;
        switch (c)
            case 1
                Mask = [ ] ;
            case 2
                Mask = (sprand (ni, nj, 0.3) ~= 0) ;
        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 ;

        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 ;

    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 ;
        C3 = GB_spec_subassign (C3, M, accum, A, I, J, d, scalar) ;
    end

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

    % with sparsity control
    for C_sparsity_control = [1 2 4 8]
        for M_sparsity_control = [2 12]
            ctrl = [C_sparsity_control M_sparsity_control] ;
            C2 = GB_mex_subassign (Corig, Work2, ctrl) ; % WORK_ASSIGN
            GB_spec_compare (C2, C3) ;
        end
    end

    % with no accum

    C3 = Corig ;
    for k = 1:ntrials
        J = Work (k).J ;
        I = Work (k).I ;
        A = Work (k).A ;
        M = Work (k).Mask ;
        d = Work (k).desc ;
        scalar = Work (k).scalar ;
        C3 = GB_spec_subassign (C3, M, [ ], A, I, J, d, scalar) ;
        Work2 (k).accum = [ ] ;
    end

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

    % with sparsity control
    for C_sparsity_control = [1 2 4 8]
        for M_sparsity_control = [2 12]
            ctrl = [C_sparsity_control M_sparsity_control] ;
            C2 = GB_mex_subassign (Corig, Work2, ctrl) ;    % WORK_ASSIGN
            GB_spec_compare (C2, C3) ;
        end
    end

end

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