1function test15 (nmat)
2%TEST15 test symbfact2 vs MATLAB
3% Example:
4%   test15(nmat)
5% See also cholmod_test
6
7% Copyright 2007, Timothy A. Davis, http://www.suitesparse.com
8
9fprintf ('=================================================================\n');
10
11index = ssget ;
12
13% only test matrices with nrows = 109000 or less.  large ones nearly always
14% cause a MATLAB segfault.
15f = find (index.nrows < 109000 & index.ncols < 109000) ;
16
17% sort by row /col dimension
18s = max (index.nrows, index.ncols) ;
19[ignore i] = sort (s (f)) ;
20f = f (i) ;
21
22if (nargin > 0)
23    nmat = max (0,nmat) ;
24    nmat = min (nmat, length (f)) ;
25    f = f (1:nmat) ;
26end
27
28fprintf ('Matrices to test: %d\n', length (f)) ;
29
30for i = f
31
32    % try
33
34	Problem = ssget (i) ;
35	A = spones (Problem.A) ;
36	[m n] = size (A) ;
37	fprintf ('\n%4d: %-20s nrow: %6d ncol: %6d nnz: %10d\n', ...
38	    i, Problem.name, m, n, nnz(A)) ;
39
40	% warmup, for accurate timing
41	etree (sparse (1)) ;
42	etree2 (sparse (1)) ;
43	amd2 (sparse (1)) ;
44	symbfact (sparse (1)) ;
45	symbfact2 (sparse (1)) ;
46
47	% test symmetric case
48	if (m == n)
49
50	    % permute the matrix first
51	    p = amd2 (A) ;
52	    A = A (p,p) ;
53
54	    % test with triu(A)
55	    tic
56	    co = symbfact (A) ;
57	    t1 = toc ;
58	    tic
59	    co2 = symbfact2 (A) ;
60	    t2 = toc ;
61
62	    fprintf ('c=symbfact(A):         %10.4f %10.4f  speedup %8.2f lnz %d\n', ...
63		t1, t2, t1/t2, sum (co)) ;
64
65	    if (any (co ~= co2))
66		error ('!') ;
67	    end
68
69	    tic
70	    [co h parent post R] = symbfact (A) ;
71	    t1 = toc ;
72	    tic
73	    [co2 h2 parent2 post2 R2] = symbfact2 (A) ;
74	    t2 = toc ;
75
76	    fprintf ('R=symbfact(A):         %10.4f %10.4f  speedup %8.2f\n',...
77		t1, t2, t1/t2) ;
78
79	    checkem(co,co2,parent,parent2,post,post2,R,R2,h,h2) ;
80
81	    % test with tril(A)
82	    tic
83	    co = symbfact (A') ;
84	    t1 = toc ;
85	    tic
86	    co2 = symbfact2 (A,'lo') ;
87	    t2 = toc ;
88
89	    fprintf (...
90	    'c=symbfact(A''):        %10.4f %10.4f  speedup %8.2f lnz %d\n',...
91		t1, t2, t1/t2, sum (co)) ;
92
93	    if (any (co ~= co2))
94		error ('!') ;
95	    end
96
97	    tic
98	    [co h parent post R] = symbfact (A') ;
99	    t1 = toc ;
100	    tic
101	    [co2 h2 parent2 post2 R2] = symbfact2 (A,'lo') ;
102	    t2 = toc ;
103
104	    fprintf (...
105		'R=symbfact(A''):        %10.4f %10.4f  speedup %8.2f\n',...
106		t1, t2, t1/t2) ;
107
108	    checkem(co,co2,parent,parent2,post,post2,R,R2,h,h2) ;
109
110	end
111
112	% permute the matrix first
113	p = colamd (A) ;
114	[parent post] = etree2 (A (:,p), 'col') ;
115	p = p (post) ;
116	A = A (:,p) ;
117
118	% test column case
119	tic
120	co = symbfact (A,'col') ;
121	t1 = toc ;
122	tic
123	co2 = symbfact2 (A,'col') ;
124	t2 = toc ;
125
126	fprintf ('c=symbfact(A,''col''):   %10.4f %10.4f  speedup %8.2f lnz %d\n', ...
127	    t1, t2, t1/t2, sum (co)) ;
128
129	if (any (co ~= co2))
130	    error ('!') ;
131	end
132
133	tic
134	[co h parent post R] = symbfact (A,'col') ;
135	t1 = toc ;
136	tic
137	[co2 h2 parent2 post2 R2] = symbfact2 (A,'col') ;
138	t2 = toc ;
139
140	fprintf ('R=symbfact(A,''col''):   %10.4f %10.4f  speedup %8.2f\n', ...
141	    t1, t2, t1/t2) ;
142
143	checkem(co,co2,parent,parent2,post,post2,R,R2,h,h2) ;
144
145%    catch
146%    	fprintf ('%d failed\n', i) ;
147%    end
148end
149
150fprintf ('test15 passed\n') ;
151
152%-------------------------------------------------------------------------------
153
154function checkem(co,co2,parent,parent2,post,post2,R,R2,h,h2)
155% checkem compare results from symbfact and symbfact2
156if (any (co ~= co2))
157    error ('count!') ;
158end
159if (any (parent ~= parent2))
160    error ('parent!') ;
161end
162if (any (post ~= post2))
163    error ('post!') ;
164end
165if (nnz (R2) ~= nnz (R))
166    error ('lnz!') ;
167end
168if (h ~= h2)
169    error ('h!') ;
170end
171% this may run out of memory
172try % compute nnz(R-R2)
173    err = nnz (R-R2) ;
174catch
175    err = -1 ;
176    fprintf ('nnz(R-R2) not computed\n')  ;
177end
178if (err > 0)
179    error ('R!') ;
180end
181