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
|
function test209
%TEST209 test iso build
% SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2022, All Rights Reserved.
% SPDX-License-Identifier: Apache-2.0
rng ('default') ;
GB_builtin_complex_set (true) ;
[~, ~, ~, types ~, ~,] = GB_spec_opsall ;
types = types.all ;
op.opname = 'second' ;
% GrB.burble (1) ;
n = 100 ;
m = 200 ;
nnz = 1000 ;
I = irand (0, m-1, nnz, 1) ;
I1 = double (I) + 1 ;
J = irand (0, n-1, nnz, 1) ;
Y = 10 * rand (nnz, 1) ;
Yimag = 10 * rand (nnz, 1) ;
ntypes = 1+length(types) ;
for k = 1:ntypes
type = types {min (k, length (types))} ;
fprintf ('%s ', type) ;
if (test_contains (type, 'complex') && k <= length (types)) ;
% the build is generic if Y is double and op is complex
Y = Y + 1i * Yimag ;
end
X = GB_mex_cast (Y, type) ;
Z = X (1) ;
X (:) = Z ;
op.optype = type ;
% non-iso matrix build
C1 = GB_mex_Matrix_build (I, J, X, m, n, op, type) ;
C2 = GB_spec_build (I, J, X, m, n, op) ;
GB_spec_compare (C1, C2) ;
% iso matrix build
C1 = GB_mex_Matrix_build (I, J, Z, m, n, op, type) ;
C2 = GB_spec_build (I, J, X, m, n, op) ;
GB_spec_compare (C1, C2) ;
% non-iso vector build
C1 = GB_mex_Vector_build (I, X, m, op, type) ;
C2 = GB_spec_build (I, [ ], X, m, 1, op) ;
GB_spec_compare (C1, C2) ;
% iso vector build
C1 = GB_mex_Vector_build (I, Z, m, op, type) ;
C2 = GB_spec_build (I, [ ], X, m, 1, op) ;
GB_spec_compare (C1, C2) ;
end
% large iso vector build
n = 1 ;
m = 200e6 ;
nnz = 4e6 ;
X = true (nnz, 1) ;
Z = X (1) ;
I = irand (0, m-1, nnz, 1) ;
I1 = double (I) + 1 ;
C1 = GB_mex_Vector_build (I, Z, m, op, type) ;
C2 = logical (sparse (I1, 1, X, m, 1)) ;
assert (isequal (C1.matrix, C2)) ;
GrB.burble (0) ;
fprintf ('\ntest209: all tests passed\n') ;
|