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 |
|
20 Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. |
|
21 |
|
22 */ |
|
23 |
|
24 #ifdef HAVE_CONFIG_H |
1192
|
25 #include <config.h> |
457
|
26 #endif |
|
27 |
|
28 #include "CmplxHESS.h" |
|
29 #include "mx-inlines.cc" |
|
30 #include "lo-error.h" |
|
31 #include "f77-uscore.h" |
|
32 |
|
33 extern "C" |
|
34 { |
1253
|
35 int F77_FCN (zgebal, ZGEBAL) (const char*, const int&, Complex*, |
|
36 const int&, int&, int&, double*, int&, |
|
37 long, long); |
457
|
38 |
1253
|
39 int F77_FCN (zgehrd, ZGEHRD) (const int&, const int&, const int&, |
|
40 Complex*, const int&, Complex*, |
|
41 Complex*, const int&, int&, long, |
|
42 long); |
1251
|
43 |
1253
|
44 int F77_FCN (zunghr, ZUNGHR) (const int&, const int&, const int&, |
|
45 Complex*, const int&, Complex*, |
|
46 Complex*, const int&, int&, long, long); |
457
|
47 |
1253
|
48 int F77_FCN (zgebak, ZGEBAK) (const char*, const char*, const int&, |
|
49 const int&, const int&, double*, |
|
50 const int&, Complex*, const int&, |
|
51 int&, long, long); |
457
|
52 } |
|
53 |
|
54 int |
|
55 ComplexHESS::init (const ComplexMatrix& a) |
|
56 { |
|
57 int a_nr = a.rows (); |
|
58 int a_nc = a.cols (); |
|
59 if (a_nr != a_nc) |
|
60 { |
|
61 (*current_liboctave_error_handler) |
|
62 ("ComplexHESS requires square matrix"); |
|
63 return -1; |
|
64 } |
|
65 |
1251
|
66 char *job = "N"; |
|
67 char *side = "R"; |
457
|
68 |
|
69 int n = a_nc; |
|
70 int lwork = 32 * n; |
|
71 int info; |
|
72 int ilo; |
|
73 int ihi; |
|
74 |
|
75 Complex *h = dup (a.data (), a.length ()); |
|
76 |
|
77 double *scale = new double [n]; |
|
78 Complex *tau = new Complex [n-1]; |
|
79 Complex *work = new Complex [lwork]; |
|
80 Complex *z = new Complex [n*n]; |
|
81 |
1253
|
82 F77_FCN (zgebal, ZGEBAL) (job, n, h, n, ilo, ihi, scale, info, 1L, |
|
83 1L); |
457
|
84 |
1253
|
85 F77_FCN (zgehrd, ZGEHRD) (n, ilo, ihi, h, n, tau, work, lwork, |
|
86 info, 1L, 1L); |
457
|
87 |
|
88 copy (z, h, n*n); |
|
89 |
1253
|
90 F77_FCN (zunghr, ZUNGHR) (n, ilo, ihi, z, n, tau, work, lwork, |
|
91 info, 1L, 1L); |
457
|
92 |
1253
|
93 F77_FCN (zgebak, ZGEBAK) (job, side, n, ilo, ihi, scale, n, z, n, |
|
94 info, 1L, 1L); |
457
|
95 |
532
|
96 hess_mat = ComplexMatrix (h, n, n); |
|
97 unitary_hess_mat = ComplexMatrix (z, n, n); |
457
|
98 |
|
99 // If someone thinks of a more graceful way of doing this (or faster for |
|
100 // that matter :-)), please let me know! |
|
101 |
|
102 if (n > 2) |
|
103 for (int j = 0; j < a_nc; j++) |
|
104 for (int i = j+2; i < a_nr; i++) |
|
105 hess_mat.elem (i, j) = 0; |
|
106 |
|
107 delete [] work; |
|
108 delete [] tau; |
|
109 delete [] scale; |
|
110 |
|
111 return info; |
|
112 } |
|
113 |
|
114 /* |
|
115 ;;; Local Variables: *** |
|
116 ;;; mode: C++ *** |
|
117 ;;; page-delimiter: "^/\\*" *** |
|
118 ;;; End: *** |
|
119 */ |