fCmplxHESS.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 "fCmplxHESS.h"
00028 #include "f77-fcn.h"
00029 #include "lo-error.h"
00030 
00031 extern "C"
00032 {
00033   F77_RET_T
00034   F77_FUNC (cgebal, CGEBAL) (F77_CONST_CHAR_ARG_DECL,
00035                              const octave_idx_type&, FloatComplex*,
00036                              const octave_idx_type&, octave_idx_type&,
00037                              octave_idx_type&, float*, octave_idx_type&
00038                              F77_CHAR_ARG_LEN_DECL);
00039 
00040   F77_RET_T
00041   F77_FUNC (cgehrd, CGEHRD) (const octave_idx_type&, const octave_idx_type&,
00042                              const octave_idx_type&, FloatComplex*,
00043                              const octave_idx_type&, FloatComplex*,
00044                              FloatComplex*, const octave_idx_type&,
00045                              octave_idx_type&);
00046 
00047   F77_RET_T
00048   F77_FUNC (cunghr, CUNGHR) (const octave_idx_type&, const octave_idx_type&,
00049                              const octave_idx_type&, FloatComplex*,
00050                              const octave_idx_type&, FloatComplex*,
00051                              FloatComplex*, const octave_idx_type&,
00052                              octave_idx_type&);
00053 
00054   F77_RET_T
00055   F77_FUNC (cgebak, CGEBAK) (F77_CONST_CHAR_ARG_DECL,
00056                              F77_CONST_CHAR_ARG_DECL,
00057                              const octave_idx_type&, const octave_idx_type&,
00058                              const octave_idx_type&, float*,
00059                              const octave_idx_type&, FloatComplex*,
00060                              const octave_idx_type&, octave_idx_type&
00061                              F77_CHAR_ARG_LEN_DECL
00062                              F77_CHAR_ARG_LEN_DECL);
00063 }
00064 
00065 octave_idx_type
00066 FloatComplexHESS::init (const FloatComplexMatrix& a)
00067 {
00068   octave_idx_type a_nr = a.rows ();
00069   octave_idx_type a_nc = a.cols ();
00070 
00071   if (a_nr != a_nc)
00072     {
00073       (*current_liboctave_error_handler)
00074         ("FloatComplexHESS requires square matrix");
00075       return -1;
00076     }
00077 
00078   char job = 'N';
00079   char side = 'R';
00080 
00081   octave_idx_type n = a_nc;
00082   octave_idx_type lwork = 32 * n;
00083   octave_idx_type info;
00084   octave_idx_type ilo;
00085   octave_idx_type ihi;
00086 
00087   hess_mat = a;
00088   FloatComplex *h = hess_mat.fortran_vec ();
00089 
00090   Array<float> scale (dim_vector (n, 1));
00091   float *pscale = scale.fortran_vec ();
00092 
00093   F77_XFCN (cgebal, CGEBAL, (F77_CONST_CHAR_ARG2 (&job, 1),
00094                              n, h, n, ilo, ihi, pscale, info
00095                              F77_CHAR_ARG_LEN (1)));
00096 
00097   Array<FloatComplex> tau (dim_vector (n-1, 1));
00098   FloatComplex *ptau = tau.fortran_vec ();
00099 
00100   Array<FloatComplex> work (dim_vector (lwork, 1));
00101   FloatComplex *pwork = work.fortran_vec ();
00102 
00103   F77_XFCN (cgehrd, CGEHRD, (n, ilo, ihi, h, n, ptau, pwork, lwork, info));
00104 
00105   unitary_hess_mat = hess_mat;
00106   FloatComplex *z = unitary_hess_mat.fortran_vec ();
00107 
00108   F77_XFCN (cunghr, CUNGHR, (n, ilo, ihi, z, n, ptau, pwork,
00109                              lwork, info));
00110 
00111   F77_XFCN (cgebak, CGEBAK, (F77_CONST_CHAR_ARG2 (&job, 1),
00112                              F77_CONST_CHAR_ARG2 (&side, 1),
00113                              n, ilo, ihi, pscale, n, z, n, info
00114                              F77_CHAR_ARG_LEN (1)
00115                              F77_CHAR_ARG_LEN (1)));
00116 
00117   // If someone thinks of a more graceful way of
00118   // doing this (or faster for that matter :-)),
00119   // please let me know!
00120 
00121   if (n > 2)
00122     for (octave_idx_type j = 0; j < a_nc; j++)
00123       for (octave_idx_type i = j+2; i < a_nr; i++)
00124         hess_mat.elem (i, j) = 0;
00125 
00126   return info;
00127 }
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines