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