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