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 |
4066
|
23 #if defined (__GNUG__) && ! defined (NO_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 { |
3887
|
37 int F77_FUNC (dgebal, DGEBAL) (const char*, const int&, double*, |
1253
|
38 const int&, int&, int&, double*, |
|
39 int&, long, long); |
457
|
40 |
3887
|
41 int F77_FUNC (dgehrd, DGEHRD) (const int&, const int&, const int&, |
1253
|
42 double*, const int&, double*, double*, |
|
43 const int&, int&, long, long); |
457
|
44 |
3887
|
45 int F77_FUNC (dorghr, DORGHR) (const int&, const int&, const int&, |
1253
|
46 double*, const int&, double*, double*, |
|
47 const int&, int&, long, long); |
457
|
48 |
3887
|
49 int F77_FUNC (dgebak, DGEBAK) (const char*, const char*, const int&, |
1253
|
50 const int&, const int&, double*, |
|
51 const int&, double*, const int&, int&, |
|
52 long, long); |
457
|
53 } |
|
54 |
|
55 int |
|
56 HESS::init (const Matrix& a) |
|
57 { |
|
58 int a_nr = a.rows (); |
|
59 int a_nc = a.cols (); |
1932
|
60 |
457
|
61 if (a_nr != a_nc) |
|
62 { |
|
63 (*current_liboctave_error_handler) ("HESS requires square matrix"); |
|
64 return -1; |
|
65 } |
|
66 |
1932
|
67 char job = 'N'; |
|
68 char side = 'R'; |
457
|
69 |
|
70 int n = a_nc; |
|
71 int lwork = 32 * n; |
|
72 int info; |
|
73 int ilo; |
|
74 int ihi; |
|
75 |
1932
|
76 hess_mat = a; |
|
77 double *h = hess_mat.fortran_vec (); |
457
|
78 |
1932
|
79 Array<double> scale (n); |
|
80 double *pscale = scale.fortran_vec (); |
|
81 |
|
82 F77_XFCN (dgebal, DGEBAL, (&job, n, h, n, ilo, ihi, pscale, info, |
|
83 1L, 1L)); |
457
|
84 |
1932
|
85 if (f77_exception_encountered) |
|
86 (*current_liboctave_error_handler) ("unrecoverable error in dgebal"); |
|
87 else |
|
88 { |
|
89 Array<double> tau (n-1); |
|
90 double *ptau = tau.fortran_vec (); |
|
91 |
|
92 Array<double> work (lwork); |
|
93 double *pwork = work.fortran_vec (); |
457
|
94 |
1932
|
95 F77_XFCN (dgehrd, DGEHRD, (n, ilo, ihi, h, n, ptau, pwork, |
|
96 lwork, info, 1L, 1L)); |
457
|
97 |
1932
|
98 if (f77_exception_encountered) |
|
99 (*current_liboctave_error_handler) ("unrecoverable error in dgehrd"); |
|
100 else |
|
101 { |
|
102 unitary_hess_mat = hess_mat; |
|
103 double *z = unitary_hess_mat.fortran_vec (); |
457
|
104 |
1932
|
105 F77_XFCN (dorghr, DORGHR, (n, ilo, ihi, z, n, ptau, pwork, |
|
106 lwork, info, 1L, 1L)); |
457
|
107 |
1932
|
108 if (f77_exception_encountered) |
|
109 (*current_liboctave_error_handler) |
|
110 ("unrecoverable error in dorghr"); |
|
111 else |
|
112 { |
|
113 F77_XFCN (dgebak, DGEBAK, (&job, &side, n, ilo, ihi, |
|
114 pscale, n, z, n, info, 1L, 1L)); |
457
|
115 |
1932
|
116 if (f77_exception_encountered) |
|
117 (*current_liboctave_error_handler) |
|
118 ("unrecoverable error in dgebak"); |
|
119 else |
|
120 { |
|
121 // If someone thinks of a more graceful way of doing |
|
122 // this (or faster for that matter :-)), please let |
|
123 // me know! |
457
|
124 |
1932
|
125 if (n > 2) |
|
126 for (int j = 0; j < a_nc; j++) |
|
127 for (int i = j+2; i < a_nr; i++) |
|
128 hess_mat.elem (i, j) = 0; |
|
129 } |
|
130 } |
|
131 } |
|
132 } |
457
|
133 |
|
134 return info; |
|
135 } |
|
136 |
|
137 /* |
|
138 ;;; Local Variables: *** |
|
139 ;;; mode: C++ *** |
|
140 ;;; End: *** |
|
141 */ |