457
|
1 /* |
|
2 |
2847
|
3 Copyright (C) 1996, 1997 John W. Eaton |
457
|
4 |
|
5 This file is part of Octave. |
|
6 |
|
7 Octave is free software; you can redistribute it and/or modify it |
|
8 under the terms of the GNU General Public License as published by the |
7016
|
9 Free Software Foundation; either version 3 of the License, or (at your |
|
10 option) any later version. |
457
|
11 |
|
12 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
15 for more details. |
|
16 |
|
17 You should have received a copy of the GNU General Public License |
7016
|
18 along with Octave; see the file COPYING. If not, see |
|
19 <http://www.gnu.org/licenses/>. |
457
|
20 |
|
21 */ |
|
22 |
|
23 #ifdef HAVE_CONFIG_H |
1192
|
24 #include <config.h> |
457
|
25 #endif |
|
26 |
|
27 #include "CmplxSCHUR.h" |
1847
|
28 #include "f77-fcn.h" |
457
|
29 #include "lo-error.h" |
|
30 |
|
31 extern "C" |
|
32 { |
4552
|
33 F77_RET_T |
|
34 F77_FUNC (zgeesx, ZGEESX) (F77_CONST_CHAR_ARG_DECL, |
|
35 F77_CONST_CHAR_ARG_DECL, |
|
36 ComplexSCHUR::select_function, |
|
37 F77_CONST_CHAR_ARG_DECL, |
5275
|
38 const octave_idx_type&, Complex*, const octave_idx_type&, octave_idx_type&, |
|
39 Complex*, Complex*, const octave_idx_type&, double&, |
|
40 double&, Complex*, const octave_idx_type&, double*, octave_idx_type*, |
|
41 octave_idx_type& |
4552
|
42 F77_CHAR_ARG_LEN_DECL |
|
43 F77_CHAR_ARG_LEN_DECL |
|
44 F77_CHAR_ARG_LEN_DECL); |
457
|
45 } |
|
46 |
5275
|
47 static octave_idx_type |
1929
|
48 select_ana (const Complex& a) |
457
|
49 { |
1251
|
50 return a.real () < 0.0; |
457
|
51 } |
|
52 |
5275
|
53 static octave_idx_type |
1929
|
54 select_dig (const Complex& a) |
457
|
55 { |
1251
|
56 return (abs (a) < 1.0); |
457
|
57 } |
|
58 |
5275
|
59 octave_idx_type |
5008
|
60 ComplexSCHUR::init (const ComplexMatrix& a, const std::string& ord, |
|
61 bool calc_unitary) |
457
|
62 { |
5275
|
63 octave_idx_type a_nr = a.rows (); |
|
64 octave_idx_type a_nc = a.cols (); |
1929
|
65 |
457
|
66 if (a_nr != a_nc) |
|
67 { |
|
68 (*current_liboctave_error_handler) |
|
69 ("ComplexSCHUR requires square matrix"); |
|
70 return -1; |
|
71 } |
|
72 |
3334
|
73 // Workspace requirements may need to be fixed if any of the |
|
74 // following change. |
|
75 |
5008
|
76 char jobvs; |
1930
|
77 char sense = 'N'; |
|
78 char sort = 'N'; |
1756
|
79 |
5008
|
80 if (calc_unitary) |
|
81 jobvs = 'V'; |
|
82 else |
|
83 jobvs = 'N'; |
|
84 |
1756
|
85 char ord_char = ord.empty () ? 'U' : ord[0]; |
|
86 |
|
87 if (ord_char == 'A' || ord_char == 'D' || ord_char == 'a' || ord_char == 'd') |
1930
|
88 sort = 'S'; |
457
|
89 |
1929
|
90 if (ord_char == 'A' || ord_char == 'a') |
|
91 selector = select_ana; |
|
92 else if (ord_char == 'D' || ord_char == 'd') |
|
93 selector = select_dig; |
1930
|
94 else |
|
95 selector = 0; |
457
|
96 |
5275
|
97 octave_idx_type n = a_nc; |
|
98 octave_idx_type lwork = 8 * n; |
|
99 octave_idx_type info; |
|
100 octave_idx_type sdim; |
457
|
101 double rconde; |
|
102 double rcondv; |
|
103 |
1929
|
104 schur_mat = a; |
5008
|
105 if (calc_unitary) |
|
106 unitary_mat.resize (n, n); |
1929
|
107 |
|
108 Complex *s = schur_mat.fortran_vec (); |
|
109 Complex *q = unitary_mat.fortran_vec (); |
|
110 |
|
111 Array<double> rwork (n); |
|
112 double *prwork = rwork.fortran_vec (); |
|
113 |
|
114 Array<Complex> w (n); |
|
115 Complex *pw = w.fortran_vec (); |
|
116 |
|
117 Array<Complex> work (lwork); |
|
118 Complex *pwork = work.fortran_vec (); |
457
|
119 |
3334
|
120 // BWORK is not referenced for non-ordered Schur. |
5275
|
121 Array<octave_idx_type> bwork ((ord_char == 'N' || ord_char == 'n') ? 0 : n); |
|
122 octave_idx_type *pbwork = bwork.fortran_vec (); |
457
|
123 |
4552
|
124 F77_XFCN (zgeesx, ZGEESX, (F77_CONST_CHAR_ARG2 (&jobvs, 1), |
|
125 F77_CONST_CHAR_ARG2 (&sort, 1), |
|
126 selector, |
|
127 F77_CONST_CHAR_ARG2 (&sense, 1), |
|
128 n, s, n, sdim, pw, q, n, rconde, rcondv, |
|
129 pwork, lwork, prwork, pbwork, info |
|
130 F77_CHAR_ARG_LEN (1) |
|
131 F77_CHAR_ARG_LEN (1) |
|
132 F77_CHAR_ARG_LEN (1))); |
457
|
133 |
1929
|
134 if (f77_exception_encountered) |
|
135 (*current_liboctave_error_handler) ("unrecoverable error in zgeesx"); |
457
|
136 |
|
137 return info; |
|
138 } |
|
139 |
|
140 /* |
|
141 ;;; Local Variables: *** |
|
142 ;;; mode: C++ *** |
|
143 ;;; End: *** |
|
144 */ |