457
|
1 /* |
|
2 |
2847
|
3 Copyright (C) 1996, 1997 John W. Eaton |
457
|
4 |
|
5 This file is part of Octave. |
|
6 |
|
7 Octave is free software; you can redistribute it and/or modify it |
|
8 under the terms of the GNU General Public License as published by the |
|
9 Free Software Foundation; either version 2, or (at your option) any |
|
10 later version. |
|
11 |
|
12 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
15 for more details. |
|
16 |
|
17 You should have received a copy of the GNU General Public License |
|
18 along with Octave; see the file COPYING. If not, write to the Free |
1315
|
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
457
|
20 |
|
21 */ |
|
22 |
4192
|
23 #if defined (__GNUG__) && defined (USE_PRAGMA_INTERFACE_IMPLEMENTATION) |
1296
|
24 #pragma implementation |
|
25 #endif |
|
26 |
457
|
27 #ifdef HAVE_CONFIG_H |
1192
|
28 #include <config.h> |
457
|
29 #endif |
|
30 |
3503
|
31 #include <iostream> |
1631
|
32 |
457
|
33 #include "dbleSCHUR.h" |
1847
|
34 #include "f77-fcn.h" |
457
|
35 #include "lo-error.h" |
|
36 |
|
37 extern "C" |
|
38 { |
4552
|
39 F77_RET_T |
|
40 F77_FUNC (dgeesx, DGEESX) (F77_CONST_CHAR_ARG_DECL, |
|
41 F77_CONST_CHAR_ARG_DECL, |
|
42 SCHUR::select_function, |
|
43 F77_CONST_CHAR_ARG_DECL, |
|
44 const int&, double*, const int&, int&, |
|
45 double*, double*, double*, const int&, |
|
46 double&, double&, double*, const int&, |
|
47 int*, const int&, int*, int& |
|
48 F77_CHAR_ARG_LEN_DECL |
|
49 F77_CHAR_ARG_LEN_DECL |
|
50 F77_CHAR_ARG_LEN_DECL); |
457
|
51 } |
|
52 |
|
53 static int |
1486
|
54 select_ana (const double& a, const double&) |
457
|
55 { |
1251
|
56 return (a < 0.0); |
457
|
57 } |
|
58 |
|
59 static int |
1251
|
60 select_dig (const double& a, const double& b) |
457
|
61 { |
1251
|
62 return (hypot (a, b) < 1.0); |
457
|
63 } |
|
64 |
|
65 int |
5008
|
66 SCHUR::init (const Matrix& a, const std::string& ord, bool calc_unitary) |
457
|
67 { |
|
68 int a_nr = a.rows (); |
|
69 int a_nc = a.cols (); |
1929
|
70 |
457
|
71 if (a_nr != a_nc) |
|
72 { |
|
73 (*current_liboctave_error_handler) ("SCHUR requires square matrix"); |
|
74 return -1; |
|
75 } |
|
76 |
3334
|
77 // Workspace requirements may need to be fixed if any of the |
|
78 // following change. |
|
79 |
5008
|
80 char jobvs; |
1930
|
81 char sense = 'N'; |
|
82 char sort = 'N'; |
457
|
83 |
5008
|
84 if (calc_unitary) |
|
85 jobvs = 'V'; |
|
86 else |
|
87 jobvs = 'N'; |
|
88 |
1756
|
89 char ord_char = ord.empty () ? 'U' : ord[0]; |
|
90 |
|
91 if (ord_char == 'A' || ord_char == 'D' || ord_char == 'a' || ord_char == 'd') |
1930
|
92 sort = 'S'; |
457
|
93 |
1929
|
94 if (ord_char == 'A' || ord_char == 'a') |
|
95 selector = select_ana; |
|
96 else if (ord_char == 'D' || ord_char == 'd') |
|
97 selector = select_dig; |
1930
|
98 else |
|
99 selector = 0; |
457
|
100 |
|
101 int n = a_nc; |
|
102 int lwork = 8 * n; |
|
103 int liwork = 1; |
|
104 int info; |
|
105 int sdim; |
|
106 double rconde; |
|
107 double rcondv; |
|
108 |
1929
|
109 schur_mat = a; |
5008
|
110 |
|
111 if (calc_unitary) |
|
112 unitary_mat.resize (n, n); |
1929
|
113 |
|
114 double *s = schur_mat.fortran_vec (); |
|
115 double *q = unitary_mat.fortran_vec (); |
457
|
116 |
1929
|
117 Array<double> wr (n); |
|
118 double *pwr = wr.fortran_vec (); |
|
119 |
|
120 Array<double> wi (n); |
|
121 double *pwi = wi.fortran_vec (); |
|
122 |
|
123 Array<double> work (lwork); |
|
124 double *pwork = work.fortran_vec (); |
457
|
125 |
3334
|
126 // BWORK is not referenced for the non-ordered Schur routine. |
|
127 Array<int> bwork ((ord_char == 'N' || ord_char == 'n') ? 0 : n); |
|
128 int *pbwork = bwork.fortran_vec (); |
1929
|
129 |
3334
|
130 Array<int> iwork (liwork); |
1929
|
131 int *piwork = iwork.fortran_vec (); |
|
132 |
4552
|
133 F77_XFCN (dgeesx, DGEESX, (F77_CONST_CHAR_ARG2 (&jobvs, 1), |
|
134 F77_CONST_CHAR_ARG2 (&sort, 1), |
|
135 selector, |
|
136 F77_CONST_CHAR_ARG2 (&sense, 1), |
|
137 n, s, n, sdim, pwr, pwi, q, n, rconde, rcondv, |
|
138 pwork, lwork, piwork, liwork, pbwork, info |
|
139 F77_CHAR_ARG_LEN (1) |
|
140 F77_CHAR_ARG_LEN (1) |
|
141 F77_CHAR_ARG_LEN (1))); |
457
|
142 |
1929
|
143 if (f77_exception_encountered) |
|
144 (*current_liboctave_error_handler) ("unrecoverable error in dgeesx"); |
457
|
145 |
|
146 return info; |
|
147 } |
|
148 |
3504
|
149 std::ostream& |
|
150 operator << (std::ostream& os, const SCHUR& a) |
457
|
151 { |
|
152 os << a.schur_matrix () << "\n"; |
|
153 os << a.unitary_matrix () << "\n"; |
|
154 |
|
155 return os; |
|
156 } |
|
157 |
|
158 /* |
|
159 ;;; Local Variables: *** |
|
160 ;;; mode: C++ *** |
|
161 ;;; End: *** |
|
162 */ |