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 #include "CmplxHESS.h" |
|
29 #include "mx-inlines.cc" |
|
30 #include "lo-error.h" |
|
31 #include "f77-uscore.h" |
|
32 |
|
33 extern "C" |
|
34 { |
|
35 int F77_FCN (zgebal) (const char*, const int*, Complex*, const int*, |
|
36 int*, int*, double*, int*, long, long); |
|
37 |
|
38 int F77_FCN (zgebak) (const char*, const char*, const int*, const int*, |
|
39 const int*, double*, const int*, Complex*, |
|
40 const int*, int*, long, long); |
|
41 |
|
42 int F77_FCN (zgehrd) (const int*, const int*, const int*, Complex*, |
|
43 const int*, Complex*, Complex*, const int*, |
|
44 int*, long, long); |
|
45 |
|
46 int F77_FCN (zunghr) (const int*, const int*, const int*, Complex*, |
|
47 const int*, Complex*, Complex*, const int*, |
|
48 int*, long, long); |
|
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 |
|
63 char job = 'N'; |
|
64 char side = 'R'; |
|
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 |
|
79 F77_FCN (zgebal) (&job, &n, h, &n, &ilo, &ihi, scale, &info, 1L, 1L); |
|
80 |
|
81 F77_FCN (zgehrd) (&n, &ilo, &ihi, h, &n, tau, work, &lwork, &info, 1L, |
|
82 1L); |
|
83 |
|
84 copy (z, h, n*n); |
|
85 |
|
86 F77_FCN (zunghr) (&n, &ilo, &ihi, z, &n, tau, work, &lwork, &info, 1L, |
|
87 1L); |
|
88 |
|
89 F77_FCN (zgebak) (&job, &side, &n, &ilo, &ihi, scale, &n, z, &n, &info, |
|
90 1L, 1L); |
|
91 |
532
|
92 hess_mat = ComplexMatrix (h, n, n); |
|
93 unitary_hess_mat = ComplexMatrix (z, n, n); |
457
|
94 |
|
95 // If someone thinks of a more graceful way of doing this (or faster for |
|
96 // that matter :-)), please let me know! |
|
97 |
|
98 if (n > 2) |
|
99 for (int j = 0; j < a_nc; j++) |
|
100 for (int i = j+2; i < a_nr; i++) |
|
101 hess_mat.elem (i, j) = 0; |
|
102 |
|
103 delete [] work; |
|
104 delete [] tau; |
|
105 delete [] scale; |
|
106 |
|
107 return info; |
|
108 } |
|
109 |
|
110 /* |
|
111 ;;; Local Variables: *** |
|
112 ;;; mode: C++ *** |
|
113 ;;; page-delimiter: "^/\\*" *** |
|
114 ;;; End: *** |
|
115 */ |