annotate liboctave/dbleHESS.cc @ 7334:274d9642ac10 release-3-0-0

[project @ 2007-12-22 01:42:45 by jwe]
author jwe
date Sat, 22 Dec 2007 01:42:46 +0000
parents a1dbe9d80eee
children 29980c6b8604
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
457
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
1 /*
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
2
7017
a1dbe9d80eee [project @ 2007-10-12 21:27:11 by jwe]
jwe
parents: 7016
diff changeset
3 Copyright (C) 1994, 1995, 1996, 1997, 2002, 2003, 2004, 2005, 2007
a1dbe9d80eee [project @ 2007-10-12 21:27:11 by jwe]
jwe
parents: 7016
diff changeset
4 John W. Eaton
457
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
5
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
6 This file is part of Octave.
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
7
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
8 Octave is free software; you can redistribute it and/or modify it
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
9 under the terms of the GNU General Public License as published by the
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5307
diff changeset
10 Free Software Foundation; either version 3 of the License, or (at your
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5307
diff changeset
11 option) any later version.
457
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
12
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
13 Octave is distributed in the hope that it will be useful, but WITHOUT
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
16 for more details.
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
17
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
18 You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5307
diff changeset
19 along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5307
diff changeset
20 <http://www.gnu.org/licenses/>.
457
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
21
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
22 */
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
23
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
24 #ifdef HAVE_CONFIG_H
1192
b6360f2d4fa6 [project @ 1995-03-30 21:38:35 by jwe]
jwe
parents: 1011
diff changeset
25 #include <config.h>
457
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
26 #endif
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
27
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
28 #include "dbleHESS.h"
1847
2ffe49eb95a5 [project @ 1996-02-03 12:47:55 by jwe]
jwe
parents: 1368
diff changeset
29 #include "f77-fcn.h"
457
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
30 #include "lo-error.h"
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
31
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
32 extern "C"
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
33 {
4552
6f3382e08a52 [project @ 2003-10-27 20:38:02 by jwe]
jwe
parents: 4192
diff changeset
34 F77_RET_T
6f3382e08a52 [project @ 2003-10-27 20:38:02 by jwe]
jwe
parents: 4192
diff changeset
35 F77_FUNC (dgebal, DGEBAL) (F77_CONST_CHAR_ARG_DECL,
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
36 const octave_idx_type&, double*, const octave_idx_type&, octave_idx_type&,
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
37 octave_idx_type&, double*, octave_idx_type&
4552
6f3382e08a52 [project @ 2003-10-27 20:38:02 by jwe]
jwe
parents: 4192
diff changeset
38 F77_CHAR_ARG_LEN_DECL);
457
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
39
4552
6f3382e08a52 [project @ 2003-10-27 20:38:02 by jwe]
jwe
parents: 4192
diff changeset
40 F77_RET_T
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
41 F77_FUNC (dgehrd, DGEHRD) (const octave_idx_type&, const octave_idx_type&, const octave_idx_type&,
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
42 double*, const octave_idx_type&, double*, double*,
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
43 const octave_idx_type&, octave_idx_type&);
457
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
44
4552
6f3382e08a52 [project @ 2003-10-27 20:38:02 by jwe]
jwe
parents: 4192
diff changeset
45 F77_RET_T
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
46 F77_FUNC (dorghr, DORGHR) (const octave_idx_type&, const octave_idx_type&, const octave_idx_type&,
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
47 double*, const octave_idx_type&, double*, double*,
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
48 const octave_idx_type&, octave_idx_type&);
457
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
49
4552
6f3382e08a52 [project @ 2003-10-27 20:38:02 by jwe]
jwe
parents: 4192
diff changeset
50 F77_RET_T
6f3382e08a52 [project @ 2003-10-27 20:38:02 by jwe]
jwe
parents: 4192
diff changeset
51 F77_FUNC (dgebak, DGEBAK) (F77_CONST_CHAR_ARG_DECL,
6f3382e08a52 [project @ 2003-10-27 20:38:02 by jwe]
jwe
parents: 4192
diff changeset
52 F77_CONST_CHAR_ARG_DECL,
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
53 const octave_idx_type&, const octave_idx_type&, const octave_idx_type&, double*,
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
54 const octave_idx_type&, double*, const octave_idx_type&, octave_idx_type&
4552
6f3382e08a52 [project @ 2003-10-27 20:38:02 by jwe]
jwe
parents: 4192
diff changeset
55 F77_CHAR_ARG_LEN_DECL
6f3382e08a52 [project @ 2003-10-27 20:38:02 by jwe]
jwe
parents: 4192
diff changeset
56 F77_CHAR_ARG_LEN_DECL);
457
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
57 }
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
58
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
59 octave_idx_type
457
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
60 HESS::init (const Matrix& a)
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
61 {
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
62 octave_idx_type a_nr = a.rows ();
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
63 octave_idx_type a_nc = a.cols ();
1932
682f31b20894 [project @ 1996-02-12 02:26:07 by jwe]
jwe
parents: 1882
diff changeset
64
457
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
65 if (a_nr != a_nc)
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
66 {
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
67 (*current_liboctave_error_handler) ("HESS requires square matrix");
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
68 return -1;
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
69 }
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
70
1932
682f31b20894 [project @ 1996-02-12 02:26:07 by jwe]
jwe
parents: 1882
diff changeset
71 char job = 'N';
682f31b20894 [project @ 1996-02-12 02:26:07 by jwe]
jwe
parents: 1882
diff changeset
72 char side = 'R';
457
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
73
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
74 octave_idx_type n = a_nc;
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
75 octave_idx_type lwork = 32 * n;
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
76 octave_idx_type info;
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
77 octave_idx_type ilo;
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
78 octave_idx_type ihi;
457
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
79
1932
682f31b20894 [project @ 1996-02-12 02:26:07 by jwe]
jwe
parents: 1882
diff changeset
80 hess_mat = a;
682f31b20894 [project @ 1996-02-12 02:26:07 by jwe]
jwe
parents: 1882
diff changeset
81 double *h = hess_mat.fortran_vec ();
457
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
82
1932
682f31b20894 [project @ 1996-02-12 02:26:07 by jwe]
jwe
parents: 1882
diff changeset
83 Array<double> scale (n);
682f31b20894 [project @ 1996-02-12 02:26:07 by jwe]
jwe
parents: 1882
diff changeset
84 double *pscale = scale.fortran_vec ();
682f31b20894 [project @ 1996-02-12 02:26:07 by jwe]
jwe
parents: 1882
diff changeset
85
4552
6f3382e08a52 [project @ 2003-10-27 20:38:02 by jwe]
jwe
parents: 4192
diff changeset
86 F77_XFCN (dgebal, DGEBAL, (F77_CONST_CHAR_ARG2 (&job, 1),
6f3382e08a52 [project @ 2003-10-27 20:38:02 by jwe]
jwe
parents: 4192
diff changeset
87 n, h, n, ilo, ihi, pscale, info
6f3382e08a52 [project @ 2003-10-27 20:38:02 by jwe]
jwe
parents: 4192
diff changeset
88 F77_CHAR_ARG_LEN (1)));
457
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
89
1932
682f31b20894 [project @ 1996-02-12 02:26:07 by jwe]
jwe
parents: 1882
diff changeset
90 if (f77_exception_encountered)
682f31b20894 [project @ 1996-02-12 02:26:07 by jwe]
jwe
parents: 1882
diff changeset
91 (*current_liboctave_error_handler) ("unrecoverable error in dgebal");
682f31b20894 [project @ 1996-02-12 02:26:07 by jwe]
jwe
parents: 1882
diff changeset
92 else
682f31b20894 [project @ 1996-02-12 02:26:07 by jwe]
jwe
parents: 1882
diff changeset
93 {
682f31b20894 [project @ 1996-02-12 02:26:07 by jwe]
jwe
parents: 1882
diff changeset
94 Array<double> tau (n-1);
682f31b20894 [project @ 1996-02-12 02:26:07 by jwe]
jwe
parents: 1882
diff changeset
95 double *ptau = tau.fortran_vec ();
682f31b20894 [project @ 1996-02-12 02:26:07 by jwe]
jwe
parents: 1882
diff changeset
96
682f31b20894 [project @ 1996-02-12 02:26:07 by jwe]
jwe
parents: 1882
diff changeset
97 Array<double> work (lwork);
682f31b20894 [project @ 1996-02-12 02:26:07 by jwe]
jwe
parents: 1882
diff changeset
98 double *pwork = work.fortran_vec ();
457
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
99
1932
682f31b20894 [project @ 1996-02-12 02:26:07 by jwe]
jwe
parents: 1882
diff changeset
100 F77_XFCN (dgehrd, DGEHRD, (n, ilo, ihi, h, n, ptau, pwork,
4552
6f3382e08a52 [project @ 2003-10-27 20:38:02 by jwe]
jwe
parents: 4192
diff changeset
101 lwork, info));
457
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
102
1932
682f31b20894 [project @ 1996-02-12 02:26:07 by jwe]
jwe
parents: 1882
diff changeset
103 if (f77_exception_encountered)
682f31b20894 [project @ 1996-02-12 02:26:07 by jwe]
jwe
parents: 1882
diff changeset
104 (*current_liboctave_error_handler) ("unrecoverable error in dgehrd");
682f31b20894 [project @ 1996-02-12 02:26:07 by jwe]
jwe
parents: 1882
diff changeset
105 else
682f31b20894 [project @ 1996-02-12 02:26:07 by jwe]
jwe
parents: 1882
diff changeset
106 {
682f31b20894 [project @ 1996-02-12 02:26:07 by jwe]
jwe
parents: 1882
diff changeset
107 unitary_hess_mat = hess_mat;
682f31b20894 [project @ 1996-02-12 02:26:07 by jwe]
jwe
parents: 1882
diff changeset
108 double *z = unitary_hess_mat.fortran_vec ();
457
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
109
1932
682f31b20894 [project @ 1996-02-12 02:26:07 by jwe]
jwe
parents: 1882
diff changeset
110 F77_XFCN (dorghr, DORGHR, (n, ilo, ihi, z, n, ptau, pwork,
4552
6f3382e08a52 [project @ 2003-10-27 20:38:02 by jwe]
jwe
parents: 4192
diff changeset
111 lwork, info));
457
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
112
1932
682f31b20894 [project @ 1996-02-12 02:26:07 by jwe]
jwe
parents: 1882
diff changeset
113 if (f77_exception_encountered)
682f31b20894 [project @ 1996-02-12 02:26:07 by jwe]
jwe
parents: 1882
diff changeset
114 (*current_liboctave_error_handler)
682f31b20894 [project @ 1996-02-12 02:26:07 by jwe]
jwe
parents: 1882
diff changeset
115 ("unrecoverable error in dorghr");
682f31b20894 [project @ 1996-02-12 02:26:07 by jwe]
jwe
parents: 1882
diff changeset
116 else
682f31b20894 [project @ 1996-02-12 02:26:07 by jwe]
jwe
parents: 1882
diff changeset
117 {
4552
6f3382e08a52 [project @ 2003-10-27 20:38:02 by jwe]
jwe
parents: 4192
diff changeset
118 F77_XFCN (dgebak, DGEBAK, (F77_CONST_CHAR_ARG2 (&job, 1),
6f3382e08a52 [project @ 2003-10-27 20:38:02 by jwe]
jwe
parents: 4192
diff changeset
119 F77_CONST_CHAR_ARG2 (&side, 1),
6f3382e08a52 [project @ 2003-10-27 20:38:02 by jwe]
jwe
parents: 4192
diff changeset
120 n, ilo, ihi, pscale, n, z,
6f3382e08a52 [project @ 2003-10-27 20:38:02 by jwe]
jwe
parents: 4192
diff changeset
121 n, info
6f3382e08a52 [project @ 2003-10-27 20:38:02 by jwe]
jwe
parents: 4192
diff changeset
122 F77_CHAR_ARG_LEN (1)
6f3382e08a52 [project @ 2003-10-27 20:38:02 by jwe]
jwe
parents: 4192
diff changeset
123 F77_CHAR_ARG_LEN (1)));
457
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
124
1932
682f31b20894 [project @ 1996-02-12 02:26:07 by jwe]
jwe
parents: 1882
diff changeset
125 if (f77_exception_encountered)
682f31b20894 [project @ 1996-02-12 02:26:07 by jwe]
jwe
parents: 1882
diff changeset
126 (*current_liboctave_error_handler)
682f31b20894 [project @ 1996-02-12 02:26:07 by jwe]
jwe
parents: 1882
diff changeset
127 ("unrecoverable error in dgebak");
682f31b20894 [project @ 1996-02-12 02:26:07 by jwe]
jwe
parents: 1882
diff changeset
128 else
682f31b20894 [project @ 1996-02-12 02:26:07 by jwe]
jwe
parents: 1882
diff changeset
129 {
682f31b20894 [project @ 1996-02-12 02:26:07 by jwe]
jwe
parents: 1882
diff changeset
130 // If someone thinks of a more graceful way of doing
682f31b20894 [project @ 1996-02-12 02:26:07 by jwe]
jwe
parents: 1882
diff changeset
131 // this (or faster for that matter :-)), please let
682f31b20894 [project @ 1996-02-12 02:26:07 by jwe]
jwe
parents: 1882
diff changeset
132 // me know!
457
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
133
1932
682f31b20894 [project @ 1996-02-12 02:26:07 by jwe]
jwe
parents: 1882
diff changeset
134 if (n > 2)
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
135 for (octave_idx_type j = 0; j < a_nc; j++)
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
136 for (octave_idx_type i = j+2; i < a_nr; i++)
1932
682f31b20894 [project @ 1996-02-12 02:26:07 by jwe]
jwe
parents: 1882
diff changeset
137 hess_mat.elem (i, j) = 0;
682f31b20894 [project @ 1996-02-12 02:26:07 by jwe]
jwe
parents: 1882
diff changeset
138 }
682f31b20894 [project @ 1996-02-12 02:26:07 by jwe]
jwe
parents: 1882
diff changeset
139 }
682f31b20894 [project @ 1996-02-12 02:26:07 by jwe]
jwe
parents: 1882
diff changeset
140 }
682f31b20894 [project @ 1996-02-12 02:26:07 by jwe]
jwe
parents: 1882
diff changeset
141 }
457
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
142
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
143 return info;
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
144 }
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
145
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
146 /*
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
147 ;;; Local Variables: ***
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
148 ;;; mode: C++ ***
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
149 ;;; End: ***
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
150 */