457
|
1 // -*- C++ -*- |
|
2 /* |
|
3 |
1882
|
4 Copyright (C) 1996 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 |
1631
|
32 #include <iostream.h> |
|
33 |
457
|
34 #include "dbleSCHUR.h" |
1847
|
35 #include "f77-fcn.h" |
457
|
36 #include "lo-error.h" |
1368
|
37 #include "mx-inlines.cc" |
457
|
38 |
|
39 extern "C" |
|
40 { |
1253
|
41 int F77_FCN (dgeesx, DGEESX) (const char*, const char*, |
1929
|
42 SCHUR::select_function, const char*, |
|
43 const int&, double*, const int&, |
|
44 int&, double*, double*, double*, |
|
45 const int&, double&, double&, double*, |
|
46 const int&, int*, const int&, int*, |
|
47 int&, long, long); |
457
|
48 } |
|
49 |
|
50 static int |
1486
|
51 select_ana (const double& a, const double&) |
457
|
52 { |
1251
|
53 return (a < 0.0); |
457
|
54 } |
|
55 |
|
56 static int |
1251
|
57 select_dig (const double& a, const double& b) |
457
|
58 { |
1251
|
59 return (hypot (a, b) < 1.0); |
457
|
60 } |
|
61 |
|
62 int |
1756
|
63 SCHUR::init (const Matrix& a, const string& ord) |
457
|
64 { |
|
65 int a_nr = a.rows (); |
|
66 int a_nc = a.cols (); |
1929
|
67 |
457
|
68 if (a_nr != a_nc) |
|
69 { |
|
70 (*current_liboctave_error_handler) ("SCHUR requires square matrix"); |
|
71 return -1; |
|
72 } |
|
73 |
1251
|
74 char *jobvs = "V"; |
1929
|
75 char *sense = "N"; |
|
76 char *sort = "N"; |
457
|
77 |
1756
|
78 char ord_char = ord.empty () ? 'U' : ord[0]; |
|
79 |
|
80 if (ord_char == 'A' || ord_char == 'D' || ord_char == 'a' || ord_char == 'd') |
1251
|
81 sort = "S"; |
457
|
82 |
1929
|
83 select_function selector = 0; |
|
84 if (ord_char == 'A' || ord_char == 'a') |
|
85 selector = select_ana; |
|
86 else if (ord_char == 'D' || ord_char == 'd') |
|
87 selector = select_dig; |
457
|
88 |
|
89 int n = a_nc; |
|
90 int lwork = 8 * n; |
|
91 int liwork = 1; |
|
92 int info; |
|
93 int sdim; |
|
94 double rconde; |
|
95 double rcondv; |
|
96 |
1929
|
97 schur_mat = a; |
|
98 unitary_mat.resize (n, n); |
|
99 |
|
100 double *s = schur_mat.fortran_vec (); |
|
101 double *q = unitary_mat.fortran_vec (); |
457
|
102 |
1929
|
103 Array<double> wr (n); |
|
104 double *pwr = wr.fortran_vec (); |
|
105 |
|
106 Array<double> wi (n); |
|
107 double *pwi = wi.fortran_vec (); |
|
108 |
|
109 Array<double> work (lwork); |
|
110 double *pwork = work.fortran_vec (); |
457
|
111 |
1360
|
112 // These are not referenced for the non-ordered Schur routine. |
457
|
113 |
1929
|
114 Array<int> bwork; |
|
115 Array<int> iwork; |
|
116 |
1756
|
117 if (ord_char == 'A' || ord_char == 'D' || ord_char == 'a' || ord_char == 'd') |
457
|
118 { |
1929
|
119 bwork.resize (n); |
|
120 iwork.resize (liwork); |
457
|
121 } |
|
122 |
1929
|
123 int *pbwork = bwork.fortran_vec (); |
|
124 int *piwork = iwork.fortran_vec (); |
|
125 |
457
|
126 |
1929
|
127 F77_XFCN (dgeesx, DGEESX, (jobvs, sort, selector, sense, n, s, |
|
128 n, sdim, pwr, pwi, q, n, rconde, rcondv, |
|
129 pwork, lwork, piwork, liwork, pbwork, |
|
130 info, 1L, 1L)); |
457
|
131 |
1929
|
132 if (f77_exception_encountered) |
|
133 (*current_liboctave_error_handler) ("unrecoverable error in dgeesx"); |
457
|
134 |
|
135 return info; |
|
136 } |
|
137 |
|
138 ostream& |
|
139 operator << (ostream& os, const SCHUR& a) |
|
140 { |
|
141 os << a.schur_matrix () << "\n"; |
|
142 os << a.unitary_matrix () << "\n"; |
|
143 |
|
144 return os; |
|
145 } |
|
146 |
|
147 /* |
|
148 ;;; Local Variables: *** |
|
149 ;;; mode: C++ *** |
|
150 ;;; page-delimiter: "^/\\*" *** |
|
151 ;;; End: *** |
|
152 */ |