457
|
1 // -*- C++ -*- |
|
2 /* |
|
3 |
|
4 Copyright (C) 1992, 1993, 1994 John W. Eaton |
|
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 |
|
25 #include "config.h" |
|
26 #endif |
|
27 |
|
28 #if defined (__GNUG__) |
|
29 #pragma implementation |
|
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 { |
|
39 int F77_FCN (zgebal) (const char*, const int*, Complex*, const int*, |
|
40 int*, int*, double*, int*, long, long); |
|
41 |
|
42 int F77_FCN (zgebak) (const char*, const char*, const int*, const int*, |
|
43 const int*, double*, const int*, Complex*, |
|
44 const int*, int*, long, long); |
|
45 |
|
46 int F77_FCN (zgehrd) (const int*, const int*, const int*, Complex*, |
|
47 const int*, Complex*, Complex*, const int*, |
|
48 int*, long, long); |
|
49 |
|
50 int F77_FCN (zunghr) (const int*, const int*, const int*, Complex*, |
|
51 const int*, Complex*, Complex*, const int*, |
|
52 int*, long, long); |
|
53 } |
|
54 |
|
55 int |
|
56 ComplexHESS::init (const ComplexMatrix& a) |
|
57 { |
|
58 int a_nr = a.rows (); |
|
59 int a_nc = a.cols (); |
|
60 if (a_nr != a_nc) |
|
61 { |
|
62 (*current_liboctave_error_handler) |
|
63 ("ComplexHESS requires square matrix"); |
|
64 return -1; |
|
65 } |
|
66 |
|
67 char job = 'N'; |
|
68 char side = 'R'; |
|
69 |
|
70 int n = a_nc; |
|
71 int lwork = 32 * n; |
|
72 int info; |
|
73 int ilo; |
|
74 int ihi; |
|
75 |
|
76 Complex *h = dup (a.data (), a.length ()); |
|
77 |
|
78 double *scale = new double [n]; |
|
79 Complex *tau = new Complex [n-1]; |
|
80 Complex *work = new Complex [lwork]; |
|
81 Complex *z = new Complex [n*n]; |
|
82 |
|
83 F77_FCN (zgebal) (&job, &n, h, &n, &ilo, &ihi, scale, &info, 1L, 1L); |
|
84 |
|
85 F77_FCN (zgehrd) (&n, &ilo, &ihi, h, &n, tau, work, &lwork, &info, 1L, |
|
86 1L); |
|
87 |
|
88 copy (z, h, n*n); |
|
89 |
|
90 F77_FCN (zunghr) (&n, &ilo, &ihi, z, &n, tau, work, &lwork, &info, 1L, |
|
91 1L); |
|
92 |
|
93 F77_FCN (zgebak) (&job, &side, &n, &ilo, &ihi, scale, &n, z, &n, &info, |
|
94 1L, 1L); |
|
95 |
|
96 hess_mat = ComplexMatrix (h,n,n); |
|
97 unitary_hess_mat = ComplexMatrix (z,n,n); |
|
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 */ |