Mercurial > hg > octave-nkf
annotate test/build_sparse_tests.sh @ 12119:e320928eeb3a release-3-2-x release-3-2-4
version 3.2.4
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Fri, 22 Jan 2010 12:43:12 +0100 |
parents | 97c84c4c2247 |
children | 25417bd9a3c7 |
rev | line source |
---|---|
5590 | 1 #!/bin/sh |
2 | |
8920 | 3 # Copyright (C) 2006, 2007, 2008, 2009 David Bateman |
7019 | 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"); | |
8836
d79edebd8f45
fix sparse diag divide by zero test
John W. Eaton <jwe@octave.org>
parents:
8366
diff
changeset
|
219 %! assert(full(sparse(eye(3))/0),full(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 |
8954
97c84c4c2247
Make the column permutation vector in sparse LU cols()-long.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
668 %! [L,U,P,Q] = lu(bs,'vector'); |
97c84c4c2247
Make the column permutation vector in sparse LU cols()-long.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
669 %! assert(L(P,:)*U(:,Q),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 | |
8954
97c84c4c2247
Make the column permutation vector in sparse LU cols()-long.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
748 cat >>$TESTS <<EOF |
97c84c4c2247
Make the column permutation vector in sparse LU cols()-long.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
749 %!testif HAVE_UMFPACK ;# permuted LU |
97c84c4c2247
Make the column permutation vector in sparse LU cols()-long.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
750 %! [L,U] = lu(bs); |
97c84c4c2247
Make the column permutation vector in sparse LU cols()-long.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
751 %! assert(L*U,bs,1e-10); |
97c84c4c2247
Make the column permutation vector in sparse LU cols()-long.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
752 |
97c84c4c2247
Make the column permutation vector in sparse LU cols()-long.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
753 %!testif HAVE_UMFPACK ;# simple LU + row permutations |
97c84c4c2247
Make the column permutation vector in sparse LU cols()-long.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
754 %! [L,U,P] = lu(bs); |
97c84c4c2247
Make the column permutation vector in sparse LU cols()-long.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
755 %! assert(P'*L*U,bs,1e-10); |
97c84c4c2247
Make the column permutation vector in sparse LU cols()-long.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
756 %! # triangularity |
97c84c4c2247
Make the column permutation vector in sparse LU cols()-long.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
757 %! [i,j,v]=find(L); |
97c84c4c2247
Make the column permutation vector in sparse LU cols()-long.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
758 %! assert(i-j>=0); |
97c84c4c2247
Make the column permutation vector in sparse LU cols()-long.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
759 %! [i,j,v]=find(U); |
97c84c4c2247
Make the column permutation vector in sparse LU cols()-long.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
760 %! assert(j-i>=0); |
97c84c4c2247
Make the column permutation vector in sparse LU cols()-long.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
761 |
97c84c4c2247
Make the column permutation vector in sparse LU cols()-long.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
762 %!testif HAVE_UMFPACK ;# simple LU + row/col permutations |
97c84c4c2247
Make the column permutation vector in sparse LU cols()-long.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
763 %! [L,U,P,Q] = lu(bs); |
97c84c4c2247
Make the column permutation vector in sparse LU cols()-long.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
764 %! assert(P'*L*U*Q',bs,1e-10); |
97c84c4c2247
Make the column permutation vector in sparse LU cols()-long.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
765 %! # triangularity |
97c84c4c2247
Make the column permutation vector in sparse LU cols()-long.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
766 %! [i,j,v]=find(L); |
97c84c4c2247
Make the column permutation vector in sparse LU cols()-long.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
767 %! assert(i-j>=0); |
97c84c4c2247
Make the column permutation vector in sparse LU cols()-long.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
768 %! [i,j,v]=find(U); |
97c84c4c2247
Make the column permutation vector in sparse LU cols()-long.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
769 %! assert(j-i>=0); |
97c84c4c2247
Make the column permutation vector in sparse LU cols()-long.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
770 |
97c84c4c2247
Make the column permutation vector in sparse LU cols()-long.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
771 %!testif HAVE_UMFPACK ;# LU with vector permutations |
97c84c4c2247
Make the column permutation vector in sparse LU cols()-long.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
772 %! [L,U,P,Q] = lu(bs,'vector'); |
97c84c4c2247
Make the column permutation vector in sparse LU cols()-long.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
773 %! assert(L(P,:)*U(:,Q),bs,1e-10); |
97c84c4c2247
Make the column permutation vector in sparse LU cols()-long.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
774 %! # triangularity |
97c84c4c2247
Make the column permutation vector in sparse LU cols()-long.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
775 %! [i,j,v]=find(L); |
97c84c4c2247
Make the column permutation vector in sparse LU cols()-long.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
776 %! assert(i-j>=0); |
97c84c4c2247
Make the column permutation vector in sparse LU cols()-long.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
777 %! [i,j,v]=find(U); |
97c84c4c2247
Make the column permutation vector in sparse LU cols()-long.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
778 %! assert(j-i>=0); |
97c84c4c2247
Make the column permutation vector in sparse LU cols()-long.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
779 |
97c84c4c2247
Make the column permutation vector in sparse LU cols()-long.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
780 %!testif HAVE_UMFPACK ;# LU with scaling |
97c84c4c2247
Make the column permutation vector in sparse LU cols()-long.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
781 %! [L,U,P,Q,R] = lu(bs); |
97c84c4c2247
Make the column permutation vector in sparse LU cols()-long.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
782 %! assert(R*P'*L*U*Q',bs,1e-10); |
97c84c4c2247
Make the column permutation vector in sparse LU cols()-long.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
783 %! # triangularity |
97c84c4c2247
Make the column permutation vector in sparse LU cols()-long.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
784 %! [i,j,v]=find(L); |
97c84c4c2247
Make the column permutation vector in sparse LU cols()-long.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
785 %! assert(i-j>=0); |
97c84c4c2247
Make the column permutation vector in sparse LU cols()-long.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
786 %! [i,j,v]=find(U); |
97c84c4c2247
Make the column permutation vector in sparse LU cols()-long.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
787 %! assert(j-i>=0); |
97c84c4c2247
Make the column permutation vector in sparse LU cols()-long.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
788 |
97c84c4c2247
Make the column permutation vector in sparse LU cols()-long.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
789 EOF |
5590 | 790 } |
791 | |
792 | |
793 # ======================================================= | |
794 # sparse assembly tests | |
795 | |
796 gen_assembly_tests() { | |
797 cat >>$TESTS <<EOF | |
798 %%Assembly tests | |
799 %!test | |
800 %! m=max([m;r(:)]); | |
801 %! n=max([n;c(:)]); | |
802 %! funiq=fsum=zeros(m,n); | |
803 %! funiq(r(:) + m*(c(:)-1) ) = ones(size(r(:))); | |
804 %! funiq = sparse(funiq); | |
805 %! for k=1:length(r), fsum(r(k),c(k)) += 1; end | |
806 %! fsum = sparse(fsum); | |
807 %!assert(sparse(r,c,1),sparse(fsum(1:max(r),1:max(c)))); | |
808 %!assert(sparse(r,c,1,"sum"),sparse(fsum(1:max(r),1:max(c)))); | |
809 %!assert(sparse(r,c,1,"unique"),sparse(funiq(1:max(r),1:max(c)))); | |
810 %!assert(sparse(r,c,1,m,n),sparse(fsum)); | |
811 %!assert(sparse(r,c,1,m,n,"sum"),sparse(fsum)); | |
812 %!assert(sparse(r,c,1,m,n,"unique"),sparse(funiq)); | |
813 | |
814 %!assert(sparse(r,c,1i),sparse(fsum(1:max(r),1:max(c))*1i)); | |
815 %!assert(sparse(r,c,1i,"sum"),sparse(fsum(1:max(r),1:max(c))*1i)); | |
816 %!assert(sparse(r,c,1i,"unique"),sparse(funiq(1:max(r),1:max(c))*1i)); | |
817 %!assert(sparse(r,c,1i,m,n),sparse(fsum*1i)); | |
818 %!assert(sparse(r,c,1i,m,n,"sum"),sparse(fsum*1i)); | |
819 %!assert(sparse(r,c,1i,m,n,"unique"),sparse(funiq*1i)); | |
820 | |
821 %!test | |
822 %! if (issparse(funiq)) | |
823 %! assert(sparse(full(1i*funiq)),sparse(1i*funiq)); | |
824 %! endif | |
825 | |
826 %!assert(sparse(full(funiq)),funiq); | |
827 | |
828 | |
829 EOF | |
830 } | |
831 | |
832 # ======================================================= | |
833 # sparse selection tests | |
834 | |
7326 | 835 gen_scalar_select_tests () { |
836 cat >>$TESTS <<EOF | |
837 %!assert (sparse(42)([1,1]),sparse([42,42])) | |
838 %!assert (sparse(42*1i)([1,1]),sparse([42,42].*1i)) | |
839 EOF | |
840 } | |
841 | |
5590 | 842 gen_select_tests() { |
843 cat >>$TESTS <<EOF | |
844 %!test as=sparse(af); | |
845 | |
846 %% Point tests | |
847 %!test idx=ridx(:)+rows(as)*(cidx(:)-1); | |
7287 | 848 %!assert(sparse(as(idx)),sparse(af(idx))); |
849 %!assert(as(idx),sparse(af(idx))); | |
850 %!assert(as(idx'),sparse(af(idx'))); | |
851 %!assert(as(flipud(idx(:))),sparse(af(flipud(idx(:))))) | |
852 %!assert(as([idx,idx]),sparse(af([idx,idx]))); | |
5590 | 853 %!error(as(reshape([idx;idx],[1,length(idx),2]))); |
854 | |
855 %% Slice tests | |
7287 | 856 %!assert(as(ridx,cidx), sparse(af(ridx,cidx))) |
857 %!assert(as(ridx,:), sparse(af(ridx,:))) | |
858 %!assert(as(:,cidx), sparse(af(:,cidx))) | |
859 %!assert(as(:,:), sparse(af(:,:))) | |
860 %!assert(as((size(as,1):-1:1),:),sparse(af((size(af,1):-1:1),:))) | |
861 %!assert(as(:,(size(as,2):-1:1)),sparse(af(:,(size(af,2):-1:1)))) | |
5603 | 862 |
7322 | 863 %% Indexing tests |
864 %!assert(full(as([1,1],:)), af([1,1],:)) | |
865 %!assert(full(as(:,[1,1])), af(:,[1,1])) | |
866 %!test | |
867 %! [i,j,v] = find (as); | |
868 %! assert (as(i(1),j(1))([1,1]), sparse([v(1),v(1)])) | |
869 | |
5603 | 870 %% Assignment test |
871 %!test | |
872 %! ts=as;ts(:,:)=ts(fliplr(1:size(as,1)),:); | |
873 %! tf=af;tf(:,:)=tf(fliplr(1:size(af,1)),:); | |
7287 | 874 %! assert(ts,sparse(tf)); |
5603 | 875 %!test |
876 %! ts=as;ts(fliplr(1:size(as,1)),:)=ts; | |
877 %! tf=af;tf(fliplr(1:size(af,1)),:)=tf; | |
7287 | 878 %! assert(ts,sparse(tf)); |
5603 | 879 %!test |
880 %! ts=as;ts(:,fliplr(1:size(as,2)))=ts; | |
881 %! tf=af;tf(:,fliplr(1:size(af,2)))=tf; | |
7287 | 882 %! assert(ts,sparse(tf)); |
5603 | 883 %!test |
884 %! ts(fliplr(1:size(as,1)))=as(:,1);tf(fliplr(1:size(af,1)))=af(:,1); | |
7287 | 885 %! assert(ts,sparse(tf)); |
5603 | 886 |
887 %% Deletion tests | |
888 %!test | |
889 %! ts=as;ts(1,:)=[];tf=af;tf(1,:)=[]; | |
7287 | 890 %! assert(ts,sparse(tf)); |
5603 | 891 %!test |
892 %! ts=as;ts(:,1)=[];tf=af;tf(:,1)=[]; | |
7287 | 893 %! assert(ts,sparse(tf)); |
5590 | 894 |
895 %% Test 'end' keyword | |
7197 | 896 %!assert(full(as(end)), af(end)) |
897 %!assert(full(as(1,end)), af(1,end)) | |
898 %!assert(full(as(end,1)), af(end,1)) | |
899 %!assert(full(as(end,end)), af(end,end)) | |
7287 | 900 %!assert(as(2:end,2:end), sparse(af(2:end,2:end))) |
901 %!assert(as(1:end-1,1:end-1), sparse(af(1:end-1,1:end-1))) | |
5590 | 902 EOF |
903 } | |
904 | |
905 # ======================================================= | |
906 # sparse save and load tests | |
907 | |
908 gen_save_tests() { | |
909 cat >>$TESTS <<EOF | |
910 %!test # save ascii | |
911 %! savefile= tmpnam(); | |
912 %! as_save=as; save("-text",savefile,"bf","as_save","af"); | |
913 %! clear as_save; | |
914 %! load(savefile,"as_save"); | |
915 %! unlink(savefile); | |
916 %! assert(as_save,sparse(af)); | |
917 %!test # save binary | |
918 %! savefile= tmpnam(); | |
919 %! as_save=as; save("-binary",savefile,"bf","as_save","af"); | |
920 %! clear as_save; | |
921 %! load(savefile,"as_save"); | |
922 %! unlink(savefile); | |
923 %! assert(as_save,sparse(af)); | |
8153
ec0a13863eb7
Only run tests that depend on HDF5 and QHull if Octave was actually
Soren Hauberg <hauberg@gmail.com>
parents:
7515
diff
changeset
|
924 %!testif HAVE_HDF5 # save hdf5 |
5590 | 925 %! savefile= tmpnam(); |
926 %! as_save=as; save("-hdf5",savefile,"bf","as_save","af"); | |
927 %! clear as_save; | |
928 %! load(savefile,"as_save"); | |
929 %! unlink(savefile); | |
930 %! assert(as_save,sparse(af)); | |
8871 | 931 ## FIXME -- we should skip (or mark as an expected failure) the test for |
932 ## saving sparse matrices to MAT files when using 64-bit indexing since | |
933 ## that is not implemented yet. | |
5590 | 934 %!test # save matlab |
935 %! savefile= tmpnam(); | |
936 %! as_save=as; save("-mat",savefile,"bf","as_save","af"); | |
937 %! clear as_save; | |
938 %! load(savefile,"as_save"); | |
939 %! unlink(savefile); | |
940 %! assert(as_save,sparse(af)); | |
941 EOF | |
942 } | |
943 | |
944 # ============================================================= | |
945 # Specific solver tests for matrices that will test all of the solver | |
946 # code. Uses alpha and beta | |
947 gen_solver_tests() { | |
948 | |
949 if $preset; then | |
950 cat >>$TESTS <<EOF | |
951 %! n=8; | |
952 %! lf=diag(1:n);lf(n-1,1)=0.5*alpha;lf(n,2)=0.25*alpha;ls=sparse(lf); | |
953 %! uf=diag(1:n);uf(1,n-1)=2*alpha;uf(2,n)=alpha;us=sparse(uf); | |
954 %! ts=spdiags(ones(n,3),-1:1,n,n)+diag(1:n); tf = full(ts); | |
955 EOF | |
956 else | |
957 cat >>$TESTS <<EOF | |
958 %! n=floor(lognormal_rnd(8,2)+1)' | |
959 %! ls = tril(sprandn(8,8,0.2),-1).*alpha + n*speye(8); lf = full(ls); | |
960 %! us = triu(sprandn(8,8,0.2),1).*alpha + n*speye(8); uf = full(us); | |
961 %! ts = spdiags(randn(8,3),-1:1,8,8).*alpha; tf = full(ts); | |
962 EOF | |
963 fi | |
964 | |
965 cat >>$TESTS <<EOF | |
966 %! df = diag(1:n).* alpha; ds = sparse(df); | |
967 %! pdf = df(randperm(n),randperm(n)); pds = sparse(pdf); | |
968 %! plf = lf(randperm(n),randperm(n)); pls = sparse(plf); | |
969 %! puf = uf(randperm(n),randperm(n)); pus = sparse(puf); | |
970 %! bs = spdiags(repmat([1:n]',1,4),-2:1,n,n).*alpha; bf = full(bs); | |
971 %! cf = lf + lf'; cs = sparse(cf); | |
972 %! bcf = bf + bf'; bcs = sparse(bcf); | |
973 %! tcf = tf + tf'; tcs = sparse(tcf); | |
974 %! xf = diag(1:n) + fliplr(diag(1:n)).*beta; xs = sparse(xf); | |
7080 | 975 %!assert(ds\xf,df\xf,1e-10); |
7287 | 976 %!assert(ds\xs,sparse(df\xf),1e-10); |
5590 | 977 %!assert(pds\xf,pdf\xf,1e-10); |
7287 | 978 %!assert(pds\xs,sparse(pdf\xf),1e-10); |
5590 | 979 %!assert(ls\xf,lf\xf,1e-10); |
980 %!assert(sparse(ls\xs),sparse(lf\xf),1e-10); | |
7243 | 981 %!testif HAVE_UMFPACK |
982 %! assert(pls\xf,plf\xf,1e-10); | |
983 %!testif HAVE_UMFPACK | |
984 %! assert(sparse(pls\xs),sparse(plf\xf),1e-10); | |
5590 | 985 %!assert(us\xf,uf\xf,1e-10); |
986 %!assert(sparse(us\xs),sparse(uf\xf),1e-10); | |
7243 | 987 %!testif HAVE_UMFPACK |
988 %! assert(pus\xf,puf\xf,1e-10); | |
989 %!testif HAVE_UMFPACK | |
990 %! assert(sparse(pus\xs),sparse(puf\xf),1e-10); | |
5590 | 991 %!assert(bs\xf,bf\xf,1e-10); |
992 %!assert(sparse(bs\xs),sparse(bf\xf),1e-10); | |
7243 | 993 %!testif HAVE_UMFPACK |
994 %! assert(cs\xf,cf\xf,1e-10); | |
995 %!testif HAVE_UMFPACK | |
996 %! assert(sparse(cs\xs),sparse(cf\xf),1e-10); | |
997 %!testif HAVE_UMFPACK | |
998 %! assert(bcs\xf,bcf\xf,1e-10); | |
7254 | 999 %!testif HAVE_UMFPACK |
7243 | 1000 %! assert(sparse(bcs\xs),sparse(bcf\xf),1e-10); |
5590 | 1001 %!assert(ts\xf,tf\xf,1e-10); |
1002 %!assert(sparse(ts\xs),sparse(tf\xf),1e-10); | |
1003 %!assert(tcs\xf,tcf\xf,1e-10); | |
1004 %!assert(sparse(tcs\xs),sparse(tcf\xf),1e-10); | |
1005 | |
1006 EOF | |
5610 | 1007 |
1008 cat >>$TESTS <<EOF | |
1009 %% QR solver tests | |
1010 | |
1011 %!function f(a, sz, feps) | |
1012 %! b = randn(sz); x = a \b; | |
1013 %! assert (a * x, b, feps); | |
1014 %! b = randn(sz)+1i*randn(sz); x = a \ b; | |
1015 %! assert (a * x, b, feps); | |
1016 %! b = sprandn(sz(1),sz(2),0.2); x = a \b; | |
1017 %! assert (sparse(a * x), b, feps); | |
1018 %! b = sprandn(sz(1),sz(2),0.2)+1i*sprandn(sz(1),sz(2),0.2); x = a \b; | |
1019 %! assert (sparse(a * x), b, feps); | |
7243 | 1020 %!testif HAVE_CXSPARSE |
5610 | 1021 %! a = alpha*sprandn(10,11,0.2)+speye(10,11); f(a,[10,2],1e-10); |
5630 | 1022 %! ## Test this by forcing matrix_type, as can't get a certain |
1023 %! ## result for over-determined systems. | |
5610 | 1024 %! a = alpha*sprandn(10,10,0.2)+speye(10,10); matrix_type(a, "Singular"); |
1025 %! f(a,[10,2],1e-10); | |
1026 | |
5630 | 1027 %% Rectanguar solver tests that don't use QR |
1028 | |
1029 %!test | |
1030 %! ds = alpha * spdiags([1:11]',0,10,11); | |
1031 %! df = full(ds); | |
5681 | 1032 %! xf = beta * ones(10,2); |
5630 | 1033 %! xs = speye(10,10); |
1034 %!assert(ds\xf,df\xf,100*eps) | |
7287 | 1035 %!assert(ds\xs,sparse(df\xs),100*eps) |
5630 | 1036 %!test |
1037 %! pds = ds([2,1,3:10],:); | |
1038 %! pdf = full(pds); | |
1039 %!assert(pds\xf,pdf\xf,100*eps) | |
7287 | 1040 %!assert(pds\xs,sparse(pdf\xs),100*eps) |
5630 | 1041 %!test |
1042 %! ds = alpha * spdiags([1:11]',0,11,10); | |
1043 %! df = full(ds); | |
5681 | 1044 %! xf = beta * ones(11,2); |
5630 | 1045 %! xs = speye(11,11); |
1046 %!assert(ds\xf,df\xf,100*eps) | |
7287 | 1047 %!assert(ds\xs,sparse(df\xs),100*eps) |
5630 | 1048 %!test |
1049 %! pds = ds([2,1,3:11],:); | |
1050 %! pdf = full(pds); | |
1051 %!assert(pds\xf,pdf\xf,100*eps) | |
7287 | 1052 %!assert(pds\xs,sparse(pdf\xs),100*eps) |
5630 | 1053 %!test |
1054 %! us = alpha*[[speye(10,10);sparse(1,10)],[[1,1];sparse(9,2);[1,1]]]; | |
7243 | 1055 %!testif HAVE_UMFPACK |
1056 %! assert(us*(us\xf),xf,100*eps) | |
1057 %!testif HAVE_UMFPACK | |
1058 %! assert(us*(us\xs),xs,100*eps) | |
5630 | 1059 %!test |
1060 %! pus = us(:,[2,1,3:12]); | |
7243 | 1061 %!testif HAVE_UMFPACK |
1062 %! assert(pus*(pus\xf),xf,100*eps) | |
1063 %!testif HAVE_UMFPACK | |
1064 %! assert(pus*(pus\xs),xs,100*eps) | |
5630 | 1065 %!test |
1066 %! us = alpha*[speye(11,9),[1;sparse(8,1);1;0]]; | |
7243 | 1067 %!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
|
1068 %! [c,r] = qr (us, xf); |
5630 | 1069 %! assert(us\xf,r\c,100*eps) |
7243 | 1070 %!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
|
1071 %! [c,r] = qr (us, xs); |
5681 | 1072 %! r = matrix_type(r,"Singular"); ## Force Matrix Type |
5630 | 1073 %! assert(us\xs,r\c,100*eps) |
1074 %!test | |
1075 %! pus = us(:,[1:8,10,9]); | |
7243 | 1076 %!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
|
1077 %! [c,r] = qr (pus, xf); |
5681 | 1078 %! r = matrix_type(r,"Singular"); ## Force Matrix Type |
5630 | 1079 %! assert(pus\xf,r\c,100*eps) |
7243 | 1080 %!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
|
1081 %! [c,r] = qr (pus, xs); |
5681 | 1082 %! r = matrix_type(r,"Singular"); ## Force Matrix Type |
5630 | 1083 %! assert(pus\xs,r\c,100*eps) |
1084 %!test | |
1085 %! ls = alpha*[speye(9,11);[1,sparse(1,8),1,0]]; | |
5681 | 1086 %! xf = beta * ones(10,2); |
5630 | 1087 %! xs = speye(10,10); |
1088 %!assert(ls*(ls\xf),xf,100*eps) | |
1089 %!assert(ls*(ls\xs),xs,100*eps) | |
1090 %!test | |
1091 %! pls = ls([1:8,10,9],:); | |
1092 %!assert(pls*(pls\xf),xf,100*eps) | |
1093 %!assert(pls*(pls\xs),xs,100*eps) | |
1094 %!test | |
1095 %! ls = alpha*[speye(10,10),sparse(10,1);[1;1],sparse(2,9),[1;1]]; | |
5681 | 1096 %! xf = beta * ones(12,2); |
5630 | 1097 %! xs = speye(12,12); |
7243 | 1098 %!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
|
1099 %! [c,r] = qr (ls, xf); |
5630 | 1100 %! assert(ls\xf,r\c,100*eps) |
7243 | 1101 %!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
|
1102 %! [c,r] = qr (ls, xs); |
5681 | 1103 %! r = matrix_type(r,"Singular"); ## Force Matrix Type |
5630 | 1104 %! assert(ls\xs,r\c,100*eps) |
7243 | 1105 %!testif HAVE_CXSPARSE |
5630 | 1106 %! pls = ls(:,[1:8,10,9]); |
7243 | 1107 %!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
|
1108 %! [c,r] = qr (pls, xf); |
5681 | 1109 %! r = matrix_type(r,"Singular"); ## Force Matrix Type |
5630 | 1110 %! assert(pls\xf,r\c,100*eps) |
7243 | 1111 %!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
|
1112 %! [c,r] = qr (pls, xs); |
5681 | 1113 %! r = matrix_type(r,"Singular"); ## Force Matrix Type |
5630 | 1114 %! assert(pls\xs,r\c,100*eps) |
1115 | |
5610 | 1116 EOF |
5590 | 1117 } |
1118 | |
1119 | |
1120 # ============================================================= | |
1121 # Putting it all together: defining the combined tests | |
1122 | |
1123 | |
1124 # initial function | |
1125 gen_function | |
1126 gen_section | |
1127 | |
1128 # specific tests | |
1129 if $preset; then | |
1130 gen_specific_tests | |
1131 gen_section | |
1132 fi | |
1133 | |
1134 # scalar operations | |
1135 echo '%!shared as,af,bs,bf' >> $TESTS | |
1136 if $preset; then | |
1137 echo '%!test af=[1+1i,2-1i,0,0;0,0,0,3+2i;0,0,0,4];' >> $TESTS | |
1138 echo '%!test bf=3;' >>$TESTS | |
1139 else | |
1140 cat >>$TESTS <<EOF | |
1141 %!test | |
1142 %! % generate m,n from 1 to <5000 | |
1143 %! m=floor(lognormal_rnd(8,2)+1); | |
1144 %! n=floor(lognormal_rnd(8,2)+1); | |
1145 %! as=sprandn(m,n,0.3); af = full(as+1i*sprandn(as)); | |
1146 %! bf = randn; | |
1147 EOF | |
1148 fi | |
1149 | |
1150 gen_scalar_tests | |
1151 gen_section | |
1152 | |
1153 # rectangular operations | |
1154 if $preset; then | |
1155 echo '%!test af=[1+1i,2-1i,0,0;0,0,0,3+2i;0,0,0,4];' >> $TESTS | |
1156 echo '%!test bf=[0,1-1i,0,0;2+1i,0,0,0;3-1i,2+3i,0,0];' >> $TESTS | |
1157 else | |
1158 cat >>$TESTS <<EOF | |
1159 %!test | |
1160 %! m=floor(lognormal_rnd(8,2)+1); | |
1161 %! n=floor(lognormal_rnd(8,2)+1); | |
1162 %! as=sprandn(m,n,0.3); af = full(as+1i*sprandn(as)); | |
1163 %! bs=sprandn(m,n,0.3); bf = full(bs+1i*sprandn(bs)); | |
1164 EOF | |
1165 fi | |
1166 | |
1167 gen_rectangular_tests | |
1168 gen_section | |
1169 gen_save_tests | |
1170 gen_section | |
1171 echo '%!test bf=real(bf);' >> $TESTS | |
1172 gen_rectangular_tests | |
1173 gen_section | |
1174 gen_sparsesparse_ordering_tests | |
1175 gen_section | |
1176 echo '%!test af=real(af);' >> $TESTS | |
1177 gen_rectangular_tests | |
1178 gen_section | |
1179 gen_save_tests | |
1180 gen_section | |
1181 echo '%!test bf=bf+1i*(bf~=0);' >> $TESTS | |
1182 gen_rectangular_tests | |
1183 gen_section | |
1184 | |
1185 # square operations | |
1186 if $preset; then | |
1187 echo '%!test af=[1+1i,2-1i,0,0;0,0,0,3+2i;0,0,0,4];' >> $TESTS | |
1188 echo '%! as=sparse(af);' >> $TESTS | |
1189 echo '%!test bf=[0,1-1i,0,0;2+1i,0,0,0;3-1i,2+3i,0,0];' >> $TESTS | |
1190 else | |
1191 cat >>$TESTS <<EOF | |
1192 %!test | |
1193 %! m=floor(lognormal_rnd(8,2)+1); | |
1194 %! n=floor(lognormal_rnd(8,2)+1); | |
1195 %! as=sprandn(m,n,0.3); af = full(as+1i*sprandn(as)); | |
1196 %! bs=sprandn(m,n,0.3); bf = full(bs+1i*sprandn(bs)); | |
1197 EOF | |
1198 fi | |
1199 | |
1200 cat >>$TESTS <<EOF | |
1201 %!test ;# invertible matrix | |
1202 %! bf=af'*bf+max(abs([af(:);bf(:)]))*sparse(eye(columns(as))); | |
1203 %! bs=sparse(bf); | |
1204 | |
1205 EOF | |
1206 | |
1207 gen_square_tests | |
1208 gen_section | |
1209 echo '%!test bf=real(bf);' >> $TESTS | |
1210 echo '%! bs=sparse(bf);' >> $TESTS | |
1211 gen_square_tests | |
1212 gen_section | |
1213 echo '%!test af=real(af);' >> $TESTS | |
1214 echo '%! as=sparse(af);' >> $TESTS | |
1215 gen_square_tests | |
1216 gen_section | |
1217 echo '%!test bf=bf+1i*(bf~=0);' >> $TESTS | |
1218 echo '%! bs=sparse(bf);' >> $TESTS | |
1219 gen_square_tests | |
1220 gen_section | |
1221 | |
1222 # cholesky tests | |
1223 if $preset; then | |
1224 echo '%!test bf=[5,0,1+1i,0;0,5,0,1-2i;1-1i,0,5,0;0,1+2i,0,5];' >> $TESTS | |
1225 echo '%! bs=sparse(bf);' >> $TESTS | |
1226 else | |
1227 echo '# This has a small chance of failing to create a positive definite matrix' >> $TESTS | |
1228 echo '%!test n=floor(lognormal_rnd(8,2)+1)' >> $TESTS | |
1229 echo '%! bs = n*speye(n,n) + sprandn(n,n,0.3); bf = full(bs);' >> $TESTS | |
1230 fi | |
1231 | |
1232 gen_cholesky_tests | |
1233 gen_section | |
1234 echo '%!test bf=real(bf);' >> $TESTS | |
1235 echo '%! bs=sparse(bf);' >> $TESTS | |
1236 gen_cholesky_tests | |
1237 gen_section | |
1238 | |
1239 # assembly tests | |
1240 echo '%!shared r,c,m,n,fsum,funiq' >>$TESTS | |
1241 if $use_preset; then | |
1242 cat >>$TESTS <<EOF | |
1243 %!test | |
1244 %! r=[1,1,2,1,2,3]; | |
1245 %! c=[2,1,1,1,2,1]; | |
1246 %! m=n=0; | |
1247 EOF | |
1248 else | |
1249 cat >>$TESTS <<EOF | |
1250 %!test | |
1251 %! % generate m,n from 1 to <5000 | |
1252 %! m=floor(lognormal_rnd(8,2)+1); | |
1253 %! n=floor(lognormal_rnd(8,2)+1); | |
1254 %! nz=ceil((m+n)/2); | |
1255 %! r=floor(rand(5,nz)*n)+1; | |
1256 %! c=floor(rand(5,nn)*m)+1; | |
1257 EOF | |
1258 fi | |
1259 gen_assembly_tests #includes real and complex tests | |
1260 gen_section | |
1261 | |
1262 # slicing tests | |
1263 echo '%!shared ridx,cidx,idx,as,af' >>$TESTS | |
1264 if $use_preset; then | |
1265 cat >>$TESTS <<EOF | |
1266 %!test | |
1267 %! af=[1+1i,2-1i,0,0;0,0,0,3+2i;0,0,0,4]; | |
1268 %! ridx=[1,3]; cidx=[2,3]; | |
1269 EOF | |
1270 else | |
1271 cat >>$TESTS <<EOF | |
1272 %!test | |
1273 %! % generate m,n from 1 to <5000 | |
1274 %! m=floor(lognormal_rnd(8,2)+1); | |
1275 %! n=floor(lognormal_rnd(8,2)+1); | |
1276 %! as=sprandn(m,n,0.3); af = full(as+1i*sprandn(as)); | |
1277 %! ridx = ceil(m*rand(1,ceil(rand*m)) | |
1278 %! cidx = ceil(n*rand(1,ceil(rand*n)) | |
1279 EOF | |
1280 fi | |
7326 | 1281 gen_scalar_select_tests |
5590 | 1282 gen_select_tests |
1283 echo '%!test af=real(af);' >> $TESTS | |
1284 gen_select_tests | |
1285 gen_section | |
1286 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 | |
1287 echo '%!test alpha=1;beta=1;' >> $TESTS | |
1288 gen_solver_tests | |
1289 echo '%!test alpha=1;beta=1i;' >> $TESTS | |
1290 gen_solver_tests | |
1291 echo '%!test alpha=1i;beta=1;' >> $TESTS | |
1292 gen_solver_tests | |
1293 echo '%!test alpha=1i;beta=1i;' >> $TESTS | |
1294 gen_solver_tests | |
1295 gen_section |