457
|
1 // -*- C++ -*- |
|
2 /* |
|
3 |
1011
|
4 Copyright (C) 1992, 1993, 1994, 1995 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" |
|
33 #include "mx-inlines.cc" |
|
34 #include "lo-error.h" |
|
35 #include "f77-uscore.h" |
|
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 (); |
|
63 if (a_nr != a_nc) |
|
64 { |
|
65 (*current_liboctave_error_handler) |
|
66 ("ComplexHESS requires square matrix"); |
|
67 return -1; |
|
68 } |
|
69 |
1251
|
70 char *job = "N"; |
|
71 char *side = "R"; |
457
|
72 |
|
73 int n = a_nc; |
|
74 int lwork = 32 * n; |
|
75 int info; |
|
76 int ilo; |
|
77 int ihi; |
|
78 |
|
79 Complex *h = dup (a.data (), a.length ()); |
|
80 |
|
81 double *scale = new double [n]; |
|
82 Complex *tau = new Complex [n-1]; |
|
83 Complex *work = new Complex [lwork]; |
|
84 Complex *z = new Complex [n*n]; |
|
85 |
1253
|
86 F77_FCN (zgebal, ZGEBAL) (job, n, h, n, ilo, ihi, scale, info, 1L, |
|
87 1L); |
457
|
88 |
1253
|
89 F77_FCN (zgehrd, ZGEHRD) (n, ilo, ihi, h, n, tau, work, lwork, |
|
90 info, 1L, 1L); |
457
|
91 |
|
92 copy (z, h, n*n); |
|
93 |
1253
|
94 F77_FCN (zunghr, ZUNGHR) (n, ilo, ihi, z, n, tau, work, lwork, |
|
95 info, 1L, 1L); |
457
|
96 |
1253
|
97 F77_FCN (zgebak, ZGEBAK) (job, side, n, ilo, ihi, scale, n, z, n, |
|
98 info, 1L, 1L); |
457
|
99 |
532
|
100 hess_mat = ComplexMatrix (h, n, n); |
|
101 unitary_hess_mat = ComplexMatrix (z, n, n); |
457
|
102 |
1360
|
103 // If someone thinks of a more graceful way of doing this (or faster |
|
104 // for that matter :-)), please let me know! |
457
|
105 |
|
106 if (n > 2) |
|
107 for (int j = 0; j < a_nc; j++) |
|
108 for (int i = j+2; i < a_nr; i++) |
|
109 hess_mat.elem (i, j) = 0; |
|
110 |
|
111 delete [] work; |
|
112 delete [] tau; |
|
113 delete [] scale; |
|
114 |
|
115 return info; |
|
116 } |
|
117 |
|
118 /* |
|
119 ;;; Local Variables: *** |
|
120 ;;; mode: C++ *** |
|
121 ;;; page-delimiter: "^/\\*" *** |
|
122 ;;; End: *** |
|
123 */ |