00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifdef HAVE_CONFIG_H
00024 #include <config.h>
00025 #endif
00026
00027 #include "dbleHESS.h"
00028 #include "f77-fcn.h"
00029 #include "lo-error.h"
00030
00031 extern "C"
00032 {
00033 F77_RET_T
00034 F77_FUNC (dgebal, DGEBAL) (F77_CONST_CHAR_ARG_DECL,
00035 const octave_idx_type&, double*,
00036 const octave_idx_type&, octave_idx_type&,
00037 octave_idx_type&, double*, octave_idx_type&
00038 F77_CHAR_ARG_LEN_DECL);
00039
00040 F77_RET_T
00041 F77_FUNC (dgehrd, DGEHRD) (const octave_idx_type&, const octave_idx_type&,
00042 const octave_idx_type&, double*,
00043 const octave_idx_type&, double*, double*,
00044 const octave_idx_type&, octave_idx_type&);
00045
00046 F77_RET_T
00047 F77_FUNC (dorghr, DORGHR) (const octave_idx_type&, const octave_idx_type&,
00048 const octave_idx_type&, double*,
00049 const octave_idx_type&, double*, double*,
00050 const octave_idx_type&, octave_idx_type&);
00051
00052 F77_RET_T
00053 F77_FUNC (dgebak, DGEBAK) (F77_CONST_CHAR_ARG_DECL,
00054 F77_CONST_CHAR_ARG_DECL,
00055 const octave_idx_type&, const octave_idx_type&,
00056 const octave_idx_type&, double*,
00057 const octave_idx_type&, double*,
00058 const octave_idx_type&, octave_idx_type&
00059 F77_CHAR_ARG_LEN_DECL
00060 F77_CHAR_ARG_LEN_DECL);
00061 }
00062
00063 octave_idx_type
00064 HESS::init (const Matrix& a)
00065 {
00066 octave_idx_type a_nr = a.rows ();
00067 octave_idx_type a_nc = a.cols ();
00068
00069 if (a_nr != a_nc)
00070 {
00071 (*current_liboctave_error_handler) ("HESS requires square matrix");
00072 return -1;
00073 }
00074
00075 char job = 'N';
00076 char side = 'R';
00077
00078 octave_idx_type n = a_nc;
00079 octave_idx_type lwork = 32 * n;
00080 octave_idx_type info;
00081 octave_idx_type ilo;
00082 octave_idx_type ihi;
00083
00084 hess_mat = a;
00085 double *h = hess_mat.fortran_vec ();
00086
00087 Array<double> scale (dim_vector (n, 1));
00088 double *pscale = scale.fortran_vec ();
00089
00090 F77_XFCN (dgebal, DGEBAL, (F77_CONST_CHAR_ARG2 (&job, 1),
00091 n, h, n, ilo, ihi, pscale, info
00092 F77_CHAR_ARG_LEN (1)));
00093
00094 Array<double> tau (dim_vector (n-1, 1));
00095 double *ptau = tau.fortran_vec ();
00096
00097 Array<double> work (dim_vector (lwork, 1));
00098 double *pwork = work.fortran_vec ();
00099
00100 F77_XFCN (dgehrd, DGEHRD, (n, ilo, ihi, h, n, ptau, pwork,
00101 lwork, info));
00102
00103 unitary_hess_mat = hess_mat;
00104 double *z = unitary_hess_mat.fortran_vec ();
00105
00106 F77_XFCN (dorghr, DORGHR, (n, ilo, ihi, z, n, ptau, pwork,
00107 lwork, info));
00108
00109 F77_XFCN (dgebak, DGEBAK, (F77_CONST_CHAR_ARG2 (&job, 1),
00110 F77_CONST_CHAR_ARG2 (&side, 1),
00111 n, ilo, ihi, pscale, n, z,
00112 n, info
00113 F77_CHAR_ARG_LEN (1)
00114 F77_CHAR_ARG_LEN (1)));
00115
00116
00117
00118
00119
00120 if (n > 2)
00121 for (octave_idx_type j = 0; j < a_nc; j++)
00122 for (octave_idx_type i = j+2; i < a_nr; i++)
00123 hess_mat.elem (i, j) = 0;
00124
00125 return info;
00126 }