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