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
CmplxGEPBAL.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 "CmplxGEPBAL.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 (zggbal, ZGGBAL) (F77_CONST_CHAR_ARG_DECL,
40  const octave_idx_type& LDA, Complex* B,
41  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 
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  ("ComplexGEPBALANCE requires square matrix");
71  return -1;
72  }
73 
74  if (a.dims () != b.dims ())
75  {
76  gripe_nonconformant ("ComplexGEPBALANCE", 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 (double, plscale, n);
85  OCTAVE_LOCAL_BUFFER (double, prscale, n);
86  OCTAVE_LOCAL_BUFFER (double, pwork, 6 * n);
87 
88  balanced_mat = a;
89  Complex *p_balanced_mat = balanced_mat.fortran_vec ();
90  balanced_mat2 = b;
91  Complex *p_balanced_mat2 = balanced_mat2.fortran_vec ();
92 
93  char job = balance_job[0];
94 
95  F77_XFCN (zggbal, ZGGBAL, (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 = Matrix (n, n, 0.0);
101  balancing_mat2 = Matrix (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  double *p_balancing_mat = balancing_mat.fortran_vec ();
110  double *p_balancing_mat2 = balancing_mat2.fortran_vec ();
111 
112  // first left
113  F77_XFCN (dggbak, DGGBAK, (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 (dggbak, DGGBAK, (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 }
F77_RET_T F77_CONST_CHAR_ARG_DECL
Definition: CmplxGEPBAL.cc:49
#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 F77_FUNC(zggbal, ZGGBAL)(F77_CONST_CHAR_ARG_DECL
F77_RET_T const octave_idx_type Complex const octave_idx_type Complex const octave_idx_type octave_idx_type octave_idx_type double double * RSCALE
Definition: CmplxGEPBAL.cc:39
ComplexMatrix balanced_mat
Definition: CmplxGEPBAL.h:80
F77_RET_T const octave_idx_type Complex * A
Definition: CmplxGEPBAL.cc:39
F77_RET_T const octave_idx_type const octave_idx_type const octave_idx_type const double const double octave_idx_type & M
Definition: CmplxGEPBAL.cc:49
F77_RET_T const octave_idx_type Complex const octave_idx_type Complex const octave_idx_type octave_idx_type & ILO
Definition: CmplxGEPBAL.cc:39
T & elem(octave_idx_type n)
Definition: Array.h:380
#define F77_XFCN(f, F, args)
Definition: f77-fcn.h:51
ComplexMatrix balanced_mat2
Definition: CmplxGEPBAL.h:81
F77_RET_T const octave_idx_type Complex const octave_idx_type Complex const octave_idx_type & LDB
Definition: CmplxGEPBAL.cc:39
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 const octave_idx_type Complex const octave_idx_type Complex const octave_idx_type octave_idx_type octave_idx_type double double double octave_idx_type &INFO F77_CHAR_ARG_LEN_DECL
Definition: CmplxGEPBAL.cc:39
#define F77_RET_T
Definition: f77-fcn.h:264
Definition: dMatrix.h:35
Matrix balancing_mat
Definition: CmplxGEPBAL.h:82
Matrix balancing_mat2
Definition: CmplxGEPBAL.h:83
F77_RET_T const octave_idx_type Complex const octave_idx_type Complex const octave_idx_type octave_idx_type octave_idx_type double double double * WORK
Definition: CmplxGEPBAL.cc:39
F77_RET_T const octave_idx_type Complex const octave_idx_type & LDA
Definition: CmplxGEPBAL.cc:39
F77_RET_T const octave_idx_type Complex const octave_idx_type Complex const octave_idx_type octave_idx_type octave_idx_type double * LSCALE
Definition: CmplxGEPBAL.cc:39
F77_RET_T const octave_idx_type Complex const octave_idx_type Complex * B
Definition: CmplxGEPBAL.cc:39
F77_RET_T const octave_idx_type & N
Definition: CmplxGEPBAL.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: CmplxGEPBAL.cc:49
octave_idx_type init(const ComplexMatrix &a, const ComplexMatrix &b, const std::string &balance_job)
Definition: CmplxGEPBAL.cc:62
F77_RET_T const octave_idx_type Complex const octave_idx_type Complex const octave_idx_type octave_idx_type octave_idx_type & IHI
Definition: CmplxGEPBAL.cc:39
#define OCTAVE_LOCAL_BUFFER(T, buf, size)
Definition: oct-locbuf.h:197
std::complex< double > Complex
Definition: oct-cmplx.h:29
const T * fortran_vec(void) const
Definition: Array.h:481
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: CmplxGEPBAL.cc:49
octave_idx_type cols(void) const
Definition: Array.h:321