457
|
1 /* |
|
2 |
2847
|
3 Copyright (C) 1996, 1997 John W. Eaton |
457
|
4 |
|
5 This file is part of Octave. |
|
6 |
|
7 Octave is free software; you can redistribute it and/or modify it |
|
8 under the terms of the GNU General Public License as published by the |
|
9 Free Software Foundation; either version 2, or (at your option) any |
|
10 later version. |
|
11 |
|
12 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
15 for more details. |
|
16 |
|
17 You should have received a copy of the GNU General Public License |
|
18 along with Octave; see the file COPYING. If not, write to the Free |
1315
|
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
457
|
20 |
|
21 */ |
|
22 |
4192
|
23 #if defined (__GNUG__) && defined (USE_PRAGMA_INTERFACE_IMPLEMENTATION) |
1296
|
24 #pragma implementation |
|
25 #endif |
|
26 |
457
|
27 #ifdef HAVE_CONFIG_H |
1192
|
28 #include <config.h> |
457
|
29 #endif |
|
30 |
|
31 #include "dbleHESS.h" |
1847
|
32 #include "f77-fcn.h" |
457
|
33 #include "lo-error.h" |
|
34 |
|
35 extern "C" |
|
36 { |
4552
|
37 F77_RET_T |
|
38 F77_FUNC (dgebal, DGEBAL) (F77_CONST_CHAR_ARG_DECL, |
|
39 const int&, double*, const int&, int&, |
|
40 int&, double*, int& |
|
41 F77_CHAR_ARG_LEN_DECL); |
457
|
42 |
4552
|
43 F77_RET_T |
|
44 F77_FUNC (dgehrd, DGEHRD) (const int&, const int&, const int&, |
|
45 double*, const int&, double*, double*, |
|
46 const int&, int&); |
457
|
47 |
4552
|
48 F77_RET_T |
|
49 F77_FUNC (dorghr, DORGHR) (const int&, const int&, const int&, |
|
50 double*, const int&, double*, double*, |
|
51 const int&, int&); |
457
|
52 |
4552
|
53 F77_RET_T |
|
54 F77_FUNC (dgebak, DGEBAK) (F77_CONST_CHAR_ARG_DECL, |
|
55 F77_CONST_CHAR_ARG_DECL, |
|
56 const int&, const int&, const int&, double*, |
|
57 const int&, double*, const int&, int& |
|
58 F77_CHAR_ARG_LEN_DECL |
|
59 F77_CHAR_ARG_LEN_DECL); |
457
|
60 } |
|
61 |
|
62 int |
|
63 HESS::init (const Matrix& a) |
|
64 { |
|
65 int a_nr = a.rows (); |
|
66 int a_nc = a.cols (); |
1932
|
67 |
457
|
68 if (a_nr != a_nc) |
|
69 { |
|
70 (*current_liboctave_error_handler) ("HESS requires square matrix"); |
|
71 return -1; |
|
72 } |
|
73 |
1932
|
74 char job = 'N'; |
|
75 char side = 'R'; |
457
|
76 |
|
77 int n = a_nc; |
|
78 int lwork = 32 * n; |
|
79 int info; |
|
80 int ilo; |
|
81 int ihi; |
|
82 |
1932
|
83 hess_mat = a; |
|
84 double *h = hess_mat.fortran_vec (); |
457
|
85 |
1932
|
86 Array<double> scale (n); |
|
87 double *pscale = scale.fortran_vec (); |
|
88 |
4552
|
89 F77_XFCN (dgebal, DGEBAL, (F77_CONST_CHAR_ARG2 (&job, 1), |
|
90 n, h, n, ilo, ihi, pscale, info |
|
91 F77_CHAR_ARG_LEN (1))); |
457
|
92 |
1932
|
93 if (f77_exception_encountered) |
|
94 (*current_liboctave_error_handler) ("unrecoverable error in dgebal"); |
|
95 else |
|
96 { |
|
97 Array<double> tau (n-1); |
|
98 double *ptau = tau.fortran_vec (); |
|
99 |
|
100 Array<double> work (lwork); |
|
101 double *pwork = work.fortran_vec (); |
457
|
102 |
1932
|
103 F77_XFCN (dgehrd, DGEHRD, (n, ilo, ihi, h, n, ptau, pwork, |
4552
|
104 lwork, info)); |
457
|
105 |
1932
|
106 if (f77_exception_encountered) |
|
107 (*current_liboctave_error_handler) ("unrecoverable error in dgehrd"); |
|
108 else |
|
109 { |
|
110 unitary_hess_mat = hess_mat; |
|
111 double *z = unitary_hess_mat.fortran_vec (); |
457
|
112 |
1932
|
113 F77_XFCN (dorghr, DORGHR, (n, ilo, ihi, z, n, ptau, pwork, |
4552
|
114 lwork, info)); |
457
|
115 |
1932
|
116 if (f77_exception_encountered) |
|
117 (*current_liboctave_error_handler) |
|
118 ("unrecoverable error in dorghr"); |
|
119 else |
|
120 { |
4552
|
121 F77_XFCN (dgebak, DGEBAK, (F77_CONST_CHAR_ARG2 (&job, 1), |
|
122 F77_CONST_CHAR_ARG2 (&side, 1), |
|
123 n, ilo, ihi, pscale, n, z, |
|
124 n, info |
|
125 F77_CHAR_ARG_LEN (1) |
|
126 F77_CHAR_ARG_LEN (1))); |
457
|
127 |
1932
|
128 if (f77_exception_encountered) |
|
129 (*current_liboctave_error_handler) |
|
130 ("unrecoverable error in dgebak"); |
|
131 else |
|
132 { |
|
133 // If someone thinks of a more graceful way of doing |
|
134 // this (or faster for that matter :-)), please let |
|
135 // me know! |
457
|
136 |
1932
|
137 if (n > 2) |
|
138 for (int j = 0; j < a_nc; j++) |
|
139 for (int i = j+2; i < a_nr; i++) |
|
140 hess_mat.elem (i, j) = 0; |
|
141 } |
|
142 } |
|
143 } |
|
144 } |
457
|
145 |
|
146 return info; |
|
147 } |
|
148 |
|
149 /* |
|
150 ;;; Local Variables: *** |
|
151 ;;; mode: C++ *** |
|
152 ;;; End: *** |
|
153 */ |