7
|
1 // f-schur.cc -*- C++ -*- |
1
|
2 /* |
|
3 |
|
4 Copyright (C) 1993 John W. Eaton |
|
5 |
|
6 This file is part of Octave. |
|
7 |
|
8 Octave is free software; you can redistribute it and/or modify it |
|
9 under the terms of the GNU General Public License as published by the |
|
10 Free Software Foundation; either version 2, or (at your option) any |
|
11 later version. |
|
12 |
|
13 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
16 for more details. |
|
17 |
|
18 You should have received a copy of the GNU General Public License |
|
19 along with Octave; see the file COPYING. If not, write to the Free |
|
20 Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. |
|
21 |
|
22 */ |
|
23 |
|
24 #ifdef __GNUG__ |
|
25 #pragma implementation |
|
26 #endif |
|
27 |
|
28 #include "Matrix.h" |
|
29 |
|
30 #include "tree-const.h" |
|
31 #include "user-prefs.h" |
|
32 #include "error.h" |
|
33 #include "gripes.h" |
7
|
34 #include "f-schur.h" |
1
|
35 |
|
36 #ifdef WITH_DLD |
|
37 tree_constant * |
162
|
38 builtin_schur_2 (const tree_constant *args, int nargin, int nargout) |
1
|
39 { |
|
40 return schur (args, nargin, nargout); |
|
41 } |
|
42 #endif |
|
43 |
|
44 tree_constant * |
162
|
45 schur (const tree_constant *args, int nargin, int nargout) |
1
|
46 { |
|
47 tree_constant *retval = NULL_TREE_CONST; |
|
48 |
|
49 tree_constant arg = args[1].make_numeric (); |
|
50 |
|
51 char *ord; |
|
52 if (nargin != 3) |
|
53 ord = "U"; |
|
54 else |
|
55 ord = args[2].string_value (); |
|
56 |
|
57 if (*ord != 'U' && *ord != 'A' && *ord != 'D' |
|
58 && *ord != 'u' && *ord != 'a' && *ord != 'd') |
|
59 { |
|
60 warning ("schur: incorrect ordered schur argument `%c'", *ord); |
|
61 Matrix m; |
|
62 retval = new tree_constant [3]; |
|
63 retval[0] = tree_constant (m); |
|
64 retval[1] = tree_constant (m); |
|
65 return retval; |
|
66 } |
|
67 int a_nr = arg.rows (); |
|
68 int a_nc = arg.columns (); |
|
69 |
|
70 if (a_nr == 0 || a_nc == 0) |
|
71 { |
|
72 int flag = user_pref.propagate_empty_matrices; |
|
73 if (flag != 0) |
|
74 { |
|
75 if (flag < 0) |
|
76 warning ("schur: argument is empty matrix"); |
|
77 Matrix m; |
|
78 retval = new tree_constant [3]; |
|
79 retval[0] = tree_constant (m); |
|
80 retval[1] = tree_constant (m); |
|
81 } |
|
82 else |
|
83 error ("schur: empty matrix is invalid as argument"); |
|
84 |
|
85 return retval; |
|
86 } |
|
87 if (a_nr != a_nc) |
|
88 { |
|
89 gripe_square_matrix_required ("schur"); |
|
90 return retval; |
|
91 } |
|
92 |
|
93 Matrix tmp; |
|
94 ComplexMatrix ctmp; |
|
95 |
|
96 switch (arg.const_type ()) |
|
97 { |
|
98 case tree_constant_rep::matrix_constant: |
|
99 { |
|
100 tmp = arg.matrix_value (); |
|
101 |
|
102 SCHUR result (tmp,ord); |
|
103 |
|
104 if (nargout == 1) |
|
105 { |
|
106 retval = new tree_constant [2]; |
|
107 retval[0] = tree_constant (result.schur_matrix ()); |
|
108 } |
|
109 else |
|
110 { |
|
111 retval = new tree_constant [3]; |
|
112 retval[0] = tree_constant (result.unitary_matrix ()); |
|
113 retval[1] = tree_constant (result.schur_matrix ()); |
|
114 } |
|
115 } |
|
116 break; |
|
117 case tree_constant_rep::complex_matrix_constant: |
|
118 { |
|
119 ctmp = arg.complex_matrix_value (); |
|
120 |
|
121 ComplexSCHUR result (ctmp,ord); |
|
122 |
|
123 if (nargout == 1) |
|
124 { |
|
125 retval = new tree_constant [2]; |
|
126 retval[0] = tree_constant (result.schur_matrix ()); |
|
127 } |
|
128 else |
|
129 { |
|
130 retval = new tree_constant [3]; |
|
131 retval[0] = tree_constant (result.unitary_matrix ()); |
|
132 retval[1] = tree_constant (result.schur_matrix ()); |
|
133 } |
|
134 } |
|
135 break; |
|
136 case tree_constant_rep::scalar_constant: |
|
137 { |
|
138 double d = arg.double_value (); |
|
139 if (nargout == 1) |
|
140 { |
|
141 retval = new tree_constant [2]; |
|
142 retval[0] = tree_constant (d); |
|
143 } |
|
144 else |
|
145 { |
|
146 retval = new tree_constant [3]; |
|
147 retval[0] = tree_constant (1); |
|
148 retval[1] = tree_constant (d); |
|
149 } |
|
150 } |
|
151 break; |
|
152 case tree_constant_rep::complex_scalar_constant: |
|
153 { |
|
154 Complex c = arg.complex_value (); |
|
155 if (nargout == 1) |
|
156 { |
|
157 retval = new tree_constant [2]; |
|
158 retval[0] = tree_constant (c); |
|
159 } |
|
160 else |
|
161 { |
|
162 retval = new tree_constant [3]; |
|
163 retval[0] = tree_constant (1); |
|
164 retval[1] = tree_constant (c); |
|
165 } |
|
166 } |
|
167 break; |
|
168 default: |
|
169 panic_impossible (); |
|
170 break; |
|
171 } |
|
172 |
|
173 return retval; |
|
174 } |
|
175 |
|
176 /* |
|
177 ;;; Local Variables: *** |
|
178 ;;; mode: C++ *** |
|
179 ;;; page-delimiter: "^/\\*" *** |
|
180 ;;; End: *** |
|
181 */ |