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

« back to all changes in this revision

Viewing changes to CXSparse/MATLAB/Test/test21.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 test21
 
2
%TEST21 test cs_updown, chol_updown2
 
3
%
 
4
% Example:
 
5
%   test21
 
6
% See also: testall
 
7
 
 
8
%   Copyright 2006-2007, Timothy A. Davis.
 
9
%   http://www.cise.ufl.edu/research/sparse
 
10
 
 
11
 
 
12
clear functions
 
13
rand ('state', 0) ;
 
14
randn ('state', 0) ;
 
15
 
 
16
clf
 
17
 
 
18
for trials = 1:100
 
19
    if (trials <= 1)
 
20
        n = trials ;
 
21
    else
 
22
        n = 1+fix (100 * rand (1)) ;
 
23
    end
 
24
    fprintf ('n: %d\n', n) ;
 
25
    d = 0.1 * rand (1) ;
 
26
    A = sprandn (n,n,d) ;
 
27
    if (rand ( ) > .5)
 
28
        A = A + 1i * sprand (A) ;
 
29
    end
 
30
    A = A+A' + 100 * speye (n) ;
 
31
    try
 
32
        p = amd (A) ;
 
33
    catch
 
34
        p = symamd (A) ;
 
35
    end
 
36
    A = sparse (A (p,p)) ;
 
37
 
 
38
    try
 
39
        L = chol (A)' ;
 
40
    catch
 
41
        continue ;
 
42
    end
 
43
 
 
44
    parent = etree (A) ;
 
45
 
 
46
    subplot (1,3,1) ;
 
47
    spy (A) ;
 
48
 
 
49
    if (n > 0)
 
50
        subplot (1,3,2) ;
 
51
        treeplot (parent) ;
 
52
    end
 
53
 
 
54
    subplot (1,3,3) ;
 
55
    spy (L) ;
 
56
 
 
57
    drawnow
 
58
 
 
59
    for trials2 = 1:10
 
60
 
 
61
        k = 1+fix (n * rand (1)) ;
 
62
        if (k <= 0 | k > n)                                                 %#ok
 
63
            k = 1 ;
 
64
        end
 
65
 
 
66
        w = sprandn (L (:,k)) ;
 
67
        Anew = A + w*w' ;
 
68
 
 
69
        Lnew = cs_updown (L, w, parent) ;
 
70
        err6 = norm (Lnew*Lnew' - Anew, 1) ;
 
71
 
 
72
        Lnew = cs_updown (L, w, parent, '+') ;
 
73
        err7 = norm (Lnew*Lnew' - Anew, 1) ;
 
74
 
 
75
        [Lnew, wnew] = chol_updown2 (L, 1, w) ;
 
76
        err2 = norm (Lnew*Lnew' - Anew, 1) ;
 
77
        err10 = norm (wnew - (L\w)) ;
 
78
 
 
79
        L3 = chol_updown2 (L, +1, w) ;
 
80
        err9 = norm (L3*L3' - Anew, 1) ;
 
81
 
 
82
 
 
83
 
 
84
        [L2, wnew] = chol_updown2 (Lnew, -1, w) ;
 
85
        err3 = norm (L2*L2' - A, 1) ;
 
86
        err11 = norm (wnew - (Lnew\w)) ;
 
87
 
 
88
        L2 = cs_updown (Lnew, w, parent, '-') ;
 
89
        err5 = norm (L2*L2' - A, 1) ;
 
90
 
 
91
        L2 = chol_updown2 (Lnew, -1, w) ;
 
92
        err8 = norm (L2*L2' - A, 1) ;
 
93
 
 
94
        err = max ([err2 err3 err5 err6 err7 err9 err8 err10 err11]) ;
 
95
 
 
96
        fprintf ('   k %3d  %6.2e\n', k, err) ;
 
97
 
 
98
        if (err > 1e-11)
 
99
            err2        %#ok
 
100
            err3        %#ok
 
101
            err5        %#ok
 
102
            err6        %#ok
 
103
            err7        %#ok
 
104
            err8        %#ok
 
105
            err9        %#ok
 
106
            err10       %#ok
 
107
            err11       %#ok
 
108
            pause
 
109
        end
 
110
 
 
111
 
 
112
    end
 
113
    % pause
 
114
 
 
115
end