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