annotate libinterp/corefcn/ordschur.cc @ 20819:f428cbe7576f

eliminate unnecessary uses of nargin * __dsearchn__.cc, betainc.cc, bsxfun.cc, data.cc, debug.cc, det.cc, dot.cc, error.cc, file-io.cc, givens.cc, graphics.cc, hess.cc, hex2num.cc, input.cc, inv.cc, mgorth.cc, ordschur.cc, pr-output.cc, profiler.cc, rcond.cc, regexp.cc, sqrtm.cc, sub2ind.cc, sylvester.cc, syscalls.cc, sysdep.cc, tsearch.cc, urlwrite.cc, utils.cc, variables.cc: Don't use nargin variable unless it is used more than once.
author John W. Eaton <jwe@octave.org>
date Mon, 07 Dec 2015 13:54:01 -0500
parents b16bcd7a2a33
children 35241c4b696c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
19747
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
1 /*
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
2
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
3 Copyright (C) 2015 Sébastien Villemot <sebastien@debian.org>
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
4
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
5 This file is part of Octave.
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
6
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
7 Octave is free software; you can redistribute it and/or modify it
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
8 under the terms of the GNU General Public License as published by the
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
9 Free Software Foundation; either version 3 of the License, or (at your
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
10 option) any later version.
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
11
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
12 Octave is distributed in the hope that it will be useful, but WITHOUT
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
15 for more details.
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
16
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
18 along with Octave; see the file COPYING. If not, see
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
19 <http://www.gnu.org/licenses/>.
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
20
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
21 */
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
22
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
23 #ifdef HAVE_CONFIG_H
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
24 #include <config.h>
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
25 #endif
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
26
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
27 #include "defun.h"
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
28 #include "error.h"
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
29 #include "oct-obj.h"
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
30 #include "f77-fcn.h"
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
31
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
32 extern "C"
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
33 {
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
34 F77_RET_T
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
35 F77_FUNC (dtrsen, DTRSEN) (F77_CONST_CHAR_ARG_DECL, F77_CONST_CHAR_ARG_DECL,
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
36 const octave_idx_type*, const octave_idx_type&,
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
37 double*, const octave_idx_type&, double*, const octave_idx_type&,
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
38 double*, double*, octave_idx_type&, double&, double&, double*,
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
39 const octave_idx_type&, octave_idx_type*,
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
40 const octave_idx_type&, octave_idx_type&);
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
41
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
42 F77_RET_T
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
43 F77_FUNC (ztrsen, ZTRSEN) (F77_CONST_CHAR_ARG_DECL, F77_CONST_CHAR_ARG_DECL,
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
44 const octave_idx_type*, const octave_idx_type&,
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
45 Complex*, const octave_idx_type&, Complex*, const octave_idx_type&,
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
46 Complex*, octave_idx_type&, double&, double&, Complex*,
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
47 const octave_idx_type&, octave_idx_type &);
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
48
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
49 F77_RET_T
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
50 F77_FUNC (strsen, STRSEN) (F77_CONST_CHAR_ARG_DECL, F77_CONST_CHAR_ARG_DECL,
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
51 const octave_idx_type*, const octave_idx_type&,
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
52 float*, const octave_idx_type&, float*, const octave_idx_type&,
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
53 float*, float*, octave_idx_type&, float&, float&, float*,
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
54 const octave_idx_type&, octave_idx_type*,
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
55 const octave_idx_type&, octave_idx_type&);
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
56
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
57 F77_RET_T
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
58 F77_FUNC (ctrsen, CTRSEN) (F77_CONST_CHAR_ARG_DECL, F77_CONST_CHAR_ARG_DECL,
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
59 const octave_idx_type*, const octave_idx_type&,
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
60 FloatComplex*, const octave_idx_type&, FloatComplex*, const octave_idx_type&,
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
61 FloatComplex*, octave_idx_type&, float&, float&, FloatComplex*,
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
62 const octave_idx_type&, octave_idx_type &);
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
63 }
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
64
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
65 DEFUN (ordschur, args, ,
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
66 "-*- texinfo -*-\n\
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
67 @deftypefn {Loadable Function} {[@var{UR}, @var{SR}] =} ordschur (@var{U}, @var{S}, @var{select})\n\
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
68 Reorders the real Schur factorization (@var{U},@var{S}) obtained with the\n\
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
69 @code{schur} function, so that selected eigenvalues appear in the upper left\n\
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
70 diagonal blocks of the quasi triangular Schur matrix.\n\
20172
4f45eaf83908 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19861
diff changeset
71 \n\
19747
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
72 The logical vector @var{select} specifies the selected eigenvalues as they\n\
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
73 appear along @var{S}'s diagonal.\n\
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
74 \n\
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
75 For example, given the matrix @code{@var{A} = [1, 2; 3, 4]}, and its Schur\n\
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
76 decomposition\n\
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
77 \n\
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
78 @example\n\
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
79 [@var{U}, @var{S}] = schur (@var{A})\n\
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
80 @end example\n\
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
81 \n\
19795
ca7599ae464d doc: Grammarcheck documentation ahead of 4.0 release.
Rik <rik@octave.org>
parents: 19747
diff changeset
82 @noindent\n\
19747
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
83 which returns\n\
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
84 \n\
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
85 @example\n\
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
86 @group\n\
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
87 @var{U} =\n\
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
88 \n\
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
89 -0.82456 -0.56577\n\
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
90 0.56577 -0.82456\n\
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
91 \n\
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
92 @var{S} =\n\
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
93 \n\
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
94 -0.37228 -1.00000\n\
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
95 0.00000 5.37228\n\
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
96 \n\
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
97 @end group\n\
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
98 @end example\n\
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
99 \n\
19795
ca7599ae464d doc: Grammarcheck documentation ahead of 4.0 release.
Rik <rik@octave.org>
parents: 19747
diff changeset
100 It is possible to reorder the decomposition so that the positive eigenvalue\n\
ca7599ae464d doc: Grammarcheck documentation ahead of 4.0 release.
Rik <rik@octave.org>
parents: 19747
diff changeset
101 is in the upper left corner, by doing:\n\
19747
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
102 \n\
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
103 @example\n\
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
104 [@var{U}, @var{S}] = ordschur (@var{U}, @var{S}, [0,1])\n\
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
105 @end example\n\
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
106 \n\
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
107 @seealso{schur}\n\
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
108 @end deftypefn")
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
109 {
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
110 octave_value_list retval;
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
111
20819
f428cbe7576f eliminate unnecessary uses of nargin
John W. Eaton <jwe@octave.org>
parents: 20816
diff changeset
112 if (args.length () != 3)
20802
8bb38ba1bad6 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20704
diff changeset
113 print_usage ();
19747
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
114
20703
85e5efae848a eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20172
diff changeset
115 const Array<octave_idx_type> sel = args(2).octave_idx_type_vector_value ("ordschur: SELECT must be an array of integers");
85e5efae848a eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20172
diff changeset
116
19747
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
117 const octave_idx_type n = sel.numel ();
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
118
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
119 const dim_vector dimU = args(0).dims ();
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
120 const dim_vector dimS = args(1).dims ();
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
121 if (n != dimU(0))
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
122 {
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
123 error ("ordschur: SELECT must have same length as the sides of U and S");
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
124 return retval;
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
125 }
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
126 else if (n != dimU(0) || n != dimS(0) || n != dimU(1) || n != dimS(1))
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
127 {
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
128 error ("ordschur: U and S must be square and of equal sizes");
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
129 return retval;
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
130 }
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
131
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
132 const bool double_type = args(0).is_double_type ()
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
133 || args(1).is_double_type ();
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
134 const bool complex_type = args(0).is_complex_type ()
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
135 || args(1).is_complex_type ();
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
136
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
137 #define PREPARE_ARGS(TYPE, TYPE_M, TYPE_COND) \
20704
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20703
diff changeset
138 TYPE ## Matrix U = args(0).x ## TYPE_M ## _value ("ordschur: U and S must be real or complex floating point matrices"); \
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20703
diff changeset
139 TYPE ## Matrix S = args(1).x ## TYPE_M ## _value ("ordschur: U and S must be real or complex floating point matrices"); \
19747
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
140 TYPE ## Matrix w (dim_vector (n, 1)); \
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
141 TYPE ## Matrix work (dim_vector (n, 1)); \
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
142 octave_idx_type m; \
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
143 octave_idx_type info; \
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
144 TYPE_COND cond1, cond2;
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
145
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
146 #define PREPARE_OUTPUT()\
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
147 if (info != 0) \
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
148 { \
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
149 error ("ordschur: trsen failed"); \
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
150 return retval; \
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
151 } \
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
152 retval(0) = U; \
19861
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19795
diff changeset
153 retval(1) = S;
19747
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
154
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
155 if (double_type)
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
156 {
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
157 if (complex_type)
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
158 {
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
159 PREPARE_ARGS (Complex, complex_matrix, double)
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
160
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
161 F77_XFCN (ztrsen, ztrsen,
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
162 (F77_CONST_CHAR_ARG ("N"), F77_CONST_CHAR_ARG ("V"),
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
163 sel.data (), n, S.fortran_vec (), n, U.fortran_vec (), n,
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
164 w.fortran_vec (), m, cond1, cond2, work.fortran_vec (), n,
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
165 info));
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
166 PREPARE_OUTPUT()
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
167 }
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
168 else
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
169 {
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
170 PREPARE_ARGS (, matrix, double)
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
171 Matrix wi (dim_vector (n, 1));
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
172 Array<octave_idx_type> iwork (dim_vector (n, 1));
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
173
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
174 F77_XFCN (dtrsen, dtrsen,
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
175 (F77_CONST_CHAR_ARG ("N"), F77_CONST_CHAR_ARG ("V"),
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
176 sel.data (), n, S.fortran_vec (), n, U.fortran_vec (), n,
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
177 w.fortran_vec (), wi.fortran_vec (), m, cond1, cond2,
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
178 work.fortran_vec (), n, iwork.fortran_vec (), n, info));
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
179 PREPARE_OUTPUT ()
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
180 }
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
181 }
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
182 else
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
183 {
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
184 if (complex_type)
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
185 {
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
186 PREPARE_ARGS (FloatComplex, float_complex_matrix, float)
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
187
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
188 F77_XFCN (ctrsen, ctrsen,
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
189 (F77_CONST_CHAR_ARG ("N"), F77_CONST_CHAR_ARG ("V"),
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
190 sel.data (), n, S.fortran_vec (), n, U.fortran_vec (), n,
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
191 w.fortran_vec (), m, cond1, cond2, work.fortran_vec (), n,
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
192 info));
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
193 PREPARE_OUTPUT ()
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
194 }
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
195 else
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
196 {
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
197 PREPARE_ARGS (Float, float_matrix, float)
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
198 FloatMatrix wi (dim_vector (n, 1));
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
199 Array<octave_idx_type> iwork (dim_vector (n, 1));
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
200
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
201 F77_XFCN (strsen, strsen,
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
202 (F77_CONST_CHAR_ARG ("N"), F77_CONST_CHAR_ARG ("V"),
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
203 sel.data (), n, S.fortran_vec (), n, U.fortran_vec (), n,
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
204 w.fortran_vec (), wi.fortran_vec (), m, cond1, cond2,
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
205 work.fortran_vec (), n, iwork.fortran_vec (), n, info));
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
206 PREPARE_OUTPUT ()
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
207 }
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
208 }
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
209
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
210 #undef PREPARE_ARGS
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
211 #undef PREPARE_OUTPUT
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
212
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
213 return retval;
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
214 }
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
215
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
216 /*
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
217
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
218 %!test
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
219 %! A = [1, 2, 3, -2; 4, 5, 6, -5 ; 7, 8, 9, -5; 10, 11, 12, 4 ];
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
220 %! [U, T] = schur (A);
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
221 %! [US, TS] = ordschur (U, T, [ 0, 0, 1, 1 ]);
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
222 %! assert (US*TS*US', A, sqrt (eps))
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
223 %! assert (diag (T)(3:4), diag (TS)(1:2), sqrt (eps))
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
224
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
225 %!test
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
226 %! A = [1, 2, 3, -2; 4, 5, 6, -5 ; 7, 8, 9, -5; 10, 11, 12, 4 ];
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
227 %! [U, T] = schur (A);
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
228 %! [US, TS] = ordschur (single (U), single (T), [ 0, 0, 1, 1 ]);
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
229 %! assert (US*TS*US', A, sqrt (eps ("single")))
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
230 %! assert (diag (T)(3:4), diag (TS)(1:2), sqrt (eps ("single")))
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
231
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
232 %!test
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
233 %! A = [1, 2, 3, -2; 4, 5, 6, -5 ; 7, 8, 9, -5; 10, 11, 12, 4+3i ];
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
234 %! [U, T] = schur (A);
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
235 %! [US, TS] = ordschur (U, T, [ 0, 0, 1, 1 ]);
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
236 %! assert (US*TS*US', A, sqrt (eps))
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
237 %! assert (diag (T)(3:4), diag (TS)(1:2), sqrt (eps))
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
238
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
239 %!test
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
240 %! A = [1, 2, 3, -2; 4, 5, 6, -5 ; 7, 8, 9, -5; 10, 11, 12, 4+3i ];
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
241 %! [U, T] = schur (A);
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
242 %! [US, TS] = ordschur (single (U), single (T), [ 0, 0, 1, 1 ]);
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
243 %! assert (US*TS*US', A, sqrt (eps ("single")))
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
244 %! assert (diag (T)(3:4), diag (TS)(1:2), sqrt (eps ("single")))
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
245
56157a7505ed Add new ordschur function.
Sébastien Villemot <sebastien@debian.org>
parents:
diff changeset
246 */