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 "dbleSCHUR.h" |
1368
|
33 #include "f77-uscore.h" |
457
|
34 #include "lo-error.h" |
1368
|
35 #include "mx-inlines.cc" |
457
|
36 |
|
37 extern "C" |
|
38 { |
1253
|
39 int F77_FCN (dgeesx, DGEESX) (const char*, const char*, |
|
40 int (*)(const double&, const double&), |
|
41 const char*, const int&, double*, |
|
42 const int&, int&, double*, double*, |
|
43 double*, const int&, double&, double&, |
|
44 double*, const int&, int*, const int&, |
|
45 int*, int&, long, long); |
457
|
46 } |
|
47 |
|
48 static int |
1251
|
49 select_ana (const double& a, const double& b) |
457
|
50 { |
1251
|
51 return (a < 0.0); |
457
|
52 } |
|
53 |
|
54 static int |
1251
|
55 select_dig (const double& a, const double& b) |
457
|
56 { |
1251
|
57 return (hypot (a, b) < 1.0); |
457
|
58 } |
|
59 |
|
60 int |
|
61 SCHUR::init (const Matrix& 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) ("SCHUR requires square matrix"); |
|
68 return -1; |
|
69 } |
|
70 |
1251
|
71 char *jobvs = "V"; |
|
72 char *sort; |
457
|
73 |
|
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 liwork = 1; |
|
84 int info; |
|
85 int sdim; |
|
86 double rconde; |
|
87 double rcondv; |
|
88 |
|
89 double *s = dup (a.data (), a.length ()); |
|
90 |
|
91 double *wr = new double [n]; |
|
92 double *wi = new double [n]; |
|
93 double *q = new double [n*n]; |
|
94 double *work = new double [lwork]; |
|
95 |
1360
|
96 // These are not referenced for the non-ordered Schur routine. |
457
|
97 |
533
|
98 int *iwork = 0; |
|
99 int *bwork = 0; |
457
|
100 if (*ord == 'A' || *ord == 'D' || *ord == 'a' || *ord == 'd') |
|
101 { |
|
102 iwork = new int [liwork]; |
|
103 bwork = new int [n]; |
|
104 } |
|
105 |
|
106 if (*ord == 'A' || *ord == 'a') |
|
107 { |
1253
|
108 F77_FCN (dgeesx, DGEESX) (jobvs, sort, select_ana, sense, n, s, |
|
109 n, sdim, wr, wi, q, n, rconde, rcondv, |
|
110 work, lwork, iwork, liwork, bwork, |
|
111 info, 1L, 1L); |
457
|
112 } |
|
113 else if (*ord == 'D' || *ord == 'd') |
|
114 { |
1253
|
115 F77_FCN (dgeesx, DGEESX) (jobvs, sort, select_dig, sense, n, s, |
|
116 n, sdim, wr, wi, q, n, rconde, rcondv, |
|
117 work, lwork, iwork, liwork, bwork, |
|
118 info, 1L, 1L); |
457
|
119 |
|
120 } |
|
121 else |
|
122 { |
1253
|
123 F77_FCN (dgeesx, DGEESX) (jobvs, sort, (void *) 0, sense, n, s, |
|
124 n, sdim, wr, wi, q, n, rconde, rcondv, |
|
125 work, lwork, iwork, liwork, bwork, |
|
126 info, 1L, 1L); |
457
|
127 } |
|
128 |
|
129 schur_mat = Matrix (s, n, n); |
|
130 unitary_mat = Matrix (q, n, n); |
|
131 |
|
132 delete [] wr; |
|
133 delete [] wi; |
|
134 delete [] work; |
|
135 delete [] iwork; |
|
136 delete [] bwork; |
|
137 |
|
138 return info; |
|
139 } |
|
140 |
|
141 ostream& |
|
142 operator << (ostream& os, const SCHUR& a) |
|
143 { |
|
144 os << a.schur_matrix () << "\n"; |
|
145 os << a.unitary_matrix () << "\n"; |
|
146 |
|
147 return os; |
|
148 } |
|
149 |
|
150 /* |
|
151 ;;; Local Variables: *** |
|
152 ;;; mode: C++ *** |
|
153 ;;; page-delimiter: "^/\\*" *** |
|
154 ;;; End: *** |
|
155 */ |