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 |
|
9 Free Software Foundation; either version 2, or (at your option) any |
|
10 later version. |
|
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 |
|
18 along with Octave; see the file COPYING. If not, write to the Free |
1315
|
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
457
|
20 |
|
21 */ |
|
22 |
4192
|
23 #if defined (__GNUG__) && defined (USE_PRAGMA_INTERFACE_IMPLEMENTATION) |
1296
|
24 #pragma implementation |
|
25 #endif |
|
26 |
457
|
27 #ifdef HAVE_CONFIG_H |
1192
|
28 #include <config.h> |
457
|
29 #endif |
|
30 |
|
31 #include "CmplxSCHUR.h" |
1847
|
32 #include "f77-fcn.h" |
457
|
33 #include "lo-error.h" |
|
34 |
|
35 extern "C" |
|
36 { |
4552
|
37 F77_RET_T |
|
38 F77_FUNC (zgeesx, ZGEESX) (F77_CONST_CHAR_ARG_DECL, |
|
39 F77_CONST_CHAR_ARG_DECL, |
|
40 ComplexSCHUR::select_function, |
|
41 F77_CONST_CHAR_ARG_DECL, |
|
42 const int&, Complex*, const int&, int&, |
|
43 Complex*, Complex*, const int&, double&, |
|
44 double&, Complex*, const int&, double*, int*, |
|
45 int& |
|
46 F77_CHAR_ARG_LEN_DECL |
|
47 F77_CHAR_ARG_LEN_DECL |
|
48 F77_CHAR_ARG_LEN_DECL); |
457
|
49 } |
|
50 |
|
51 static int |
1929
|
52 select_ana (const Complex& a) |
457
|
53 { |
1251
|
54 return a.real () < 0.0; |
457
|
55 } |
|
56 |
|
57 static int |
1929
|
58 select_dig (const Complex& a) |
457
|
59 { |
1251
|
60 return (abs (a) < 1.0); |
457
|
61 } |
|
62 |
|
63 int |
3504
|
64 ComplexSCHUR::init (const ComplexMatrix& a, const std::string& ord) |
457
|
65 { |
|
66 int a_nr = a.rows (); |
|
67 int a_nc = a.cols (); |
1929
|
68 |
457
|
69 if (a_nr != a_nc) |
|
70 { |
|
71 (*current_liboctave_error_handler) |
|
72 ("ComplexSCHUR requires square matrix"); |
|
73 return -1; |
|
74 } |
|
75 |
3334
|
76 // Workspace requirements may need to be fixed if any of the |
|
77 // following change. |
|
78 |
1930
|
79 char jobvs = 'V'; |
|
80 char sense = 'N'; |
|
81 char sort = 'N'; |
1756
|
82 |
|
83 char ord_char = ord.empty () ? 'U' : ord[0]; |
|
84 |
|
85 if (ord_char == 'A' || ord_char == 'D' || ord_char == 'a' || ord_char == 'd') |
1930
|
86 sort = 'S'; |
457
|
87 |
1929
|
88 if (ord_char == 'A' || ord_char == 'a') |
|
89 selector = select_ana; |
|
90 else if (ord_char == 'D' || ord_char == 'd') |
|
91 selector = select_dig; |
1930
|
92 else |
|
93 selector = 0; |
457
|
94 |
|
95 int n = a_nc; |
|
96 int lwork = 8 * n; |
|
97 int info; |
|
98 int sdim; |
|
99 double rconde; |
|
100 double rcondv; |
|
101 |
1929
|
102 schur_mat = a; |
|
103 unitary_mat.resize (n, n); |
|
104 |
|
105 Complex *s = schur_mat.fortran_vec (); |
|
106 Complex *q = unitary_mat.fortran_vec (); |
|
107 |
|
108 Array<double> rwork (n); |
|
109 double *prwork = rwork.fortran_vec (); |
|
110 |
|
111 Array<Complex> w (n); |
|
112 Complex *pw = w.fortran_vec (); |
|
113 |
|
114 Array<Complex> work (lwork); |
|
115 Complex *pwork = work.fortran_vec (); |
457
|
116 |
3334
|
117 // BWORK is not referenced for non-ordered Schur. |
|
118 Array<int> bwork ((ord_char == 'N' || ord_char == 'n') ? 0 : n); |
1929
|
119 int *pbwork = bwork.fortran_vec (); |
457
|
120 |
4552
|
121 F77_XFCN (zgeesx, ZGEESX, (F77_CONST_CHAR_ARG2 (&jobvs, 1), |
|
122 F77_CONST_CHAR_ARG2 (&sort, 1), |
|
123 selector, |
|
124 F77_CONST_CHAR_ARG2 (&sense, 1), |
|
125 n, s, n, sdim, pw, q, n, rconde, rcondv, |
|
126 pwork, lwork, prwork, pbwork, info |
|
127 F77_CHAR_ARG_LEN (1) |
|
128 F77_CHAR_ARG_LEN (1) |
|
129 F77_CHAR_ARG_LEN (1))); |
457
|
130 |
1929
|
131 if (f77_exception_encountered) |
|
132 (*current_liboctave_error_handler) ("unrecoverable error in zgeesx"); |
457
|
133 |
|
134 return info; |
|
135 } |
|
136 |
|
137 /* |
|
138 ;;; Local Variables: *** |
|
139 ;;; mode: C++ *** |
|
140 ;;; End: *** |
|
141 */ |