comparison libinterp/corefcn/schur.cc @ 20892:c07bee629973

2015 Code Sprint: use ovl ().
author Rik <rik@octave.org>
date Mon, 14 Dec 2015 11:28:48 -0800
parents 1142cf6abc0d
children 8da80da1ac37
comparison
equal deleted inserted replaced
20891:95c0d4c07c56 20892:c07bee629973
126 matrix, and has applications in the solution of algebraic Riccati equations\n\ 126 matrix, and has applications in the solution of algebraic Riccati equations\n\
127 in control (see @code{are} and @code{dare}).\n\ 127 in control (see @code{are} and @code{dare}).\n\
128 @seealso{rsf2csf, ordschur, lu, chol, hess, qr, qz, svd}\n\ 128 @seealso{rsf2csf, ordschur, lu, chol, hess, qr, qz, svd}\n\
129 @end deftypefn") 129 @end deftypefn")
130 { 130 {
131 octave_value_list retval;
132
133 int nargin = args.length (); 131 int nargin = args.length ();
134 132
135 if (nargin < 1 || nargin > 2 || nargout > 2) 133 if (nargin < 1 || nargin > 2 || nargout > 2)
136 print_usage (); 134 print_usage ();
137 135
138 octave_value arg = args(0); 136 octave_value arg = args(0);
139 137
140 std::string ord; 138 std::string ord;
141
142 if (nargin == 2) 139 if (nargin == 2)
143 ord = args(1).xstring_value ("schur: second argument must be a string"); 140 ord = args(1).xstring_value ("schur: second argument must be a string");
144 141
145 bool force_complex = false; 142 bool force_complex = false;
146 143
160 if (ord_char != 'U' && ord_char != 'A' && ord_char != 'D' 157 if (ord_char != 'U' && ord_char != 'A' && ord_char != 'D'
161 && ord_char != 'u' && ord_char != 'a' && ord_char != 'd') 158 && ord_char != 'u' && ord_char != 'a' && ord_char != 'd')
162 { 159 {
163 warning ("schur: incorrect ordered schur argument '%s'", 160 warning ("schur: incorrect ordered schur argument '%s'",
164 ord.c_str ()); 161 ord.c_str ());
165 return retval; 162 return octave_value_list ();
166 } 163 }
167 } 164 }
168 165
169 octave_idx_type nr = arg.rows (); 166 octave_idx_type nr = arg.rows ();
170 octave_idx_type nc = arg.columns (); 167 octave_idx_type nc = arg.columns ();
171 168
172 if (nr != nc) 169 if (nr != nc)
173 { 170 {
174 gripe_square_matrix_required ("schur"); 171 gripe_square_matrix_required ("schur");
175 return retval; 172 return octave_value_list ();
176 } 173 }
174
175 octave_value_list retval (nargout > 1 ? 2 : 1);
177 176
178 if (! arg.is_numeric_type ()) 177 if (! arg.is_numeric_type ())
179 gripe_wrong_type_arg ("schur", arg); 178 gripe_wrong_type_arg ("schur", arg);
180 else if (arg.is_single_type ()) 179 else if (arg.is_single_type ())
181 { 180 {
182 if (! force_complex && arg.is_real_type ()) 181 if (! force_complex && arg.is_real_type ())
183 { 182 {
184 FloatMatrix tmp = arg.float_matrix_value (); 183 FloatMatrix tmp = arg.float_matrix_value ();
185 184
186 if (nargout == 0 || nargout == 1) 185 if (nargout <= 1)
187 { 186 {
188 FloatSCHUR result (tmp, ord, false); 187 FloatSCHUR result (tmp, ord, false);
189 retval(0) = result.schur_matrix (); 188 retval = ovl (result.schur_matrix ());
190 } 189 }
191 else 190 else
192 { 191 {
193 FloatSCHUR result (tmp, ord, true); 192 FloatSCHUR result (tmp, ord, true);
194 retval(1) = result.schur_matrix (); 193 retval = ovl (result.unitary_matrix (),
195 retval(0) = result.unitary_matrix (); 194 result.schur_matrix ());
196 } 195 }
197 } 196 }
198 else 197 else
199 { 198 {
200 FloatComplexMatrix ctmp = arg.float_complex_matrix_value (); 199 FloatComplexMatrix ctmp = arg.float_complex_matrix_value ();
201 200
202 if (nargout == 0 || nargout == 1) 201 if (nargout <= 1)
203 { 202 {
204 FloatComplexSCHUR result (ctmp, ord, false); 203 FloatComplexSCHUR result (ctmp, ord, false);
205 retval(0) = mark_upper_triangular (result.schur_matrix ()); 204 retval = ovl (mark_upper_triangular (result.schur_matrix ()));
206 } 205 }
207 else 206 else
208 { 207 {
209 FloatComplexSCHUR result (ctmp, ord, true); 208 FloatComplexSCHUR result (ctmp, ord, true);
210 retval(1) = mark_upper_triangular (result.schur_matrix ()); 209 retval = ovl (result.unitary_matrix (),
211 retval(0) = result.unitary_matrix (); 210 mark_upper_triangular (result.schur_matrix ()));
212 } 211 }
213 } 212 }
214 } 213 }
215 else 214 else
216 { 215 {
217 if (! force_complex && arg.is_real_type ()) 216 if (! force_complex && arg.is_real_type ())
218 { 217 {
219 Matrix tmp = arg.matrix_value (); 218 Matrix tmp = arg.matrix_value ();
220 219
221 if (nargout == 0 || nargout == 1) 220 if (nargout <= 1)
222 { 221 {
223 SCHUR result (tmp, ord, false); 222 SCHUR result (tmp, ord, false);
224 retval(0) = result.schur_matrix (); 223 retval = ovl (result.schur_matrix ());
225 } 224 }
226 else 225 else
227 { 226 {
228 SCHUR result (tmp, ord, true); 227 SCHUR result (tmp, ord, true);
229 retval(1) = result.schur_matrix (); 228 retval = ovl (result.unitary_matrix (),
230 retval(0) = result.unitary_matrix (); 229 result.schur_matrix ());
231 } 230 }
232 } 231 }
233 else 232 else
234 { 233 {
235 ComplexMatrix ctmp = arg.complex_matrix_value (); 234 ComplexMatrix ctmp = arg.complex_matrix_value ();
236 235
237 if (nargout == 0 || nargout == 1) 236 if (nargout <= 1)
238 { 237 {
239 ComplexSCHUR result (ctmp, ord, false); 238 ComplexSCHUR result (ctmp, ord, false);
240 retval(0) = mark_upper_triangular (result.schur_matrix ()); 239 retval = ovl (mark_upper_triangular (result.schur_matrix ()));
241 } 240 }
242 else 241 else
243 { 242 {
244 ComplexSCHUR result (ctmp, ord, true); 243 ComplexSCHUR result (ctmp, ord, true);
245 retval(1) = mark_upper_triangular (result.schur_matrix ()); 244 retval = ovl (result.unitary_matrix (),
246 retval(0) = result.unitary_matrix (); 245 mark_upper_triangular (result.schur_matrix ()));
247 } 246 }
248 } 247 }
249 } 248 }
250 249
251 return retval; 250 return retval;