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

« back to all changes in this revision

Viewing changes to BTF/MATLAB/Test/test4.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
 
%TEST4 test script for BTF
 
1
function test4 (nmat)
 
2
%TEST4 test for BTF
2
3
% Requires UFget
3
4
% Example:
4
5
%   test4
7
8
 
8
9
% Copyright 2007, Timothy A. Davis, University of Florida
9
10
 
10
 
clear ;
11
11
index = UFget ;
12
12
f = find (index.nrows == index.ncols) ;
13
13
[ignore i] = sort (index.nnz (f)) ;
14
14
f = f (i) ;
15
 
nmat = length (f) ;
16
 
 
17
 
for k = 1:nmat
18
 
 
19
 
    Prob = UFget (f (k), index) ;
20
 
    A = Prob.A ;
21
 
 
22
 
    for tr = [1 -1]
23
 
 
24
 
        if (tr == -1)
25
 
            AT = A' ;
26
 
            [m n] = size (A) ;
27
 
            if (m == n)
28
 
                if (nnz (spones (AT) - spones (A)) == 0)
29
 
                    fprintf ('skip transpose\n') ;
30
 
                    continue ;
31
 
                end
32
 
            end
33
 
            A = AT ;
34
 
        end
35
 
 
36
 
        tic
37
 
        [p1,q1,r1,work1] = btf (A) ;
38
 
        t1 = toc ;
39
 
        n1 = length (r1) - 1 ;
40
 
 
41
 
        tic
42
 
        [p2,q2,r2,work2] = btf (A, 10) ;
43
 
        t2 = toc ;
44
 
        n2 = length (r2) - 1 ;
45
 
 
46
 
        fprintf (...
47
 
        '%4d %4d : %10.4f %8d  %8g : %10.4f %8d  %8g : rel %8.4f %8.4f\n', ...
48
 
        k, f(k), t1, n1, work1, t2, n2, work2, t1 ./ t2, n2 ./ (max (1, n1))) ;
49
 
 
50
 
        if (n1 ~= n2 | work1 ~= work2)                                      %#ok
51
 
            disp (Prob) ;
52
 
            fprintf ('^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n') ;
53
 
        end
54
 
 
55
 
    end
56
 
end
57
 
 
 
15
 
 
16
% time intensive
 
17
skip_costly = [1514 1297 1876 1301] ;
 
18
f = setdiff (f, skip_costly) ;
 
19
 
 
20
if (nargin < 1)
 
21
    nmat = 1000 ;
 
22
end
 
23
nmat = min (nmat, length (f)) ;
 
24
f = f (1:nmat) ;
 
25
 
 
26
h = waitbar (0, 'BTF test 4 of 6') ;
 
27
 
 
28
try
 
29
    for k = 1:nmat
 
30
 
 
31
        Prob = UFget (f (k), 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 transpose\n') ;
 
44
                        continue ;
 
45
                    end
 
46
                end
 
47
                A = AT ;
 
48
            end
 
49
 
 
50
            tic
 
51
            [p1,q1,r1,work1] = btf (A) ;
 
52
            t1 = toc ;
 
53
            n1 = length (r1) - 1 ;
 
54
 
 
55
            tic
 
56
            [p2,q2,r2,work2] = btf (A, 10) ;
 
57
            t2 = toc ;
 
58
            n2 = length (r2) - 1 ;
 
59
 
 
60
            fprintf (...
 
61
                '%4d %4d : %10.4f %8d  %8g : %10.4f %8d  %8g :', ...
 
62
                k, f(k), t1, n1, work1, t2, n2, work2) ;
 
63
            if (t2 ~= 0)
 
64
                fprintf (' rel %8.4f %8.4f' , t1 / t2, n2 / (max (1, n1))) ;
 
65
            end
 
66
            fprintf ('\n') ;
 
67
 
 
68
            if (n1 ~= n2 | work1 ~= work2)                                  %#ok
 
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) ;