annotate src/DLD-FUNCTIONS/matrix_type.cc @ 10154:40dfc0c99116

DLD-FUNCTIONS/*.cc: untabify
author John W. Eaton <jwe@octave.org>
date Wed, 20 Jan 2010 17:33:41 -0500
parents 09da0bd91412
children d0ce5e973937
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5323
e5a68648db9c [project @ 2005-04-29 13:10:36 by dbateman]
dbateman
parents:
diff changeset
1 /*
e5a68648db9c [project @ 2005-04-29 13:10:36 by dbateman]
dbateman
parents:
diff changeset
2
8920
eb63fbe60fab update copyright notices
John W. Eaton <jwe@octave.org>
parents: 8489
diff changeset
3 Copyright (C) 2005, 2006, 2007, 2008, 2009 David Bateman
5323
e5a68648db9c [project @ 2005-04-29 13:10:36 by dbateman]
dbateman
parents:
diff changeset
4
5720
067948dc39bf [project @ 2006-03-28 11:25:29 by jwe]
jwe
parents: 5681
diff changeset
5 This file is part of Octave.
067948dc39bf [project @ 2006-03-28 11:25:29 by jwe]
jwe
parents: 5681
diff changeset
6
5323
e5a68648db9c [project @ 2005-04-29 13:10:36 by dbateman]
dbateman
parents:
diff changeset
7 Octave is free software; you can redistribute it and/or modify it
e5a68648db9c [project @ 2005-04-29 13:10:36 by dbateman]
dbateman
parents:
diff changeset
8 under the terms of the GNU General Public License as published by the
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7001
diff changeset
9 Free Software Foundation; either version 3 of the License, or (at your
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7001
diff changeset
10 option) any later version.
5323
e5a68648db9c [project @ 2005-04-29 13:10:36 by dbateman]
dbateman
parents:
diff changeset
11
e5a68648db9c [project @ 2005-04-29 13:10:36 by dbateman]
dbateman
parents:
diff changeset
12 Octave is distributed in the hope that it will be useful, but WITHOUT
e5a68648db9c [project @ 2005-04-29 13:10:36 by dbateman]
dbateman
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
e5a68648db9c [project @ 2005-04-29 13:10:36 by dbateman]
dbateman
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
e5a68648db9c [project @ 2005-04-29 13:10:36 by dbateman]
dbateman
parents:
diff changeset
15 for more details.
e5a68648db9c [project @ 2005-04-29 13:10:36 by dbateman]
dbateman
parents:
diff changeset
16
e5a68648db9c [project @ 2005-04-29 13:10:36 by dbateman]
dbateman
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7001
diff changeset
18 along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7001
diff changeset
19 <http://www.gnu.org/licenses/>.
5323
e5a68648db9c [project @ 2005-04-29 13:10:36 by dbateman]
dbateman
parents:
diff changeset
20
e5a68648db9c [project @ 2005-04-29 13:10:36 by dbateman]
dbateman
parents:
diff changeset
21 */
e5a68648db9c [project @ 2005-04-29 13:10:36 by dbateman]
dbateman
parents:
diff changeset
22
e5a68648db9c [project @ 2005-04-29 13:10:36 by dbateman]
dbateman
parents:
diff changeset
23 #ifdef HAVE_CONFIG_H
e5a68648db9c [project @ 2005-04-29 13:10:36 by dbateman]
dbateman
parents:
diff changeset
24 #include <config.h>
e5a68648db9c [project @ 2005-04-29 13:10:36 by dbateman]
dbateman
parents:
diff changeset
25 #endif
e5a68648db9c [project @ 2005-04-29 13:10:36 by dbateman]
dbateman
parents:
diff changeset
26
5403
7bdddf96f028 [project @ 2005-07-07 16:46:23 by jwe]
jwe
parents: 5324
diff changeset
27 #include <algorithm>
7bdddf96f028 [project @ 2005-07-07 16:46:23 by jwe]
jwe
parents: 5324
diff changeset
28
5323
e5a68648db9c [project @ 2005-04-29 13:10:36 by dbateman]
dbateman
parents:
diff changeset
29 #include "ov.h"
e5a68648db9c [project @ 2005-04-29 13:10:36 by dbateman]
dbateman
parents:
diff changeset
30 #include "defun-dld.h"
e5a68648db9c [project @ 2005-04-29 13:10:36 by dbateman]
dbateman
parents:
diff changeset
31 #include "error.h"
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5775
diff changeset
32 #include "ov-re-mat.h"
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5775
diff changeset
33 #include "ov-cx-mat.h"
5323
e5a68648db9c [project @ 2005-04-29 13:10:36 by dbateman]
dbateman
parents:
diff changeset
34 #include "ov-re-sparse.h"
e5a68648db9c [project @ 2005-04-29 13:10:36 by dbateman]
dbateman
parents:
diff changeset
35 #include "ov-cx-sparse.h"
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5775
diff changeset
36 #include "MatrixType.h"
8377
25bc2d31e1bf improve OCTAVE_LOCAL_BUFFER
Jaroslav Hajek <highegg@gmail.com>
parents: 8325
diff changeset
37 #include "oct-locbuf.h"
5323
e5a68648db9c [project @ 2005-04-29 13:10:36 by dbateman]
dbateman
parents:
diff changeset
38
e5a68648db9c [project @ 2005-04-29 13:10:36 by dbateman]
dbateman
parents:
diff changeset
39 DEFUN_DLD (matrix_type, args, ,
e5a68648db9c [project @ 2005-04-29 13:10:36 by dbateman]
dbateman
parents:
diff changeset
40 "-*- texinfo -*-\n\
e5a68648db9c [project @ 2005-04-29 13:10:36 by dbateman]
dbateman
parents:
diff changeset
41 @deftypefn {Loadable Function} {@var{type} =} matrix_type (@var{a})\n\
9714
0407883e1a33 support nocompute option to matrix_type
Jaroslav Hajek <highegg@gmail.com>
parents: 9064
diff changeset
42 @deftypefnx {Loadable Function} {@var{type} =} matrix_type (@var{a}, 'nocompute')\n\
5323
e5a68648db9c [project @ 2005-04-29 13:10:36 by dbateman]
dbateman
parents:
diff changeset
43 @deftypefnx {Loadable Function} {@var{a} =} matrix_type (@var{a}, @var{type})\n\
e5a68648db9c [project @ 2005-04-29 13:10:36 by dbateman]
dbateman
parents:
diff changeset
44 @deftypefnx {Loadable Function} {@var{a} =} matrix_type (@var{a}, 'upper', @var{perm})\n\
e5a68648db9c [project @ 2005-04-29 13:10:36 by dbateman]
dbateman
parents:
diff changeset
45 @deftypefnx {Loadable Function} {@var{a} =} matrix_type (@var{a}, 'lower', @var{perm})\n\
e5a68648db9c [project @ 2005-04-29 13:10:36 by dbateman]
dbateman
parents:
diff changeset
46 @deftypefnx {Loadable Function} {@var{a} =} matrix_type (@var{a}, 'banded', @var{nl}, @var{nu})\n\
9064
7c02ec148a3c Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
47 Identify the matrix type or mark a matrix as a particular type. This allows rapid\n\
7c02ec148a3c Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
48 for solutions of linear equations involving @var{a} to be performed. Called with a\n\
5323
e5a68648db9c [project @ 2005-04-29 13:10:36 by dbateman]
dbateman
parents:
diff changeset
49 single argument, @code{matrix_type} returns the type of the matrix and caches it for\n\
9064
7c02ec148a3c Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
50 future use. Called with more than one argument, @code{matrix_type} allows the type\n\
5323
e5a68648db9c [project @ 2005-04-29 13:10:36 by dbateman]
dbateman
parents:
diff changeset
51 of the matrix to be defined.\n\
e5a68648db9c [project @ 2005-04-29 13:10:36 by dbateman]
dbateman
parents:
diff changeset
52 \n\
9714
0407883e1a33 support nocompute option to matrix_type
Jaroslav Hajek <highegg@gmail.com>
parents: 9064
diff changeset
53 If the option 'nocompute' is given, the function will not attempt to guess the type if it is\n\
9758
09da0bd91412 Periodic grammar check of Octave documentation files to ensure common format
Rik <rdrider0-list@yahoo.com>
parents: 9714
diff changeset
54 still unknown. This is useful for debugging purposes.\n\
9714
0407883e1a33 support nocompute option to matrix_type
Jaroslav Hajek <highegg@gmail.com>
parents: 9064
diff changeset
55 \n\
5323
e5a68648db9c [project @ 2005-04-29 13:10:36 by dbateman]
dbateman
parents:
diff changeset
56 The possible matrix types depend on whether the matrix is full or sparse, and can be\n\
e5a68648db9c [project @ 2005-04-29 13:10:36 by dbateman]
dbateman
parents:
diff changeset
57 one of the following\n\
e5a68648db9c [project @ 2005-04-29 13:10:36 by dbateman]
dbateman
parents:
diff changeset
58 \n\
e5a68648db9c [project @ 2005-04-29 13:10:36 by dbateman]
dbateman
parents:
diff changeset
59 @table @asis\n\
e5a68648db9c [project @ 2005-04-29 13:10:36 by dbateman]
dbateman
parents:
diff changeset
60 @item 'unknown'\n\
e5a68648db9c [project @ 2005-04-29 13:10:36 by dbateman]
dbateman
parents:
diff changeset
61 Remove any previously cached matrix type, and mark type as unknown\n\
e5a68648db9c [project @ 2005-04-29 13:10:36 by dbateman]
dbateman
parents:
diff changeset
62 \n\
e5a68648db9c [project @ 2005-04-29 13:10:36 by dbateman]
dbateman
parents:
diff changeset
63 @item 'full'\n\
e5a68648db9c [project @ 2005-04-29 13:10:36 by dbateman]
dbateman
parents:
diff changeset
64 Mark the matrix as full.\n\
e5a68648db9c [project @ 2005-04-29 13:10:36 by dbateman]
dbateman
parents:
diff changeset
65 \n\
e5a68648db9c [project @ 2005-04-29 13:10:36 by dbateman]
dbateman
parents:
diff changeset
66 @item 'positive definite'\n\
7567
6b07c15eb8e1 Document positive definite behavior of matrix_type
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
67 Probable full positive definite matrix.\n\
5323
e5a68648db9c [project @ 2005-04-29 13:10:36 by dbateman]
dbateman
parents:
diff changeset
68 \n\
e5a68648db9c [project @ 2005-04-29 13:10:36 by dbateman]
dbateman
parents:
diff changeset
69 @item 'diagonal'\n\
9064
7c02ec148a3c Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
70 Diagonal Matrix. (Sparse matrices only)\n\
5323
e5a68648db9c [project @ 2005-04-29 13:10:36 by dbateman]
dbateman
parents:
diff changeset
71 \n\
e5a68648db9c [project @ 2005-04-29 13:10:36 by dbateman]
dbateman
parents:
diff changeset
72 @item 'permuted diagonal'\n\
9064
7c02ec148a3c Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
73 Permuted Diagonal matrix. The permutation does not need to be specifically\n\
7c02ec148a3c Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
74 indicated, as the structure of the matrix explicitly gives this. (Sparse matrices\n\
5323
e5a68648db9c [project @ 2005-04-29 13:10:36 by dbateman]
dbateman
parents:
diff changeset
75 only)\n\
e5a68648db9c [project @ 2005-04-29 13:10:36 by dbateman]
dbateman
parents:
diff changeset
76 \n\
e5a68648db9c [project @ 2005-04-29 13:10:36 by dbateman]
dbateman
parents:
diff changeset
77 @item 'upper'\n\
9064
7c02ec148a3c Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
78 Upper triangular. If the optional third argument @var{perm} is given, the matrix is\n\
5323
e5a68648db9c [project @ 2005-04-29 13:10:36 by dbateman]
dbateman
parents:
diff changeset
79 assumed to be a permuted upper triangular with the permutations defined by the\n\
e5a68648db9c [project @ 2005-04-29 13:10:36 by dbateman]
dbateman
parents:
diff changeset
80 vector @var{perm}.\n\
e5a68648db9c [project @ 2005-04-29 13:10:36 by dbateman]
dbateman
parents:
diff changeset
81 \n\
e5a68648db9c [project @ 2005-04-29 13:10:36 by dbateman]
dbateman
parents:
diff changeset
82 @item 'lower'\n\
9064
7c02ec148a3c Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
83 Lower triangular. If the optional third argument @var{perm} is given, the matrix is\n\
5323
e5a68648db9c [project @ 2005-04-29 13:10:36 by dbateman]
dbateman
parents:
diff changeset
84 assumed to be a permuted lower triangular with the permutations defined by the\n\
e5a68648db9c [project @ 2005-04-29 13:10:36 by dbateman]
dbateman
parents:
diff changeset
85 vector @var{perm}.\n\
e5a68648db9c [project @ 2005-04-29 13:10:36 by dbateman]
dbateman
parents:
diff changeset
86 \n\
e5a68648db9c [project @ 2005-04-29 13:10:36 by dbateman]
dbateman
parents:
diff changeset
87 @item 'banded'\n\
e5a68648db9c [project @ 2005-04-29 13:10:36 by dbateman]
dbateman
parents:
diff changeset
88 @itemx 'banded positive definite'\n\
e5a68648db9c [project @ 2005-04-29 13:10:36 by dbateman]
dbateman
parents:
diff changeset
89 Banded matrix with the band size of @var{nl} below the diagonal and @var{nu} above\n\
9064
7c02ec148a3c Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
90 it. If @var{nl} and @var{nu} are 1, then the matrix is tridiagonal and treated\n\
7c02ec148a3c Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
91 with specialized code. In addition the matrix can be marked as probably a\n\
7567
6b07c15eb8e1 Document positive definite behavior of matrix_type
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
92 positive definite (Sparse matrices only)\n\
5323
e5a68648db9c [project @ 2005-04-29 13:10:36 by dbateman]
dbateman
parents:
diff changeset
93 \n\
e5a68648db9c [project @ 2005-04-29 13:10:36 by dbateman]
dbateman
parents:
diff changeset
94 @item 'singular'\n\
e5a68648db9c [project @ 2005-04-29 13:10:36 by dbateman]
dbateman
parents:
diff changeset
95 The matrix is assumed to be singular and will be treated with a minimum norm solution\n\
e5a68648db9c [project @ 2005-04-29 13:10:36 by dbateman]
dbateman
parents:
diff changeset
96 \n\
e5a68648db9c [project @ 2005-04-29 13:10:36 by dbateman]
dbateman
parents:
diff changeset
97 @end table\n\
e5a68648db9c [project @ 2005-04-29 13:10:36 by dbateman]
dbateman
parents:
diff changeset
98 \n\
e5a68648db9c [project @ 2005-04-29 13:10:36 by dbateman]
dbateman
parents:
diff changeset
99 Note that the matrix type will be discovered automatically on the first attempt to\n\
9064
7c02ec148a3c Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
100 solve a linear equation involving @var{a}. Therefore @code{matrix_type} is only\n\
7c02ec148a3c Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
101 useful to give Octave hints of the matrix type. Incorrectly defining the\n\
5323
e5a68648db9c [project @ 2005-04-29 13:10:36 by dbateman]
dbateman
parents:
diff changeset
102 matrix type will result in incorrect results from solutions of linear equations,\n\
7001
8b0cfeb06365 [project @ 2007-10-10 18:02:59 by jwe]
jwe
parents: 6371
diff changeset
103 and so it is entirely the responsibility of the user to correctly identify the\n\
5323
e5a68648db9c [project @ 2005-04-29 13:10:36 by dbateman]
dbateman
parents:
diff changeset
104 matrix type.\n\
7567
6b07c15eb8e1 Document positive definite behavior of matrix_type
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
105 \n\
8489
e76b92c7f779 [docs] low cost => low-cost
Brian Gough <bjg@gnu.org>
parents: 8377
diff changeset
106 Also the test for positive definiteness is a low-cost test for a hermitian\n\
9064
7c02ec148a3c Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
107 matrix with a real positive diagonal. This does not guarantee that the matrix\n\
7c02ec148a3c Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
108 is positive definite, but only that it is a probable candidate. When such a\n\
7567
6b07c15eb8e1 Document positive definite behavior of matrix_type
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
109 matrix is factorized, a Cholesky factorization is first attempted, and if\n\
9064
7c02ec148a3c Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
110 that fails the matrix is then treated with an LU factorization. Once the\n\
7567
6b07c15eb8e1 Document positive definite behavior of matrix_type
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
111 matrix has been factorized, @code{matrix_type} will return the correct\n\
6b07c15eb8e1 Document positive definite behavior of matrix_type
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
112 classification of the matrix.\n\
5323
e5a68648db9c [project @ 2005-04-29 13:10:36 by dbateman]
dbateman
parents:
diff changeset
113 @end deftypefn")
e5a68648db9c [project @ 2005-04-29 13:10:36 by dbateman]
dbateman
parents:
diff changeset
114 {
e5a68648db9c [project @ 2005-04-29 13:10:36 by dbateman]
dbateman
parents:
diff changeset
115 int nargin = args.length ();
e5a68648db9c [project @ 2005-04-29 13:10:36 by dbateman]
dbateman
parents:
diff changeset
116 octave_value retval;
e5a68648db9c [project @ 2005-04-29 13:10:36 by dbateman]
dbateman
parents:
diff changeset
117
e5a68648db9c [project @ 2005-04-29 13:10:36 by dbateman]
dbateman
parents:
diff changeset
118 if (nargin == 0)
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5785
diff changeset
119 print_usage ();
5323
e5a68648db9c [project @ 2005-04-29 13:10:36 by dbateman]
dbateman
parents:
diff changeset
120 else if (nargin > 4)
e5a68648db9c [project @ 2005-04-29 13:10:36 by dbateman]
dbateman
parents:
diff changeset
121 error ("matrix_type: incorrect number of arguments");
e5a68648db9c [project @ 2005-04-29 13:10:36 by dbateman]
dbateman
parents:
diff changeset
122 else
e5a68648db9c [project @ 2005-04-29 13:10:36 by dbateman]
dbateman
parents:
diff changeset
123 {
9714
0407883e1a33 support nocompute option to matrix_type
Jaroslav Hajek <highegg@gmail.com>
parents: 9064
diff changeset
124 bool autocomp = true;
0407883e1a33 support nocompute option to matrix_type
Jaroslav Hajek <highegg@gmail.com>
parents: 9064
diff changeset
125 if (nargin == 2 && args(1).is_string () && args(1).string_value () == "nocompute")
0407883e1a33 support nocompute option to matrix_type
Jaroslav Hajek <highegg@gmail.com>
parents: 9064
diff changeset
126 {
0407883e1a33 support nocompute option to matrix_type
Jaroslav Hajek <highegg@gmail.com>
parents: 9064
diff changeset
127 nargin = 1;
0407883e1a33 support nocompute option to matrix_type
Jaroslav Hajek <highegg@gmail.com>
parents: 9064
diff changeset
128 autocomp = false;
0407883e1a33 support nocompute option to matrix_type
Jaroslav Hajek <highegg@gmail.com>
parents: 9064
diff changeset
129 }
0407883e1a33 support nocompute option to matrix_type
Jaroslav Hajek <highegg@gmail.com>
parents: 9064
diff changeset
130
6371
b51f76ee24bb [project @ 2007-03-01 14:55:23 by dbateman]
dbateman
parents: 5823
diff changeset
131 if (args(0).is_scalar_type())
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
132 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
133 if (nargin == 1)
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
134 retval = octave_value ("Diagonal");
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
135 else
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
136 retval = args(0);
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
137 }
6371
b51f76ee24bb [project @ 2007-03-01 14:55:23 by dbateman]
dbateman
parents: 5823
diff changeset
138 else if (args(0).is_sparse_type ())
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
139 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
140 if (nargin == 1)
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
141 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
142 MatrixType mattyp;
5323
e5a68648db9c [project @ 2005-04-29 13:10:36 by dbateman]
dbateman
parents:
diff changeset
143
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
144 if (args(0).is_complex_type ())
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
145 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
146 mattyp = args(0).matrix_type ();
5323
e5a68648db9c [project @ 2005-04-29 13:10:36 by dbateman]
dbateman
parents:
diff changeset
147
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
148 if (mattyp.is_unknown () && autocomp )
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
149 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
150 SparseComplexMatrix m =
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
151 args(0).sparse_complex_matrix_value ();
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
152 if (!error_state)
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
153 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
154 mattyp = MatrixType (m);
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
155 args(0).matrix_type (mattyp);
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
156 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
157 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
158 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
159 else
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
160 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
161 mattyp = args(0).matrix_type ();
5323
e5a68648db9c [project @ 2005-04-29 13:10:36 by dbateman]
dbateman
parents:
diff changeset
162
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
163 if (mattyp.is_unknown () && autocomp)
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
164 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
165 SparseMatrix m = args(0).sparse_matrix_value ();
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
166 if (!error_state)
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
167 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
168 mattyp = MatrixType (m);
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
169 args(0).matrix_type (mattyp);
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
170 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
171 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
172 }
5323
e5a68648db9c [project @ 2005-04-29 13:10:36 by dbateman]
dbateman
parents:
diff changeset
173
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
174 int typ = mattyp.type ();
5323
e5a68648db9c [project @ 2005-04-29 13:10:36 by dbateman]
dbateman
parents:
diff changeset
175
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
176 if (typ == MatrixType::Diagonal)
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
177 retval = octave_value ("Diagonal");
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
178 else if (typ == MatrixType::Permuted_Diagonal)
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
179 retval = octave_value ("Permuted Diagonal");
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
180 else if (typ == MatrixType::Upper)
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
181 retval = octave_value ("Upper");
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
182 else if (typ == MatrixType::Permuted_Upper)
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
183 retval = octave_value ("Permuted Upper");
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
184 else if (typ == MatrixType::Lower)
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
185 retval = octave_value ("Lower");
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
186 else if (typ == MatrixType::Permuted_Lower)
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
187 retval = octave_value ("Permuted Lower");
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
188 else if (typ == MatrixType::Banded)
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
189 retval = octave_value ("Banded");
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
190 else if (typ == MatrixType::Banded_Hermitian)
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
191 retval = octave_value ("Banded Positive Definite");
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
192 else if (typ == MatrixType::Tridiagonal)
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
193 retval = octave_value ("Tridiagonal");
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
194 else if (typ == MatrixType::Tridiagonal_Hermitian)
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
195 retval = octave_value ("Tridiagonal Positive Definite");
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
196 else if (typ == MatrixType::Hermitian)
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
197 retval = octave_value ("Positive Definite");
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
198 else if (typ == MatrixType::Rectangular)
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
199 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
200 if (args(0).rows() == args(0).columns())
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
201 retval = octave_value ("Singular");
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
202 else
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
203 retval = octave_value ("Rectangular");
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
204 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
205 else if (typ == MatrixType::Full)
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
206 retval = octave_value ("Full");
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
207 else
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
208 retval = octave_value ("Unknown");
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
209 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
210 else
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
211 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
212 // Ok, we're changing the matrix type
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
213 std::string str_typ = args(1).string_value ();
5323
e5a68648db9c [project @ 2005-04-29 13:10:36 by dbateman]
dbateman
parents:
diff changeset
214
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
215 // FIXME -- why do I have to explicitly call the constructor?
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
216 MatrixType mattyp = MatrixType ();
5323
e5a68648db9c [project @ 2005-04-29 13:10:36 by dbateman]
dbateman
parents:
diff changeset
217
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
218 octave_idx_type nl = 0;
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
219 octave_idx_type nu = 0;
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
220
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
221 if (error_state)
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
222 error ("Matrix type must be a string");
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
223 else
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
224 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
225 // Use STL function to convert to lower case
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
226 std::transform (str_typ.begin (), str_typ.end (),
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
227 str_typ.begin (), tolower);
5323
e5a68648db9c [project @ 2005-04-29 13:10:36 by dbateman]
dbateman
parents:
diff changeset
228
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
229 if (str_typ == "diagonal")
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
230 mattyp.mark_as_diagonal ();
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
231 if (str_typ == "permuted diagonal")
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
232 mattyp.mark_as_permuted_diagonal ();
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
233 else if (str_typ == "upper")
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
234 mattyp.mark_as_upper_triangular ();
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
235 else if (str_typ == "lower")
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
236 mattyp.mark_as_lower_triangular ();
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
237 else if (str_typ == "banded" || str_typ == "banded positive definite")
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
238 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
239 if (nargin != 4)
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
240 error ("matrix_type: banded matrix type requires 4 arguments");
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
241 else
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
242 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
243 nl = args(2).nint_value ();
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
244 nu = args(3).nint_value ();
5323
e5a68648db9c [project @ 2005-04-29 13:10:36 by dbateman]
dbateman
parents:
diff changeset
245
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
246 if (error_state)
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
247 error ("matrix_type: band size must be integer");
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
248 else
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
249 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
250 if (nl == 1 && nu == 1)
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
251 mattyp.mark_as_tridiagonal ();
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
252 else
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
253 mattyp.mark_as_banded (nu, nl);
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
254
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
255 if (str_typ == "banded positive definite")
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
256 mattyp.mark_as_symmetric ();
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
257 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
258 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
259 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
260 else if (str_typ == "positive definite")
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
261 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
262 mattyp.mark_as_full ();
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
263 mattyp.mark_as_symmetric ();
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
264 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
265 else if (str_typ == "singular")
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
266 mattyp.mark_as_rectangular ();
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
267 else if (str_typ == "full")
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
268 mattyp.mark_as_full ();
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
269 else if (str_typ == "unknown")
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
270 mattyp.invalidate_type ();
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
271 else
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
272 error ("matrix_type: Unknown matrix type %s", str_typ.c_str());
5323
e5a68648db9c [project @ 2005-04-29 13:10:36 by dbateman]
dbateman
parents:
diff changeset
273
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
274 if (! error_state)
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
275 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
276 if (nargin == 3 && (str_typ == "upper" || str_typ == "lower"))
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
277 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
278 const ColumnVector perm =
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
279 ColumnVector (args (2).vector_value ());
5323
e5a68648db9c [project @ 2005-04-29 13:10:36 by dbateman]
dbateman
parents:
diff changeset
280
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
281 if (error_state)
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
282 error ("matrix_type: Invalid permutation vector");
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
283 else
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
284 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
285 octave_idx_type len = perm.length ();
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
286 dim_vector dv = args(0).dims ();
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
287
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
288 if (len != dv(0))
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
289 error ("matrix_type: Invalid permutation vector");
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
290 else
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
291 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
292 OCTAVE_LOCAL_BUFFER (octave_idx_type, p, len);
5323
e5a68648db9c [project @ 2005-04-29 13:10:36 by dbateman]
dbateman
parents:
diff changeset
293
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
294 for (octave_idx_type i = 0; i < len; i++)
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
295 p[i] = static_cast<octave_idx_type> (perm (i)) - 1;
5323
e5a68648db9c [project @ 2005-04-29 13:10:36 by dbateman]
dbateman
parents:
diff changeset
296
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
297 if (str_typ == "upper")
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
298 mattyp.mark_as_permuted (len, p);
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
299 else
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
300 mattyp.mark_as_permuted (len, p);
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
301 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
302 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
303 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
304 else if (nargin != 2 && str_typ != "banded positive definite" &&
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
305 str_typ != "banded")
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
306 error ("matrix_type: Invalid number of arguments");
5323
e5a68648db9c [project @ 2005-04-29 13:10:36 by dbateman]
dbateman
parents:
diff changeset
307
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
308 if (! error_state)
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
309 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
310 // Set the matrix type
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
311 if (args(0).is_complex_type ())
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
312 retval =
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
313 octave_value (args(0).sparse_complex_matrix_value (),
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
314 mattyp);
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
315 else
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
316 retval = octave_value (args(0).sparse_matrix_value (),
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
317 mattyp);
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
318 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
319 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
320 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
321 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
322 }
5323
e5a68648db9c [project @ 2005-04-29 13:10:36 by dbateman]
dbateman
parents:
diff changeset
323 else
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
324 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
325 if (nargin == 1)
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
326 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
327 MatrixType mattyp;
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5775
diff changeset
328
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
329 if (args(0).is_complex_type ())
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
330 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
331 mattyp = args(0).matrix_type ();
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5775
diff changeset
332
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
333 if (mattyp.is_unknown () && autocomp)
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
334 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
335 if (args(0).is_single_type ())
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
336 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
337 FloatComplexMatrix m = args(0).float_complex_matrix_value ();
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
338 if (!error_state)
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
339 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
340 mattyp = MatrixType (m);
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
341 args(0).matrix_type (mattyp);
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
342 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
343 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
344 else
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
345 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
346 ComplexMatrix m = args(0).complex_matrix_value ();
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
347 if (!error_state)
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
348 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
349 mattyp = MatrixType (m);
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
350 args(0).matrix_type (mattyp);
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
351 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
352 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
353 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
354 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
355 else
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
356 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
357 mattyp = args(0).matrix_type ();
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5775
diff changeset
358
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
359 if (mattyp.is_unknown () && autocomp)
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
360 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
361 if (args(0).is_single_type ())
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
362 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
363 FloatMatrix m = args(0).float_matrix_value ();
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
364 if (!error_state)
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
365 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
366 mattyp = MatrixType (m);
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
367 args(0).matrix_type (mattyp);
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
368 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
369 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
370 else
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
371 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
372 Matrix m = args(0).matrix_value ();
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
373 if (!error_state)
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
374 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
375 mattyp = MatrixType (m);
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
376 args(0).matrix_type (mattyp);
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
377 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
378 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
379 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
380 }
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5775
diff changeset
381
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
382 int typ = mattyp.type ();
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5775
diff changeset
383
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
384 if (typ == MatrixType::Upper)
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
385 retval = octave_value ("Upper");
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
386 else if (typ == MatrixType::Permuted_Upper)
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
387 retval = octave_value ("Permuted Upper");
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
388 else if (typ == MatrixType::Lower)
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
389 retval = octave_value ("Lower");
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
390 else if (typ == MatrixType::Permuted_Lower)
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
391 retval = octave_value ("Permuted Lower");
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
392 else if (typ == MatrixType::Hermitian)
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
393 retval = octave_value ("Positive Definite");
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
394 else if (typ == MatrixType::Rectangular)
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
395 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
396 if (args(0).rows() == args(0).columns())
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
397 retval = octave_value ("Singular");
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
398 else
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
399 retval = octave_value ("Rectangular");
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
400 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
401 else if (typ == MatrixType::Full)
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
402 retval = octave_value ("Full");
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
403 else
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
404 retval = octave_value ("Unknown");
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
405 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
406 else
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
407 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
408 // Ok, we're changing the matrix type
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
409 std::string str_typ = args(1).string_value ();
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5775
diff changeset
410
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
411 // FIXME -- why do I have to explicitly call the constructor?
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
412 MatrixType mattyp = MatrixType (MatrixType::Unknown, true);
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5775
diff changeset
413
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
414 if (error_state)
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
415 error ("Matrix type must be a string");
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
416 else
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
417 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
418 // Use STL function to convert to lower case
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
419 std::transform (str_typ.begin (), str_typ.end (),
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
420 str_typ.begin (), tolower);
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5775
diff changeset
421
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
422 if (str_typ == "upper")
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
423 mattyp.mark_as_upper_triangular ();
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
424 else if (str_typ == "lower")
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
425 mattyp.mark_as_lower_triangular ();
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
426 else if (str_typ == "positive definite")
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
427 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
428 mattyp.mark_as_full ();
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
429 mattyp.mark_as_symmetric ();
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
430 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
431 else if (str_typ == "singular")
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
432 mattyp.mark_as_rectangular ();
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
433 else if (str_typ == "full")
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
434 mattyp.mark_as_full ();
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
435 else if (str_typ == "unknown")
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
436 mattyp.invalidate_type ();
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
437 else
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
438 error ("matrix_type: Unknown matrix type %s", str_typ.c_str());
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5775
diff changeset
439
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
440 if (! error_state)
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
441 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
442 if (nargin == 3 && (str_typ == "upper"
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
443 || str_typ == "lower"))
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
444 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
445 const ColumnVector perm =
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
446 ColumnVector (args (2).vector_value ());
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5775
diff changeset
447
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
448 if (error_state)
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
449 error ("matrix_type: Invalid permutation vector");
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
450 else
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
451 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
452 octave_idx_type len = perm.length ();
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
453 dim_vector dv = args(0).dims ();
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
454
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
455 if (len != dv(0))
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
456 error ("matrix_type: Invalid permutation vector");
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
457 else
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
458 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
459 OCTAVE_LOCAL_BUFFER (octave_idx_type, p, len);
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5775
diff changeset
460
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
461 for (octave_idx_type i = 0; i < len; i++)
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
462 p[i] = static_cast<octave_idx_type> (perm (i)) - 1;
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5775
diff changeset
463
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
464 if (str_typ == "upper")
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
465 mattyp.mark_as_permuted (len, p);
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
466 else
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
467 mattyp.mark_as_permuted (len, p);
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
468 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
469 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
470 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
471 else if (nargin != 2)
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
472 error ("matrix_type: Invalid number of arguments");
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5775
diff changeset
473
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
474 if (! error_state)
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
475 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
476 // Set the matrix type
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
477 if (args(0).is_single_type ())
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
478 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
479 if (args(0).is_complex_type())
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
480 retval = octave_value
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
481 (args(0).float_complex_matrix_value (),
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
482 mattyp);
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
483 else
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
484 retval = octave_value
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
485 (args(0).float_matrix_value (),
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
486 mattyp);
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
487 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
488 else
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
489 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
490 if (args(0).is_complex_type())
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
491 retval = octave_value
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
492 (args(0).complex_matrix_value (),
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
493 mattyp);
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
494 else
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
495 retval = octave_value
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
496 (args(0).matrix_value (),
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
497 mattyp);
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
498 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
499 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
500 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
501 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
502 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
503 }
5323
e5a68648db9c [project @ 2005-04-29 13:10:36 by dbateman]
dbateman
parents:
diff changeset
504 }
e5a68648db9c [project @ 2005-04-29 13:10:36 by dbateman]
dbateman
parents:
diff changeset
505
e5a68648db9c [project @ 2005-04-29 13:10:36 by dbateman]
dbateman
parents:
diff changeset
506 return retval;
e5a68648db9c [project @ 2005-04-29 13:10:36 by dbateman]
dbateman
parents:
diff changeset
507 }
e5a68648db9c [project @ 2005-04-29 13:10:36 by dbateman]
dbateman
parents:
diff changeset
508
e5a68648db9c [project @ 2005-04-29 13:10:36 by dbateman]
dbateman
parents:
diff changeset
509 /*
5681
233d98d95659 [project @ 2006-03-16 17:48:55 by dbateman]
dbateman
parents: 5631
diff changeset
510
5775
ace8d8d26933 [project @ 2006-04-24 19:13:06 by jwe]
jwe
parents: 5760
diff changeset
511 ## FIXME
5681
233d98d95659 [project @ 2006-03-16 17:48:55 by dbateman]
dbateman
parents: 5631
diff changeset
512 ## Disable tests for lower under-determined and upper over-determined
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7567
diff changeset
513 ## matrices as this detection is disabled in MatrixType due to issues
5681
233d98d95659 [project @ 2006-03-16 17:48:55 by dbateman]
dbateman
parents: 5631
diff changeset
514 ## of non minimum norm solution being found.
5610
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents: 5506
diff changeset
515
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents: 5506
diff changeset
516 %!assert(matrix_type(speye(10,10)),"Diagonal");
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents: 5506
diff changeset
517 %!assert(matrix_type(speye(10,10)([2:10,1],:)),"Permuted Diagonal");
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents: 5506
diff changeset
518 %!assert(matrix_type([[speye(10,10);sparse(1,10)],[1;sparse(9,1);1]]),"Upper");
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents: 5506
diff changeset
519 %!assert(matrix_type([[speye(10,10);sparse(1,10)],[1;sparse(9,1);1]](:,[2,1,3:11])),"Permuted Upper");
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents: 5506
diff changeset
520 %!assert(matrix_type([speye(10,10),sparse(10,1);1,sparse(1,9),1]),"Lower");
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents: 5506
diff changeset
521 %!assert(matrix_type([speye(10,10),sparse(10,1);1,sparse(1,9),1]([2,1,3:11],:)),"Permuted Lower");
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents: 5506
diff changeset
522 %!test
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents: 5506
diff changeset
523 %! bnd=spparms("bandden");
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents: 5506
diff changeset
524 %! spparms("bandden",0.5);
7798
42c42c640108 improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents: 7789
diff changeset
525 %! a = spdiags(rand(10,3)-0.5,[-1,0,1],10,10);
5610
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents: 5506
diff changeset
526 %! assert(matrix_type(a),"Tridiagonal");
7798
42c42c640108 improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents: 7789
diff changeset
527 %! assert(matrix_type(a'+a+2*speye(10)),"Tridiagonal Positive Definite");
5610
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents: 5506
diff changeset
528 %! spparms("bandden",bnd);
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents: 5506
diff changeset
529 %!test
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents: 5506
diff changeset
530 %! bnd=spparms("bandden");
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents: 5506
diff changeset
531 %! spparms("bandden",0.5);
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents: 5506
diff changeset
532 %! a = spdiags(randn(10,4),[-2:1],10,10);
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents: 5506
diff changeset
533 %! assert(matrix_type(a),"Banded");
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents: 5506
diff changeset
534 %! assert(matrix_type(a'*a),"Banded Positive Definite");
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents: 5506
diff changeset
535 %! spparms("bandden",bnd);
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents: 5506
diff changeset
536 %!test
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents: 5506
diff changeset
537 %! a=[speye(10,10),[sparse(9,1);1];-1,sparse(1,9),1];
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents: 5506
diff changeset
538 %! assert(matrix_type(a),"Full");
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents: 5506
diff changeset
539 %! assert(matrix_type(a'*a),"Positive Definite");
5630
512d0d11ae39 [project @ 2006-02-20 22:05:30 by dbateman]
dbateman
parents: 5610
diff changeset
540 %!assert(matrix_type(speye(10,11)),"Diagonal");
512d0d11ae39 [project @ 2006-02-20 22:05:30 by dbateman]
dbateman
parents: 5610
diff changeset
541 %!assert(matrix_type(speye(10,11)([2:10,1],:)),"Permuted Diagonal");
512d0d11ae39 [project @ 2006-02-20 22:05:30 by dbateman]
dbateman
parents: 5610
diff changeset
542 %!assert(matrix_type(speye(11,10)),"Diagonal");
512d0d11ae39 [project @ 2006-02-20 22:05:30 by dbateman]
dbateman
parents: 5610
diff changeset
543 %!assert(matrix_type(speye(11,10)([2:11,1],:)),"Permuted Diagonal");
5681
233d98d95659 [project @ 2006-03-16 17:48:55 by dbateman]
dbateman
parents: 5631
diff changeset
544 %#!assert(matrix_type([[speye(10,10);sparse(1,10)],[[1,1];sparse(9,2);[1,1]]]),"Upper");
233d98d95659 [project @ 2006-03-16 17:48:55 by dbateman]
dbateman
parents: 5631
diff changeset
545 %#!assert(matrix_type([[speye(10,10);sparse(1,10)],[[1,1];sparse(9,2);[1,1]]](:,[2,1,3:12])),"Permuted Upper");
5630
512d0d11ae39 [project @ 2006-02-20 22:05:30 by dbateman]
dbateman
parents: 5610
diff changeset
546 %!assert(matrix_type([speye(11,9),[1;sparse(8,1);1;0]]),"Upper");
512d0d11ae39 [project @ 2006-02-20 22:05:30 by dbateman]
dbateman
parents: 5610
diff changeset
547 %!assert(matrix_type([speye(11,9),[1;sparse(8,1);1;0]](:,[2,1,3:10])),"Permuted Upper");
5681
233d98d95659 [project @ 2006-03-16 17:48:55 by dbateman]
dbateman
parents: 5631
diff changeset
548 %#!assert(matrix_type([speye(10,10),sparse(10,1);[1;1],sparse(2,9),[1;1]]),"Lower");
233d98d95659 [project @ 2006-03-16 17:48:55 by dbateman]
dbateman
parents: 5631
diff changeset
549 %#!assert(matrix_type([speye(10,10),sparse(10,1);[1;1],sparse(2,9),[1;1]]([2,1,3:12],:)),"Permuted Lower");
5630
512d0d11ae39 [project @ 2006-02-20 22:05:30 by dbateman]
dbateman
parents: 5610
diff changeset
550 %!assert(matrix_type([speye(9,11);[1,sparse(1,8),1,0]]),"Lower");
512d0d11ae39 [project @ 2006-02-20 22:05:30 by dbateman]
dbateman
parents: 5610
diff changeset
551 %!assert(matrix_type([speye(9,11);[1,sparse(1,8),1,0]]([2,1,3:10],:)),"Permuted Lower");
512d0d11ae39 [project @ 2006-02-20 22:05:30 by dbateman]
dbateman
parents: 5610
diff changeset
552 %!assert(matrix_type(spdiags(randn(10,4),[-2:1],10,9)),"Rectangular")
5610
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents: 5506
diff changeset
553
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents: 5506
diff changeset
554 %!assert(matrix_type(1i*speye(10,10)),"Diagonal");
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents: 5506
diff changeset
555 %!assert(matrix_type(1i*speye(10,10)([2:10,1],:)),"Permuted Diagonal");
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents: 5506
diff changeset
556 %!assert(matrix_type([[speye(10,10);sparse(1,10)],[1i;sparse(9,1);1]]),"Upper");
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents: 5506
diff changeset
557 %!assert(matrix_type([[speye(10,10);sparse(1,10)],[1i;sparse(9,1);1]](:,[2,1,3:11])),"Permuted Upper");
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents: 5506
diff changeset
558 %!assert(matrix_type([speye(10,10),sparse(10,1);1i,sparse(1,9),1]),"Lower");
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents: 5506
diff changeset
559 %!assert(matrix_type([speye(10,10),sparse(10,1);1i,sparse(1,9),1]([2,1,3:11],:)),"Permuted Lower");
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents: 5506
diff changeset
560 %!test
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents: 5506
diff changeset
561 %! bnd=spparms("bandden");
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents: 5506
diff changeset
562 %! spparms("bandden",0.5);
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents: 5506
diff changeset
563 %! assert(matrix_type(spdiags(1i*randn(10,3),[-1,0,1],10,10)),"Tridiagonal");
7798
42c42c640108 improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents: 7789
diff changeset
564 %! a = 1i*(rand(9,1)-0.5);a=[[a;0],ones(10,1),[0;-a]];
5610
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents: 5506
diff changeset
565 %! assert(matrix_type(spdiags(a,[-1,0,1],10,10)),"Tridiagonal Positive Definite");
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents: 5506
diff changeset
566 %! spparms("bandden",bnd);
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents: 5506
diff changeset
567 %!test
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents: 5506
diff changeset
568 %! bnd=spparms("bandden");
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents: 5506
diff changeset
569 %! spparms("bandden",0.5);
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents: 5506
diff changeset
570 %! assert(matrix_type(spdiags(1i*randn(10,4),[-2:1],10,10)),"Banded");
7798
42c42c640108 improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents: 7789
diff changeset
571 %! a = 1i*(rand(9,2)-0.5);a=[[a;[0,0]],ones(10,1),[[0;-a(:,2)],[0;0;-a(1:8,1)]]];
5610
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents: 5506
diff changeset
572 %! assert(matrix_type(spdiags(a,[-2:2],10,10)),"Banded Positive Definite");
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents: 5506
diff changeset
573 %! spparms("bandden",bnd);
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents: 5506
diff changeset
574 %!test
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents: 5506
diff changeset
575 %! a=[speye(10,10),[sparse(9,1);1i];-1,sparse(1,9),1];
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents: 5506
diff changeset
576 %! assert(matrix_type(a),"Full");
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents: 5506
diff changeset
577 %! assert(matrix_type(a'*a),"Positive Definite");
5630
512d0d11ae39 [project @ 2006-02-20 22:05:30 by dbateman]
dbateman
parents: 5610
diff changeset
578 %!assert(matrix_type(1i*speye(10,11)),"Diagonal");
512d0d11ae39 [project @ 2006-02-20 22:05:30 by dbateman]
dbateman
parents: 5610
diff changeset
579 %!assert(matrix_type(1i*speye(10,11)([2:10,1],:)),"Permuted Diagonal");
512d0d11ae39 [project @ 2006-02-20 22:05:30 by dbateman]
dbateman
parents: 5610
diff changeset
580 %!assert(matrix_type(1i*speye(11,10)),"Diagonal");
512d0d11ae39 [project @ 2006-02-20 22:05:30 by dbateman]
dbateman
parents: 5610
diff changeset
581 %!assert(matrix_type(1i*speye(11,10)([2:11,1],:)),"Permuted Diagonal");
5681
233d98d95659 [project @ 2006-03-16 17:48:55 by dbateman]
dbateman
parents: 5631
diff changeset
582 %#!assert(matrix_type([[speye(10,10);sparse(1,10)],[[1i,1i];sparse(9,2);[1i,1i]]]),"Upper");
233d98d95659 [project @ 2006-03-16 17:48:55 by dbateman]
dbateman
parents: 5631
diff changeset
583 %#!assert(matrix_type([[speye(10,10);sparse(1,10)],[[1i,1i];sparse(9,2);[1i,1i]]](:,[2,1,3:12])),"Permuted Upper");
5630
512d0d11ae39 [project @ 2006-02-20 22:05:30 by dbateman]
dbateman
parents: 5610
diff changeset
584 %!assert(matrix_type([speye(11,9),[1i;sparse(8,1);1i;0]]),"Upper");
512d0d11ae39 [project @ 2006-02-20 22:05:30 by dbateman]
dbateman
parents: 5610
diff changeset
585 %!assert(matrix_type([speye(11,9),[1i;sparse(8,1);1i;0]](:,[2,1,3:10])),"Permuted Upper");
5681
233d98d95659 [project @ 2006-03-16 17:48:55 by dbateman]
dbateman
parents: 5631
diff changeset
586 %#!assert(matrix_type([speye(10,10),sparse(10,1);[1i;1i],sparse(2,9),[1i;1i]]),"Lower");
233d98d95659 [project @ 2006-03-16 17:48:55 by dbateman]
dbateman
parents: 5631
diff changeset
587 %#!assert(matrix_type([speye(10,10),sparse(10,1);[1i;1i],sparse(2,9),[1i;1i]]([2,1,3:12],:)),"Permuted Lower");
5630
512d0d11ae39 [project @ 2006-02-20 22:05:30 by dbateman]
dbateman
parents: 5610
diff changeset
588 %!assert(matrix_type([speye(9,11);[1i,sparse(1,8),1i,0]]),"Lower");
512d0d11ae39 [project @ 2006-02-20 22:05:30 by dbateman]
dbateman
parents: 5610
diff changeset
589 %!assert(matrix_type([speye(9,11);[1i,sparse(1,8),1i,0]]([2,1,3:10],:)),"Permuted Lower");
512d0d11ae39 [project @ 2006-02-20 22:05:30 by dbateman]
dbateman
parents: 5610
diff changeset
590 %!assert(matrix_type(1i*spdiags(randn(10,4),[-2:1],10,9)),"Rectangular")
5610
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents: 5506
diff changeset
591
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents: 5506
diff changeset
592 %!test
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents: 5506
diff changeset
593 %! a = matrix_type(spdiags(randn(10,3),[-1,0,1],10,10),"Singular");
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents: 5506
diff changeset
594 %! assert(matrix_type(a),"Singular");
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents: 5506
diff changeset
595
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5775
diff changeset
596 %!assert(matrix_type(triu(ones(10,10))),"Upper");
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5775
diff changeset
597 %!assert(matrix_type(triu(ones(10,10),-1)),"Full");
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5775
diff changeset
598 %!assert(matrix_type(tril(ones(10,10))),"Lower");
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5775
diff changeset
599 %!assert(matrix_type(tril(ones(10,10),1)),"Full");
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5775
diff changeset
600 %!assert(matrix_type(10*eye(10,10) + ones(10,10)), "Positive Definite");
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5775
diff changeset
601 %!assert(matrix_type(ones(11,10)),"Rectangular")
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5775
diff changeset
602 %!test
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5775
diff changeset
603 %! a = matrix_type(ones(10,10),"Singular");
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5775
diff changeset
604 %! assert(matrix_type(a),"Singular");
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5775
diff changeset
605
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5775
diff changeset
606 %!assert(matrix_type(triu(1i*ones(10,10))),"Upper");
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5775
diff changeset
607 %!assert(matrix_type(triu(1i*ones(10,10),-1)),"Full");
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5775
diff changeset
608 %!assert(matrix_type(tril(1i*ones(10,10))),"Lower");
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5775
diff changeset
609 %!assert(matrix_type(tril(1i*ones(10,10),1)),"Full");
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5775
diff changeset
610 %!assert(matrix_type(10*eye(10,10) + 1i*triu(ones(10,10),1) -1i*tril(ones(10,10),-1)), "Positive Definite");
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5775
diff changeset
611 %!assert(matrix_type(ones(11,10)),"Rectangular")
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5775
diff changeset
612 %!test
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5775
diff changeset
613 %! a = matrix_type(ones(10,10),"Singular");
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5775
diff changeset
614 %! assert(matrix_type(a),"Singular");
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5775
diff changeset
615
5610
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents: 5506
diff changeset
616 */
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents: 5506
diff changeset
617
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents: 5506
diff changeset
618 /*
5323
e5a68648db9c [project @ 2005-04-29 13:10:36 by dbateman]
dbateman
parents:
diff changeset
619 ;;; Local Variables: ***
e5a68648db9c [project @ 2005-04-29 13:10:36 by dbateman]
dbateman
parents:
diff changeset
620 ;;; mode: C++ ***
e5a68648db9c [project @ 2005-04-29 13:10:36 by dbateman]
dbateman
parents:
diff changeset
621 ;;; End: ***
e5a68648db9c [project @ 2005-04-29 13:10:36 by dbateman]
dbateman
parents:
diff changeset
622 */