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