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
|
#include "rb_lapack.h"
extern VOID dgghrd_(char* compq, char* compz, integer* n, integer* ilo, integer* ihi, doublereal* a, integer* lda, doublereal* b, integer* ldb, doublereal* q, integer* ldq, doublereal* z, integer* ldz, integer* info);
static VALUE
rblapack_dgghrd(int argc, VALUE *argv, VALUE self){
VALUE rblapack_compq;
char compq;
VALUE rblapack_compz;
char compz;
VALUE rblapack_ilo;
integer ilo;
VALUE rblapack_ihi;
integer ihi;
VALUE rblapack_a;
doublereal *a;
VALUE rblapack_b;
doublereal *b;
VALUE rblapack_q;
doublereal *q;
VALUE rblapack_z;
doublereal *z;
VALUE rblapack_info;
integer info;
VALUE rblapack_a_out__;
doublereal *a_out__;
VALUE rblapack_b_out__;
doublereal *b_out__;
VALUE rblapack_q_out__;
doublereal *q_out__;
VALUE rblapack_z_out__;
doublereal *z_out__;
integer lda;
integer n;
integer ldb;
integer ldq;
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 info, a, b, q, z = NumRu::Lapack.dgghrd( compq, compz, ilo, ihi, a, b, q, z, [:usage => usage, :help => help])\n\n\nFORTRAN MANUAL\n SUBROUTINE DGGHRD( COMPQ, COMPZ, N, ILO, IHI, A, LDA, B, LDB, Q, LDQ, Z, LDZ, INFO )\n\n* Purpose\n* =======\n*\n* DGGHRD reduces a pair of real matrices (A,B) to generalized upper\n* Hessenberg form using orthogonal transformations, where A is a\n* general matrix and B is upper triangular. The form of the\n* generalized eigenvalue problem is\n* A*x = lambda*B*x,\n* and B is typically made upper triangular by computing its QR\n* factorization and moving the orthogonal matrix Q to the left side\n* of the equation.\n*\n* This subroutine simultaneously reduces A to a Hessenberg matrix H:\n* Q**T*A*Z = H\n* and transforms B to another upper triangular matrix T:\n* Q**T*B*Z = T\n* in order to reduce the problem to its standard form\n* H*y = lambda*T*y\n* where y = Z**T*x.\n*\n* The orthogonal matrices Q and Z are determined as products of Givens\n* rotations. They may either be formed explicitly, or they may be\n* postmultiplied into input matrices Q1 and Z1, so that\n*\n* Q1 * A * Z1**T = (Q1*Q) * H * (Z1*Z)**T\n*\n* Q1 * B * Z1**T = (Q1*Q) * T * (Z1*Z)**T\n*\n* If Q1 is the orthogonal matrix from the QR factorization of B in the\n* original equation A*x = lambda*B*x, then DGGHRD reduces the original\n* problem to generalized Hessenberg form.\n*\n\n* Arguments\n* =========\n*\n* COMPQ (input) CHARACTER*1\n* = 'N': do not compute Q;\n* = 'I': Q is initialized to the unit matrix, and the\n* orthogonal matrix Q is returned;\n* = 'V': Q must contain an orthogonal matrix Q1 on entry,\n* and the product Q1*Q is returned.\n*\n* COMPZ (input) CHARACTER*1\n* = 'N': do not compute Z;\n* = 'I': Z is initialized to the unit matrix, and the\n* orthogonal matrix Z is returned;\n* = 'V': Z must contain an orthogonal matrix Z1 on entry,\n* and the product Z1*Z is returned.\n*\n* N (input) INTEGER\n* The order of the matrices A and B. N >= 0.\n*\n* ILO (input) INTEGER\n* IHI (input) INTEGER\n* ILO and IHI mark the rows and columns of A which are to be\n* reduced. It is assumed that A is already upper triangular\n* in rows and columns 1:ILO-1 and IHI+1:N. ILO and IHI are\n* normally set by a previous call to SGGBAL; otherwise they\n* should be set to 1 and N respectively.\n* 1 <= ILO <= IHI <= N, if N > 0; ILO=1 and IHI=0, if N=0.\n*\n* A (input/output) DOUBLE PRECISION array, dimension (LDA, N)\n* On entry, the N-by-N general matrix to be reduced.\n* On exit, the upper triangle and the first subdiagonal of A\n* are overwritten with the upper Hessenberg matrix H, and the\n* rest is set to zero.\n*\n* LDA (input) INTEGER\n* The leading dimension of the array A. LDA >= max(1,N).\n*\n* B (input/output) DOUBLE PRECISION array, dimension (LDB, N)\n* On entry, the N-by-N upper triangular matrix B.\n* On exit, the upper triangular matrix T = Q**T B Z. The\n* elements below the diagonal are set to zero.\n*\n* LDB (input) INTEGER\n* The leading dimension of the array B. LDB >= max(1,N).\n*\n* Q (input/output) DOUBLE PRECISION array, dimension (LDQ, N)\n* On entry, if COMPQ = 'V', the orthogonal matrix Q1,\n* typically from the QR factorization of B.\n* On exit, if COMPQ='I', the orthogonal matrix Q, and if\n* COMPQ = 'V', the product Q1*Q.\n* Not referenced if COMPQ='N'.\n*\n* LDQ (input) INTEGER\n* The leading dimension of the array Q.\n* LDQ >= N if COMPQ='V' or 'I'; LDQ >= 1 otherwise.\n*\n* Z (input/output) DOUBLE PRECISION array, dimension (LDZ, N)\n* On entry, if COMPZ = 'V', the orthogonal matrix Z1.\n* On exit, if COMPZ='I', the orthogonal matrix Z, and if\n* COMPZ = 'V', the product Z1*Z.\n* Not referenced if COMPZ='N'.\n*\n* LDZ (input) INTEGER\n* The leading dimension of the array Z.\n* LDZ >= N if COMPZ='V' or 'I'; LDZ >= 1 otherwise.\n*\n* INFO (output) INTEGER\n* = 0: successful exit.\n* < 0: if INFO = -i, the i-th argument had an illegal value.\n*\n\n* Further Details\n* ===============\n*\n* This routine reduces A to Hessenberg and B to triangular form by\n* an unblocked reduction, as described in _Matrix_Computations_,\n* by Golub and Van Loan (Johns Hopkins Press.)\n*\n* =====================================================================\n*\n\n");
return Qnil;
}
if (rb_hash_aref(rblapack_options, sUsage) == Qtrue) {
printf("%s\n", "USAGE:\n info, a, b, q, z = NumRu::Lapack.dgghrd( compq, compz, ilo, ihi, a, b, q, z, [:usage => usage, :help => help])\n");
return Qnil;
}
} else
rblapack_options = Qnil;
if (argc != 8 && argc != 8)
rb_raise(rb_eArgError,"wrong number of arguments (%d for 8)", argc);
rblapack_compq = argv[0];
rblapack_compz = argv[1];
rblapack_ilo = argv[2];
rblapack_ihi = argv[3];
rblapack_a = argv[4];
rblapack_b = argv[5];
rblapack_q = argv[6];
rblapack_z = argv[7];
if (argc == 8) {
} else if (rblapack_options != Qnil) {
} else {
}
compq = StringValueCStr(rblapack_compq)[0];
ilo = NUM2INT(rblapack_ilo);
if (!NA_IsNArray(rblapack_a))
rb_raise(rb_eArgError, "a (5th argument) must be NArray");
if (NA_RANK(rblapack_a) != 2)
rb_raise(rb_eArgError, "rank of a (5th argument) must be %d", 2);
lda = NA_SHAPE0(rblapack_a);
n = NA_SHAPE1(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_q))
rb_raise(rb_eArgError, "q (7th argument) must be NArray");
if (NA_RANK(rblapack_q) != 2)
rb_raise(rb_eArgError, "rank of q (7th argument) must be %d", 2);
ldq = NA_SHAPE0(rblapack_q);
if (NA_SHAPE1(rblapack_q) != n)
rb_raise(rb_eRuntimeError, "shape 1 of q must be the same as shape 1 of a");
if (NA_TYPE(rblapack_q) != NA_DFLOAT)
rblapack_q = na_change_type(rblapack_q, NA_DFLOAT);
q = NA_PTR_TYPE(rblapack_q, doublereal*);
compz = StringValueCStr(rblapack_compz)[0];
if (!NA_IsNArray(rblapack_b))
rb_raise(rb_eArgError, "b (6th argument) must be NArray");
if (NA_RANK(rblapack_b) != 2)
rb_raise(rb_eArgError, "rank of b (6th argument) must be %d", 2);
ldb = NA_SHAPE0(rblapack_b);
if (NA_SHAPE1(rblapack_b) != n)
rb_raise(rb_eRuntimeError, "shape 1 of b must be the same as shape 1 of a");
if (NA_TYPE(rblapack_b) != NA_DFLOAT)
rblapack_b = na_change_type(rblapack_b, NA_DFLOAT);
b = NA_PTR_TYPE(rblapack_b, doublereal*);
ihi = NUM2INT(rblapack_ihi);
if (!NA_IsNArray(rblapack_z))
rb_raise(rb_eArgError, "z (8th argument) must be NArray");
if (NA_RANK(rblapack_z) != 2)
rb_raise(rb_eArgError, "rank of z (8th argument) must be %d", 2);
ldz = NA_SHAPE0(rblapack_z);
if (NA_SHAPE1(rblapack_z) != n)
rb_raise(rb_eRuntimeError, "shape 1 of z must be the same as shape 1 of a");
if (NA_TYPE(rblapack_z) != NA_DFLOAT)
rblapack_z = na_change_type(rblapack_z, NA_DFLOAT);
z = NA_PTR_TYPE(rblapack_z, doublereal*);
{
na_shape_t shape[2];
shape[0] = lda;
shape[1] = n;
rblapack_a_out__ = na_make_object(NA_DFLOAT, 2, 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[2];
shape[0] = ldb;
shape[1] = n;
rblapack_b_out__ = na_make_object(NA_DFLOAT, 2, 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[2];
shape[0] = ldq;
shape[1] = n;
rblapack_q_out__ = na_make_object(NA_DFLOAT, 2, shape, cNArray);
}
q_out__ = NA_PTR_TYPE(rblapack_q_out__, doublereal*);
MEMCPY(q_out__, q, doublereal, NA_TOTAL(rblapack_q));
rblapack_q = rblapack_q_out__;
q = q_out__;
{
na_shape_t shape[2];
shape[0] = ldz;
shape[1] = n;
rblapack_z_out__ = na_make_object(NA_DFLOAT, 2, shape, cNArray);
}
z_out__ = NA_PTR_TYPE(rblapack_z_out__, doublereal*);
MEMCPY(z_out__, z, doublereal, NA_TOTAL(rblapack_z));
rblapack_z = rblapack_z_out__;
z = z_out__;
dgghrd_(&compq, &compz, &n, &ilo, &ihi, a, &lda, b, &ldb, q, &ldq, z, &ldz, &info);
rblapack_info = INT2NUM(info);
return rb_ary_new3(5, rblapack_info, rblapack_a, rblapack_b, rblapack_q, rblapack_z);
}
void
init_lapack_dgghrd(VALUE mLapack, VALUE sH, VALUE sU, VALUE zero){
sHelp = sH;
sUsage = sU;
rblapack_ZERO = zero;
rb_define_module_function(mLapack, "dgghrd", rblapack_dgghrd, -1);
}
|