~ubuntu-branches/ubuntu/hardy/suitesparse/hardy

« back to all changes in this revision

Viewing changes to BTF/MATLAB/Test/test6.m

  • Committer: Bazaar Package Importer
  • Author(s): Rafael Laboissiere, Rafael Laboissiere, Ondrej Certik
  • Date: 2008-02-21 14:46:50 UTC
  • mfrom: (1.1.2 upstream) (5.1.1 hardy)
  • Revision ID: james.westby@ubuntu.com-20080221144650-tgeppgj0t7s759i8
Tags: 3.1.0-3
[ Rafael Laboissiere ]
* Upload to unstable

[ Ondrej Certik ]
* XS-DM-Upload-Allowed: yes field added
* Ondrej Certik added to uploaders

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
function test6
 
2
%TEST6 test for BTF
 
3
% Requires UFget
 
4
% Example:
 
5
%   test6
 
6
% See also btf, maxtrans, strongcomp, dmperm, UFget,
 
7
%   test1, test2, test3, test4, test5.
 
8
 
 
9
% Copyright 2007, Timothy A. Davis, University of Florida
 
10
 
 
11
quick2 = [ ...
 
12
 1522 -272  1463  1521   460 1507  -838 1533 -1533 -1456 -1512   734   211 ...
 
13
 -385 -735   394  -397  1109 -744  ...
 
14
 -734 -375 -1200 -1536  -837  519  -519  520  -520   189  -189   454   385 ...
 
15
  387 -387   384  -384   386 -386   388 -388   525  -525   526  -526   735 ...
 
16
 1508  209   210  1243 -1243 1534  -840 1234 -1234   390  -390   392  -392 ...
 
17
 -394 1472  1242 -1242   389 -389   391 -391   393  -393  1215 -1215  1216 ...
 
18
-1216  736  -736   737  -737  455  -455 -224  -839  1426 -1426 -1473   396 ...
 
19
 -396  398  -398   400  -400  402  -402  404  -404 -1531   395  -395   397 ...
 
20
  399 -399   401  -401   403 -403   405 -405  -738  -739  1459 -1459  1111 ...
 
21
 1110  376  -376   284  -284 -740  -742 -741  -743  1293 -1293   452   920 ...
 
22
 -745 -446  1462 -1461   448 -448   283 -283  1502 -1502  1292 -1292  1503 ...
 
23
-1503 1291 -1291   445  -445 -746  -747 1300 -1300   435  -435 -1343 -1345 ...
 
24
-1344 1305 -1305   921 -1513 1307 -1307 1369 -1369  1374 -1374  1377 ...
 
25
-1377  748  -748  -749  1510  922  -922 ] ;
 
26
 
 
27
index = UFget ;
 
28
nmat = length (quick2) ;
 
29
dopause = 0 ;
 
30
 
 
31
h = waitbar (0, 'BTF test 6 of 6') ;
 
32
 
 
33
try
 
34
 
 
35
    for k = 1:nmat
 
36
 
 
37
        waitbar (k/nmat, h) ;
 
38
 
 
39
        i = quick2 (k) ;
 
40
        Prob = UFget (abs (i), index) ;
 
41
        disp (Prob) ;
 
42
        if (i < 0)
 
43
            fprintf ('transposed\n') ;
 
44
            A = Prob.A' ;
 
45
            [m n] = size (A) ;
 
46
            if (m == n)
 
47
                if (nnz (spones (A) - spones (Prob.A)) == 0)
 
48
                    fprintf ('skip...\n') ;
 
49
                    continue ;
 
50
                end
 
51
            end
 
52
        else
 
53
            A = Prob.A ;
 
54
        end
 
55
 
 
56
        tic
 
57
        [p1,q1,r1,work1] = btf (A) ;
 
58
        t1 = toc ;
 
59
        n1 = length (r1) - 1 ;
 
60
        m1 = nnz (diag (A (p1, abs (q1)))) ;
 
61
 
 
62
        limit = work1/nnz(A) ;
 
63
 
 
64
        fprintf ('full search: %g * nnz(A)\n', limit) ;
 
65
 
 
66
        works = linspace(0,limit,9) ;
 
67
        works (1) = eps ;
 
68
        nw = length (works) ;
 
69
 
 
70
        T2 = zeros (nw, 1) ;
 
71
        N2 = zeros (nw, 1) ;
 
72
        M2 = zeros (nw, 1) ;
 
73
 
 
74
        T2 (end) = t1 ;
 
75
        N2 (end) = n1 ;
 
76
        M2 (end) = m1 ;
 
77
 
 
78
        fprintf ('full time %10.4f   blocks %8d  nnz(diag) %8d\n\n', t1, n1, m1) ;
 
79
 
 
80
        subplot (3,4,4) ;
 
81
        drawbtf (A, p1, abs (q1), r1) ;
 
82
        title (Prob.name, 'Interpreter', 'none') ;
 
83
 
 
84
        for j = 1:nw-1
 
85
 
 
86
            maxwork = works (j) ;
 
87
 
 
88
            tic
 
89
            [p2,q2,r2,work2] = btf (A, maxwork) ;
 
90
            t2 = toc ;
 
91
            n2 = length (r2) - 1 ;
 
92
            m2 = nnz (diag (A (p2, abs (q2)))) ;
 
93
            T2 (j) = t2 ;
 
94
            N2 (j) = n2 ;
 
95
            M2 (j) = m2 ;
 
96
 
 
97
            fprintf ('%9.1f %10.4f   blocks %8d  nnz(diag) %8d\n', ...
 
98
                maxwork, t2, n2, m2) ;
 
99
 
 
100
            subplot (3,4,4+j) ;
 
101
            drawbtf (A, p2, abs (q2), r2) ;
 
102
            title (sprintf ('%g', maxwork)) ;
 
103
 
 
104
            ss = [1:j nw] ;
 
105
 
 
106
            subplot (3,4,1) ;
 
107
            plot (works(ss), T2(ss), 'o-') ;  title ('time vs work') ;
 
108
            axis ([0 limit 0 max(0.1,max(T2))]) ;
 
109
 
 
110
            subplot (3,4,2) ;
 
111
            plot (works(ss), N2(ss), 'o-') ; title ('blocks vs work') ;
 
112
            axis ([0 limit 0 n1]) ;
 
113
 
 
114
            subplot (3,4,3) ;
 
115
            plot (works(ss), M2(ss), 'o-') ; title ('nnz(diag) vs work') ;
 
116
            axis ([0 limit 0 m1]) ;
 
117
            drawnow
 
118
 
 
119
        end
 
120
        fprintf ('full time %10.4f   blocks %8d  nnz(diag) %8d\n', t1, n1, m1) ;
 
121
 
 
122
        if (dopause)
 
123
            input ('hit enter: ') ;
 
124
        end
 
125
 
 
126
    end
 
127
 
 
128
catch
 
129
    % out-of-memory is OK, other errors are not
 
130
    disp (lasterr) ;
 
131
    if (isempty (strfind (lasterr, 'Out of memory')))
 
132
        error (lasterr) ;                                                   %#ok
 
133
    else
 
134
        fprintf ('test terminated early, but otherwise OK\n') ;
 
135
    end
 
136
end
 
137
 
 
138
close (h) ;