comparison liboctave/floatHESS.cc @ 7792:39c1026191e9

add missing files from single-precision merge
author John W. Eaton <jwe@octave.org>
date Wed, 21 May 2008 09:36:46 -0400
parents
children eb63fbe60fab
comparison
equal deleted inserted replaced
7791:975e9540be2c 7792:39c1026191e9
1 /*
2
3 Copyright (C) 1994, 1995, 1996, 1997, 2002, 2003, 2004, 2005, 2007
4 John W. Eaton
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 3 of the License, or (at your
11 option) any 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, see
20 <http://www.gnu.org/licenses/>.
21
22 */
23
24 #ifdef HAVE_CONFIG_H
25 #include <config.h>
26 #endif
27
28 #include "floatHESS.h"
29 #include "f77-fcn.h"
30 #include "lo-error.h"
31
32 extern "C"
33 {
34 F77_RET_T
35 F77_FUNC (sgebal, SGEBAL) (F77_CONST_CHAR_ARG_DECL,
36 const octave_idx_type&, float*, const octave_idx_type&, octave_idx_type&,
37 octave_idx_type&, float*, octave_idx_type&
38 F77_CHAR_ARG_LEN_DECL);
39
40 F77_RET_T
41 F77_FUNC (sgehrd, SGEHRD) (const octave_idx_type&, const octave_idx_type&, const octave_idx_type&,
42 float*, const octave_idx_type&, float*, float*,
43 const octave_idx_type&, octave_idx_type&);
44
45 F77_RET_T
46 F77_FUNC (sorghr, SORGHR) (const octave_idx_type&, const octave_idx_type&, const octave_idx_type&,
47 float*, const octave_idx_type&, float*, float*,
48 const octave_idx_type&, octave_idx_type&);
49
50 F77_RET_T
51 F77_FUNC (sgebak, SGEBAK) (F77_CONST_CHAR_ARG_DECL,
52 F77_CONST_CHAR_ARG_DECL,
53 const octave_idx_type&, const octave_idx_type&, const octave_idx_type&, float*,
54 const octave_idx_type&, float*, const octave_idx_type&, octave_idx_type&
55 F77_CHAR_ARG_LEN_DECL
56 F77_CHAR_ARG_LEN_DECL);
57 }
58
59 octave_idx_type
60 FloatHESS::init (const FloatMatrix& a)
61 {
62 octave_idx_type a_nr = a.rows ();
63 octave_idx_type a_nc = a.cols ();
64
65 if (a_nr != a_nc)
66 {
67 (*current_liboctave_error_handler) ("FloatHESS requires square matrix");
68 return -1;
69 }
70
71 char job = 'N';
72 char side = 'R';
73
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;
79
80 hess_mat = a;
81 float *h = hess_mat.fortran_vec ();
82
83 Array<float> scale (n);
84 float *pscale = scale.fortran_vec ();
85
86 F77_XFCN (sgebal, SGEBAL, (F77_CONST_CHAR_ARG2 (&job, 1),
87 n, h, n, ilo, ihi, pscale, info
88 F77_CHAR_ARG_LEN (1)));
89
90 Array<float> tau (n-1);
91 float *ptau = tau.fortran_vec ();
92
93 Array<float> work (lwork);
94 float *pwork = work.fortran_vec ();
95
96 F77_XFCN (sgehrd, SGEHRD, (n, ilo, ihi, h, n, ptau, pwork,
97 lwork, info));
98
99 unitary_hess_mat = hess_mat;
100 float *z = unitary_hess_mat.fortran_vec ();
101
102 F77_XFCN (sorghr, SORGHR, (n, ilo, ihi, z, n, ptau, pwork,
103 lwork, info));
104
105 F77_XFCN (sgebak, SGEBAK, (F77_CONST_CHAR_ARG2 (&job, 1),
106 F77_CONST_CHAR_ARG2 (&side, 1),
107 n, ilo, ihi, pscale, n, z,
108 n, info
109 F77_CHAR_ARG_LEN (1)
110 F77_CHAR_ARG_LEN (1)));
111
112 // If someone thinks of a more graceful way of doing
113 // this (or faster for that matter :-)), please let
114 // me know!
115
116 if (n > 2)
117 for (octave_idx_type j = 0; j < a_nc; j++)
118 for (octave_idx_type i = j+2; i < a_nr; i++)
119 hess_mat.elem (i, j) = 0;
120
121 return info;
122 }
123
124 /*
125 ;;; Local Variables: ***
126 ;;; mode: C++ ***
127 ;;; End: ***
128 */