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 |
7016
|
9 Free Software Foundation; either version 3 of the License, or (at your |
|
10 option) any later version. |
457
|
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 |
7016
|
18 along with Octave; see the file COPYING. If not, see |
|
19 <http://www.gnu.org/licenses/>. |
457
|
20 |
|
21 */ |
|
22 |
|
23 #ifdef HAVE_CONFIG_H |
1192
|
24 #include <config.h> |
457
|
25 #endif |
|
26 |
|
27 #include "dbleHESS.h" |
1847
|
28 #include "f77-fcn.h" |
457
|
29 #include "lo-error.h" |
|
30 |
|
31 extern "C" |
|
32 { |
4552
|
33 F77_RET_T |
|
34 F77_FUNC (dgebal, DGEBAL) (F77_CONST_CHAR_ARG_DECL, |
5275
|
35 const octave_idx_type&, double*, const octave_idx_type&, octave_idx_type&, |
|
36 octave_idx_type&, double*, octave_idx_type& |
4552
|
37 F77_CHAR_ARG_LEN_DECL); |
457
|
38 |
4552
|
39 F77_RET_T |
5275
|
40 F77_FUNC (dgehrd, DGEHRD) (const octave_idx_type&, const octave_idx_type&, const octave_idx_type&, |
|
41 double*, const octave_idx_type&, double*, double*, |
|
42 const octave_idx_type&, octave_idx_type&); |
457
|
43 |
4552
|
44 F77_RET_T |
5275
|
45 F77_FUNC (dorghr, DORGHR) (const octave_idx_type&, const octave_idx_type&, const octave_idx_type&, |
|
46 double*, const octave_idx_type&, double*, double*, |
|
47 const octave_idx_type&, octave_idx_type&); |
457
|
48 |
4552
|
49 F77_RET_T |
|
50 F77_FUNC (dgebak, DGEBAK) (F77_CONST_CHAR_ARG_DECL, |
|
51 F77_CONST_CHAR_ARG_DECL, |
5275
|
52 const octave_idx_type&, const octave_idx_type&, const octave_idx_type&, double*, |
|
53 const octave_idx_type&, double*, const octave_idx_type&, octave_idx_type& |
4552
|
54 F77_CHAR_ARG_LEN_DECL |
|
55 F77_CHAR_ARG_LEN_DECL); |
457
|
56 } |
|
57 |
5275
|
58 octave_idx_type |
457
|
59 HESS::init (const Matrix& a) |
|
60 { |
5275
|
61 octave_idx_type a_nr = a.rows (); |
|
62 octave_idx_type a_nc = a.cols (); |
1932
|
63 |
457
|
64 if (a_nr != a_nc) |
|
65 { |
|
66 (*current_liboctave_error_handler) ("HESS requires square matrix"); |
|
67 return -1; |
|
68 } |
|
69 |
1932
|
70 char job = 'N'; |
|
71 char side = 'R'; |
457
|
72 |
5275
|
73 octave_idx_type n = a_nc; |
|
74 octave_idx_type lwork = 32 * n; |
|
75 octave_idx_type info; |
|
76 octave_idx_type ilo; |
|
77 octave_idx_type ihi; |
457
|
78 |
1932
|
79 hess_mat = a; |
|
80 double *h = hess_mat.fortran_vec (); |
457
|
81 |
1932
|
82 Array<double> scale (n); |
|
83 double *pscale = scale.fortran_vec (); |
|
84 |
4552
|
85 F77_XFCN (dgebal, DGEBAL, (F77_CONST_CHAR_ARG2 (&job, 1), |
|
86 n, h, n, ilo, ihi, pscale, info |
|
87 F77_CHAR_ARG_LEN (1))); |
457
|
88 |
1932
|
89 if (f77_exception_encountered) |
|
90 (*current_liboctave_error_handler) ("unrecoverable error in dgebal"); |
|
91 else |
|
92 { |
|
93 Array<double> tau (n-1); |
|
94 double *ptau = tau.fortran_vec (); |
|
95 |
|
96 Array<double> work (lwork); |
|
97 double *pwork = work.fortran_vec (); |
457
|
98 |
1932
|
99 F77_XFCN (dgehrd, DGEHRD, (n, ilo, ihi, h, n, ptau, pwork, |
4552
|
100 lwork, info)); |
457
|
101 |
1932
|
102 if (f77_exception_encountered) |
|
103 (*current_liboctave_error_handler) ("unrecoverable error in dgehrd"); |
|
104 else |
|
105 { |
|
106 unitary_hess_mat = hess_mat; |
|
107 double *z = unitary_hess_mat.fortran_vec (); |
457
|
108 |
1932
|
109 F77_XFCN (dorghr, DORGHR, (n, ilo, ihi, z, n, ptau, pwork, |
4552
|
110 lwork, info)); |
457
|
111 |
1932
|
112 if (f77_exception_encountered) |
|
113 (*current_liboctave_error_handler) |
|
114 ("unrecoverable error in dorghr"); |
|
115 else |
|
116 { |
4552
|
117 F77_XFCN (dgebak, DGEBAK, (F77_CONST_CHAR_ARG2 (&job, 1), |
|
118 F77_CONST_CHAR_ARG2 (&side, 1), |
|
119 n, ilo, ihi, pscale, n, z, |
|
120 n, info |
|
121 F77_CHAR_ARG_LEN (1) |
|
122 F77_CHAR_ARG_LEN (1))); |
457
|
123 |
1932
|
124 if (f77_exception_encountered) |
|
125 (*current_liboctave_error_handler) |
|
126 ("unrecoverable error in dgebak"); |
|
127 else |
|
128 { |
|
129 // If someone thinks of a more graceful way of doing |
|
130 // this (or faster for that matter :-)), please let |
|
131 // me know! |
457
|
132 |
1932
|
133 if (n > 2) |
5275
|
134 for (octave_idx_type j = 0; j < a_nc; j++) |
|
135 for (octave_idx_type i = j+2; i < a_nr; i++) |
1932
|
136 hess_mat.elem (i, j) = 0; |
|
137 } |
|
138 } |
|
139 } |
|
140 } |
457
|
141 |
|
142 return info; |
|
143 } |
|
144 |
|
145 /* |
|
146 ;;; Local Variables: *** |
|
147 ;;; mode: C++ *** |
|
148 ;;; End: *** |
|
149 */ |