457
|
1 // -*- C++ -*- |
|
2 /* |
|
3 |
1882
|
4 Copyright (C) 1996 John W. Eaton |
457
|
5 |
|
6 This file is part of Octave. |
|
7 |
|
8 Octave is free software; you can redistribute it and/or modify it |
|
9 under the terms of the GNU General Public License as published by the |
|
10 Free Software Foundation; either version 2, or (at your option) any |
|
11 later version. |
|
12 |
|
13 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
16 for more details. |
|
17 |
|
18 You should have received a copy of the GNU General Public License |
|
19 along with Octave; see the file COPYING. If not, write to the Free |
1315
|
20 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
457
|
21 |
|
22 */ |
|
23 |
1296
|
24 #if defined (__GNUG__) |
|
25 #pragma implementation |
|
26 #endif |
|
27 |
457
|
28 #ifdef HAVE_CONFIG_H |
1192
|
29 #include <config.h> |
457
|
30 #endif |
|
31 |
|
32 #include "CmplxSCHUR.h" |
1847
|
33 #include "f77-fcn.h" |
457
|
34 #include "lo-error.h" |
1368
|
35 #include "mx-inlines.cc" |
457
|
36 |
|
37 extern "C" |
|
38 { |
1253
|
39 int F77_FCN (zgeesx, ZGEESX) (const char*, const char*, |
1929
|
40 ComplexSCHUR::select_function, |
1253
|
41 const char*, const int&, Complex*, |
|
42 const int&, int&, Complex*, Complex*, |
|
43 const int&, double&, double&, |
|
44 Complex*, const int&, double*, int*, |
|
45 int&, long, long); |
457
|
46 } |
|
47 |
|
48 static int |
1929
|
49 select_ana (const Complex& a) |
457
|
50 { |
1251
|
51 return a.real () < 0.0; |
457
|
52 } |
|
53 |
|
54 static int |
1929
|
55 select_dig (const Complex& a) |
457
|
56 { |
1251
|
57 return (abs (a) < 1.0); |
457
|
58 } |
|
59 |
|
60 int |
1756
|
61 ComplexSCHUR::init (const ComplexMatrix& a, const string& ord) |
457
|
62 { |
|
63 int a_nr = a.rows (); |
|
64 int 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 |
1930
|
73 char jobvs = 'V'; |
|
74 char sense = 'N'; |
|
75 char sort = 'N'; |
1756
|
76 |
|
77 char ord_char = ord.empty () ? 'U' : ord[0]; |
|
78 |
|
79 if (ord_char == 'A' || ord_char == 'D' || ord_char == 'a' || ord_char == 'd') |
1930
|
80 sort = 'S'; |
457
|
81 |
1929
|
82 if (ord_char == 'A' || ord_char == 'a') |
|
83 selector = select_ana; |
|
84 else if (ord_char == 'D' || ord_char == 'd') |
|
85 selector = select_dig; |
1930
|
86 else |
|
87 selector = 0; |
457
|
88 |
|
89 int n = a_nc; |
|
90 int lwork = 8 * n; |
|
91 int info; |
|
92 int sdim; |
|
93 double rconde; |
|
94 double rcondv; |
|
95 |
1929
|
96 schur_mat = a; |
|
97 unitary_mat.resize (n, n); |
|
98 |
|
99 Complex *s = schur_mat.fortran_vec (); |
|
100 Complex *q = unitary_mat.fortran_vec (); |
|
101 |
|
102 Array<double> rwork (n); |
|
103 double *prwork = rwork.fortran_vec (); |
|
104 |
|
105 Array<Complex> w (n); |
|
106 Complex *pw = w.fortran_vec (); |
|
107 |
|
108 Array<Complex> work (lwork); |
|
109 Complex *pwork = work.fortran_vec (); |
457
|
110 |
1360
|
111 // bwork is not referenced for non-ordered Schur. |
457
|
112 |
1929
|
113 Array<int> bwork; |
457
|
114 |
1929
|
115 if (ord_char == 'A' || ord_char == 'D' || ord_char == 'a' || ord_char == 'd') |
|
116 bwork.resize (n); |
457
|
117 |
1929
|
118 int *pbwork = bwork.fortran_vec (); |
457
|
119 |
1930
|
120 F77_XFCN (zgeesx, ZGEESX, (&jobvs, &sort, selector, &sense, n, s, n, |
1929
|
121 sdim, pw, q, n, rconde, rcondv, pwork, |
|
122 lwork, prwork, pbwork, info, 1L, 1L)); |
457
|
123 |
1929
|
124 if (f77_exception_encountered) |
|
125 (*current_liboctave_error_handler) ("unrecoverable error in zgeesx"); |
457
|
126 |
|
127 return info; |
|
128 } |
|
129 |
|
130 /* |
|
131 ;;; Local Variables: *** |
|
132 ;;; mode: C++ *** |
|
133 ;;; page-delimiter: "^/\\*" *** |
|
134 ;;; End: *** |
|
135 */ |