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 |
1315
|
20 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
457
|
21 |
|
22 */ |
|
23 |
1296
|
24 #if defined (__GNUG__) |
|
25 #pragma implementation |
|
26 #endif |
|
27 |
457
|
28 #ifdef HAVE_CONFIG_H |
1192
|
29 #include <config.h> |
457
|
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 { |
1253
|
39 int F77_FCN (dgebal, DGEBAL) (const char*, const int&, double*, |
|
40 const int&, int&, int&, double*, |
|
41 int&, long, long); |
457
|
42 |
1253
|
43 int F77_FCN (dgehrd, DGEHRD) (const int&, const int&, const int&, |
|
44 double*, const int&, double*, double*, |
|
45 const int&, int&, long, long); |
457
|
46 |
1253
|
47 int F77_FCN (dorghr, DORGHR) (const int&, const int&, const int&, |
|
48 double*, const int&, double*, double*, |
|
49 const int&, int&, long, long); |
457
|
50 |
1253
|
51 int F77_FCN (dgebak, DGEBAK) (const char*, const char*, const int&, |
|
52 const int&, const int&, double*, |
|
53 const int&, double*, const int&, int&, |
|
54 long, long); |
457
|
55 } |
|
56 |
|
57 int |
|
58 HESS::init (const Matrix& a) |
|
59 { |
|
60 int a_nr = a.rows (); |
|
61 int a_nc = a.cols (); |
|
62 if (a_nr != a_nc) |
|
63 { |
|
64 (*current_liboctave_error_handler) ("HESS requires square matrix"); |
|
65 return -1; |
|
66 } |
|
67 |
1251
|
68 char *jobbal = "N"; |
|
69 char *side = "R"; |
457
|
70 |
|
71 int n = a_nc; |
|
72 int lwork = 32 * n; |
|
73 int info; |
|
74 int ilo; |
|
75 int ihi; |
|
76 |
|
77 double *h = dup (a.data (), a.length ()); |
|
78 |
|
79 double *tau = new double [n+1]; |
|
80 double *scale = new double [n]; |
|
81 double *z = new double [n*n]; |
|
82 double *work = new double [lwork]; |
|
83 |
1253
|
84 F77_FCN (dgebal, DGEBAL) (jobbal, n, h, n, ilo, ihi, scale, info, |
|
85 1L, 1L); |
457
|
86 |
1253
|
87 F77_FCN (dgehrd, DGEHRD) (n, ilo, ihi, h, n, tau, work, lwork, info, |
|
88 1L, 1L); |
457
|
89 |
|
90 copy (z, h, n*n); |
|
91 |
1253
|
92 F77_FCN (dorghr, DORGHR) (n, ilo, ihi, z, n, tau, work, lwork, info, |
|
93 1L, 1L); |
457
|
94 |
1253
|
95 F77_FCN (dgebak, DGEBAK) (jobbal, side, n, ilo, ihi, scale, n, z, n, |
|
96 info, 1L, 1L); |
457
|
97 |
|
98 // We need to clear out all of the area below the sub-diagonal which was used |
|
99 // to store the unitary matrix. |
|
100 |
|
101 hess_mat = Matrix (h, n, n); |
|
102 unitary_hess_mat = Matrix (z, n, n); |
|
103 |
|
104 // If someone thinks of a more graceful way of doing this (or faster for |
|
105 // that matter :-)), please let me know! |
|
106 |
|
107 if (n > 2) |
|
108 for (int j = 0; j < a_nc; j++) |
|
109 for (int i = j+2; i < a_nr; i++) |
|
110 hess_mat.elem (i, j) = 0; |
|
111 |
|
112 delete [] tau; |
|
113 delete [] work; |
|
114 delete [] scale; |
|
115 |
|
116 return info; |
|
117 } |
|
118 |
|
119 /* |
|
120 ;;; Local Variables: *** |
|
121 ;;; mode: C++ *** |
|
122 ;;; page-delimiter: "^/\\*" *** |
|
123 ;;; End: *** |
|
124 */ |