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
|
#include "rb_lapack.h"
extern VOID zlarfgp_(integer* n, doublecomplex* alpha, doublecomplex* x, integer* incx, doublecomplex* tau);
static VALUE
rblapack_zlarfgp(int argc, VALUE *argv, VALUE self){
VALUE rblapack_n;
integer n;
VALUE rblapack_alpha;
doublecomplex alpha;
VALUE rblapack_x;
doublecomplex *x;
VALUE rblapack_incx;
integer incx;
VALUE rblapack_tau;
doublecomplex tau;
VALUE rblapack_x_out__;
doublecomplex *x_out__;
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 tau, alpha, x = NumRu::Lapack.zlarfgp( n, alpha, x, incx, [:usage => usage, :help => help])\n\n\nFORTRAN MANUAL\n SUBROUTINE ZLARFGP( N, ALPHA, X, INCX, TAU )\n\n* Purpose\n* =======\n*\n* ZLARFGP generates a complex elementary reflector H of order n, such\n* that\n*\n* H' * ( alpha ) = ( beta ), H' * H = I.\n* ( x ) ( 0 )\n*\n* where alpha and beta are scalars, beta is real and non-negative, and\n* x is an (n-1)-element complex vector. H is represented in the form\n*\n* H = I - tau * ( 1 ) * ( 1 v' ) ,\n* ( v )\n*\n* where tau is a complex scalar and v is a complex (n-1)-element\n* vector. Note that H is not hermitian.\n*\n* If the elements of x are all zero and alpha is real, then tau = 0\n* and H is taken to be the unit matrix.\n*\n\n* Arguments\n* =========\n*\n* N (input) INTEGER\n* The order of the elementary reflector.\n*\n* ALPHA (input/output) COMPLEX*16\n* On entry, the value alpha.\n* On exit, it is overwritten with the value beta.\n*\n* X (input/output) COMPLEX*16 array, dimension\n* (1+(N-2)*abs(INCX))\n* On entry, the vector x.\n* On exit, it is overwritten with the vector v.\n*\n* INCX (input) INTEGER\n* The increment between elements of X. INCX > 0.\n*\n* TAU (output) COMPLEX*16\n* The value tau.\n*\n\n* =====================================================================\n*\n\n");
return Qnil;
}
if (rb_hash_aref(rblapack_options, sUsage) == Qtrue) {
printf("%s\n", "USAGE:\n tau, alpha, x = NumRu::Lapack.zlarfgp( n, alpha, x, incx, [:usage => usage, :help => help])\n");
return Qnil;
}
} else
rblapack_options = Qnil;
if (argc != 4 && argc != 4)
rb_raise(rb_eArgError,"wrong number of arguments (%d for 4)", argc);
rblapack_n = argv[0];
rblapack_alpha = argv[1];
rblapack_x = argv[2];
rblapack_incx = argv[3];
if (argc == 4) {
} else if (rblapack_options != Qnil) {
} else {
}
n = NUM2INT(rblapack_n);
incx = NUM2INT(rblapack_incx);
alpha.r = NUM2DBL(rb_funcall(rblapack_alpha, rb_intern("real"), 0));
alpha.i = NUM2DBL(rb_funcall(rblapack_alpha, rb_intern("imag"), 0));
if (!NA_IsNArray(rblapack_x))
rb_raise(rb_eArgError, "x (3th argument) must be NArray");
if (NA_RANK(rblapack_x) != 1)
rb_raise(rb_eArgError, "rank of x (3th argument) must be %d", 1);
if (NA_SHAPE0(rblapack_x) != (1+(n-2)*abs(incx)))
rb_raise(rb_eRuntimeError, "shape 0 of x must be %d", 1+(n-2)*abs(incx));
if (NA_TYPE(rblapack_x) != NA_DCOMPLEX)
rblapack_x = na_change_type(rblapack_x, NA_DCOMPLEX);
x = NA_PTR_TYPE(rblapack_x, doublecomplex*);
{
na_shape_t shape[1];
shape[0] = 1+(n-2)*abs(incx);
rblapack_x_out__ = na_make_object(NA_DCOMPLEX, 1, shape, cNArray);
}
x_out__ = NA_PTR_TYPE(rblapack_x_out__, doublecomplex*);
MEMCPY(x_out__, x, doublecomplex, NA_TOTAL(rblapack_x));
rblapack_x = rblapack_x_out__;
x = x_out__;
zlarfgp_(&n, &alpha, x, &incx, &tau);
rblapack_tau = rb_funcall(rb_gv_get("Complex"), rb_intern("new"), 2, rb_float_new((double)(tau.r)), rb_float_new((double)(tau.i)));
rblapack_alpha = rb_funcall(rb_gv_get("Complex"), rb_intern("new"), 2, rb_float_new((double)(alpha.r)), rb_float_new((double)(alpha.i)));
return rb_ary_new3(3, rblapack_tau, rblapack_alpha, rblapack_x);
}
void
init_lapack_zlarfgp(VALUE mLapack, VALUE sH, VALUE sU, VALUE zero){
sHelp = sH;
sUsage = sU;
rblapack_ZERO = zero;
rb_define_module_function(mLapack, "zlarfgp", rblapack_zlarfgp, -1);
}
|