1function test93 2%TEST93 test dpagerank and ipagerank 3 4% SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2021, All Rights Reserved. 5% SPDX-License-Identifier: Apache-2.0 6 7rng ('default') ; 8addpath ('../Demo/MATLAB') ; 9 10for n = [10 100 1000 1e4 1e5 ] % 1e6] 11 12 fprintf ('\n--------------n: %d\n', n) ; 13 nz = 8*n ; 14 d = nz / n^2 ; 15 A = sprand (n, n, d) ; 16 A = spones (A + speye (n)) ; 17% A = spones (A) ; 18% A (:,1) = 0 ; 19% A (1,:) = 0 ; 20 21 tic 22 [r1, i1] = dpagerank (A) ; 23 t1 = toc ; 24 25 [r2, i2] = GB_mex_dpagerank (A) ; 26 t2 = grbresults ; 27 28 % [i1' i2'] 29 30 % results won't be identical because of different random number generators 31 mismatch = length (find (i1 ~= i2)) ; 32 e = norm (r1 - r2) / norm (r1) ; 33 fprintf ('i1 i2 mismatch: %d\n', mismatch) ; 34 fprintf ('r1-r2 = %g\n', e) ; 35 fprintf ('time: MATLAB %g GraphBLAS %g speedup %g\n', t1, t2, t1/t2) ; 36 % if (n <= 1e5) 37 % assert (mismatch < 100) ; 38 % end 39 % assert (e < 1e-6) ; 40 41 tic 42 [r4, i4, iter4] = dpagerank2 (A) ; 43 t4 = toc ; 44 fprintf ('\nWith stopping criterion, iter: %d\n', iter4) ; 45 46 C.matrix = A ; 47 C.class = 'logical' ; 48 C.is_csc = false ; 49 50 [r3, i3, iter3] = GB_mex_dpagerank (C, 0) ; 51 t3 = grbresults ; 52 fprintf ('GraphBLAS method 2: time %g speedup %g iters %g\n', ... 53 t3, t4/t3, iter3) ; 54 e = norm (r2 - r3) / norm (r3) ; 55 % assert (e < 1e-12) ; 56 % assert (isequal (i3, i2)) ; 57 mismatch = length (find (i1 ~= i3)) ; 58 59 fprintf ('\ndpagerank2 version:\n') ; 60 fprintf ('i1 i3 mismatch: %d\n', mismatch) ; 61 fprintf ('r1-r3 = %g\n', e) ; 62 63 mismatch = length (find (i3 ~= i4)) ; 64 fprintf ('\ndpagerank2 version:\n') ; 65 fprintf ('i3 i4 mismatch: %d\n', mismatch) ; 66 fprintf ('r3-r4 = %g\n', e) ; 67 68 % test the integer versions 69 tic 70 [ir1, ii1] = ipagerank (A) ; 71 ti1 = toc ; 72 73 [ir2, ii2] = GB_mex_ipagerank (A) ; 74 ti2 = grbresults ; 75 76 % [ii1' ii2'] 77 78 ir1 = ir1 / norm (ir1) ; 79 ir2 = ir2 / norm (ir2) ; 80 81 % results won't be identical because of different random number generators 82 mismatch = length (find (ii1 ~= ii2)) ; 83 e = norm (ir1 - ir2) / norm (ir1) ; 84 fprintf ('i1 i2 mismatch: %d\n', mismatch) ; 85 fprintf ('r1-r2 = %g\n', e) ; 86 fprintf ('time: MATLAB %g GraphBLAS %g speedup %g\n', ti1, ti2, ti1/ti2) ; 87 if (n < 1e4) 88 assert (mismatch < n/10) ; 89 assert (e < 1e-4) ; 90 end 91 92end 93 94fprintf ('test93: all tests passed\n') ; 95 96