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