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
floatGEPBAL.cc
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 1994-2013 John W. Eaton
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 #ifdef HAVE_CONFIG_H
24 #include <config.h>
25 #endif
26 
27 #include <string>
28 #include <vector>
29 
30 #include "floatGEPBAL.h"
31 #include "Array-util.h"
32 #include "f77-fcn.h"
33 #include "oct-locbuf.h"
34 
35 extern "C"
36 {
37  F77_RET_T
38  F77_FUNC (sggbal, SGGBAL) (F77_CONST_CHAR_ARG_DECL,
39  const octave_idx_type& N, float* A,
40  const octave_idx_type& LDA, float* B,
41  const octave_idx_type& LDB,
43  float* LSCALE, float* RSCALE,
44  float* WORK, octave_idx_type& INFO
46 
47  F77_RET_T
48  F77_FUNC (sggbak, SGGBAK) (F77_CONST_CHAR_ARG_DECL,
50  const octave_idx_type& N,
51  const octave_idx_type& ILO,
52  const octave_idx_type& IHI,
53  const float* LSCALE, const float* RSCALE,
54  octave_idx_type& M, float* V,
55  const octave_idx_type& LDV, octave_idx_type& INFO
58 
59 }
60 
63  const std::string& balance_job)
64 {
65  octave_idx_type n = a.cols ();
66 
67  if (a.rows () != n)
68  {
69  (*current_liboctave_error_handler)
70  ("FloatGEPBALANCE requires square matrix");
71  return -1;
72  }
73 
74  if (a.dims () != b.dims ())
75  {
76  gripe_nonconformant ("FloatGEPBALANCE", n, n, b.rows(), b.cols());
77  return -1;
78  }
79 
80  octave_idx_type info;
81  octave_idx_type ilo;
82  octave_idx_type ihi;
83 
84  OCTAVE_LOCAL_BUFFER (float, plscale, n);
85  OCTAVE_LOCAL_BUFFER (float, prscale, n);
86  OCTAVE_LOCAL_BUFFER (float, pwork, 6 * n);
87 
88  balanced_mat = a;
89  float *p_balanced_mat = balanced_mat.fortran_vec ();
90  balanced_mat2 = b;
91  float *p_balanced_mat2 = balanced_mat2.fortran_vec ();
92 
93  char job = balance_job[0];
94 
95  F77_XFCN (sggbal, SGGBAL, (F77_CONST_CHAR_ARG2 (&job, 1),
96  n, p_balanced_mat, n, p_balanced_mat2,
97  n, ilo, ihi, plscale, prscale, pwork, info
98  F77_CHAR_ARG_LEN (1)));
99 
100  balancing_mat = FloatMatrix (n, n, 0.0);
101  balancing_mat2 = FloatMatrix (n, n, 0.0);
102  for (octave_idx_type i = 0; i < n; i++)
103  {
104  octave_quit ();
105  balancing_mat.elem (i ,i) = 1.0;
106  balancing_mat2.elem (i ,i) = 1.0;
107  }
108 
109  float *p_balancing_mat = balancing_mat.fortran_vec ();
110  float *p_balancing_mat2 = balancing_mat2.fortran_vec ();
111 
112  // first left
113  F77_XFCN (sggbak, SGGBAK, (F77_CONST_CHAR_ARG2 (&job, 1),
114  F77_CONST_CHAR_ARG2 ("L", 1),
115  n, ilo, ihi, plscale, prscale,
116  n, p_balancing_mat, n, info
117  F77_CHAR_ARG_LEN (1)
118  F77_CHAR_ARG_LEN (1)));
119 
120  // then right
121  F77_XFCN (sggbak, SGGBAK, (F77_CONST_CHAR_ARG2 (&job, 1),
122  F77_CONST_CHAR_ARG2 ("R", 1),
123  n, ilo, ihi, plscale, prscale,
124  n, p_balancing_mat2, n, info
125  F77_CHAR_ARG_LEN (1)
126  F77_CHAR_ARG_LEN (1)));
127 
128  return info;
129 }