~logan/ubuntu/trusty/suitesparse/4.2.1-3ubuntu1

« back to all changes in this revision

Viewing changes to CXSparse_newfiles/MATLAB/Test/test10.m

  • Committer: Bazaar Package Importer
  • Author(s): Christophe Prud'homme
  • Date: 2007-05-29 09:36:29 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20070529093629-zowquo0b7slkk6nc
Tags: 3.0.0-2
* suitesparse builds properly twice in a row
* Bug fix: "suitesparse - FTBFS: Broken build depens: libgfortran1-dev",
  thanks to Bastian Blank (Closes: #426349).
* Bug fix: "suitesparse_3.0.0-1: FTBFS: build-depends on
  libgfortran1-dev", thanks to Steve Langasek (Closes: #426354).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
function test10
 
2
%TEST10 test cs_qr
 
3
%
 
4
% Example:
 
5
%   test10
 
6
% See also: testall
 
7
 
 
8
%   Copyright 2006-2007, Timothy A. Davis.
 
9
%   http://www.cise.ufl.edu/research/sparse
 
10
 
 
11
 
 
12
rand ('state', 0) ;
 
13
 
 
14
 
 
15
% f = 185 ;
 
16
% f = 449 ;
 
17
clf
 
18
 
 
19
for trials = 1:100
 
20
    
 
21
    m = fix (100 * rand (1)) ;
 
22
    n = fix (100 * rand (1)) ;
 
23
    d = 0.1 * rand (1) ;
 
24
    A = sprandn (m, n, d) ;
 
25
    [m n] = size (A) ;
 
26
    if (m < n)
 
27
        A = A' ;
 
28
    end
 
29
    [m n] = size (A) ;
 
30
    sp = sprank (A) ;
 
31
    % if (sp < n)
 
32
    %   continue ;
 
33
    % end
 
34
 
 
35
    for cmplex = 0:1
 
36
 
 
37
        if (cmplex)
 
38
            A = A + 1i * sprand (A) * norm (A,1) / 10 ;
 
39
        end
 
40
 
 
41
        Aorig = A ;
 
42
 
 
43
        % A = A (:, colamd (A)) ;
 
44
 
 
45
        if (cmplex)
 
46
            tic ;
 
47
            R = chol (A'*A + speye (n)) ;
 
48
            t1 = toc ;
 
49
        else
 
50
            tic ;
 
51
            R = qr (A) ;
 
52
            t1 = toc ;
 
53
        end
 
54
 
 
55
        % tic ;
 
56
        % [Q,R] = qr (A) ;
 
57
        % t1 = toc ;
 
58
 
 
59
        [c,h,parent] = symbfact (A, 'col') ;                                %#ok
 
60
        rnz = sum (c) ;                                                     %#ok
 
61
        tic ;
 
62
        [V2,Beta2,p,R2] = cs_qr (sparse(A)) ;
 
63
        t2 = toc ;
 
64
 
 
65
        C = A ;
 
66
        m2 = size (V2,1) ;
 
67
        if (m2 > m)
 
68
            C = [A ; sparse(m2-m, n)] ;
 
69
        end
 
70
        C = C (p,:) ;
 
71
 
 
72
        [H1,R1] = myqr (C) ;
 
73
        err1 = norm (R1-R2,1) / norm (R1) ;
 
74
        disp ('err1 = ') ;
 
75
        disp (err1) ;
 
76
        % [svd(A) svd(R1) svd(full(R2))]
 
77
        s1 = svd (full (A)) ;
 
78
        s2 = svd (full (R2)) ;
 
79
        if (n > 0)
 
80
            err2 = norm (s1 - s2) / s1 (1)  ;
 
81
            disp ('err2 = ') ;
 
82
            disp (err2) ;
 
83
        else
 
84
            err2 = 0 ;
 
85
        end
 
86
        fprintf ('%10.6f %10.6f  cs speedup %8.3f sprank %d vs %d\n', t1, t2, t1/t2, sp, n) ;
 
87
 
 
88
        % H2 = full (H2)
 
89
        % R2 = full (R2)
 
90
 
 
91
        subplot (2,4,1) ; spy (A) ;             title ('A colamd') ;
 
92
        subplot (2,4,4) ; spy (Aorig) ; title ('Aorig') ;
 
93
        subplot (2,4,2) ; spy (C) ;             title ('A rperm') ;
 
94
        subplot (2,4,5) ; spy (abs(R2)>0) ;     title ('spqr R, no zeros') ;
 
95
        subplot (2,4,6) ; spy (R) ;             title ('matlab R') ;
 
96
        subplot (2,4,7) ; spy (R2) ;    title ('spqr R') ;
 
97
        subplot (2,4,8) ; spy (V2) ;    title ('spqr H') ;
 
98
        drawnow
 
99
 
 
100
        if (err2 > 1e-9)
 
101
            error ('!') ;
 
102
        end
 
103
 
 
104
        if (m2 > m)
 
105
            fprintf ('added %d rows, sprank %d n %d\n', m2-m, sp, n) ;
 
106
        end
 
107
    end
 
108
end