File: test77.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 (243 lines) | stat: -rw-r--r-- 5,535 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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
function test77 (fulltest)
%TEST77 test GrB_kronecker

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

% TODO: this test takes too long; cut it down

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

if (nargin < 1)
    fulltest = 0 ;
end

if (fulltest)
    fprintf ('--------------lengthy tests of GrB_kronecker\n') ;
    k1test = 1:length(types) ;
else
    fprintf ('--------------quick tests of GrB_kronecker\n') ;
    k1test = [4 5 10 11] ;
end

rng ('default') ;

dnn = struct ;
dtn = struct ( 'inp0', 'tran' ) ;
dnt = struct ( 'inp1', 'tran' ) ;
dtt = struct ( 'inp0', 'tran', 'inp1', 'tran' ) ;

n_semirings = 0 ;
for k1 = k1test
    type = types {k1}  ;

    fprintf ('\n%s:\n', type) ;

    if (fulltest)
        k2test = 1:length(binops) ;
    else
        k2test = [45:52 45 4 7] ;
    end

    for k2 = k2test

    binop = binops {k2}  ;
    op.opname = binop ;
    op.optype = type ;
    if (GB_spec_is_positional (op.opname))
        if (~(isequal (type, 'int32') || isequal (type, 'int64')))
            continue
        end
    end

    try
        GB_spec_operator (op) ;
    catch
        continue
    end

    fprintf ('\n    binary op: [ %s %s ] ', binop, type) ;

    for k4 = [0 randi([0,length(binops)], 1, 3)] % 0:length(binops)

    clear accum
    if (k4 == 0)
        accum = ''  ;
        ntypes = 1 ;
        fprintf ('\n        accum: [ none ]') ;
    else
        if (GB_spec_is_positional (op.opname))
            continue ;
        end
        accum.opname = binops {k4}  ;
        if (GB_spec_is_positional (accum.opname))
            continue ;
        end
        ntypes = length (types) ;
        fprintf ('\n        accum: %s ', accum.opname) ;
    end

    for k5 = randi ([1 ntypes], 1, 3) % ntypes

    if (k4 > 0)
        accum.optype = types {k5}  ;
    end

    if (GB_spec_is_positional (accum))
        continue ;
    end

    try
        GB_spec_operator (accum) ;
    catch
        continue
    end

    if (~isempty (accum))
        fprintf ('%s ', accum.optype) ;
    end

    for Mask_complement = [false true]

    if (Mask_complement)
        dnn.mask = 'complement' ;
        dtn.mask = 'complement' ;
        dnt.mask = 'complement' ;
        dtt.mask = 'complement' ;
    else
        dnn.mask = 'default' ;
        dtn.mask = 'default' ;
        dnt.mask = 'default' ;
        dtt.mask = 'default' ;
    end

    for C_replace = [false true]

    if (C_replace)
        dnn.outp = 'replace' ;
        dtn.outp = 'replace' ;
        dnt.outp = 'replace' ;
        dtt.outp = 'replace' ;
    else
        dnn.outp = 'default' ;
        dtn.outp = 'default' ;
        dnt.outp = 'default' ;
        dtt.outp = 'default' ;
    end

    % try some matrices
    for am = 5 %  % Was [1 5 10 ]
    for an = 3 % [1 10 ] % Was [ 1 5 10 ]
    for bm = 4 %  % Was [1 4 9 ]
    for bn = 2 %  % Was [1 4 9 ]
    fprintf ('.') ;

    Ax= sparse (100 * sprandn (am,an, 0.5));
    Bx= sparse (100 * sprandn (bm,bn, 0.5));
    cm = am * bm ;
    cn = an * bn ;
    Cx= sparse (100 * sprandn (cm,cn, 0.2));
    Mask = sprandn (cm,cn,0.2) ~= 0 ;
    AT = Ax' ;
    BT = Bx' ;

    for A_is_hyper = 0:1
    for A_is_csc   = 0:1
    for B_is_hyper = 0:1
    for B_is_csc   = 0:1
    for C_is_hyper = 0:1
    for C_is_csc   = 0:1

    clear A
    A.matrix = Ax ;
    A.is_hyper = A_is_hyper ;
    A.is_csc   = A_is_csc   ;

    clear B
    B.matrix = Bx ;
    B.is_hyper = B_is_hyper ;
    B.is_csc   = B_is_csc   ;

    clear C
    C.matrix = Cx ;
    C.is_hyper = C_is_hyper ;
    C.is_csc   = C_is_csc   ;

    %---------------------------------------
    % kron(A,B)
    %---------------------------------------

    % C = kron(A,B)
    C0 = GB_spec_kron (C, [ ], accum, op, A, B, dnn);
    C1 = GB_mex_kron  (C, [ ], accum, op, A, B, dnn);
    GB_spec_compare (C0, C1) ;

    % C = kron(A,B) with Mask
    C0 = GB_spec_kron (C, Mask, accum, op, A, B, dnn);
    C1 = GB_mex_kron  (C, Mask, accum, op, A, B, dnn);
    GB_spec_compare (C0, C1) ;

    %---------------------------------------
    % kron(A',B)
    %---------------------------------------

    % C = kron(A',B), no Mask
    C0 = GB_spec_kron (C, [ ], accum, op, AT, B, dtn);
    C1 = GB_mex_kron  (C, [ ], accum, op, AT, B, dtn);
    GB_spec_compare (C0, C1) ;

    % C = kron(A',B), with Mask
    C0 = GB_spec_kron (C, Mask, accum, op, AT, B, dtn);
    C1 = GB_mex_kron  (C, Mask, accum, op, AT, B, dtn);
    GB_spec_compare (C0, C1) ;

    %---------------------------------------
    % kron(A,B')
    %---------------------------------------

    % no mask
    C0 = GB_spec_kron (C, [ ], accum, op, A, BT, dnt);
    C1 = GB_mex_kron  (C, [ ], accum, op, A, BT, dnt);
    GB_spec_compare (C0, C1) ;

    % with mask
    C0 = GB_spec_kron (C, Mask, accum, op, A, BT, dnt);
    C1 = GB_mex_kron  (C, Mask, accum, op, A, BT, dnt);
    GB_spec_compare (C0, C1) ;

    %---------------------------------------
    % kron(A',B')
    %---------------------------------------

    % no Mask
    C0 = GB_spec_kron (C, [ ], accum, op, AT, BT, dtt);
    C1 = GB_mex_kron  (C, [ ], accum, op, AT, BT, dtt);
    GB_spec_compare (C0, C1) ;

    % with mask
    C0 = GB_spec_kron (C, Mask, accum, op, AT, BT, dtt);
    C1 = GB_mex_kron (C, Mask, accum, op, AT, BT, dtt);
    GB_spec_compare (C0, C1) ;

    end
    end
    end
    end
    end
    end

end
end
end
end
end
end
end
end
end
end

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