GNU Octave  4.0.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
dbleGEPBAL.cc
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 1994-2015 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 "dbleGEPBAL.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 (dggbal, DGGBAL) (F77_CONST_CHAR_ARG_DECL,
40  double* A, const octave_idx_type& LDA,
41  double* B, const octave_idx_type& LDB,
43  double* LSCALE, double* RSCALE,
44  double* WORK, octave_idx_type& INFO
46 
47  F77_RET_T
48  F77_FUNC (dggbak, DGGBAK) (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 double* LSCALE, const double* RSCALE,
54  octave_idx_type& M, double* V,
55  const octave_idx_type& LDV, octave_idx_type& INFO
58 
59 }
60 
62 GEPBALANCE::init (const Matrix& a, const Matrix& b,
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) ("GEPBALANCE requires square matrix");
70  return -1;
71  }
72 
73  if (a.dims () != b.dims ())
74  {
75  gripe_nonconformant ("GEPBALANCE", n, n, b.rows(), b.cols());
76  return -1;
77  }
78 
79  octave_idx_type info;
80  octave_idx_type ilo;
81  octave_idx_type ihi;
82 
83  OCTAVE_LOCAL_BUFFER (double, plscale, n);
84  OCTAVE_LOCAL_BUFFER (double, prscale, n);
85  OCTAVE_LOCAL_BUFFER (double, pwork, 6 * n);
86 
87  balanced_mat = a;
88  double *p_balanced_mat = balanced_mat.fortran_vec ();
89  balanced_mat2 = b;
90  double *p_balanced_mat2 = balanced_mat2.fortran_vec ();
91 
92  char job = balance_job[0];
93 
94  F77_XFCN (dggbal, DGGBAL, (F77_CONST_CHAR_ARG2 (&job, 1),
95  n, p_balanced_mat, n, p_balanced_mat2,
96  n, ilo, ihi, plscale, prscale, pwork, info
97  F77_CHAR_ARG_LEN (1)));
98 
99  balancing_mat = Matrix (n, n, 0.0);
100  balancing_mat2 = Matrix (n, n, 0.0);
101  for (octave_idx_type i = 0; i < n; i++)
102  {
103  octave_quit ();
104  balancing_mat.elem (i ,i) = 1.0;
105  balancing_mat2.elem (i ,i) = 1.0;
106  }
107 
108  double *p_balancing_mat = balancing_mat.fortran_vec ();
109  double *p_balancing_mat2 = balancing_mat2.fortran_vec ();
110 
111  // first left
112  F77_XFCN (dggbak, DGGBAK, (F77_CONST_CHAR_ARG2 (&job, 1),
113  F77_CONST_CHAR_ARG2 ("L", 1),
114  n, ilo, ihi, plscale, prscale,
115  n, p_balancing_mat, n, info
116  F77_CHAR_ARG_LEN (1)
117  F77_CHAR_ARG_LEN (1)));
118 
119  // then right
120  F77_XFCN (dggbak, DGGBAK, (F77_CONST_CHAR_ARG2 (&job, 1),
121  F77_CONST_CHAR_ARG2 ("R", 1),
122  n, ilo, ihi, plscale, prscale,
123  n, p_balancing_mat2, n, info
124  F77_CHAR_ARG_LEN (1)
125  F77_CHAR_ARG_LEN (1)));
126 
127  return info;
128 }
Matrix balanced_mat
Definition: dbleGEPBAL.h:78
Matrix balanced_mat2
Definition: dbleGEPBAL.h:79
F77_RET_T const octave_idx_type double const octave_idx_type double const octave_idx_type octave_idx_type octave_idx_type & IHI
Definition: dbleGEPBAL.cc:39
#define F77_CHAR_ARG_LEN(l)
Definition: f77-fcn.h:253
void gripe_nonconformant(const char *op, octave_idx_type op1_len, octave_idx_type op2_len)
F77_RET_T const octave_idx_type double const octave_idx_type double * B
Definition: dbleGEPBAL.cc:39
octave_idx_type init(const Matrix &a, const Matrix &b, const std::string &balance_job)
Definition: dbleGEPBAL.cc:62
F77_RET_T const octave_idx_type & N
Definition: dbleGEPBAL.cc:39
F77_RET_T const octave_idx_type double const octave_idx_type & LDA
Definition: dbleGEPBAL.cc:39
T & elem(octave_idx_type n)
Definition: Array.h:380
#define F77_XFCN(f, F, args)
Definition: f77-fcn.h:51
octave_idx_type rows(void) const
Definition: Array.h:313
#define F77_CONST_CHAR_ARG2(x, l)
Definition: f77-fcn.h:251
const dim_vector & dims(void) const
Return a const-reference so that dims ()(i) works efficiently.
Definition: Array.h:337
F77_RET_T F77_FUNC(dggbal, DGGBAL)(F77_CONST_CHAR_ARG_DECL
F77_RET_T const octave_idx_type double const octave_idx_type double const octave_idx_type & LDB
Definition: dbleGEPBAL.cc:39
Matrix balancing_mat
Definition: dbleGEPBAL.h:80
F77_RET_T const octave_idx_type double const octave_idx_type double const octave_idx_type octave_idx_type octave_idx_type double double * RSCALE
Definition: dbleGEPBAL.cc:39
F77_RET_T F77_CONST_CHAR_ARG_DECL
Definition: dbleGEPBAL.cc:49
F77_RET_T const octave_idx_type const octave_idx_type const octave_idx_type const double const double octave_idx_type & M
Definition: dbleGEPBAL.cc:49
F77_RET_T const octave_idx_type double const octave_idx_type double const octave_idx_type octave_idx_type octave_idx_type double double double octave_idx_type &INFO F77_CHAR_ARG_LEN_DECL
Definition: dbleGEPBAL.cc:39
F77_RET_T const octave_idx_type const octave_idx_type const octave_idx_type const double const double octave_idx_type double * V
Definition: dbleGEPBAL.cc:49
#define F77_RET_T
Definition: f77-fcn.h:264
Definition: dMatrix.h:35
F77_RET_T const octave_idx_type double const octave_idx_type double const octave_idx_type octave_idx_type octave_idx_type double * LSCALE
Definition: dbleGEPBAL.cc:39
Matrix balancing_mat2
Definition: dbleGEPBAL.h:81
F77_RET_T const octave_idx_type double * A
Definition: dbleGEPBAL.cc:39
F77_RET_T const octave_idx_type double const octave_idx_type double const octave_idx_type octave_idx_type octave_idx_type double double double * WORK
Definition: dbleGEPBAL.cc:39
#define OCTAVE_LOCAL_BUFFER(T, buf, size)
Definition: oct-locbuf.h:197
F77_RET_T const octave_idx_type double const octave_idx_type double const octave_idx_type octave_idx_type & ILO
Definition: dbleGEPBAL.cc:39
const T * fortran_vec(void) const
Definition: Array.h:481
octave_idx_type cols(void) const
Definition: Array.h:321
F77_RET_T const octave_idx_type const octave_idx_type const octave_idx_type const double const double octave_idx_type double const octave_idx_type & LDV
Definition: dbleGEPBAL.cc:49