Mercurial > hg > octave-lyh
annotate test/build_sparse_tests.sh @ 7595:90ad1f69ca9d
Escape "-" signs that mean the "minus" character
author | Rafael Laboissiere <rafael@debian.org> |
---|---|
date | Tue, 18 Mar 2008 14:05:50 -0400 |
parents | f3c00dc0912b |
children | ec0a13863eb7 |
rev | line source |
---|---|
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.. | |
7243 | 182 %!testif HAVE_UMFPACK |
7515
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
183 %! assert(inv(sparse([1,1;1,1+i])),sparse([1-1i,1i;1i,-1i]),10*eps); |
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
184 % !error inv( sparse( [1,1;1,1] ) ); |
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
185 % !error inv( sparse( [0,0;0,1] ) ); |
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
186 % !error inv( sparse( [0,0;0,1+i] ) ); |
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
187 % !error inv( sparse( [0,0;0,0] ) ); |
5590 | 188 |
189 %% error handling in constructor | |
190 %!error sparse(1,[2,3],[1,2,3]); | |
191 %!error sparse([1,1],[1,1],[1,2],3,3,"bogus"); | |
192 %!error sparse([1,3],[1,-4],[3,5],2,2); | |
193 %!error sparse([1,3],[1,-4],[3,5i],2,2); | |
194 %!error sparse(-1,-1,1); | |
195 EOF | |
196 } | |
197 | |
198 | |
199 gen_specific_tests() { | |
200 gen_section | |
201 gen_specific | |
202 gen_section | |
203 echo '%!shared bf' >> $TESTS | |
204 echo '%!test bf=realmin;' >> $TESTS | |
205 gen_eat_zeros | |
206 echo '%!test bf=realmin+realmin*1i;' >> $TESTS | |
207 gen_eat_zeros | |
208 cat >>$TESTS <<EOF | |
209 %!assert(nnz(sparse([-1,realmin,realmin]).^1.5),1); | |
210 %!assert(nnz(sparse([-1,realmin,realmin,1]).^1.5),2); | |
211 | |
212 %!assert(nnz(sparse(1,1,0)),0); # Make sure scalar v==0 doesn't confuse matters | |
213 %!assert(nnz(sparse(eye(3))*0),0); | |
214 %!assert(nnz(sparse(eye(3))-sparse(eye(3))),0); | |
215 | |
216 %!test | |
5781 | 217 %! wdbz = warning ("query", "Octave:divide-by-zero"); |
218 %! warning ("off", "Octave:divide-by-zero"); | |
7197 | 219 %! assert(full(sparse(eye(3))/0),eye(3)/0); |
5781 | 220 %! warning (wdbz.state, "Octave:divide-by-zero"); |
5590 | 221 |
222 EOF | |
223 } | |
224 | |
225 | |
226 # ======================================================= | |
227 # Main function definition | |
228 | |
229 gen_function() { | |
230 if $preset; then | |
231 cat >>$TESTS <<EOF | |
232 ## | |
233 ## test_sparse | |
234 ## | |
235 ## run preset sparse tests. All should pass. | |
236 function [passes,tests] = test_sparse | |
237 disp("writing test output to sptest.log"); | |
238 test("test_sparse","normal","sptest.log"); | |
239 endfunction | |
240 | |
241 EOF | |
242 else | |
243 cat >>$TESTS <<EOF | |
244 ## | |
245 ## test_sprandom | |
246 ## | |
247 ## total_passes=0; total_tests=0; | |
248 ## for i=1:10 | |
249 ## [passes,tests] = sprandomtest; | |
250 ## total_passes += passes; | |
251 ## total_tests += tests; | |
252 ## end | |
253 ## The test log is appended to sprandomtest.log | |
254 function [passes,total] = test_sprandom | |
255 warning("untested --- fix the source in buildtests.sh"); | |
256 disp("appending test output to sprandomtest.log"); | |
257 fid = fopen("sprandomtest.log","at"); | |
258 test("test_sprandom","normal",fid); | |
259 ##[passes, total] = test("sprandomtest","normal",fid); | |
260 fclose(fid); | |
261 endfunction | |
262 | |
263 EOF | |
264 fi | |
265 | |
266 } | |
267 | |
268 | |
269 # ======================================================= | |
270 # matrix ops | |
271 | |
272 # test ordered comparisons: uses as,af,bs,bf | |
273 gen_ordering_tests() { | |
274 cat >>$TESTS <<EOF | |
275 %% real values can be ordered (uses as,af) | |
7287 | 276 %!assert(as<=bf,sparse(af<=bf)) |
277 %!assert(bf<=as,sparse(bf<=af)) | |
5590 | 278 |
7287 | 279 %!assert(as>=bf,sparse(af>=bf)) |
280 %!assert(bf>=as,sparse(bf>=af)) | |
5590 | 281 |
7287 | 282 %!assert(as<bf,sparse(af<bf)) |
283 %!assert(bf<as,sparse(bf<af)) | |
5590 | 284 |
7287 | 285 %!assert(as>bf,sparse(af>bf)) |
286 %!assert(bf>as,sparse(bf>af)) | |
5590 | 287 |
288 EOF | |
289 } | |
290 | |
291 gen_sparsesparse_ordering_tests() { | |
292 cat >>$TESTS <<EOF | |
7287 | 293 %!assert(as<=bs,sparse(af<=bf)) |
294 %!assert(as>=bs,sparse(af>=bf)) | |
295 %!assert(as<bs,sparse(af<bf)) | |
296 %!assert(as>bs,sparse(af>bf)) | |
5590 | 297 EOF |
298 } | |
299 | |
300 # test element-wise binary operations: uses as,af,bs,bf,scalar | |
301 gen_elementop_tests() { | |
302 cat >>$TESTS <<EOF | |
303 %% Elementwise binary tests (uses as,af,bs,bf,scalar) | |
7287 | 304 %!assert(as==bs,sparse(af==bf)) |
305 %!assert(bf==as,sparse(bf==af)) | |
5590 | 306 |
7287 | 307 %!assert(as!=bf,sparse(af!=bf)) |
308 %!assert(bf!=as,sparse(bf!=af)) | |
5590 | 309 |
310 %!assert(as+bf,af+bf) | |
311 %!assert(bf+as,bf+af) | |
312 | |
313 %!assert(as-bf,af-bf) | |
314 %!assert(bf-as,bf-af) | |
315 | |
7287 | 316 %!assert(as.*bf,sparse(af.*bf)) |
317 %!assert(bf.*as,sparse(bf.*af)) | |
5590 | 318 |
7287 | 319 %!assert(as./bf,sparse(af./bf),100*eps) |
320 %!assert(bf.\as,sparse(bf.\af),100*eps) | |
5590 | 321 |
322 %!test | |
323 %! sv = as.^bf; | |
324 %! fv = af.^bf; | |
325 %! idx = find(af~=0); | |
7287 | 326 %! assert(sv(:)(idx),sparse(fv(:)(idx)),100*eps) |
5590 | 327 |
328 EOF | |
329 } | |
330 | |
331 gen_sparsesparse_elementop_tests() { | |
332 cat >>$TESTS <<EOF | |
7287 | 333 %!assert(as==bs,sparse(af==bf)) |
334 %!assert(as!=bs,sparse(af!=bf)) | |
335 %!assert(as+bs,sparse(af+bf)) | |
336 %!assert(as-bs,sparse(af-bf)) | |
337 %!assert(as.*bs,sparse(af.*bf)) | |
338 %!xtest assert(as./bs,sparse(af./bf),100*eps); | |
5590 | 339 %!test |
340 %! sv = as.^bs; | |
341 %! fv = af.^bf; | |
342 %! idx = find(af~=0); | |
7287 | 343 %! assert(sv(:)(idx),sparse(fv(:)(idx)),100*eps) |
5590 | 344 |
345 EOF | |
346 } | |
347 | |
348 # test matrix-matrix left and right division: uses as,af,bs,bf | |
349 gen_divop_tests() { | |
350 cat >>$TESTS <<EOF | |
351 %% Matrix-matrix operators (uses af,as,bs,bf) | |
352 %!assert(as/bf,af/bf,100*eps) | |
353 %!assert(af/bs,af/bf,100*eps) | |
7287 | 354 %!assert(as/bs,sparse(af/bf),100*eps) |
5590 | 355 %!assert(bs\af',bf\af',100*eps) |
356 %!assert(bf\as',bf\af',100*eps) | |
7287 | 357 %!assert(bs\as',sparse(bf\af'),100*eps) |
5590 | 358 |
359 EOF | |
360 } | |
361 | |
362 # test matrix-matrix left and right division: uses as,af,bs,bf | |
363 gen_square_divop_tests() { | |
364 cat >>$TESTS <<EOF | |
365 %% Matrix-matrix operators (uses af,as,bs,bf) | |
366 %!assert(as/bf,af/bf,100*eps) | |
367 %!assert(af/bs,af/bf,100*eps) | |
7287 | 368 %!assert(as/bs,sparse(af/bf),100*eps) |
5590 | 369 %!assert(bs\af',bf\af',100*eps) |
370 %!assert(bf\as',bf\af',100*eps) | |
7287 | 371 %!assert(bs\as',sparse(bf\af'),100*eps) |
5590 | 372 |
373 EOF | |
374 } | |
375 | |
376 # test matrix-matrix operations: uses as,af,bs,bf | |
377 gen_matrixop_tests() { | |
378 cat >>$TESTS <<EOF | |
379 %% Matrix-matrix operators (uses af,as,bs,bf) | |
380 %!assert(as*bf',af*bf') | |
381 %!assert(af*bs',af*bf') | |
7287 | 382 %!assert(as*bs',sparse(af*bf')) |
5590 | 383 |
384 EOF | |
385 } | |
386 | |
387 # test diagonal operations | |
388 gen_matrixdiag_tests() { | |
389 cat >>$TESTS <<EOF | |
390 %% Matrix diagonal tests (uses af,as,bf,bs) | |
7515
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
391 %!assert(diag(as),sparse(diag(af))) |
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
392 %!assert(diag(bs),sparse(diag(bf))) |
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
393 %!assert(diag(as,1),sparse(diag(af,1))) |
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
394 %!assert(diag(bs,1),sparse(diag(bf,1))) |
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
395 %!assert(diag(as,-1),sparse(diag(af,-1))) |
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
396 %!assert(diag(bs,-1),sparse(diag(bf,-1))) |
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
397 %!assert(diag(as(:)),sparse(diag(af(:)))) |
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
398 %!assert(diag(as(:),1),sparse(diag(af(:),1))) |
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
399 %!assert(diag(as(:),-1),sparse(diag(af(:),-1))) |
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
400 %!assert(diag(as(:)'),sparse(diag(af(:)'))) |
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
401 %!assert(diag(as(:)',1),sparse(diag(af(:)',1))) |
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
402 %!assert(diag(as(:)',-1),sparse(diag(af(:)',-1))) |
5590 | 403 %!assert(spdiags(as,[0,1]),[diag(af,0),diag(af,1)]) |
404 %!test [tb,tc]=spdiags(as); | |
405 %! assert(spdiags(tb,tc,sparse(zeros(size(as)))),as) | |
406 %! assert(spdiags(tb,tc,size(as,1),size(as,2)),as) | |
407 | |
408 EOF | |
409 } | |
410 | |
411 # test matrix reshape operations | |
412 gen_matrixreshape_tests() { | |
413 cat >>$TESTS <<EOF | |
414 %% Matrix diagonal tests (uses af,as,bf,bs) | |
7287 | 415 %!assert(reshape(as,1,prod(size(as))),sparse(reshape(af,1,prod(size(af))))) |
416 %!assert(reshape(as,prod(size(as)),1),sparse(reshape(af,prod(size(af)),1))) | |
417 %!assert(reshape(as,fliplr(size(as))),sparse(reshape(af,fliplr(size(af))))) | |
418 %!assert(reshape(bs,1,prod(size(as))),sparse(reshape(bf,1,prod(size(af))))) | |
419 %!assert(reshape(bs,prod(size(as)),1),sparse(reshape(bf,prod(size(af)),1))) | |
420 %!assert(reshape(bs,fliplr(size(as))),sparse(reshape(bf,fliplr(size(af))))) | |
5590 | 421 |
422 EOF | |
423 } | |
424 | |
425 # test mapper matrix operations: uses as,af | |
426 print_mapper_test() { | |
7287 | 427 echo "%!assert($1(as),sparse($1(af)))" >>$TESTS |
5590 | 428 } |
429 | |
430 print_real_mapper_test() { | |
431 cat >>$TESTS <<EOF | |
432 %!test | |
5781 | 433 %! wn2s = warning ("query", "Octave:num-to-str"); |
434 %! warning ("off", "Octave:num-to-str"); | |
5590 | 435 %! if isreal(af) |
5953 | 436 %! if ($2) |
7287 | 437 %! assert($1(as),sparse($1(af))) |
5953 | 438 %! else |
439 %! assert($1(as),$1(af)) | |
440 %! endif | |
5590 | 441 %! endif |
5781 | 442 %! warning (wn2s.state, "Octave:num-to-str"); |
5590 | 443 |
444 EOF | |
445 } | |
446 | |
447 gen_mapper_tests() { | |
448 echo "%% Unary matrix tests (uses af,as)">>$TESTS | |
449 print_mapper_test abs | |
450 print_mapper_test acos | |
451 print_mapper_test acosh | |
452 print_mapper_test angle | |
453 print_mapper_test arg | |
454 print_mapper_test asin | |
455 print_mapper_test asinh | |
456 print_mapper_test atan | |
457 print_mapper_test atanh | |
458 print_mapper_test ceil | |
459 print_mapper_test conj | |
460 print_mapper_test cos | |
461 print_mapper_test cosh | |
462 print_mapper_test exp | |
463 print_mapper_test finite | |
464 print_mapper_test fix | |
465 print_mapper_test floor | |
466 print_mapper_test imag | |
467 print_mapper_test isinf | |
468 print_mapper_test isna | |
469 print_mapper_test isnan | |
470 print_mapper_test log | |
471 #print_mapper_test log10 ## fails with different NaN, not a problem | |
472 print_mapper_test real | |
473 print_mapper_test round | |
474 print_mapper_test sign | |
475 print_mapper_test sin | |
476 print_mapper_test sinh | |
477 print_mapper_test sqrt | |
478 print_mapper_test tan | |
479 print_mapper_test tanh | |
480 | |
481 # Specific tests for certain mapper functions | |
482 cat >>$TESTS <<EOF | |
483 %!assert(issparse(abs(as))&&isreal(abs(as))) | |
484 %!assert(issparse(real(as))&&isreal(real(as))) | |
485 %!assert(issparse(imag(as))&&isreal(imag(as))) | |
486 | |
487 EOF | |
488 } | |
489 | |
490 gen_real_mapper_tests() { | |
491 echo "%% Unary matrix tests (uses af,as)">>$TESTS | |
5953 | 492 print_real_mapper_test erf 1 |
493 print_real_mapper_test erfc 1 | |
494 #print_real_mapper_test gamma 1 | |
495 print_real_mapper_test isalnum 0 | |
496 print_real_mapper_test isalpha 0 | |
497 print_real_mapper_test isascii 0 | |
498 print_real_mapper_test iscntrl 0 | |
499 print_real_mapper_test isdigit 0 | |
500 print_real_mapper_test isgraph 0 | |
501 print_real_mapper_test islower 0 | |
502 print_real_mapper_test isprint 0 | |
503 print_real_mapper_test ispunct 0 | |
504 print_real_mapper_test isspace 0 | |
505 print_real_mapper_test isupper 0 | |
506 print_real_mapper_test isxdigit 0 | |
507 #print_real_mapper_test lgamma 1 | |
5590 | 508 |
509 # Specific tests for certain mapper functions | |
510 cat >>$TESTS <<EOF | |
511 | |
512 %% These mapper functions always return a full matrix | |
513 %!test | |
5781 | 514 %! wn2s = warning ("query", "Octave:num-to-str"); |
515 %! warning ("off", "Octave:num-to-str"); | |
5590 | 516 %! if isreal(af) |
517 %! assert(toascii(as),toascii(af)) | |
518 %! assert(tolower(as),tolower(af)) | |
519 %! assert(toupper(as),toupper(af)) | |
520 %! endif | |
5781 | 521 %! warning (wn2s.state, "Octave:num-to-str"); |
5590 | 522 |
523 EOF | |
524 } | |
525 | |
526 # test matrix operations: uses as,af | |
527 gen_unaryop_tests() { | |
528 cat >>$TESTS <<EOF | |
529 %% Unary matrix tests (uses af,as) | |
530 %!assert(issparse(as)) | |
531 %!assert(!issparse(af)) | |
532 %!assert(!(issparse(af)&&iscomplex(af))) | |
533 %!assert(!(issparse(af)&&isreal(af))) | |
7515
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
534 %!assert(sum(as),sparse(sum(af))) |
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
535 %!assert(sum(as,1),sparse(sum(af,1))) |
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
536 %!assert(sum(as,2),sparse(sum(af,2))) |
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
537 %!assert(cumsum(as),sparse(cumsum(af))) |
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
538 %!assert(cumsum(as,1),sparse(cumsum(af,1))) |
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
539 %!assert(cumsum(as,2),sparse(cumsum(af,2))) |
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
540 %!assert(sumsq(as),sparse(sumsq(af))) |
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
541 %!assert(sumsq(as,1),sparse(sumsq(af,1))) |
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
542 %!assert(sumsq(as,2),sparse(sumsq(af,2))) |
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
543 %!assert(prod(as),sparse(prod(af))) |
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
544 %!assert(prod(as,1),sparse(prod(af,1))) |
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
545 %!assert(prod(as,2),sparse(prod(af,2))) |
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
546 %!assert(cumprod(as),sparse(cumprod(af))) |
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
547 %!assert(cumprod(as,1),sparse(cumprod(af,1))) |
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
548 %!assert(cumprod(as,2),sparse(cumprod(af,2))) |
5590 | 549 |
7505
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7326
diff
changeset
|
550 %!assert(min(as),sparse(min(af))) |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7326
diff
changeset
|
551 %!assert(full(min(as(:))),min(af(:))) |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7326
diff
changeset
|
552 %!assert(min(as,[],1),sparse(min(af,[],1))) |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7326
diff
changeset
|
553 %!assert(min(as,[],2),sparse(min(af,[],2))) |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7326
diff
changeset
|
554 %!assert(min(as,[],1),sparse(min(af,[],1))) |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7326
diff
changeset
|
555 %!assert(min(as,0),sparse(min(af,0))) |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7326
diff
changeset
|
556 %!assert(min(as,bs),sparse(min(af,bf))) |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7326
diff
changeset
|
557 %!assert(max(as),sparse(max(af))) |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7326
diff
changeset
|
558 %!assert(full(max(as(:))),max(af(:))) |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7326
diff
changeset
|
559 %!assert(max(as,[],1),sparse(max(af,[],1))) |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7326
diff
changeset
|
560 %!assert(max(as,[],2),sparse(max(af,[],2))) |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7326
diff
changeset
|
561 %!assert(max(as,[],1),sparse(max(af,[],1))) |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7326
diff
changeset
|
562 %!assert(max(as,0),sparse(max(af,0))) |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7326
diff
changeset
|
563 %!assert(max(as,bs),sparse(max(af,bf))) |
5590 | 564 |
565 %!assert(as==as) | |
566 %!assert(as==af) | |
567 %!assert(af==as) | |
568 %!test | |
7505
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7326
diff
changeset
|
569 %! [ii,jj,vv,nr,nc] = find(as); |
5590 | 570 %! assert(af,full(sparse(ii,jj,vv,nr,nc))); |
571 %!assert(nnz(as),sum(af(:)!=0)) | |
572 %!assert(nnz(as),nnz(af)) | |
573 %!assert(issparse(as.')) | |
574 %!assert(issparse(as')) | |
575 %!assert(issparse(-as)) | |
7287 | 576 %!assert(~as,sparse(~af)) |
577 %!assert(as.', sparse(af.')); | |
578 %!assert(as', sparse(af')); | |
579 %!assert(-as, sparse(-af)); | |
580 %!assert(~as, sparse(~af)); | |
5590 | 581 %!error [i,j]=size(af);as(i-1,j+1); |
582 %!error [i,j]=size(af);as(i+1,j-1); | |
583 %!test | |
7505
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7326
diff
changeset
|
584 %! [Is,Js,Vs] = find(as); |
5590 | 585 %! [If,Jf,Vf] = find(af); |
586 %! assert(Is,If); | |
587 %! assert(Js,Jf); | |
588 %! assert(Vs,Vf); | |
589 %!error as(0,1); | |
590 %!error as(1,0); | |
7505
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7326
diff
changeset
|
591 %!assert(find(as),find(af)) |
5590 | 592 %!test |
7505
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7326
diff
changeset
|
593 %! [i,j,v] = find(as); |
5590 | 594 %! [m,n] = size(as); |
595 %! x = sparse(i,j,v,m,n); | |
596 %! assert(x,as); | |
597 %!test | |
7505
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7326
diff
changeset
|
598 %! [i,j,v,m,n] = find(as); |
5590 | 599 %! x = sparse(i,j,v,m,n); |
600 %! assert(x,as); | |
601 %!assert(issparse(horzcat(as,as))); | |
602 %!assert(issparse(vertcat(as,as))); | |
603 %!assert(issparse(cat(1,as,as))); | |
604 %!assert(issparse(cat(2,as,as))); | |
605 %!assert(issparse([as,as])); | |
606 %!assert(issparse([as;as])); | |
607 %!assert(horzcat(as,as), sparse([af,af])); | |
608 %!assert(vertcat(as,as), sparse([af;af])); | |
609 %!assert(horzcat(as,as,as), sparse([af,af,af])); | |
610 %!assert(vertcat(as,as,as), sparse([af;af;af])); | |
611 %!assert([as,as], sparse([af,af])); | |
612 %!assert([as;as], sparse([af;af])); | |
613 %!assert([as,as,as], sparse([af,af,af])); | |
614 %!assert([as;as;as], sparse([af;af;af])); | |
615 %!assert(cat(2,as,as), sparse([af,af])); | |
616 %!assert(cat(1,as,as), sparse([af;af])); | |
617 %!assert(cat(2,as,as,as), sparse([af,af,af])); | |
618 %!assert(cat(1,as,as,as), sparse([af;af;af])); | |
619 %!assert(issparse([as,af])); | |
620 %!assert(issparse([af,as])); | |
621 %!assert([as,af], sparse([af,af])); | |
622 %!assert([as;af], sparse([af;af])); | |
623 | |
624 EOF | |
625 } | |
626 | |
627 # operations which require square matrices. | |
628 gen_square_tests() { | |
629 # The \ and / operator tests on square matrices | |
630 gen_square_divop_tests | |
631 | |
632 cat >>$TESTS <<EOF | |
7243 | 633 %!testif HAVE_UMFPACK |
7505
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7326
diff
changeset
|
634 %! assert(det(bs+speye(size(bs))),det(bf+eye(size(bf))),100*eps*abs(det(bf+eye(size(bf))))) |
5590 | 635 |
7243 | 636 %!testif HAVE_UMFPACK |
7515
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
637 %! [l,u]=lu(sparse([1,1;1,1])); |
5590 | 638 %! assert(l*u,[1,1;1,1],10*eps); |
639 | |
7243 | 640 %!testif HAVE_UMFPACK |
7515
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
641 %! [l,u]=lu(sparse([1,1;1,1+i])); |
5590 | 642 %! assert(l,sparse([1,2,2],[1,1,2],1),10*eps); |
643 %! assert(u,sparse([1,1,2],[1,2,2],[1,1,1i]),10*eps); | |
644 | |
7243 | 645 %!testif HAVE_UMFPACK ;# permuted LU |
7515
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
646 %! [L,U] = lu(bs); |
5590 | 647 %! assert(L*U,bs,1e-10); |
648 | |
7243 | 649 %!testif HAVE_UMFPACK ;# simple LU + row permutations |
7515
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
650 %! [L,U,P] = lu(bs); |
5590 | 651 %! assert(P'*L*U,bs,1e-10); |
652 %! # triangularity | |
7505
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7326
diff
changeset
|
653 %! [i,j,v]=find(L); |
5590 | 654 %! assert(i-j>=0); |
7505
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7326
diff
changeset
|
655 %! [i,j,v]=find(U); |
5590 | 656 %! assert(j-i>=0); |
657 | |
7243 | 658 %!testif HAVE_UMFPACK ;# simple LU + row/col permutations |
7515
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
659 %! [L,U,P,Q] = lu(bs); |
5590 | 660 %! assert(P'*L*U*Q',bs,1e-10); |
661 %! # triangularity | |
7505
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7326
diff
changeset
|
662 %! [i,j,v]=find(L); |
5590 | 663 %! assert(i-j>=0); |
7505
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7326
diff
changeset
|
664 %! [i,j,v]=find(U); |
5590 | 665 %! assert(j-i>=0); |
666 | |
7515
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
667 %!testif HAVE_UMFPACK ;# LU with vector permutations |
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
668 %! [L,U,P] = lu(bs,'vector'); |
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
669 %! assert(L(P,:)*U,bs,1e-10); |
5590 | 670 %! # triangularity |
7505
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7326
diff
changeset
|
671 %! [i,j,v]=find(L); |
5590 | 672 %! assert(i-j>=0); |
7515
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
673 %! [i,j,v]=find(U); |
5590 | 674 %! assert(j-i>=0); |
675 | |
7515
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
676 %!testif HAVE_UMFPACK ;# LU with scaling |
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
677 %! [L,U,P,Q,R] = lu(bs); |
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
678 %! assert(R*P'*L*U*Q',bs,1e-10); |
5590 | 679 %! # triangularity |
7505
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7326
diff
changeset
|
680 %! [i,j,v]=find(L); |
5590 | 681 %! assert(i-j>=0); |
7505
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7326
diff
changeset
|
682 %! [i,j,v]=find(U); |
5590 | 683 %! assert(j-i>=0); |
684 | |
7243 | 685 %!testif HAVE_UMFPACK ;# inverse |
7515
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
686 %! assert(inv(bs)*bs,sparse(eye(rows(bs))),1e-10); |
5590 | 687 |
688 %!assert(bf\as',bf\af',100*eps); | |
689 %!assert(bs\af',bf\af',100*eps); | |
690 %!assert(bs\as',sparse(bf\af'),100*eps); | |
691 | |
692 EOF | |
693 } | |
694 | |
695 # Cholesky tests | |
696 gen_cholesky_tests() { | |
697 cat >>$TESTS <<EOF | |
7243 | 698 %!testif HAVE_CHOLMOD |
7515
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
699 %! assert(chol(bs)'*chol(bs),bs,1e-10); |
7243 | 700 %!testif HAVE_CHOLMOD |
7515
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
701 %! assert(chol(bs,'lower')*chol(bs,'lower')',bs,1e-10); |
7243 | 702 %!testif HAVE_CHOLMOD |
7515
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
703 %! assert(chol(bs,'lower'),chol(bs)',1e-10); |
5590 | 704 |
7243 | 705 %!testif HAVE_CHOLMOD ;# Return Partial Cholesky factorization |
7515
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
706 %! [RS,PS] = chol(bs); |
5590 | 707 %! assert(RS'*RS,bs,1e-10); |
708 %! assert(PS,0); | |
7515
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
709 %! [LS,PS] = chol(bs,'lower'); |
5590 | 710 %! assert(LS*LS',bs,1e-10); |
711 %! assert(PS,0); | |
712 | |
7243 | 713 %!testif HAVE_CHOLMOD ;# Permuted Cholesky factorization |
7515
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
714 %! [RS,PS,QS] = chol(bs); |
5590 | 715 %! assert(RS'*RS,QS*bs*QS',1e-10); |
716 %! assert(PS,0); | |
7515
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
717 %! [LS,PS,QS] = chol(bs,'lower'); |
5590 | 718 %! assert(LS*LS',QS*bs*QS',1e-10); |
719 %! assert(PS,0); | |
720 | |
721 EOF | |
722 } | |
723 | |
724 # test scalar operations: uses af and real scalar bf; modifies as,bf,bs | |
725 gen_scalar_tests() { | |
726 echo '%!test as=sparse(af);' >> $TESTS | |
727 echo '%!test bs=bf;' >> $TESTS | |
728 gen_elementop_tests | |
729 gen_ordering_tests | |
730 echo '%!test bf=bf+1i;' >>$TESTS | |
731 echo '%!test bs=bf;' >> $TESTS | |
732 gen_elementop_tests | |
733 } | |
734 | |
735 # test matrix operations: uses af and bf; modifies as,bs | |
736 gen_rectangular_tests() { | |
737 echo '%!test as=sparse(af);' >> $TESTS | |
738 echo '%!test bs=sparse(bf);' >>$TESTS | |
739 gen_mapper_tests | |
740 gen_real_mapper_tests | |
741 gen_unaryop_tests | |
742 gen_elementop_tests | |
743 gen_sparsesparse_elementop_tests | |
744 gen_matrixop_tests | |
745 # gen_divop_tests # Disable rectangular \ and / for now | |
746 gen_matrixdiag_tests | |
747 gen_matrixreshape_tests | |
748 } | |
749 | |
750 | |
751 # ======================================================= | |
752 # sparse assembly tests | |
753 | |
754 gen_assembly_tests() { | |
755 cat >>$TESTS <<EOF | |
756 %%Assembly tests | |
757 %!test | |
758 %! m=max([m;r(:)]); | |
759 %! n=max([n;c(:)]); | |
760 %! funiq=fsum=zeros(m,n); | |
761 %! funiq(r(:) + m*(c(:)-1) ) = ones(size(r(:))); | |
762 %! funiq = sparse(funiq); | |
763 %! for k=1:length(r), fsum(r(k),c(k)) += 1; end | |
764 %! fsum = sparse(fsum); | |
765 %!assert(sparse(r,c,1),sparse(fsum(1:max(r),1:max(c)))); | |
766 %!assert(sparse(r,c,1,"sum"),sparse(fsum(1:max(r),1:max(c)))); | |
767 %!assert(sparse(r,c,1,"unique"),sparse(funiq(1:max(r),1:max(c)))); | |
768 %!assert(sparse(r,c,1,m,n),sparse(fsum)); | |
769 %!assert(sparse(r,c,1,m,n,"sum"),sparse(fsum)); | |
770 %!assert(sparse(r,c,1,m,n,"unique"),sparse(funiq)); | |
771 | |
772 %!assert(sparse(r,c,1i),sparse(fsum(1:max(r),1:max(c))*1i)); | |
773 %!assert(sparse(r,c,1i,"sum"),sparse(fsum(1:max(r),1:max(c))*1i)); | |
774 %!assert(sparse(r,c,1i,"unique"),sparse(funiq(1:max(r),1:max(c))*1i)); | |
775 %!assert(sparse(r,c,1i,m,n),sparse(fsum*1i)); | |
776 %!assert(sparse(r,c,1i,m,n,"sum"),sparse(fsum*1i)); | |
777 %!assert(sparse(r,c,1i,m,n,"unique"),sparse(funiq*1i)); | |
778 | |
779 %!test | |
780 %! if (issparse(funiq)) | |
781 %! assert(sparse(full(1i*funiq)),sparse(1i*funiq)); | |
782 %! endif | |
783 | |
784 %!assert(sparse(full(funiq)),funiq); | |
785 | |
786 | |
787 EOF | |
788 } | |
789 | |
790 # ======================================================= | |
791 # sparse selection tests | |
792 | |
7326 | 793 gen_scalar_select_tests () { |
794 cat >>$TESTS <<EOF | |
795 %!assert (sparse(42)([1,1]),sparse([42,42])) | |
796 %!assert (sparse(42*1i)([1,1]),sparse([42,42].*1i)) | |
797 EOF | |
798 } | |
799 | |
5590 | 800 gen_select_tests() { |
801 cat >>$TESTS <<EOF | |
802 %!test as=sparse(af); | |
803 | |
804 %% Point tests | |
805 %!test idx=ridx(:)+rows(as)*(cidx(:)-1); | |
7287 | 806 %!assert(sparse(as(idx)),sparse(af(idx))); |
807 %!assert(as(idx),sparse(af(idx))); | |
808 %!assert(as(idx'),sparse(af(idx'))); | |
809 %!assert(as(flipud(idx(:))),sparse(af(flipud(idx(:))))) | |
810 %!assert(as([idx,idx]),sparse(af([idx,idx]))); | |
5590 | 811 %!error(as(reshape([idx;idx],[1,length(idx),2]))); |
812 | |
813 %% Slice tests | |
7287 | 814 %!assert(as(ridx,cidx), sparse(af(ridx,cidx))) |
815 %!assert(as(ridx,:), sparse(af(ridx,:))) | |
816 %!assert(as(:,cidx), sparse(af(:,cidx))) | |
817 %!assert(as(:,:), sparse(af(:,:))) | |
818 %!assert(as((size(as,1):-1:1),:),sparse(af((size(af,1):-1:1),:))) | |
819 %!assert(as(:,(size(as,2):-1:1)),sparse(af(:,(size(af,2):-1:1)))) | |
5603 | 820 |
7322 | 821 %% Indexing tests |
822 %!assert(full(as([1,1],:)), af([1,1],:)) | |
823 %!assert(full(as(:,[1,1])), af(:,[1,1])) | |
824 %!test | |
825 %! [i,j,v] = find (as); | |
826 %! assert (as(i(1),j(1))([1,1]), sparse([v(1),v(1)])) | |
827 | |
5603 | 828 %% Assignment test |
829 %!test | |
830 %! ts=as;ts(:,:)=ts(fliplr(1:size(as,1)),:); | |
831 %! tf=af;tf(:,:)=tf(fliplr(1:size(af,1)),:); | |
7287 | 832 %! assert(ts,sparse(tf)); |
5603 | 833 %!test |
834 %! ts=as;ts(fliplr(1:size(as,1)),:)=ts; | |
835 %! tf=af;tf(fliplr(1:size(af,1)),:)=tf; | |
7287 | 836 %! assert(ts,sparse(tf)); |
5603 | 837 %!test |
838 %! ts=as;ts(:,fliplr(1:size(as,2)))=ts; | |
839 %! tf=af;tf(:,fliplr(1:size(af,2)))=tf; | |
7287 | 840 %! assert(ts,sparse(tf)); |
5603 | 841 %!test |
842 %! ts(fliplr(1:size(as,1)))=as(:,1);tf(fliplr(1:size(af,1)))=af(:,1); | |
7287 | 843 %! assert(ts,sparse(tf)); |
5603 | 844 |
845 %% Deletion tests | |
846 %!test | |
847 %! ts=as;ts(1,:)=[];tf=af;tf(1,:)=[]; | |
7287 | 848 %! assert(ts,sparse(tf)); |
5603 | 849 %!test |
850 %! ts=as;ts(:,1)=[];tf=af;tf(:,1)=[]; | |
7287 | 851 %! assert(ts,sparse(tf)); |
5590 | 852 |
853 %% Test 'end' keyword | |
7197 | 854 %!assert(full(as(end)), af(end)) |
855 %!assert(full(as(1,end)), af(1,end)) | |
856 %!assert(full(as(end,1)), af(end,1)) | |
857 %!assert(full(as(end,end)), af(end,end)) | |
7287 | 858 %!assert(as(2:end,2:end), sparse(af(2:end,2:end))) |
859 %!assert(as(1:end-1,1:end-1), sparse(af(1:end-1,1:end-1))) | |
5590 | 860 EOF |
861 } | |
862 | |
863 # ======================================================= | |
864 # sparse save and load tests | |
865 | |
866 gen_save_tests() { | |
867 cat >>$TESTS <<EOF | |
868 %!test # save ascii | |
869 %! savefile= tmpnam(); | |
870 %! as_save=as; save("-text",savefile,"bf","as_save","af"); | |
871 %! clear as_save; | |
872 %! load(savefile,"as_save"); | |
873 %! unlink(savefile); | |
874 %! assert(as_save,sparse(af)); | |
875 %!test # save binary | |
876 %! savefile= tmpnam(); | |
877 %! as_save=as; save("-binary",savefile,"bf","as_save","af"); | |
878 %! clear as_save; | |
879 %! load(savefile,"as_save"); | |
880 %! unlink(savefile); | |
881 %! assert(as_save,sparse(af)); | |
882 %!test # save hdf5 | |
883 %! savefile= tmpnam(); | |
884 %! as_save=as; save("-hdf5",savefile,"bf","as_save","af"); | |
885 %! clear as_save; | |
886 %! load(savefile,"as_save"); | |
887 %! unlink(savefile); | |
888 %! assert(as_save,sparse(af)); | |
889 %!test # save matlab | |
890 %! savefile= tmpnam(); | |
891 %! as_save=as; save("-mat",savefile,"bf","as_save","af"); | |
892 %! clear as_save; | |
893 %! load(savefile,"as_save"); | |
894 %! unlink(savefile); | |
895 %! assert(as_save,sparse(af)); | |
896 EOF | |
897 } | |
898 | |
899 # ============================================================= | |
900 # Specific solver tests for matrices that will test all of the solver | |
901 # code. Uses alpha and beta | |
902 gen_solver_tests() { | |
903 | |
904 if $preset; then | |
905 cat >>$TESTS <<EOF | |
906 %! n=8; | |
907 %! lf=diag(1:n);lf(n-1,1)=0.5*alpha;lf(n,2)=0.25*alpha;ls=sparse(lf); | |
908 %! uf=diag(1:n);uf(1,n-1)=2*alpha;uf(2,n)=alpha;us=sparse(uf); | |
909 %! ts=spdiags(ones(n,3),-1:1,n,n)+diag(1:n); tf = full(ts); | |
910 EOF | |
911 else | |
912 cat >>$TESTS <<EOF | |
913 %! n=floor(lognormal_rnd(8,2)+1)' | |
914 %! ls = tril(sprandn(8,8,0.2),-1).*alpha + n*speye(8); lf = full(ls); | |
915 %! us = triu(sprandn(8,8,0.2),1).*alpha + n*speye(8); uf = full(us); | |
916 %! ts = spdiags(randn(8,3),-1:1,8,8).*alpha; tf = full(ts); | |
917 EOF | |
918 fi | |
919 | |
920 cat >>$TESTS <<EOF | |
921 %! df = diag(1:n).* alpha; ds = sparse(df); | |
922 %! pdf = df(randperm(n),randperm(n)); pds = sparse(pdf); | |
923 %! plf = lf(randperm(n),randperm(n)); pls = sparse(plf); | |
924 %! puf = uf(randperm(n),randperm(n)); pus = sparse(puf); | |
925 %! bs = spdiags(repmat([1:n]',1,4),-2:1,n,n).*alpha; bf = full(bs); | |
926 %! cf = lf + lf'; cs = sparse(cf); | |
927 %! bcf = bf + bf'; bcs = sparse(bcf); | |
928 %! tcf = tf + tf'; tcs = sparse(tcf); | |
929 %! xf = diag(1:n) + fliplr(diag(1:n)).*beta; xs = sparse(xf); | |
7080 | 930 %!assert(ds\xf,df\xf,1e-10); |
7287 | 931 %!assert(ds\xs,sparse(df\xf),1e-10); |
5590 | 932 %!assert(pds\xf,pdf\xf,1e-10); |
7287 | 933 %!assert(pds\xs,sparse(pdf\xf),1e-10); |
5590 | 934 %!assert(ls\xf,lf\xf,1e-10); |
935 %!assert(sparse(ls\xs),sparse(lf\xf),1e-10); | |
7243 | 936 %!testif HAVE_UMFPACK |
937 %! assert(pls\xf,plf\xf,1e-10); | |
938 %!testif HAVE_UMFPACK | |
939 %! assert(sparse(pls\xs),sparse(plf\xf),1e-10); | |
5590 | 940 %!assert(us\xf,uf\xf,1e-10); |
941 %!assert(sparse(us\xs),sparse(uf\xf),1e-10); | |
7243 | 942 %!testif HAVE_UMFPACK |
943 %! assert(pus\xf,puf\xf,1e-10); | |
944 %!testif HAVE_UMFPACK | |
945 %! assert(sparse(pus\xs),sparse(puf\xf),1e-10); | |
5590 | 946 %!assert(bs\xf,bf\xf,1e-10); |
947 %!assert(sparse(bs\xs),sparse(bf\xf),1e-10); | |
7243 | 948 %!testif HAVE_UMFPACK |
949 %! assert(cs\xf,cf\xf,1e-10); | |
950 %!testif HAVE_UMFPACK | |
951 %! assert(sparse(cs\xs),sparse(cf\xf),1e-10); | |
952 %!testif HAVE_UMFPACK | |
953 %! assert(bcs\xf,bcf\xf,1e-10); | |
7254 | 954 %!testif HAVE_UMFPACK |
7243 | 955 %! assert(sparse(bcs\xs),sparse(bcf\xf),1e-10); |
5590 | 956 %!assert(ts\xf,tf\xf,1e-10); |
957 %!assert(sparse(ts\xs),sparse(tf\xf),1e-10); | |
958 %!assert(tcs\xf,tcf\xf,1e-10); | |
959 %!assert(sparse(tcs\xs),sparse(tcf\xf),1e-10); | |
960 | |
961 EOF | |
5610 | 962 |
963 cat >>$TESTS <<EOF | |
964 %% QR solver tests | |
965 | |
966 %!function f(a, sz, feps) | |
967 %! b = randn(sz); x = a \b; | |
968 %! assert (a * x, b, feps); | |
969 %! b = randn(sz)+1i*randn(sz); x = a \ b; | |
970 %! assert (a * x, b, feps); | |
971 %! b = sprandn(sz(1),sz(2),0.2); x = a \b; | |
972 %! assert (sparse(a * x), b, feps); | |
973 %! b = sprandn(sz(1),sz(2),0.2)+1i*sprandn(sz(1),sz(2),0.2); x = a \b; | |
974 %! assert (sparse(a * x), b, feps); | |
7243 | 975 %!testif HAVE_CXSPARSE |
5610 | 976 %! a = alpha*sprandn(10,11,0.2)+speye(10,11); f(a,[10,2],1e-10); |
5630 | 977 %! ## Test this by forcing matrix_type, as can't get a certain |
978 %! ## result for over-determined systems. | |
5610 | 979 %! a = alpha*sprandn(10,10,0.2)+speye(10,10); matrix_type(a, "Singular"); |
980 %! f(a,[10,2],1e-10); | |
981 | |
5630 | 982 %% Rectanguar solver tests that don't use QR |
983 | |
984 %!test | |
985 %! ds = alpha * spdiags([1:11]',0,10,11); | |
986 %! df = full(ds); | |
5681 | 987 %! xf = beta * ones(10,2); |
5630 | 988 %! xs = speye(10,10); |
989 %!assert(ds\xf,df\xf,100*eps) | |
7287 | 990 %!assert(ds\xs,sparse(df\xs),100*eps) |
5630 | 991 %!test |
992 %! pds = ds([2,1,3:10],:); | |
993 %! pdf = full(pds); | |
994 %!assert(pds\xf,pdf\xf,100*eps) | |
7287 | 995 %!assert(pds\xs,sparse(pdf\xs),100*eps) |
5630 | 996 %!test |
997 %! ds = alpha * spdiags([1:11]',0,11,10); | |
998 %! df = full(ds); | |
5681 | 999 %! xf = beta * ones(11,2); |
5630 | 1000 %! xs = speye(11,11); |
1001 %!assert(ds\xf,df\xf,100*eps) | |
7287 | 1002 %!assert(ds\xs,sparse(df\xs),100*eps) |
5630 | 1003 %!test |
1004 %! pds = ds([2,1,3:11],:); | |
1005 %! pdf = full(pds); | |
1006 %!assert(pds\xf,pdf\xf,100*eps) | |
7287 | 1007 %!assert(pds\xs,sparse(pdf\xs),100*eps) |
5630 | 1008 %!test |
1009 %! us = alpha*[[speye(10,10);sparse(1,10)],[[1,1];sparse(9,2);[1,1]]]; | |
7243 | 1010 %!testif HAVE_UMFPACK |
1011 %! assert(us*(us\xf),xf,100*eps) | |
1012 %!testif HAVE_UMFPACK | |
1013 %! assert(us*(us\xs),xs,100*eps) | |
5630 | 1014 %!test |
1015 %! pus = us(:,[2,1,3:12]); | |
7243 | 1016 %!testif HAVE_UMFPACK |
1017 %! assert(pus*(pus\xf),xf,100*eps) | |
1018 %!testif HAVE_UMFPACK | |
1019 %! assert(pus*(pus\xs),xs,100*eps) | |
5630 | 1020 %!test |
1021 %! us = alpha*[speye(11,9),[1;sparse(8,1);1;0]]; | |
7243 | 1022 %!testif HAVE_CXSPARSE |
7505
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7326
diff
changeset
|
1023 %! [c,r] = qr (us, xf); |
5630 | 1024 %! assert(us\xf,r\c,100*eps) |
7243 | 1025 %!testif HAVE_CXSPARSE |
7505
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7326
diff
changeset
|
1026 %! [c,r] = qr (us, xs); |
5681 | 1027 %! r = matrix_type(r,"Singular"); ## Force Matrix Type |
5630 | 1028 %! assert(us\xs,r\c,100*eps) |
1029 %!test | |
1030 %! pus = us(:,[1:8,10,9]); | |
7243 | 1031 %!testif HAVE_CXSPARSE |
7505
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7326
diff
changeset
|
1032 %! [c,r] = qr (pus, xf); |
5681 | 1033 %! r = matrix_type(r,"Singular"); ## Force Matrix Type |
5630 | 1034 %! assert(pus\xf,r\c,100*eps) |
7243 | 1035 %!testif HAVE_CXSPARSE |
7505
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7326
diff
changeset
|
1036 %! [c,r] = qr (pus, xs); |
5681 | 1037 %! r = matrix_type(r,"Singular"); ## Force Matrix Type |
5630 | 1038 %! assert(pus\xs,r\c,100*eps) |
1039 %!test | |
1040 %! ls = alpha*[speye(9,11);[1,sparse(1,8),1,0]]; | |
5681 | 1041 %! xf = beta * ones(10,2); |
5630 | 1042 %! xs = speye(10,10); |
1043 %!assert(ls*(ls\xf),xf,100*eps) | |
1044 %!assert(ls*(ls\xs),xs,100*eps) | |
1045 %!test | |
1046 %! pls = ls([1:8,10,9],:); | |
1047 %!assert(pls*(pls\xf),xf,100*eps) | |
1048 %!assert(pls*(pls\xs),xs,100*eps) | |
1049 %!test | |
1050 %! ls = alpha*[speye(10,10),sparse(10,1);[1;1],sparse(2,9),[1;1]]; | |
5681 | 1051 %! xf = beta * ones(12,2); |
5630 | 1052 %! xs = speye(12,12); |
7243 | 1053 %!testif HAVE_CXSPARSE |
7505
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7326
diff
changeset
|
1054 %! [c,r] = qr (ls, xf); |
5630 | 1055 %! assert(ls\xf,r\c,100*eps) |
7243 | 1056 %!testif HAVE_CXSPARSE |
7505
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7326
diff
changeset
|
1057 %! [c,r] = qr (ls, xs); |
5681 | 1058 %! r = matrix_type(r,"Singular"); ## Force Matrix Type |
5630 | 1059 %! assert(ls\xs,r\c,100*eps) |
7243 | 1060 %!testif HAVE_CXSPARSE |
5630 | 1061 %! pls = ls(:,[1:8,10,9]); |
7243 | 1062 %!testif HAVE_CXSPARSE |
7505
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7326
diff
changeset
|
1063 %! [c,r] = qr (pls, xf); |
5681 | 1064 %! r = matrix_type(r,"Singular"); ## Force Matrix Type |
5630 | 1065 %! assert(pls\xf,r\c,100*eps) |
7243 | 1066 %!testif HAVE_CXSPARSE |
7505
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7326
diff
changeset
|
1067 %! [c,r] = qr (pls, xs); |
5681 | 1068 %! r = matrix_type(r,"Singular"); ## Force Matrix Type |
5630 | 1069 %! assert(pls\xs,r\c,100*eps) |
1070 | |
5610 | 1071 EOF |
5590 | 1072 } |
1073 | |
1074 | |
1075 # ============================================================= | |
1076 # Putting it all together: defining the combined tests | |
1077 | |
1078 | |
1079 # initial function | |
1080 gen_function | |
1081 gen_section | |
1082 | |
1083 # specific tests | |
1084 if $preset; then | |
1085 gen_specific_tests | |
1086 gen_section | |
1087 fi | |
1088 | |
1089 # scalar operations | |
1090 echo '%!shared as,af,bs,bf' >> $TESTS | |
1091 if $preset; then | |
1092 echo '%!test af=[1+1i,2-1i,0,0;0,0,0,3+2i;0,0,0,4];' >> $TESTS | |
1093 echo '%!test bf=3;' >>$TESTS | |
1094 else | |
1095 cat >>$TESTS <<EOF | |
1096 %!test | |
1097 %! % generate m,n from 1 to <5000 | |
1098 %! m=floor(lognormal_rnd(8,2)+1); | |
1099 %! n=floor(lognormal_rnd(8,2)+1); | |
1100 %! as=sprandn(m,n,0.3); af = full(as+1i*sprandn(as)); | |
1101 %! bf = randn; | |
1102 EOF | |
1103 fi | |
1104 | |
1105 gen_scalar_tests | |
1106 gen_section | |
1107 | |
1108 # rectangular operations | |
1109 if $preset; then | |
1110 echo '%!test af=[1+1i,2-1i,0,0;0,0,0,3+2i;0,0,0,4];' >> $TESTS | |
1111 echo '%!test bf=[0,1-1i,0,0;2+1i,0,0,0;3-1i,2+3i,0,0];' >> $TESTS | |
1112 else | |
1113 cat >>$TESTS <<EOF | |
1114 %!test | |
1115 %! m=floor(lognormal_rnd(8,2)+1); | |
1116 %! n=floor(lognormal_rnd(8,2)+1); | |
1117 %! as=sprandn(m,n,0.3); af = full(as+1i*sprandn(as)); | |
1118 %! bs=sprandn(m,n,0.3); bf = full(bs+1i*sprandn(bs)); | |
1119 EOF | |
1120 fi | |
1121 | |
1122 gen_rectangular_tests | |
1123 gen_section | |
1124 gen_save_tests | |
1125 gen_section | |
1126 echo '%!test bf=real(bf);' >> $TESTS | |
1127 gen_rectangular_tests | |
1128 gen_section | |
1129 gen_sparsesparse_ordering_tests | |
1130 gen_section | |
1131 echo '%!test af=real(af);' >> $TESTS | |
1132 gen_rectangular_tests | |
1133 gen_section | |
1134 gen_save_tests | |
1135 gen_section | |
1136 echo '%!test bf=bf+1i*(bf~=0);' >> $TESTS | |
1137 gen_rectangular_tests | |
1138 gen_section | |
1139 | |
1140 # square operations | |
1141 if $preset; then | |
1142 echo '%!test af=[1+1i,2-1i,0,0;0,0,0,3+2i;0,0,0,4];' >> $TESTS | |
1143 echo '%! as=sparse(af);' >> $TESTS | |
1144 echo '%!test bf=[0,1-1i,0,0;2+1i,0,0,0;3-1i,2+3i,0,0];' >> $TESTS | |
1145 else | |
1146 cat >>$TESTS <<EOF | |
1147 %!test | |
1148 %! m=floor(lognormal_rnd(8,2)+1); | |
1149 %! n=floor(lognormal_rnd(8,2)+1); | |
1150 %! as=sprandn(m,n,0.3); af = full(as+1i*sprandn(as)); | |
1151 %! bs=sprandn(m,n,0.3); bf = full(bs+1i*sprandn(bs)); | |
1152 EOF | |
1153 fi | |
1154 | |
1155 cat >>$TESTS <<EOF | |
1156 %!test ;# invertible matrix | |
1157 %! bf=af'*bf+max(abs([af(:);bf(:)]))*sparse(eye(columns(as))); | |
1158 %! bs=sparse(bf); | |
1159 | |
1160 EOF | |
1161 | |
1162 gen_square_tests | |
1163 gen_section | |
1164 echo '%!test bf=real(bf);' >> $TESTS | |
1165 echo '%! bs=sparse(bf);' >> $TESTS | |
1166 gen_square_tests | |
1167 gen_section | |
1168 echo '%!test af=real(af);' >> $TESTS | |
1169 echo '%! as=sparse(af);' >> $TESTS | |
1170 gen_square_tests | |
1171 gen_section | |
1172 echo '%!test bf=bf+1i*(bf~=0);' >> $TESTS | |
1173 echo '%! bs=sparse(bf);' >> $TESTS | |
1174 gen_square_tests | |
1175 gen_section | |
1176 | |
1177 # cholesky tests | |
1178 if $preset; then | |
1179 echo '%!test bf=[5,0,1+1i,0;0,5,0,1-2i;1-1i,0,5,0;0,1+2i,0,5];' >> $TESTS | |
1180 echo '%! bs=sparse(bf);' >> $TESTS | |
1181 else | |
1182 echo '# This has a small chance of failing to create a positive definite matrix' >> $TESTS | |
1183 echo '%!test n=floor(lognormal_rnd(8,2)+1)' >> $TESTS | |
1184 echo '%! bs = n*speye(n,n) + sprandn(n,n,0.3); bf = full(bs);' >> $TESTS | |
1185 fi | |
1186 | |
1187 gen_cholesky_tests | |
1188 gen_section | |
1189 echo '%!test bf=real(bf);' >> $TESTS | |
1190 echo '%! bs=sparse(bf);' >> $TESTS | |
1191 gen_cholesky_tests | |
1192 gen_section | |
1193 | |
1194 # assembly tests | |
1195 echo '%!shared r,c,m,n,fsum,funiq' >>$TESTS | |
1196 if $use_preset; then | |
1197 cat >>$TESTS <<EOF | |
1198 %!test | |
1199 %! r=[1,1,2,1,2,3]; | |
1200 %! c=[2,1,1,1,2,1]; | |
1201 %! m=n=0; | |
1202 EOF | |
1203 else | |
1204 cat >>$TESTS <<EOF | |
1205 %!test | |
1206 %! % generate m,n from 1 to <5000 | |
1207 %! m=floor(lognormal_rnd(8,2)+1); | |
1208 %! n=floor(lognormal_rnd(8,2)+1); | |
1209 %! nz=ceil((m+n)/2); | |
1210 %! r=floor(rand(5,nz)*n)+1; | |
1211 %! c=floor(rand(5,nn)*m)+1; | |
1212 EOF | |
1213 fi | |
1214 gen_assembly_tests #includes real and complex tests | |
1215 gen_section | |
1216 | |
1217 # slicing tests | |
1218 echo '%!shared ridx,cidx,idx,as,af' >>$TESTS | |
1219 if $use_preset; then | |
1220 cat >>$TESTS <<EOF | |
1221 %!test | |
1222 %! af=[1+1i,2-1i,0,0;0,0,0,3+2i;0,0,0,4]; | |
1223 %! ridx=[1,3]; cidx=[2,3]; | |
1224 EOF | |
1225 else | |
1226 cat >>$TESTS <<EOF | |
1227 %!test | |
1228 %! % generate m,n from 1 to <5000 | |
1229 %! m=floor(lognormal_rnd(8,2)+1); | |
1230 %! n=floor(lognormal_rnd(8,2)+1); | |
1231 %! as=sprandn(m,n,0.3); af = full(as+1i*sprandn(as)); | |
1232 %! ridx = ceil(m*rand(1,ceil(rand*m)) | |
1233 %! cidx = ceil(n*rand(1,ceil(rand*n)) | |
1234 EOF | |
1235 fi | |
7326 | 1236 gen_scalar_select_tests |
5590 | 1237 gen_select_tests |
1238 echo '%!test af=real(af);' >> $TESTS | |
1239 gen_select_tests | |
1240 gen_section | |
1241 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 | |
1242 echo '%!test alpha=1;beta=1;' >> $TESTS | |
1243 gen_solver_tests | |
1244 echo '%!test alpha=1;beta=1i;' >> $TESTS | |
1245 gen_solver_tests | |
1246 echo '%!test alpha=1i;beta=1;' >> $TESTS | |
1247 gen_solver_tests | |
1248 echo '%!test alpha=1i;beta=1i;' >> $TESTS | |
1249 gen_solver_tests | |
1250 gen_section |