Mercurial > octave
annotate libinterp/corefcn/qz.cc @ 31976:e6b24d0d485c
qz: Handle input and output arguments in a Matlab-compatible way.
* etc/NEWS.9.md: Announce changes in the Matlab Compatibility section.
* libinterp/corefcn/qz.cc: Always compute the complex QZ decomposition if
there are only two input arguments. Accept an optional third input argument
'real' or 'complex' to select the type of decomposition. The output arguments
are now always in the same order independently of the input arguments, and the
generalized eigenvalues are no longer returned. Remove the optional reordering
of generalized eigenvalues. In the real case, do not try to compute the complex
form of eigenvectors. Emit warnings for cases when behaviour has been modified
in a backward-incompatible way. Adapt BIST to the new interface.
* scripts/linear-algebra/ordeig.m: Adapt BIST to the new qz interface.
author | Sébastien Villemot <sebastien@debian.org> |
---|---|
date | Tue, 04 Apr 2023 17:54:53 +0200 |
parents | c8dd3da44e83 |
children | f5c0a0754da1 |
rev | line source |
---|---|
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
1 //////////////////////////////////////////////////////////////////////// |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
2 // |
31706
597f3ee61a48
update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents:
31605
diff
changeset
|
3 // Copyright (C) 1998-2023 The Octave Project Developers |
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
4 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
5 // See the file COPYRIGHT.md in the top-level directory of this |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
6 // distribution or <https://octave.org/copyright/>. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
7 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
8 // This file is part of Octave. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
9 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
10 // Octave is free software: you can redistribute it and/or modify it |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
11 // under the terms of the GNU General Public License as published by |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
12 // the Free Software Foundation, either version 3 of the License, or |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
13 // (at your option) any later version. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
14 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
15 // Octave is distributed in the hope that it will be useful, but |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
16 // WITHOUT ANY WARRANTY; without even the implied warranty of |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
18 // GNU General Public License for more details. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
19 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
20 // You should have received a copy of the GNU General Public License |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
21 // along with Octave; see the file COPYING. If not, see |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
22 // <https://www.gnu.org/licenses/>. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
23 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
24 //////////////////////////////////////////////////////////////////////// |
3183 | 25 |
26 // Generalized eigenvalue balancing via LAPACK | |
3911 | 27 |
25570
da2b38b7a077
Use LAPACK DTGSEN subrouting for ordered-qz computation (bug #53761)
Sébastien Villemot <sebastien@debian.org>
parents:
25106
diff
changeset
|
28 // Originally written by A. S. Hodel <scotte@eng.auburn.edu>, but is |
da2b38b7a077
Use LAPACK DTGSEN subrouting for ordered-qz computation (bug #53761)
Sébastien Villemot <sebastien@debian.org>
parents:
25106
diff
changeset
|
29 // substantially different with the change to use LAPACK. |
3183 | 30 |
31 #undef DEBUG | |
32 #undef DEBUG_SORT | |
33 #undef DEBUG_EIG | |
34 | |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21562
diff
changeset
|
35 #if defined (HAVE_CONFIG_H) |
21301
40de9f8f23a6
Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents:
21279
diff
changeset
|
36 # include "config.h" |
9786
2c279308f6ab
fix includes in some src/DLD-FUNCTIONS files
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
37 #endif |
3183 | 38 |
23430 | 39 #include <cctype> |
40 #include <cmath> | |
4051 | 41 |
26001
acb4689aa5f2
* qz.cc: Use octave_stdout instead of std::cout for debugging messages.
John W. Eaton <jwe@octave.org>
parents:
25734
diff
changeset
|
42 #if defined (DEBUG_EIG) |
acb4689aa5f2
* qz.cc: Use octave_stdout instead of std::cout for debugging messages.
John W. Eaton <jwe@octave.org>
parents:
25734
diff
changeset
|
43 # include <iomanip> |
23430 | 44 #endif |
3183 | 45 |
4153 | 46 #include "f77-fcn.h" |
22322
93b3cdd36854
move most f77 function decls to separate header files
John W. Eaton <jwe@octave.org>
parents:
22317
diff
changeset
|
47 #include "lo-lapack-proto.h" |
21279
eb1524b07fe3
better use of templates for qr classes
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
48 #include "qr.h" |
4153 | 49 #include "quit.h" |
50 | |
15039
e753177cde93
maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents:
14876
diff
changeset
|
51 #include "defun.h" |
3183 | 52 #include "error.h" |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
53 #include "errwarn.h" |
20940
48b2ad5ee801
maint: Rename oct-obj.[cc|h] to ovl.[cc|h] for clarity.
Rik <rik@octave.org>
parents:
20892
diff
changeset
|
54 #include "ovl.h" |
3185 | 55 #if defined (DEBUG) || defined (DEBUG_SORT) |
26001
acb4689aa5f2
* qz.cc: Use octave_stdout instead of std::cout for debugging messages.
John W. Eaton <jwe@octave.org>
parents:
25734
diff
changeset
|
56 # include "pager.h" |
21200
fcac5dbbf9ed
maint: Indent #ifdef blocks in libinterp.
Rik <rik@octave.org>
parents:
21110
diff
changeset
|
57 # include "pr-output.h" |
3183 | 58 #endif |
59 | |
31605
e88a07dec498
maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents:
30564
diff
changeset
|
60 OCTAVE_BEGIN_NAMESPACE(octave) |
29958
32c3a5805893
move DEFUN and DEFMETHOD functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29558
diff
changeset
|
61 |
15039
e753177cde93
maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents:
14876
diff
changeset
|
62 DEFUN (qz, args, nargout, |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
63 doc: /* -*- texinfo -*- |
31976
e6b24d0d485c
qz: Handle input and output arguments in a Matlab-compatible way.
Sébastien Villemot <sebastien@debian.org>
parents:
31827
diff
changeset
|
64 @deftypefn {} {[@var{AA}, @var{BB}, @var{Q}, @var{Z}, @var{V}, @var{W}] =} qz (@var{A}, @var{B}) |
e6b24d0d485c
qz: Handle input and output arguments in a Matlab-compatible way.
Sébastien Villemot <sebastien@debian.org>
parents:
31827
diff
changeset
|
65 @deftypefnx {} {[@var{AA}, @var{BB}, @var{Q}, @var{Z}, @var{V}, @var{W}] =} qz (@var{A}, @var{B}, @var{opt}) |
25106
d7ad543255c5
doc: Shorten very long first sentences of docstrings (bug #53388).
Rik <rik@octave.org>
parents:
25103
diff
changeset
|
66 Compute the QZ@tie{}decomposition of a generalized eigenvalue problem. |
d7ad543255c5
doc: Shorten very long first sentences of docstrings (bug #53388).
Rik <rik@octave.org>
parents:
25103
diff
changeset
|
67 |
d7ad543255c5
doc: Shorten very long first sentences of docstrings (bug #53388).
Rik <rik@octave.org>
parents:
25103
diff
changeset
|
68 The generalized eigenvalue problem is defined as |
d7ad543255c5
doc: Shorten very long first sentences of docstrings (bug #53388).
Rik <rik@octave.org>
parents:
25103
diff
changeset
|
69 |
23428
1bc0e610e293
doc: Redo docstring for qz (bug #50846).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
70 @tex |
1bc0e610e293
doc: Redo docstring for qz (bug #50846).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
71 $$A x = \lambda B x$$ |
1bc0e610e293
doc: Redo docstring for qz (bug #50846).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
72 @end tex |
1bc0e610e293
doc: Redo docstring for qz (bug #50846).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
73 @ifnottex |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
74 |
23428
1bc0e610e293
doc: Redo docstring for qz (bug #50846).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
75 @math{A x = @var{lambda} B x} |
1bc0e610e293
doc: Redo docstring for qz (bug #50846).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
76 |
1bc0e610e293
doc: Redo docstring for qz (bug #50846).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
77 @end ifnottex |
1bc0e610e293
doc: Redo docstring for qz (bug #50846).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
78 |
31976
e6b24d0d485c
qz: Handle input and output arguments in a Matlab-compatible way.
Sébastien Villemot <sebastien@debian.org>
parents:
31827
diff
changeset
|
79 There are two calling forms of the function: |
23428
1bc0e610e293
doc: Redo docstring for qz (bug #50846).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
80 |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
81 @enumerate |
23428
1bc0e610e293
doc: Redo docstring for qz (bug #50846).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
82 @item @code{[@var{AA}, @var{BB}, @var{Q}, @var{Z}, @var{V}, @var{W}, @var{lambda}] = qz (@var{A}, @var{B})} |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
83 |
31976
e6b24d0d485c
qz: Handle input and output arguments in a Matlab-compatible way.
Sébastien Villemot <sebastien@debian.org>
parents:
31827
diff
changeset
|
84 Compute the complex QZ@tie{}decomposition, generalized eigenvectors, and generalized |
23428
1bc0e610e293
doc: Redo docstring for qz (bug #50846).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
85 eigenvalues. |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
86 @tex |
29556
d75aa2bf4915
qz.cc: return correct number of eigenvalues (bug #60357).
Rik <rik@octave.org>
parents:
29358
diff
changeset
|
87 $$ AA = Q^T AZ, BB = Q^T BZ $$ |
31976
e6b24d0d485c
qz: Handle input and output arguments in a Matlab-compatible way.
Sébastien Villemot <sebastien@debian.org>
parents:
31827
diff
changeset
|
88 $$ { \rm diag }(BB)AV = BV{ \rm diag }(AA) $$ |
e6b24d0d485c
qz: Handle input and output arguments in a Matlab-compatible way.
Sébastien Villemot <sebastien@debian.org>
parents:
31827
diff
changeset
|
89 $$ { \rm diag }(BB) W^T A = { \rm diag }(AA) W^T B $$ |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
90 @end tex |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
91 @ifnottex |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
92 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
93 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
94 @group |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
95 |
29556
d75aa2bf4915
qz.cc: return correct number of eigenvalues (bug #60357).
Rik <rik@octave.org>
parents:
29358
diff
changeset
|
96 @var{AA} = @var{Q} * @var{A} * @var{Z}, @var{BB} = @var{Q} * @var{B} * @var{Z} |
31976
e6b24d0d485c
qz: Handle input and output arguments in a Matlab-compatible way.
Sébastien Villemot <sebastien@debian.org>
parents:
31827
diff
changeset
|
97 @var{A} * @var{V} * diag (diag (@var{BB})) = @var{B} * @var{V} * diag (diag (@var{AA})) |
e6b24d0d485c
qz: Handle input and output arguments in a Matlab-compatible way.
Sébastien Villemot <sebastien@debian.org>
parents:
31827
diff
changeset
|
98 diag (diag (@var{BB})) * @var{W}' * @var{A} = diag (diag (@var{AA})) * @var{W}' * @var{B} |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
99 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
100 @end group |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
101 @end example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
102 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
103 @end ifnottex |
31976
e6b24d0d485c
qz: Handle input and output arguments in a Matlab-compatible way.
Sébastien Villemot <sebastien@debian.org>
parents:
31827
diff
changeset
|
104 with @var{AA} and @var{BB} upper triangular, and @var{Q} and @var{Z} |
e6b24d0d485c
qz: Handle input and output arguments in a Matlab-compatible way.
Sébastien Villemot <sebastien@debian.org>
parents:
31827
diff
changeset
|
105 unitary. The matrices @var{V} and @var{W} respectively contain the right |
e6b24d0d485c
qz: Handle input and output arguments in a Matlab-compatible way.
Sébastien Villemot <sebastien@debian.org>
parents:
31827
diff
changeset
|
106 and left generalized eigenvectors. |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
107 |
23428
1bc0e610e293
doc: Redo docstring for qz (bug #50846).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
108 @item @code{[@var{AA}, @var{BB}, @var{Z} @{, @var{lambda}@}] = qz (@var{A}, @var{B}, @var{opt})} |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
109 |
31976
e6b24d0d485c
qz: Handle input and output arguments in a Matlab-compatible way.
Sébastien Villemot <sebastien@debian.org>
parents:
31827
diff
changeset
|
110 The @var{opt} argument must be equal to either @qcode{"real"} or |
e6b24d0d485c
qz: Handle input and output arguments in a Matlab-compatible way.
Sébastien Villemot <sebastien@debian.org>
parents:
31827
diff
changeset
|
111 @qcode{"complex"}. If it is equal to @qcode{"complex"}, then this |
e6b24d0d485c
qz: Handle input and output arguments in a Matlab-compatible way.
Sébastien Villemot <sebastien@debian.org>
parents:
31827
diff
changeset
|
112 calling form is equivalent to the first one with only two input |
e6b24d0d485c
qz: Handle input and output arguments in a Matlab-compatible way.
Sébastien Villemot <sebastien@debian.org>
parents:
31827
diff
changeset
|
113 arguments. |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
114 |
31976
e6b24d0d485c
qz: Handle input and output arguments in a Matlab-compatible way.
Sébastien Villemot <sebastien@debian.org>
parents:
31827
diff
changeset
|
115 If @var{opt} is equal to @qcode{"real"}, then the real QZ decomposition |
e6b24d0d485c
qz: Handle input and output arguments in a Matlab-compatible way.
Sébastien Villemot <sebastien@debian.org>
parents:
31827
diff
changeset
|
116 is computed. In particular, @var{AA} is only guaranteed to be |
e6b24d0d485c
qz: Handle input and output arguments in a Matlab-compatible way.
Sébastien Villemot <sebastien@debian.org>
parents:
31827
diff
changeset
|
117 quasi-upper triangular with 1-by-1 and 2-by-2 blocks on the diagonal, |
e6b24d0d485c
qz: Handle input and output arguments in a Matlab-compatible way.
Sébastien Villemot <sebastien@debian.org>
parents:
31827
diff
changeset
|
118 and @var{Q} and @var{Z} are orthogonal. The identities mentioned above |
e6b24d0d485c
qz: Handle input and output arguments in a Matlab-compatible way.
Sébastien Villemot <sebastien@debian.org>
parents:
31827
diff
changeset
|
119 for right and left generalized eigenvectors are only verified if |
e6b24d0d485c
qz: Handle input and output arguments in a Matlab-compatible way.
Sébastien Villemot <sebastien@debian.org>
parents:
31827
diff
changeset
|
120 @var{AA} is upper triangular (i.e., when all the generalized eigenvalues |
e6b24d0d485c
qz: Handle input and output arguments in a Matlab-compatible way.
Sébastien Villemot <sebastien@debian.org>
parents:
31827
diff
changeset
|
121 are real, in which case the real and complex QZ coincide). |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
122 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
123 @end enumerate |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
124 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
125 Note: @code{qz} performs permutation balancing, but not scaling |
28961
d9d028b479ac
doc: Use @code{} within alternate text for @xref,@pxref macros in libinterp/
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
126 (@pxref{XREFbalance,,@code{balance}}), which may be lead to less accurate |
d9d028b479ac
doc: Use @code{} within alternate text for @xref,@pxref macros in libinterp/
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
127 results than @code{eig}. The order of output arguments was selected for |
d9d028b479ac
doc: Use @code{} within alternate text for @xref,@pxref macros in libinterp/
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
128 compatibility with @sc{matlab}. |
29556
d75aa2bf4915
qz.cc: return correct number of eigenvalues (bug #60357).
Rik <rik@octave.org>
parents:
29358
diff
changeset
|
129 @seealso{eig, gsvd, balance, chol, hess, lu, qr, qzhess, schur} |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
130 @end deftypefn */) |
3183 | 131 { |
23430 | 132 int nargin = args.length (); |
3183 | 133 |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21562
diff
changeset
|
134 #if defined (DEBUG) |
26001
acb4689aa5f2
* qz.cc: Use octave_stdout instead of std::cout for debugging messages.
John W. Eaton <jwe@octave.org>
parents:
25734
diff
changeset
|
135 octave_stdout << "qz: nargin = " << nargin |
acb4689aa5f2
* qz.cc: Use octave_stdout instead of std::cout for debugging messages.
John W. Eaton <jwe@octave.org>
parents:
25734
diff
changeset
|
136 << ", nargout = " << nargout << std::endl; |
3185 | 137 #endif |
3183 | 138 |
31976
e6b24d0d485c
qz: Handle input and output arguments in a Matlab-compatible way.
Sébastien Villemot <sebastien@debian.org>
parents:
31827
diff
changeset
|
139 if (nargin < 2 || nargin > 3 || nargout > 6) |
20802
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20700
diff
changeset
|
140 print_usage (); |
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20700
diff
changeset
|
141 |
31976
e6b24d0d485c
qz: Handle input and output arguments in a Matlab-compatible way.
Sébastien Villemot <sebastien@debian.org>
parents:
31827
diff
changeset
|
142 bool complex_case = true; |
3185 | 143 |
24116
e1020353fff5
qz: initialize optional ordering flag safely
Mike Miller <mtmiller@octave.org>
parents:
23826
diff
changeset
|
144 if (nargin == 3) |
3185 | 145 { |
23430 | 146 std::string opt = args(2).xstring_value ("qz: OPT must be a string"); |
8927
d75f4ee0538d
qz.cc (Fqz): avoid maybe clobbred by vfork warning from GCC
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
147 |
24116
e1020353fff5
qz: initialize optional ordering flag safely
Mike Miller <mtmiller@octave.org>
parents:
23826
diff
changeset
|
148 if (opt.empty ()) |
e1020353fff5
qz: initialize optional ordering flag safely
Mike Miller <mtmiller@octave.org>
parents:
23826
diff
changeset
|
149 error ("qz: OPT must be a non-empty string"); |
e1020353fff5
qz: initialize optional ordering flag safely
Mike Miller <mtmiller@octave.org>
parents:
23826
diff
changeset
|
150 |
31976
e6b24d0d485c
qz: Handle input and output arguments in a Matlab-compatible way.
Sébastien Villemot <sebastien@debian.org>
parents:
31827
diff
changeset
|
151 if (opt == "real") |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
152 { |
31976
e6b24d0d485c
qz: Handle input and output arguments in a Matlab-compatible way.
Sébastien Villemot <sebastien@debian.org>
parents:
31827
diff
changeset
|
153 if (args(0).iscomplex () || args(1).iscomplex ()) |
e6b24d0d485c
qz: Handle input and output arguments in a Matlab-compatible way.
Sébastien Villemot <sebastien@debian.org>
parents:
31827
diff
changeset
|
154 { |
e6b24d0d485c
qz: Handle input and output arguments in a Matlab-compatible way.
Sébastien Villemot <sebastien@debian.org>
parents:
31827
diff
changeset
|
155 warning ("qz: ignoring 'real' option with complex matrices"); |
e6b24d0d485c
qz: Handle input and output arguments in a Matlab-compatible way.
Sébastien Villemot <sebastien@debian.org>
parents:
31827
diff
changeset
|
156 complex_case = true; |
e6b24d0d485c
qz: Handle input and output arguments in a Matlab-compatible way.
Sébastien Villemot <sebastien@debian.org>
parents:
31827
diff
changeset
|
157 } |
e6b24d0d485c
qz: Handle input and output arguments in a Matlab-compatible way.
Sébastien Villemot <sebastien@debian.org>
parents:
31827
diff
changeset
|
158 else |
e6b24d0d485c
qz: Handle input and output arguments in a Matlab-compatible way.
Sébastien Villemot <sebastien@debian.org>
parents:
31827
diff
changeset
|
159 complex_case = false; |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
160 } |
31976
e6b24d0d485c
qz: Handle input and output arguments in a Matlab-compatible way.
Sébastien Villemot <sebastien@debian.org>
parents:
31827
diff
changeset
|
161 else if (opt == "complex") |
e6b24d0d485c
qz: Handle input and output arguments in a Matlab-compatible way.
Sébastien Villemot <sebastien@debian.org>
parents:
31827
diff
changeset
|
162 complex_case = true; |
e6b24d0d485c
qz: Handle input and output arguments in a Matlab-compatible way.
Sébastien Villemot <sebastien@debian.org>
parents:
31827
diff
changeset
|
163 else |
e6b24d0d485c
qz: Handle input and output arguments in a Matlab-compatible way.
Sébastien Villemot <sebastien@debian.org>
parents:
31827
diff
changeset
|
164 error ("qz: OPT must be real or complex"); |
3183 | 165 } |
166 | |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21562
diff
changeset
|
167 #if defined (DEBUG) |
26001
acb4689aa5f2
* qz.cc: Use octave_stdout instead of std::cout for debugging messages.
John W. Eaton <jwe@octave.org>
parents:
25734
diff
changeset
|
168 octave_stdout << "qz: check matrix A" << std::endl; |
3185 | 169 #endif |
170 | |
23430 | 171 // Matrix A: check dimensions. |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
172 F77_INT nn = to_f77_int (args(0).rows ()); |
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
173 F77_INT nc = to_f77_int (args(0).columns ()); |
20892 | 174 |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21562
diff
changeset
|
175 #if defined (DEBUG) |
26001
acb4689aa5f2
* qz.cc: Use octave_stdout instead of std::cout for debugging messages.
John W. Eaton <jwe@octave.org>
parents:
25734
diff
changeset
|
176 octave_stdout << "Matrix A dimensions: (" << nn << ',' << nc << ')' |
acb4689aa5f2
* qz.cc: Use octave_stdout instead of std::cout for debugging messages.
John W. Eaton <jwe@octave.org>
parents:
25734
diff
changeset
|
177 << std::endl; |
3185 | 178 #endif |
179 | |
31976
e6b24d0d485c
qz: Handle input and output arguments in a Matlab-compatible way.
Sébastien Villemot <sebastien@debian.org>
parents:
31827
diff
changeset
|
180 if (nc != nn) |
21110
3d0d84305600
Use err_square_matrix_required more widely.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
181 err_square_matrix_required ("qz", "A"); |
3183 | 182 |
23430 | 183 // Matrix A: get value. |
3183 | 184 Matrix aa; |
185 ComplexMatrix caa; | |
3185 | 186 |
23581
c3075ae020e1
maint: Deprecate is_complex_type and replace with iscomplex.
Rik <rik@octave.org>
parents:
23577
diff
changeset
|
187 if (args(0).iscomplex ()) |
3183 | 188 caa = args(0).complex_matrix_value (); |
3185 | 189 else |
3183 | 190 aa = args(0).matrix_value (); |
3185 | 191 |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21562
diff
changeset
|
192 #if defined (DEBUG) |
26001
acb4689aa5f2
* qz.cc: Use octave_stdout instead of std::cout for debugging messages.
John W. Eaton <jwe@octave.org>
parents:
25734
diff
changeset
|
193 octave_stdout << "qz: check matrix B" << std::endl; |
3185 | 194 #endif |
3183 | 195 |
10311 | 196 // Extract argument 2 (bb, or cbb if complex). |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
197 F77_INT b_nr = to_f77_int (args(1).rows ()); |
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
198 F77_INT b_nc = to_f77_int (args(1).columns ()); |
22964
0c12642be005
use F77_INT instead of octave_idx_type for libinterp QZ function
John W. Eaton <jwe@octave.org>
parents:
22860
diff
changeset
|
199 |
0c12642be005
use F77_INT instead of octave_idx_type for libinterp QZ function
John W. Eaton <jwe@octave.org>
parents:
22860
diff
changeset
|
200 if (nn != b_nc || nn != b_nr) |
29958
32c3a5805893
move DEFUN and DEFMETHOD functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29558
diff
changeset
|
201 ::err_nonconformant (); |
3185 | 202 |
3183 | 203 Matrix bb; |
204 ComplexMatrix cbb; | |
3185 | 205 |
23581
c3075ae020e1
maint: Deprecate is_complex_type and replace with iscomplex.
Rik <rik@octave.org>
parents:
23577
diff
changeset
|
206 if (args(1).iscomplex ()) |
3183 | 207 cbb = args(1).complex_matrix_value (); |
208 else | |
209 bb = args(1).matrix_value (); | |
3185 | 210 |
23430 | 211 // First, declare variables used in both the real and complex cases. |
212 // FIXME: There are a lot of excess variables declared. | |
213 // Probably a better way to handle this. | |
30390
a61e1a0f6024
maint: style check C++ files in libinterp/ ahead of 7.1 release.
Rik <rik@octave.org>
parents:
29961
diff
changeset
|
214 Matrix QQ (nn, nn), ZZ (nn, nn), VR (nn, nn), VL (nn, nn); |
23430 | 215 RowVector alphar (nn), alphai (nn), betar (nn); |
216 ComplexRowVector xalpha (nn), xbeta (nn); | |
30390
a61e1a0f6024
maint: style check C++ files in libinterp/ ahead of 7.1 release.
Rik <rik@octave.org>
parents:
29961
diff
changeset
|
217 ComplexMatrix CQ (nn, nn), CZ (nn, nn), CVR (nn, nn), CVL (nn, nn); |
22964
0c12642be005
use F77_INT instead of octave_idx_type for libinterp QZ function
John W. Eaton <jwe@octave.org>
parents:
22860
diff
changeset
|
218 F77_INT ilo, ihi, info; |
23430 | 219 char comp_q = (nargout >= 3 ? 'V' : 'N'); |
31976
e6b24d0d485c
qz: Handle input and output arguments in a Matlab-compatible way.
Sébastien Villemot <sebastien@debian.org>
parents:
31827
diff
changeset
|
220 char comp_z = (nargout >= 4 ? 'V' : 'N'); |
3183 | 221 |
23430 | 222 // Initialize Q, Z to identity matrix if either is needed |
223 if (comp_q == 'V' || comp_z == 'V') | |
224 { | |
23477
3530b956d707
maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
225 double *QQptr = QQ.fortran_vec (); |
3530b956d707
maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
226 double *ZZptr = ZZ.fortran_vec (); |
23430 | 227 std::fill_n (QQptr, QQ.numel (), 0.0); |
228 std::fill_n (ZZptr, ZZ.numel (), 0.0); | |
229 for (F77_INT i = 0; i < nn; i++) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
230 { |
30390
a61e1a0f6024
maint: style check C++ files in libinterp/ ahead of 7.1 release.
Rik <rik@octave.org>
parents:
29961
diff
changeset
|
231 QQ(i, i) = 1.0; |
a61e1a0f6024
maint: style check C++ files in libinterp/ ahead of 7.1 release.
Rik <rik@octave.org>
parents:
29961
diff
changeset
|
232 ZZ(i, i) = 1.0; |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
233 } |
23430 | 234 } |
3183 | 235 |
10311 | 236 // Always perform permutation balancing. |
4552 | 237 const char bal_job = 'P'; |
10311 | 238 RowVector lscale (nn), rscale (nn), work (6 * nn), rwork (nn); |
3183 | 239 |
3185 | 240 if (complex_case) |
241 { | |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21562
diff
changeset
|
242 #if defined (DEBUG) |
23430 | 243 if (comp_q == 'V') |
26001
acb4689aa5f2
* qz.cc: Use octave_stdout instead of std::cout for debugging messages.
John W. Eaton <jwe@octave.org>
parents:
25734
diff
changeset
|
244 octave_stdout << "qz: performing balancing; CQ =\n" << CQ << std::endl; |
10307
4e4270ab70d6
support complex case in qz
Jyh-miin Lin <jyhmiinlin@gmail.com>
parents:
10155
diff
changeset
|
245 #endif |
23582
0cc2011d800e
maint: Deprecate is_real_type and replace with isreal.
Rik <rik@octave.org>
parents:
23581
diff
changeset
|
246 if (args(0).isreal ()) |
10311 | 247 caa = ComplexMatrix (aa); |
10307
4e4270ab70d6
support complex case in qz
Jyh-miin Lin <jyhmiinlin@gmail.com>
parents:
10155
diff
changeset
|
248 |
23582
0cc2011d800e
maint: Deprecate is_real_type and replace with isreal.
Rik <rik@octave.org>
parents:
23581
diff
changeset
|
249 if (args(1).isreal ()) |
10311 | 250 cbb = ComplexMatrix (bb); |
10307
4e4270ab70d6
support complex case in qz
Jyh-miin Lin <jyhmiinlin@gmail.com>
parents:
10155
diff
changeset
|
251 |
23430 | 252 if (comp_q == 'V') |
10311 | 253 CQ = ComplexMatrix (QQ); |
10307
4e4270ab70d6
support complex case in qz
Jyh-miin Lin <jyhmiinlin@gmail.com>
parents:
10155
diff
changeset
|
254 |
23430 | 255 if (comp_z == 'V') |
10311 | 256 CZ = ComplexMatrix (ZZ); |
10307
4e4270ab70d6
support complex case in qz
Jyh-miin Lin <jyhmiinlin@gmail.com>
parents:
10155
diff
changeset
|
257 |
10311 | 258 F77_XFCN (zggbal, ZGGBAL, |
259 (F77_CONST_CHAR_ARG2 (&bal_job, 1), | |
22407
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22372
diff
changeset
|
260 nn, F77_DBLE_CMPLX_ARG (caa.fortran_vec ()), nn, |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22372
diff
changeset
|
261 F77_DBLE_CMPLX_ARG (cbb.fortran_vec ()), |
10311 | 262 nn, ilo, ihi, lscale.fortran_vec (), |
263 rscale.fortran_vec (), work.fortran_vec (), info | |
264 F77_CHAR_ARG_LEN (1))); | |
3185 | 265 } |
3183 | 266 else |
3185 | 267 { |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21562
diff
changeset
|
268 #if defined (DEBUG) |
23430 | 269 if (comp_q == 'V') |
26001
acb4689aa5f2
* qz.cc: Use octave_stdout instead of std::cout for debugging messages.
John W. Eaton <jwe@octave.org>
parents:
25734
diff
changeset
|
270 octave_stdout << "qz: performing balancing; QQ =\n" << QQ << std::endl; |
3185 | 271 #endif |
3183 | 272 |
3185 | 273 F77_XFCN (dggbal, DGGBAL, |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
274 (F77_CONST_CHAR_ARG2 (&bal_job, 1), |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
275 nn, aa.fortran_vec (), nn, bb.fortran_vec (), |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
276 nn, ilo, ihi, lscale.fortran_vec (), |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
277 rscale.fortran_vec (), work.fortran_vec (), info |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
278 F77_CHAR_ARG_LEN (1))); |
3185 | 279 } |
3183 | 280 |
23430 | 281 // Only permutation balance above is done. Skip scaling balance. |
282 | |
283 char qz_job = (nargout < 2 ? 'E' : 'S'); | |
3185 | 284 |
3183 | 285 if (complex_case) |
3185 | 286 { |
10311 | 287 // Complex case. |
288 | |
289 // The QR decomposition of cbb. | |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
290 math::qr<ComplexMatrix> cbqr (cbb); |
10311 | 291 // The R matrix of QR decomposition for cbb. |
292 cbb = cbqr.R (); | |
293 // (Q*)caa for following work. | |
294 caa = (cbqr.Q ().hermitian ()) * caa; | |
295 CQ = CQ * cbqr.Q (); | |
296 | |
10307
4e4270ab70d6
support complex case in qz
Jyh-miin Lin <jyhmiinlin@gmail.com>
parents:
10155
diff
changeset
|
297 F77_XFCN (zgghrd, ZGGHRD, |
23430 | 298 (F77_CONST_CHAR_ARG2 (&comp_q, 1), |
299 F77_CONST_CHAR_ARG2 (&comp_z, 1), | |
22135
407c66ae1e20
reduce warnings from GCC's link-time optimization feature (bug #48531)
John W. Eaton <jwe@octave.org>
parents:
22133
diff
changeset
|
300 nn, ilo, ihi, F77_DBLE_CMPLX_ARG (caa.fortran_vec ()), |
22407
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22372
diff
changeset
|
301 nn, F77_DBLE_CMPLX_ARG (cbb.fortran_vec ()), nn, |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22372
diff
changeset
|
302 F77_DBLE_CMPLX_ARG (CQ.fortran_vec ()), nn, |
22135
407c66ae1e20
reduce warnings from GCC's link-time optimization feature (bug #48531)
John W. Eaton <jwe@octave.org>
parents:
22133
diff
changeset
|
303 F77_DBLE_CMPLX_ARG (CZ.fortran_vec ()), nn, info |
10307
4e4270ab70d6
support complex case in qz
Jyh-miin Lin <jyhmiinlin@gmail.com>
parents:
10155
diff
changeset
|
304 F77_CHAR_ARG_LEN (1) |
4e4270ab70d6
support complex case in qz
Jyh-miin Lin <jyhmiinlin@gmail.com>
parents:
10155
diff
changeset
|
305 F77_CHAR_ARG_LEN (1))); |
10311 | 306 |
23430 | 307 ComplexRowVector cwork (nn); |
10311 | 308 |
10307
4e4270ab70d6
support complex case in qz
Jyh-miin Lin <jyhmiinlin@gmail.com>
parents:
10155
diff
changeset
|
309 F77_XFCN (zhgeqz, ZHGEQZ, |
4e4270ab70d6
support complex case in qz
Jyh-miin Lin <jyhmiinlin@gmail.com>
parents:
10155
diff
changeset
|
310 (F77_CONST_CHAR_ARG2 (&qz_job, 1), |
23430 | 311 F77_CONST_CHAR_ARG2 (&comp_q, 1), |
312 F77_CONST_CHAR_ARG2 (&comp_z, 1), | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
313 nn, ilo, ihi, |
22135
407c66ae1e20
reduce warnings from GCC's link-time optimization feature (bug #48531)
John W. Eaton <jwe@octave.org>
parents:
22133
diff
changeset
|
314 F77_DBLE_CMPLX_ARG (caa.fortran_vec ()), nn, |
407c66ae1e20
reduce warnings from GCC's link-time optimization feature (bug #48531)
John W. Eaton <jwe@octave.org>
parents:
22133
diff
changeset
|
315 F77_DBLE_CMPLX_ARG (cbb.fortran_vec ()), nn, |
407c66ae1e20
reduce warnings from GCC's link-time optimization feature (bug #48531)
John W. Eaton <jwe@octave.org>
parents:
22133
diff
changeset
|
316 F77_DBLE_CMPLX_ARG (xalpha.fortran_vec ()), |
407c66ae1e20
reduce warnings from GCC's link-time optimization feature (bug #48531)
John W. Eaton <jwe@octave.org>
parents:
22133
diff
changeset
|
317 F77_DBLE_CMPLX_ARG (xbeta.fortran_vec ()), |
407c66ae1e20
reduce warnings from GCC's link-time optimization feature (bug #48531)
John W. Eaton <jwe@octave.org>
parents:
22133
diff
changeset
|
318 F77_DBLE_CMPLX_ARG (CQ.fortran_vec ()), nn, |
407c66ae1e20
reduce warnings from GCC's link-time optimization feature (bug #48531)
John W. Eaton <jwe@octave.org>
parents:
22133
diff
changeset
|
319 F77_DBLE_CMPLX_ARG (CZ.fortran_vec ()), nn, |
23430 | 320 F77_DBLE_CMPLX_ARG (cwork.fortran_vec ()), nn, |
25103
078b795c5219
maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
321 rwork.fortran_vec (), info |
10307
4e4270ab70d6
support complex case in qz
Jyh-miin Lin <jyhmiinlin@gmail.com>
parents:
10155
diff
changeset
|
322 F77_CHAR_ARG_LEN (1) |
4e4270ab70d6
support complex case in qz
Jyh-miin Lin <jyhmiinlin@gmail.com>
parents:
10155
diff
changeset
|
323 F77_CHAR_ARG_LEN (1) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
324 F77_CHAR_ARG_LEN (1))); |
3185 | 325 |
23430 | 326 if (comp_q == 'V') |
10307
4e4270ab70d6
support complex case in qz
Jyh-miin Lin <jyhmiinlin@gmail.com>
parents:
10155
diff
changeset
|
327 { |
10311 | 328 // Left eigenvector. |
10307
4e4270ab70d6
support complex case in qz
Jyh-miin Lin <jyhmiinlin@gmail.com>
parents:
10155
diff
changeset
|
329 F77_XFCN (zggbak, ZGGBAK, |
4e4270ab70d6
support complex case in qz
Jyh-miin Lin <jyhmiinlin@gmail.com>
parents:
10155
diff
changeset
|
330 (F77_CONST_CHAR_ARG2 (&bal_job, 1), |
4e4270ab70d6
support complex case in qz
Jyh-miin Lin <jyhmiinlin@gmail.com>
parents:
10155
diff
changeset
|
331 F77_CONST_CHAR_ARG2 ("L", 1), |
4e4270ab70d6
support complex case in qz
Jyh-miin Lin <jyhmiinlin@gmail.com>
parents:
10155
diff
changeset
|
332 nn, ilo, ihi, lscale.data (), rscale.data (), |
22135
407c66ae1e20
reduce warnings from GCC's link-time optimization feature (bug #48531)
John W. Eaton <jwe@octave.org>
parents:
22133
diff
changeset
|
333 nn, F77_DBLE_CMPLX_ARG (CQ.fortran_vec ()), nn, info |
10307
4e4270ab70d6
support complex case in qz
Jyh-miin Lin <jyhmiinlin@gmail.com>
parents:
10155
diff
changeset
|
334 F77_CHAR_ARG_LEN (1) |
4e4270ab70d6
support complex case in qz
Jyh-miin Lin <jyhmiinlin@gmail.com>
parents:
10155
diff
changeset
|
335 F77_CHAR_ARG_LEN (1))); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
336 } |
3185 | 337 |
23430 | 338 if (comp_z == 'V') |
10307
4e4270ab70d6
support complex case in qz
Jyh-miin Lin <jyhmiinlin@gmail.com>
parents:
10155
diff
changeset
|
339 { |
23430 | 340 // Right eigenvector. |
10307
4e4270ab70d6
support complex case in qz
Jyh-miin Lin <jyhmiinlin@gmail.com>
parents:
10155
diff
changeset
|
341 F77_XFCN (zggbak, ZGGBAK, |
4e4270ab70d6
support complex case in qz
Jyh-miin Lin <jyhmiinlin@gmail.com>
parents:
10155
diff
changeset
|
342 (F77_CONST_CHAR_ARG2 (&bal_job, 1), |
4e4270ab70d6
support complex case in qz
Jyh-miin Lin <jyhmiinlin@gmail.com>
parents:
10155
diff
changeset
|
343 F77_CONST_CHAR_ARG2 ("R", 1), |
4e4270ab70d6
support complex case in qz
Jyh-miin Lin <jyhmiinlin@gmail.com>
parents:
10155
diff
changeset
|
344 nn, ilo, ihi, lscale.data (), rscale.data (), |
22135
407c66ae1e20
reduce warnings from GCC's link-time optimization feature (bug #48531)
John W. Eaton <jwe@octave.org>
parents:
22133
diff
changeset
|
345 nn, F77_DBLE_CMPLX_ARG (CZ.fortran_vec ()), nn, info |
10307
4e4270ab70d6
support complex case in qz
Jyh-miin Lin <jyhmiinlin@gmail.com>
parents:
10155
diff
changeset
|
346 F77_CHAR_ARG_LEN (1) |
4e4270ab70d6
support complex case in qz
Jyh-miin Lin <jyhmiinlin@gmail.com>
parents:
10155
diff
changeset
|
347 F77_CHAR_ARG_LEN (1))); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
348 } |
3185 | 349 |
350 } | |
10311 | 351 else |
3185 | 352 { |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21562
diff
changeset
|
353 #if defined (DEBUG) |
26001
acb4689aa5f2
* qz.cc: Use octave_stdout instead of std::cout for debugging messages.
John W. Eaton <jwe@octave.org>
parents:
25734
diff
changeset
|
354 octave_stdout << "qz: performing qr decomposition of bb" << std::endl; |
3185 | 355 #endif |
3183 | 356 |
10311 | 357 // Compute the QR factorization of bb. |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
358 math::qr<Matrix> bqr (bb); |
3185 | 359 |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21562
diff
changeset
|
360 #if defined (DEBUG) |
26001
acb4689aa5f2
* qz.cc: Use octave_stdout instead of std::cout for debugging messages.
John W. Eaton <jwe@octave.org>
parents:
25734
diff
changeset
|
361 octave_stdout << "qz: qr (bb) done; now performing qz decomposition" |
acb4689aa5f2
* qz.cc: Use octave_stdout instead of std::cout for debugging messages.
John W. Eaton <jwe@octave.org>
parents:
25734
diff
changeset
|
362 << std::endl; |
3185 | 363 #endif |
3183 | 364 |
3185 | 365 bb = bqr.R (); |
366 | |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21562
diff
changeset
|
367 #if defined (DEBUG) |
26001
acb4689aa5f2
* qz.cc: Use octave_stdout instead of std::cout for debugging messages.
John W. Eaton <jwe@octave.org>
parents:
25734
diff
changeset
|
368 octave_stdout << "qz: extracted bb" << std::endl; |
3185 | 369 #endif |
3183 | 370 |
10311 | 371 aa = (bqr.Q ()).transpose () * aa; |
3185 | 372 |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21562
diff
changeset
|
373 #if defined (DEBUG) |
26001
acb4689aa5f2
* qz.cc: Use octave_stdout instead of std::cout for debugging messages.
John W. Eaton <jwe@octave.org>
parents:
25734
diff
changeset
|
374 octave_stdout << "qz: updated aa " << std::endl; |
acb4689aa5f2
* qz.cc: Use octave_stdout instead of std::cout for debugging messages.
John W. Eaton <jwe@octave.org>
parents:
25734
diff
changeset
|
375 octave_stdout << "bqr.Q () =\n" << bqr.Q () << std::endl; |
3183 | 376 |
23430 | 377 if (comp_q == 'V') |
26001
acb4689aa5f2
* qz.cc: Use octave_stdout instead of std::cout for debugging messages.
John W. Eaton <jwe@octave.org>
parents:
25734
diff
changeset
|
378 octave_stdout << "QQ =" << QQ << std::endl; |
3185 | 379 #endif |
3183 | 380 |
23430 | 381 if (comp_q == 'V') |
10311 | 382 QQ = QQ * bqr.Q (); |
3183 | 383 |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21562
diff
changeset
|
384 #if defined (DEBUG) |
26001
acb4689aa5f2
* qz.cc: Use octave_stdout instead of std::cout for debugging messages.
John W. Eaton <jwe@octave.org>
parents:
25734
diff
changeset
|
385 octave_stdout << "qz: precursors done..." << std::endl; |
3185 | 386 #endif |
3183 | 387 |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21562
diff
changeset
|
388 #if defined (DEBUG) |
26001
acb4689aa5f2
* qz.cc: Use octave_stdout instead of std::cout for debugging messages.
John W. Eaton <jwe@octave.org>
parents:
25734
diff
changeset
|
389 octave_stdout << "qz: comp_q = " << comp_q << ", comp_z = " << comp_z |
acb4689aa5f2
* qz.cc: Use octave_stdout instead of std::cout for debugging messages.
John W. Eaton <jwe@octave.org>
parents:
25734
diff
changeset
|
390 << std::endl; |
3185 | 391 #endif |
3183 | 392 |
21562
6c2fd62db1f7
maint: Eliminate accidental double spaces in code.
Rik <rik@octave.org>
parents:
21301
diff
changeset
|
393 // Reduce to generalized Hessenberg form. |
3185 | 394 F77_XFCN (dgghrd, DGGHRD, |
23430 | 395 (F77_CONST_CHAR_ARG2 (&comp_q, 1), |
396 F77_CONST_CHAR_ARG2 (&comp_z, 1), | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
397 nn, ilo, ihi, aa.fortran_vec (), |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
398 nn, bb.fortran_vec (), nn, QQ.fortran_vec (), nn, |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
399 ZZ.fortran_vec (), nn, info |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
400 F77_CHAR_ARG_LEN (1) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
401 F77_CHAR_ARG_LEN (1))); |
3183 | 402 |
23430 | 403 // Check if just computing generalized eigenvalues, |
404 // or if we're actually computing the decomposition. | |
3183 | 405 |
10311 | 406 // Reduce to generalized Schur form. |
3185 | 407 F77_XFCN (dhgeqz, DHGEQZ, |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
408 (F77_CONST_CHAR_ARG2 (&qz_job, 1), |
23430 | 409 F77_CONST_CHAR_ARG2 (&comp_q, 1), |
410 F77_CONST_CHAR_ARG2 (&comp_z, 1), | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
411 nn, ilo, ihi, aa.fortran_vec (), nn, bb.fortran_vec (), |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
412 nn, alphar.fortran_vec (), alphai.fortran_vec (), |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
413 betar.fortran_vec (), QQ.fortran_vec (), nn, |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
414 ZZ.fortran_vec (), nn, work.fortran_vec (), nn, info |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
415 F77_CHAR_ARG_LEN (1) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
416 F77_CHAR_ARG_LEN (1) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
417 F77_CHAR_ARG_LEN (1))); |
10311 | 418 |
23430 | 419 if (comp_q == 'V') |
10311 | 420 { |
421 F77_XFCN (dggbak, DGGBAK, | |
422 (F77_CONST_CHAR_ARG2 (&bal_job, 1), | |
423 F77_CONST_CHAR_ARG2 ("L", 1), | |
424 nn, ilo, ihi, lscale.data (), rscale.data (), | |
425 nn, QQ.fortran_vec (), nn, info | |
426 F77_CHAR_ARG_LEN (1) | |
427 F77_CHAR_ARG_LEN (1))); | |
10307
4e4270ab70d6
support complex case in qz
Jyh-miin Lin <jyhmiinlin@gmail.com>
parents:
10155
diff
changeset
|
428 |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21562
diff
changeset
|
429 #if defined (DEBUG) |
23430 | 430 if (comp_q == 'V') |
26001
acb4689aa5f2
* qz.cc: Use octave_stdout instead of std::cout for debugging messages.
John W. Eaton <jwe@octave.org>
parents:
25734
diff
changeset
|
431 octave_stdout << "qz: balancing done; QQ=\n" << QQ << std::endl; |
10307
4e4270ab70d6
support complex case in qz
Jyh-miin Lin <jyhmiinlin@gmail.com>
parents:
10155
diff
changeset
|
432 #endif |
4e4270ab70d6
support complex case in qz
Jyh-miin Lin <jyhmiinlin@gmail.com>
parents:
10155
diff
changeset
|
433 } |
4e4270ab70d6
support complex case in qz
Jyh-miin Lin <jyhmiinlin@gmail.com>
parents:
10155
diff
changeset
|
434 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
435 // then right |
23430 | 436 if (comp_z == 'V') |
10307
4e4270ab70d6
support complex case in qz
Jyh-miin Lin <jyhmiinlin@gmail.com>
parents:
10155
diff
changeset
|
437 { |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
438 F77_XFCN (dggbak, DGGBAK, |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
439 (F77_CONST_CHAR_ARG2 (&bal_job, 1), |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
440 F77_CONST_CHAR_ARG2 ("R", 1), |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
441 nn, ilo, ihi, lscale.data (), rscale.data (), |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
442 nn, ZZ.fortran_vec (), nn, info |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
443 F77_CHAR_ARG_LEN (1) |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
444 F77_CHAR_ARG_LEN (1))); |
10307
4e4270ab70d6
support complex case in qz
Jyh-miin Lin <jyhmiinlin@gmail.com>
parents:
10155
diff
changeset
|
445 |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21562
diff
changeset
|
446 #if defined (DEBUG) |
23430 | 447 if (comp_z == 'V') |
26001
acb4689aa5f2
* qz.cc: Use octave_stdout instead of std::cout for debugging messages.
John W. Eaton <jwe@octave.org>
parents:
25734
diff
changeset
|
448 octave_stdout << "qz: balancing done; ZZ=\n" << ZZ << std::endl; |
10307
4e4270ab70d6
support complex case in qz
Jyh-miin Lin <jyhmiinlin@gmail.com>
parents:
10155
diff
changeset
|
449 #endif |
4e4270ab70d6
support complex case in qz
Jyh-miin Lin <jyhmiinlin@gmail.com>
parents:
10155
diff
changeset
|
450 } |
4e4270ab70d6
support complex case in qz
Jyh-miin Lin <jyhmiinlin@gmail.com>
parents:
10155
diff
changeset
|
451 |
3185 | 452 } |
3183 | 453 |
10311 | 454 // Right, left eigenvector matrices. |
3185 | 455 if (nargout >= 5) |
3183 | 456 { |
10311 | 457 // Which side to compute? |
458 char side = (nargout == 5 ? 'R' : 'B'); | |
459 // Compute all of them and backtransform | |
23430 | 460 char howmany = 'B'; |
10311 | 461 // Dummy pointer; select is not used. |
23457
21baad6b35c4
maint: Use C++11 nullptr rather than 0 or NULL when possible.
Rik <rik@octave.org>
parents:
23449
diff
changeset
|
462 F77_INT *select = nullptr; |
3185 | 463 |
464 if (complex_case) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
465 { |
10311 | 466 CVL = CQ; |
467 CVR = CZ; | |
468 ComplexRowVector cwork2 (2 * nn); | |
469 RowVector rwork2 (8 * nn); | |
22964
0c12642be005
use F77_INT instead of octave_idx_type for libinterp QZ function
John W. Eaton <jwe@octave.org>
parents:
22860
diff
changeset
|
470 F77_INT m; |
10307
4e4270ab70d6
support complex case in qz
Jyh-miin Lin <jyhmiinlin@gmail.com>
parents:
10155
diff
changeset
|
471 |
10311 | 472 F77_XFCN (ztgevc, ZTGEVC, |
473 (F77_CONST_CHAR_ARG2 (&side, 1), | |
23430 | 474 F77_CONST_CHAR_ARG2 (&howmany, 1), |
22407
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22372
diff
changeset
|
475 select, nn, F77_DBLE_CMPLX_ARG (caa.fortran_vec ()), nn, |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22372
diff
changeset
|
476 F77_DBLE_CMPLX_ARG (cbb.fortran_vec ()), |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22372
diff
changeset
|
477 nn, F77_DBLE_CMPLX_ARG (CVL.fortran_vec ()), nn, |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22372
diff
changeset
|
478 F77_DBLE_CMPLX_ARG (CVR.fortran_vec ()), nn, nn, |
23430 | 479 m, F77_DBLE_CMPLX_ARG (cwork2.fortran_vec ()), |
480 rwork2.fortran_vec (), info | |
10311 | 481 F77_CHAR_ARG_LEN (1) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
482 F77_CHAR_ARG_LEN (1))); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
483 } |
3185 | 484 else |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
485 { |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21562
diff
changeset
|
486 #if defined (DEBUG) |
26001
acb4689aa5f2
* qz.cc: Use octave_stdout instead of std::cout for debugging messages.
John W. Eaton <jwe@octave.org>
parents:
25734
diff
changeset
|
487 octave_stdout << "qz: computing generalized eigenvectors" << std::endl; |
3185 | 488 #endif |
489 | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
490 VL = QQ; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
491 VR = ZZ; |
22964
0c12642be005
use F77_INT instead of octave_idx_type for libinterp QZ function
John W. Eaton <jwe@octave.org>
parents:
22860
diff
changeset
|
492 F77_INT m; |
10311 | 493 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
494 F77_XFCN (dtgevc, DTGEVC, |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
495 (F77_CONST_CHAR_ARG2 (&side, 1), |
23430 | 496 F77_CONST_CHAR_ARG2 (&howmany, 1), |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
497 select, nn, aa.fortran_vec (), nn, bb.fortran_vec (), |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
498 nn, VL.fortran_vec (), nn, VR.fortran_vec (), nn, nn, |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
499 m, work.fortran_vec (), info |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
500 F77_CHAR_ARG_LEN (1) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
501 F77_CHAR_ARG_LEN (1))); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
502 } |
3183 | 503 } |
3185 | 504 |
23430 | 505 octave_value_list retval (nargout); |
506 | |
3185 | 507 switch (nargout) |
508 { | |
10311 | 509 case 6: |
23430 | 510 // Return left eigenvectors. |
31976
e6b24d0d485c
qz: Handle input and output arguments in a Matlab-compatible way.
Sébastien Villemot <sebastien@debian.org>
parents:
31827
diff
changeset
|
511 if (complex_case) |
e6b24d0d485c
qz: Handle input and output arguments in a Matlab-compatible way.
Sébastien Villemot <sebastien@debian.org>
parents:
31827
diff
changeset
|
512 retval(5) = CVL; |
e6b24d0d485c
qz: Handle input and output arguments in a Matlab-compatible way.
Sébastien Villemot <sebastien@debian.org>
parents:
31827
diff
changeset
|
513 else |
e6b24d0d485c
qz: Handle input and output arguments in a Matlab-compatible way.
Sébastien Villemot <sebastien@debian.org>
parents:
31827
diff
changeset
|
514 retval(5) = VL; |
23826
d69021d58a61
avoid fallthrough warnings
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
515 OCTAVE_FALLTHROUGH; |
3185 | 516 |
10311 | 517 case 5: |
23430 | 518 // Return right eigenvectors. |
31976
e6b24d0d485c
qz: Handle input and output arguments in a Matlab-compatible way.
Sébastien Villemot <sebastien@debian.org>
parents:
31827
diff
changeset
|
519 if (complex_case) |
e6b24d0d485c
qz: Handle input and output arguments in a Matlab-compatible way.
Sébastien Villemot <sebastien@debian.org>
parents:
31827
diff
changeset
|
520 retval(4) = CVR; |
e6b24d0d485c
qz: Handle input and output arguments in a Matlab-compatible way.
Sébastien Villemot <sebastien@debian.org>
parents:
31827
diff
changeset
|
521 else |
e6b24d0d485c
qz: Handle input and output arguments in a Matlab-compatible way.
Sébastien Villemot <sebastien@debian.org>
parents:
31827
diff
changeset
|
522 retval(4) = VR; |
23826
d69021d58a61
avoid fallthrough warnings
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
523 OCTAVE_FALLTHROUGH; |
3185 | 524 |
525 case 4: | |
31976
e6b24d0d485c
qz: Handle input and output arguments in a Matlab-compatible way.
Sébastien Villemot <sebastien@debian.org>
parents:
31827
diff
changeset
|
526 if (complex_case) |
e6b24d0d485c
qz: Handle input and output arguments in a Matlab-compatible way.
Sébastien Villemot <sebastien@debian.org>
parents:
31827
diff
changeset
|
527 retval(3) = CZ; |
3185 | 528 else |
31976
e6b24d0d485c
qz: Handle input and output arguments in a Matlab-compatible way.
Sébastien Villemot <sebastien@debian.org>
parents:
31827
diff
changeset
|
529 retval(3) = ZZ; |
23826
d69021d58a61
avoid fallthrough warnings
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
530 OCTAVE_FALLTHROUGH; |
3185 | 531 |
532 case 3: | |
31976
e6b24d0d485c
qz: Handle input and output arguments in a Matlab-compatible way.
Sébastien Villemot <sebastien@debian.org>
parents:
31827
diff
changeset
|
533 if (complex_case) |
e6b24d0d485c
qz: Handle input and output arguments in a Matlab-compatible way.
Sébastien Villemot <sebastien@debian.org>
parents:
31827
diff
changeset
|
534 retval(2) = CQ.hermitian (); |
3185 | 535 else |
31976
e6b24d0d485c
qz: Handle input and output arguments in a Matlab-compatible way.
Sébastien Villemot <sebastien@debian.org>
parents:
31827
diff
changeset
|
536 retval(2) = QQ.transpose (); |
23826
d69021d58a61
avoid fallthrough warnings
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
537 OCTAVE_FALLTHROUGH; |
10311 | 538 |
3185 | 539 case 2: |
31976
e6b24d0d485c
qz: Handle input and output arguments in a Matlab-compatible way.
Sébastien Villemot <sebastien@debian.org>
parents:
31827
diff
changeset
|
540 case 1: |
e6b24d0d485c
qz: Handle input and output arguments in a Matlab-compatible way.
Sébastien Villemot <sebastien@debian.org>
parents:
31827
diff
changeset
|
541 case 0: |
10307
4e4270ab70d6
support complex case in qz
Jyh-miin Lin <jyhmiinlin@gmail.com>
parents:
10155
diff
changeset
|
542 { |
10311 | 543 if (complex_case) |
544 { | |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21562
diff
changeset
|
545 #if defined (DEBUG) |
26001
acb4689aa5f2
* qz.cc: Use octave_stdout instead of std::cout for debugging messages.
John W. Eaton <jwe@octave.org>
parents:
25734
diff
changeset
|
546 octave_stdout << "qz: retval(1) = cbb =\n"; |
acb4689aa5f2
* qz.cc: Use octave_stdout instead of std::cout for debugging messages.
John W. Eaton <jwe@octave.org>
parents:
25734
diff
changeset
|
547 octave_print_internal (octave_stdout, cbb); |
acb4689aa5f2
* qz.cc: Use octave_stdout instead of std::cout for debugging messages.
John W. Eaton <jwe@octave.org>
parents:
25734
diff
changeset
|
548 octave_stdout << "\nqz: retval(0) = caa =\n"; |
acb4689aa5f2
* qz.cc: Use octave_stdout instead of std::cout for debugging messages.
John W. Eaton <jwe@octave.org>
parents:
25734
diff
changeset
|
549 octave_print_internal (octave_stdout, caa); |
acb4689aa5f2
* qz.cc: Use octave_stdout instead of std::cout for debugging messages.
John W. Eaton <jwe@octave.org>
parents:
25734
diff
changeset
|
550 octave_stdout << std::endl; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
551 #endif |
10311 | 552 retval(1) = cbb; |
553 retval(0) = caa; | |
554 } | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
555 else |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
556 { |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21562
diff
changeset
|
557 #if defined (DEBUG) |
26001
acb4689aa5f2
* qz.cc: Use octave_stdout instead of std::cout for debugging messages.
John W. Eaton <jwe@octave.org>
parents:
25734
diff
changeset
|
558 octave_stdout << "qz: retval(1) = bb =\n"; |
acb4689aa5f2
* qz.cc: Use octave_stdout instead of std::cout for debugging messages.
John W. Eaton <jwe@octave.org>
parents:
25734
diff
changeset
|
559 octave_print_internal (octave_stdout, bb); |
acb4689aa5f2
* qz.cc: Use octave_stdout instead of std::cout for debugging messages.
John W. Eaton <jwe@octave.org>
parents:
25734
diff
changeset
|
560 octave_stdout << "\nqz: retval(0) = aa =\n"; |
acb4689aa5f2
* qz.cc: Use octave_stdout instead of std::cout for debugging messages.
John W. Eaton <jwe@octave.org>
parents:
25734
diff
changeset
|
561 octave_print_internal (octave_stdout, aa); |
acb4689aa5f2
* qz.cc: Use octave_stdout instead of std::cout for debugging messages.
John W. Eaton <jwe@octave.org>
parents:
25734
diff
changeset
|
562 octave_stdout << std::endl; |
3185 | 563 #endif |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
564 retval(1) = bb; |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
565 retval(0) = aa; |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
566 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
567 } |
10311 | 568 break; |
10307
4e4270ab70d6
support complex case in qz
Jyh-miin Lin <jyhmiinlin@gmail.com>
parents:
10155
diff
changeset
|
569 |
3185 | 570 default: |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
571 error ("qz: too many return arguments"); |
3185 | 572 break; |
25103
078b795c5219
maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
573 } |
3183 | 574 |
31976
e6b24d0d485c
qz: Handle input and output arguments in a Matlab-compatible way.
Sébastien Villemot <sebastien@debian.org>
parents:
31827
diff
changeset
|
575 if (nargout == 1) |
e6b24d0d485c
qz: Handle input and output arguments in a Matlab-compatible way.
Sébastien Villemot <sebastien@debian.org>
parents:
31827
diff
changeset
|
576 { |
e6b24d0d485c
qz: Handle input and output arguments in a Matlab-compatible way.
Sébastien Villemot <sebastien@debian.org>
parents:
31827
diff
changeset
|
577 warning_with_id ("Octave:qz:single-arg-out", |
e6b24d0d485c
qz: Handle input and output arguments in a Matlab-compatible way.
Sébastien Villemot <sebastien@debian.org>
parents:
31827
diff
changeset
|
578 "qz: requesting a single output argument no longer gives eigenvalues since version 9"); |
e6b24d0d485c
qz: Handle input and output arguments in a Matlab-compatible way.
Sébastien Villemot <sebastien@debian.org>
parents:
31827
diff
changeset
|
579 disable_warning ("Octave:qz:single-arg-out"); |
e6b24d0d485c
qz: Handle input and output arguments in a Matlab-compatible way.
Sébastien Villemot <sebastien@debian.org>
parents:
31827
diff
changeset
|
580 } |
e6b24d0d485c
qz: Handle input and output arguments in a Matlab-compatible way.
Sébastien Villemot <sebastien@debian.org>
parents:
31827
diff
changeset
|
581 |
e6b24d0d485c
qz: Handle input and output arguments in a Matlab-compatible way.
Sébastien Villemot <sebastien@debian.org>
parents:
31827
diff
changeset
|
582 if (nargin == 2 && args(0).isreal () && args(1).isreal () && retval(0).iscomplex ()) |
e6b24d0d485c
qz: Handle input and output arguments in a Matlab-compatible way.
Sébastien Villemot <sebastien@debian.org>
parents:
31827
diff
changeset
|
583 { |
e6b24d0d485c
qz: Handle input and output arguments in a Matlab-compatible way.
Sébastien Villemot <sebastien@debian.org>
parents:
31827
diff
changeset
|
584 warning_with_id ("Octave:qz:complex-default", |
e6b24d0d485c
qz: Handle input and output arguments in a Matlab-compatible way.
Sébastien Villemot <sebastien@debian.org>
parents:
31827
diff
changeset
|
585 "qz: returns the complex QZ by default on real matrices since version 9"); |
e6b24d0d485c
qz: Handle input and output arguments in a Matlab-compatible way.
Sébastien Villemot <sebastien@debian.org>
parents:
31827
diff
changeset
|
586 disable_warning ("Octave:qz:complex-default"); |
e6b24d0d485c
qz: Handle input and output arguments in a Matlab-compatible way.
Sébastien Villemot <sebastien@debian.org>
parents:
31827
diff
changeset
|
587 } |
e6b24d0d485c
qz: Handle input and output arguments in a Matlab-compatible way.
Sébastien Villemot <sebastien@debian.org>
parents:
31827
diff
changeset
|
588 |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21562
diff
changeset
|
589 #if defined (DEBUG) |
26001
acb4689aa5f2
* qz.cc: Use octave_stdout instead of std::cout for debugging messages.
John W. Eaton <jwe@octave.org>
parents:
25734
diff
changeset
|
590 octave_stdout << "qz: exiting (at long last)" << std::endl; |
3185 | 591 #endif |
3183 | 592 |
593 return retval; | |
594 } | |
13074
0b789a03bde1
codesprint: Add 3 tests for qz.cc
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12642
diff
changeset
|
595 |
0b789a03bde1
codesprint: Add 3 tests for qz.cc
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12642
diff
changeset
|
596 /* |
31976
e6b24d0d485c
qz: Handle input and output arguments in a Matlab-compatible way.
Sébastien Villemot <sebastien@debian.org>
parents:
31827
diff
changeset
|
597 ## Example 7.7.3 in Golub & Van Loan (3rd ed.; not present in 4th ed.) |
e6b24d0d485c
qz: Handle input and output arguments in a Matlab-compatible way.
Sébastien Villemot <sebastien@debian.org>
parents:
31827
diff
changeset
|
598 ## The generalized eigenvalues are real, so the real and complex QZ coincide. |
13074
0b789a03bde1
codesprint: Add 3 tests for qz.cc
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12642
diff
changeset
|
599 %!test |
0b789a03bde1
codesprint: Add 3 tests for qz.cc
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12642
diff
changeset
|
600 %! a = [ 10 1 2; |
0b789a03bde1
codesprint: Add 3 tests for qz.cc
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12642
diff
changeset
|
601 %! 1 2 -1; |
29556
d75aa2bf4915
qz.cc: return correct number of eigenvalues (bug #60357).
Rik <rik@octave.org>
parents:
29358
diff
changeset
|
602 %! 1 1 2 ]; |
d75aa2bf4915
qz.cc: return correct number of eigenvalues (bug #60357).
Rik <rik@octave.org>
parents:
29358
diff
changeset
|
603 %! b = reshape (1:9, 3,3); |
31976
e6b24d0d485c
qz: Handle input and output arguments in a Matlab-compatible way.
Sébastien Villemot <sebastien@debian.org>
parents:
31827
diff
changeset
|
604 %! [aa, bb, q, z, v, w] = qz (a, b); |
e6b24d0d485c
qz: Handle input and output arguments in a Matlab-compatible way.
Sébastien Villemot <sebastien@debian.org>
parents:
31827
diff
changeset
|
605 %! assert (isreal (aa) && isreal (bb) && isreal (q) && isreal (z) ... |
e6b24d0d485c
qz: Handle input and output arguments in a Matlab-compatible way.
Sébastien Villemot <sebastien@debian.org>
parents:
31827
diff
changeset
|
606 %! && isreal (v) && isreal (w)); |
e6b24d0d485c
qz: Handle input and output arguments in a Matlab-compatible way.
Sébastien Villemot <sebastien@debian.org>
parents:
31827
diff
changeset
|
607 %! assert (istriu (aa) && istriu (bb)); |
e6b24d0d485c
qz: Handle input and output arguments in a Matlab-compatible way.
Sébastien Villemot <sebastien@debian.org>
parents:
31827
diff
changeset
|
608 %! assert (q * q', eye(3), 1e-15); |
e6b24d0d485c
qz: Handle input and output arguments in a Matlab-compatible way.
Sébastien Villemot <sebastien@debian.org>
parents:
31827
diff
changeset
|
609 %! assert (z * z', eye(3), 1e-15); |
13088
4ffea87ad71b
codesprint: Fix tolerance for qz.cc tests.
Ben Abbott <bpabbott@mac.com>
parents:
13074
diff
changeset
|
610 %! assert (q * a * z, aa, norm (aa) * 1e-14); |
4ffea87ad71b
codesprint: Fix tolerance for qz.cc tests.
Ben Abbott <bpabbott@mac.com>
parents:
13074
diff
changeset
|
611 %! assert (q * b * z, bb, norm (bb) * 1e-14); |
31976
e6b24d0d485c
qz: Handle input and output arguments in a Matlab-compatible way.
Sébastien Villemot <sebastien@debian.org>
parents:
31827
diff
changeset
|
612 %! assert (a * v * diag (diag (bb)), b * v * diag (diag (aa)), 1e-13); |
e6b24d0d485c
qz: Handle input and output arguments in a Matlab-compatible way.
Sébastien Villemot <sebastien@debian.org>
parents:
31827
diff
changeset
|
613 %! assert (diag (diag (bb)) * w' * a, diag (diag (aa)) * w' * b, 1e-13); |
13074
0b789a03bde1
codesprint: Add 3 tests for qz.cc
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12642
diff
changeset
|
614 |
31976
e6b24d0d485c
qz: Handle input and output arguments in a Matlab-compatible way.
Sébastien Villemot <sebastien@debian.org>
parents:
31827
diff
changeset
|
615 ## An example with real matrices where some generalized eigenvalues are |
e6b24d0d485c
qz: Handle input and output arguments in a Matlab-compatible way.
Sébastien Villemot <sebastien@debian.org>
parents:
31827
diff
changeset
|
616 ## complex, so the real and complex QZ differ. |
25570
da2b38b7a077
Use LAPACK DTGSEN subrouting for ordered-qz computation (bug #53761)
Sébastien Villemot <sebastien@debian.org>
parents:
25106
diff
changeset
|
617 %!test |
da2b38b7a077
Use LAPACK DTGSEN subrouting for ordered-qz computation (bug #53761)
Sébastien Villemot <sebastien@debian.org>
parents:
25106
diff
changeset
|
618 %! A = [ -1.03428 0.24929 0.43205 -0.12860; |
da2b38b7a077
Use LAPACK DTGSEN subrouting for ordered-qz computation (bug #53761)
Sébastien Villemot <sebastien@debian.org>
parents:
25106
diff
changeset
|
619 %! 1.16228 0.27870 2.12954 0.69250; |
da2b38b7a077
Use LAPACK DTGSEN subrouting for ordered-qz computation (bug #53761)
Sébastien Villemot <sebastien@debian.org>
parents:
25106
diff
changeset
|
620 %! -0.51524 -0.34939 -0.77820 2.13721; |
da2b38b7a077
Use LAPACK DTGSEN subrouting for ordered-qz computation (bug #53761)
Sébastien Villemot <sebastien@debian.org>
parents:
25106
diff
changeset
|
621 %! -1.32941 2.11870 0.72005 1.00835 ]; |
da2b38b7a077
Use LAPACK DTGSEN subrouting for ordered-qz computation (bug #53761)
Sébastien Villemot <sebastien@debian.org>
parents:
25106
diff
changeset
|
622 %! B = [ 1.407302 -0.632956 -0.360628 0.068534; |
da2b38b7a077
Use LAPACK DTGSEN subrouting for ordered-qz computation (bug #53761)
Sébastien Villemot <sebastien@debian.org>
parents:
25106
diff
changeset
|
623 %! 0.149898 0.298248 0.991777 0.023652; |
da2b38b7a077
Use LAPACK DTGSEN subrouting for ordered-qz computation (bug #53761)
Sébastien Villemot <sebastien@debian.org>
parents:
25106
diff
changeset
|
624 %! 0.169281 -0.405205 -1.775834 1.511730; |
da2b38b7a077
Use LAPACK DTGSEN subrouting for ordered-qz computation (bug #53761)
Sébastien Villemot <sebastien@debian.org>
parents:
25106
diff
changeset
|
625 %! 0.717770 1.291390 -1.766607 -0.531352 ]; |
31976
e6b24d0d485c
qz: Handle input and output arguments in a Matlab-compatible way.
Sébastien Villemot <sebastien@debian.org>
parents:
31827
diff
changeset
|
626 %! [CAA, CBB, CQ, CZ, CV, CW] = qz (A, B, 'complex'); |
e6b24d0d485c
qz: Handle input and output arguments in a Matlab-compatible way.
Sébastien Villemot <sebastien@debian.org>
parents:
31827
diff
changeset
|
627 %! assert (iscomplex (CAA) && iscomplex (CBB) && iscomplex (CQ) ... |
e6b24d0d485c
qz: Handle input and output arguments in a Matlab-compatible way.
Sébastien Villemot <sebastien@debian.org>
parents:
31827
diff
changeset
|
628 %! && iscomplex (CZ) && iscomplex (CV) && iscomplex (CW)); |
e6b24d0d485c
qz: Handle input and output arguments in a Matlab-compatible way.
Sébastien Villemot <sebastien@debian.org>
parents:
31827
diff
changeset
|
629 %! assert (istriu (CAA) && istriu (CBB)); |
e6b24d0d485c
qz: Handle input and output arguments in a Matlab-compatible way.
Sébastien Villemot <sebastien@debian.org>
parents:
31827
diff
changeset
|
630 %! assert (CQ * CQ', eye(4), 1e-14); |
e6b24d0d485c
qz: Handle input and output arguments in a Matlab-compatible way.
Sébastien Villemot <sebastien@debian.org>
parents:
31827
diff
changeset
|
631 %! assert (CZ * CZ', eye(4), 1e-14); |
e6b24d0d485c
qz: Handle input and output arguments in a Matlab-compatible way.
Sébastien Villemot <sebastien@debian.org>
parents:
31827
diff
changeset
|
632 %! assert (CQ * A * CZ, CAA, norm (CAA) * 1e-14); |
e6b24d0d485c
qz: Handle input and output arguments in a Matlab-compatible way.
Sébastien Villemot <sebastien@debian.org>
parents:
31827
diff
changeset
|
633 %! assert (CQ * B * CZ, CBB, norm (CBB) * 1e-14); |
e6b24d0d485c
qz: Handle input and output arguments in a Matlab-compatible way.
Sébastien Villemot <sebastien@debian.org>
parents:
31827
diff
changeset
|
634 %! assert (A * CV * diag (diag (CBB)), B * CV * diag (diag (CAA)), 1e-13); |
e6b24d0d485c
qz: Handle input and output arguments in a Matlab-compatible way.
Sébastien Villemot <sebastien@debian.org>
parents:
31827
diff
changeset
|
635 %! assert (diag (diag (CBB)) * CW' * A, diag (diag (CAA)) * CW' * B, 1e-13); |
e6b24d0d485c
qz: Handle input and output arguments in a Matlab-compatible way.
Sébastien Villemot <sebastien@debian.org>
parents:
31827
diff
changeset
|
636 %! [AA, BB, Q, Z, V, W] = qz (A, B, 'real'); |
e6b24d0d485c
qz: Handle input and output arguments in a Matlab-compatible way.
Sébastien Villemot <sebastien@debian.org>
parents:
31827
diff
changeset
|
637 %! assert (isreal (AA) && isreal (BB) && isreal (Q) && isreal (Z) ... |
e6b24d0d485c
qz: Handle input and output arguments in a Matlab-compatible way.
Sébastien Villemot <sebastien@debian.org>
parents:
31827
diff
changeset
|
638 %! && isreal (V) && isreal (W)); |
e6b24d0d485c
qz: Handle input and output arguments in a Matlab-compatible way.
Sébastien Villemot <sebastien@debian.org>
parents:
31827
diff
changeset
|
639 %! assert (istriu (BB)); |
e6b24d0d485c
qz: Handle input and output arguments in a Matlab-compatible way.
Sébastien Villemot <sebastien@debian.org>
parents:
31827
diff
changeset
|
640 %! assert (Q * Q', eye(4), 1e-14); |
e6b24d0d485c
qz: Handle input and output arguments in a Matlab-compatible way.
Sébastien Villemot <sebastien@debian.org>
parents:
31827
diff
changeset
|
641 %! assert (Z * Z', eye(4), 1e-14); |
e6b24d0d485c
qz: Handle input and output arguments in a Matlab-compatible way.
Sébastien Villemot <sebastien@debian.org>
parents:
31827
diff
changeset
|
642 %! assert (Q * A * Z, AA, norm (AA) * 1e-14); |
e6b24d0d485c
qz: Handle input and output arguments in a Matlab-compatible way.
Sébastien Villemot <sebastien@debian.org>
parents:
31827
diff
changeset
|
643 %! assert (Q * B * Z, BB, norm (BB) * 1e-14); |
13074
0b789a03bde1
codesprint: Add 3 tests for qz.cc
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12642
diff
changeset
|
644 */ |
29958
32c3a5805893
move DEFUN and DEFMETHOD functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29558
diff
changeset
|
645 |
31605
e88a07dec498
maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents:
30564
diff
changeset
|
646 OCTAVE_END_NAMESPACE(octave) |