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 |
7016
|
9 Free Software Foundation; either version 3 of the License, or (at your |
|
10 option) any later version. |
457
|
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 |
7016
|
18 along with Octave; see the file COPYING. If not, see |
|
19 <http://www.gnu.org/licenses/>. |
457
|
20 |
|
21 */ |
|
22 |
|
23 #ifdef HAVE_CONFIG_H |
1192
|
24 #include <config.h> |
457
|
25 #endif |
|
26 |
3503
|
27 #include <iostream> |
1631
|
28 |
457
|
29 #include "dbleSCHUR.h" |
1847
|
30 #include "f77-fcn.h" |
457
|
31 #include "lo-error.h" |
|
32 |
|
33 extern "C" |
|
34 { |
4552
|
35 F77_RET_T |
|
36 F77_FUNC (dgeesx, DGEESX) (F77_CONST_CHAR_ARG_DECL, |
|
37 F77_CONST_CHAR_ARG_DECL, |
|
38 SCHUR::select_function, |
|
39 F77_CONST_CHAR_ARG_DECL, |
5275
|
40 const octave_idx_type&, double*, const octave_idx_type&, octave_idx_type&, |
|
41 double*, double*, double*, const octave_idx_type&, |
|
42 double&, double&, double*, const octave_idx_type&, |
|
43 octave_idx_type*, const octave_idx_type&, octave_idx_type*, octave_idx_type& |
4552
|
44 F77_CHAR_ARG_LEN_DECL |
|
45 F77_CHAR_ARG_LEN_DECL |
|
46 F77_CHAR_ARG_LEN_DECL); |
457
|
47 } |
|
48 |
5275
|
49 static octave_idx_type |
1486
|
50 select_ana (const double& a, const double&) |
457
|
51 { |
1251
|
52 return (a < 0.0); |
457
|
53 } |
|
54 |
5275
|
55 static octave_idx_type |
1251
|
56 select_dig (const double& a, const double& b) |
457
|
57 { |
1251
|
58 return (hypot (a, b) < 1.0); |
457
|
59 } |
|
60 |
5275
|
61 octave_idx_type |
5008
|
62 SCHUR::init (const Matrix& a, const std::string& ord, bool calc_unitary) |
457
|
63 { |
5275
|
64 octave_idx_type a_nr = a.rows (); |
|
65 octave_idx_type a_nc = a.cols (); |
1929
|
66 |
457
|
67 if (a_nr != a_nc) |
|
68 { |
|
69 (*current_liboctave_error_handler) ("SCHUR requires square matrix"); |
|
70 return -1; |
|
71 } |
|
72 |
3334
|
73 // Workspace requirements may need to be fixed if any of the |
|
74 // following change. |
|
75 |
5008
|
76 char jobvs; |
1930
|
77 char sense = 'N'; |
|
78 char sort = 'N'; |
457
|
79 |
5008
|
80 if (calc_unitary) |
|
81 jobvs = 'V'; |
|
82 else |
|
83 jobvs = 'N'; |
|
84 |
1756
|
85 char ord_char = ord.empty () ? 'U' : ord[0]; |
|
86 |
|
87 if (ord_char == 'A' || ord_char == 'D' || ord_char == 'a' || ord_char == 'd') |
1930
|
88 sort = 'S'; |
457
|
89 |
1929
|
90 if (ord_char == 'A' || ord_char == 'a') |
|
91 selector = select_ana; |
|
92 else if (ord_char == 'D' || ord_char == 'd') |
|
93 selector = select_dig; |
1930
|
94 else |
|
95 selector = 0; |
457
|
96 |
5275
|
97 octave_idx_type n = a_nc; |
|
98 octave_idx_type lwork = 8 * n; |
|
99 octave_idx_type liwork = 1; |
|
100 octave_idx_type info; |
|
101 octave_idx_type sdim; |
457
|
102 double rconde; |
|
103 double rcondv; |
|
104 |
1929
|
105 schur_mat = a; |
5008
|
106 |
|
107 if (calc_unitary) |
|
108 unitary_mat.resize (n, n); |
1929
|
109 |
|
110 double *s = schur_mat.fortran_vec (); |
|
111 double *q = unitary_mat.fortran_vec (); |
457
|
112 |
1929
|
113 Array<double> wr (n); |
|
114 double *pwr = wr.fortran_vec (); |
|
115 |
|
116 Array<double> wi (n); |
|
117 double *pwi = wi.fortran_vec (); |
|
118 |
|
119 Array<double> work (lwork); |
|
120 double *pwork = work.fortran_vec (); |
457
|
121 |
3334
|
122 // BWORK is not referenced for the non-ordered Schur routine. |
5275
|
123 Array<octave_idx_type> bwork ((ord_char == 'N' || ord_char == 'n') ? 0 : n); |
|
124 octave_idx_type *pbwork = bwork.fortran_vec (); |
1929
|
125 |
5275
|
126 Array<octave_idx_type> iwork (liwork); |
|
127 octave_idx_type *piwork = iwork.fortran_vec (); |
1929
|
128 |
4552
|
129 F77_XFCN (dgeesx, DGEESX, (F77_CONST_CHAR_ARG2 (&jobvs, 1), |
|
130 F77_CONST_CHAR_ARG2 (&sort, 1), |
|
131 selector, |
|
132 F77_CONST_CHAR_ARG2 (&sense, 1), |
|
133 n, s, n, sdim, pwr, pwi, q, n, rconde, rcondv, |
|
134 pwork, lwork, piwork, liwork, pbwork, info |
|
135 F77_CHAR_ARG_LEN (1) |
|
136 F77_CHAR_ARG_LEN (1) |
|
137 F77_CHAR_ARG_LEN (1))); |
457
|
138 |
1929
|
139 if (f77_exception_encountered) |
|
140 (*current_liboctave_error_handler) ("unrecoverable error in dgeesx"); |
457
|
141 |
|
142 return info; |
|
143 } |
|
144 |
3504
|
145 std::ostream& |
|
146 operator << (std::ostream& os, const SCHUR& a) |
457
|
147 { |
|
148 os << a.schur_matrix () << "\n"; |
|
149 os << a.unitary_matrix () << "\n"; |
|
150 |
|
151 return os; |
|
152 } |
|
153 |
|
154 /* |
|
155 ;;; Local Variables: *** |
|
156 ;;; mode: C++ *** |
|
157 ;;; End: *** |
|
158 */ |