Mercurial > hg > octave-nkf
annotate liboctave/CmplxSCHUR.cc @ 11542:695141f1c05c ss-3-3-55
snapshot 3.3.55
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Sat, 15 Jan 2011 04:53:04 -0500 |
parents | fd0a3ac60b0e |
children | 57632dea2446 |
rev | line source |
---|---|
457 | 1 /* |
2 | |
11523 | 3 Copyright (C) 1994-2011 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 | |
27 #include "CmplxSCHUR.h" | |
1847 | 28 #include "f77-fcn.h" |
457 | 29 #include "lo-error.h" |
10822 | 30 #include "oct-locbuf.h" |
457 | 31 |
32 extern "C" | |
33 { | |
4552 | 34 F77_RET_T |
35 F77_FUNC (zgeesx, ZGEESX) (F77_CONST_CHAR_ARG_DECL, | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
36 F77_CONST_CHAR_ARG_DECL, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
37 ComplexSCHUR::select_function, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
38 F77_CONST_CHAR_ARG_DECL, |
11495 | 39 const octave_idx_type&, Complex*, |
40 const octave_idx_type&, octave_idx_type&, | |
41 Complex*, Complex*, const octave_idx_type&, | |
42 double&, double&, Complex*, | |
43 const octave_idx_type&, double*, | |
44 octave_idx_type*, octave_idx_type& | |
10314
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); |
11495 | 48 |
10822 | 49 F77_RET_T |
11495 | 50 F77_FUNC (zrsf2csf, ZRSF2CSF) (const octave_idx_type&, Complex *, |
51 Complex *, double *, double *); | |
457 | 52 } |
53 | |
5275 | 54 static octave_idx_type |
1929 | 55 select_ana (const Complex& a) |
457 | 56 { |
1251 | 57 return a.real () < 0.0; |
457 | 58 } |
59 | |
5275 | 60 static octave_idx_type |
1929 | 61 select_dig (const Complex& a) |
457 | 62 { |
1251 | 63 return (abs (a) < 1.0); |
457 | 64 } |
65 | |
5275 | 66 octave_idx_type |
5008 | 67 ComplexSCHUR::init (const ComplexMatrix& a, const std::string& ord, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
68 bool calc_unitary) |
457 | 69 { |
5275 | 70 octave_idx_type a_nr = a.rows (); |
71 octave_idx_type a_nc = a.cols (); | |
1929 | 72 |
457 | 73 if (a_nr != a_nc) |
74 { | |
75 (*current_liboctave_error_handler) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
76 ("ComplexSCHUR requires square matrix"); |
457 | 77 return -1; |
78 } | |
10607
f7501986e42d
make schur more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
79 else if (a_nr == 0) |
f7501986e42d
make schur more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
80 { |
f7501986e42d
make schur more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
81 schur_mat.clear (); |
f7501986e42d
make schur more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
82 unitary_mat.clear (); |
f7501986e42d
make schur more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
83 return 0; |
f7501986e42d
make schur more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
84 } |
457 | 85 |
3334 | 86 // Workspace requirements may need to be fixed if any of the |
87 // following change. | |
88 | |
5008 | 89 char jobvs; |
1930 | 90 char sense = 'N'; |
91 char sort = 'N'; | |
1756 | 92 |
5008 | 93 if (calc_unitary) |
94 jobvs = 'V'; | |
95 else | |
96 jobvs = 'N'; | |
97 | |
1756 | 98 char ord_char = ord.empty () ? 'U' : ord[0]; |
99 | |
100 if (ord_char == 'A' || ord_char == 'D' || ord_char == 'a' || ord_char == 'd') | |
1930 | 101 sort = 'S'; |
457 | 102 |
1929 | 103 if (ord_char == 'A' || ord_char == 'a') |
104 selector = select_ana; | |
105 else if (ord_char == 'D' || ord_char == 'd') | |
106 selector = select_dig; | |
1930 | 107 else |
108 selector = 0; | |
457 | 109 |
5275 | 110 octave_idx_type n = a_nc; |
111 octave_idx_type lwork = 8 * n; | |
112 octave_idx_type info; | |
113 octave_idx_type sdim; | |
457 | 114 double rconde; |
115 double rcondv; | |
116 | |
1929 | 117 schur_mat = a; |
5008 | 118 if (calc_unitary) |
10607
f7501986e42d
make schur more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
119 unitary_mat.clear (n, n); |
1929 | 120 |
121 Complex *s = schur_mat.fortran_vec (); | |
122 Complex *q = unitary_mat.fortran_vec (); | |
123 | |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10314
diff
changeset
|
124 Array<double> rwork (n, 1); |
1929 | 125 double *prwork = rwork.fortran_vec (); |
126 | |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10314
diff
changeset
|
127 Array<Complex> w (n, 1); |
1929 | 128 Complex *pw = w.fortran_vec (); |
129 | |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10314
diff
changeset
|
130 Array<Complex> work (lwork, 1); |
1929 | 131 Complex *pwork = work.fortran_vec (); |
457 | 132 |
3334 | 133 // BWORK is not referenced for non-ordered Schur. |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10314
diff
changeset
|
134 Array<octave_idx_type> bwork ((ord_char == 'N' || ord_char == 'n') ? 0 : n, 1); |
5275 | 135 octave_idx_type *pbwork = bwork.fortran_vec (); |
457 | 136 |
4552 | 137 F77_XFCN (zgeesx, ZGEESX, (F77_CONST_CHAR_ARG2 (&jobvs, 1), |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
138 F77_CONST_CHAR_ARG2 (&sort, 1), |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
139 selector, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
140 F77_CONST_CHAR_ARG2 (&sense, 1), |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
141 n, s, n, sdim, pw, q, n, rconde, rcondv, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
142 pwork, lwork, prwork, pbwork, info |
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) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
145 F77_CHAR_ARG_LEN (1))); |
457 | 146 |
147 return info; | |
148 } | |
10822 | 149 |
11498
367bfee35ba0
data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
11495
diff
changeset
|
150 ComplexSCHUR::ComplexSCHUR (const ComplexMatrix& s, const ComplexMatrix& u) |
367bfee35ba0
data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
11495
diff
changeset
|
151 : schur_mat (s), unitary_mat (u), selector (0) |
10822 | 152 { |
153 octave_idx_type n = s.rows (); | |
154 if (s.columns () != n || u.rows () != n || u.columns () != n) | |
155 (*current_liboctave_error_handler) | |
156 ("schur: inconsistent matrix dimensions"); | |
157 } | |
158 | |
159 ComplexSCHUR::ComplexSCHUR (const SCHUR& s) | |
11498
367bfee35ba0
data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
11495
diff
changeset
|
160 : schur_mat (s.schur_matrix ()), unitary_mat (s.unitary_matrix ()), |
367bfee35ba0
data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
11495
diff
changeset
|
161 selector (0) |
10822 | 162 { |
163 octave_idx_type n = schur_mat.rows (); | |
164 if (n > 0) | |
165 { | |
166 OCTAVE_LOCAL_BUFFER (double, c, n-1); | |
167 OCTAVE_LOCAL_BUFFER (double, sx, n-1); | |
168 | |
169 F77_XFCN (zrsf2csf, ZRSF2CSF, (n, schur_mat.fortran_vec (), | |
170 unitary_mat.fortran_vec (), c, sx)); | |
171 } | |
172 } |