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 "dbleHESS.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 (dgebal) (const char*, const int*, double*, |
|
40 const int*, int*, int*, double*, |
|
41 int*, long, long); |
|
42 |
|
43 int F77_FCN (dgebak) (const char*, const char*, const int*, const int*, |
|
44 const int*, double*, const int*, double*, const int*, |
|
45 int*, long, long); |
|
46 |
|
47 int F77_FCN (dgehrd) (const int*, const int*, const int*, |
|
48 double*, const int*, double*, double*, |
|
49 const int*, int*, long, long); |
|
50 |
|
51 int F77_FCN (dorghr) (const int*, const int*, const int*, |
|
52 double*, const int*, double*, double*, |
|
53 const int*, int*, long, long); |
|
54 } |
|
55 |
|
56 int |
|
57 HESS::init (const Matrix& a) |
|
58 { |
|
59 int a_nr = a.rows (); |
|
60 int a_nc = a.cols (); |
|
61 if (a_nr != a_nc) |
|
62 { |
|
63 (*current_liboctave_error_handler) ("HESS requires square matrix"); |
|
64 return -1; |
|
65 } |
|
66 |
|
67 char jobbal = '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 double *h = dup (a.data (), a.length ()); |
|
77 |
|
78 double *tau = new double [n+1]; |
|
79 double *scale = new double [n]; |
|
80 double *z = new double [n*n]; |
|
81 double *work = new double [lwork]; |
|
82 |
|
83 F77_FCN (dgebal) (&jobbal, &n, h, &n, &ilo, &ihi, scale, &info, |
|
84 1L, 1L); |
|
85 |
|
86 F77_FCN (dgehrd) (&n, &ilo, &ihi, h, &n, tau, work, &lwork, &info, |
|
87 1L, 1L); |
|
88 |
|
89 copy (z, h, n*n); |
|
90 |
|
91 F77_FCN (dorghr) (&n, &ilo, &ihi, z, &n, tau, work, &lwork, &info, |
|
92 1L, 1L); |
|
93 |
|
94 F77_FCN (dgebak) (&jobbal, &side, &n, &ilo, &ihi, scale, &n, z, &n, |
|
95 &info, 1L, 1L); |
|
96 |
|
97 // We need to clear out all of the area below the sub-diagonal which was used |
|
98 // to store the unitary matrix. |
|
99 |
|
100 hess_mat = Matrix (h, n, n); |
|
101 unitary_hess_mat = Matrix (z, n, n); |
|
102 |
|
103 // If someone thinks of a more graceful way of doing this (or faster for |
|
104 // that matter :-)), please let me know! |
|
105 |
|
106 if (n > 2) |
|
107 for (int j = 0; j < a_nc; j++) |
|
108 for (int i = j+2; i < a_nr; i++) |
|
109 hess_mat.elem (i, j) = 0; |
|
110 |
|
111 delete [] tau; |
|
112 delete [] work; |
|
113 delete [] scale; |
|
114 |
|
115 return info; |
|
116 } |
|
117 |
|
118 /* |
|
119 ;;; Local Variables: *** |
|
120 ;;; mode: C++ *** |
|
121 ;;; page-delimiter: "^/\\*" *** |
|
122 ;;; End: *** |
|
123 */ |