1function test15
2%TEST15 test cs_amd
3%
4% Example:
5%   test15
6% See also: testall
7
8% Copyright 2006-2012, Timothy A. Davis, http://www.suitesparse.com
9
10rand ('state', 0) ;
11randn ('state', 0) ;
12clf
13
14for trials = 1:100
15    n = fix (200 * rand (1)) ;
16    d = 0.05 * rand (1) ;
17    A = sprandn (n, n, d) ;
18
19    % add a randomly placed dense column
20    k = fix (n * rand (1)) ;
21    k = max (1, k) ;
22    k = min (n, k) ;
23    if (n > 0)
24        A (:,k) = 1 ;
25    end
26
27    if (~ispc)
28        if (rand ( ) > .5)
29            A = A + 1i * sprand (A) ;
30        end
31    end
32
33    try
34        p0 = amd (A) ;
35    catch
36        p0 = symamd (A) ;
37    end
38    p1 = cs_amd (A) ;
39
40    if (any (sort (p1) ~= 1:n))
41        error ('not perm!') ;
42    end
43
44    C = A+A' + speye (n) ;
45    lnz0 = sum (symbfact (C (p0,p0))) ;
46    lnz1 = sum (symbfact (C (p1,p1))) ;
47    subplot (1,3,1) ; spy (C)
48    subplot (1,3,2) ; spy (C (p0,p0))
49    subplot (1,3,3) ; spy (C (p1,p1))
50    fprintf ('n %4d nz %6d lnz %6d %6d\n', n, nnz(A), lnz0, lnz1) ;
51    drawnow
52
53end
54
55