~ubuntu-branches/ubuntu/natty/suitesparse/natty

« back to all changes in this revision

Viewing changes to CHOLMOD/MATLAB/Test/test12.m

  • Committer: Bazaar Package Importer
  • Author(s): Christophe Prud'homme
  • Date: 2006-12-22 10:16:15 UTC
  • Revision ID: james.westby@ubuntu.com-20061222101615-2ohaj8902oix2rnk
Tags: upstream-2.3.1
ImportĀ upstreamĀ versionĀ 2.3.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
function test12 (nmat)
 
2
% test12(nmat): test etree2 and compare with etree
 
3
fprintf ('=================================================================\n');
 
4
fprintf ('test12: test etree2 and compare with etree\n') ;
 
5
 
 
6
index = UFget ;
 
7
 
 
8
% only test matrices with nrows = 109000 or less.  large ones nearly always
 
9
% cause a MATLAB segfault.
 
10
% f = find (index.nrows < 109000) ;
 
11
f = 1:length (index.nrows) ;
 
12
 
 
13
% sort by row dimension
 
14
[ignore i] = sort (index.nrows (f)) ;
 
15
f = f (i) ;
 
16
 
 
17
if (nargin > 0)
 
18
    nmat = max (0,nmat) ;
 
19
    nmat = min (nmat, length (f)) ;
 
20
    f = f (1:nmat) ;
 
21
end
 
22
 
 
23
% MATLAB 7.0 (R14, sp2, linux) etree gives a segfault for these matrices:
 
24
s_skip =   [ 803 374 1287 1311 1308 957 958 1257 955 761 1282 1230 1256 ...
 
25
            924 1302 537 820 821 822 1258 ...
 
26
            844 845 1238 804 939 1270 1305 1208 1209 290 879 928 1307 1244 ...
 
27
            1275 1276 1296 885 1269 959 542 1290 ] ;
 
28
 
 
29
sym_skip = [ s_skip ] ;
 
30
 
 
31
p_sym_skip =  [ 1296 ] ;
 
32
p_symt_skip = [ 1296 ] ;
 
33
 
 
34
symt_skip= [ s_skip 592 593 809 ] ;
 
35
 
 
36
rowcol_skip = [ 646 ...
 
37
             1224 803 588 589 374 1287 562 563 801 1311 1246 951 1308 950 ...
 
38
             957 958 800 1257 564 565 955 761 1282 590 591 1230 1256 952 566 ...
 
39
             567 924 1302 1293 1294 537 820 821 822 1306 849 1258 592 593 ...
 
40
             1225 844 845 1226 1238 1227 804 939 1270 752 753 1305 809 1228 ...
 
41
             1208 1209 1291 1292 1300 856 1229 290 879 928 1307 857 1244  ...
 
42
             1275 1276 1296 885 858 859 1269 1263 959 542 1290 ] ;
 
43
 
 
44
col_skip = [ rowcol_skip 647 612 610 648 799 651 652 750 751 640 ] ;
 
45
 
 
46
row_skip= [ rowcol_skip 903 373 ] ;
 
47
 
 
48
% f = f (find (f == 1290) : end) ;
 
49
 
 
50
fprintf ('Matrices to test: %d\n', length (f)) ;
 
51
 
 
52
 
 
53
for i = f
 
54
 
 
55
    % try
 
56
 
 
57
        Problem = UFget (i) ;
 
58
        A = spones (Problem.A) ;
 
59
        [m n] = size (A) ;
 
60
        fprintf ('\n%4d: %-20s nrow: %6d ncol: %6d nnz: %10d\n', ...
 
61
            i, Problem.name, m, n, nnz(A)) ;
 
62
 
 
63
        % if (max (m,n) < 500)
 
64
        %    A = full (A) ;
 
65
        % end
 
66
 
 
67
        % warmup, for accurate timing
 
68
        etree (sparse (1)) ;
 
69
        etree2 (sparse (1)) ;
 
70
        amd (sparse (1)) ;
 
71
 
 
72
        % test column etree
 
73
        skip = any (i == col_skip) || m > 109000 ;
 
74
        if (~skip)
 
75
            tic ;
 
76
            [parent post] = etree (A, 'col') ;
 
77
            t1 = toc ;
 
78
        else
 
79
            t1 = Inf ;
 
80
        end
 
81
 
 
82
        tic ;
 
83
        [my_parent my_post] = etree2 (A, 'col') ;
 
84
        t2 = toc ;
 
85
 
 
86
        if (~skip)
 
87
            if (any (parent ~= my_parent))
 
88
                error ('parent invalid!') ;
 
89
            end
 
90
        end
 
91
        fprintf ('etree(A,''col''): %8.4f  %8.4f              speedup %8.2f  ',...
 
92
                t1, t2, t1/t2);
 
93
        if (~skip)
 
94
            if (any (post ~= my_post))
 
95
                fprintf ('postorder differs') ;
 
96
            end
 
97
        end
 
98
        fprintf ('\n') ;
 
99
 
 
100
        % test row etree
 
101
        skip = any (i == row_skip) || m > 109000 ;
 
102
        if (~skip)
 
103
            tic ;
 
104
            [parent post] = etree (A', 'col') ;
 
105
            t1 = toc ;
 
106
        else
 
107
            t1 = Inf ;
 
108
        end
 
109
 
 
110
        tic ;
 
111
        [my_parent my_post] = etree2 (A, 'row') ;
 
112
        t2 = toc ;
 
113
 
 
114
        if (~skip)
 
115
            if (any (parent ~= my_parent))
 
116
                error ('parent invalid!') ;
 
117
            end
 
118
        end
 
119
        fprintf ('etree(A,''row''): %8.4f  %8.4f              speedup %8.2f  ',...
 
120
                t1, t2, t1/t2);
 
121
        if (~skip)
 
122
            if (any (post ~= my_post))
 
123
                fprintf ('postorder differs') ;
 
124
            end
 
125
        end
 
126
        fprintf ('\n') ;
 
127
 
 
128
 
 
129
 
 
130
        if (m == n)
 
131
 
 
132
            for trial = 1:2
 
133
 
 
134
                if (trial == 1)
 
135
                    skip1 = any (i == sym_skip)  || m > 109000 ;
 
136
                    skip2 = any (i == symt_skip) || m > 109000 ;
 
137
                else
 
138
                    skip1 = any (i == p_sym_skip)  || m > 109000 ;
 
139
                    skip2 = any (i == p_symt_skip) || m > 109000 ;
 
140
                    fprintf ('after amd:\n') ;
 
141
                    p = amd (A) ;
 
142
                    A = A (p,p) ;
 
143
                end
 
144
 
 
145
                % test symmetric etree, using triu(A)
 
146
                if (~skip1)
 
147
                    tic ;
 
148
                    [parent post] = etree (A) ;
 
149
                    t1 = toc ;
 
150
                else
 
151
                    t1 = Inf ;
 
152
                end
 
153
 
 
154
                tic ;
 
155
                [my_parent my_post] = etree2 (A) ;
 
156
                t2 = toc ;
 
157
 
 
158
                if (~skip1)
 
159
                    if (any (parent ~= my_parent))
 
160
                        error ('parent invalid!') ;
 
161
                    end
 
162
                end
 
163
                fprintf ('etree(A):       %8.4f  %8.4f              speedup %8.2f  ',...
 
164
                        t1, t2, t1/t2);
 
165
                if (~skip1)
 
166
                    if (any (post ~= my_post))
 
167
                        fprintf ('postorder differs') ;
 
168
                    end
 
169
                end
 
170
                fprintf ('\n') ;
 
171
 
 
172
                % test symmetric etree, using tril(A)
 
173
                if (~skip2)
 
174
                    tic ;
 
175
                    [parent post] = etree (A') ;
 
176
                    t1 = toc ;
 
177
                else
 
178
                    t1 = Inf ;
 
179
                end
 
180
 
 
181
                tic ;
 
182
                [my_parent my_post] = etree2 (A, 'lo') ;
 
183
                t2 = toc ;
 
184
 
 
185
                if (~skip2)
 
186
                    if (any (parent ~= my_parent))
 
187
                        error ('parent invalid!') ;
 
188
                    end
 
189
                end
 
190
                fprintf('etree(A''):      %8.4f  %8.4f              speedup %8.2f  ',...
 
191
                        t1, t2, t1/t2);
 
192
                if (~skip2)
 
193
                    if (any (post ~= my_post))
 
194
                        fprintf ('postorder differs') ;
 
195
                    end
 
196
                end
 
197
                fprintf ('\n') ;
 
198
 
 
199
            end
 
200
 
 
201
        end
 
202
 
 
203
    % catch
 
204
        % fprintf ('%d: failed\n', i) ;
 
205
    % end
 
206
end
 
207
 
 
208
fprintf ('test12 passed\n') ;