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
|
function test128
%TEST128 test eWiseMult, eWiseAdd, eWiseUnion, special cases
% SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2022, All Rights Reserved.
% SPDX-License-Identifier: Apache-2.0
fprintf ('\ntest128: test eWiseMult, eWiseAdd, eWiseUnion, special cases\n') ;
rng ('default') ;
m = 100 ;
n = 100 ;
Mmat = sparse (m,n) ;
Mmat (1,:) = 1 ;
Amat = sparse (rand (m,n)) ;
Amat (:, 2) = 0 ;
Amat (:, 5) = 0 ;
Amat (1, 5) = 1 ;
Amat (2, 6) = 0 ;
Bmat = sparse (rand (m,n)) ;
Bmat (:, 3:4) = 0 ;
Bmat (:, 6) = 0 ;
Bmat (1, 6) = 1 ;
Amat (2, 5) = 0 ;
clear M
M.matrix = Mmat ;
M.pattern = logical (spones (Mmat)) ;
M.class = 'logical' ;
clear A
A.matrix = Amat ;
A.pattern = logical (spones (Amat)) ;
A.class = 'double' ;
clear B
B.matrix = Bmat ;
B.pattern = logical (spones (Bmat)) ;
B.class = 'double' ;
S = sparse (m,n) ;
X = sparse (rand (m,n)) ;
% test the workaround for the GB_COMPILER_MSC_2019 bug in the
% Microsoft C compiler
A.class = 'single complex' ;
B.class = 'single complex' ;
T.matrix = sparse (m,n) ;
T.class = 'single complex' ;
GrB.burble (1) ;
for B_hyper = 0:1
for A_hyper = 0:1
A.is_hyper = A_hyper ;
B.is_hyper = B_hyper ;
C1 = GB_spec_Matrix_eWiseUnion(T, [ ], [ ], 'first', A, 1, B, 2, [ ]) ;
C4 = GB_mex_Matrix_eWiseUnion (T, [ ], [ ], 'first', A, 1, B, 2, [ ]) ;
GB_spec_compare (C1, C4) ;
C1 = GB_spec_Matrix_eWiseUnion(T, [ ], [ ], 'second', A, 1, B, 2, [ ]) ;
C4 = GB_mex_Matrix_eWiseUnion (T, [ ], [ ], 'second', A, 1, B, 2, [ ]) ;
GB_spec_compare (C1, C4) ;
end
end
GrB.burble (0) ;
A.class = 'double' ;
B.class = 'double' ;
for B_hyper = 0:1
for A_hyper = 0:1
A.is_hyper = A_hyper ;
B.is_hyper = B_hyper ;
for M_hyper = 0:1
M.is_hyper = M_hyper ;
C0 = Amat .* Bmat .* Mmat ;
C1 = GB_spec_Matrix_eWiseMult (S, M, [ ], 'times', A, B, [ ]) ;
C2 = GB_mex_Matrix_eWiseMult (S, M, [ ], 'times', A, B, [ ]) ;
C3 = GB_mex_Matrix_eWiseMult (S, M, [ ], 'times', B, A, [ ]) ;
GB_spec_compare (C1, C2) ;
GB_spec_compare (C1, C3) ;
assert (isequal (C0, C2.matrix)) ;
C0 = (Amat + Bmat) .* Mmat ;
C1 = GB_spec_Matrix_eWiseAdd (S, M, [ ], 'plus', A, B, [ ]) ;
C2 = GB_mex_Matrix_eWiseAdd (S, M, [ ], 'plus', A, B, [ ]) ;
C3 = GB_mex_Matrix_eWiseAdd (S, M, [ ], 'plus', B, A, [ ]) ;
C4 = GB_mex_Matrix_eWiseUnion(S, M, [ ], 'plus', A, 0, B, 0, [ ]) ;
GB_spec_compare (C1, C2) ;
GB_spec_compare (C1, C3) ;
GB_spec_compare (C1, C4) ;
assert (isequal (C0, C2.matrix)) ;
C1 = GB_spec_Matrix_eWiseMult (X, M, [ ], 'times', A, B, [ ]) ;
C2 = GB_mex_Matrix_eWiseMult (X, M, [ ], 'times', A, B, [ ]) ;
GB_spec_compare (C1, C2) ;
C1 = GB_spec_Matrix_eWiseAdd (X, M, [ ], 'plus', A, B, [ ]) ;
C2 = GB_mex_Matrix_eWiseAdd (X, M, [ ], 'plus', A, B, [ ]) ;
C3 = GB_mex_Matrix_eWiseUnion(X, M, [ ], 'plus', A, 0, B, 0,[ ]) ;
GB_spec_compare (C1, C2) ;
GB_spec_compare (C1, C3) ;
end
C0 = Amat .* Bmat ;
C1 = GB_spec_Matrix_eWiseMult (S, [ ], [ ], 'times', A, B, [ ]) ;
C2 = GB_mex_Matrix_eWiseMult (S, [ ], [ ], 'times', A, B, [ ]) ;
C3 = GB_mex_Matrix_eWiseMult (S, [ ], [ ], 'times', B, A, [ ]) ;
GB_spec_compare (C1, C2) ;
GB_spec_compare (C1, C3) ;
assert (isequal (C0, C2.matrix)) ;
C0 = Amat + Bmat ;
C1 = GB_spec_Matrix_eWiseAdd (S, [ ], [ ], 'plus', A, B, [ ]) ;
C2 = GB_mex_Matrix_eWiseAdd (S, [ ], [ ], 'plus', A, B, [ ]) ;
C3 = GB_mex_Matrix_eWiseAdd (S, [ ], [ ], 'plus', B, A, [ ]) ;
C4 = GB_mex_Matrix_eWiseUnion(S, [ ], [ ], 'plus', A, 0, B, 0, [ ]) ;
GB_spec_compare (C1, C2) ;
GB_spec_compare (C1, C3) ;
GB_spec_compare (C1, C4) ;
assert (isequal (C0, C2.matrix)) ;
C1 = GB_spec_Matrix_eWiseMult (X, [ ], [ ], 'times', A, B, [ ]) ;
C2 = GB_mex_Matrix_eWiseMult (X, [ ], [ ], 'times', A, B, [ ]) ;
GB_spec_compare (C1, C2) ;
C1 = GB_spec_Matrix_eWiseAdd (X, [ ], [ ], 'plus', A, B, [ ]) ;
C2 = GB_mex_Matrix_eWiseAdd (X, [ ], [ ], 'plus', A, B, [ ]) ;
C3 = GB_mex_Matrix_eWiseUnion(X, [ ], [ ], 'plus', A, 0, B, 0, [ ]) ;
GB_spec_compare (C1, C2) ;
GB_spec_compare (C1, C3) ;
end
end
fprintf ('test128: all tests passed\n') ;
|