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 |
1192
|
25 #include <config.h> |
457
|
26 #endif |
|
27 |
|
28 #include "dbleSCHUR.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 (dgeesx) (const char*, const char*, |
|
36 int (*)(double*, double*), const char*, |
|
37 const int*, double*, const int*, int*, double*, |
|
38 double*, double*, const int*, double*, double*, |
|
39 double*, const int*, int*, const int*, int*, |
|
40 int*, long, long); |
|
41 } |
|
42 |
|
43 static int |
|
44 select_ana (double *a, double *b) |
|
45 { |
|
46 return (*a < 0.0); |
|
47 } |
|
48 |
|
49 static int |
|
50 select_dig (double *a, double *b) |
|
51 { |
|
52 return (hypot (*a, *b) < 1.0); |
|
53 } |
|
54 |
|
55 int |
|
56 SCHUR::init (const Matrix& a, const char *ord) |
|
57 { |
|
58 int a_nr = a.rows (); |
|
59 int a_nc = a.cols (); |
|
60 if (a_nr != a_nc) |
|
61 { |
|
62 (*current_liboctave_error_handler) ("SCHUR requires square matrix"); |
|
63 return -1; |
|
64 } |
|
65 |
|
66 char jobvs = 'V'; |
|
67 char sort; |
|
68 |
|
69 if (*ord == 'A' || *ord == 'D' || *ord == 'a' || *ord == 'd') |
|
70 sort = 'S'; |
|
71 else |
|
72 sort = 'N'; |
|
73 |
|
74 char sense = 'N'; |
|
75 |
|
76 int n = a_nc; |
|
77 int lwork = 8 * n; |
|
78 int liwork = 1; |
|
79 int info; |
|
80 int sdim; |
|
81 double rconde; |
|
82 double rcondv; |
|
83 |
|
84 double *s = dup (a.data (), a.length ()); |
|
85 |
|
86 double *wr = new double [n]; |
|
87 double *wi = new double [n]; |
|
88 double *q = new double [n*n]; |
|
89 double *work = new double [lwork]; |
|
90 |
|
91 // These are not referenced for the non-ordered Schur routine. |
|
92 |
533
|
93 int *iwork = 0; |
|
94 int *bwork = 0; |
457
|
95 if (*ord == 'A' || *ord == 'D' || *ord == 'a' || *ord == 'd') |
|
96 { |
|
97 iwork = new int [liwork]; |
|
98 bwork = new int [n]; |
|
99 } |
|
100 |
|
101 if (*ord == 'A' || *ord == 'a') |
|
102 { |
|
103 F77_FCN (dgeesx) (&jobvs, &sort, select_ana, &sense, &n, s, &n, |
|
104 &sdim, wr, wi, q, &n, &rconde, &rcondv, work, |
|
105 &lwork, iwork, &liwork, bwork, &info, 1L, 1L); |
|
106 } |
|
107 else if (*ord == 'D' || *ord == 'd') |
|
108 { |
|
109 F77_FCN (dgeesx) (&jobvs, &sort, select_dig, &sense, &n, s, &n, |
|
110 &sdim, wr, wi, q, &n, &rconde, &rcondv, work, |
|
111 &lwork, iwork, &liwork, bwork, &info, 1L, 1L); |
|
112 |
|
113 } |
|
114 else |
|
115 { |
|
116 F77_FCN (dgeesx) (&jobvs, &sort, (void *) 0, &sense, &n, s, |
|
117 &n, &sdim, wr, wi, q, &n, &rconde, &rcondv, |
|
118 work, &lwork, iwork, &liwork, bwork, &info, |
|
119 1L, 1L); |
|
120 } |
|
121 |
|
122 schur_mat = Matrix (s, n, n); |
|
123 unitary_mat = Matrix (q, n, n); |
|
124 |
|
125 delete [] wr; |
|
126 delete [] wi; |
|
127 delete [] work; |
|
128 delete [] iwork; |
|
129 delete [] bwork; |
|
130 |
|
131 return info; |
|
132 } |
|
133 |
|
134 ostream& |
|
135 operator << (ostream& os, const SCHUR& a) |
|
136 { |
|
137 os << a.schur_matrix () << "\n"; |
|
138 os << a.unitary_matrix () << "\n"; |
|
139 |
|
140 return os; |
|
141 } |
|
142 |
|
143 /* |
|
144 ;;; Local Variables: *** |
|
145 ;;; mode: C++ *** |
|
146 ;;; page-delimiter: "^/\\*" *** |
|
147 ;;; End: *** |
|
148 */ |