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 |
1296
|
23 #if defined (__GNUG__) |
|
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 { |
1253
|
37 int F77_FCN (zgeesx, ZGEESX) (const char*, const char*, |
1929
|
38 ComplexSCHUR::select_function, |
1253
|
39 const char*, const int&, Complex*, |
|
40 const int&, int&, Complex*, Complex*, |
|
41 const int&, double&, double&, |
|
42 Complex*, const int&, double*, int*, |
3334
|
43 int&, long, long, long); |
457
|
44 } |
|
45 |
|
46 static int |
1929
|
47 select_ana (const Complex& a) |
457
|
48 { |
1251
|
49 return a.real () < 0.0; |
457
|
50 } |
|
51 |
|
52 static int |
1929
|
53 select_dig (const Complex& a) |
457
|
54 { |
1251
|
55 return (abs (a) < 1.0); |
457
|
56 } |
|
57 |
|
58 int |
3504
|
59 ComplexSCHUR::init (const ComplexMatrix& a, const std::string& ord) |
457
|
60 { |
|
61 int a_nr = a.rows (); |
|
62 int a_nc = a.cols (); |
1929
|
63 |
457
|
64 if (a_nr != a_nc) |
|
65 { |
|
66 (*current_liboctave_error_handler) |
|
67 ("ComplexSCHUR requires square matrix"); |
|
68 return -1; |
|
69 } |
|
70 |
3334
|
71 // Workspace requirements may need to be fixed if any of the |
|
72 // following change. |
|
73 |
1930
|
74 char jobvs = 'V'; |
|
75 char sense = 'N'; |
|
76 char sort = 'N'; |
1756
|
77 |
|
78 char ord_char = ord.empty () ? 'U' : ord[0]; |
|
79 |
|
80 if (ord_char == 'A' || ord_char == 'D' || ord_char == 'a' || ord_char == 'd') |
1930
|
81 sort = 'S'; |
457
|
82 |
1929
|
83 if (ord_char == 'A' || ord_char == 'a') |
|
84 selector = select_ana; |
|
85 else if (ord_char == 'D' || ord_char == 'd') |
|
86 selector = select_dig; |
1930
|
87 else |
|
88 selector = 0; |
457
|
89 |
|
90 int n = a_nc; |
|
91 int lwork = 8 * n; |
|
92 int info; |
|
93 int sdim; |
|
94 double rconde; |
|
95 double rcondv; |
|
96 |
1929
|
97 schur_mat = a; |
|
98 unitary_mat.resize (n, n); |
|
99 |
|
100 Complex *s = schur_mat.fortran_vec (); |
|
101 Complex *q = unitary_mat.fortran_vec (); |
|
102 |
|
103 Array<double> rwork (n); |
|
104 double *prwork = rwork.fortran_vec (); |
|
105 |
|
106 Array<Complex> w (n); |
|
107 Complex *pw = w.fortran_vec (); |
|
108 |
|
109 Array<Complex> work (lwork); |
|
110 Complex *pwork = work.fortran_vec (); |
457
|
111 |
3334
|
112 // BWORK is not referenced for non-ordered Schur. |
|
113 Array<int> bwork ((ord_char == 'N' || ord_char == 'n') ? 0 : n); |
1929
|
114 int *pbwork = bwork.fortran_vec (); |
457
|
115 |
1930
|
116 F77_XFCN (zgeesx, ZGEESX, (&jobvs, &sort, selector, &sense, n, s, n, |
1929
|
117 sdim, pw, q, n, rconde, rcondv, pwork, |
3334
|
118 lwork, prwork, pbwork, info, 1L, 1L, 1L)); |
457
|
119 |
1929
|
120 if (f77_exception_encountered) |
|
121 (*current_liboctave_error_handler) ("unrecoverable error in zgeesx"); |
457
|
122 |
|
123 return info; |
|
124 } |
|
125 |
|
126 /* |
|
127 ;;; Local Variables: *** |
|
128 ;;; mode: C++ *** |
|
129 ;;; End: *** |
|
130 */ |