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
|
function test72
%TEST72 special cases for mxm, ewise, ...
% SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2022, All Rights Reserved.
% SPDX-License-Identifier: Apache-2.0
fprintf ('\n--------------test72: special cases\n') ;
rng ('default') ;
clear
dnt = struct ( 'inp1', 'tran' ) ;
dtn = struct ( 'inp0', 'tran' ) ;
dtt = struct ( 'inp0', 'tran', 'inp1', 'tran' ) ;
n = 20 ;
p = randperm (n) ;
A = speye (n) ;
A = A (p,p) ;
B = sprand (n, n, 0.2) ;
Z = sparse (n, n) ;
semiring.multiply = 'times' ;
semiring.add = 'plus' ;
semiring.class = 'double' ;
Mask = sparse (ones (n)) ;
C0 = GB_spec_mxm (Z, Mask, [ ], semiring, A, B, dtt);
C1 = GB_mex_mxm (Z, Mask, [ ], semiring, A, B, dtt);
C2 = (A'*B') .* Mask ;
GB_spec_compare (C0, C1, 0) ;
assert (isequal (C2, C0.matrix)) ;
M = GB_mex_Matrix_eWiseAdd (Z, [ ], [ ], 'minus', Mask, Mask, [ ]) ;
C0 = GB_spec_mxm (Z, M.matrix, [ ], semiring, A, B, dtn);
C1 = GB_mex_mxm (Z, M.matrix, [ ], semiring, A, B, dtn);
GB_spec_compare (C0, C1, 0) ;
assert (isequal (Z, sparse (C0.matrix))) ;
n = 500 ;
% n = 4 ;
A = speye (n) ;
% A = sparse (rand (n)) ;
B = sparse (rand (n)) ;
Z = sparse (n,n) ;
C0 = GB_mex_Matrix_eWiseMult (Z, [ ], [ ], 'times', A, B, [ ]) ;
C1 = A .* B ;
assert (isequal (C1, sparse (C0.matrix))) ;
C0 = GB_mex_Matrix_eWiseMult (Z, [ ], [ ], 'times', B, A, [ ]) ;
C1 = B .* A ;
assert (isequal (C1, sparse (C0.matrix))) ;
A = logical (A) ;
C0 = GB_mex_Matrix_eWiseMult (Z, [ ], [ ], 'times', A, B, [ ]) ;
C1 = double (A) .* B ;
assert (isequal (C1, sparse (C0.matrix))) ;
C0 = GB_mex_Matrix_eWiseMult (Z, [ ], [ ], 'times', B, A, [ ]) ;
C1 = B .* double (A) ;
assert (isequal (C1, sparse (C0.matrix))) ;
M = sprand (n, n, 0.01) ;
C0 = GB_mex_mxm (Z, M, [ ], semiring, A, B, dnt) ;
C1 = (A*B') .* spones (M) ;
assert (isequal (C1, sparse (C0.matrix))) ;
fprintf ('test72: all tests passed\n') ;
|