GNU Octave  3.8.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
base-aepbal.h
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 2008-2013 Jaroslav Hajek
4 
5 This file is part of Octave.
6 
7 Octave is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 3 of the License, or (at your
10 option) any later version.
11 
12 Octave is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with Octave; see the file COPYING. If not, see
19 <http://www.gnu.org/licenses/>.
20 
21 */
22 
23 #if !defined (octave_base_aepbal_h)
24 #define octave_base_aepbal_h 1
25 
26 template <class MatrixT, class VectorT>
28 {
29 protected:
30  MatrixT balanced_mat;
31  VectorT scale;
33  char job;
34 
35  base_aepbal (void) : balanced_mat (), scale (), ilo (), ihi (), job () { }
36 
37 public:
38 
41  ilo(a.ilo), ihi(a.ihi), job(a.job)
42  {
43  }
44 
46  {
48  scale = a.scale;
49  ilo = a.ilo;
50  ihi = a.ihi;
51  job = a.job;
52  return *this;
53  }
54 
55  virtual ~base_aepbal (void) { }
56 
57  MatrixT balanced_matrix (void) const { return balanced_mat; }
58 
59  VectorT permuting_vector (void) const
60  {
61  octave_idx_type n = balanced_mat.rows ();
62  VectorT pv (n);
63  for (octave_idx_type i = 0; i < n; i++)
64  pv(i) = i+1;
65  for (octave_idx_type i = n-1; i >= ihi; i--)
66  {
67  octave_idx_type j = scale(i) - 1;
68  std::swap (pv(i), pv(j));
69  }
70  for (octave_idx_type i = 0; i < ilo-1; i++)
71  {
72  octave_idx_type j = scale(i) - 1;
73  std::swap (pv(i), pv(j));
74  }
75 
76  return pv;
77  }
78 
79  VectorT scaling_vector (void) const
80  {
81  octave_idx_type n = balanced_mat.rows ();
82  VectorT scv (n);
83  for (octave_idx_type i = 0; i < ilo-1; i++)
84  scv(i) = 1;
85  for (octave_idx_type i = ilo-1; i < ihi; i++)
86  scv(i) = scale(i);
87  for (octave_idx_type i = ihi; i < n; i++)
88  scv(i) = 1;
89 
90  return scv;
91  }
92 };
93 
94 #endif