1function test28
2%TEST28 test cs_randperm, cs_dmperm
3%
4% Example:
5%   test28
6% See also: testall
7
8% Copyright 2006-2012, Timothy A. Davis, http://www.suitesparse.com
9
10clear functions
11
12rand ('state', 0) ;
13for n = 1:100
14    for trials = 1:1000
15        p = cs_randperm (n, rand) ;
16        if (any (sort (p) ~= 1:n))
17            n           %#ok
18            p           %#ok
19            error ('!')
20        end
21    end
22end
23
24index = ssget ;
25[ignore f] = sort (index.nnz) ;
26
27fprintf ('p=dmperm (std, rand, rev)  [p,q,r,s]=dmperm (std, rand, rev)\n') ;
28
29nmat = min (100, length (f)) ;
30T1 = zeros (nmat,1) ;
31T2 = zeros (nmat,1) ;
32T3 = zeros (nmat,1) ;
33D1 = zeros (nmat,1) ;
34D2 = zeros (nmat,1) ;
35D3 = zeros (nmat,1) ;
36
37
38for k = 1:nmat
39
40    i = f (k) ;
41    Prob = ssget (i,index) ;
42    A = Prob.A ;
43    [m n] = size (A) ;
44    fprintf ('%35s: ', Prob.name) ;
45
46    tic
47    p = cs_dmperm (A) ;
48    t1 = toc ;
49    sprank1 = sum (p > 0) ;
50    fprintf (' %8.2f', t1) ;
51    T1 (k) = t1 ;
52
53    tic
54    p = cs_dmperm (A,1) ;
55    t2 = toc ;
56    sprank2 = sum (p > 0) ;
57    fprintf (' %8.2f', t2) ;
58    T2 (k) = t2 ;
59
60    tic
61    p = cs_dmperm (A,-1) ;
62    t3 = toc ;
63    sprank3 = sum (p > 0) ;
64    fprintf (' %8.2f', t3) ;
65    T3 (k) = t3 ;
66
67    if (sprank1 ~= sprank2 | sprank1 ~= sprank3)                            %#ok
68        error ('!') ;
69    end
70
71    tic
72    [p1,q1,r1,s1,cc1,rr1] = cs_dmperm (A) ;                                 %#ok
73    d1 = toc ;
74    fprintf (' %8.2f', d1) ;
75    D1 (k) = d1 ;
76
77    tic
78    [p2,q2,r2,s2,cc2,rr2] = cs_dmperm (A,1) ;                               %#ok
79    d2 = toc ;
80    fprintf (' %8.2f', d2) ;
81    D2 (k) = d2 ;
82
83    tic
84    [p3,q3,r3,s3,cc3,rr3] = cs_dmperm (A,-1) ;                              %#ok
85    d3 = toc ;
86    fprintf (' %8.2f\n', d3) ;
87    D3 (k) = d3 ;
88
89    if (sprank1 == max (m,n))
90        nz1 = nnz (diag (A (p1,q1))) ;
91        nz2 = nnz (diag (A (p2,q2))) ;
92        nz3 = nnz (diag (A (p3,q3))) ;
93
94        if (nz1 ~= sprank1 | nz2 ~= sprank2 | nz3 ~= sprank3)               %#ok
95            error ('!')
96        end
97    end
98
99    subplot (1,2,1)
100    loglog (T1 (1:k), T2 (1:k), 'x', ...
101        T1 (1:k), T3 (1:k), 'go', ...
102        [1e-5 1e3], [1e-5 1e3], 'r-') ;
103    axis equal
104
105    subplot (1,2,2)
106    loglog (D1 (1:k), D2 (1:k), 'x', ...
107        D1 (1:k), D3 (1:k), 'go', ...
108        [1e-5 1e3], [1e-5 1e3], 'r-') ;
109    axis equal
110
111    drawnow
112end
113