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