457
|
1 // -*- C++ -*- |
|
2 /* |
|
3 |
1882
|
4 Copyright (C) 1996 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" |
1847
|
33 #include "f77-fcn.h" |
457
|
34 #include "lo-error.h" |
1368
|
35 #include "mx-inlines.cc" |
457
|
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 (); |
1932
|
62 |
457
|
63 if (a_nr != a_nc) |
|
64 { |
|
65 (*current_liboctave_error_handler) ("HESS requires square matrix"); |
|
66 return -1; |
|
67 } |
|
68 |
1932
|
69 char job = 'N'; |
|
70 char side = 'R'; |
457
|
71 |
|
72 int n = a_nc; |
|
73 int lwork = 32 * n; |
|
74 int info; |
|
75 int ilo; |
|
76 int ihi; |
|
77 |
1932
|
78 hess_mat = a; |
|
79 double *h = hess_mat.fortran_vec (); |
457
|
80 |
1932
|
81 Array<double> scale (n); |
|
82 double *pscale = scale.fortran_vec (); |
|
83 |
|
84 F77_XFCN (dgebal, DGEBAL, (&job, n, h, n, ilo, ihi, pscale, info, |
|
85 1L, 1L)); |
457
|
86 |
1932
|
87 if (f77_exception_encountered) |
|
88 (*current_liboctave_error_handler) ("unrecoverable error in dgebal"); |
|
89 else |
|
90 { |
|
91 Array<double> tau (n-1); |
|
92 double *ptau = tau.fortran_vec (); |
|
93 |
|
94 Array<double> work (lwork); |
|
95 double *pwork = work.fortran_vec (); |
457
|
96 |
1932
|
97 F77_XFCN (dgehrd, DGEHRD, (n, ilo, ihi, h, n, ptau, pwork, |
|
98 lwork, info, 1L, 1L)); |
457
|
99 |
1932
|
100 if (f77_exception_encountered) |
|
101 (*current_liboctave_error_handler) ("unrecoverable error in dgehrd"); |
|
102 else |
|
103 { |
|
104 unitary_hess_mat = hess_mat; |
|
105 double *z = unitary_hess_mat.fortran_vec (); |
457
|
106 |
1932
|
107 F77_XFCN (dorghr, DORGHR, (n, ilo, ihi, z, n, ptau, pwork, |
|
108 lwork, info, 1L, 1L)); |
457
|
109 |
1932
|
110 if (f77_exception_encountered) |
|
111 (*current_liboctave_error_handler) |
|
112 ("unrecoverable error in dorghr"); |
|
113 else |
|
114 { |
|
115 F77_XFCN (dgebak, DGEBAK, (&job, &side, n, ilo, ihi, |
|
116 pscale, n, z, n, info, 1L, 1L)); |
457
|
117 |
1932
|
118 if (f77_exception_encountered) |
|
119 (*current_liboctave_error_handler) |
|
120 ("unrecoverable error in dgebak"); |
|
121 else |
|
122 { |
|
123 // If someone thinks of a more graceful way of doing |
|
124 // this (or faster for that matter :-)), please let |
|
125 // me know! |
457
|
126 |
1932
|
127 if (n > 2) |
|
128 for (int j = 0; j < a_nc; j++) |
|
129 for (int i = j+2; i < a_nr; i++) |
|
130 hess_mat.elem (i, j) = 0; |
|
131 } |
|
132 } |
|
133 } |
|
134 } |
457
|
135 |
|
136 return info; |
|
137 } |
|
138 |
|
139 /* |
|
140 ;;; Local Variables: *** |
|
141 ;;; mode: C++ *** |
|
142 ;;; page-delimiter: "^/\\*" *** |
|
143 ;;; End: *** |
|
144 */ |