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
|
#include "rb_lapack.h"
extern VOID dlagtf_(integer* n, doublereal* a, doublereal* lambda, doublereal* b, doublereal* c, doublereal* tol, doublereal* d, integer* in, integer* info);
static VALUE
rblapack_dlagtf(int argc, VALUE *argv, VALUE self){
VALUE rblapack_a;
doublereal *a;
VALUE rblapack_lambda;
doublereal lambda;
VALUE rblapack_b;
doublereal *b;
VALUE rblapack_c;
doublereal *c;
VALUE rblapack_tol;
doublereal tol;
VALUE rblapack_d;
doublereal *d;
VALUE rblapack_in;
integer *in;
VALUE rblapack_info;
integer info;
VALUE rblapack_a_out__;
doublereal *a_out__;
VALUE rblapack_b_out__;
doublereal *b_out__;
VALUE rblapack_c_out__;
doublereal *c_out__;
integer n;
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 d, in, info, a, b, c = NumRu::Lapack.dlagtf( a, lambda, b, c, tol, [:usage => usage, :help => help])\n\n\nFORTRAN MANUAL\n SUBROUTINE DLAGTF( N, A, LAMBDA, B, C, TOL, D, IN, INFO )\n\n* Purpose\n* =======\n*\n* DLAGTF factorizes the matrix (T - lambda*I), where T is an n by n\n* tridiagonal matrix and lambda is a scalar, as\n*\n* T - lambda*I = PLU,\n*\n* where P is a permutation matrix, L is a unit lower tridiagonal matrix\n* with at most one non-zero sub-diagonal elements per column and U is\n* an upper triangular matrix with at most two non-zero super-diagonal\n* elements per column.\n*\n* The factorization is obtained by Gaussian elimination with partial\n* pivoting and implicit row scaling.\n*\n* The parameter LAMBDA is included in the routine so that DLAGTF may\n* be used, in conjunction with DLAGTS, to obtain eigenvectors of T by\n* inverse iteration.\n*\n\n* Arguments\n* =========\n*\n* N (input) INTEGER\n* The order of the matrix T.\n*\n* A (input/output) DOUBLE PRECISION array, dimension (N)\n* On entry, A must contain the diagonal elements of T.\n*\n* On exit, A is overwritten by the n diagonal elements of the\n* upper triangular matrix U of the factorization of T.\n*\n* LAMBDA (input) DOUBLE PRECISION\n* On entry, the scalar lambda.\n*\n* B (input/output) DOUBLE PRECISION array, dimension (N-1)\n* On entry, B must contain the (n-1) super-diagonal elements of\n* T.\n*\n* On exit, B is overwritten by the (n-1) super-diagonal\n* elements of the matrix U of the factorization of T.\n*\n* C (input/output) DOUBLE PRECISION array, dimension (N-1)\n* On entry, C must contain the (n-1) sub-diagonal elements of\n* T.\n*\n* On exit, C is overwritten by the (n-1) sub-diagonal elements\n* of the matrix L of the factorization of T.\n*\n* TOL (input) DOUBLE PRECISION\n* On entry, a relative tolerance used to indicate whether or\n* not the matrix (T - lambda*I) is nearly singular. TOL should\n* normally be chose as approximately the largest relative error\n* in the elements of T. For example, if the elements of T are\n* correct to about 4 significant figures, then TOL should be\n* set to about 5*10**(-4). If TOL is supplied as less than eps,\n* where eps is the relative machine precision, then the value\n* eps is used in place of TOL.\n*\n* D (output) DOUBLE PRECISION array, dimension (N-2)\n* On exit, D is overwritten by the (n-2) second super-diagonal\n* elements of the matrix U of the factorization of T.\n*\n* IN (output) INTEGER array, dimension (N)\n* On exit, IN contains details of the permutation matrix P. If\n* an interchange occurred at the kth step of the elimination,\n* then IN(k) = 1, otherwise IN(k) = 0. The element IN(n)\n* returns the smallest positive integer j such that\n*\n* abs( u(j,j) ).le. norm( (T - lambda*I)(j) )*TOL,\n*\n* where norm( A(j) ) denotes the sum of the absolute values of\n* the jth row of the matrix A. If no such j exists then IN(n)\n* is returned as zero. If IN(n) is returned as positive, then a\n* diagonal element of U is small, indicating that\n* (T - lambda*I) is singular or nearly singular,\n*\n* INFO (output) INTEGER\n* = 0 : successful exit\n* .lt. 0: if INFO = -k, the kth argument had an illegal value\n*\n\n* =====================================================================\n*\n\n");
return Qnil;
}
if (rb_hash_aref(rblapack_options, sUsage) == Qtrue) {
printf("%s\n", "USAGE:\n d, in, info, a, b, c = NumRu::Lapack.dlagtf( a, lambda, b, c, tol, [:usage => usage, :help => help])\n");
return Qnil;
}
} else
rblapack_options = Qnil;
if (argc != 5 && argc != 5)
rb_raise(rb_eArgError,"wrong number of arguments (%d for 5)", argc);
rblapack_a = argv[0];
rblapack_lambda = argv[1];
rblapack_b = argv[2];
rblapack_c = argv[3];
rblapack_tol = argv[4];
if (argc == 5) {
} else if (rblapack_options != Qnil) {
} else {
}
if (!NA_IsNArray(rblapack_a))
rb_raise(rb_eArgError, "a (1th argument) must be NArray");
if (NA_RANK(rblapack_a) != 1)
rb_raise(rb_eArgError, "rank of a (1th argument) must be %d", 1);
n = NA_SHAPE0(rblapack_a);
if (NA_TYPE(rblapack_a) != NA_DFLOAT)
rblapack_a = na_change_type(rblapack_a, NA_DFLOAT);
a = NA_PTR_TYPE(rblapack_a, doublereal*);
if (!NA_IsNArray(rblapack_b))
rb_raise(rb_eArgError, "b (3th argument) must be NArray");
if (NA_RANK(rblapack_b) != 1)
rb_raise(rb_eArgError, "rank of b (3th argument) must be %d", 1);
if (NA_SHAPE0(rblapack_b) != (n-1))
rb_raise(rb_eRuntimeError, "shape 0 of b must be %d", n-1);
if (NA_TYPE(rblapack_b) != NA_DFLOAT)
rblapack_b = na_change_type(rblapack_b, NA_DFLOAT);
b = NA_PTR_TYPE(rblapack_b, doublereal*);
tol = NUM2DBL(rblapack_tol);
lambda = NUM2DBL(rblapack_lambda);
if (!NA_IsNArray(rblapack_c))
rb_raise(rb_eArgError, "c (4th argument) must be NArray");
if (NA_RANK(rblapack_c) != 1)
rb_raise(rb_eArgError, "rank of c (4th argument) must be %d", 1);
if (NA_SHAPE0(rblapack_c) != (n-1))
rb_raise(rb_eRuntimeError, "shape 0 of c must be %d", n-1);
if (NA_TYPE(rblapack_c) != NA_DFLOAT)
rblapack_c = na_change_type(rblapack_c, NA_DFLOAT);
c = NA_PTR_TYPE(rblapack_c, doublereal*);
{
na_shape_t shape[1];
shape[0] = n-2;
rblapack_d = na_make_object(NA_DFLOAT, 1, shape, cNArray);
}
d = NA_PTR_TYPE(rblapack_d, doublereal*);
{
na_shape_t shape[1];
shape[0] = n;
rblapack_in = na_make_object(NA_LINT, 1, shape, cNArray);
}
in = NA_PTR_TYPE(rblapack_in, integer*);
{
na_shape_t shape[1];
shape[0] = n;
rblapack_a_out__ = na_make_object(NA_DFLOAT, 1, shape, cNArray);
}
a_out__ = NA_PTR_TYPE(rblapack_a_out__, doublereal*);
MEMCPY(a_out__, a, doublereal, NA_TOTAL(rblapack_a));
rblapack_a = rblapack_a_out__;
a = a_out__;
{
na_shape_t shape[1];
shape[0] = n-1;
rblapack_b_out__ = na_make_object(NA_DFLOAT, 1, shape, cNArray);
}
b_out__ = NA_PTR_TYPE(rblapack_b_out__, doublereal*);
MEMCPY(b_out__, b, doublereal, NA_TOTAL(rblapack_b));
rblapack_b = rblapack_b_out__;
b = b_out__;
{
na_shape_t shape[1];
shape[0] = n-1;
rblapack_c_out__ = na_make_object(NA_DFLOAT, 1, shape, cNArray);
}
c_out__ = NA_PTR_TYPE(rblapack_c_out__, doublereal*);
MEMCPY(c_out__, c, doublereal, NA_TOTAL(rblapack_c));
rblapack_c = rblapack_c_out__;
c = c_out__;
dlagtf_(&n, a, &lambda, b, c, &tol, d, in, &info);
rblapack_info = INT2NUM(info);
return rb_ary_new3(6, rblapack_d, rblapack_in, rblapack_info, rblapack_a, rblapack_b, rblapack_c);
}
void
init_lapack_dlagtf(VALUE mLapack, VALUE sH, VALUE sU, VALUE zero){
sHelp = sH;
sUsage = sU;
rblapack_ZERO = zero;
rb_define_module_function(mLapack, "dlagtf", rblapack_dlagtf, -1);
}
|