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