File: test15.m

package info (click to toggle)
suitesparse 1%3A5.12.0%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 176,720 kB
  • sloc: ansic: 1,193,914; cpp: 31,704; makefile: 6,638; fortran: 1,927; java: 1,826; csh: 765; ruby: 725; sh: 529; python: 333; perl: 225; sed: 164; awk: 35
file content (180 lines) | stat: -rw-r--r-- 3,742 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
function test15 (nmat)
%TEST15 test symbfact2 vs MATLAB
% Example:
%   test15(nmat)
% See also cholmod_test

% Copyright 2007, Timothy A. Davis, http://www.suitesparse.com

fprintf ('=================================================================\n');

index = ssget ;

% only test matrices with nrows = 109000 or less.  large ones nearly always
% cause a MATLAB segfault.
f = find (index.nrows < 109000 & index.ncols < 109000) ;

% sort by row /col dimension
s = max (index.nrows, index.ncols) ;
[ignore i] = sort (s (f)) ;
f = f (i) ;

if (nargin > 0)
    nmat = max (0,nmat) ;
    nmat = min (nmat, length (f)) ;
    f = f (1:nmat) ;
end

fprintf ('Matrices to test: %d\n', length (f)) ;

for i = f

    % try

	Problem = ssget (i) ;
	A = spones (Problem.A) ;
	[m n] = size (A) ;
	fprintf ('\n%4d: %-20s nrow: %6d ncol: %6d nnz: %10d\n', ...
	    i, Problem.name, m, n, nnz(A)) ;

	% warmup, for accurate timing
	etree (sparse (1)) ;
	etree2 (sparse (1)) ;
	amd2 (sparse (1)) ;
	symbfact (sparse (1)) ;
	symbfact2 (sparse (1)) ;

	% test symmetric case
	if (m == n)

	    % permute the matrix first
	    p = amd2 (A) ;
	    A = A (p,p) ;

	    % test with triu(A)
	    tic
	    co = symbfact (A) ;
	    t1 = toc ;
	    tic
	    co2 = symbfact2 (A) ;
	    t2 = toc ;

	    fprintf ('c=symbfact(A):         %10.4f %10.4f  speedup %8.2f lnz %d\n', ...
		t1, t2, t1/t2, sum (co)) ;

	    if (any (co ~= co2))
		error ('!') ;
	    end

	    tic
	    [co h parent post R] = symbfact (A) ;
	    t1 = toc ;
	    tic
	    [co2 h2 parent2 post2 R2] = symbfact2 (A) ;
	    t2 = toc ;

	    fprintf ('R=symbfact(A):         %10.4f %10.4f  speedup %8.2f\n',...
		t1, t2, t1/t2) ;

	    checkem(co,co2,parent,parent2,post,post2,R,R2,h,h2) ;

	    % test with tril(A)
	    tic
	    co = symbfact (A') ;
	    t1 = toc ;
	    tic
	    co2 = symbfact2 (A,'lo') ;
	    t2 = toc ;

	    fprintf (...
	    'c=symbfact(A''):        %10.4f %10.4f  speedup %8.2f lnz %d\n',...
		t1, t2, t1/t2, sum (co)) ;

	    if (any (co ~= co2))
		error ('!') ;
	    end

	    tic
	    [co h parent post R] = symbfact (A') ;
	    t1 = toc ;
	    tic
	    [co2 h2 parent2 post2 R2] = symbfact2 (A,'lo') ;
	    t2 = toc ;

	    fprintf (...
		'R=symbfact(A''):        %10.4f %10.4f  speedup %8.2f\n',...
		t1, t2, t1/t2) ;

	    checkem(co,co2,parent,parent2,post,post2,R,R2,h,h2) ;

	end

	% permute the matrix first
	p = colamd (A) ;
	[parent post] = etree2 (A (:,p), 'col') ;
	p = p (post) ;
	A = A (:,p) ;

	% test column case
	tic
	co = symbfact (A,'col') ;
	t1 = toc ;
	tic
	co2 = symbfact2 (A,'col') ;
	t2 = toc ;

	fprintf ('c=symbfact(A,''col''):   %10.4f %10.4f  speedup %8.2f lnz %d\n', ...
	    t1, t2, t1/t2, sum (co)) ;

	if (any (co ~= co2))
	    error ('!') ;
	end

	tic
	[co h parent post R] = symbfact (A,'col') ;
	t1 = toc ;
	tic
	[co2 h2 parent2 post2 R2] = symbfact2 (A,'col') ;
	t2 = toc ;

	fprintf ('R=symbfact(A,''col''):   %10.4f %10.4f  speedup %8.2f\n', ...
	    t1, t2, t1/t2) ;

	checkem(co,co2,parent,parent2,post,post2,R,R2,h,h2) ;

%    catch
%    	fprintf ('%d failed\n', i) ;
%    end
end

fprintf ('test15 passed\n') ;

%-------------------------------------------------------------------------------

function checkem(co,co2,parent,parent2,post,post2,R,R2,h,h2)
% checkem compare results from symbfact and symbfact2
if (any (co ~= co2))
    error ('count!') ;
end
if (any (parent ~= parent2))
    error ('parent!') ;
end
if (any (post ~= post2))
    error ('post!') ;
end
if (nnz (R2) ~= nnz (R))
    error ('lnz!') ;
end
if (h ~= h2)
    error ('h!') ;
end
% this may run out of memory
try % compute nnz(R-R2)
    err = nnz (R-R2) ;
catch
    err = -1 ;
    fprintf ('nnz(R-R2) not computed\n')  ;
end
if (err > 0)
    error ('R!') ;
end