1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200
|
#include "rb_lapack.h"
extern VOID slaqr5_(logical* wantt, logical* wantz, integer* kacc22, integer* n, integer* ktop, integer* kbot, integer* nshfts, real* sr, real* si, real* h, integer* ldh, integer* iloz, integer* ihiz, real* z, integer* ldz, real* v, integer* ldv, real* u, integer* ldu, integer* nv, real* wv, integer* ldwv, integer* nh, real* wh, integer* ldwh);
static VALUE
rblapack_slaqr5(int argc, VALUE *argv, VALUE self){
VALUE rblapack_wantt;
logical wantt;
VALUE rblapack_wantz;
logical wantz;
VALUE rblapack_kacc22;
integer kacc22;
VALUE rblapack_ktop;
integer ktop;
VALUE rblapack_kbot;
integer kbot;
VALUE rblapack_sr;
real *sr;
VALUE rblapack_si;
real *si;
VALUE rblapack_h;
real *h;
VALUE rblapack_iloz;
integer iloz;
VALUE rblapack_ihiz;
integer ihiz;
VALUE rblapack_z;
real *z;
VALUE rblapack_nv;
integer nv;
VALUE rblapack_nh;
integer nh;
VALUE rblapack_sr_out__;
real *sr_out__;
VALUE rblapack_si_out__;
real *si_out__;
VALUE rblapack_h_out__;
real *h_out__;
VALUE rblapack_z_out__;
real *z_out__;
real *v;
real *u;
real *wv;
real *wh;
integer nshfts;
integer ldh;
integer n;
integer ldv;
integer ldu;
integer ldwv;
integer ldwh;
integer ldz;
VALUE rblapack_options;
if (argc > 0 && TYPE(argv[argc-1]) == T_HASH) {
argc--;
rblapack_options = argv[argc];
if (rb_hash_aref(rblapack_options, sHelp) == Qtrue) {
printf("%s\n", "USAGE:\n sr, si, h, z = NumRu::Lapack.slaqr5( wantt, wantz, kacc22, ktop, kbot, sr, si, h, iloz, ihiz, z, nv, nh, [:usage => usage, :help => help])\n\n\nFORTRAN MANUAL\n SUBROUTINE SLAQR5( WANTT, WANTZ, KACC22, N, KTOP, KBOT, NSHFTS, SR, SI, H, LDH, ILOZ, IHIZ, Z, LDZ, V, LDV, U, LDU, NV, WV, LDWV, NH, WH, LDWH )\n\n* This auxiliary subroutine called by SLAQR0 performs a\n* single small-bulge multi-shift QR sweep.\n*\n\n* WANTT (input) logical scalar\n* WANTT = .true. if the quasi-triangular Schur factor\n* is being computed. WANTT is set to .false. otherwise.\n*\n* WANTZ (input) logical scalar\n* WANTZ = .true. if the orthogonal Schur factor is being\n* computed. WANTZ is set to .false. otherwise.\n*\n* KACC22 (input) integer with value 0, 1, or 2.\n* Specifies the computation mode of far-from-diagonal\n* orthogonal updates.\n* = 0: SLAQR5 does not accumulate reflections and does not\n* use matrix-matrix multiply to update far-from-diagonal\n* matrix entries.\n* = 1: SLAQR5 accumulates reflections and uses matrix-matrix\n* multiply to update the far-from-diagonal matrix entries.\n* = 2: SLAQR5 accumulates reflections, uses matrix-matrix\n* multiply to update the far-from-diagonal matrix entries,\n* and takes advantage of 2-by-2 block structure during\n* matrix multiplies.\n*\n* N (input) integer scalar\n* N is the order of the Hessenberg matrix H upon which this\n* subroutine operates.\n*\n* KTOP (input) integer scalar\n* KBOT (input) integer scalar\n* These are the first and last rows and columns of an\n* isolated diagonal block upon which the QR sweep is to be\n* applied. It is assumed without a check that\n* either KTOP = 1 or H(KTOP,KTOP-1) = 0\n* and\n* either KBOT = N or H(KBOT+1,KBOT) = 0.\n*\n* NSHFTS (input) integer scalar\n* NSHFTS gives the number of simultaneous shifts. NSHFTS\n* must be positive and even.\n*\n* SR (input/output) REAL array of size (NSHFTS)\n* SI (input/output) REAL array of size (NSHFTS)\n* SR contains the real parts and SI contains the imaginary\n* parts of the NSHFTS shifts of origin that define the\n* multi-shift QR sweep. On output SR and SI may be\n* reordered.\n*\n* H (input/output) REAL array of size (LDH,N)\n* On input H contains a Hessenberg matrix. On output a\n* multi-shift QR sweep with shifts SR(J)+i*SI(J) is applied\n* to the isolated diagonal block in rows and columns KTOP\n* through KBOT.\n*\n* LDH (input) integer scalar\n* LDH is the leading dimension of H just as declared in the\n* calling procedure. LDH.GE.MAX(1,N).\n*\n* ILOZ (input) INTEGER\n* IHIZ (input) INTEGER\n* Specify the rows of Z to which transformations must be\n* applied if WANTZ is .TRUE.. 1 .LE. ILOZ .LE. IHIZ .LE. N\n*\n* Z (input/output) REAL array of size (LDZ,IHI)\n* If WANTZ = .TRUE., then the QR Sweep orthogonal\n* similarity transformation is accumulated into\n* Z(ILOZ:IHIZ,ILO:IHI) from the right.\n* If WANTZ = .FALSE., then Z is unreferenced.\n*\n* LDZ (input) integer scalar\n* LDA is the leading dimension of Z just as declared in\n* the calling procedure. LDZ.GE.N.\n*\n* V (workspace) REAL array of size (LDV,NSHFTS/2)\n*\n* LDV (input) integer scalar\n* LDV is the leading dimension of V as declared in the\n* calling procedure. LDV.GE.3.\n*\n* U (workspace) REAL array of size\n* (LDU,3*NSHFTS-3)\n*\n* LDU (input) integer scalar\n* LDU is the leading dimension of U just as declared in the\n* in the calling subroutine. LDU.GE.3*NSHFTS-3.\n*\n* NH (input) integer scalar\n* NH is the number of columns in array WH available for\n* workspace. NH.GE.1.\n*\n* WH (workspace) REAL array of size (LDWH,NH)\n*\n* LDWH (input) integer scalar\n* Leading dimension of WH just as declared in the\n* calling procedure. LDWH.GE.3*NSHFTS-3.\n*\n* NV (input) integer scalar\n* NV is the number of rows in WV agailable for workspace.\n* NV.GE.1.\n*\n* WV (workspace) REAL array of size\n* (LDWV,3*NSHFTS-3)\n*\n* LDWV (input) integer scalar\n* LDWV is the leading dimension of WV as declared in the\n* in the calling subroutine. LDWV.GE.NV.\n*\n\n* ================================================================\n* Based on contributions by\n* Karen Braman and Ralph Byers, Department of Mathematics,\n* University of Kansas, USA\n*\n* ================================================================\n* Reference:\n*\n* K. Braman, R. Byers and R. Mathias, The Multi-Shift QR\n* Algorithm Part I: Maintaining Well Focused Shifts, and\n* Level 3 Performance, SIAM Journal of Matrix Analysis,\n* volume 23, pages 929--947, 2002.\n*\n* ================================================================\n\n");
return Qnil;
}
if (rb_hash_aref(rblapack_options, sUsage) == Qtrue) {
printf("%s\n", "USAGE:\n sr, si, h, z = NumRu::Lapack.slaqr5( wantt, wantz, kacc22, ktop, kbot, sr, si, h, iloz, ihiz, z, nv, nh, [:usage => usage, :help => help])\n");
return Qnil;
}
} else
rblapack_options = Qnil;
if (argc != 13 && argc != 13)
rb_raise(rb_eArgError,"wrong number of arguments (%d for 13)", argc);
rblapack_wantt = argv[0];
rblapack_wantz = argv[1];
rblapack_kacc22 = argv[2];
rblapack_ktop = argv[3];
rblapack_kbot = argv[4];
rblapack_sr = argv[5];
rblapack_si = argv[6];
rblapack_h = argv[7];
rblapack_iloz = argv[8];
rblapack_ihiz = argv[9];
rblapack_z = argv[10];
rblapack_nv = argv[11];
rblapack_nh = argv[12];
if (argc == 13) {
} else if (rblapack_options != Qnil) {
} else {
}
wantt = (rblapack_wantt == Qtrue);
kacc22 = NUM2INT(rblapack_kacc22);
kbot = NUM2INT(rblapack_kbot);
if (!NA_IsNArray(rblapack_si))
rb_raise(rb_eArgError, "si (7th argument) must be NArray");
if (NA_RANK(rblapack_si) != 1)
rb_raise(rb_eArgError, "rank of si (7th argument) must be %d", 1);
nshfts = NA_SHAPE0(rblapack_si);
if (NA_TYPE(rblapack_si) != NA_SFLOAT)
rblapack_si = na_change_type(rblapack_si, NA_SFLOAT);
si = NA_PTR_TYPE(rblapack_si, real*);
iloz = NUM2INT(rblapack_iloz);
nv = NUM2INT(rblapack_nv);
ldwv = nv;
ldv = 3;
wantz = (rblapack_wantz == Qtrue);
if (!NA_IsNArray(rblapack_sr))
rb_raise(rb_eArgError, "sr (6th argument) must be NArray");
if (NA_RANK(rblapack_sr) != 1)
rb_raise(rb_eArgError, "rank of sr (6th argument) must be %d", 1);
if (NA_SHAPE0(rblapack_sr) != nshfts)
rb_raise(rb_eRuntimeError, "shape 0 of sr must be the same as shape 0 of si");
if (NA_TYPE(rblapack_sr) != NA_SFLOAT)
rblapack_sr = na_change_type(rblapack_sr, NA_SFLOAT);
sr = NA_PTR_TYPE(rblapack_sr, real*);
ihiz = NUM2INT(rblapack_ihiz);
nh = NUM2INT(rblapack_nh);
ldu = 3*nshfts-3;
ktop = NUM2INT(rblapack_ktop);
ldwh = 3*nshfts-3;
if (!NA_IsNArray(rblapack_h))
rb_raise(rb_eArgError, "h (8th argument) must be NArray");
if (NA_RANK(rblapack_h) != 2)
rb_raise(rb_eArgError, "rank of h (8th argument) must be %d", 2);
ldh = NA_SHAPE0(rblapack_h);
n = NA_SHAPE1(rblapack_h);
if (NA_TYPE(rblapack_h) != NA_SFLOAT)
rblapack_h = na_change_type(rblapack_h, NA_SFLOAT);
h = NA_PTR_TYPE(rblapack_h, real*);
ldz = n;
if (!NA_IsNArray(rblapack_z))
rb_raise(rb_eArgError, "z (11th argument) must be NArray");
if (NA_RANK(rblapack_z) != 2)
rb_raise(rb_eArgError, "rank of z (11th argument) must be %d", 2);
if (NA_SHAPE0(rblapack_z) != (wantz ? ldz : 0))
rb_raise(rb_eRuntimeError, "shape 0 of z must be %d", wantz ? ldz : 0);
if (NA_SHAPE1(rblapack_z) != (wantz ? ihiz : 0))
rb_raise(rb_eRuntimeError, "shape 1 of z must be %d", wantz ? ihiz : 0);
if (NA_TYPE(rblapack_z) != NA_SFLOAT)
rblapack_z = na_change_type(rblapack_z, NA_SFLOAT);
z = NA_PTR_TYPE(rblapack_z, real*);
{
na_shape_t shape[1];
shape[0] = nshfts;
rblapack_sr_out__ = na_make_object(NA_SFLOAT, 1, shape, cNArray);
}
sr_out__ = NA_PTR_TYPE(rblapack_sr_out__, real*);
MEMCPY(sr_out__, sr, real, NA_TOTAL(rblapack_sr));
rblapack_sr = rblapack_sr_out__;
sr = sr_out__;
{
na_shape_t shape[1];
shape[0] = nshfts;
rblapack_si_out__ = na_make_object(NA_SFLOAT, 1, shape, cNArray);
}
si_out__ = NA_PTR_TYPE(rblapack_si_out__, real*);
MEMCPY(si_out__, si, real, NA_TOTAL(rblapack_si));
rblapack_si = rblapack_si_out__;
si = si_out__;
{
na_shape_t shape[2];
shape[0] = ldh;
shape[1] = n;
rblapack_h_out__ = na_make_object(NA_SFLOAT, 2, shape, cNArray);
}
h_out__ = NA_PTR_TYPE(rblapack_h_out__, real*);
MEMCPY(h_out__, h, real, NA_TOTAL(rblapack_h));
rblapack_h = rblapack_h_out__;
h = h_out__;
{
na_shape_t shape[2];
shape[0] = wantz ? ldz : 0;
shape[1] = wantz ? ihiz : 0;
rblapack_z_out__ = na_make_object(NA_SFLOAT, 2, shape, cNArray);
}
z_out__ = NA_PTR_TYPE(rblapack_z_out__, real*);
MEMCPY(z_out__, z, real, NA_TOTAL(rblapack_z));
rblapack_z = rblapack_z_out__;
z = z_out__;
v = ALLOC_N(real, (ldv)*(nshfts/2));
u = ALLOC_N(real, (ldu)*(3*nshfts-3));
wv = ALLOC_N(real, (ldwv)*(3*nshfts-3));
wh = ALLOC_N(real, (ldwh)*(MAX(1,nh)));
slaqr5_(&wantt, &wantz, &kacc22, &n, &ktop, &kbot, &nshfts, sr, si, h, &ldh, &iloz, &ihiz, z, &ldz, v, &ldv, u, &ldu, &nv, wv, &ldwv, &nh, wh, &ldwh);
free(v);
free(u);
free(wv);
free(wh);
return rb_ary_new3(4, rblapack_sr, rblapack_si, rblapack_h, rblapack_z);
}
void
init_lapack_slaqr5(VALUE mLapack, VALUE sH, VALUE sU, VALUE zero){
sHelp = sH;
sUsage = sU;
rblapack_ZERO = zero;
rb_define_module_function(mLapack, "slaqr5", rblapack_slaqr5, -1);
}
|