00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifdef HAVE_CONFIG_H
00024 #include <config.h>
00025 #endif
00026
00027 #include <iostream>
00028
00029 #include "dbleSCHUR.h"
00030 #include "f77-fcn.h"
00031 #include "lo-error.h"
00032
00033 extern "C"
00034 {
00035 F77_RET_T
00036 F77_FUNC (dgeesx, DGEESX) (F77_CONST_CHAR_ARG_DECL,
00037 F77_CONST_CHAR_ARG_DECL,
00038 SCHUR::select_function,
00039 F77_CONST_CHAR_ARG_DECL,
00040 const octave_idx_type&, double*,
00041 const octave_idx_type&, octave_idx_type&,
00042 double*, double*, double*, const octave_idx_type&,
00043 double&, double&, double*, const octave_idx_type&,
00044 octave_idx_type*, const octave_idx_type&,
00045 octave_idx_type*, octave_idx_type&
00046 F77_CHAR_ARG_LEN_DECL
00047 F77_CHAR_ARG_LEN_DECL
00048 F77_CHAR_ARG_LEN_DECL);
00049 }
00050
00051 static octave_idx_type
00052 select_ana (const double& a, const double&)
00053 {
00054 return (a < 0.0);
00055 }
00056
00057 static octave_idx_type
00058 select_dig (const double& a, const double& b)
00059 {
00060 return (hypot (a, b) < 1.0);
00061 }
00062
00063 octave_idx_type
00064 SCHUR::init (const Matrix& a, const std::string& ord, bool calc_unitary)
00065 {
00066 octave_idx_type a_nr = a.rows ();
00067 octave_idx_type a_nc = a.cols ();
00068
00069 if (a_nr != a_nc)
00070 {
00071 (*current_liboctave_error_handler) ("SCHUR requires square matrix");
00072 return -1;
00073 }
00074 else if (a_nr == 0)
00075 {
00076 schur_mat.clear ();
00077 unitary_mat.clear ();
00078 return 0;
00079 }
00080
00081
00082
00083
00084 char jobvs;
00085 char sense = 'N';
00086 char sort = 'N';
00087
00088 if (calc_unitary)
00089 jobvs = 'V';
00090 else
00091 jobvs = 'N';
00092
00093 char ord_char = ord.empty () ? 'U' : ord[0];
00094
00095 if (ord_char == 'A' || ord_char == 'D' || ord_char == 'a' || ord_char == 'd')
00096 sort = 'S';
00097
00098 if (ord_char == 'A' || ord_char == 'a')
00099 selector = select_ana;
00100 else if (ord_char == 'D' || ord_char == 'd')
00101 selector = select_dig;
00102 else
00103 selector = 0;
00104
00105 octave_idx_type n = a_nc;
00106 octave_idx_type lwork = 8 * n;
00107 octave_idx_type liwork = 1;
00108 octave_idx_type info;
00109 octave_idx_type sdim;
00110 double rconde;
00111 double rcondv;
00112
00113 schur_mat = a;
00114
00115 if (calc_unitary)
00116 unitary_mat.clear (n, n);
00117
00118 double *s = schur_mat.fortran_vec ();
00119 double *q = unitary_mat.fortran_vec ();
00120
00121 Array<double> wr (dim_vector (n, 1));
00122 double *pwr = wr.fortran_vec ();
00123
00124 Array<double> wi (dim_vector (n, 1));
00125 double *pwi = wi.fortran_vec ();
00126
00127 Array<double> work (dim_vector (lwork, 1));
00128 double *pwork = work.fortran_vec ();
00129
00130
00131 octave_idx_type ntmp = (ord_char == 'N' || ord_char == 'n') ? 0 : n;
00132 Array<octave_idx_type> bwork (dim_vector (ntmp, 1));
00133 octave_idx_type *pbwork = bwork.fortran_vec ();
00134
00135 Array<octave_idx_type> iwork (dim_vector (liwork, 1));
00136 octave_idx_type *piwork = iwork.fortran_vec ();
00137
00138 F77_XFCN (dgeesx, DGEESX, (F77_CONST_CHAR_ARG2 (&jobvs, 1),
00139 F77_CONST_CHAR_ARG2 (&sort, 1),
00140 selector,
00141 F77_CONST_CHAR_ARG2 (&sense, 1),
00142 n, s, n, sdim, pwr, pwi, q, n, rconde, rcondv,
00143 pwork, lwork, piwork, liwork, pbwork, info
00144 F77_CHAR_ARG_LEN (1)
00145 F77_CHAR_ARG_LEN (1)
00146 F77_CHAR_ARG_LEN (1)));
00147
00148 return info;
00149 }
00150
00151 std::ostream&
00152 operator << (std::ostream& os, const SCHUR& a)
00153 {
00154 os << a.schur_matrix () << "\n";
00155 os << a.unitary_matrix () << "\n";
00156
00157 return os;
00158 }
00159
00160 SCHUR::SCHUR (const Matrix& s, const Matrix& u)
00161 : schur_mat (s), unitary_mat (u), selector (0)
00162 {
00163 octave_idx_type n = s.rows ();
00164 if (s.columns () != n || u.rows () != n || u.columns () != n)
00165 (*current_liboctave_error_handler)
00166 ("schur: inconsistent matrix dimensions");
00167 }
00168