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 |
|
25 #include "config.h" |
|
26 #endif |
|
27 |
|
28 #include "dbleHESS.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 (dgebal) (const char*, const int*, double*, |
|
36 const int*, int*, int*, double*, |
|
37 int*, long, long); |
|
38 |
|
39 int F77_FCN (dgebak) (const char*, const char*, const int*, const int*, |
|
40 const int*, double*, const int*, double*, const int*, |
|
41 int*, long, long); |
|
42 |
|
43 int F77_FCN (dgehrd) (const int*, const int*, const int*, |
|
44 double*, const int*, double*, double*, |
|
45 const int*, int*, long, long); |
|
46 |
|
47 int F77_FCN (dorghr) (const int*, const int*, const int*, |
|
48 double*, const int*, double*, double*, |
|
49 const int*, int*, long, long); |
|
50 } |
|
51 |
|
52 int |
|
53 HESS::init (const Matrix& a) |
|
54 { |
|
55 int a_nr = a.rows (); |
|
56 int a_nc = a.cols (); |
|
57 if (a_nr != a_nc) |
|
58 { |
|
59 (*current_liboctave_error_handler) ("HESS requires square matrix"); |
|
60 return -1; |
|
61 } |
|
62 |
|
63 char jobbal = '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 double *h = dup (a.data (), a.length ()); |
|
73 |
|
74 double *tau = new double [n+1]; |
|
75 double *scale = new double [n]; |
|
76 double *z = new double [n*n]; |
|
77 double *work = new double [lwork]; |
|
78 |
|
79 F77_FCN (dgebal) (&jobbal, &n, h, &n, &ilo, &ihi, scale, &info, |
|
80 1L, 1L); |
|
81 |
|
82 F77_FCN (dgehrd) (&n, &ilo, &ihi, h, &n, tau, work, &lwork, &info, |
|
83 1L, 1L); |
|
84 |
|
85 copy (z, h, n*n); |
|
86 |
|
87 F77_FCN (dorghr) (&n, &ilo, &ihi, z, &n, tau, work, &lwork, &info, |
|
88 1L, 1L); |
|
89 |
|
90 F77_FCN (dgebak) (&jobbal, &side, &n, &ilo, &ihi, scale, &n, z, &n, |
|
91 &info, 1L, 1L); |
|
92 |
|
93 // We need to clear out all of the area below the sub-diagonal which was used |
|
94 // to store the unitary matrix. |
|
95 |
|
96 hess_mat = Matrix (h, n, n); |
|
97 unitary_hess_mat = Matrix (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 [] tau; |
|
108 delete [] work; |
|
109 delete [] scale; |
|
110 |
|
111 return info; |
|
112 } |
|
113 |
|
114 /* |
|
115 ;;; Local Variables: *** |
|
116 ;;; mode: C++ *** |
|
117 ;;; page-delimiter: "^/\\*" *** |
|
118 ;;; End: *** |
|
119 */ |