Mercurial > hg > octave-nkf
annotate liboctave/dbleSCHUR.cc @ 10822:23d2378512a0
implement rsf2csf
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Tue, 27 Jul 2010 11:26:43 +0200 |
parents | f7501986e42d |
children | 8a5e980da6aa |
rev | line source |
---|---|
457 | 1 /* |
2 | |
7017 | 3 Copyright (C) 1994, 1995, 1996, 1997, 1999, 2000, 2002, 2003, 2004, |
8920 | 4 2005, 2007, 2008 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, | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
38 F77_CONST_CHAR_ARG_DECL, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
39 SCHUR::select_function, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
40 F77_CONST_CHAR_ARG_DECL, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
41 const octave_idx_type&, double*, const octave_idx_type&, octave_idx_type&, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
42 double*, double*, double*, const octave_idx_type&, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
43 double&, double&, double*, const octave_idx_type&, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
44 octave_idx_type*, const octave_idx_type&, octave_idx_type*, octave_idx_type& |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
45 F77_CHAR_ARG_LEN_DECL |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
46 F77_CHAR_ARG_LEN_DECL |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
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 } | |
10607
f7501986e42d
make schur more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
73 else if (a_nr == 0) |
f7501986e42d
make schur more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
74 { |
f7501986e42d
make schur more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
75 schur_mat.clear (); |
f7501986e42d
make schur more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
76 unitary_mat.clear (); |
f7501986e42d
make schur more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
77 return 0; |
f7501986e42d
make schur more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
78 } |
457 | 79 |
3334 | 80 // Workspace requirements may need to be fixed if any of the |
81 // following change. | |
82 | |
5008 | 83 char jobvs; |
1930 | 84 char sense = 'N'; |
85 char sort = 'N'; | |
457 | 86 |
5008 | 87 if (calc_unitary) |
88 jobvs = 'V'; | |
89 else | |
90 jobvs = 'N'; | |
91 | |
1756 | 92 char ord_char = ord.empty () ? 'U' : ord[0]; |
93 | |
94 if (ord_char == 'A' || ord_char == 'D' || ord_char == 'a' || ord_char == 'd') | |
1930 | 95 sort = 'S'; |
457 | 96 |
1929 | 97 if (ord_char == 'A' || ord_char == 'a') |
98 selector = select_ana; | |
99 else if (ord_char == 'D' || ord_char == 'd') | |
100 selector = select_dig; | |
1930 | 101 else |
102 selector = 0; | |
457 | 103 |
5275 | 104 octave_idx_type n = a_nc; |
105 octave_idx_type lwork = 8 * n; | |
106 octave_idx_type liwork = 1; | |
107 octave_idx_type info; | |
108 octave_idx_type sdim; | |
457 | 109 double rconde; |
110 double rcondv; | |
111 | |
1929 | 112 schur_mat = a; |
5008 | 113 |
114 if (calc_unitary) | |
10607
f7501986e42d
make schur more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
115 unitary_mat.clear (n, n); |
1929 | 116 |
117 double *s = schur_mat.fortran_vec (); | |
118 double *q = unitary_mat.fortran_vec (); | |
457 | 119 |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10314
diff
changeset
|
120 Array<double> wr (n, 1); |
1929 | 121 double *pwr = wr.fortran_vec (); |
122 | |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10314
diff
changeset
|
123 Array<double> wi (n, 1); |
1929 | 124 double *pwi = wi.fortran_vec (); |
125 | |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10314
diff
changeset
|
126 Array<double> work (lwork, 1); |
1929 | 127 double *pwork = work.fortran_vec (); |
457 | 128 |
3334 | 129 // BWORK is not referenced for the non-ordered Schur routine. |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10314
diff
changeset
|
130 Array<octave_idx_type> bwork ((ord_char == 'N' || ord_char == 'n') ? 0 : n, 1); |
5275 | 131 octave_idx_type *pbwork = bwork.fortran_vec (); |
1929 | 132 |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10314
diff
changeset
|
133 Array<octave_idx_type> iwork (liwork, 1); |
5275 | 134 octave_idx_type *piwork = iwork.fortran_vec (); |
1929 | 135 |
4552 | 136 F77_XFCN (dgeesx, DGEESX, (F77_CONST_CHAR_ARG2 (&jobvs, 1), |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
137 F77_CONST_CHAR_ARG2 (&sort, 1), |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
138 selector, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
139 F77_CONST_CHAR_ARG2 (&sense, 1), |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
140 n, s, n, sdim, pwr, pwi, q, n, rconde, rcondv, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
141 pwork, lwork, piwork, liwork, pbwork, info |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
142 F77_CHAR_ARG_LEN (1) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
143 F77_CHAR_ARG_LEN (1) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
144 F77_CHAR_ARG_LEN (1))); |
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 } | |
10822 | 157 |
158 SCHUR::SCHUR (const Matrix& s, const Matrix& u) | |
159 : schur_mat (s), unitary_mat (u) | |
160 { | |
161 octave_idx_type n = s.rows (); | |
162 if (s.columns () != n || u.rows () != n || u.columns () != n) | |
163 (*current_liboctave_error_handler) | |
164 ("schur: inconsistent matrix dimensions"); | |
165 } | |
166 |