457
|
1 // -*- C++ -*- |
|
2 /* |
|
3 |
1882
|
4 Copyright (C) 1996 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 |
|
10 Free Software Foundation; either version 2, or (at your option) any |
|
11 later version. |
|
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 |
|
19 along with Octave; see the file COPYING. If not, write to the Free |
1315
|
20 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
457
|
21 |
|
22 */ |
|
23 |
1296
|
24 #if defined (__GNUG__) |
|
25 #pragma implementation |
|
26 #endif |
|
27 |
457
|
28 #ifdef HAVE_CONFIG_H |
1192
|
29 #include <config.h> |
457
|
30 #endif |
|
31 |
|
32 #include "CmplxHESS.h" |
1847
|
33 #include "f77-fcn.h" |
457
|
34 #include "lo-error.h" |
1368
|
35 #include "mx-inlines.cc" |
457
|
36 |
|
37 extern "C" |
|
38 { |
1253
|
39 int F77_FCN (zgebal, ZGEBAL) (const char*, const int&, Complex*, |
|
40 const int&, int&, int&, double*, int&, |
|
41 long, long); |
457
|
42 |
1253
|
43 int F77_FCN (zgehrd, ZGEHRD) (const int&, const int&, const int&, |
|
44 Complex*, const int&, Complex*, |
|
45 Complex*, const int&, int&, long, |
|
46 long); |
1251
|
47 |
1253
|
48 int F77_FCN (zunghr, ZUNGHR) (const int&, const int&, const int&, |
|
49 Complex*, const int&, Complex*, |
|
50 Complex*, const int&, int&, long, long); |
457
|
51 |
1253
|
52 int F77_FCN (zgebak, ZGEBAK) (const char*, const char*, const int&, |
|
53 const int&, const int&, double*, |
|
54 const int&, Complex*, const int&, |
|
55 int&, long, long); |
457
|
56 } |
|
57 |
|
58 int |
|
59 ComplexHESS::init (const ComplexMatrix& a) |
|
60 { |
|
61 int a_nr = a.rows (); |
|
62 int 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 |
|
74 int n = a_nc; |
|
75 int lwork = 32 * n; |
|
76 int info; |
|
77 int ilo; |
|
78 int 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 |
|
86 F77_XFCN (zgebal, ZGEBAL, (&job, n, h, n, ilo, ihi, pscale, info, |
|
87 1L, 1L)); |
457
|
88 |
1932
|
89 if (f77_exception_encountered) |
|
90 (*current_liboctave_error_handler) ("unrecoverable error in zgebal"); |
|
91 else |
|
92 { |
|
93 Array<Complex> tau (n-1); |
|
94 Complex *ptau = tau.fortran_vec (); |
457
|
95 |
1932
|
96 Array<Complex> work (lwork); |
|
97 Complex *pwork = work.fortran_vec (); |
457
|
98 |
1932
|
99 F77_XFCN (zgehrd, ZGEHRD, (n, ilo, ihi, h, n, ptau, pwork, lwork, |
|
100 info, 1L, 1L)); |
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, |
|
110 lwork, info, 1L, 1L)); |
457
|
111 |
1932
|
112 if (f77_exception_encountered) |
|
113 (*current_liboctave_error_handler) |
|
114 ("unrecoverable error in zunghr"); |
|
115 else |
|
116 { |
|
117 F77_XFCN (zgebak, ZGEBAK, (&job, &side, n, ilo, ihi, |
|
118 pscale, n, z, n, info, 1L, 1L)); |
457
|
119 |
1932
|
120 if (f77_exception_encountered) |
|
121 (*current_liboctave_error_handler) |
|
122 ("unrecoverable error in zgebak"); |
|
123 else |
|
124 { |
|
125 // If someone thinks of a more graceful way of |
|
126 // doing this (or faster for that matter :-)), |
|
127 // please let me know! |
457
|
128 |
1932
|
129 if (n > 2) |
|
130 for (int j = 0; j < a_nc; j++) |
|
131 for (int i = j+2; i < a_nr; i++) |
|
132 hess_mat.elem (i, j) = 0; |
|
133 } |
|
134 } |
|
135 } |
|
136 } |
457
|
137 |
1932
|
138 return info; |
457
|
139 } |
|
140 |
|
141 /* |
|
142 ;;; Local Variables: *** |
|
143 ;;; mode: C++ *** |
|
144 ;;; page-delimiter: "^/\\*" *** |
|
145 ;;; End: *** |
|
146 */ |