Mercurial > octave-nkf
annotate liboctave/dbleSCHUR.cc @ 10350:12884915a8e4
merge MArray classes & improve Array interface
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Sat, 23 Jan 2010 21:41:03 +0100 |
parents | 07ebe522dac2 |
children | f7501986e42d |
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 } | |
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 |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10314
diff
changeset
|
114 Array<double> wr (n, 1); |
1929 | 115 double *pwr = wr.fortran_vec (); |
116 | |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10314
diff
changeset
|
117 Array<double> wi (n, 1); |
1929 | 118 double *pwi = wi.fortran_vec (); |
119 | |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10314
diff
changeset
|
120 Array<double> work (lwork, 1); |
1929 | 121 double *pwork = work.fortran_vec (); |
457 | 122 |
3334 | 123 // 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
|
124 Array<octave_idx_type> bwork ((ord_char == 'N' || ord_char == 'n') ? 0 : n, 1); |
5275 | 125 octave_idx_type *pbwork = bwork.fortran_vec (); |
1929 | 126 |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10314
diff
changeset
|
127 Array<octave_idx_type> iwork (liwork, 1); |
5275 | 128 octave_idx_type *piwork = iwork.fortran_vec (); |
1929 | 129 |
4552 | 130 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
|
131 F77_CONST_CHAR_ARG2 (&sort, 1), |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
132 selector, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
133 F77_CONST_CHAR_ARG2 (&sense, 1), |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
134 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
|
135 pwork, lwork, piwork, liwork, pbwork, info |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
136 F77_CHAR_ARG_LEN (1) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
137 F77_CHAR_ARG_LEN (1) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
138 F77_CHAR_ARG_LEN (1))); |
457 | 139 |
140 return info; | |
141 } | |
142 | |
3504 | 143 std::ostream& |
144 operator << (std::ostream& os, const SCHUR& a) | |
457 | 145 { |
146 os << a.schur_matrix () << "\n"; | |
147 os << a.unitary_matrix () << "\n"; | |
148 | |
149 return os; | |
150 } |