base-aepbal.h

Go to the documentation of this file.
00001 /*
00002 
00003 Copyright (C) 2008-2012 Jaroslav Hajek
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 #if !defined (octave_base_aepbal_h)
00024 #define octave_base_aepbal_h 1
00025 
00026 template <class MatrixT, class VectorT>
00027 class base_aepbal
00028 {
00029 protected:
00030   MatrixT balanced_mat;
00031   VectorT scale;
00032   octave_idx_type ilo, ihi;
00033   char job;
00034 
00035   base_aepbal (void) : balanced_mat (), scale (), ilo (), ihi (), job () { }
00036 
00037 public:
00038 
00039   base_aepbal (const base_aepbal& a)
00040     : balanced_mat (a.balanced_mat), scale (a.scale),
00041       ilo(a.ilo), ihi(a.ihi), job(a.job)
00042   {
00043   }
00044 
00045   base_aepbal& operator = (const base_aepbal& a)
00046     {
00047       balanced_mat = a.balanced_mat;
00048       scale = a.scale;
00049       ilo = a.ilo;
00050       ihi = a.ihi;
00051       job = a.job;
00052       return *this;
00053     }
00054 
00055   virtual ~base_aepbal (void) { }
00056 
00057   MatrixT balanced_matrix (void) const { return balanced_mat; }
00058 
00059   VectorT permuting_vector (void) const
00060     {
00061       octave_idx_type n = balanced_mat.rows ();
00062       VectorT pv (n);
00063       for (octave_idx_type i = 0; i < n; i++)
00064         pv(i) = i+1;
00065       for (octave_idx_type i = n-1; i >= ihi; i--)
00066         {
00067           octave_idx_type j = scale(i) - 1;
00068           std::swap (pv(i), pv(j));
00069         }
00070       for (octave_idx_type i = 0; i < ilo-1; i++)
00071         {
00072           octave_idx_type j = scale(i) - 1;
00073           std::swap (pv(i), pv(j));
00074         }
00075 
00076       return pv;
00077     }
00078 
00079   VectorT scaling_vector (void) const
00080     {
00081       octave_idx_type n = balanced_mat.rows ();
00082       VectorT scv (n);
00083       for (octave_idx_type i = 0; i < ilo-1; i++)
00084         scv(i) = 1;
00085       for (octave_idx_type i = ilo-1; i < ihi; i++)
00086         scv(i) = scale(i);
00087       for (octave_idx_type i = ihi; i < n; i++)
00088         scv(i) = 1;
00089 
00090       return scv;
00091     }
00092 };
00093 
00094 #endif
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines