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*, |
|
43 int&, 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 |
1756
|
59 ComplexSCHUR::init (const ComplexMatrix& a, const 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 |
1930
|
71 char jobvs = 'V'; |
|
72 char sense = 'N'; |
|
73 char sort = 'N'; |
1756
|
74 |
|
75 char ord_char = ord.empty () ? 'U' : ord[0]; |
|
76 |
|
77 if (ord_char == 'A' || ord_char == 'D' || ord_char == 'a' || ord_char == 'd') |
1930
|
78 sort = 'S'; |
457
|
79 |
1929
|
80 if (ord_char == 'A' || ord_char == 'a') |
|
81 selector = select_ana; |
|
82 else if (ord_char == 'D' || ord_char == 'd') |
|
83 selector = select_dig; |
1930
|
84 else |
|
85 selector = 0; |
457
|
86 |
|
87 int n = a_nc; |
|
88 int lwork = 8 * n; |
|
89 int info; |
|
90 int sdim; |
|
91 double rconde; |
|
92 double rcondv; |
|
93 |
1929
|
94 schur_mat = a; |
|
95 unitary_mat.resize (n, n); |
|
96 |
|
97 Complex *s = schur_mat.fortran_vec (); |
|
98 Complex *q = unitary_mat.fortran_vec (); |
|
99 |
|
100 Array<double> rwork (n); |
|
101 double *prwork = rwork.fortran_vec (); |
|
102 |
|
103 Array<Complex> w (n); |
|
104 Complex *pw = w.fortran_vec (); |
|
105 |
|
106 Array<Complex> work (lwork); |
|
107 Complex *pwork = work.fortran_vec (); |
457
|
108 |
1360
|
109 // bwork is not referenced for non-ordered Schur. |
457
|
110 |
1929
|
111 Array<int> bwork; |
457
|
112 |
1929
|
113 if (ord_char == 'A' || ord_char == 'D' || ord_char == 'a' || ord_char == 'd') |
|
114 bwork.resize (n); |
457
|
115 |
1929
|
116 int *pbwork = bwork.fortran_vec (); |
457
|
117 |
1930
|
118 F77_XFCN (zgeesx, ZGEESX, (&jobvs, &sort, selector, &sense, n, s, n, |
1929
|
119 sdim, pw, q, n, rconde, rcondv, pwork, |
|
120 lwork, prwork, pbwork, info, 1L, 1L)); |
457
|
121 |
1929
|
122 if (f77_exception_encountered) |
|
123 (*current_liboctave_error_handler) ("unrecoverable error in zgeesx"); |
457
|
124 |
|
125 return info; |
|
126 } |
|
127 |
|
128 /* |
|
129 ;;; Local Variables: *** |
|
130 ;;; mode: C++ *** |
|
131 ;;; End: *** |
|
132 */ |