457
|
1 // -*- C++ -*- |
|
2 /* |
|
3 |
1011
|
4 Copyright (C) 1992, 1993, 1994, 1995 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*, |
|
40 int (*)(const Complex&), |
|
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 |
1251
|
49 complex_select_ana (const Complex& a) |
457
|
50 { |
1251
|
51 return a.real () < 0.0; |
457
|
52 } |
|
53 |
|
54 static int |
1251
|
55 complex_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 (); |
|
65 if (a_nr != a_nc) |
|
66 { |
|
67 (*current_liboctave_error_handler) |
|
68 ("ComplexSCHUR requires square matrix"); |
|
69 return -1; |
|
70 } |
|
71 |
1251
|
72 char *jobvs = "V"; |
|
73 char *sort; |
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') |
1251
|
78 sort = "S"; |
457
|
79 else |
1251
|
80 sort = "N"; |
457
|
81 |
1251
|
82 char *sense = "N"; |
457
|
83 |
|
84 int n = a_nc; |
|
85 int lwork = 8 * n; |
|
86 int info; |
|
87 int sdim; |
|
88 double rconde; |
|
89 double rcondv; |
|
90 |
|
91 double *rwork = new double [n]; |
|
92 |
1360
|
93 // bwork is not referenced for non-ordered Schur. |
457
|
94 |
534
|
95 int *bwork = 0; |
1756
|
96 if (ord_char == 'A' || ord_char == 'D' || ord_char == 'a' || ord_char == 'd') |
457
|
97 bwork = new int [n]; |
|
98 |
|
99 Complex *s = dup (a.data (), a.length ()); |
|
100 |
|
101 Complex *work = new Complex [lwork]; |
|
102 Complex *q = new Complex [n*n]; |
|
103 Complex *w = new Complex [n]; |
|
104 |
1756
|
105 if (ord_char == 'A' || ord_char == 'a') |
457
|
106 { |
1253
|
107 F77_FCN (zgeesx, ZGEESX) (jobvs, sort, complex_select_ana, |
|
108 sense, n, s, n, sdim, w, q, n, rconde, |
|
109 rcondv, work, lwork, rwork, bwork, |
|
110 info, 1L, 1L); |
457
|
111 } |
1756
|
112 else if (ord_char == 'D' || ord_char == 'd') |
457
|
113 { |
1253
|
114 F77_FCN (zgeesx, ZGEESX) (jobvs, sort, complex_select_dig, |
|
115 sense, n, s, n, sdim, w, q, n, rconde, |
|
116 rcondv, work, lwork, rwork, bwork, |
|
117 info, 1L, 1L); |
457
|
118 } |
|
119 else |
|
120 { |
1253
|
121 F77_FCN (zgeesx, ZGEESX) (jobvs, sort, (void *) 0, sense, n, s, |
|
122 n, sdim, w, q, n, rconde, rcondv, |
|
123 work, lwork, rwork, bwork, info, 1L, |
|
124 1L); |
457
|
125 } |
|
126 |
532
|
127 schur_mat = ComplexMatrix (s, n, n); |
|
128 unitary_mat = ComplexMatrix (q, n, n); |
457
|
129 |
|
130 delete [] w; |
|
131 delete [] work; |
|
132 delete [] rwork; |
|
133 delete [] bwork; |
|
134 |
|
135 return info; |
|
136 } |
|
137 |
|
138 /* |
|
139 ;;; Local Variables: *** |
|
140 ;;; mode: C++ *** |
|
141 ;;; page-delimiter: "^/\\*" *** |
|
142 ;;; End: *** |
|
143 */ |