dbleHESS.cc

Go to the documentation of this file.
00001 /*
00002 
00003 Copyright (C) 1994-2012 John W. Eaton
00004 
00005 This file is part of Octave.
00006 
00007 Octave is free software; you can redistribute it and/or modify it
00008 under the terms of the GNU General Public License as published by the
00009 Free Software Foundation; either version 3 of the License, or (at your
00010 option) any later version.
00011 
00012 Octave is distributed in the hope that it will be useful, but WITHOUT
00013 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00014 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00015 for more details.
00016 
00017 You should have received a copy of the GNU General Public License
00018 along with Octave; see the file COPYING.  If not, see
00019 <http://www.gnu.org/licenses/>.
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   // If someone thinks of a more graceful way of doing
00117   // this (or faster for that matter :-)), please let
00118   // me know!
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 }
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines