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

« back to all changes in this revision

Viewing changes to BTF/MATLAB/Test/test5.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
 
%TEST5 test script for BTF
 
1
function test5 (nmat)
 
2
%TEST5 test for BTF
2
3
% Requires UFget
3
4
% Example:
4
5
%   test5
7
8
 
8
9
% Copyright 2007, Timothy A. Davis, University of Florida
9
10
 
10
 
clear ;
11
11
index = UFget ;
12
12
 
13
13
[ignore f] = sort (index.nnz) ;
14
14
 
15
 
nmat = length(f) ;
16
 
 
17
 
for k = 1:nmat
18
 
 
19
 
    i = f(k) ;
20
 
    Prob = UFget (i, index) ;
21
 
    A = Prob.A ;
22
 
 
23
 
    for tr = [1 -1]
24
 
 
25
 
        if (tr == -1)
26
 
            AT = A' ;
27
 
            [m n] = size (A) ;
28
 
            if (m == n)
29
 
                if (nnz (spones (AT) - spones (A)) == 0)
30
 
                    fprintf ('skip test with transpose\n') ;
31
 
                    continue ;
32
 
                end
33
 
            end
34
 
            A = AT ;
35
 
        end
36
 
 
37
 
        tic
38
 
        q1 = maxtrans (A) ;
39
 
        t1 = toc ;
40
 
        r1 = sum (q1 > 0) ;
41
 
 
42
 
        tic
43
 
        q2 = maxtrans (A, 10) ;
44
 
        t2 = toc ;
45
 
        r2 = sum (q2 > 0) ;
46
 
 
47
 
        fprintf (...
48
 
            '%4d %4d : %10.4f %8d  : %10.4f %8d  : rel %8.4f %8.4f\n', ...
49
 
            k, f(k), t1, r1, t2, r2, t1 ./ t2, r2 ./ (max (1, r1))) ;
50
 
 
51
 
        if (r1 ~= r2)
52
 
            disp (Prob) ;
53
 
            fprintf ('^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n') ;
54
 
        end
55
 
 
56
 
    end
57
 
end
 
15
% time intensive
 
16
skip_costly = [1514 1297 1876 1301] ;
 
17
f = setdiff (f, skip_costly) ;
 
18
 
 
19
if (nargin < 1)
 
20
    nmat = 1000 ;
 
21
end
 
22
nmat = min (nmat, length (f)) ;
 
23
f = f (1:nmat) ;
 
24
 
 
25
h = waitbar (0, 'BTF test 5 of 6') ;
 
26
 
 
27
try
 
28
    for k = 1:nmat
 
29
 
 
30
        i = f(k) ;
 
31
        Prob = UFget (i, index) ;
 
32
        A = Prob.A ;
 
33
 
 
34
        waitbar (k/nmat, h) ;
 
35
 
 
36
        for tr = [1 -1]
 
37
 
 
38
            if (tr == -1)
 
39
                AT = A' ;
 
40
                [m n] = size (A) ;
 
41
                if (m == n)
 
42
                    if (nnz (spones (AT) - spones (A)) == 0)
 
43
                        fprintf ('skip test with transpose\n') ;
 
44
                        continue ;
 
45
                    end
 
46
                end
 
47
                A = AT ;
 
48
            end
 
49
 
 
50
            tic
 
51
            q1 = maxtrans (A) ;
 
52
            t1 = toc ;
 
53
            r1 = sum (q1 > 0) ;
 
54
 
 
55
            tic
 
56
            q2 = maxtrans (A, 10) ;
 
57
            t2 = toc ;
 
58
            r2 = sum (q2 > 0) ;
 
59
 
 
60
            fprintf (...
 
61
                '%4d %4d : %10.4f %8d  : %10.4f %8d', k, f(k), t1, r1, t2, r2) ;
 
62
            fprintf (' rel sprank %8.4f', r2 / (max (1, r1))) ;
 
63
            if (t2 ~= 0)
 
64
                fprintf (': rel time %8.4f', t1 / t2) ;
 
65
            end
 
66
            fprintf ('\n') ;
 
67
 
 
68
            if (r1 ~= r2)
 
69
                disp (Prob) ;
 
70
                fprintf ('^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n') ;
 
71
            end
 
72
 
 
73
        end
 
74
    end
 
75
 
 
76
catch
 
77
    % out-of-memory is OK, other errors are not
 
78
    disp (lasterr) ;
 
79
    if (isempty (strfind (lasterr, 'Out of memory')))
 
80
        error (lasterr) ;                                                   %#ok
 
81
    else
 
82
        fprintf ('test terminated early, but otherwise OK\n') ;
 
83
    end
 
84
end
 
85
 
 
86
close (h) ;