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 244 245 246 247 248 249 250 251 252 253 254 255 256
|
function test21b (fulltest)
%TEST21B test GrB_assign
% SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2022, All Rights Reserved.
% SPDX-License-Identifier: Apache-2.0
if (nargin < 1)
% do a short test, by default
fulltest = 0 ;
end
[binops, ~, ~, types, ~, ~] = GB_spec_opsall ;
accum_ops = binops.all ;
types = types.all ;
dn = struct ;
dt = struct ( 'inp0', 'tran' ) ;
if (fulltest)
fprintf ('\ntest21b --------------exhaustive test of GB_mex_assign\n') ;
k1test = 0:length(accum_ops) ;
else
fprintf ('\ntest21b --------------quick test of GB_mex_assign\n') ;
k1test = [0 4] ; % Was [0 2 4] ;
end
quick = 0 ;
% try all accum
for k1 = k1test
if (k1 == 0)
accum_op = '' ;
ntypes = 1 ;
else
accum_op = accum_ops {k1} ;
ntypes = length (types) ;
end
fprintf ('\naccum: [%s]', accum_op) ;
if (fulltest)
k2test = 1:ntypes ;
else
k2test = [1 11] ; % Was [1 2 11] ;
end
% try all types
for k2 = k2test % 1:ntypes
clear accum
if (~isempty (accum_op))
accum_type = types {k2} ;
accum.opname = accum_op ;
accum.optype = accum_type ;
else
accum = '' ;
accum_type = '' ;
end
if (GB_spec_is_positional (accum))
continue ;
end
try
GB_spec_operator (accum) ;
catch
continue ;
end
rng (k1 * 100 + k2, 'v4') ;
for Mask_complement = [false true]
if (Mask_complement)
dn.mask = 'complement' ;
dt.mask = 'complement' ;
else
dn.mask = 'default' ;
dt.mask = 'default' ;
end
for C_replace = [true false]
if (C_replace)
% fprintf ('C_replace') ;
dn.outp = 'replace' ;
dt.outp = 'replace' ;
else
dn.outp = 'default' ;
dt.outp = 'default' ;
end
kk3 = randperm (length (types), 1) ;
% try all matrix types, to test casting
for k3 = kk3 % 1:length (types)
atype = types {k3} ;
% try some matrices
for m = [1 5 10 ]
for n = [ 1 5 10 ]
for sm = [ -3 -2 -1 0 1 5 10 ]
if (sm > m)
continue
end
fprintf ('.') ;
for sn = [ 0 1 5 10 ]
if (sn > n)
continue
end
for scalar = [false true]
if (sm == -3)
% I = (m-2):-2:1
if (m < 5)
continue
end
clear I0
I0.begin = m-3 ;
I0.inc = -2 ;
I0.end = 0 ;
I = (m-2):-2:1 ;
am = length (I) ;
elseif (sm == -2)
% I = 1:2:(m-2)
if (m < 5)
continue
end
clear I0
I0.begin = 0 ;
I0.inc = 2 ;
I0.end = m-3 ;
I = 1:2:(m-2) ;
am = length (I) ;
elseif (sm == -1)
% I = 1:(m-2)
if (m < 5)
continue
end
clear I0
I0.begin = 0 ;
I0.end = m-3 ;
I = 1:(m-2) ;
am = length (I) ;
elseif (sm == 0)
% I = ":"
I = [ ] ;
am = m ;
I0 = uint64 (I-1) ;
else
% I = random list of length sm
I = randperm (m,sm) ;
am = sm ;
I0 = uint64 (I-1) ;
end
if (sn == 0)
J = [ ] ;
an = n ;
else
J = randperm (n,sn) ; % J = J(1:sn);
an = sn ;
end
J0 = uint64 (J-1) ;
for A_is_hyper = 0:1
for A_is_csc = 0:1
for C_is_hyper = 0:1
for C_is_csc = 0:1
for M_is_hyper = 0:1
for M_is_csc = 0:1
quick = quick+1 ;
if (~fulltest)
% only do every 11th test
if (mod (quick, 11) ~= 1)
continue
end
end
if (scalar)
% test scalar expansion
% fprintf ('test expansion\n') ;
A.matrix = sparse (rand (1)) * 100 ;
A.pattern = sparse (logical (true));
A.class = atype ;
if (A_is_hyper || ~A_is_csc)
continue
end
else
A = GB_spec_random (am,an,0.2,100,atype, A_is_csc, A_is_hyper) ;
end
C = GB_spec_random (m,n,0.2,100,atype, C_is_csc, C_is_hyper) ;
Mask = GB_random_mask (m,n,0.2, M_is_csc, M_is_hyper) ;
% C(I,J) = accum (C (I,J),A)
% Mask = [ ] ;
C0 = GB_spec_assign (C, [ ], accum, A, I, J, dn, scalar);
C1 = GB_mex_assign (C, [ ], accum, A, I0, J0, dn);
GB_spec_compare (C0, C1) ;
% C<Mask>(I,J) = accum (C (I,J),A)
C0 = GB_spec_assign (C, Mask, accum, A, I, J, dn, scalar);
C1 = GB_mex_assign (C, Mask, accum, A, I0, J0, dn);
GB_spec_compare (C0, C1) ;
%---------------------------------------
% C<Mask>(I,J) = accum (C(I,J), A');
% note transposing twice
clear AT
AT.matrix = A.matrix' ;
AT.pattern = A.pattern' ;
AT.class = A.class ;
C0 = GB_spec_assign (C, [ ], accum, AT, I, J, dt, scalar);
C1 = GB_mex_assign (C, [ ], accum, AT, I0, J0, dt);
GB_spec_compare (C0, C1) ;
C0 = GB_spec_assign (C, Mask, accum, AT, I, J, dt, scalar);
C1 = GB_mex_assign (C, Mask, accum, AT, I0, J0, dt);
GB_spec_compare (C0, C1) ;
%---------------------------------------
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
fprintf ('\ntest21b: all tests passed\n') ;
|