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 { |
1251
|
35 int F77_FCN (zgebal) (const char*, const int&, Complex*, const int&, |
|
36 int&, int&, double*, int&, long, long); |
457
|
37 |
1251
|
38 int F77_FCN (zgehrd) (const int&, const int&, const int&, Complex*, |
|
39 const int&, Complex*, Complex*, const int&, |
|
40 int&, long, long); |
|
41 |
|
42 int F77_FCN (zunghr) (const int&, const int&, const int&, Complex*, |
|
43 const int&, Complex*, Complex*, const int&, |
|
44 int&, long, long); |
457
|
45 |
1251
|
46 int F77_FCN (zgebak) (const char*, const char*, const int&, const int&, |
|
47 const int&, double*, const int&, Complex*, |
|
48 const int&, int&, long, long); |
457
|
49 } |
|
50 |
|
51 int |
|
52 ComplexHESS::init (const ComplexMatrix& a) |
|
53 { |
|
54 int a_nr = a.rows (); |
|
55 int a_nc = a.cols (); |
|
56 if (a_nr != a_nc) |
|
57 { |
|
58 (*current_liboctave_error_handler) |
|
59 ("ComplexHESS requires square matrix"); |
|
60 return -1; |
|
61 } |
|
62 |
1251
|
63 char *job = "N"; |
|
64 char *side = "R"; |
457
|
65 |
|
66 int n = a_nc; |
|
67 int lwork = 32 * n; |
|
68 int info; |
|
69 int ilo; |
|
70 int ihi; |
|
71 |
|
72 Complex *h = dup (a.data (), a.length ()); |
|
73 |
|
74 double *scale = new double [n]; |
|
75 Complex *tau = new Complex [n-1]; |
|
76 Complex *work = new Complex [lwork]; |
|
77 Complex *z = new Complex [n*n]; |
|
78 |
1251
|
79 F77_FCN (zgebal) (job, n, h, n, ilo, ihi, scale, info, 1L, 1L); |
457
|
80 |
1251
|
81 F77_FCN (zgehrd) (n, ilo, ihi, h, n, tau, work, lwork, info, 1L, 1L); |
457
|
82 |
|
83 copy (z, h, n*n); |
|
84 |
1251
|
85 F77_FCN (zunghr) (n, ilo, ihi, z, n, tau, work, lwork, info, 1L, 1L); |
457
|
86 |
1251
|
87 F77_FCN (zgebak) (job, side, n, ilo, ihi, scale, n, z, n, info, 1L, 1L); |
457
|
88 |
532
|
89 hess_mat = ComplexMatrix (h, n, n); |
|
90 unitary_hess_mat = ComplexMatrix (z, n, n); |
457
|
91 |
|
92 // If someone thinks of a more graceful way of doing this (or faster for |
|
93 // that matter :-)), please let me know! |
|
94 |
|
95 if (n > 2) |
|
96 for (int j = 0; j < a_nc; j++) |
|
97 for (int i = j+2; i < a_nr; i++) |
|
98 hess_mat.elem (i, j) = 0; |
|
99 |
|
100 delete [] work; |
|
101 delete [] tau; |
|
102 delete [] scale; |
|
103 |
|
104 return info; |
|
105 } |
|
106 |
|
107 /* |
|
108 ;;; Local Variables: *** |
|
109 ;;; mode: C++ *** |
|
110 ;;; page-delimiter: "^/\\*" *** |
|
111 ;;; End: *** |
|
112 */ |