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