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
|
function gbtest61
%GBTEST61 test GrB.laplacian
% SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2022, All Rights Reserved.
% SPDX-License-Identifier: Apache-2.0
rng ('default') ;
n = 10 ;
A = sprand (n, n, 0.4) ;
S = tril (A, -1) ;
S = S+S' ;
G = GrB (S) ;
L0 = laplacian (graph (S, 'OmitSelfLoops')) ;
% GrB.laplacian places explicit zeros on the diagonal
L1 = GrB.laplacian (S) ;
L2 = GrB.laplacian (G) ;
L3 = GrB.laplacian (G, 'double', 'check') ;
assert (norm (L0-L1,1) == 0) ;
assert (isequal (GrB.offdiag (L0), GrB.offdiag (L1))) ;
assert (isequal (L0, double (L1))) ;
assert (isequal (L1, L2)) ;
assert (isequal (L1, L3)) ;
G = GrB (G, 'by row') ;
L2 = GrB.laplacian (G) ;
L3 = GrB.laplacian (G, 'double', 'check') ;
assert (norm (L0-L2,1) == 0) ;
assert (isequal (GrB.offdiag (L0), GrB.offdiag (L2))) ;
assert (isequal (L2, L3)) ;
types = { 'double', 'single', 'int8', 'int16', 'int32', 'int64' } ;
for k = 1:6
type = types {k} ;
L2 = GrB.laplacian (G, type) ;
assert (isequal (GrB.type (L2), type)) ;
assert (isequal (L0, double (L2))) ;
end
fprintf ('gbtest61: all tests passed\n') ;
|