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 |
|
20 Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. |
|
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" |
|
33 #include "mx-inlines.cc" |
|
34 #include "lo-error.h" |
|
35 #include "f77-uscore.h" |
|
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 |
|
61 ComplexSCHUR::init (const ComplexMatrix& a, const char *ord) |
|
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; |
457
|
74 if (*ord == 'A' || *ord == 'D' || *ord == 'a' || *ord == 'd') |
1251
|
75 sort = "S"; |
457
|
76 else |
1251
|
77 sort = "N"; |
457
|
78 |
1251
|
79 char *sense = "N"; |
457
|
80 |
|
81 int n = a_nc; |
|
82 int lwork = 8 * n; |
|
83 int info; |
|
84 int sdim; |
|
85 double rconde; |
|
86 double rcondv; |
|
87 |
|
88 double *rwork = new double [n]; |
|
89 |
|
90 // bwork is not referenced for non-ordered Schur. |
|
91 |
534
|
92 int *bwork = 0; |
457
|
93 if (*ord == 'A' || *ord == 'D' || *ord == 'a' || *ord == 'd') |
|
94 bwork = new int [n]; |
|
95 |
|
96 Complex *s = dup (a.data (), a.length ()); |
|
97 |
|
98 Complex *work = new Complex [lwork]; |
|
99 Complex *q = new Complex [n*n]; |
|
100 Complex *w = new Complex [n]; |
|
101 |
|
102 if (*ord == 'A' || *ord == 'a') |
|
103 { |
1253
|
104 F77_FCN (zgeesx, ZGEESX) (jobvs, sort, complex_select_ana, |
|
105 sense, n, s, n, sdim, w, q, n, rconde, |
|
106 rcondv, work, lwork, rwork, bwork, |
|
107 info, 1L, 1L); |
457
|
108 } |
|
109 else if (*ord == 'D' || *ord == 'd') |
|
110 { |
1253
|
111 F77_FCN (zgeesx, ZGEESX) (jobvs, sort, complex_select_dig, |
|
112 sense, n, s, n, sdim, w, q, n, rconde, |
|
113 rcondv, work, lwork, rwork, bwork, |
|
114 info, 1L, 1L); |
457
|
115 } |
|
116 else |
|
117 { |
1253
|
118 F77_FCN (zgeesx, ZGEESX) (jobvs, sort, (void *) 0, sense, n, s, |
|
119 n, sdim, w, q, n, rconde, rcondv, |
|
120 work, lwork, rwork, bwork, info, 1L, |
|
121 1L); |
457
|
122 } |
|
123 |
532
|
124 schur_mat = ComplexMatrix (s, n, n); |
|
125 unitary_mat = ComplexMatrix (q, n, n); |
457
|
126 |
|
127 delete [] w; |
|
128 delete [] work; |
|
129 delete [] rwork; |
|
130 delete [] bwork; |
|
131 |
|
132 return info; |
|
133 } |
|
134 |
|
135 /* |
|
136 ;;; Local Variables: *** |
|
137 ;;; mode: C++ *** |
|
138 ;;; page-delimiter: "^/\\*" *** |
|
139 ;;; End: *** |
|
140 */ |