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