annotate liboctave/numeric/fEIG.cc @ 33657:6f2baadfdb3d bytecode-interpreter tip

maint: Merge default to bytecode-interpreter.
author Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
date Tue, 04 Jun 2024 20:06:05 -0400
parents ebc26cef3096
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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 //
32632
2e484f9f1f18 maint: update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents: 31706
diff changeset
3 // Copyright (C) 1994-2024 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 ////////////////////////////////////////////////////////////////////////
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
25
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
26 #if defined (HAVE_CONFIG_H)
21301
40de9f8f23a6 Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents: 21202
diff changeset
27 # include "config.h"
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
28 #endif
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
29
23475
d691ed308237 maint: Clean up #includes in liboctave/numeric directory.
Rik <rik@octave.org>
parents: 23450
diff changeset
30 #include "Array.h"
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
31 #include "fEIG.h"
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
32 #include "fColVector.h"
23475
d691ed308237 maint: Clean up #includes in liboctave/numeric directory.
Rik <rik@octave.org>
parents: 23450
diff changeset
33 #include "fMatrix.h"
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
34 #include "lo-error.h"
22322
93b3cdd36854 move most f77 function decls to separate header files
John W. Eaton <jwe@octave.org>
parents: 22305
diff changeset
35 #include "lo-lapack-proto.h"
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
36
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
37 octave_idx_type
22402
4caa7b28d183 maint: Style check C++ code in liboctave/
Rik <rik@octave.org>
parents: 22323
diff changeset
38 FloatEIG::init (const FloatMatrix& a, bool calc_rev, bool calc_lev,
4caa7b28d183 maint: Style check C++ code in liboctave/
Rik <rik@octave.org>
parents: 22323
diff changeset
39 bool balance)
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
40 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
41 if (a.any_element_is_inf_or_nan ())
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 20490
diff changeset
42 (*current_liboctave_error_handler)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 20490
diff changeset
43 ("EIG: matrix contains Inf or NaN values");
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
44
23596
b63c3a09aee7 maint: Deprecate is_symmetric and replace with issymmetric.
Rik <rik@octave.org>
parents: 23594
diff changeset
45 if (a.issymmetric ())
22305
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
46 return symmetric_init (a, calc_rev, calc_lev);
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
47
22988
cd33c785e80e put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22953
diff changeset
48 F77_INT n = octave::to_f77_int (a.rows ());
cd33c785e80e put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22953
diff changeset
49 F77_INT a_nc = octave::to_f77_int (a.cols ());
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
50
22953
fd649fd3db75 use F77_INT instead of octave_idx_type for liboctave EIG classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
51 if (n != a_nc)
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 20490
diff changeset
52 (*current_liboctave_error_handler) ("EIG requires square matrix");
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
53
22953
fd649fd3db75 use F77_INT instead of octave_idx_type for liboctave EIG classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
54 F77_INT info = 0;
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
55
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
56 FloatMatrix atmp = a;
32660
f53ac65ffba6 maint: New method rwdata() as clearer alternative to fortran_vec().
Rik <rik@octave.org>
parents: 32632
diff changeset
57 float *tmp_data = atmp.rwdata ();
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
58
11570
57632dea2446 attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
59 Array<float> wr (dim_vector (n, 1));
32660
f53ac65ffba6 maint: New method rwdata() as clearer alternative to fortran_vec().
Rik <rik@octave.org>
parents: 32632
diff changeset
60 float *pwr = wr.rwdata ();
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
61
11570
57632dea2446 attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
62 Array<float> wi (dim_vector (n, 1));
32660
f53ac65ffba6 maint: New method rwdata() as clearer alternative to fortran_vec().
Rik <rik@octave.org>
parents: 32632
diff changeset
63 float *pwi = wi.rwdata ();
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
64
33041
ebc26cef3096 eliminate more obsolete volatile declarations
John W. Eaton <jwe@octave.org>
parents: 32660
diff changeset
65 F77_INT nvr = (calc_rev ? n : 0);
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
66 FloatMatrix vr (nvr, nvr);
32660
f53ac65ffba6 maint: New method rwdata() as clearer alternative to fortran_vec().
Rik <rik@octave.org>
parents: 32632
diff changeset
67 float *pvr = vr.rwdata ();
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
68
33041
ebc26cef3096 eliminate more obsolete volatile declarations
John W. Eaton <jwe@octave.org>
parents: 32660
diff changeset
69 F77_INT nvl = (calc_lev ? n : 0);
22305
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
70 FloatMatrix vl (nvl, nvl);
32660
f53ac65ffba6 maint: New method rwdata() as clearer alternative to fortran_vec().
Rik <rik@octave.org>
parents: 32632
diff changeset
71 float *pvl = vl.rwdata ();
22305
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
72
22953
fd649fd3db75 use F77_INT instead of octave_idx_type for liboctave EIG classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
73 F77_INT lwork = -1;
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
74 float dummy_work;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
75
22953
fd649fd3db75 use F77_INT instead of octave_idx_type for liboctave EIG classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
76 F77_INT ilo;
fd649fd3db75 use F77_INT instead of octave_idx_type for liboctave EIG classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
77 F77_INT ihi;
22305
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
78
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
79 Array<float> scale (dim_vector (n, 1));
32660
f53ac65ffba6 maint: New method rwdata() as clearer alternative to fortran_vec().
Rik <rik@octave.org>
parents: 32632
diff changeset
80 float *pscale = scale.rwdata ();
22305
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
81
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
82 float abnrm;
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
83
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
84 Array<float> rconde (dim_vector (n, 1));
32660
f53ac65ffba6 maint: New method rwdata() as clearer alternative to fortran_vec().
Rik <rik@octave.org>
parents: 32632
diff changeset
85 float *prconde = rconde.rwdata ();
22305
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
86
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
87 Array<float> rcondv (dim_vector (n, 1));
32660
f53ac65ffba6 maint: New method rwdata() as clearer alternative to fortran_vec().
Rik <rik@octave.org>
parents: 32632
diff changeset
88 float *prcondv = rcondv.rwdata ();
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
89
22953
fd649fd3db75 use F77_INT instead of octave_idx_type for liboctave EIG classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
90 F77_INT dummy_iwork;
22305
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
91
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
92 F77_XFCN (sgeevx, SGEEVX, (F77_CONST_CHAR_ARG2 (balance ? "B" : "N", 1),
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
93 F77_CONST_CHAR_ARG2 ("N", 1),
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
94 F77_CONST_CHAR_ARG2 (calc_rev ? "V" : "N", 1),
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
95 F77_CONST_CHAR_ARG2 ("N", 1),
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
96 n, tmp_data, n, pwr, pwi,
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
97 pvl, n, pvr, n,
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
98 ilo, ihi, pscale, abnrm, prconde, prcondv,
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
99 &dummy_work, lwork, &dummy_iwork, info
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
100 F77_CHAR_ARG_LEN (1)
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
101 F77_CHAR_ARG_LEN (1)
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
102 F77_CHAR_ARG_LEN (1)
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
103 F77_CHAR_ARG_LEN (1)));
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
104
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 20490
diff changeset
105 if (info != 0)
22305
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
106 (*current_liboctave_error_handler) ("sgeevx workspace query failed");
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
107
22953
fd649fd3db75 use F77_INT instead of octave_idx_type for liboctave EIG classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
108 lwork = static_cast<F77_INT> (dummy_work);
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 20490
diff changeset
109 Array<float> work (dim_vector (lwork, 1));
32660
f53ac65ffba6 maint: New method rwdata() as clearer alternative to fortran_vec().
Rik <rik@octave.org>
parents: 32632
diff changeset
110 float *pwork = work.rwdata ();
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
111
22305
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
112 F77_XFCN (sgeevx, SGEEVX, (F77_CONST_CHAR_ARG2 (balance ? "B" : "N", 1),
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
113 F77_CONST_CHAR_ARG2 ("N", 1),
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
114 F77_CONST_CHAR_ARG2 (calc_rev ? "V" : "N", 1),
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
115 F77_CONST_CHAR_ARG2 ("N", 1),
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
116 n, tmp_data, n, pwr, pwi,
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
117 pvl, n, pvr, n,
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
118 ilo, ihi, pscale, abnrm, prconde, prcondv,
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
119 pwork, lwork, &dummy_iwork, info
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
120 F77_CHAR_ARG_LEN (1)
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
121 F77_CHAR_ARG_LEN (1)
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
122 F77_CHAR_ARG_LEN (1)
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
123 F77_CHAR_ARG_LEN (1)));
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
124
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 20490
diff changeset
125 if (info < 0)
22305
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
126 (*current_liboctave_error_handler) ("unrecoverable error in sgeevx");
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
127
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 20490
diff changeset
128 if (info > 0)
22305
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
129 (*current_liboctave_error_handler) ("sgeevx failed to converge");
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 20490
diff changeset
130
30044
1f34286a2637 maint: use "m_" prefix for member variables of classes associated with EIG.
Rik <rik@octave.org>
parents: 29358
diff changeset
131 m_lambda.resize (n);
1f34286a2637 maint: use "m_" prefix for member variables of classes associated with EIG.
Rik <rik@octave.org>
parents: 29358
diff changeset
132 m_v.resize (nvr, nvr);
1f34286a2637 maint: use "m_" prefix for member variables of classes associated with EIG.
Rik <rik@octave.org>
parents: 29358
diff changeset
133 m_w.resize (nvl, nvl);
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
134
22953
fd649fd3db75 use F77_INT instead of octave_idx_type for liboctave EIG classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
135 for (F77_INT j = 0; j < n; j++)
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 20490
diff changeset
136 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 20490
diff changeset
137 if (wi.elem (j) == 0.0)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
138 {
30044
1f34286a2637 maint: use "m_" prefix for member variables of classes associated with EIG.
Rik <rik@octave.org>
parents: 29358
diff changeset
139 m_lambda.elem (j) = FloatComplex (wr.elem (j));
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 20490
diff changeset
140 for (octave_idx_type i = 0; i < nvr; i++)
30044
1f34286a2637 maint: use "m_" prefix for member variables of classes associated with EIG.
Rik <rik@octave.org>
parents: 29358
diff changeset
141 m_v.elem (i, j) = vr.elem (i, j);
22305
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
142
22953
fd649fd3db75 use F77_INT instead of octave_idx_type for liboctave EIG classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
143 for (F77_INT i = 0; i < nvl; i++)
30044
1f34286a2637 maint: use "m_" prefix for member variables of classes associated with EIG.
Rik <rik@octave.org>
parents: 29358
diff changeset
144 m_w.elem (i, j) = vl.elem (i, j);
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 20490
diff changeset
145 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 20490
diff changeset
146 else
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 20490
diff changeset
147 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 20490
diff changeset
148 if (j+1 >= n)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 20490
diff changeset
149 (*current_liboctave_error_handler) ("EIG: internal error");
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 20490
diff changeset
150
30044
1f34286a2637 maint: use "m_" prefix for member variables of classes associated with EIG.
Rik <rik@octave.org>
parents: 29358
diff changeset
151 m_lambda.elem (j) = FloatComplex (wr.elem (j), wi.elem (j));
1f34286a2637 maint: use "m_" prefix for member variables of classes associated with EIG.
Rik <rik@octave.org>
parents: 29358
diff changeset
152 m_lambda.elem (j+1) = FloatComplex (wr.elem (j+1), wi.elem (j+1));
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 20490
diff changeset
153
22953
fd649fd3db75 use F77_INT instead of octave_idx_type for liboctave EIG classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
154 for (F77_INT i = 0; i < nvr; i++)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
155 {
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 20490
diff changeset
156 float real_part = vr.elem (i, j);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 20490
diff changeset
157 float imag_part = vr.elem (i, j+1);
30044
1f34286a2637 maint: use "m_" prefix for member variables of classes associated with EIG.
Rik <rik@octave.org>
parents: 29358
diff changeset
158 m_v.elem (i, j) = FloatComplex (real_part, imag_part);
1f34286a2637 maint: use "m_" prefix for member variables of classes associated with EIG.
Rik <rik@octave.org>
parents: 29358
diff changeset
159 m_v.elem (i, j+1) = FloatComplex (real_part, -imag_part);
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
160 }
22953
fd649fd3db75 use F77_INT instead of octave_idx_type for liboctave EIG classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
161 for (F77_INT i = 0; i < nvl; i++)
22305
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
162 {
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
163 float real_part = vl.elem (i, j);
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
164 float imag_part = vl.elem (i, j+1);
30044
1f34286a2637 maint: use "m_" prefix for member variables of classes associated with EIG.
Rik <rik@octave.org>
parents: 29358
diff changeset
165 m_w.elem (i, j) = FloatComplex (real_part, imag_part);
1f34286a2637 maint: use "m_" prefix for member variables of classes associated with EIG.
Rik <rik@octave.org>
parents: 29358
diff changeset
166 m_w.elem (i, j+1) = FloatComplex (real_part, -imag_part);
22305
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
167 }
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 20490
diff changeset
168 j++;
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
169 }
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
170 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
171
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
172 return info;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
173 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
174
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11570
diff changeset
175 octave_idx_type
22305
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
176 FloatEIG::symmetric_init (const FloatMatrix& a, bool calc_rev, bool calc_lev)
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
177 {
22988
cd33c785e80e put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22953
diff changeset
178 F77_INT n = octave::to_f77_int (a.rows ());
cd33c785e80e put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22953
diff changeset
179 F77_INT a_nc = octave::to_f77_int (a.cols ());
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
180
22953
fd649fd3db75 use F77_INT instead of octave_idx_type for liboctave EIG classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
181 if (n != a_nc)
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 20490
diff changeset
182 (*current_liboctave_error_handler) ("EIG requires square matrix");
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
183
22953
fd649fd3db75 use F77_INT instead of octave_idx_type for liboctave EIG classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
184 F77_INT info = 0;
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
185
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
186 FloatMatrix atmp = a;
32660
f53ac65ffba6 maint: New method rwdata() as clearer alternative to fortran_vec().
Rik <rik@octave.org>
parents: 32632
diff changeset
187 float *tmp_data = atmp.rwdata ();
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
188
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
189 FloatColumnVector wr (n);
32660
f53ac65ffba6 maint: New method rwdata() as clearer alternative to fortran_vec().
Rik <rik@octave.org>
parents: 32632
diff changeset
190 float *pwr = wr.rwdata ();
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
191
22953
fd649fd3db75 use F77_INT instead of octave_idx_type for liboctave EIG classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
192 F77_INT lwork = -1;
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
193 float dummy_work;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
194
22305
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
195 F77_XFCN (ssyev, SSYEV, (F77_CONST_CHAR_ARG2 (calc_rev ? "V" : "N", 1),
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
196 F77_CONST_CHAR_ARG2 ("U", 1),
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
197 n, tmp_data, n, pwr, &dummy_work, lwork, info
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
198 F77_CHAR_ARG_LEN (1)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
199 F77_CHAR_ARG_LEN (1)));
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
200
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 20490
diff changeset
201 if (info != 0)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 20490
diff changeset
202 (*current_liboctave_error_handler) ("ssyev workspace query failed");
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
203
22953
fd649fd3db75 use F77_INT instead of octave_idx_type for liboctave EIG classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
204 lwork = static_cast<F77_INT> (dummy_work);
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 20490
diff changeset
205 Array<float> work (dim_vector (lwork, 1));
32660
f53ac65ffba6 maint: New method rwdata() as clearer alternative to fortran_vec().
Rik <rik@octave.org>
parents: 32632
diff changeset
206 float *pwork = work.rwdata ();
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
207
22305
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
208 F77_XFCN (ssyev, SSYEV, (F77_CONST_CHAR_ARG2 (calc_rev ? "V" : "N", 1),
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 20490
diff changeset
209 F77_CONST_CHAR_ARG2 ("U", 1),
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 20490
diff changeset
210 n, tmp_data, n, pwr, pwork, lwork, info
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 20490
diff changeset
211 F77_CHAR_ARG_LEN (1)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 20490
diff changeset
212 F77_CHAR_ARG_LEN (1)));
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
213
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 20490
diff changeset
214 if (info < 0)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 20490
diff changeset
215 (*current_liboctave_error_handler) ("unrecoverable error in ssyev");
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
216
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 20490
diff changeset
217 if (info > 0)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 20490
diff changeset
218 (*current_liboctave_error_handler) ("ssyev failed to converge");
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 20490
diff changeset
219
30044
1f34286a2637 maint: use "m_" prefix for member variables of classes associated with EIG.
Rik <rik@octave.org>
parents: 29358
diff changeset
220 m_lambda = FloatComplexColumnVector (wr);
1f34286a2637 maint: use "m_" prefix for member variables of classes associated with EIG.
Rik <rik@octave.org>
parents: 29358
diff changeset
221 m_v = (calc_rev ? FloatComplexMatrix (atmp) : FloatComplexMatrix ());
1f34286a2637 maint: use "m_" prefix for member variables of classes associated with EIG.
Rik <rik@octave.org>
parents: 29358
diff changeset
222 m_w = (calc_lev ? FloatComplexMatrix (atmp) : FloatComplexMatrix ());
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
223
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
224 return info;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
225 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
226
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
227 octave_idx_type
22305
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
228 FloatEIG::init (const FloatComplexMatrix& a, bool calc_rev, bool calc_lev,
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
229 bool balance)
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
230 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
231 if (a.any_element_is_inf_or_nan ())
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 20490
diff changeset
232 (*current_liboctave_error_handler)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 20490
diff changeset
233 ("EIG: matrix contains Inf or NaN values");
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
234
23594
af5b813503cb maint: Deprecate is_hermitian and replace with ishermitian.
Rik <rik@octave.org>
parents: 23475
diff changeset
235 if (a.ishermitian ())
22305
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
236 return hermitian_init (a, calc_rev, calc_lev);
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
237
22988
cd33c785e80e put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22953
diff changeset
238 F77_INT n = octave::to_f77_int (a.rows ());
cd33c785e80e put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22953
diff changeset
239 F77_INT a_nc = octave::to_f77_int (a.cols ());
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
240
22953
fd649fd3db75 use F77_INT instead of octave_idx_type for liboctave EIG classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
241 if (n != a_nc)
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 20490
diff changeset
242 (*current_liboctave_error_handler) ("EIG requires square matrix");
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
243
22953
fd649fd3db75 use F77_INT instead of octave_idx_type for liboctave EIG classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
244 F77_INT info = 0;
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
245
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
246 FloatComplexMatrix atmp = a;
32660
f53ac65ffba6 maint: New method rwdata() as clearer alternative to fortran_vec().
Rik <rik@octave.org>
parents: 32632
diff changeset
247 FloatComplex *tmp_data = atmp.rwdata ();
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
248
22305
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
249 FloatComplexColumnVector wr (n);
32660
f53ac65ffba6 maint: New method rwdata() as clearer alternative to fortran_vec().
Rik <rik@octave.org>
parents: 32632
diff changeset
250 FloatComplex *pw = wr.rwdata ();
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
251
23450
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23220
diff changeset
252 F77_INT nvr = (calc_rev ? n : 0);
22305
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
253 FloatComplexMatrix vrtmp (nvr, nvr);
32660
f53ac65ffba6 maint: New method rwdata() as clearer alternative to fortran_vec().
Rik <rik@octave.org>
parents: 32632
diff changeset
254 FloatComplex *pvr = vrtmp.rwdata ();
22305
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
255
23450
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23220
diff changeset
256 F77_INT nvl = (calc_lev ? n : 0);
22305
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
257 FloatComplexMatrix vltmp (nvl, nvl);
32660
f53ac65ffba6 maint: New method rwdata() as clearer alternative to fortran_vec().
Rik <rik@octave.org>
parents: 32632
diff changeset
258 FloatComplex *pvl = vltmp.rwdata ();
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
259
22953
fd649fd3db75 use F77_INT instead of octave_idx_type for liboctave EIG classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
260 F77_INT lwork = -1;
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
261 FloatComplex dummy_work;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
262
22953
fd649fd3db75 use F77_INT instead of octave_idx_type for liboctave EIG classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
263 F77_INT lrwork = 2*n;
11570
57632dea2446 attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
264 Array<float> rwork (dim_vector (lrwork, 1));
32660
f53ac65ffba6 maint: New method rwdata() as clearer alternative to fortran_vec().
Rik <rik@octave.org>
parents: 32632
diff changeset
265 float *prwork = rwork.rwdata ();
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
266
22953
fd649fd3db75 use F77_INT instead of octave_idx_type for liboctave EIG classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
267 F77_INT ilo;
fd649fd3db75 use F77_INT instead of octave_idx_type for liboctave EIG classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
268 F77_INT ihi;
22305
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
269
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
270 Array<float> scale (dim_vector (n, 1));
32660
f53ac65ffba6 maint: New method rwdata() as clearer alternative to fortran_vec().
Rik <rik@octave.org>
parents: 32632
diff changeset
271 float *pscale = scale.rwdata ();
22305
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
272
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
273 float abnrm;
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
274
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
275 Array<float> rconde (dim_vector (n, 1));
32660
f53ac65ffba6 maint: New method rwdata() as clearer alternative to fortran_vec().
Rik <rik@octave.org>
parents: 32632
diff changeset
276 float *prconde = rconde.rwdata ();
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
277
22305
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
278 Array<float> rcondv (dim_vector (n, 1));
32660
f53ac65ffba6 maint: New method rwdata() as clearer alternative to fortran_vec().
Rik <rik@octave.org>
parents: 32632
diff changeset
279 float *prcondv = rcondv.rwdata ();
22305
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
280
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
281 F77_XFCN (cgeevx, CGEEVX, (F77_CONST_CHAR_ARG2 (balance ? "B" : "N", 1),
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
282 F77_CONST_CHAR_ARG2 (calc_lev ? "V" : "N", 1),
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
283 F77_CONST_CHAR_ARG2 (calc_rev ? "V" : "N", 1),
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
284 F77_CONST_CHAR_ARG2 ("N", 1),
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
285 n, F77_CMPLX_ARG (tmp_data), n, F77_CMPLX_ARG (pw),
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
286 F77_CMPLX_ARG (pvl), n, F77_CMPLX_ARG (pvr), n,
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
287 ilo, ihi, pscale, abnrm, prconde, prcondv,
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
288 F77_CMPLX_ARG (&dummy_work), lwork, prwork, info
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
289 F77_CHAR_ARG_LEN (1)
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
290 F77_CHAR_ARG_LEN (1)
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
291 F77_CHAR_ARG_LEN (1)
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
292 F77_CHAR_ARG_LEN (1)));
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
293
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 20490
diff changeset
294 if (info != 0)
22305
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
295 (*current_liboctave_error_handler) ("cgeevx workspace query failed");
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
296
22953
fd649fd3db75 use F77_INT instead of octave_idx_type for liboctave EIG classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
297 lwork = static_cast<F77_INT> (dummy_work.real ());
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 20490
diff changeset
298 Array<FloatComplex> work (dim_vector (lwork, 1));
32660
f53ac65ffba6 maint: New method rwdata() as clearer alternative to fortran_vec().
Rik <rik@octave.org>
parents: 32632
diff changeset
299 FloatComplex *pwork = work.rwdata ();
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
300
22305
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
301 F77_XFCN (cgeevx, CGEEVX, (F77_CONST_CHAR_ARG2 (balance ? "B" : "N", 1),
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
302 F77_CONST_CHAR_ARG2 (calc_lev ? "V" : "N", 1),
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
303 F77_CONST_CHAR_ARG2 (calc_rev ? "V" : "N", 1),
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
304 F77_CONST_CHAR_ARG2 ("N", 1),
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
305 n, F77_CMPLX_ARG (tmp_data), n, F77_CMPLX_ARG (pw),
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
306 F77_CMPLX_ARG (pvl), n, F77_CMPLX_ARG (pvr), n,
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
307 ilo, ihi, pscale, abnrm, prconde, prcondv,
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
308 F77_CMPLX_ARG (pwork), lwork, prwork, info
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
309 F77_CHAR_ARG_LEN (1)
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
310 F77_CHAR_ARG_LEN (1)
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
311 F77_CHAR_ARG_LEN (1)
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
312 F77_CHAR_ARG_LEN (1)));
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
313
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 20490
diff changeset
314 if (info < 0)
22305
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
315 (*current_liboctave_error_handler) ("unrecoverable error in cgeevx");
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
316
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 20490
diff changeset
317 if (info > 0)
22305
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
318 (*current_liboctave_error_handler) ("cgeevx failed to converge");
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 20490
diff changeset
319
30044
1f34286a2637 maint: use "m_" prefix for member variables of classes associated with EIG.
Rik <rik@octave.org>
parents: 29358
diff changeset
320 m_lambda = wr;
1f34286a2637 maint: use "m_" prefix for member variables of classes associated with EIG.
Rik <rik@octave.org>
parents: 29358
diff changeset
321 m_v = vrtmp;
1f34286a2637 maint: use "m_" prefix for member variables of classes associated with EIG.
Rik <rik@octave.org>
parents: 29358
diff changeset
322 m_w = vltmp;
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
323
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
324 return info;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
325 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
326
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
327 octave_idx_type
22305
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
328 FloatEIG::hermitian_init (const FloatComplexMatrix& a, bool calc_rev,
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
329 bool calc_lev)
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
330 {
22988
cd33c785e80e put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22953
diff changeset
331 F77_INT n = octave::to_f77_int (a.rows ());
cd33c785e80e put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22953
diff changeset
332 F77_INT a_nc = octave::to_f77_int (a.cols ());
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
333
22953
fd649fd3db75 use F77_INT instead of octave_idx_type for liboctave EIG classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
334 if (n != a_nc)
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 20490
diff changeset
335 (*current_liboctave_error_handler) ("EIG requires square matrix");
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
336
22953
fd649fd3db75 use F77_INT instead of octave_idx_type for liboctave EIG classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
337 F77_INT info = 0;
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
338
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
339 FloatComplexMatrix atmp = a;
32660
f53ac65ffba6 maint: New method rwdata() as clearer alternative to fortran_vec().
Rik <rik@octave.org>
parents: 32632
diff changeset
340 FloatComplex *tmp_data = atmp.rwdata ();
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
341
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
342 FloatColumnVector wr (n);
32660
f53ac65ffba6 maint: New method rwdata() as clearer alternative to fortran_vec().
Rik <rik@octave.org>
parents: 32632
diff changeset
343 float *pwr = wr.rwdata ();
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
344
22953
fd649fd3db75 use F77_INT instead of octave_idx_type for liboctave EIG classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
345 F77_INT lwork = -1;
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
346 FloatComplex dummy_work;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
347
22953
fd649fd3db75 use F77_INT instead of octave_idx_type for liboctave EIG classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
348 F77_INT lrwork = 3*n;
11570
57632dea2446 attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
349 Array<float> rwork (dim_vector (lrwork, 1));
32660
f53ac65ffba6 maint: New method rwdata() as clearer alternative to fortran_vec().
Rik <rik@octave.org>
parents: 32632
diff changeset
350 float *prwork = rwork.rwdata ();
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
351
22305
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
352 F77_XFCN (cheev, CHEEV, (F77_CONST_CHAR_ARG2 (calc_rev ? "V" : "N", 1),
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
353 F77_CONST_CHAR_ARG2 ("U", 1),
22305
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
354 n, F77_CMPLX_ARG (tmp_data), n, pwr,
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
355 F77_CMPLX_ARG (&dummy_work), lwork,
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
356 prwork, info
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
357 F77_CHAR_ARG_LEN (1)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
358 F77_CHAR_ARG_LEN (1)));
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
359
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 20490
diff changeset
360 if (info != 0)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 20490
diff changeset
361 (*current_liboctave_error_handler) ("cheev workspace query failed");
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
362
22953
fd649fd3db75 use F77_INT instead of octave_idx_type for liboctave EIG classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
363 lwork = static_cast<F77_INT> (dummy_work.real ());
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 20490
diff changeset
364 Array<FloatComplex> work (dim_vector (lwork, 1));
32660
f53ac65ffba6 maint: New method rwdata() as clearer alternative to fortran_vec().
Rik <rik@octave.org>
parents: 32632
diff changeset
365 FloatComplex *pwork = work.rwdata ();
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
366
22305
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
367 F77_XFCN (cheev, CHEEV, (F77_CONST_CHAR_ARG2 (calc_rev ? "V" : "N", 1),
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 20490
diff changeset
368 F77_CONST_CHAR_ARG2 ("U", 1),
22305
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
369 n, F77_CMPLX_ARG (tmp_data), n, pwr,
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
370 F77_CMPLX_ARG (pwork), lwork, prwork, info
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 20490
diff changeset
371 F77_CHAR_ARG_LEN (1)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 20490
diff changeset
372 F77_CHAR_ARG_LEN (1)));
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
373
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 20490
diff changeset
374 if (info < 0)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 20490
diff changeset
375 (*current_liboctave_error_handler) ("unrecoverable error in cheev");
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
376
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 20490
diff changeset
377 if (info > 0)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 20490
diff changeset
378 (*current_liboctave_error_handler) ("cheev failed to converge");
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 20490
diff changeset
379
30044
1f34286a2637 maint: use "m_" prefix for member variables of classes associated with EIG.
Rik <rik@octave.org>
parents: 29358
diff changeset
380 m_lambda = FloatComplexColumnVector (wr);
1f34286a2637 maint: use "m_" prefix for member variables of classes associated with EIG.
Rik <rik@octave.org>
parents: 29358
diff changeset
381 m_v = (calc_rev ? FloatComplexMatrix (atmp) : FloatComplexMatrix ());
1f34286a2637 maint: use "m_" prefix for member variables of classes associated with EIG.
Rik <rik@octave.org>
parents: 29358
diff changeset
382 m_w = (calc_lev ? FloatComplexMatrix (atmp) : FloatComplexMatrix ());
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
383
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
384 return info;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
385 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
diff changeset
386
8339
18c4ded8612a Add generalized eigenvalue functions
Jarkko Kaleva <d3roga@gmail.com>
parents: 7789
diff changeset
387 octave_idx_type
22305
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
388 FloatEIG::init (const FloatMatrix& a, const FloatMatrix& b, bool calc_rev,
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
389 bool calc_lev, bool force_qz)
8339
18c4ded8612a Add generalized eigenvalue functions
Jarkko Kaleva <d3roga@gmail.com>
parents: 7789
diff changeset
390 {
18c4ded8612a Add generalized eigenvalue functions
Jarkko Kaleva <d3roga@gmail.com>
parents: 7789
diff changeset
391 if (a.any_element_is_inf_or_nan () || b.any_element_is_inf_or_nan ())
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 20490
diff changeset
392 (*current_liboctave_error_handler)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 20490
diff changeset
393 ("EIG: matrix contains Inf or NaN values");
8339
18c4ded8612a Add generalized eigenvalue functions
Jarkko Kaleva <d3roga@gmail.com>
parents: 7789
diff changeset
394
22988
cd33c785e80e put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22953
diff changeset
395 F77_INT n = octave::to_f77_int (a.rows ());
cd33c785e80e put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22953
diff changeset
396 F77_INT nb = octave::to_f77_int (b.rows ());
8339
18c4ded8612a Add generalized eigenvalue functions
Jarkko Kaleva <d3roga@gmail.com>
parents: 7789
diff changeset
397
22988
cd33c785e80e put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22953
diff changeset
398 F77_INT a_nc = octave::to_f77_int (a.cols ());
cd33c785e80e put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22953
diff changeset
399 F77_INT b_nc = octave::to_f77_int (b.cols ());
22953
fd649fd3db75 use F77_INT instead of octave_idx_type for liboctave EIG classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
400
fd649fd3db75 use F77_INT instead of octave_idx_type for liboctave EIG classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
401 if (n != a_nc || nb != b_nc)
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 20490
diff changeset
402 (*current_liboctave_error_handler) ("EIG requires square matrix");
8339
18c4ded8612a Add generalized eigenvalue functions
Jarkko Kaleva <d3roga@gmail.com>
parents: 7789
diff changeset
403
18c4ded8612a Add generalized eigenvalue functions
Jarkko Kaleva <d3roga@gmail.com>
parents: 7789
diff changeset
404 if (n != nb)
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 20490
diff changeset
405 (*current_liboctave_error_handler) ("EIG requires same size matrices");
8339
18c4ded8612a Add generalized eigenvalue functions
Jarkko Kaleva <d3roga@gmail.com>
parents: 7789
diff changeset
406
22953
fd649fd3db75 use F77_INT instead of octave_idx_type for liboctave EIG classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
407 F77_INT info = 0;
8339
18c4ded8612a Add generalized eigenvalue functions
Jarkko Kaleva <d3roga@gmail.com>
parents: 7789
diff changeset
408
18c4ded8612a Add generalized eigenvalue functions
Jarkko Kaleva <d3roga@gmail.com>
parents: 7789
diff changeset
409 FloatMatrix tmp = b;
32660
f53ac65ffba6 maint: New method rwdata() as clearer alternative to fortran_vec().
Rik <rik@octave.org>
parents: 32632
diff changeset
410 float *tmp_data = tmp.rwdata ();
22305
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
411 if (! force_qz)
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
412 {
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
413 F77_XFCN (spotrf, SPOTRF, (F77_CONST_CHAR_ARG2 ("L", 1),
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
414 n, tmp_data, n,
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
415 info
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
416 F77_CHAR_ARG_LEN (1)));
8339
18c4ded8612a Add generalized eigenvalue functions
Jarkko Kaleva <d3roga@gmail.com>
parents: 7789
diff changeset
417
23596
b63c3a09aee7 maint: Deprecate is_symmetric and replace with issymmetric.
Rik <rik@octave.org>
parents: 23594
diff changeset
418 if (a.issymmetric () && b.issymmetric () && info == 0)
22305
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
419 return symmetric_init (a, b, calc_rev, calc_lev);
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
420 }
8339
18c4ded8612a Add generalized eigenvalue functions
Jarkko Kaleva <d3roga@gmail.com>
parents: 7789
diff changeset
421
18c4ded8612a Add generalized eigenvalue functions
Jarkko Kaleva <d3roga@gmail.com>
parents: 7789
diff changeset
422 FloatMatrix atmp = a;
32660
f53ac65ffba6 maint: New method rwdata() as clearer alternative to fortran_vec().
Rik <rik@octave.org>
parents: 32632
diff changeset
423 float *atmp_data = atmp.rwdata ();
8339
18c4ded8612a Add generalized eigenvalue functions
Jarkko Kaleva <d3roga@gmail.com>
parents: 7789
diff changeset
424
18c4ded8612a Add generalized eigenvalue functions
Jarkko Kaleva <d3roga@gmail.com>
parents: 7789
diff changeset
425 FloatMatrix btmp = b;
32660
f53ac65ffba6 maint: New method rwdata() as clearer alternative to fortran_vec().
Rik <rik@octave.org>
parents: 32632
diff changeset
426 float *btmp_data = btmp.rwdata ();
8339
18c4ded8612a Add generalized eigenvalue functions
Jarkko Kaleva <d3roga@gmail.com>
parents: 7789
diff changeset
427
11570
57632dea2446 attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
428 Array<float> ar (dim_vector (n, 1));
32660
f53ac65ffba6 maint: New method rwdata() as clearer alternative to fortran_vec().
Rik <rik@octave.org>
parents: 32632
diff changeset
429 float *par = ar.rwdata ();
8339
18c4ded8612a Add generalized eigenvalue functions
Jarkko Kaleva <d3roga@gmail.com>
parents: 7789
diff changeset
430
11570
57632dea2446 attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
431 Array<float> ai (dim_vector (n, 1));
32660
f53ac65ffba6 maint: New method rwdata() as clearer alternative to fortran_vec().
Rik <rik@octave.org>
parents: 32632
diff changeset
432 float *pai = ai.rwdata ();
8339
18c4ded8612a Add generalized eigenvalue functions
Jarkko Kaleva <d3roga@gmail.com>
parents: 7789
diff changeset
433
11570
57632dea2446 attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
434 Array<float> beta (dim_vector (n, 1));
32660
f53ac65ffba6 maint: New method rwdata() as clearer alternative to fortran_vec().
Rik <rik@octave.org>
parents: 32632
diff changeset
435 float *pbeta = beta.rwdata ();
8339
18c4ded8612a Add generalized eigenvalue functions
Jarkko Kaleva <d3roga@gmail.com>
parents: 7789
diff changeset
436
33041
ebc26cef3096 eliminate more obsolete volatile declarations
John W. Eaton <jwe@octave.org>
parents: 32660
diff changeset
437 F77_INT nvr = (calc_rev ? n : 0);
8339
18c4ded8612a Add generalized eigenvalue functions
Jarkko Kaleva <d3roga@gmail.com>
parents: 7789
diff changeset
438 FloatMatrix vr (nvr, nvr);
32660
f53ac65ffba6 maint: New method rwdata() as clearer alternative to fortran_vec().
Rik <rik@octave.org>
parents: 32632
diff changeset
439 float *pvr = vr.rwdata ();
8339
18c4ded8612a Add generalized eigenvalue functions
Jarkko Kaleva <d3roga@gmail.com>
parents: 7789
diff changeset
440
33041
ebc26cef3096 eliminate more obsolete volatile declarations
John W. Eaton <jwe@octave.org>
parents: 32660
diff changeset
441 F77_INT nvl = (calc_lev ? n : 0);
22305
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
442 FloatMatrix vl (nvl, nvl);
32660
f53ac65ffba6 maint: New method rwdata() as clearer alternative to fortran_vec().
Rik <rik@octave.org>
parents: 32632
diff changeset
443 float *pvl = vl.rwdata ();
22305
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
444
22953
fd649fd3db75 use F77_INT instead of octave_idx_type for liboctave EIG classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
445 F77_INT lwork = -1;
8339
18c4ded8612a Add generalized eigenvalue functions
Jarkko Kaleva <d3roga@gmail.com>
parents: 7789
diff changeset
446 float dummy_work;
18c4ded8612a Add generalized eigenvalue functions
Jarkko Kaleva <d3roga@gmail.com>
parents: 7789
diff changeset
447
22305
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
448 F77_XFCN (sggev, SGGEV, (F77_CONST_CHAR_ARG2 (calc_lev ? "V" : "N", 1),
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
449 F77_CONST_CHAR_ARG2 (calc_rev ? "V" : "N", 1),
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11570
diff changeset
450 n, atmp_data, n, btmp_data, n,
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
451 par, pai, pbeta,
22305
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
452 pvl, n, pvr, n,
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
453 &dummy_work, lwork, info
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
454 F77_CHAR_ARG_LEN (1)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
455 F77_CHAR_ARG_LEN (1)));
8339
18c4ded8612a Add generalized eigenvalue functions
Jarkko Kaleva <d3roga@gmail.com>
parents: 7789
diff changeset
456
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 20490
diff changeset
457 if (info != 0)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 20490
diff changeset
458 (*current_liboctave_error_handler) ("sggev workspace query failed");
8339
18c4ded8612a Add generalized eigenvalue functions
Jarkko Kaleva <d3roga@gmail.com>
parents: 7789
diff changeset
459
22953
fd649fd3db75 use F77_INT instead of octave_idx_type for liboctave EIG classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
460 lwork = static_cast<F77_INT> (dummy_work);
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 20490
diff changeset
461 Array<float> work (dim_vector (lwork, 1));
32660
f53ac65ffba6 maint: New method rwdata() as clearer alternative to fortran_vec().
Rik <rik@octave.org>
parents: 32632
diff changeset
462 float *pwork = work.rwdata ();
8339
18c4ded8612a Add generalized eigenvalue functions
Jarkko Kaleva <d3roga@gmail.com>
parents: 7789
diff changeset
463
22305
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
464 F77_XFCN (sggev, SGGEV, (F77_CONST_CHAR_ARG2 (calc_lev ? "V" : "N", 1),
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
465 F77_CONST_CHAR_ARG2 (calc_rev ? "V" : "N", 1),
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 20490
diff changeset
466 n, atmp_data, n, btmp_data, n,
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 20490
diff changeset
467 par, pai, pbeta,
22305
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
468 pvl, n, pvr, n,
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 20490
diff changeset
469 pwork, lwork, info
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 20490
diff changeset
470 F77_CHAR_ARG_LEN (1)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 20490
diff changeset
471 F77_CHAR_ARG_LEN (1)));
8339
18c4ded8612a Add generalized eigenvalue functions
Jarkko Kaleva <d3roga@gmail.com>
parents: 7789
diff changeset
472
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 20490
diff changeset
473 if (info < 0)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 20490
diff changeset
474 (*current_liboctave_error_handler) ("unrecoverable error in sggev");
8339
18c4ded8612a Add generalized eigenvalue functions
Jarkko Kaleva <d3roga@gmail.com>
parents: 7789
diff changeset
475
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 20490
diff changeset
476 if (info > 0)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 20490
diff changeset
477 (*current_liboctave_error_handler) ("sggev failed to converge");
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 20490
diff changeset
478
30044
1f34286a2637 maint: use "m_" prefix for member variables of classes associated with EIG.
Rik <rik@octave.org>
parents: 29358
diff changeset
479 m_lambda.resize (n);
1f34286a2637 maint: use "m_" prefix for member variables of classes associated with EIG.
Rik <rik@octave.org>
parents: 29358
diff changeset
480 m_v.resize (nvr, nvr);
1f34286a2637 maint: use "m_" prefix for member variables of classes associated with EIG.
Rik <rik@octave.org>
parents: 29358
diff changeset
481 m_w.resize (nvl, nvl);
22305
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
482
8339
18c4ded8612a Add generalized eigenvalue functions
Jarkko Kaleva <d3roga@gmail.com>
parents: 7789
diff changeset
483
22953
fd649fd3db75 use F77_INT instead of octave_idx_type for liboctave EIG classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
484 for (F77_INT j = 0; j < n; j++)
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 20490
diff changeset
485 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 20490
diff changeset
486 if (ai.elem (j) == 0.0)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 20490
diff changeset
487 {
30044
1f34286a2637 maint: use "m_" prefix for member variables of classes associated with EIG.
Rik <rik@octave.org>
parents: 29358
diff changeset
488 m_lambda.elem (j) = FloatComplex (ar.elem (j) / beta.elem (j));
22953
fd649fd3db75 use F77_INT instead of octave_idx_type for liboctave EIG classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
489 for (F77_INT i = 0; i < nvr; i++)
30044
1f34286a2637 maint: use "m_" prefix for member variables of classes associated with EIG.
Rik <rik@octave.org>
parents: 29358
diff changeset
490 m_v.elem (i, j) = vr.elem (i, j);
22305
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
491
22953
fd649fd3db75 use F77_INT instead of octave_idx_type for liboctave EIG classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
492 for (F77_INT i = 0; i < nvl; i++)
30044
1f34286a2637 maint: use "m_" prefix for member variables of classes associated with EIG.
Rik <rik@octave.org>
parents: 29358
diff changeset
493 m_w.elem (i, j) = vl.elem (i, j);
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 20490
diff changeset
494 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 20490
diff changeset
495 else
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
496 {
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 20490
diff changeset
497 if (j+1 >= n)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 20490
diff changeset
498 (*current_liboctave_error_handler) ("EIG: internal error");
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 20490
diff changeset
499
30044
1f34286a2637 maint: use "m_" prefix for member variables of classes associated with EIG.
Rik <rik@octave.org>
parents: 29358
diff changeset
500 m_lambda.elem (j) = FloatComplex (ar.elem (j) / beta.elem (j),
1f34286a2637 maint: use "m_" prefix for member variables of classes associated with EIG.
Rik <rik@octave.org>
parents: 29358
diff changeset
501 ai.elem (j) / beta.elem (j));
1f34286a2637 maint: use "m_" prefix for member variables of classes associated with EIG.
Rik <rik@octave.org>
parents: 29358
diff changeset
502 m_lambda.elem (j+1) = FloatComplex (ar.elem (j+1) / beta.elem (j+1),
1f34286a2637 maint: use "m_" prefix for member variables of classes associated with EIG.
Rik <rik@octave.org>
parents: 29358
diff changeset
503 ai.elem (j+1) / beta.elem (j+1));
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 20490
diff changeset
504
22953
fd649fd3db75 use F77_INT instead of octave_idx_type for liboctave EIG classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
505 for (F77_INT i = 0; i < nvr; i++)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
506 {
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 20490
diff changeset
507 float real_part = vr.elem (i, j);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 20490
diff changeset
508 float imag_part = vr.elem (i, j+1);
30044
1f34286a2637 maint: use "m_" prefix for member variables of classes associated with EIG.
Rik <rik@octave.org>
parents: 29358
diff changeset
509 m_v.elem (i, j) = FloatComplex (real_part, imag_part);
1f34286a2637 maint: use "m_" prefix for member variables of classes associated with EIG.
Rik <rik@octave.org>
parents: 29358
diff changeset
510 m_v.elem (i, j+1) = FloatComplex (real_part, -imag_part);
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
511 }
22953
fd649fd3db75 use F77_INT instead of octave_idx_type for liboctave EIG classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
512 for (F77_INT i = 0; i < nvl; i++)
22305
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
513 {
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
514 float real_part = vl.elem (i, j);
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
515 float imag_part = vl.elem (i, j+1);
30044
1f34286a2637 maint: use "m_" prefix for member variables of classes associated with EIG.
Rik <rik@octave.org>
parents: 29358
diff changeset
516 m_w.elem (i, j) = FloatComplex (real_part, imag_part);
1f34286a2637 maint: use "m_" prefix for member variables of classes associated with EIG.
Rik <rik@octave.org>
parents: 29358
diff changeset
517 m_w.elem (i, j+1) = FloatComplex (real_part, -imag_part);
22305
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
518 }
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 20490
diff changeset
519 j++;
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
520 }
8339
18c4ded8612a Add generalized eigenvalue functions
Jarkko Kaleva <d3roga@gmail.com>
parents: 7789
diff changeset
521 }
18c4ded8612a Add generalized eigenvalue functions
Jarkko Kaleva <d3roga@gmail.com>
parents: 7789
diff changeset
522
18c4ded8612a Add generalized eigenvalue functions
Jarkko Kaleva <d3roga@gmail.com>
parents: 7789
diff changeset
523 return info;
18c4ded8612a Add generalized eigenvalue functions
Jarkko Kaleva <d3roga@gmail.com>
parents: 7789
diff changeset
524 }
18c4ded8612a Add generalized eigenvalue functions
Jarkko Kaleva <d3roga@gmail.com>
parents: 7789
diff changeset
525
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11570
diff changeset
526 octave_idx_type
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
527 FloatEIG::symmetric_init (const FloatMatrix& a, const FloatMatrix& b,
22305
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
528 bool calc_rev, bool calc_lev)
8339
18c4ded8612a Add generalized eigenvalue functions
Jarkko Kaleva <d3roga@gmail.com>
parents: 7789
diff changeset
529 {
22988
cd33c785e80e put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22953
diff changeset
530 F77_INT n = octave::to_f77_int (a.rows ());
cd33c785e80e put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22953
diff changeset
531 F77_INT nb = octave::to_f77_int (b.rows ());
8339
18c4ded8612a Add generalized eigenvalue functions
Jarkko Kaleva <d3roga@gmail.com>
parents: 7789
diff changeset
532
22988
cd33c785e80e put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22953
diff changeset
533 F77_INT a_nc = octave::to_f77_int (a.cols ());
cd33c785e80e put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22953
diff changeset
534 F77_INT b_nc = octave::to_f77_int (b.cols ());
22953
fd649fd3db75 use F77_INT instead of octave_idx_type for liboctave EIG classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
535
fd649fd3db75 use F77_INT instead of octave_idx_type for liboctave EIG classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
536 if (n != a_nc || nb != b_nc)
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 20490
diff changeset
537 (*current_liboctave_error_handler) ("EIG requires square matrix");
8339
18c4ded8612a Add generalized eigenvalue functions
Jarkko Kaleva <d3roga@gmail.com>
parents: 7789
diff changeset
538
18c4ded8612a Add generalized eigenvalue functions
Jarkko Kaleva <d3roga@gmail.com>
parents: 7789
diff changeset
539 if (n != nb)
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 20490
diff changeset
540 (*current_liboctave_error_handler) ("EIG requires same size matrices");
8339
18c4ded8612a Add generalized eigenvalue functions
Jarkko Kaleva <d3roga@gmail.com>
parents: 7789
diff changeset
541
22953
fd649fd3db75 use F77_INT instead of octave_idx_type for liboctave EIG classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
542 F77_INT info = 0;
8339
18c4ded8612a Add generalized eigenvalue functions
Jarkko Kaleva <d3roga@gmail.com>
parents: 7789
diff changeset
543
18c4ded8612a Add generalized eigenvalue functions
Jarkko Kaleva <d3roga@gmail.com>
parents: 7789
diff changeset
544 FloatMatrix atmp = a;
32660
f53ac65ffba6 maint: New method rwdata() as clearer alternative to fortran_vec().
Rik <rik@octave.org>
parents: 32632
diff changeset
545 float *atmp_data = atmp.rwdata ();
8339
18c4ded8612a Add generalized eigenvalue functions
Jarkko Kaleva <d3roga@gmail.com>
parents: 7789
diff changeset
546
18c4ded8612a Add generalized eigenvalue functions
Jarkko Kaleva <d3roga@gmail.com>
parents: 7789
diff changeset
547 FloatMatrix btmp = b;
32660
f53ac65ffba6 maint: New method rwdata() as clearer alternative to fortran_vec().
Rik <rik@octave.org>
parents: 32632
diff changeset
548 float *btmp_data = btmp.rwdata ();
8339
18c4ded8612a Add generalized eigenvalue functions
Jarkko Kaleva <d3roga@gmail.com>
parents: 7789
diff changeset
549
18c4ded8612a Add generalized eigenvalue functions
Jarkko Kaleva <d3roga@gmail.com>
parents: 7789
diff changeset
550 FloatColumnVector wr (n);
32660
f53ac65ffba6 maint: New method rwdata() as clearer alternative to fortran_vec().
Rik <rik@octave.org>
parents: 32632
diff changeset
551 float *pwr = wr.rwdata ();
8339
18c4ded8612a Add generalized eigenvalue functions
Jarkko Kaleva <d3roga@gmail.com>
parents: 7789
diff changeset
552
22953
fd649fd3db75 use F77_INT instead of octave_idx_type for liboctave EIG classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
553 F77_INT lwork = -1;
8339
18c4ded8612a Add generalized eigenvalue functions
Jarkko Kaleva <d3roga@gmail.com>
parents: 7789
diff changeset
554 float dummy_work;
18c4ded8612a Add generalized eigenvalue functions
Jarkko Kaleva <d3roga@gmail.com>
parents: 7789
diff changeset
555
22305
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
556 F77_XFCN (ssygv, SSYGV, (1, F77_CONST_CHAR_ARG2 (calc_rev ? "V" : "N", 1),
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
557 F77_CONST_CHAR_ARG2 ("U", 1),
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11570
diff changeset
558 n, atmp_data, n,
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11570
diff changeset
559 btmp_data, n,
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
560 pwr, &dummy_work, lwork, info
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
561 F77_CHAR_ARG_LEN (1)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
562 F77_CHAR_ARG_LEN (1)));
8339
18c4ded8612a Add generalized eigenvalue functions
Jarkko Kaleva <d3roga@gmail.com>
parents: 7789
diff changeset
563
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 20490
diff changeset
564 if (info != 0)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 20490
diff changeset
565 (*current_liboctave_error_handler) ("ssygv workspace query failed");
8339
18c4ded8612a Add generalized eigenvalue functions
Jarkko Kaleva <d3roga@gmail.com>
parents: 7789
diff changeset
566
22953
fd649fd3db75 use F77_INT instead of octave_idx_type for liboctave EIG classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
567 lwork = static_cast<F77_INT> (dummy_work);
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 20490
diff changeset
568 Array<float> work (dim_vector (lwork, 1));
32660
f53ac65ffba6 maint: New method rwdata() as clearer alternative to fortran_vec().
Rik <rik@octave.org>
parents: 32632
diff changeset
569 float *pwork = work.rwdata ();
8339
18c4ded8612a Add generalized eigenvalue functions
Jarkko Kaleva <d3roga@gmail.com>
parents: 7789
diff changeset
570
22305
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
571 F77_XFCN (ssygv, SSYGV, (1, F77_CONST_CHAR_ARG2 (calc_rev ? "V" : "N", 1),
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 20490
diff changeset
572 F77_CONST_CHAR_ARG2 ("U", 1),
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 20490
diff changeset
573 n, atmp_data, n,
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 20490
diff changeset
574 btmp_data, n,
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 20490
diff changeset
575 pwr, pwork, lwork, info
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 20490
diff changeset
576 F77_CHAR_ARG_LEN (1)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 20490
diff changeset
577 F77_CHAR_ARG_LEN (1)));
8339
18c4ded8612a Add generalized eigenvalue functions
Jarkko Kaleva <d3roga@gmail.com>
parents: 7789
diff changeset
578
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 20490
diff changeset
579 if (info < 0)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 20490
diff changeset
580 (*current_liboctave_error_handler) ("unrecoverable error in ssygv");
8339
18c4ded8612a Add generalized eigenvalue functions
Jarkko Kaleva <d3roga@gmail.com>
parents: 7789
diff changeset
581
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 20490
diff changeset
582 if (info > 0)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 20490
diff changeset
583 (*current_liboctave_error_handler) ("ssygv failed to converge");
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 20490
diff changeset
584
30044
1f34286a2637 maint: use "m_" prefix for member variables of classes associated with EIG.
Rik <rik@octave.org>
parents: 29358
diff changeset
585 m_lambda = FloatComplexColumnVector (wr);
1f34286a2637 maint: use "m_" prefix for member variables of classes associated with EIG.
Rik <rik@octave.org>
parents: 29358
diff changeset
586 m_v = (calc_rev ? FloatComplexMatrix (atmp) : FloatComplexMatrix ());
1f34286a2637 maint: use "m_" prefix for member variables of classes associated with EIG.
Rik <rik@octave.org>
parents: 29358
diff changeset
587 m_w = (calc_lev ? FloatComplexMatrix (atmp) : FloatComplexMatrix ());
8339
18c4ded8612a Add generalized eigenvalue functions
Jarkko Kaleva <d3roga@gmail.com>
parents: 7789
diff changeset
588
18c4ded8612a Add generalized eigenvalue functions
Jarkko Kaleva <d3roga@gmail.com>
parents: 7789
diff changeset
589 return info;
18c4ded8612a Add generalized eigenvalue functions
Jarkko Kaleva <d3roga@gmail.com>
parents: 7789
diff changeset
590 }
18c4ded8612a Add generalized eigenvalue functions
Jarkko Kaleva <d3roga@gmail.com>
parents: 7789
diff changeset
591
18c4ded8612a Add generalized eigenvalue functions
Jarkko Kaleva <d3roga@gmail.com>
parents: 7789
diff changeset
592 octave_idx_type
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
593 FloatEIG::init (const FloatComplexMatrix& a, const FloatComplexMatrix& b,
22305
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
594 bool calc_rev, bool calc_lev, bool force_qz)
8339
18c4ded8612a Add generalized eigenvalue functions
Jarkko Kaleva <d3roga@gmail.com>
parents: 7789
diff changeset
595 {
18c4ded8612a Add generalized eigenvalue functions
Jarkko Kaleva <d3roga@gmail.com>
parents: 7789
diff changeset
596 if (a.any_element_is_inf_or_nan () || b.any_element_is_inf_or_nan ())
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 20490
diff changeset
597 (*current_liboctave_error_handler)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 20490
diff changeset
598 ("EIG: matrix contains Inf or NaN values");
8339
18c4ded8612a Add generalized eigenvalue functions
Jarkko Kaleva <d3roga@gmail.com>
parents: 7789
diff changeset
599
22988
cd33c785e80e put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22953
diff changeset
600 F77_INT n = octave::to_f77_int (a.rows ());
cd33c785e80e put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22953
diff changeset
601 F77_INT nb = octave::to_f77_int (b.rows ());
8339
18c4ded8612a Add generalized eigenvalue functions
Jarkko Kaleva <d3roga@gmail.com>
parents: 7789
diff changeset
602
22988
cd33c785e80e put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22953
diff changeset
603 F77_INT a_nc = octave::to_f77_int (a.cols ());
cd33c785e80e put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22953
diff changeset
604 F77_INT b_nc = octave::to_f77_int (b.cols ());
22953
fd649fd3db75 use F77_INT instead of octave_idx_type for liboctave EIG classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
605
fd649fd3db75 use F77_INT instead of octave_idx_type for liboctave EIG classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
606 if (n != a_nc || nb != b_nc)
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 20490
diff changeset
607 (*current_liboctave_error_handler) ("EIG requires square matrix");
8339
18c4ded8612a Add generalized eigenvalue functions
Jarkko Kaleva <d3roga@gmail.com>
parents: 7789
diff changeset
608
18c4ded8612a Add generalized eigenvalue functions
Jarkko Kaleva <d3roga@gmail.com>
parents: 7789
diff changeset
609 if (n != nb)
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 20490
diff changeset
610 (*current_liboctave_error_handler) ("EIG requires same size matrices");
8339
18c4ded8612a Add generalized eigenvalue functions
Jarkko Kaleva <d3roga@gmail.com>
parents: 7789
diff changeset
611
22953
fd649fd3db75 use F77_INT instead of octave_idx_type for liboctave EIG classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
612 F77_INT info = 0;
8339
18c4ded8612a Add generalized eigenvalue functions
Jarkko Kaleva <d3roga@gmail.com>
parents: 7789
diff changeset
613
18c4ded8612a Add generalized eigenvalue functions
Jarkko Kaleva <d3roga@gmail.com>
parents: 7789
diff changeset
614 FloatComplexMatrix tmp = b;
32660
f53ac65ffba6 maint: New method rwdata() as clearer alternative to fortran_vec().
Rik <rik@octave.org>
parents: 32632
diff changeset
615 FloatComplex *tmp_data = tmp.rwdata ();
8339
18c4ded8612a Add generalized eigenvalue functions
Jarkko Kaleva <d3roga@gmail.com>
parents: 7789
diff changeset
616
22305
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
617 if (! force_qz)
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
618 {
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
619 F77_XFCN (cpotrf, CPOTRF, (F77_CONST_CHAR_ARG2 ("L", 1),
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
620 n, F77_CMPLX_ARG (tmp_data), n,
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
621 info
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
622 F77_CHAR_ARG_LEN (1)));
8339
18c4ded8612a Add generalized eigenvalue functions
Jarkko Kaleva <d3roga@gmail.com>
parents: 7789
diff changeset
623
23594
af5b813503cb maint: Deprecate is_hermitian and replace with ishermitian.
Rik <rik@octave.org>
parents: 23475
diff changeset
624 if (a.ishermitian () && b.ishermitian () && info == 0)
22305
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
625 return hermitian_init (a, b, calc_rev, calc_lev);
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
626 }
8339
18c4ded8612a Add generalized eigenvalue functions
Jarkko Kaleva <d3roga@gmail.com>
parents: 7789
diff changeset
627
18c4ded8612a Add generalized eigenvalue functions
Jarkko Kaleva <d3roga@gmail.com>
parents: 7789
diff changeset
628 FloatComplexMatrix atmp = a;
32660
f53ac65ffba6 maint: New method rwdata() as clearer alternative to fortran_vec().
Rik <rik@octave.org>
parents: 32632
diff changeset
629 FloatComplex *atmp_data = atmp.rwdata ();
8339
18c4ded8612a Add generalized eigenvalue functions
Jarkko Kaleva <d3roga@gmail.com>
parents: 7789
diff changeset
630
18c4ded8612a Add generalized eigenvalue functions
Jarkko Kaleva <d3roga@gmail.com>
parents: 7789
diff changeset
631 FloatComplexMatrix btmp = b;
32660
f53ac65ffba6 maint: New method rwdata() as clearer alternative to fortran_vec().
Rik <rik@octave.org>
parents: 32632
diff changeset
632 FloatComplex *btmp_data = btmp.rwdata ();
8339
18c4ded8612a Add generalized eigenvalue functions
Jarkko Kaleva <d3roga@gmail.com>
parents: 7789
diff changeset
633
18c4ded8612a Add generalized eigenvalue functions
Jarkko Kaleva <d3roga@gmail.com>
parents: 7789
diff changeset
634 FloatComplexColumnVector alpha (n);
32660
f53ac65ffba6 maint: New method rwdata() as clearer alternative to fortran_vec().
Rik <rik@octave.org>
parents: 32632
diff changeset
635 FloatComplex *palpha = alpha.rwdata ();
8339
18c4ded8612a Add generalized eigenvalue functions
Jarkko Kaleva <d3roga@gmail.com>
parents: 7789
diff changeset
636
18c4ded8612a Add generalized eigenvalue functions
Jarkko Kaleva <d3roga@gmail.com>
parents: 7789
diff changeset
637 FloatComplexColumnVector beta (n);
32660
f53ac65ffba6 maint: New method rwdata() as clearer alternative to fortran_vec().
Rik <rik@octave.org>
parents: 32632
diff changeset
638 FloatComplex *pbeta = beta.rwdata ();
8339
18c4ded8612a Add generalized eigenvalue functions
Jarkko Kaleva <d3roga@gmail.com>
parents: 7789
diff changeset
639
23450
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23220
diff changeset
640 F77_INT nvr = (calc_rev ? n : 0);
22305
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
641 FloatComplexMatrix vrtmp (nvr, nvr);
32660
f53ac65ffba6 maint: New method rwdata() as clearer alternative to fortran_vec().
Rik <rik@octave.org>
parents: 32632
diff changeset
642 FloatComplex *pvr = vrtmp.rwdata ();
22305
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
643
23450
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23220
diff changeset
644 F77_INT nvl = (calc_lev ? n : 0);
22305
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
645 FloatComplexMatrix vltmp (nvl, nvl);
32660
f53ac65ffba6 maint: New method rwdata() as clearer alternative to fortran_vec().
Rik <rik@octave.org>
parents: 32632
diff changeset
646 FloatComplex *pvl = vltmp.rwdata ();
8339
18c4ded8612a Add generalized eigenvalue functions
Jarkko Kaleva <d3roga@gmail.com>
parents: 7789
diff changeset
647
22953
fd649fd3db75 use F77_INT instead of octave_idx_type for liboctave EIG classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
648 F77_INT lwork = -1;
8339
18c4ded8612a Add generalized eigenvalue functions
Jarkko Kaleva <d3roga@gmail.com>
parents: 7789
diff changeset
649 FloatComplex dummy_work;
18c4ded8612a Add generalized eigenvalue functions
Jarkko Kaleva <d3roga@gmail.com>
parents: 7789
diff changeset
650
22953
fd649fd3db75 use F77_INT instead of octave_idx_type for liboctave EIG classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
651 F77_INT lrwork = 8*n;
11570
57632dea2446 attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
652 Array<float> rwork (dim_vector (lrwork, 1));
32660
f53ac65ffba6 maint: New method rwdata() as clearer alternative to fortran_vec().
Rik <rik@octave.org>
parents: 32632
diff changeset
653 float *prwork = rwork.rwdata ();
8339
18c4ded8612a Add generalized eigenvalue functions
Jarkko Kaleva <d3roga@gmail.com>
parents: 7789
diff changeset
654
22305
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
655 F77_XFCN (cggev, CGGEV, (F77_CONST_CHAR_ARG2 (calc_lev ? "V" : "N", 1),
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
656 F77_CONST_CHAR_ARG2 (calc_rev ? "V" : "N", 1),
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
657 n, F77_CMPLX_ARG (atmp_data), n,
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
658 F77_CMPLX_ARG (btmp_data), n,
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
659 F77_CMPLX_ARG (palpha), F77_CMPLX_ARG (pbeta),
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
660 F77_CMPLX_ARG (pvl), n, F77_CMPLX_ARG (pvr), n,
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
661 F77_CMPLX_ARG (&dummy_work), lwork, prwork, info
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
662 F77_CHAR_ARG_LEN (1)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
663 F77_CHAR_ARG_LEN (1)));
8339
18c4ded8612a Add generalized eigenvalue functions
Jarkko Kaleva <d3roga@gmail.com>
parents: 7789
diff changeset
664
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 20490
diff changeset
665 if (info != 0)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 20490
diff changeset
666 (*current_liboctave_error_handler) ("cggev workspace query failed");
8339
18c4ded8612a Add generalized eigenvalue functions
Jarkko Kaleva <d3roga@gmail.com>
parents: 7789
diff changeset
667
22953
fd649fd3db75 use F77_INT instead of octave_idx_type for liboctave EIG classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
668 lwork = static_cast<F77_INT> (dummy_work.real ());
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 20490
diff changeset
669 Array<FloatComplex> work (dim_vector (lwork, 1));
32660
f53ac65ffba6 maint: New method rwdata() as clearer alternative to fortran_vec().
Rik <rik@octave.org>
parents: 32632
diff changeset
670 FloatComplex *pwork = work.rwdata ();
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11570
diff changeset
671
22305
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
672 F77_XFCN (cggev, CGGEV, (F77_CONST_CHAR_ARG2 (calc_lev ? "V" : "N", 1),
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
673 F77_CONST_CHAR_ARG2 (calc_rev ? "V" : "N", 1),
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
674 n, F77_CMPLX_ARG (atmp_data), n,
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
675 F77_CMPLX_ARG (btmp_data), n,
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
676 F77_CMPLX_ARG (palpha), F77_CMPLX_ARG (pbeta),
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
677 F77_CMPLX_ARG (pvl), n, F77_CMPLX_ARG (pvr), n,
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
678 F77_CMPLX_ARG (pwork), lwork, prwork, info
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 20490
diff changeset
679 F77_CHAR_ARG_LEN (1)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 20490
diff changeset
680 F77_CHAR_ARG_LEN (1)));
8339
18c4ded8612a Add generalized eigenvalue functions
Jarkko Kaleva <d3roga@gmail.com>
parents: 7789
diff changeset
681
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 20490
diff changeset
682 if (info < 0)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 20490
diff changeset
683 (*current_liboctave_error_handler) ("unrecoverable error in cggev");
8339
18c4ded8612a Add generalized eigenvalue functions
Jarkko Kaleva <d3roga@gmail.com>
parents: 7789
diff changeset
684
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 20490
diff changeset
685 if (info > 0)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 20490
diff changeset
686 (*current_liboctave_error_handler) ("cggev failed to converge");
8339
18c4ded8612a Add generalized eigenvalue functions
Jarkko Kaleva <d3roga@gmail.com>
parents: 7789
diff changeset
687
30044
1f34286a2637 maint: use "m_" prefix for member variables of classes associated with EIG.
Rik <rik@octave.org>
parents: 29358
diff changeset
688 m_lambda.resize (n);
8339
18c4ded8612a Add generalized eigenvalue functions
Jarkko Kaleva <d3roga@gmail.com>
parents: 7789
diff changeset
689
22953
fd649fd3db75 use F77_INT instead of octave_idx_type for liboctave EIG classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
690 for (F77_INT j = 0; j < n; j++)
30044
1f34286a2637 maint: use "m_" prefix for member variables of classes associated with EIG.
Rik <rik@octave.org>
parents: 29358
diff changeset
691 m_lambda.elem (j) = alpha.elem (j) / beta.elem (j);
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 20490
diff changeset
692
30044
1f34286a2637 maint: use "m_" prefix for member variables of classes associated with EIG.
Rik <rik@octave.org>
parents: 29358
diff changeset
693 m_v = vrtmp;
1f34286a2637 maint: use "m_" prefix for member variables of classes associated with EIG.
Rik <rik@octave.org>
parents: 29358
diff changeset
694 m_w = vltmp;
8339
18c4ded8612a Add generalized eigenvalue functions
Jarkko Kaleva <d3roga@gmail.com>
parents: 7789
diff changeset
695
18c4ded8612a Add generalized eigenvalue functions
Jarkko Kaleva <d3roga@gmail.com>
parents: 7789
diff changeset
696 return info;
18c4ded8612a Add generalized eigenvalue functions
Jarkko Kaleva <d3roga@gmail.com>
parents: 7789
diff changeset
697 }
18c4ded8612a Add generalized eigenvalue functions
Jarkko Kaleva <d3roga@gmail.com>
parents: 7789
diff changeset
698
18c4ded8612a Add generalized eigenvalue functions
Jarkko Kaleva <d3roga@gmail.com>
parents: 7789
diff changeset
699 octave_idx_type
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
700 FloatEIG::hermitian_init (const FloatComplexMatrix& a,
22305
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
701 const FloatComplexMatrix& b,
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
702 bool calc_rev, bool calc_lev)
8339
18c4ded8612a Add generalized eigenvalue functions
Jarkko Kaleva <d3roga@gmail.com>
parents: 7789
diff changeset
703 {
22988
cd33c785e80e put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22953
diff changeset
704 F77_INT n = octave::to_f77_int (a.rows ());
cd33c785e80e put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22953
diff changeset
705 F77_INT nb = octave::to_f77_int (b.rows ());
8339
18c4ded8612a Add generalized eigenvalue functions
Jarkko Kaleva <d3roga@gmail.com>
parents: 7789
diff changeset
706
22988
cd33c785e80e put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22953
diff changeset
707 F77_INT a_nc = octave::to_f77_int (a.cols ());
cd33c785e80e put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22953
diff changeset
708 F77_INT b_nc = octave::to_f77_int (b.cols ());
22953
fd649fd3db75 use F77_INT instead of octave_idx_type for liboctave EIG classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
709
fd649fd3db75 use F77_INT instead of octave_idx_type for liboctave EIG classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
710 if (n != a_nc || nb != b_nc)
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 20490
diff changeset
711 (*current_liboctave_error_handler) ("EIG requires square matrix");
8339
18c4ded8612a Add generalized eigenvalue functions
Jarkko Kaleva <d3roga@gmail.com>
parents: 7789
diff changeset
712
18c4ded8612a Add generalized eigenvalue functions
Jarkko Kaleva <d3roga@gmail.com>
parents: 7789
diff changeset
713 if (n != nb)
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 20490
diff changeset
714 (*current_liboctave_error_handler) ("EIG requires same size matrices");
8339
18c4ded8612a Add generalized eigenvalue functions
Jarkko Kaleva <d3roga@gmail.com>
parents: 7789
diff changeset
715
22953
fd649fd3db75 use F77_INT instead of octave_idx_type for liboctave EIG classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
716 F77_INT info = 0;
8339
18c4ded8612a Add generalized eigenvalue functions
Jarkko Kaleva <d3roga@gmail.com>
parents: 7789
diff changeset
717
18c4ded8612a Add generalized eigenvalue functions
Jarkko Kaleva <d3roga@gmail.com>
parents: 7789
diff changeset
718 FloatComplexMatrix atmp = a;
32660
f53ac65ffba6 maint: New method rwdata() as clearer alternative to fortran_vec().
Rik <rik@octave.org>
parents: 32632
diff changeset
719 FloatComplex *atmp_data = atmp.rwdata ();
8339
18c4ded8612a Add generalized eigenvalue functions
Jarkko Kaleva <d3roga@gmail.com>
parents: 7789
diff changeset
720
18c4ded8612a Add generalized eigenvalue functions
Jarkko Kaleva <d3roga@gmail.com>
parents: 7789
diff changeset
721 FloatComplexMatrix btmp = b;
32660
f53ac65ffba6 maint: New method rwdata() as clearer alternative to fortran_vec().
Rik <rik@octave.org>
parents: 32632
diff changeset
722 FloatComplex *btmp_data = btmp.rwdata ();
8339
18c4ded8612a Add generalized eigenvalue functions
Jarkko Kaleva <d3roga@gmail.com>
parents: 7789
diff changeset
723
18c4ded8612a Add generalized eigenvalue functions
Jarkko Kaleva <d3roga@gmail.com>
parents: 7789
diff changeset
724 FloatColumnVector wr (n);
32660
f53ac65ffba6 maint: New method rwdata() as clearer alternative to fortran_vec().
Rik <rik@octave.org>
parents: 32632
diff changeset
725 float *pwr = wr.rwdata ();
8339
18c4ded8612a Add generalized eigenvalue functions
Jarkko Kaleva <d3roga@gmail.com>
parents: 7789
diff changeset
726
22953
fd649fd3db75 use F77_INT instead of octave_idx_type for liboctave EIG classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
727 F77_INT lwork = -1;
8339
18c4ded8612a Add generalized eigenvalue functions
Jarkko Kaleva <d3roga@gmail.com>
parents: 7789
diff changeset
728 FloatComplex dummy_work;
18c4ded8612a Add generalized eigenvalue functions
Jarkko Kaleva <d3roga@gmail.com>
parents: 7789
diff changeset
729
22953
fd649fd3db75 use F77_INT instead of octave_idx_type for liboctave EIG classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
730 F77_INT lrwork = 3*n;
11570
57632dea2446 attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
731 Array<float> rwork (dim_vector (lrwork, 1));
32660
f53ac65ffba6 maint: New method rwdata() as clearer alternative to fortran_vec().
Rik <rik@octave.org>
parents: 32632
diff changeset
732 float *prwork = rwork.rwdata ();
8339
18c4ded8612a Add generalized eigenvalue functions
Jarkko Kaleva <d3roga@gmail.com>
parents: 7789
diff changeset
733
22305
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
734 F77_XFCN (chegv, CHEGV, (1, F77_CONST_CHAR_ARG2 (calc_rev ? "V" : "N", 1),
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
735 F77_CONST_CHAR_ARG2 ("U", 1),
22135
407c66ae1e20 reduce warnings from GCC's link-time optimization feature (bug #48531)
John W. Eaton <jwe@octave.org>
parents: 22133
diff changeset
736 n, F77_CMPLX_ARG (atmp_data), n,
407c66ae1e20 reduce warnings from GCC's link-time optimization feature (bug #48531)
John W. Eaton <jwe@octave.org>
parents: 22133
diff changeset
737 F77_CMPLX_ARG (btmp_data), n,
407c66ae1e20 reduce warnings from GCC's link-time optimization feature (bug #48531)
John W. Eaton <jwe@octave.org>
parents: 22133
diff changeset
738 pwr, F77_CMPLX_ARG (&dummy_work), lwork,
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
739 prwork, info
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
740 F77_CHAR_ARG_LEN (1)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
741 F77_CHAR_ARG_LEN (1)));
8339
18c4ded8612a Add generalized eigenvalue functions
Jarkko Kaleva <d3roga@gmail.com>
parents: 7789
diff changeset
742
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 20490
diff changeset
743 if (info != 0)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 20490
diff changeset
744 (*current_liboctave_error_handler) ("zhegv workspace query failed");
8339
18c4ded8612a Add generalized eigenvalue functions
Jarkko Kaleva <d3roga@gmail.com>
parents: 7789
diff changeset
745
22953
fd649fd3db75 use F77_INT instead of octave_idx_type for liboctave EIG classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
746 lwork = static_cast<F77_INT> (dummy_work.real ());
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 20490
diff changeset
747 Array<FloatComplex> work (dim_vector (lwork, 1));
32660
f53ac65ffba6 maint: New method rwdata() as clearer alternative to fortran_vec().
Rik <rik@octave.org>
parents: 32632
diff changeset
748 FloatComplex *pwork = work.rwdata ();
8339
18c4ded8612a Add generalized eigenvalue functions
Jarkko Kaleva <d3roga@gmail.com>
parents: 7789
diff changeset
749
22305
510886d03ef2 eig: new options for choice of algorithm, balancing, and output (patch #8960)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22135
diff changeset
750 F77_XFCN (chegv, CHEGV, (1, F77_CONST_CHAR_ARG2 (calc_rev ? "V" : "N", 1),
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 20490
diff changeset
751 F77_CONST_CHAR_ARG2 ("U", 1),
22135
407c66ae1e20 reduce warnings from GCC's link-time optimization feature (bug #48531)
John W. Eaton <jwe@octave.org>
parents: 22133
diff changeset
752 n, F77_CMPLX_ARG (atmp_data), n,
407c66ae1e20 reduce warnings from GCC's link-time optimization feature (bug #48531)
John W. Eaton <jwe@octave.org>
parents: 22133
diff changeset
753 F77_CMPLX_ARG (btmp_data), n,
407c66ae1e20 reduce warnings from GCC's link-time optimization feature (bug #48531)
John W. Eaton <jwe@octave.org>
parents: 22133
diff changeset
754 pwr, F77_CMPLX_ARG (pwork), lwork, prwork, info
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 20490
diff changeset
755 F77_CHAR_ARG_LEN (1)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 20490
diff changeset
756 F77_CHAR_ARG_LEN (1)));
8339
18c4ded8612a Add generalized eigenvalue functions
Jarkko Kaleva <d3roga@gmail.com>
parents: 7789
diff changeset
757
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 20490
diff changeset
758 if (info < 0)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 20490
diff changeset
759 (*current_liboctave_error_handler) ("unrecoverable error in zhegv");
8339
18c4ded8612a Add generalized eigenvalue functions
Jarkko Kaleva <d3roga@gmail.com>
parents: 7789
diff changeset
760
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 20490
diff changeset
761 if (info > 0)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 20490
diff changeset
762 (*current_liboctave_error_handler) ("zhegv failed to converge");
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 20490
diff changeset
763
30044
1f34286a2637 maint: use "m_" prefix for member variables of classes associated with EIG.
Rik <rik@octave.org>
parents: 29358
diff changeset
764 m_lambda = FloatComplexColumnVector (wr);
1f34286a2637 maint: use "m_" prefix for member variables of classes associated with EIG.
Rik <rik@octave.org>
parents: 29358
diff changeset
765 m_v = (calc_rev ? FloatComplexMatrix (atmp) : FloatComplexMatrix ());
1f34286a2637 maint: use "m_" prefix for member variables of classes associated with EIG.
Rik <rik@octave.org>
parents: 29358
diff changeset
766 m_w = (calc_lev ? FloatComplexMatrix (atmp) : FloatComplexMatrix ());
8339
18c4ded8612a Add generalized eigenvalue functions
Jarkko Kaleva <d3roga@gmail.com>
parents: 7789
diff changeset
767
18c4ded8612a Add generalized eigenvalue functions
Jarkko Kaleva <d3roga@gmail.com>
parents: 7789
diff changeset
768 return info;
18c4ded8612a Add generalized eigenvalue functions
Jarkko Kaleva <d3roga@gmail.com>
parents: 7789
diff changeset
769 }