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

« back to all changes in this revision

Viewing changes to CXSparse_newfiles/MATLAB/Test/test19.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 test19
 
2
%TEST19 test cs_dmperm, cs_maxtransr, cs_dmspy, cs_scc, cspy
 
3
%
 
4
% Example:
 
5
%   test19
 
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
 
 
14
randn ('state', 0) ;
 
15
rand ('state', 0) ;
 
16
 
 
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
    d = rand (1) * 4 * max (m,n) / max (m*n,1) ;
 
25
    A = sprandn (m,n,d) ;
 
26
    S = sprandn (m,m,d) + speye (m) ;
 
27
 
 
28
    if (rand ( ) > .5)
 
29
        A = A + 1i * sprand (A) ;
 
30
    end
 
31
 
 
32
    if (rand ( ) > .5)
 
33
        S = S + 1i * sprand (S) ;
 
34
    end
 
35
 
 
36
    subplot (2,3,1) ;
 
37
    cspy (A) ;
 
38
 
 
39
    pp = dmperm (A) ;
 
40
 
 
41
    sprnk = sum (pp > 0) ;
 
42
 
 
43
    pp2 = cs_dmperm (A) ;
 
44
    spr2 = sum (pp2 > 0) ;
 
45
    if (spr2 ~= sprnk)
 
46
        error ('!')
 
47
    end
 
48
 
 
49
    pp2 = cs_maxtransr (A) ;
 
50
    spr2 = sum (pp2 > 0) ;
 
51
    if (spr2 ~= sprnk)
 
52
        error ('!')
 
53
    end
 
54
 
 
55
    [p,q,r,s] = dmperm (A) ;
 
56
    C = A (p,q) ;
 
57
    % r
 
58
    % s
 
59
 
 
60
    nk = length (r) - 1 ;
 
61
 
 
62
    fprintf ('sprnk: %d  m %d n %d   nb: %d\n', sprnk, m, n, nk) ;
 
63
 
 
64
    subplot (2,3,2) ;
 
65
    hold off
 
66
    spy (C)
 
67
    hold on
 
68
 
 
69
    for k = 1:nk
 
70
        r1 = r(k) ;
 
71
        r2 = r(k+1) ;
 
72
        c1 = s(k)  ;
 
73
        c2 = s(k+1) ;
 
74
        plot ([c1 c2 c2 c1 c1]-.5, [r1 r1 r2 r2 r1]-.5, 'g') ;
 
75
    end
 
76
 
 
77
    [p2,q2,rr2,ss2,cp,rp] = cs_dmperm (A) ;
 
78
 
 
79
    if (min (m,n) > 0)
 
80
        if (length (rr2) ~= length (r))
 
81
            error ('# fine blocks!') ;
 
82
        end
 
83
    end
 
84
 
 
85
    if (rp (4) - 1 ~= sprnk)
 
86
        rp              %#ok
 
87
        sprnk           %#ok
 
88
        error ('!') ;
 
89
    end
 
90
 
 
91
    if (any (sort (p2) ~= 1:m))
 
92
        error ('p2!') ;
 
93
    end
 
94
 
 
95
    if (any (sort (q2) ~= 1:n))
 
96
        error ('q2!') ;
 
97
    end
 
98
 
 
99
    if (cp (5) ~= n+1)
 
100
        error ('cp!') ;
 
101
    end
 
102
 
 
103
    if (rp (5) ~= m+1)
 
104
        error ('rp!') ;
 
105
    end
 
106
 
 
107
    C = A (p2,q2) ;
 
108
 
 
109
    subplot (2,3,3) ; cs_dmspy (A,0) ;
 
110
 
 
111
    % hold off
 
112
    % spy (C) ;
 
113
    % hold on
 
114
 
 
115
    % r1 = rp(1) ;
 
116
    % r2 = rp(2) ;
 
117
    % c1 = cp(1)  ;
 
118
    % c2 = cp(2) ;
 
119
    % plot ([c1 c2 c2 c1 c1]-.5, [r1 r1 r2 r2 r1]-.5, 'g') ;
 
120
 
 
121
    r1 = rp(1) ;
 
122
    r2 = rp(2) ;
 
123
    c1 = cp(2) ;
 
124
    c2 = cp(3) ;
 
125
    % plot ([c1 c2 c2 c1 c1]-.5, [r1 r1 r2 r2 r1]-.5, 'g') ;
 
126
 
 
127
    B = C (r1:r2-1, c1:c2-1) ;
 
128
    if (nnz (diag (B)) ~= size (B,1))
 
129
        error ('C1 diag!') ;
 
130
    end
 
131
 
 
132
    r1 = rp(2) ;
 
133
    r2 = rp(3) ;
 
134
    c1 = cp(3) ;
 
135
    c2 = cp(4) ;
 
136
    % plot ([c1 c2 c2 c1 c1]-.5, [r1 r1 r2 r2 r1]-.5, 'r') ;
 
137
 
 
138
    B = C (r1:r2-1, c1:c2-1) ;
 
139
    if (nnz (diag (B)) ~= size (B,1))
 
140
        error ('C2 diag!') ;
 
141
    end
 
142
 
 
143
    r1 = rp(3) ;
 
144
    r2 = rp(4) ;
 
145
    c1 = cp(4) ;
 
146
    c2 = cp(5) ;
 
147
    % plot ([c1 c2 c2 c1 c1]-.5, [r1 r1 r2 r2 r1]-.5, 'g') ;
 
148
 
 
149
    B = C (r1:r2-1, c1:c2-1) ;
 
150
    if (nnz (diag (B)) ~= size (B,1))
 
151
        error ('C3 diag!') ;
 
152
    end
 
153
 
 
154
    r1 = rp(4) ;                                                            %#ok
 
155
    r2 = rp(5) ;                                                            %#ok
 
156
    c1 = cp(4) ;                                                            %#ok
 
157
    c2 = cp(5) ;                                                            %#ok
 
158
    % plot ([c1 c2 c2 c1 c1]-.5, [r1 r1 r2 r2 r1]-.5, 'g') ;
 
159
 
 
160
    if (~isempty (S))
 
161
 
 
162
        [p1,q1,r0,s0] = dmperm (S) ;
 
163
        [p3,r3] = cs_scc (S) ;
 
164
        if (length (r3) ~= length (r0))
 
165
            error ('scc size!') ;
 
166
        end
 
167
 
 
168
        if (any (sort (p3) ~= 1:m))
 
169
            error ('scc perm!') ;
 
170
        end
 
171
 
 
172
        nk = length (r0)-1 ;
 
173
 
 
174
        subplot (2,3,4) ;
 
175
        hold off
 
176
        spy (S (p1,q1)) ;
 
177
        hold on
 
178
        for k = 1:nk
 
179
            r1 = r0(k) ;
 
180
            r2 = r0(k+1) ;
 
181
            c1 = s0(k)  ;
 
182
            c2 = s0(k+1) ;
 
183
            plot ([c1 c2 c2 c1 c1]-.5, [r1 r1 r2 r2 r1]-.5, 'g') ;
 
184
        end
 
185
 
 
186
        subplot (2,3,5) ;
 
187
        hold off
 
188
        spy (S (p3,p3)) ;
 
189
        hold on
 
190
        for k = 1:nk
 
191
            r1 = r3(k) ;
 
192
            r2 = r3(k+1) ;
 
193
            c1 = r3(k)  ;
 
194
            c2 = r3(k+1) ;
 
195
            plot ([c1 c2 c2 c1 c1]-.5, [r1 r1 r2 r2 r1]-.5, 'g') ;
 
196
        end
 
197
 
 
198
    end
 
199
 
 
200
    subplot (2,3,6) ;
 
201
    cs_dmspy (A) ;
 
202
    drawnow
 
203
   % pause
 
204
 
 
205
 
 
206
 
 
207
 
 
208
end