5590
|
1 #!/bin/sh |
|
2 |
7019
|
3 # Copyright (C) 2006, 2007 David Bateman |
|
4 # |
|
5 # This file is part of Octave. |
|
6 # |
|
7 # Octave is free software; you can redistribute it and/or modify it |
|
8 # under the terms of the GNU General Public License as published by the |
|
9 # Free Software Foundation; either version 3 of the License, or (at |
|
10 # your option) any later version. |
|
11 # |
|
12 # Octave is distributed in the hope that it will be useful, but WITHOUT |
|
13 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
14 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
15 # for more details. |
|
16 # |
|
17 # You should have received a copy of the GNU General Public License |
|
18 # along with Octave; see the file COPYING. If not, see |
|
19 # <http://www.gnu.org/licenses/>. |
|
20 |
5590
|
21 # Some tests are commented out because they are known to be broken! |
|
22 # Search for "# fails" |
|
23 |
|
24 # ./buildtest.sh preset |
|
25 # creates test_sparse.m with preset tests. |
|
26 # Use "test test_sparse" from octave to run the tests. |
|
27 # |
|
28 # ./buildtest.sh random |
|
29 # Creates test_sprandom.m with randomly generated matrices. |
|
30 |
|
31 # buildtest.sh generates tests for real and complex sparse matrices. |
|
32 # Also, we want to run both fixed tests with known outputs (quick tests) |
|
33 # and longer tests with unknown outputs (thorough tests). This requires |
|
34 # two sets of tests --- one which uses preset matrices and another which |
|
35 # uses randomly generated matrices. |
|
36 # |
|
37 # The tests are mostly identical for each case but the code is different, |
|
38 # so it is important that the tests be run on all cases. Because our test |
|
39 # harness doesn't have support for looping or macros (it is only needed |
|
40 # for new data types), but sh does, we use sh to generate inline versions of |
|
41 # the tests for each case. |
|
42 # |
|
43 # Our 'macros' use shared variables as parameters. This allows us to |
|
44 # for example define A complex and include all the unary ops tests, |
|
45 # then set A=real(A) and include all the unary ops tests. Thus the |
|
46 # same tests work for real and complex. For binary tests it is even |
|
47 # more complicated because we want full X sparse, sparse X full and |
|
48 # sparse X sparse tested. |
|
49 # |
|
50 # We use the following macros: |
|
51 # |
|
52 # gen_section |
|
53 # place a separator in the test file |
|
54 # gen_function |
|
55 # define the function definion |
|
56 # helper gen_specific |
|
57 # specific tests such as error handling and null input |
|
58 # helper gen_eat_zeros |
|
59 # make sure sparse-scalar ops which generate 0 work |
|
60 # gen_specific_tests |
|
61 # specific and eat zeros tests |
|
62 # helper gen_ordering_tests |
|
63 # ordered comparison operators for real valued tests |
|
64 # helper gen_sparsesparse_ordering_tests |
|
65 # ordered comparison operators for real valued sparse-sparse tests |
|
66 # helper gen_elementop_tests |
|
67 # element-wise matrix binary operators, including scalar-matrix ops. |
|
68 # horizontal/vertical concatenation are here as well. |
|
69 # helper gen_sparsesparse_elementop_tests |
|
70 # element-wise matrix binary operators, for sparse-sparse ops. |
|
71 # horizontal/vertical concatenation are here as well. |
|
72 # helper gen_divop_tests |
|
73 # left and right matrix division operators of rectangular matrices. |
|
74 # Needs QR solvers |
|
75 # helper gen_square_divop_tests |
|
76 # left and right matrix division operators of square matrices. |
|
77 # helper gen_matrixop_tests |
|
78 # rectangular matrix binary operators: * |
|
79 # helper gen_matrixdiag_tests |
|
80 # Tests extract of diag and creation of diagonal matrices using |
|
81 # diag and spdiags functions |
|
82 # helper gen_matrixreshape_tests |
|
83 # Test the reshape function on sparse matrices |
|
84 # helper print_mapper_test |
|
85 # sub-helper function of gen_mapper_tests to print individual tests |
|
86 # helper gen_mapper_tests |
|
87 # Tests all of the one argument mapper functions. There are a few |
|
88 # specific tests that abs, real and imag return real values. |
|
89 # helper gen_unaryop_tests |
|
90 # functions and operators which transform a single matrix |
|
91 # helper gen_save_tests |
|
92 # Tests the load/save functionality for ascii/binary and hdf5 formats |
|
93 # gen_scalar_tests |
|
94 # element ops for real and complex scalar and sparse |
|
95 # gen_rectangular_tests |
|
96 # unary, element, and matrix tests for a and full/sparse b |
|
97 # gen_square_tests |
|
98 # operations which require square matrices: lu, inv, \ |
|
99 # A square non-singular matrix is defined from the rectangular |
|
100 # inputs A and B. |
|
101 # gen_assembly_tests |
|
102 # test for sparse constructors with 'sum' vs. 'unique' |
|
103 # gen_select_tests |
|
104 # indexing tests |
|
105 # gen_solver_tests |
|
106 # Tests the solve function with triangular/banded, etc matrices |
|
107 |
|
108 case $1 in |
|
109 random) preset=false ;; |
|
110 preset) preset=true ;; |
|
111 '') preset=true ;; |
|
112 *) echo "buildtest.sh random|preset" && exit 1 ;; |
|
113 esac |
|
114 |
|
115 if $preset; then |
|
116 TESTS=test_sparse.m |
|
117 else |
|
118 TESTS=test_sprandom.m |
|
119 fi |
|
120 |
|
121 # create initial file |
|
122 cat >$TESTS <<EOF |
|
123 ## THIS IS AN AUTOMATICALLY GENERATED FILE --- DO NOT EDIT --- |
|
124 ## instead modify build_sparse_tests.sh to generate the tests that you want. |
|
125 EOF |
|
126 |
|
127 |
|
128 # define all functions |
|
129 |
|
130 |
|
131 # ======================================================= |
|
132 # Section separator |
|
133 |
|
134 gen_section() { |
|
135 cat >>$TESTS <<EOF |
|
136 |
|
137 # ============================================================== |
|
138 |
|
139 EOF |
|
140 } |
|
141 |
|
142 |
|
143 # ======================================================= |
|
144 # Specific preset tests |
|
145 |
|
146 # ======================================================= |
|
147 # If a sparse operation yields zeros, then those elements |
|
148 # of the returned sparse matrix should be eaten. |
|
149 gen_eat_zeros() { |
|
150 cat >>$TESTS <<EOF |
|
151 %% Make sure newly introduced zeros get eaten |
|
152 %!assert(nnz(sparse([bf,bf,1]).^realmax),1); |
|
153 %!assert(nnz(sparse([1,bf,bf]).^realmax),1); |
|
154 %!assert(nnz(sparse([bf,bf,bf]).^realmax),0); |
|
155 |
|
156 %!assert(nnz(sparse([bf;bf;1]).^realmax),1); |
|
157 %!assert(nnz(sparse([1;bf;bf]).^realmax),1); |
|
158 %!assert(nnz(sparse([0.5;bf;bf]).^realmax),0); |
|
159 |
|
160 %!assert(nnz(sparse([bf,bf,1])*realmin),1); |
|
161 %!assert(nnz(sparse([1,bf,bf])*realmin),1); |
|
162 %!assert(nnz(sparse([bf,bf,bf])*realmin),0); |
|
163 |
|
164 %!assert(nnz(sparse([bf;bf;1])*realmin),1); |
|
165 %!assert(nnz(sparse([1;bf;bf])*realmin),1); |
|
166 %!assert(nnz(sparse([bf;bf;bf])*realmin),0); |
|
167 |
|
168 EOF |
|
169 } |
|
170 |
|
171 gen_specific() { |
|
172 cat >>$TESTS <<EOF |
|
173 |
|
174 %!test # segfault test from edd@debian.org |
|
175 %! n = 510; |
|
176 %! sparse(kron((1:n)', ones(n,1)), kron(ones(n,1), (1:n)'), ones(n)); |
|
177 |
|
178 %% segfault tests from Fabian@isas-berlin.de |
|
179 %% Note that the last four do not fail, but rather give a warning |
|
180 %% of a singular matrix, which is consistent with the full matrix |
|
181 %% behaviour. They are therefore disabled.. |
|
182 %!assert(spinv(sparse([1,1;1,1+i])),sparse([1-1i,1i;1i,-1i]),10*eps); |
|
183 % !error spinv( sparse( [1,1;1,1] ) ); |
|
184 % !error spinv( sparse( [0,0;0,1] ) ); |
|
185 % !error spinv( sparse( [0,0;0,1+i] ) ); |
|
186 % !error spinv( sparse( [0,0;0,0] ) ); |
|
187 |
|
188 %% error handling in constructor |
|
189 %!error sparse(1,[2,3],[1,2,3]); |
|
190 %!error sparse([1,1],[1,1],[1,2],3,3,"bogus"); |
|
191 %!error sparse([1,3],[1,-4],[3,5],2,2); |
|
192 %!error sparse([1,3],[1,-4],[3,5i],2,2); |
|
193 %!error sparse(-1,-1,1); |
|
194 EOF |
|
195 } |
|
196 |
|
197 |
|
198 gen_specific_tests() { |
|
199 gen_section |
|
200 gen_specific |
|
201 gen_section |
|
202 echo '%!shared bf' >> $TESTS |
|
203 echo '%!test bf=realmin;' >> $TESTS |
|
204 gen_eat_zeros |
|
205 echo '%!test bf=realmin+realmin*1i;' >> $TESTS |
|
206 gen_eat_zeros |
|
207 cat >>$TESTS <<EOF |
|
208 %!assert(nnz(sparse([-1,realmin,realmin]).^1.5),1); |
|
209 %!assert(nnz(sparse([-1,realmin,realmin,1]).^1.5),2); |
|
210 |
|
211 %!assert(nnz(sparse(1,1,0)),0); # Make sure scalar v==0 doesn't confuse matters |
|
212 %!assert(nnz(sparse(eye(3))*0),0); |
|
213 %!assert(nnz(sparse(eye(3))-sparse(eye(3))),0); |
|
214 |
|
215 %!test |
5781
|
216 %! wdbz = warning ("query", "Octave:divide-by-zero"); |
|
217 %! warning ("off", "Octave:divide-by-zero"); |
7197
|
218 %! assert(full(sparse(eye(3))/0),eye(3)/0); |
5781
|
219 %! warning (wdbz.state, "Octave:divide-by-zero"); |
5590
|
220 |
|
221 EOF |
|
222 } |
|
223 |
|
224 |
|
225 # ======================================================= |
|
226 # Main function definition |
|
227 |
|
228 gen_function() { |
|
229 if $preset; then |
|
230 cat >>$TESTS <<EOF |
|
231 ## |
|
232 ## test_sparse |
|
233 ## |
|
234 ## run preset sparse tests. All should pass. |
|
235 function [passes,tests] = test_sparse |
|
236 disp("writing test output to sptest.log"); |
|
237 test("test_sparse","normal","sptest.log"); |
|
238 endfunction |
|
239 |
|
240 EOF |
|
241 else |
|
242 cat >>$TESTS <<EOF |
|
243 ## |
|
244 ## test_sprandom |
|
245 ## |
|
246 ## total_passes=0; total_tests=0; |
|
247 ## for i=1:10 |
|
248 ## [passes,tests] = sprandomtest; |
|
249 ## total_passes += passes; |
|
250 ## total_tests += tests; |
|
251 ## end |
|
252 ## The test log is appended to sprandomtest.log |
|
253 function [passes,total] = test_sprandom |
|
254 warning("untested --- fix the source in buildtests.sh"); |
|
255 disp("appending test output to sprandomtest.log"); |
|
256 fid = fopen("sprandomtest.log","at"); |
|
257 test("test_sprandom","normal",fid); |
|
258 ##[passes, total] = test("sprandomtest","normal",fid); |
|
259 fclose(fid); |
|
260 endfunction |
|
261 |
|
262 EOF |
|
263 fi |
|
264 |
|
265 } |
|
266 |
|
267 |
|
268 # ======================================================= |
|
269 # matrix ops |
|
270 |
|
271 # test ordered comparisons: uses as,af,bs,bf |
|
272 gen_ordering_tests() { |
|
273 cat >>$TESTS <<EOF |
|
274 %% real values can be ordered (uses as,af) |
|
275 %!assert(as<=bf,sparse(af<=bf,true)) |
|
276 %!assert(bf<=as,sparse(bf<=af,true)) |
|
277 |
|
278 %!assert(as>=bf,sparse(af>=bf,true)) |
|
279 %!assert(bf>=as,sparse(bf>=af,true)) |
|
280 |
|
281 %!assert(as<bf,sparse(af<bf,true)) |
|
282 %!assert(bf<as,sparse(bf<af,true)) |
|
283 |
|
284 %!assert(as>bf,sparse(af>bf,true)) |
|
285 %!assert(bf>as,sparse(bf>af,true)) |
|
286 |
|
287 EOF |
|
288 } |
|
289 |
|
290 gen_sparsesparse_ordering_tests() { |
|
291 cat >>$TESTS <<EOF |
|
292 %!assert(as<=bs,sparse(af<=bf,true)) |
|
293 %!assert(as>=bs,sparse(af>=bf,true)) |
|
294 %!assert(as<bs,sparse(af<bf,true)) |
|
295 %!assert(as>bs,sparse(af>bf,true)) |
|
296 EOF |
|
297 } |
|
298 |
|
299 # test element-wise binary operations: uses as,af,bs,bf,scalar |
|
300 gen_elementop_tests() { |
|
301 cat >>$TESTS <<EOF |
|
302 %% Elementwise binary tests (uses as,af,bs,bf,scalar) |
|
303 %!assert(as==bs,sparse(af==bf,true)) |
|
304 %!assert(bf==as,sparse(bf==af,true)) |
|
305 |
|
306 %!assert(as!=bf,sparse(af!=bf,true)) |
|
307 %!assert(bf!=as,sparse(bf!=af,true)) |
|
308 |
|
309 %!assert(as+bf,af+bf) |
|
310 %!assert(bf+as,bf+af) |
|
311 |
|
312 %!assert(as-bf,af-bf) |
|
313 %!assert(bf-as,bf-af) |
|
314 |
|
315 %!assert(as.*bf,sparse(af.*bf,true)) |
|
316 %!assert(bf.*as,sparse(bf.*af,true)) |
|
317 |
|
318 %!assert(as./bf,sparse(af./bf,true),100*eps) |
|
319 %!assert(bf.\as,sparse(bf.\af,true),100*eps) |
|
320 |
|
321 %!test |
|
322 %! sv = as.^bf; |
|
323 %! fv = af.^bf; |
|
324 %! idx = find(af~=0); |
|
325 %! assert(sv(:)(idx),sparse(fv(:)(idx),true),100*eps) |
|
326 |
|
327 EOF |
|
328 } |
|
329 |
|
330 gen_sparsesparse_elementop_tests() { |
|
331 cat >>$TESTS <<EOF |
|
332 %!assert(as==bs,sparse(af==bf,true)) |
|
333 %!assert(as!=bs,sparse(af!=bf,true)) |
|
334 %!assert(as+bs,sparse(af+bf,true)) |
|
335 %!assert(as-bs,sparse(af-bf,true)) |
|
336 %!assert(as.*bs,sparse(af.*bf,true)) |
7055
|
337 %!xtest assert(as./bs,sparse(af./bf,true),100*eps); |
5590
|
338 %!test |
|
339 %! sv = as.^bs; |
|
340 %! fv = af.^bf; |
|
341 %! idx = find(af~=0); |
|
342 %! assert(sv(:)(idx),sparse(fv(:)(idx),true),100*eps) |
|
343 |
|
344 EOF |
|
345 } |
|
346 |
|
347 # test matrix-matrix left and right division: uses as,af,bs,bf |
|
348 gen_divop_tests() { |
|
349 cat >>$TESTS <<EOF |
|
350 %% Matrix-matrix operators (uses af,as,bs,bf) |
|
351 %!assert(as/bf,af/bf,100*eps) |
|
352 %!assert(af/bs,af/bf,100*eps) |
|
353 %!assert(as/bs,sparse(af/bf,true),100*eps) |
|
354 %!assert(bs\af',bf\af',100*eps) |
|
355 %!assert(bf\as',bf\af',100*eps) |
|
356 %!assert(bs\as',sparse(bf\af',true),100*eps) |
|
357 |
|
358 EOF |
|
359 } |
|
360 |
|
361 # test matrix-matrix left and right division: uses as,af,bs,bf |
|
362 gen_square_divop_tests() { |
|
363 cat >>$TESTS <<EOF |
|
364 %% Matrix-matrix operators (uses af,as,bs,bf) |
|
365 %!assert(as/bf,af/bf,100*eps) |
|
366 %!assert(af/bs,af/bf,100*eps) |
|
367 %!assert(as/bs,sparse(af/bf,true),100*eps) |
|
368 %!assert(bs\af',bf\af',100*eps) |
|
369 %!assert(bf\as',bf\af',100*eps) |
|
370 %!assert(bs\as',sparse(bf\af',true),100*eps) |
|
371 |
|
372 EOF |
|
373 } |
|
374 |
|
375 # test matrix-matrix operations: uses as,af,bs,bf |
|
376 gen_matrixop_tests() { |
|
377 cat >>$TESTS <<EOF |
|
378 %% Matrix-matrix operators (uses af,as,bs,bf) |
|
379 %!assert(as*bf',af*bf') |
|
380 %!assert(af*bs',af*bf') |
|
381 %!assert(as*bs',sparse(af*bf',true)) |
|
382 |
|
383 EOF |
|
384 } |
|
385 |
|
386 # test diagonal operations |
|
387 gen_matrixdiag_tests() { |
|
388 cat >>$TESTS <<EOF |
|
389 %% Matrix diagonal tests (uses af,as,bf,bs) |
|
390 %!assert(spdiag(as),sparse(diag(af),true)) |
|
391 %!assert(spdiag(bs),sparse(diag(bf),true)) |
|
392 %!assert(spdiag(as,1),sparse(diag(af,1),true)) |
|
393 %!assert(spdiag(bs,1),sparse(diag(bf,1),true)) |
|
394 %!assert(spdiag(as,-1),sparse(diag(af,-1),true)) |
|
395 %!assert(spdiag(bs,-1),sparse(diag(bf,-1),true)) |
|
396 %!assert(spdiag(as(:)),sparse(diag(af(:)),true)) |
|
397 %!assert(spdiag(as(:),1),sparse(diag(af(:),1),true)) |
|
398 %!assert(spdiag(as(:),-1),sparse(diag(af(:),-1),true)) |
|
399 %!assert(spdiag(as(:)'),sparse(diag(af(:)'),true)) |
|
400 %!assert(spdiag(as(:)',1),sparse(diag(af(:)',1),true)) |
|
401 %!assert(spdiag(as(:)',-1),sparse(diag(af(:)',-1),true)) |
|
402 %!assert(spdiags(as,[0,1]),[diag(af,0),diag(af,1)]) |
|
403 %!test [tb,tc]=spdiags(as); |
|
404 %! assert(spdiags(tb,tc,sparse(zeros(size(as)))),as) |
|
405 %! assert(spdiags(tb,tc,size(as,1),size(as,2)),as) |
|
406 |
|
407 EOF |
|
408 } |
|
409 |
|
410 # test matrix reshape operations |
|
411 gen_matrixreshape_tests() { |
|
412 cat >>$TESTS <<EOF |
|
413 %% Matrix diagonal tests (uses af,as,bf,bs) |
|
414 %!assert(reshape(as,1,prod(size(as))),sparse(reshape(af,1,prod(size(af))),true)) |
|
415 %!assert(reshape(as,prod(size(as)),1),sparse(reshape(af,prod(size(af)),1),true)) |
|
416 %!assert(reshape(as,fliplr(size(as))),sparse(reshape(af,fliplr(size(af))),true)) |
|
417 %!assert(reshape(bs,1,prod(size(as))),sparse(reshape(bf,1,prod(size(af))),true)) |
|
418 %!assert(reshape(bs,prod(size(as)),1),sparse(reshape(bf,prod(size(af)),1),true)) |
|
419 %!assert(reshape(bs,fliplr(size(as))),sparse(reshape(bf,fliplr(size(af))),true)) |
|
420 |
|
421 EOF |
|
422 } |
|
423 |
|
424 # test mapper matrix operations: uses as,af |
|
425 print_mapper_test() { |
|
426 echo "%!assert($1(as),sparse($1(af),1))" >>$TESTS |
|
427 } |
|
428 |
|
429 print_real_mapper_test() { |
|
430 cat >>$TESTS <<EOF |
|
431 %!test |
5781
|
432 %! wn2s = warning ("query", "Octave:num-to-str"); |
|
433 %! warning ("off", "Octave:num-to-str"); |
5590
|
434 %! if isreal(af) |
5953
|
435 %! if ($2) |
|
436 %! assert($1(as),sparse($1(af),1)) |
|
437 %! else |
|
438 %! assert($1(as),$1(af)) |
|
439 %! endif |
5590
|
440 %! endif |
5781
|
441 %! warning (wn2s.state, "Octave:num-to-str"); |
5590
|
442 |
|
443 EOF |
|
444 } |
|
445 |
|
446 gen_mapper_tests() { |
|
447 echo "%% Unary matrix tests (uses af,as)">>$TESTS |
|
448 print_mapper_test abs |
|
449 print_mapper_test acos |
|
450 print_mapper_test acosh |
|
451 print_mapper_test angle |
|
452 print_mapper_test arg |
|
453 print_mapper_test asin |
|
454 print_mapper_test asinh |
|
455 print_mapper_test atan |
|
456 print_mapper_test atanh |
|
457 print_mapper_test ceil |
|
458 print_mapper_test conj |
|
459 print_mapper_test cos |
|
460 print_mapper_test cosh |
|
461 print_mapper_test exp |
|
462 print_mapper_test finite |
|
463 print_mapper_test fix |
|
464 print_mapper_test floor |
|
465 print_mapper_test imag |
|
466 print_mapper_test isinf |
|
467 print_mapper_test isna |
|
468 print_mapper_test isnan |
|
469 print_mapper_test log |
|
470 #print_mapper_test log10 ## fails with different NaN, not a problem |
|
471 print_mapper_test real |
|
472 print_mapper_test round |
|
473 print_mapper_test sign |
|
474 print_mapper_test sin |
|
475 print_mapper_test sinh |
|
476 print_mapper_test sqrt |
|
477 print_mapper_test tan |
|
478 print_mapper_test tanh |
|
479 |
|
480 # Specific tests for certain mapper functions |
|
481 cat >>$TESTS <<EOF |
|
482 %!assert(issparse(abs(as))&&isreal(abs(as))) |
|
483 %!assert(issparse(real(as))&&isreal(real(as))) |
|
484 %!assert(issparse(imag(as))&&isreal(imag(as))) |
|
485 |
|
486 EOF |
|
487 } |
|
488 |
|
489 gen_real_mapper_tests() { |
|
490 echo "%% Unary matrix tests (uses af,as)">>$TESTS |
5953
|
491 print_real_mapper_test erf 1 |
|
492 print_real_mapper_test erfc 1 |
|
493 #print_real_mapper_test gamma 1 |
|
494 print_real_mapper_test isalnum 0 |
|
495 print_real_mapper_test isalpha 0 |
|
496 print_real_mapper_test isascii 0 |
|
497 print_real_mapper_test iscntrl 0 |
|
498 print_real_mapper_test isdigit 0 |
|
499 print_real_mapper_test isgraph 0 |
|
500 print_real_mapper_test islower 0 |
|
501 print_real_mapper_test isprint 0 |
|
502 print_real_mapper_test ispunct 0 |
|
503 print_real_mapper_test isspace 0 |
|
504 print_real_mapper_test isupper 0 |
|
505 print_real_mapper_test isxdigit 0 |
|
506 #print_real_mapper_test lgamma 1 |
5590
|
507 |
|
508 # Specific tests for certain mapper functions |
|
509 cat >>$TESTS <<EOF |
|
510 |
|
511 %% These mapper functions always return a full matrix |
|
512 %!test |
5781
|
513 %! wn2s = warning ("query", "Octave:num-to-str"); |
|
514 %! warning ("off", "Octave:num-to-str"); |
5590
|
515 %! if isreal(af) |
|
516 %! assert(toascii(as),toascii(af)) |
|
517 %! assert(tolower(as),tolower(af)) |
|
518 %! assert(toupper(as),toupper(af)) |
|
519 %! endif |
5781
|
520 %! warning (wn2s.state, "Octave:num-to-str"); |
5590
|
521 |
|
522 EOF |
|
523 } |
|
524 |
|
525 # test matrix operations: uses as,af |
|
526 gen_unaryop_tests() { |
|
527 cat >>$TESTS <<EOF |
|
528 %% Unary matrix tests (uses af,as) |
|
529 %!assert(issparse(as)) |
|
530 %!assert(!issparse(af)) |
|
531 %!assert(!(issparse(af)&&iscomplex(af))) |
|
532 %!assert(!(issparse(af)&&isreal(af))) |
|
533 %!assert(spsum(as),sparse(sum(af),true)) |
|
534 %!assert(spsum(as,1),sparse(sum(af,1),true)) |
|
535 %!assert(spsum(as,2),sparse(sum(af,2),true)) |
|
536 %!assert(spcumsum(as),sparse(cumsum(af),true)) |
|
537 %!assert(spcumsum(as,1),sparse(cumsum(af,1),true)) |
|
538 %!assert(spcumsum(as,2),sparse(cumsum(af,2),true)) |
|
539 %!assert(spsumsq(as),sparse(sumsq(af),true)) |
|
540 %!assert(spsumsq(as,1),sparse(sumsq(af,1),true)) |
|
541 %!assert(spsumsq(as,2),sparse(sumsq(af,2),true)) |
|
542 %!assert(spprod(as),sparse(prod(af),true)) |
|
543 %!assert(spprod(as,1),sparse(prod(af,1),true)) |
|
544 %!assert(spprod(as,2),sparse(prod(af,2),true)) |
|
545 %!assert(spcumprod(as),sparse(cumprod(af),true)) |
|
546 %!assert(spcumprod(as,1),sparse(cumprod(af,1),true)) |
|
547 %!assert(spcumprod(as,2),sparse(cumprod(af,2),true)) |
|
548 |
|
549 %!assert(spmin(as),sparse(min(af),true)) |
7197
|
550 %!assert(full(spmin(as(:))),min(af(:))) |
5590
|
551 %!assert(spmin(as,[],1),sparse(min(af,[],1),true)) |
|
552 %!assert(spmin(as,[],2),sparse(min(af,[],2),true)) |
|
553 %!assert(spmin(as,[],1),sparse(min(af,[],1),true)) |
|
554 %!assert(spmin(as,0),sparse(min(af,0),true)) |
|
555 %!assert(spmin(as,bs),sparse(min(af,bf),true)) |
|
556 %!assert(spmax(as),sparse(max(af),true)) |
7197
|
557 %!assert(full(spmax(as(:))),max(af(:))) |
5590
|
558 %!assert(spmax(as,[],1),sparse(max(af,[],1),true)) |
|
559 %!assert(spmax(as,[],2),sparse(max(af,[],2),true)) |
|
560 %!assert(spmax(as,[],1),sparse(max(af,[],1),true)) |
|
561 %!assert(spmax(as,0),sparse(max(af,0),true)) |
|
562 %!assert(spmax(as,bs),sparse(max(af,bf),true)) |
|
563 |
|
564 %!assert(as==as) |
|
565 %!assert(as==af) |
|
566 %!assert(af==as) |
|
567 %!test |
|
568 %! [ii,jj,vv,nr,nc] = spfind(as); |
|
569 %! assert(af,full(sparse(ii,jj,vv,nr,nc))); |
|
570 %!assert(nnz(as),sum(af(:)!=0)) |
|
571 %!assert(nnz(as),nnz(af)) |
|
572 %!assert(issparse(as.')) |
|
573 %!assert(issparse(as')) |
|
574 %!assert(issparse(-as)) |
|
575 %!assert(~as,sparse(~af,true)) |
|
576 %!assert(as.', sparse(af.',true)); |
|
577 %!assert(as', sparse(af',true)); |
|
578 %!assert(-as, sparse(-af,true)); |
|
579 %!assert(~as, sparse(~af,true)); |
|
580 %!error [i,j]=size(af);as(i-1,j+1); |
|
581 %!error [i,j]=size(af);as(i+1,j-1); |
|
582 %!test |
|
583 %! [Is,Js,Vs] = spfind(as); |
|
584 %! [If,Jf,Vf] = find(af); |
|
585 %! assert(Is,If); |
|
586 %! assert(Js,Jf); |
|
587 %! assert(Vs,Vf); |
|
588 %!error as(0,1); |
|
589 %!error as(1,0); |
|
590 %!assert(spfind(as),find(af)) |
|
591 %!test |
|
592 %! [i,j,v] = spfind(as); |
|
593 %! [m,n] = size(as); |
|
594 %! x = sparse(i,j,v,m,n); |
|
595 %! assert(x,as); |
|
596 %!test |
|
597 %! [i,j,v,m,n] = spfind(as); |
|
598 %! x = sparse(i,j,v,m,n); |
|
599 %! assert(x,as); |
|
600 %!assert(issparse(horzcat(as,as))); |
|
601 %!assert(issparse(vertcat(as,as))); |
|
602 %!assert(issparse(cat(1,as,as))); |
|
603 %!assert(issparse(cat(2,as,as))); |
|
604 %!assert(issparse([as,as])); |
|
605 %!assert(issparse([as;as])); |
|
606 %!assert(horzcat(as,as), sparse([af,af])); |
|
607 %!assert(vertcat(as,as), sparse([af;af])); |
|
608 %!assert(horzcat(as,as,as), sparse([af,af,af])); |
|
609 %!assert(vertcat(as,as,as), sparse([af;af;af])); |
|
610 %!assert([as,as], sparse([af,af])); |
|
611 %!assert([as;as], sparse([af;af])); |
|
612 %!assert([as,as,as], sparse([af,af,af])); |
|
613 %!assert([as;as;as], sparse([af;af;af])); |
|
614 %!assert(cat(2,as,as), sparse([af,af])); |
|
615 %!assert(cat(1,as,as), sparse([af;af])); |
|
616 %!assert(cat(2,as,as,as), sparse([af,af,af])); |
|
617 %!assert(cat(1,as,as,as), sparse([af;af;af])); |
|
618 %!assert(issparse([as,af])); |
|
619 %!assert(issparse([af,as])); |
|
620 %!assert([as,af], sparse([af,af])); |
|
621 %!assert([as;af], sparse([af;af])); |
|
622 |
|
623 EOF |
|
624 } |
|
625 |
|
626 # operations which require square matrices. |
|
627 gen_square_tests() { |
|
628 # The \ and / operator tests on square matrices |
|
629 gen_square_divop_tests |
|
630 |
|
631 cat >>$TESTS <<EOF |
|
632 %!assert(spdet(bs+speye(size(bs))),det(bf+eye(size(bf))),100*eps*abs(det(bf+eye(size(bf))))) |
|
633 |
|
634 %!test |
|
635 %! [l,u]=splu(sparse([1,1;1,1])); |
|
636 %! assert(l*u,[1,1;1,1],10*eps); |
|
637 |
|
638 %!test |
|
639 %! [l,u]=splu(sparse([1,1;1,1+i])); |
|
640 %! assert(l,sparse([1,2,2],[1,1,2],1),10*eps); |
|
641 %! assert(u,sparse([1,1,2],[1,2,2],[1,1,1i]),10*eps); |
|
642 |
|
643 %!test ;# permuted LU |
|
644 %! [L,U] = splu(bs); |
|
645 %! assert(L*U,bs,1e-10); |
|
646 |
|
647 %!test ;# simple LU + row permutations |
|
648 %! [L,U,P] = splu(bs); |
|
649 %! assert(P'*L*U,bs,1e-10); |
|
650 %! # triangularity |
|
651 %! [i,j,v]=spfind(L); |
|
652 %! assert(i-j>=0); |
|
653 %! [i,j,v]=spfind(U); |
|
654 %! assert(j-i>=0); |
|
655 |
|
656 %!test ;# simple LU + row/col permutations |
|
657 %! [L,U,P,Q] = splu(bs); |
|
658 %! assert(P'*L*U*Q',bs,1e-10); |
|
659 %! # triangularity |
|
660 %! [i,j,v]=spfind(L); |
|
661 %! assert(i-j>=0); |
|
662 %! [i,j,v]=spfind(U); |
|
663 %! assert(j-i>=0); |
|
664 |
|
665 %!test ;# LU with fixed column permutation |
|
666 %! [L,U,P] = splu(bs,colamd(bs)); |
|
667 %! assert(P'*L*U,bs,1e-10); |
|
668 %! # triangularity |
|
669 %! [i,j,v]=spfind(L); |
|
670 %! assert(i-j>=0); |
|
671 %! [i,j,v]=spfind(U(:,colamd(bs))); |
|
672 %! assert(j-i>=0); |
|
673 |
|
674 %!test ;# LU with initial column permutation |
|
675 %! [L,U,P,Q] = splu(bs,colamd(bs)); |
|
676 %! assert(P'*L*U*Q',bs,1e-10); |
|
677 %! # triangularity |
|
678 %! [i,j,v]=spfind(L); |
|
679 %! assert(i-j>=0); |
|
680 %! [i,j,v]=spfind(U); |
|
681 %! assert(j-i>=0); |
|
682 |
|
683 %!test ;# inverse |
|
684 %! assert(spinv(bs)*bs,sparse(eye(rows(bs))),1e-10); |
|
685 |
|
686 %!assert(bf\as',bf\af',100*eps); |
|
687 %!assert(bs\af',bf\af',100*eps); |
|
688 %!assert(bs\as',sparse(bf\af'),100*eps); |
|
689 |
|
690 EOF |
|
691 } |
|
692 |
|
693 # Cholesky tests |
|
694 gen_cholesky_tests() { |
|
695 cat >>$TESTS <<EOF |
|
696 %!assert(spchol(bs)'*spchol(bs),bs,1e-10); |
|
697 %!assert(splchol(bs)*splchol(bs)',bs,1e-10); |
|
698 %!assert(splchol(bs),spchol(bs)',1e-10); |
|
699 |
|
700 %!test ;# Return Partial Cholesky factorization |
|
701 %! [RS,PS] = spchol(bs); |
|
702 %! assert(RS'*RS,bs,1e-10); |
|
703 %! assert(PS,0); |
|
704 %! [LS,PS] = splchol(bs); |
|
705 %! assert(LS*LS',bs,1e-10); |
|
706 %! assert(PS,0); |
|
707 |
|
708 %!test ;# Permuted Cholesky factorization |
|
709 %! [RS,PS,QS] = spchol(bs); |
|
710 %! assert(RS'*RS,QS*bs*QS',1e-10); |
|
711 %! assert(PS,0); |
|
712 %! [LS,PS,QS] = splchol(bs); |
|
713 %! assert(LS*LS',QS*bs*QS',1e-10); |
|
714 %! assert(PS,0); |
|
715 |
|
716 EOF |
|
717 } |
|
718 |
|
719 # test scalar operations: uses af and real scalar bf; modifies as,bf,bs |
|
720 gen_scalar_tests() { |
|
721 echo '%!test as=sparse(af);' >> $TESTS |
|
722 echo '%!test bs=bf;' >> $TESTS |
|
723 gen_elementop_tests |
|
724 gen_ordering_tests |
|
725 echo '%!test bf=bf+1i;' >>$TESTS |
|
726 echo '%!test bs=bf;' >> $TESTS |
|
727 gen_elementop_tests |
|
728 } |
|
729 |
|
730 # test matrix operations: uses af and bf; modifies as,bs |
|
731 gen_rectangular_tests() { |
|
732 echo '%!test as=sparse(af);' >> $TESTS |
|
733 echo '%!test bs=sparse(bf);' >>$TESTS |
|
734 gen_mapper_tests |
|
735 gen_real_mapper_tests |
|
736 gen_unaryop_tests |
|
737 gen_elementop_tests |
|
738 gen_sparsesparse_elementop_tests |
|
739 gen_matrixop_tests |
|
740 # gen_divop_tests # Disable rectangular \ and / for now |
|
741 gen_matrixdiag_tests |
|
742 gen_matrixreshape_tests |
|
743 } |
|
744 |
|
745 |
|
746 # ======================================================= |
|
747 # sparse assembly tests |
|
748 |
|
749 gen_assembly_tests() { |
|
750 cat >>$TESTS <<EOF |
|
751 %%Assembly tests |
|
752 %!test |
|
753 %! m=max([m;r(:)]); |
|
754 %! n=max([n;c(:)]); |
|
755 %! funiq=fsum=zeros(m,n); |
|
756 %! funiq(r(:) + m*(c(:)-1) ) = ones(size(r(:))); |
|
757 %! funiq = sparse(funiq); |
|
758 %! for k=1:length(r), fsum(r(k),c(k)) += 1; end |
|
759 %! fsum = sparse(fsum); |
|
760 %!assert(sparse(r,c,1),sparse(fsum(1:max(r),1:max(c)))); |
|
761 %!assert(sparse(r,c,1,"sum"),sparse(fsum(1:max(r),1:max(c)))); |
|
762 %!assert(sparse(r,c,1,"unique"),sparse(funiq(1:max(r),1:max(c)))); |
|
763 %!assert(sparse(r,c,1,m,n),sparse(fsum)); |
|
764 %!assert(sparse(r,c,1,m,n,"sum"),sparse(fsum)); |
|
765 %!assert(sparse(r,c,1,m,n,"unique"),sparse(funiq)); |
|
766 |
|
767 %!assert(sparse(r,c,1i),sparse(fsum(1:max(r),1:max(c))*1i)); |
|
768 %!assert(sparse(r,c,1i,"sum"),sparse(fsum(1:max(r),1:max(c))*1i)); |
|
769 %!assert(sparse(r,c,1i,"unique"),sparse(funiq(1:max(r),1:max(c))*1i)); |
|
770 %!assert(sparse(r,c,1i,m,n),sparse(fsum*1i)); |
|
771 %!assert(sparse(r,c,1i,m,n,"sum"),sparse(fsum*1i)); |
|
772 %!assert(sparse(r,c,1i,m,n,"unique"),sparse(funiq*1i)); |
|
773 |
|
774 %!test |
|
775 %! if (issparse(funiq)) |
|
776 %! assert(sparse(full(1i*funiq)),sparse(1i*funiq)); |
|
777 %! endif |
|
778 |
|
779 %!assert(sparse(full(funiq)),funiq); |
|
780 |
|
781 |
|
782 EOF |
|
783 } |
|
784 |
|
785 # ======================================================= |
|
786 # sparse selection tests |
|
787 |
|
788 gen_select_tests() { |
|
789 cat >>$TESTS <<EOF |
|
790 %!test as=sparse(af); |
|
791 |
|
792 %% Point tests |
|
793 %!test idx=ridx(:)+rows(as)*(cidx(:)-1); |
|
794 %!assert(sparse(as(idx),true),sparse(af(idx),true)); |
|
795 %!assert(as(idx),sparse(af(idx),true)); |
|
796 %!assert(as(idx'),sparse(af(idx'),true)); |
5603
|
797 %!assert(as(flipud(idx(:))),sparse(af(flipud(idx(:))),true)) |
5590
|
798 %!assert(as([idx,idx]),sparse(af([idx,idx]),true)); |
|
799 %!error(as(reshape([idx;idx],[1,length(idx),2]))); |
|
800 |
|
801 %% Slice tests |
|
802 %!assert(as(ridx,cidx), sparse(af(ridx,cidx),true)) |
|
803 %!assert(as(ridx,:), sparse(af(ridx,:),true)) |
|
804 %!assert(as(:,cidx), sparse(af(:,cidx),true)) |
|
805 %!assert(as(:,:), sparse(af(:,:),true)) |
5603
|
806 %!assert(as((size(as,1):-1:1),:),sparse(af((size(af,1):-1:1),:),true)) |
|
807 %!assert(as(:,(size(as,2):-1:1)),sparse(af(:,(size(af,2):-1:1)),true)) |
|
808 |
|
809 %% Assignment test |
|
810 %!test |
|
811 %! ts=as;ts(:,:)=ts(fliplr(1:size(as,1)),:); |
|
812 %! tf=af;tf(:,:)=tf(fliplr(1:size(af,1)),:); |
|
813 %! assert(ts,sparse(tf,true)); |
|
814 %!test |
|
815 %! ts=as;ts(fliplr(1:size(as,1)),:)=ts; |
|
816 %! tf=af;tf(fliplr(1:size(af,1)),:)=tf; |
|
817 %! assert(ts,sparse(tf,true)); |
|
818 %!test |
|
819 %! ts=as;ts(:,fliplr(1:size(as,2)))=ts; |
|
820 %! tf=af;tf(:,fliplr(1:size(af,2)))=tf; |
|
821 %! assert(ts,sparse(tf,true)); |
|
822 %!test |
|
823 %! ts(fliplr(1:size(as,1)))=as(:,1);tf(fliplr(1:size(af,1)))=af(:,1); |
|
824 %! assert(ts,sparse(tf,true)); |
|
825 |
|
826 %% Deletion tests |
|
827 %!test |
|
828 %! ts=as;ts(1,:)=[];tf=af;tf(1,:)=[]; |
|
829 %! assert(ts,sparse(tf,true)); |
|
830 %!test |
|
831 %! ts=as;ts(:,1)=[];tf=af;tf(:,1)=[]; |
|
832 %! assert(ts,sparse(tf,true)); |
5590
|
833 |
|
834 %% Test 'end' keyword |
7197
|
835 %!assert(full(as(end)), af(end)) |
|
836 %!assert(full(as(1,end)), af(1,end)) |
|
837 %!assert(full(as(end,1)), af(end,1)) |
|
838 %!assert(full(as(end,end)), af(end,end)) |
5590
|
839 %!assert(as(2:end,2:end), sparse(af(2:end,2:end),true)) |
|
840 %!assert(as(1:end-1,1:end-1), sparse(af(1:end-1,1:end-1),true)) |
|
841 EOF |
|
842 } |
|
843 |
|
844 # ======================================================= |
|
845 # sparse save and load tests |
|
846 |
|
847 gen_save_tests() { |
|
848 cat >>$TESTS <<EOF |
|
849 %!test # save ascii |
|
850 %! savefile= tmpnam(); |
|
851 %! as_save=as; save("-text",savefile,"bf","as_save","af"); |
|
852 %! clear as_save; |
|
853 %! load(savefile,"as_save"); |
|
854 %! unlink(savefile); |
|
855 %! assert(as_save,sparse(af)); |
|
856 %!test # save binary |
|
857 %! savefile= tmpnam(); |
|
858 %! as_save=as; save("-binary",savefile,"bf","as_save","af"); |
|
859 %! clear as_save; |
|
860 %! load(savefile,"as_save"); |
|
861 %! unlink(savefile); |
|
862 %! assert(as_save,sparse(af)); |
|
863 %!test # save hdf5 |
|
864 %! savefile= tmpnam(); |
|
865 %! as_save=as; save("-hdf5",savefile,"bf","as_save","af"); |
|
866 %! clear as_save; |
|
867 %! load(savefile,"as_save"); |
|
868 %! unlink(savefile); |
|
869 %! assert(as_save,sparse(af)); |
|
870 %!test # save matlab |
|
871 %! savefile= tmpnam(); |
|
872 %! as_save=as; save("-mat",savefile,"bf","as_save","af"); |
|
873 %! clear as_save; |
|
874 %! load(savefile,"as_save"); |
|
875 %! unlink(savefile); |
|
876 %! assert(as_save,sparse(af)); |
|
877 EOF |
|
878 } |
|
879 |
|
880 # ============================================================= |
|
881 # Specific solver tests for matrices that will test all of the solver |
|
882 # code. Uses alpha and beta |
|
883 gen_solver_tests() { |
|
884 |
|
885 if $preset; then |
|
886 cat >>$TESTS <<EOF |
|
887 %! n=8; |
|
888 %! lf=diag(1:n);lf(n-1,1)=0.5*alpha;lf(n,2)=0.25*alpha;ls=sparse(lf); |
|
889 %! uf=diag(1:n);uf(1,n-1)=2*alpha;uf(2,n)=alpha;us=sparse(uf); |
|
890 %! ts=spdiags(ones(n,3),-1:1,n,n)+diag(1:n); tf = full(ts); |
|
891 EOF |
|
892 else |
|
893 cat >>$TESTS <<EOF |
|
894 %! n=floor(lognormal_rnd(8,2)+1)' |
|
895 %! ls = tril(sprandn(8,8,0.2),-1).*alpha + n*speye(8); lf = full(ls); |
|
896 %! us = triu(sprandn(8,8,0.2),1).*alpha + n*speye(8); uf = full(us); |
|
897 %! ts = spdiags(randn(8,3),-1:1,8,8).*alpha; tf = full(ts); |
|
898 EOF |
|
899 fi |
|
900 |
|
901 cat >>$TESTS <<EOF |
|
902 %! df = diag(1:n).* alpha; ds = sparse(df); |
|
903 %! pdf = df(randperm(n),randperm(n)); pds = sparse(pdf); |
|
904 %! plf = lf(randperm(n),randperm(n)); pls = sparse(plf); |
|
905 %! puf = uf(randperm(n),randperm(n)); pus = sparse(puf); |
|
906 %! bs = spdiags(repmat([1:n]',1,4),-2:1,n,n).*alpha; bf = full(bs); |
|
907 %! cf = lf + lf'; cs = sparse(cf); |
|
908 %! bcf = bf + bf'; bcs = sparse(bcf); |
|
909 %! tcf = tf + tf'; tcs = sparse(tcf); |
|
910 %! xf = diag(1:n) + fliplr(diag(1:n)).*beta; xs = sparse(xf); |
7080
|
911 %!assert(ds\xf,df\xf,1e-10); |
5590
|
912 %!assert(ds\xs,sparse(df\xf,1),1e-10); |
|
913 %!assert(pds\xf,pdf\xf,1e-10); |
|
914 %!assert(pds\xs,sparse(pdf\xf,1),1e-10); |
|
915 %!assert(ls\xf,lf\xf,1e-10); |
|
916 %!assert(sparse(ls\xs),sparse(lf\xf),1e-10); |
|
917 %!assert(pls\xf,plf\xf,1e-10); |
|
918 %!assert(sparse(pls\xs),sparse(plf\xf),1e-10); |
|
919 %!assert(us\xf,uf\xf,1e-10); |
|
920 %!assert(sparse(us\xs),sparse(uf\xf),1e-10); |
|
921 %!assert(pus\xf,puf\xf,1e-10); |
|
922 %!assert(sparse(pus\xs),sparse(puf\xf),1e-10); |
|
923 %!assert(bs\xf,bf\xf,1e-10); |
|
924 %!assert(sparse(bs\xs),sparse(bf\xf),1e-10); |
|
925 %!assert(cs\xf,cf\xf,1e-10); |
|
926 %!assert(sparse(cs\xs),sparse(cf\xf),1e-10); |
|
927 %!assert(bcs\xf,bcf\xf,1e-10); |
|
928 %!assert(sparse(bcs\xs),sparse(bcf\xf),1e-10); |
|
929 %!assert(ts\xf,tf\xf,1e-10); |
|
930 %!assert(sparse(ts\xs),sparse(tf\xf),1e-10); |
|
931 %!assert(tcs\xf,tcf\xf,1e-10); |
|
932 %!assert(sparse(tcs\xs),sparse(tcf\xf),1e-10); |
|
933 |
|
934 EOF |
5610
|
935 |
|
936 cat >>$TESTS <<EOF |
|
937 %% QR solver tests |
|
938 |
|
939 %!function f(a, sz, feps) |
|
940 %! b = randn(sz); x = a \b; |
|
941 %! assert (a * x, b, feps); |
|
942 %! b = randn(sz)+1i*randn(sz); x = a \ b; |
|
943 %! assert (a * x, b, feps); |
|
944 %! b = sprandn(sz(1),sz(2),0.2); x = a \b; |
|
945 %! assert (sparse(a * x), b, feps); |
|
946 %! b = sprandn(sz(1),sz(2),0.2)+1i*sprandn(sz(1),sz(2),0.2); x = a \b; |
|
947 %! assert (sparse(a * x), b, feps); |
|
948 %!test |
|
949 %! a = alpha*sprandn(10,11,0.2)+speye(10,11); f(a,[10,2],1e-10); |
5630
|
950 %! ## Test this by forcing matrix_type, as can't get a certain |
|
951 %! ## result for over-determined systems. |
5610
|
952 %! a = alpha*sprandn(10,10,0.2)+speye(10,10); matrix_type(a, "Singular"); |
|
953 %! f(a,[10,2],1e-10); |
|
954 |
5630
|
955 %% Rectanguar solver tests that don't use QR |
|
956 |
|
957 %!test |
|
958 %! ds = alpha * spdiags([1:11]',0,10,11); |
|
959 %! df = full(ds); |
5681
|
960 %! xf = beta * ones(10,2); |
5630
|
961 %! xs = speye(10,10); |
|
962 %!assert(ds\xf,df\xf,100*eps) |
|
963 %!assert(ds\xs,sparse(df\xs,true),100*eps) |
|
964 %!test |
|
965 %! pds = ds([2,1,3:10],:); |
|
966 %! pdf = full(pds); |
|
967 %!assert(pds\xf,pdf\xf,100*eps) |
|
968 %!assert(pds\xs,sparse(pdf\xs,true),100*eps) |
|
969 %!test |
|
970 %! ds = alpha * spdiags([1:11]',0,11,10); |
|
971 %! df = full(ds); |
5681
|
972 %! xf = beta * ones(11,2); |
5630
|
973 %! xs = speye(11,11); |
|
974 %!assert(ds\xf,df\xf,100*eps) |
|
975 %!assert(ds\xs,sparse(df\xs,true),100*eps) |
|
976 %!test |
|
977 %! pds = ds([2,1,3:11],:); |
|
978 %! pdf = full(pds); |
|
979 %!assert(pds\xf,pdf\xf,100*eps) |
|
980 %!assert(pds\xs,sparse(pdf\xs,true),100*eps) |
|
981 %!test |
|
982 %! us = alpha*[[speye(10,10);sparse(1,10)],[[1,1];sparse(9,2);[1,1]]]; |
|
983 %!assert(us*(us\xf),xf,100*eps) |
|
984 %!assert(us*(us\xs),xs,100*eps) |
|
985 %!test |
|
986 %! pus = us(:,[2,1,3:12]); |
|
987 %!assert(pus*(pus\xf),xf,100*eps) |
|
988 %!assert(pus*(pus\xs),xs,100*eps) |
|
989 %!test |
|
990 %! us = alpha*[speye(11,9),[1;sparse(8,1);1;0]]; |
|
991 %!test |
|
992 %! [c,r] = spqr (us, xf); |
|
993 %! assert(us\xf,r\c,100*eps) |
|
994 %!test |
|
995 %! [c,r] = spqr (us, xs); |
5681
|
996 %! r = matrix_type(r,"Singular"); ## Force Matrix Type |
5630
|
997 %! assert(us\xs,r\c,100*eps) |
|
998 %!test |
|
999 %! pus = us(:,[1:8,10,9]); |
|
1000 %!test |
|
1001 %! [c,r] = spqr (pus, xf); |
5681
|
1002 %! r = matrix_type(r,"Singular"); ## Force Matrix Type |
5630
|
1003 %! assert(pus\xf,r\c,100*eps) |
|
1004 %!test |
|
1005 %! [c,r] = spqr (pus, xs); |
5681
|
1006 %! r = matrix_type(r,"Singular"); ## Force Matrix Type |
5630
|
1007 %! assert(pus\xs,r\c,100*eps) |
|
1008 %!test |
|
1009 %! ls = alpha*[speye(9,11);[1,sparse(1,8),1,0]]; |
5681
|
1010 %! xf = beta * ones(10,2); |
5630
|
1011 %! xs = speye(10,10); |
|
1012 %!assert(ls*(ls\xf),xf,100*eps) |
|
1013 %!assert(ls*(ls\xs),xs,100*eps) |
|
1014 %!test |
|
1015 %! pls = ls([1:8,10,9],:); |
|
1016 %!assert(pls*(pls\xf),xf,100*eps) |
|
1017 %!assert(pls*(pls\xs),xs,100*eps) |
|
1018 %!test |
|
1019 %! ls = alpha*[speye(10,10),sparse(10,1);[1;1],sparse(2,9),[1;1]]; |
5681
|
1020 %! xf = beta * ones(12,2); |
5630
|
1021 %! xs = speye(12,12); |
|
1022 %!test |
|
1023 %! [c,r] = spqr (ls, xf); |
|
1024 %! assert(ls\xf,r\c,100*eps) |
|
1025 %!test |
|
1026 %! [c,r] = spqr (ls, xs); |
5681
|
1027 %! r = matrix_type(r,"Singular"); ## Force Matrix Type |
5630
|
1028 %! assert(ls\xs,r\c,100*eps) |
|
1029 %!test |
|
1030 %! pls = ls(:,[1:8,10,9]); |
|
1031 %!test |
|
1032 %! [c,r] = spqr (pls, xf); |
5681
|
1033 %! r = matrix_type(r,"Singular"); ## Force Matrix Type |
5630
|
1034 %! assert(pls\xf,r\c,100*eps) |
|
1035 %!test |
|
1036 %! [c,r] = spqr (pls, xs); |
5681
|
1037 %! r = matrix_type(r,"Singular"); ## Force Matrix Type |
5630
|
1038 %! assert(pls\xs,r\c,100*eps) |
|
1039 |
5610
|
1040 EOF |
5590
|
1041 } |
|
1042 |
|
1043 |
|
1044 # ============================================================= |
|
1045 # Putting it all together: defining the combined tests |
|
1046 |
|
1047 |
|
1048 # initial function |
|
1049 gen_function |
|
1050 gen_section |
|
1051 |
|
1052 # specific tests |
|
1053 if $preset; then |
|
1054 gen_specific_tests |
|
1055 gen_section |
|
1056 fi |
|
1057 |
|
1058 # scalar operations |
|
1059 echo '%!shared as,af,bs,bf' >> $TESTS |
|
1060 if $preset; then |
|
1061 echo '%!test af=[1+1i,2-1i,0,0;0,0,0,3+2i;0,0,0,4];' >> $TESTS |
|
1062 echo '%!test bf=3;' >>$TESTS |
|
1063 else |
|
1064 cat >>$TESTS <<EOF |
|
1065 %!test |
|
1066 %! % generate m,n from 1 to <5000 |
|
1067 %! m=floor(lognormal_rnd(8,2)+1); |
|
1068 %! n=floor(lognormal_rnd(8,2)+1); |
|
1069 %! as=sprandn(m,n,0.3); af = full(as+1i*sprandn(as)); |
|
1070 %! bf = randn; |
|
1071 EOF |
|
1072 fi |
|
1073 |
|
1074 gen_scalar_tests |
|
1075 gen_section |
|
1076 |
|
1077 # rectangular operations |
|
1078 if $preset; then |
|
1079 echo '%!test af=[1+1i,2-1i,0,0;0,0,0,3+2i;0,0,0,4];' >> $TESTS |
|
1080 echo '%!test bf=[0,1-1i,0,0;2+1i,0,0,0;3-1i,2+3i,0,0];' >> $TESTS |
|
1081 else |
|
1082 cat >>$TESTS <<EOF |
|
1083 %!test |
|
1084 %! m=floor(lognormal_rnd(8,2)+1); |
|
1085 %! n=floor(lognormal_rnd(8,2)+1); |
|
1086 %! as=sprandn(m,n,0.3); af = full(as+1i*sprandn(as)); |
|
1087 %! bs=sprandn(m,n,0.3); bf = full(bs+1i*sprandn(bs)); |
|
1088 EOF |
|
1089 fi |
|
1090 |
|
1091 gen_rectangular_tests |
|
1092 gen_section |
|
1093 gen_save_tests |
|
1094 gen_section |
|
1095 echo '%!test bf=real(bf);' >> $TESTS |
|
1096 gen_rectangular_tests |
|
1097 gen_section |
|
1098 gen_sparsesparse_ordering_tests |
|
1099 gen_section |
|
1100 echo '%!test af=real(af);' >> $TESTS |
|
1101 gen_rectangular_tests |
|
1102 gen_section |
|
1103 gen_save_tests |
|
1104 gen_section |
|
1105 echo '%!test bf=bf+1i*(bf~=0);' >> $TESTS |
|
1106 gen_rectangular_tests |
|
1107 gen_section |
|
1108 |
|
1109 # square operations |
|
1110 if $preset; then |
|
1111 echo '%!test af=[1+1i,2-1i,0,0;0,0,0,3+2i;0,0,0,4];' >> $TESTS |
|
1112 echo '%! as=sparse(af);' >> $TESTS |
|
1113 echo '%!test bf=[0,1-1i,0,0;2+1i,0,0,0;3-1i,2+3i,0,0];' >> $TESTS |
|
1114 else |
|
1115 cat >>$TESTS <<EOF |
|
1116 %!test |
|
1117 %! m=floor(lognormal_rnd(8,2)+1); |
|
1118 %! n=floor(lognormal_rnd(8,2)+1); |
|
1119 %! as=sprandn(m,n,0.3); af = full(as+1i*sprandn(as)); |
|
1120 %! bs=sprandn(m,n,0.3); bf = full(bs+1i*sprandn(bs)); |
|
1121 EOF |
|
1122 fi |
|
1123 |
|
1124 cat >>$TESTS <<EOF |
|
1125 %!test ;# invertible matrix |
|
1126 %! bf=af'*bf+max(abs([af(:);bf(:)]))*sparse(eye(columns(as))); |
|
1127 %! bs=sparse(bf); |
|
1128 |
|
1129 EOF |
|
1130 |
|
1131 gen_square_tests |
|
1132 gen_section |
|
1133 echo '%!test bf=real(bf);' >> $TESTS |
|
1134 echo '%! bs=sparse(bf);' >> $TESTS |
|
1135 gen_square_tests |
|
1136 gen_section |
|
1137 echo '%!test af=real(af);' >> $TESTS |
|
1138 echo '%! as=sparse(af);' >> $TESTS |
|
1139 gen_square_tests |
|
1140 gen_section |
|
1141 echo '%!test bf=bf+1i*(bf~=0);' >> $TESTS |
|
1142 echo '%! bs=sparse(bf);' >> $TESTS |
|
1143 gen_square_tests |
|
1144 gen_section |
|
1145 |
|
1146 # cholesky tests |
|
1147 if $preset; then |
|
1148 echo '%!test bf=[5,0,1+1i,0;0,5,0,1-2i;1-1i,0,5,0;0,1+2i,0,5];' >> $TESTS |
|
1149 echo '%! bs=sparse(bf);' >> $TESTS |
|
1150 else |
|
1151 echo '# This has a small chance of failing to create a positive definite matrix' >> $TESTS |
|
1152 echo '%!test n=floor(lognormal_rnd(8,2)+1)' >> $TESTS |
|
1153 echo '%! bs = n*speye(n,n) + sprandn(n,n,0.3); bf = full(bs);' >> $TESTS |
|
1154 fi |
|
1155 |
|
1156 gen_cholesky_tests |
|
1157 gen_section |
|
1158 echo '%!test bf=real(bf);' >> $TESTS |
|
1159 echo '%! bs=sparse(bf);' >> $TESTS |
|
1160 gen_cholesky_tests |
|
1161 gen_section |
|
1162 |
|
1163 # assembly tests |
|
1164 echo '%!shared r,c,m,n,fsum,funiq' >>$TESTS |
|
1165 if $use_preset; then |
|
1166 cat >>$TESTS <<EOF |
|
1167 %!test |
|
1168 %! r=[1,1,2,1,2,3]; |
|
1169 %! c=[2,1,1,1,2,1]; |
|
1170 %! m=n=0; |
|
1171 EOF |
|
1172 else |
|
1173 cat >>$TESTS <<EOF |
|
1174 %!test |
|
1175 %! % generate m,n from 1 to <5000 |
|
1176 %! m=floor(lognormal_rnd(8,2)+1); |
|
1177 %! n=floor(lognormal_rnd(8,2)+1); |
|
1178 %! nz=ceil((m+n)/2); |
|
1179 %! r=floor(rand(5,nz)*n)+1; |
|
1180 %! c=floor(rand(5,nn)*m)+1; |
|
1181 EOF |
|
1182 fi |
|
1183 gen_assembly_tests #includes real and complex tests |
|
1184 gen_section |
|
1185 |
|
1186 # slicing tests |
|
1187 echo '%!shared ridx,cidx,idx,as,af' >>$TESTS |
|
1188 if $use_preset; then |
|
1189 cat >>$TESTS <<EOF |
|
1190 %!test |
|
1191 %! af=[1+1i,2-1i,0,0;0,0,0,3+2i;0,0,0,4]; |
|
1192 %! ridx=[1,3]; cidx=[2,3]; |
|
1193 EOF |
|
1194 else |
|
1195 cat >>$TESTS <<EOF |
|
1196 %!test |
|
1197 %! % generate m,n from 1 to <5000 |
|
1198 %! m=floor(lognormal_rnd(8,2)+1); |
|
1199 %! n=floor(lognormal_rnd(8,2)+1); |
|
1200 %! as=sprandn(m,n,0.3); af = full(as+1i*sprandn(as)); |
|
1201 %! ridx = ceil(m*rand(1,ceil(rand*m)) |
|
1202 %! cidx = ceil(n*rand(1,ceil(rand*n)) |
|
1203 EOF |
|
1204 fi |
|
1205 gen_select_tests |
|
1206 echo '%!test af=real(af);' >> $TESTS |
|
1207 gen_select_tests |
|
1208 gen_section |
|
1209 echo '%!shared alpha,beta,df,pdf,lf,plf,uf,puf,bf,cf,bcf,tf,tcf,xf,ds,pds,ls,pls,us,pus,bs,cs,bcs,ts,tcs,xs' >>$TESTS |
|
1210 echo '%!test alpha=1;beta=1;' >> $TESTS |
|
1211 gen_solver_tests |
|
1212 echo '%!test alpha=1;beta=1i;' >> $TESTS |
|
1213 gen_solver_tests |
|
1214 echo '%!test alpha=1i;beta=1;' >> $TESTS |
|
1215 gen_solver_tests |
|
1216 echo '%!test alpha=1i;beta=1i;' >> $TESTS |
|
1217 gen_solver_tests |
|
1218 gen_section |