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
|
function test243
%TEST243 test GxB_Vector_Iterator
% 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) ;
n = 30 ;
GB_builtin_complex_set (true) ;
% scalar_in is dense and all zero
scalar_in.matrix = sparse (0) ;
scalar_in.pattern = true ;
desc.inp0 = 'tran' ;
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-11 ;
else
tol = 0 ;
end
X = [ ] ;
Y = [ ] ;
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 ;
ntrials = 51 ;
for X_sparsity = [2 4 8]
if (X_sparsity == 8)
fprintf ('X full: ') ;
elseif (X_sparsity == 4)
fprintf ('X bitmap: ') ;
elseif (X_sparsity == 2)
fprintf ('X sparse: ') ;
end
for Y_sparsity = [2 4 8]
if (Y_sparsity == 8)
fprintf ('Y full') ;
elseif (Y_sparsity == 4)
fprintf ('Y bitmap') ;
elseif (Y_sparsity == 2)
fprintf ('Y sparse') ;
end
for trial = 1:ntrials
fprintf ('.') ;
if (X_sparsity == 8 || trial >= 50)
X = GB_spec_random (n, 1, inf, 100, type) ;
else
d = trial / 200 ;
X = GB_spec_random (n, 1, d, 100, type) ;
end
X.sparsity = X_sparsity ;
X.is_csc = true ;
if (Y_sparsity == 8 || trial == 51)
Y = GB_spec_random (n, 1, inf, 100, type) ;
else
d = trial / 200 ;
Y = GB_spec_random (n, 1, d, 100, type) ;
end
Y.sparsity = Y_sparsity ;
Y.is_csc = true ;
% scalar is empty
scalar_in.class = type ;
scalar_in.iso = false ;
% y0 = X'*Y
y0 = GB_spec_mxm (scalar_in, [ ], accum, semiring, X, Y, desc) ;
% with vector iterator, with macros
y1 = GB_mex_dot_iterator (X, Y, 0) ;
GB_spec_compare (y0, y1, 0, tol) ;
% with vector iterator, brute force, with macros
y1 = GB_mex_dot_iterator (X, Y, 1) ;
GB_spec_compare (y0, y1, 0, tol) ;
% with vector iterator, with functions
y1 = GB_mex_dot_iterator (X, Y, 2) ;
GB_spec_compare (y0, y1, 0, tol) ;
% with vector iterator, brute force, with functions
y1 = GB_mex_dot_iterator (X, Y, 3) ;
GB_spec_compare (y0, y1, 0, tol) ;
end
fprintf ('\n') ;
end
end
end
GB_builtin_complex_set (true) ;
fprintf ('\ntest243: all tests passed\n') ;
|