GNU Octave  4.0.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
floatHESS.cc
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 1994-2015 John W. Eaton
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 3 of the License, or (at your
10 option) any 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, see
19 <http://www.gnu.org/licenses/>.
20 
21 */
22 
23 #ifdef HAVE_CONFIG_H
24 #include <config.h>
25 #endif
26 
27 #include "floatHESS.h"
28 #include "f77-fcn.h"
29 #include "lo-error.h"
30 
31 extern "C"
32 {
33  F77_RET_T
34  F77_FUNC (sgebal, SGEBAL) (F77_CONST_CHAR_ARG_DECL,
35  const octave_idx_type&, float*,
36  const octave_idx_type&, octave_idx_type&,
37  octave_idx_type&, float*, octave_idx_type&
39 
40  F77_RET_T
41  F77_FUNC (sgehrd, SGEHRD) (const octave_idx_type&, const octave_idx_type&,
42  const octave_idx_type&, float*,
43  const octave_idx_type&, float*, float*,
44  const octave_idx_type&, octave_idx_type&);
45 
46  F77_RET_T
47  F77_FUNC (sorghr, SORGHR) (const octave_idx_type&, const octave_idx_type&,
48  const octave_idx_type&, float*,
49  const octave_idx_type&, float*, float*,
50  const octave_idx_type&, octave_idx_type&);
51 
52  F77_RET_T
53  F77_FUNC (sgebak, SGEBAK) (F77_CONST_CHAR_ARG_DECL,
55  const octave_idx_type&, const octave_idx_type&,
56  const octave_idx_type&, float*,
57  const octave_idx_type&, float*,
58  const octave_idx_type&, octave_idx_type&
61 }
62 
65 {
66  octave_idx_type a_nr = a.rows ();
67  octave_idx_type a_nc = a.cols ();
68 
69  if (a_nr != a_nc)
70  {
71  (*current_liboctave_error_handler) ("FloatHESS requires square matrix");
72  return -1;
73  }
74 
75  char job = 'N';
76  char side = 'R';
77 
78  octave_idx_type n = a_nc;
79  octave_idx_type lwork = 32 * n;
80  octave_idx_type info;
81  octave_idx_type ilo;
82  octave_idx_type ihi;
83 
84  hess_mat = a;
85  float *h = hess_mat.fortran_vec ();
86 
87  Array<float> scale (dim_vector (n, 1));
88  float *pscale = scale.fortran_vec ();
89 
90  F77_XFCN (sgebal, SGEBAL, (F77_CONST_CHAR_ARG2 (&job, 1),
91  n, h, n, ilo, ihi, pscale, info
92  F77_CHAR_ARG_LEN (1)));
93 
94  Array<float> tau (dim_vector (n-1, 1));
95  float *ptau = tau.fortran_vec ();
96 
97  Array<float> work (dim_vector (lwork, 1));
98  float *pwork = work.fortran_vec ();
99 
100  F77_XFCN (sgehrd, SGEHRD, (n, ilo, ihi, h, n, ptau, pwork,
101  lwork, info));
102 
104  float *z = unitary_hess_mat.fortran_vec ();
105 
106  F77_XFCN (sorghr, SORGHR, (n, ilo, ihi, z, n, ptau, pwork,
107  lwork, info));
108 
109  F77_XFCN (sgebak, SGEBAK, (F77_CONST_CHAR_ARG2 (&job, 1),
110  F77_CONST_CHAR_ARG2 (&side, 1),
111  n, ilo, ihi, pscale, n, z,
112  n, info
113  F77_CHAR_ARG_LEN (1)
114  F77_CHAR_ARG_LEN (1)));
115 
116  // If someone thinks of a more graceful way of doing
117  // this (or faster for that matter :-)), please let
118  // me know!
119 
120  if (n > 2)
121  for (octave_idx_type j = 0; j < a_nc; j++)
122  for (octave_idx_type i = j+2; i < a_nr; i++)
123  hess_mat.elem (i, j) = 0;
124 
125  return info;
126 }
#define F77_CHAR_ARG_LEN(l)
Definition: f77-fcn.h:253
T & elem(octave_idx_type n)
Definition: Array.h:380
#define F77_XFCN(f, F, args)
Definition: f77-fcn.h:51
octave_idx_type rows(void) const
Definition: Array.h:313
#define F77_CONST_CHAR_ARG2(x, l)
Definition: f77-fcn.h:251
octave_idx_type init(const FloatMatrix &a)
Definition: floatHESS.cc:64
FloatMatrix hess_mat
Definition: floatHESS.h:73
F77_RET_T const octave_idx_type const octave_idx_type float const octave_idx_type float float const octave_idx_type octave_idx_type &F77_RET_T const octave_idx_type const octave_idx_type float const octave_idx_type float float const octave_idx_type octave_idx_type &F77_RET_T F77_CONST_CHAR_ARG_DECL
Definition: floatHESS.cc:54
FloatMatrix unitary_hess_mat
Definition: floatHESS.h:74
#define F77_RET_T
Definition: f77-fcn.h:264
F77_RET_T F77_FUNC(sgebal, SGEBAL)(F77_CONST_CHAR_ARG_DECL
F77_RET_T const octave_idx_type float const octave_idx_type octave_idx_type octave_idx_type float octave_idx_type & F77_CHAR_ARG_LEN_DECL
Definition: floatHESS.cc:35
void scale(Matrix &m, double x, double y, double z)
Definition: graphics.cc:5281
const T * fortran_vec(void) const
Definition: Array.h:481
octave_idx_type cols(void) const
Definition: Array.h:321