457
|
1 /* |
|
2 |
2847
|
3 Copyright (C) 1996, 1997 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 "CmplxHESS.h" |
1847
|
28 #include "f77-fcn.h" |
457
|
29 #include "lo-error.h" |
|
30 |
|
31 extern "C" |
|
32 { |
4552
|
33 F77_RET_T |
|
34 F77_FUNC (zgebal, ZGEBAL) (F77_CONST_CHAR_ARG_DECL, |
5275
|
35 const octave_idx_type&, Complex*, const octave_idx_type&, |
|
36 octave_idx_type&, octave_idx_type&, double*, octave_idx_type& |
4552
|
37 F77_CHAR_ARG_LEN_DECL); |
457
|
38 |
4552
|
39 F77_RET_T |
5275
|
40 F77_FUNC (zgehrd, ZGEHRD) (const octave_idx_type&, const octave_idx_type&, const octave_idx_type&, |
|
41 Complex*, const octave_idx_type&, Complex*, |
|
42 Complex*, const octave_idx_type&, octave_idx_type&); |
1251
|
43 |
4552
|
44 F77_RET_T |
5275
|
45 F77_FUNC (zunghr, ZUNGHR) (const octave_idx_type&, const octave_idx_type&, const octave_idx_type&, |
|
46 Complex*, const octave_idx_type&, Complex*, |
|
47 Complex*, const octave_idx_type&, octave_idx_type&); |
457
|
48 |
4552
|
49 F77_RET_T |
|
50 F77_FUNC (zgebak, ZGEBAK) (F77_CONST_CHAR_ARG_DECL, |
|
51 F77_CONST_CHAR_ARG_DECL, |
5275
|
52 const octave_idx_type&, const octave_idx_type&, const octave_idx_type&, double*, |
|
53 const octave_idx_type&, Complex*, const octave_idx_type&, octave_idx_type& |
4552
|
54 F77_CHAR_ARG_LEN_DECL |
|
55 F77_CHAR_ARG_LEN_DECL); |
457
|
56 } |
|
57 |
5275
|
58 octave_idx_type |
457
|
59 ComplexHESS::init (const ComplexMatrix& a) |
|
60 { |
5275
|
61 octave_idx_type a_nr = a.rows (); |
|
62 octave_idx_type a_nc = a.cols (); |
1932
|
63 |
|
64 if (a_nr != a_nc) |
|
65 { |
|
66 (*current_liboctave_error_handler) |
|
67 ("ComplexHESS requires square matrix"); |
|
68 return -1; |
|
69 } |
457
|
70 |
1932
|
71 char job = 'N'; |
|
72 char side = 'R'; |
|
73 |
5275
|
74 octave_idx_type n = a_nc; |
|
75 octave_idx_type lwork = 32 * n; |
|
76 octave_idx_type info; |
|
77 octave_idx_type ilo; |
|
78 octave_idx_type ihi; |
457
|
79 |
1932
|
80 hess_mat = a; |
|
81 Complex *h = hess_mat.fortran_vec (); |
457
|
82 |
1932
|
83 Array<double> scale (n); |
|
84 double *pscale = scale.fortran_vec (); |
|
85 |
4552
|
86 F77_XFCN (zgebal, ZGEBAL, (F77_CONST_CHAR_ARG2 (&job, 1), |
|
87 n, h, n, ilo, ihi, pscale, info |
|
88 F77_CHAR_ARG_LEN (1))); |
457
|
89 |
1932
|
90 if (f77_exception_encountered) |
|
91 (*current_liboctave_error_handler) ("unrecoverable error in zgebal"); |
|
92 else |
|
93 { |
|
94 Array<Complex> tau (n-1); |
|
95 Complex *ptau = tau.fortran_vec (); |
457
|
96 |
1932
|
97 Array<Complex> work (lwork); |
|
98 Complex *pwork = work.fortran_vec (); |
457
|
99 |
4552
|
100 F77_XFCN (zgehrd, ZGEHRD, (n, ilo, ihi, h, n, ptau, pwork, lwork, info)); |
457
|
101 |
1932
|
102 if (f77_exception_encountered) |
|
103 (*current_liboctave_error_handler) ("unrecoverable error in zgehrd"); |
|
104 else |
|
105 { |
|
106 unitary_hess_mat = hess_mat; |
|
107 Complex *z = unitary_hess_mat.fortran_vec (); |
457
|
108 |
1932
|
109 F77_XFCN (zunghr, ZUNGHR, (n, ilo, ihi, z, n, ptau, pwork, |
4552
|
110 lwork, info)); |
457
|
111 |
1932
|
112 if (f77_exception_encountered) |
|
113 (*current_liboctave_error_handler) |
|
114 ("unrecoverable error in zunghr"); |
|
115 else |
|
116 { |
4552
|
117 F77_XFCN (zgebak, ZGEBAK, (F77_CONST_CHAR_ARG2 (&job, 1), |
|
118 F77_CONST_CHAR_ARG2 (&side, 1), |
|
119 n, ilo, ihi, pscale, n, z, n, info |
|
120 F77_CHAR_ARG_LEN (1) |
|
121 F77_CHAR_ARG_LEN (1))); |
457
|
122 |
1932
|
123 if (f77_exception_encountered) |
|
124 (*current_liboctave_error_handler) |
|
125 ("unrecoverable error in zgebak"); |
|
126 else |
|
127 { |
|
128 // If someone thinks of a more graceful way of |
|
129 // doing this (or faster for that matter :-)), |
|
130 // please let me know! |
457
|
131 |
1932
|
132 if (n > 2) |
5275
|
133 for (octave_idx_type j = 0; j < a_nc; j++) |
|
134 for (octave_idx_type i = j+2; i < a_nr; i++) |
1932
|
135 hess_mat.elem (i, j) = 0; |
|
136 } |
|
137 } |
|
138 } |
|
139 } |
457
|
140 |
1932
|
141 return info; |
457
|
142 } |
|
143 |
|
144 /* |
|
145 ;;; Local Variables: *** |
|
146 ;;; mode: C++ *** |
|
147 ;;; End: *** |
|
148 */ |