5323
|
1 /* |
|
2 |
7017
|
3 Copyright (C) 2005, 2006, 2007 David Bateman |
5323
|
4 |
5720
|
5 This file is part of Octave. |
|
6 |
5323
|
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 |
7016
|
9 Free Software Foundation; either version 3 of the License, or (at your |
|
10 option) any later version. |
5323
|
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 |
7016
|
18 along with Octave; see the file COPYING. If not, see |
|
19 <http://www.gnu.org/licenses/>. |
5323
|
20 |
|
21 */ |
|
22 |
|
23 #ifdef HAVE_CONFIG_H |
|
24 #include <config.h> |
|
25 #endif |
|
26 |
5403
|
27 #include <algorithm> |
|
28 |
5323
|
29 #include "ov.h" |
|
30 #include "defun-dld.h" |
|
31 #include "error.h" |
5785
|
32 #include "ov-re-mat.h" |
|
33 #include "ov-cx-mat.h" |
5323
|
34 #include "ov-re-sparse.h" |
|
35 #include "ov-cx-sparse.h" |
5785
|
36 #include "MatrixType.h" |
5323
|
37 |
|
38 DEFUN_DLD (matrix_type, args, , |
|
39 "-*- texinfo -*-\n\ |
|
40 @deftypefn {Loadable Function} {@var{type} =} matrix_type (@var{a})\n\ |
|
41 @deftypefnx {Loadable Function} {@var{a} =} matrix_type (@var{a}, @var{type})\n\ |
|
42 @deftypefnx {Loadable Function} {@var{a} =} matrix_type (@var{a}, 'upper', @var{perm})\n\ |
|
43 @deftypefnx {Loadable Function} {@var{a} =} matrix_type (@var{a}, 'lower', @var{perm})\n\ |
|
44 @deftypefnx {Loadable Function} {@var{a} =} matrix_type (@var{a}, 'banded', @var{nl}, @var{nu})\n\ |
|
45 Identify the matrix type or mark a matrix as a particular type. This allows rapid\n\ |
|
46 for solutions of linear equations involving @var{a} to be performed. Called with a\n\ |
|
47 single argument, @code{matrix_type} returns the type of the matrix and caches it for\n\ |
|
48 future use. Called with more than one argument, @code{matrix_type} allows the type\n\ |
|
49 of the matrix to be defined.\n\ |
|
50 \n\ |
|
51 The possible matrix types depend on whether the matrix is full or sparse, and can be\n\ |
|
52 one of the following\n\ |
|
53 \n\ |
|
54 @table @asis\n\ |
|
55 @item 'unknown'\n\ |
|
56 Remove any previously cached matrix type, and mark type as unknown\n\ |
|
57 \n\ |
|
58 @item 'full'\n\ |
|
59 Mark the matrix as full.\n\ |
|
60 \n\ |
|
61 @item 'positive definite'\n\ |
|
62 Full positive definite matrix.\n\ |
|
63 \n\ |
|
64 @item 'diagonal'\n\ |
|
65 Diagonal Matrix. (Sparse matrices only)\n\ |
|
66 \n\ |
|
67 @item 'permuted diagonal'\n\ |
|
68 Permuted Diagonal matrix. The permutation does not need to be specifically\n\ |
|
69 indicated, as the structure of the matrix explicitly gives this. (Sparse matrices\n\ |
|
70 only)\n\ |
|
71 \n\ |
|
72 @item 'upper'\n\ |
|
73 Upper triangular. If the optional third argument @var{perm} is given, the matrix is\n\ |
|
74 assumed to be a permuted upper triangular with the permutations defined by the\n\ |
|
75 vector @var{perm}.\n\ |
|
76 \n\ |
|
77 @item 'lower'\n\ |
|
78 Lower triangular. If the optional third argument @var{perm} is given, the matrix is\n\ |
|
79 assumed to be a permuted lower triangular with the permutations defined by the\n\ |
|
80 vector @var{perm}.\n\ |
|
81 \n\ |
|
82 @item 'banded'\n\ |
|
83 @itemx 'banded positive definite'\n\ |
|
84 Banded matrix with the band size of @var{nl} below the diagonal and @var{nu} above\n\ |
|
85 it. If @var{nl} and @var{nu} are 1, then the matrix is tridiagonal and treated\n\ |
|
86 with specialized code. In addition the matrix can be marked as positive definite\n\ |
|
87 (Sparse matrices only)\n\ |
|
88 \n\ |
|
89 @item 'singular'\n\ |
|
90 The matrix is assumed to be singular and will be treated with a minimum norm solution\n\ |
|
91 \n\ |
|
92 @end table\n\ |
|
93 \n\ |
|
94 Note that the matrix type will be discovered automatically on the first attempt to\n\ |
|
95 solve a linear equation involving @var{a}. Therefore @code{matrix_type} is only\n\ |
5324
|
96 useful to give Octave hints of the matrix type. Incorrectly defining the\n\ |
5323
|
97 matrix type will result in incorrect results from solutions of linear equations,\n\ |
7001
|
98 and so it is entirely the responsibility of the user to correctly identify the\n\ |
5323
|
99 matrix type.\n\ |
|
100 @end deftypefn") |
|
101 { |
|
102 int nargin = args.length (); |
|
103 octave_value retval; |
|
104 |
|
105 if (nargin == 0) |
5823
|
106 print_usage (); |
5323
|
107 else if (nargin > 4) |
|
108 error ("matrix_type: incorrect number of arguments"); |
|
109 else |
|
110 { |
6371
|
111 if (args(0).is_scalar_type()) |
|
112 { |
|
113 if (nargin == 1) |
|
114 retval = octave_value ("Full"); |
|
115 else |
|
116 retval = args(0); |
|
117 } |
|
118 else if (args(0).is_sparse_type ()) |
5323
|
119 { |
|
120 if (nargin == 1) |
|
121 { |
5785
|
122 MatrixType mattyp; |
5323
|
123 |
6371
|
124 if (args(0).is_complex_type ()) |
5323
|
125 { |
5785
|
126 mattyp = args(0).matrix_type (); |
5323
|
127 |
|
128 if (mattyp.is_unknown ()) |
|
129 { |
5681
|
130 SparseComplexMatrix m = |
|
131 args(0).sparse_complex_matrix_value (); |
|
132 if (!error_state) |
|
133 { |
5785
|
134 mattyp = MatrixType (m); |
|
135 args(0).matrix_type (mattyp); |
5681
|
136 } |
5323
|
137 } |
|
138 } |
|
139 else |
|
140 { |
5785
|
141 mattyp = args(0).matrix_type (); |
5323
|
142 |
|
143 if (mattyp.is_unknown ()) |
|
144 { |
5681
|
145 SparseMatrix m = args(0).sparse_matrix_value (); |
|
146 if (!error_state) |
|
147 { |
5785
|
148 mattyp = MatrixType (m); |
|
149 args(0).matrix_type (mattyp); |
5681
|
150 } |
5323
|
151 } |
|
152 } |
|
153 |
|
154 int typ = mattyp.type (); |
|
155 |
5785
|
156 if (typ == MatrixType::Diagonal) |
5323
|
157 retval = octave_value ("Diagonal"); |
5785
|
158 else if (typ == MatrixType::Permuted_Diagonal) |
5323
|
159 retval = octave_value ("Permuted Diagonal"); |
5785
|
160 else if (typ == MatrixType::Upper) |
5323
|
161 retval = octave_value ("Upper"); |
5785
|
162 else if (typ == MatrixType::Permuted_Upper) |
5323
|
163 retval = octave_value ("Permuted Upper"); |
5785
|
164 else if (typ == MatrixType::Lower) |
5323
|
165 retval = octave_value ("Lower"); |
5785
|
166 else if (typ == MatrixType::Permuted_Lower) |
5323
|
167 retval = octave_value ("Permuted Lower"); |
5785
|
168 else if (typ == MatrixType::Banded) |
5323
|
169 retval = octave_value ("Banded"); |
5785
|
170 else if (typ == MatrixType::Banded_Hermitian) |
5323
|
171 retval = octave_value ("Banded Positive Definite"); |
5785
|
172 else if (typ == MatrixType::Tridiagonal) |
5323
|
173 retval = octave_value ("Tridiagonal"); |
5785
|
174 else if (typ == MatrixType::Tridiagonal_Hermitian) |
5323
|
175 retval = octave_value ("Tridiagonal Positive Definite"); |
5785
|
176 else if (typ == MatrixType::Hermitian) |
5323
|
177 retval = octave_value ("Positive Definite"); |
5785
|
178 else if (typ == MatrixType::Rectangular) |
5610
|
179 { |
|
180 if (args(0).rows() == args(0).columns()) |
|
181 retval = octave_value ("Singular"); |
|
182 else |
|
183 retval = octave_value ("Rectangular"); |
|
184 } |
5785
|
185 else if (typ == MatrixType::Full) |
5323
|
186 retval = octave_value ("Full"); |
|
187 else |
|
188 // This should never happen!!! |
|
189 retval = octave_value ("Unknown"); |
|
190 } |
|
191 else |
|
192 { |
|
193 // Ok, we're changing the matrix type |
|
194 std::string str_typ = args(1).string_value (); |
|
195 |
5775
|
196 // FIXME -- why do I have to explicitly call the constructor? |
5785
|
197 MatrixType mattyp = MatrixType (); |
5323
|
198 |
5506
|
199 octave_idx_type nl = 0; |
|
200 octave_idx_type nu = 0; |
5323
|
201 |
|
202 if (error_state) |
|
203 error ("Matrix type must be a string"); |
|
204 else |
|
205 { |
|
206 // Use STL function to convert to lower case |
5403
|
207 std::transform (str_typ.begin (), str_typ.end (), |
5406
|
208 str_typ.begin (), tolower); |
5323
|
209 |
|
210 if (str_typ == "diagonal") |
|
211 mattyp.mark_as_diagonal (); |
|
212 if (str_typ == "permuted diagonal") |
|
213 mattyp.mark_as_permuted_diagonal (); |
|
214 else if (str_typ == "upper") |
|
215 mattyp.mark_as_upper_triangular (); |
|
216 else if (str_typ == "lower") |
|
217 mattyp.mark_as_lower_triangular (); |
|
218 else if (str_typ == "banded" || str_typ == "banded positive definite") |
|
219 { |
|
220 if (nargin != 4) |
|
221 error ("matrix_type: banded matrix type requires 4 arguments"); |
|
222 else |
|
223 { |
|
224 nl = args(2).nint_value (); |
|
225 nu = args(3).nint_value (); |
|
226 |
|
227 if (error_state) |
|
228 error ("matrix_type: band size must be integer"); |
|
229 else |
|
230 { |
|
231 if (nl == 1 && nu == 1) |
|
232 mattyp.mark_as_tridiagonal (); |
|
233 else |
|
234 mattyp.mark_as_banded (nu, nl); |
|
235 |
|
236 if (str_typ == "banded positive definite") |
|
237 mattyp.mark_as_symmetric (); |
|
238 } |
|
239 } |
|
240 } |
|
241 else if (str_typ == "positive definite") |
|
242 { |
|
243 mattyp.mark_as_full (); |
|
244 mattyp.mark_as_symmetric (); |
|
245 } |
|
246 else if (str_typ == "singular") |
|
247 mattyp.mark_as_rectangular (); |
|
248 else if (str_typ == "full") |
|
249 mattyp.mark_as_full (); |
|
250 else if (str_typ == "unknown") |
|
251 mattyp.invalidate_type (); |
|
252 else |
|
253 error ("matrix_type: Unknown matrix type %s", str_typ.c_str()); |
|
254 |
|
255 if (! error_state) |
|
256 { |
|
257 if (nargin == 3 && (str_typ == "upper" || str_typ == "lower")) |
|
258 { |
|
259 const ColumnVector perm = |
|
260 ColumnVector (args (2).vector_value ()); |
|
261 |
|
262 if (error_state) |
|
263 error ("matrix_type: Invalid permutation vector"); |
|
264 else |
|
265 { |
5506
|
266 octave_idx_type len = perm.length (); |
5323
|
267 dim_vector dv = args(0).dims (); |
|
268 |
|
269 if (len != dv(0)) |
|
270 error ("matrix_type: Invalid permutation vector"); |
|
271 else |
|
272 { |
|
273 OCTAVE_LOCAL_BUFFER (octave_idx_type, p, len); |
|
274 |
5506
|
275 for (octave_idx_type i = 0; i < len; i++) |
5760
|
276 p[i] = static_cast<octave_idx_type> (perm (i)) - 1; |
5323
|
277 |
|
278 if (str_typ == "upper") |
|
279 mattyp.mark_as_permuted (len, p); |
|
280 else |
|
281 mattyp.mark_as_permuted (len, p); |
|
282 } |
|
283 } |
|
284 } |
|
285 else if (nargin != 2 && str_typ != "banded positive definite" && |
|
286 str_typ != "banded") |
|
287 error ("matrix_type: Invalid number of arguments"); |
|
288 |
|
289 if (! error_state) |
|
290 { |
|
291 // Set the matrix type |
6371
|
292 if (args(0).is_complex_type ()) |
5323
|
293 retval = |
|
294 octave_value (args(0).sparse_complex_matrix_value (), |
|
295 mattyp); |
|
296 else |
|
297 retval = octave_value (args(0).sparse_matrix_value (), |
|
298 mattyp); |
|
299 } |
|
300 } |
|
301 } |
|
302 } |
|
303 } |
|
304 else |
5785
|
305 { |
|
306 if (nargin == 1) |
|
307 { |
|
308 MatrixType mattyp; |
|
309 |
6371
|
310 if (args(0).is_complex_type ()) |
5785
|
311 { |
|
312 mattyp = args(0).matrix_type (); |
|
313 |
|
314 if (mattyp.is_unknown ()) |
|
315 { |
|
316 ComplexMatrix m = args(0).complex_matrix_value (); |
|
317 if (!error_state) |
|
318 { |
|
319 mattyp = MatrixType (m); |
|
320 args(0).matrix_type (mattyp); |
|
321 } |
|
322 } |
|
323 } |
|
324 else |
|
325 { |
|
326 mattyp = args(0).matrix_type (); |
|
327 |
|
328 if (mattyp.is_unknown ()) |
|
329 { |
|
330 Matrix m = args(0).matrix_value (); |
|
331 if (!error_state) |
|
332 { |
|
333 mattyp = MatrixType (m); |
|
334 args(0).matrix_type (mattyp); |
|
335 } |
|
336 } |
|
337 } |
|
338 |
|
339 int typ = mattyp.type (); |
|
340 |
|
341 if (typ == MatrixType::Upper) |
|
342 retval = octave_value ("Upper"); |
|
343 else if (typ == MatrixType::Permuted_Upper) |
|
344 retval = octave_value ("Permuted Upper"); |
|
345 else if (typ == MatrixType::Lower) |
|
346 retval = octave_value ("Lower"); |
|
347 else if (typ == MatrixType::Permuted_Lower) |
|
348 retval = octave_value ("Permuted Lower"); |
|
349 else if (typ == MatrixType::Hermitian) |
|
350 retval = octave_value ("Positive Definite"); |
|
351 else if (typ == MatrixType::Rectangular) |
|
352 { |
|
353 if (args(0).rows() == args(0).columns()) |
|
354 retval = octave_value ("Singular"); |
|
355 else |
|
356 retval = octave_value ("Rectangular"); |
|
357 } |
|
358 else if (typ == MatrixType::Full) |
|
359 retval = octave_value ("Full"); |
|
360 else |
|
361 // This should never happen!!! |
|
362 retval = octave_value ("Unknown"); |
|
363 } |
|
364 else |
|
365 { |
|
366 // Ok, we're changing the matrix type |
|
367 std::string str_typ = args(1).string_value (); |
|
368 |
|
369 // FIXME -- why do I have to explicitly call the constructor? |
|
370 MatrixType mattyp = MatrixType (MatrixType::Unknown, true); |
|
371 |
|
372 if (error_state) |
|
373 error ("Matrix type must be a string"); |
|
374 else |
|
375 { |
|
376 // Use STL function to convert to lower case |
|
377 std::transform (str_typ.begin (), str_typ.end (), |
|
378 str_typ.begin (), tolower); |
|
379 |
|
380 if (str_typ == "upper") |
|
381 mattyp.mark_as_upper_triangular (); |
|
382 else if (str_typ == "lower") |
|
383 mattyp.mark_as_lower_triangular (); |
|
384 else if (str_typ == "positive definite") |
|
385 { |
|
386 mattyp.mark_as_full (); |
|
387 mattyp.mark_as_symmetric (); |
|
388 } |
|
389 else if (str_typ == "singular") |
|
390 mattyp.mark_as_rectangular (); |
|
391 else if (str_typ == "full") |
|
392 mattyp.mark_as_full (); |
|
393 else if (str_typ == "unknown") |
|
394 mattyp.invalidate_type (); |
|
395 else |
|
396 error ("matrix_type: Unknown matrix type %s", str_typ.c_str()); |
|
397 |
|
398 if (! error_state) |
|
399 { |
|
400 if (nargin == 3 && (str_typ == "upper" |
|
401 || str_typ == "lower")) |
|
402 { |
|
403 const ColumnVector perm = |
|
404 ColumnVector (args (2).vector_value ()); |
|
405 |
|
406 if (error_state) |
|
407 error ("matrix_type: Invalid permutation vector"); |
|
408 else |
|
409 { |
|
410 octave_idx_type len = perm.length (); |
|
411 dim_vector dv = args(0).dims (); |
|
412 |
|
413 if (len != dv(0)) |
|
414 error ("matrix_type: Invalid permutation vector"); |
|
415 else |
|
416 { |
|
417 OCTAVE_LOCAL_BUFFER (octave_idx_type, p, len); |
|
418 |
|
419 for (octave_idx_type i = 0; i < len; i++) |
|
420 p[i] = static_cast<octave_idx_type> (perm (i)) - 1; |
|
421 |
|
422 if (str_typ == "upper") |
|
423 mattyp.mark_as_permuted (len, p); |
|
424 else |
|
425 mattyp.mark_as_permuted (len, p); |
|
426 } |
|
427 } |
|
428 } |
|
429 else if (nargin != 2) |
|
430 error ("matrix_type: Invalid number of arguments"); |
|
431 |
|
432 if (! error_state) |
|
433 { |
|
434 // Set the matrix type |
6371
|
435 if (args(0).is_complex_type()) |
5785
|
436 retval = |
|
437 octave_value (args(0).complex_matrix_value (), |
|
438 mattyp); |
|
439 else |
|
440 retval = octave_value (args(0).matrix_value (), |
|
441 mattyp); |
|
442 } |
|
443 } |
|
444 } |
|
445 } |
|
446 } |
5323
|
447 } |
|
448 |
|
449 return retval; |
|
450 } |
|
451 |
|
452 /* |
5681
|
453 |
5775
|
454 ## FIXME |
5681
|
455 ## Disable tests for lower under-determined and upper over-determined |
5785
|
456 ## matrices and this detection is disabled in MatrixType due to issues |
5681
|
457 ## of non minimum norm solution being found. |
5610
|
458 |
|
459 %!assert(matrix_type(speye(10,10)),"Diagonal"); |
|
460 %!assert(matrix_type(speye(10,10)([2:10,1],:)),"Permuted Diagonal"); |
|
461 %!assert(matrix_type([[speye(10,10);sparse(1,10)],[1;sparse(9,1);1]]),"Upper"); |
|
462 %!assert(matrix_type([[speye(10,10);sparse(1,10)],[1;sparse(9,1);1]](:,[2,1,3:11])),"Permuted Upper"); |
|
463 %!assert(matrix_type([speye(10,10),sparse(10,1);1,sparse(1,9),1]),"Lower"); |
|
464 %!assert(matrix_type([speye(10,10),sparse(10,1);1,sparse(1,9),1]([2,1,3:11],:)),"Permuted Lower"); |
|
465 %!test |
|
466 %! bnd=spparms("bandden"); |
|
467 %! spparms("bandden",0.5); |
|
468 %! a = spdiags(randn(10,3),[-1,0,1],10,10); |
|
469 %! assert(matrix_type(a),"Tridiagonal"); |
|
470 %! assert(matrix_type(abs(a')+abs(a)),"Tridiagonal Positive Definite"); |
|
471 %! spparms("bandden",bnd); |
|
472 %!test |
|
473 %! bnd=spparms("bandden"); |
|
474 %! spparms("bandden",0.5); |
|
475 %! a = spdiags(randn(10,4),[-2:1],10,10); |
|
476 %! assert(matrix_type(a),"Banded"); |
|
477 %! assert(matrix_type(a'*a),"Banded Positive Definite"); |
|
478 %! spparms("bandden",bnd); |
|
479 %!test |
|
480 %! a=[speye(10,10),[sparse(9,1);1];-1,sparse(1,9),1]; |
|
481 %! assert(matrix_type(a),"Full"); |
|
482 %! assert(matrix_type(a'*a),"Positive Definite"); |
5630
|
483 %!assert(matrix_type(speye(10,11)),"Diagonal"); |
|
484 %!assert(matrix_type(speye(10,11)([2:10,1],:)),"Permuted Diagonal"); |
|
485 %!assert(matrix_type(speye(11,10)),"Diagonal"); |
|
486 %!assert(matrix_type(speye(11,10)([2:11,1],:)),"Permuted Diagonal"); |
5681
|
487 %#!assert(matrix_type([[speye(10,10);sparse(1,10)],[[1,1];sparse(9,2);[1,1]]]),"Upper"); |
|
488 %#!assert(matrix_type([[speye(10,10);sparse(1,10)],[[1,1];sparse(9,2);[1,1]]](:,[2,1,3:12])),"Permuted Upper"); |
5630
|
489 %!assert(matrix_type([speye(11,9),[1;sparse(8,1);1;0]]),"Upper"); |
|
490 %!assert(matrix_type([speye(11,9),[1;sparse(8,1);1;0]](:,[2,1,3:10])),"Permuted Upper"); |
5681
|
491 %#!assert(matrix_type([speye(10,10),sparse(10,1);[1;1],sparse(2,9),[1;1]]),"Lower"); |
|
492 %#!assert(matrix_type([speye(10,10),sparse(10,1);[1;1],sparse(2,9),[1;1]]([2,1,3:12],:)),"Permuted Lower"); |
5630
|
493 %!assert(matrix_type([speye(9,11);[1,sparse(1,8),1,0]]),"Lower"); |
|
494 %!assert(matrix_type([speye(9,11);[1,sparse(1,8),1,0]]([2,1,3:10],:)),"Permuted Lower"); |
|
495 %!assert(matrix_type(spdiags(randn(10,4),[-2:1],10,9)),"Rectangular") |
5610
|
496 |
|
497 %!assert(matrix_type(1i*speye(10,10)),"Diagonal"); |
|
498 %!assert(matrix_type(1i*speye(10,10)([2:10,1],:)),"Permuted Diagonal"); |
|
499 %!assert(matrix_type([[speye(10,10);sparse(1,10)],[1i;sparse(9,1);1]]),"Upper"); |
|
500 %!assert(matrix_type([[speye(10,10);sparse(1,10)],[1i;sparse(9,1);1]](:,[2,1,3:11])),"Permuted Upper"); |
|
501 %!assert(matrix_type([speye(10,10),sparse(10,1);1i,sparse(1,9),1]),"Lower"); |
|
502 %!assert(matrix_type([speye(10,10),sparse(10,1);1i,sparse(1,9),1]([2,1,3:11],:)),"Permuted Lower"); |
|
503 %!test |
|
504 %! bnd=spparms("bandden"); |
|
505 %! spparms("bandden",0.5); |
|
506 %! assert(matrix_type(spdiags(1i*randn(10,3),[-1,0,1],10,10)),"Tridiagonal"); |
|
507 %! a = 1i*randn(9,1);a=[[a;0],ones(10,1),[0;-a]]; |
|
508 %! assert(matrix_type(spdiags(a,[-1,0,1],10,10)),"Tridiagonal Positive Definite"); |
|
509 %! spparms("bandden",bnd); |
|
510 %!test |
|
511 %! bnd=spparms("bandden"); |
|
512 %! spparms("bandden",0.5); |
|
513 %! assert(matrix_type(spdiags(1i*randn(10,4),[-2:1],10,10)),"Banded"); |
|
514 %! a = 1i*randn(9,2);a=[[a;[0,0]],ones(10,1),[[0;-a(:,2)],[0;0;-a(1:8,1)]]]; |
|
515 %! assert(matrix_type(spdiags(a,[-2:2],10,10)),"Banded Positive Definite"); |
|
516 %! spparms("bandden",bnd); |
|
517 %!test |
|
518 %! a=[speye(10,10),[sparse(9,1);1i];-1,sparse(1,9),1]; |
|
519 %! assert(matrix_type(a),"Full"); |
|
520 %! assert(matrix_type(a'*a),"Positive Definite"); |
5630
|
521 %!assert(matrix_type(1i*speye(10,11)),"Diagonal"); |
|
522 %!assert(matrix_type(1i*speye(10,11)([2:10,1],:)),"Permuted Diagonal"); |
|
523 %!assert(matrix_type(1i*speye(11,10)),"Diagonal"); |
|
524 %!assert(matrix_type(1i*speye(11,10)([2:11,1],:)),"Permuted Diagonal"); |
5681
|
525 %#!assert(matrix_type([[speye(10,10);sparse(1,10)],[[1i,1i];sparse(9,2);[1i,1i]]]),"Upper"); |
|
526 %#!assert(matrix_type([[speye(10,10);sparse(1,10)],[[1i,1i];sparse(9,2);[1i,1i]]](:,[2,1,3:12])),"Permuted Upper"); |
5630
|
527 %!assert(matrix_type([speye(11,9),[1i;sparse(8,1);1i;0]]),"Upper"); |
|
528 %!assert(matrix_type([speye(11,9),[1i;sparse(8,1);1i;0]](:,[2,1,3:10])),"Permuted Upper"); |
5681
|
529 %#!assert(matrix_type([speye(10,10),sparse(10,1);[1i;1i],sparse(2,9),[1i;1i]]),"Lower"); |
|
530 %#!assert(matrix_type([speye(10,10),sparse(10,1);[1i;1i],sparse(2,9),[1i;1i]]([2,1,3:12],:)),"Permuted Lower"); |
5630
|
531 %!assert(matrix_type([speye(9,11);[1i,sparse(1,8),1i,0]]),"Lower"); |
|
532 %!assert(matrix_type([speye(9,11);[1i,sparse(1,8),1i,0]]([2,1,3:10],:)),"Permuted Lower"); |
|
533 %!assert(matrix_type(1i*spdiags(randn(10,4),[-2:1],10,9)),"Rectangular") |
5610
|
534 |
|
535 %!test |
|
536 %! a = matrix_type(spdiags(randn(10,3),[-1,0,1],10,10),"Singular"); |
|
537 %! assert(matrix_type(a),"Singular"); |
|
538 |
5785
|
539 %!assert(matrix_type(triu(ones(10,10))),"Upper"); |
|
540 %!assert(matrix_type(triu(ones(10,10),-1)),"Full"); |
|
541 %!assert(matrix_type(tril(ones(10,10))),"Lower"); |
|
542 %!assert(matrix_type(tril(ones(10,10),1)),"Full"); |
|
543 %!assert(matrix_type(10*eye(10,10) + ones(10,10)), "Positive Definite"); |
|
544 %!assert(matrix_type(ones(11,10)),"Rectangular") |
|
545 %!test |
|
546 %! a = matrix_type(ones(10,10),"Singular"); |
|
547 %! assert(matrix_type(a),"Singular"); |
|
548 |
|
549 %!assert(matrix_type(triu(1i*ones(10,10))),"Upper"); |
|
550 %!assert(matrix_type(triu(1i*ones(10,10),-1)),"Full"); |
|
551 %!assert(matrix_type(tril(1i*ones(10,10))),"Lower"); |
|
552 %!assert(matrix_type(tril(1i*ones(10,10),1)),"Full"); |
|
553 %!assert(matrix_type(10*eye(10,10) + 1i*triu(ones(10,10),1) -1i*tril(ones(10,10),-1)), "Positive Definite"); |
|
554 %!assert(matrix_type(ones(11,10)),"Rectangular") |
|
555 %!test |
|
556 %! a = matrix_type(ones(10,10),"Singular"); |
|
557 %! assert(matrix_type(a),"Singular"); |
|
558 |
5610
|
559 */ |
|
560 |
|
561 /* |
5323
|
562 ;;; Local Variables: *** |
|
563 ;;; mode: C++ *** |
|
564 ;;; End: *** |
|
565 */ |