457
|
1 // -*- C++ -*- |
|
2 /* |
|
3 |
|
4 Copyright (C) 1992, 1993, 1994 John W. Eaton |
|
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 |
|
24 #ifdef HAVE_CONFIG_H |
|
25 #include "config.h" |
|
26 #endif |
|
27 |
|
28 #if defined (__GNUG__) |
|
29 #pragma implementation |
|
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 { |
|
39 int F77_FCN (zgeesx) (const char*, const char*, int (*)(Complex*), |
|
40 const char*, const int*, Complex*, const int*, |
|
41 int*, Complex*, Complex*, const int*, double*, |
|
42 double*, Complex*, const int*, double*, int*, |
|
43 int*, long, long); |
|
44 } |
|
45 |
|
46 static int |
|
47 complex_select_ana (Complex *a) |
|
48 { |
|
49 return a->real () < 0.0; |
|
50 } |
|
51 |
|
52 static int |
|
53 complex_select_dig (Complex *a) |
|
54 { |
|
55 return (abs (*a) < 1.0); |
|
56 } |
|
57 |
|
58 int |
|
59 ComplexSCHUR::init (const ComplexMatrix& a, const char *ord) |
|
60 { |
|
61 int a_nr = a.rows (); |
|
62 int a_nc = a.cols (); |
|
63 if (a_nr != a_nc) |
|
64 { |
|
65 (*current_liboctave_error_handler) |
|
66 ("ComplexSCHUR requires square matrix"); |
|
67 return -1; |
|
68 } |
|
69 |
|
70 char jobvs = 'V'; |
|
71 char sort; |
|
72 if (*ord == 'A' || *ord == 'D' || *ord == 'a' || *ord == 'd') |
|
73 sort = 'S'; |
|
74 else |
|
75 sort = 'N'; |
|
76 |
|
77 char sense = 'N'; |
|
78 |
|
79 int n = a_nc; |
|
80 int lwork = 8 * n; |
|
81 int info; |
|
82 int sdim; |
|
83 double rconde; |
|
84 double rcondv; |
|
85 |
|
86 double *rwork = new double [n]; |
|
87 |
|
88 // bwork is not referenced for non-ordered Schur. |
|
89 |
|
90 int *bwork = (int *) NULL; |
|
91 if (*ord == 'A' || *ord == 'D' || *ord == 'a' || *ord == 'd') |
|
92 bwork = new int [n]; |
|
93 |
|
94 Complex *s = dup (a.data (), a.length ()); |
|
95 |
|
96 Complex *work = new Complex [lwork]; |
|
97 Complex *q = new Complex [n*n]; |
|
98 Complex *w = new Complex [n]; |
|
99 |
|
100 if (*ord == 'A' || *ord == 'a') |
|
101 { |
|
102 F77_FCN (zgeesx) (&jobvs, &sort, complex_select_ana, &sense, |
|
103 &n, s, &n, &sdim, w, q, &n, &rconde, &rcondv, |
|
104 work, &lwork, rwork, bwork, &info, 1L, 1L); |
|
105 } |
|
106 else if (*ord == 'D' || *ord == 'd') |
|
107 { |
|
108 F77_FCN (zgeesx) (&jobvs, &sort, complex_select_dig, &sense, |
|
109 &n, s, &n, &sdim, w, q, &n, &rconde, &rcondv, |
|
110 work, &lwork, rwork, bwork, &info, 1L, 1L); |
|
111 } |
|
112 else |
|
113 { |
|
114 F77_FCN (zgeesx) (&jobvs, &sort, (void *) 0, &sense, &n, s, |
|
115 &n, &sdim, w, q, &n, &rconde, &rcondv, work, |
|
116 &lwork, rwork, bwork, &info, 1L, 1L); |
|
117 } |
|
118 |
|
119 schur_mat = ComplexMatrix (s,n,n); |
|
120 unitary_mat = ComplexMatrix (q,n,n); |
|
121 |
|
122 delete [] w; |
|
123 delete [] work; |
|
124 delete [] rwork; |
|
125 delete [] bwork; |
|
126 |
|
127 return info; |
|
128 } |
|
129 |
|
130 /* |
|
131 ;;; Local Variables: *** |
|
132 ;;; mode: C++ *** |
|
133 ;;; page-delimiter: "^/\\*" *** |
|
134 ;;; End: *** |
|
135 */ |