File: test16.m

package info (click to toggle)
suitesparse-metis 3.1.0-2
  • links: PTS, VCS
  • area: contrib
  • in suites: jessie, jessie-kfreebsd, wheezy
  • size: 36,560 kB
  • ctags: 7,484
  • sloc: ansic: 104,515; makefile: 5,984; fortran: 4,591; sh: 1,397; csh: 739; ruby: 603; perl: 219; sed: 164; awk: 18
file content (90 lines) | stat: -rw-r--r-- 1,812 bytes parent folder | download | duplicates (3)
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
function test16
%TEST16 test cs_amd
%
% Example:
%   test16
% See also: testall

%   Copyright 2006-2007, Timothy A. Davis.
%   http://www.cise.ufl.edu/research/sparse

rand ('state', 0) ;
randn ('state', 0) ;
clf

index = UFget ;
[ignore f] = sort (max (index.nrows, index.ncols)) ;
f = f (1:200) ;
skip = 811 ;

% f = 719

for i = f
    if (any (i == skip))
	continue
    end
    Prob = UFget (i) ;
    A = spones (Prob.A) ;
    Aorig = A ;
    [m n] = size (A) ;
    if (m < n)
	A = A' ;
    end
    [m n] = size (A) ;
    if (m ~= n)
	A = A'*A ;
    end

    fprintf ('n %4d nz %d\n', n, nnz (A)) ;

    try
	p0 = amd (A) ;
    catch
	p0 = symamd (A) ;
    end
    fprintf ('symmetric case:\n') ;
    p1 = cs_amd (A) ;

    if (any (sort (p1) ~= 1:n))
	error ('not perm!') ;
    end

    C = A+A' + speye (n) ;
    lnz0 = sum (symbfact (C (p0,p0))) ;
    lnz1 = sum (symbfact (C (p1,p1))) ;
    subplot (2,3,1) ; spy (C)
    subplot (2,3,2) ; spy (C (p0,p0)) ; title ('amd') ;
    subplot (2,3,3) ; spy (C (p1,p1)) ; title ('csamd') ;
    drawnow

    if (lnz0 ~= lnz1)
	fprintf ('----------------- lnz %d %d   %9.4f\n', ...
	    lnz0, lnz1, 100*(lnz0-lnz1)/max([1 lnz0])) ;
    end

    if (1)

	p0 = colamd (Aorig) ;
	[m n] = size (Aorig) ;
	fprintf ('m %d n %d\n', m, n) ;

	fprintf ('A''A case, no dense rows (for QR):\n') ;
	p1 = cs_amd (Aorig, 3) ;
	if (any (sort (p1) ~= 1:n))
	    error ('not perm!') ;
	end

	subplot (2,3,4) ; spy (Aorig)
	subplot (2,3,5) ; spy (Aorig (:,p0)) ; title ('colamd') ;
	subplot (2,3,6) ; spy (Aorig (:,p1)) ; title ('cs amd(A''A)') ;
	lnz0 = sum (symbfact (Aorig (:,p0), 'col')) ;
	lnz1 = sum (symbfact (Aorig (:,p1), 'col')) ;
	fprintf ('                    A''A: %7d %7d %9.4f\n', ...
	    lnz0, lnz1, 100*(lnz0-lnz1)/max([1 lnz0])) ;
	drawnow

	% pause

    end
end