floatAEPBAL.cc

Go to the documentation of this file.
00001 /*
00002 
00003 Copyright (C) 1994-2012 John W. Eaton
00004 Copyright (C) 2008 Jaroslav Hajek
00005 
00006 This file is part of Octave.
00007 
00008 Octave is free software; you can redistribute it and/or modify it
00009 under the terms of the GNU General Public License as published by the
00010 Free Software Foundation; either version 3 of the License, or (at your
00011 option) any later version.
00012 
00013 Octave is distributed in the hope that it will be useful, but WITHOUT
00014 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00015 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00016 for more details.
00017 
00018 You should have received a copy of the GNU General Public License
00019 along with Octave; see the file COPYING.  If not, see
00020 <http://www.gnu.org/licenses/>.
00021 
00022 */
00023 
00024 #ifdef HAVE_CONFIG_H
00025 #include <config.h>
00026 #endif
00027 
00028 #include <string>
00029 
00030 #include "floatAEPBAL.h"
00031 #include "f77-fcn.h"
00032 
00033 extern "C"
00034 {
00035   F77_RET_T
00036   F77_FUNC (sgebal, SGEBAL) (F77_CONST_CHAR_ARG_DECL,
00037                              const octave_idx_type&, float*,
00038                              const octave_idx_type&, octave_idx_type&,
00039                              octave_idx_type&, float*, octave_idx_type&
00040                              F77_CHAR_ARG_LEN_DECL);
00041 
00042   F77_RET_T
00043   F77_FUNC (sgebak, SGEBAK) (F77_CONST_CHAR_ARG_DECL,
00044                              F77_CONST_CHAR_ARG_DECL,
00045                              const octave_idx_type&, const octave_idx_type&,
00046                              const octave_idx_type&, const float*,
00047                              const octave_idx_type&, float*,
00048                              const octave_idx_type&, octave_idx_type&
00049                              F77_CHAR_ARG_LEN_DECL
00050                              F77_CHAR_ARG_LEN_DECL);
00051 }
00052 
00053 FloatAEPBALANCE::FloatAEPBALANCE (const FloatMatrix& a,
00054                                   bool noperm, bool noscal)
00055   : base_aepbal<FloatMatrix, FloatColumnVector> ()
00056 {
00057   octave_idx_type n = a.cols ();
00058 
00059   if (a.rows () != n)
00060     {
00061       (*current_liboctave_error_handler) ("AEPBALANCE requires square matrix");
00062       return;
00063     }
00064 
00065   octave_idx_type info;
00066 
00067   scale = FloatColumnVector (n);
00068   float *pscale = scale.fortran_vec ();
00069 
00070   balanced_mat = a;
00071   float *p_balanced_mat = balanced_mat.fortran_vec ();
00072 
00073   job = noperm ? (noscal ? 'N' : 'S') : (noscal ? 'P' : 'B');
00074 
00075   F77_XFCN (sgebal, SGEBAL, (F77_CONST_CHAR_ARG2 (&job, 1),
00076                              n, p_balanced_mat, n, ilo, ihi, pscale, info
00077                              F77_CHAR_ARG_LEN (1)));
00078 }
00079 
00080 FloatMatrix
00081 FloatAEPBALANCE::balancing_matrix (void) const
00082 {
00083   octave_idx_type n = balanced_mat.rows ();
00084   FloatMatrix balancing_mat (n, n, 0.0);
00085   for (octave_idx_type i = 0; i < n; i++)
00086     balancing_mat.elem (i ,i) = 1.0;
00087 
00088   float *p_balancing_mat = balancing_mat.fortran_vec ();
00089   const float *pscale = scale.fortran_vec ();
00090 
00091   octave_idx_type info;
00092 
00093   char side = 'R';
00094 
00095   F77_XFCN (sgebak, SGEBAK, (F77_CONST_CHAR_ARG2 (&job, 1),
00096                              F77_CONST_CHAR_ARG2 (&side, 1),
00097                              n, ilo, ihi, pscale, n,
00098                              p_balancing_mat, n, info
00099                              F77_CHAR_ARG_LEN (1)
00100                              F77_CHAR_ARG_LEN (1)));
00101 
00102   return balancing_mat;
00103 }
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines