00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #include "f2c.h"
00014 #include "blaswrap.h"
00015
00016
00017
00018 static integer c__1 = 1;
00019 static integer c__0 = 0;
00020 static integer c_n1 = -1;
00021 static real c_b36 = 0.f;
00022 static real c_b37 = 1.f;
00023
00024 int sggev_(char *jobvl, char *jobvr, integer *n, real *a,
00025 integer *lda, real *b, integer *ldb, real *alphar, real *alphai, real
00026 *beta, real *vl, integer *ldvl, real *vr, integer *ldvr, real *work,
00027 integer *lwork, integer *info)
00028 {
00029
00030 integer a_dim1, a_offset, b_dim1, b_offset, vl_dim1, vl_offset, vr_dim1,
00031 vr_offset, i__1, i__2;
00032 real r__1, r__2, r__3, r__4;
00033
00034
00035 double sqrt(doublereal);
00036
00037
00038 integer jc, in, jr, ihi, ilo;
00039 real eps;
00040 logical ilv;
00041 real anrm, bnrm;
00042 integer ierr, itau;
00043 real temp;
00044 logical ilvl, ilvr;
00045 integer iwrk;
00046 extern logical lsame_(char *, char *);
00047 integer ileft, icols, irows;
00048 extern int slabad_(real *, real *), sggbak_(char *, char
00049 *, integer *, integer *, integer *, real *, real *, integer *,
00050 real *, integer *, integer *), sggbal_(char *,
00051 integer *, real *, integer *, real *, integer *, integer *,
00052 integer *, real *, real *, real *, integer *);
00053 logical ilascl, ilbscl;
00054 extern doublereal slamch_(char *), slange_(char *, integer *,
00055 integer *, real *, integer *, real *);
00056 extern int xerbla_(char *, integer *), sgghrd_(
00057 char *, char *, integer *, integer *, integer *, real *, integer *
00058 , real *, integer *, real *, integer *, real *, integer *,
00059 integer *);
00060 logical ldumma[1];
00061 char chtemp[1];
00062 real bignum;
00063 extern int slascl_(char *, integer *, integer *, real *,
00064 real *, integer *, integer *, real *, integer *, integer *);
00065 extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
00066 integer *, integer *);
00067 integer ijobvl, iright;
00068 extern int sgeqrf_(integer *, integer *, real *, integer
00069 *, real *, real *, integer *, integer *);
00070 integer ijobvr;
00071 extern int slacpy_(char *, integer *, integer *, real *,
00072 integer *, real *, integer *), slaset_(char *, integer *,
00073 integer *, real *, real *, real *, integer *), stgevc_(
00074 char *, char *, logical *, integer *, real *, integer *, real *,
00075 integer *, real *, integer *, real *, integer *, integer *,
00076 integer *, real *, integer *);
00077 real anrmto, bnrmto;
00078 extern int shgeqz_(char *, char *, char *, integer *,
00079 integer *, integer *, real *, integer *, real *, integer *, real *
00080 , real *, real *, real *, integer *, real *, integer *, real *,
00081 integer *, integer *);
00082 integer minwrk, maxwrk;
00083 real smlnum;
00084 extern int sorgqr_(integer *, integer *, integer *, real
00085 *, integer *, real *, real *, integer *, integer *);
00086 logical lquery;
00087 extern int sormqr_(char *, char *, integer *, integer *,
00088 integer *, real *, integer *, real *, real *, integer *, real *,
00089 integer *, integer *);
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242 a_dim1 = *lda;
00243 a_offset = 1 + a_dim1;
00244 a -= a_offset;
00245 b_dim1 = *ldb;
00246 b_offset = 1 + b_dim1;
00247 b -= b_offset;
00248 --alphar;
00249 --alphai;
00250 --beta;
00251 vl_dim1 = *ldvl;
00252 vl_offset = 1 + vl_dim1;
00253 vl -= vl_offset;
00254 vr_dim1 = *ldvr;
00255 vr_offset = 1 + vr_dim1;
00256 vr -= vr_offset;
00257 --work;
00258
00259
00260 if (lsame_(jobvl, "N")) {
00261 ijobvl = 1;
00262 ilvl = FALSE_;
00263 } else if (lsame_(jobvl, "V")) {
00264 ijobvl = 2;
00265 ilvl = TRUE_;
00266 } else {
00267 ijobvl = -1;
00268 ilvl = FALSE_;
00269 }
00270
00271 if (lsame_(jobvr, "N")) {
00272 ijobvr = 1;
00273 ilvr = FALSE_;
00274 } else if (lsame_(jobvr, "V")) {
00275 ijobvr = 2;
00276 ilvr = TRUE_;
00277 } else {
00278 ijobvr = -1;
00279 ilvr = FALSE_;
00280 }
00281 ilv = ilvl || ilvr;
00282
00283
00284
00285 *info = 0;
00286 lquery = *lwork == -1;
00287 if (ijobvl <= 0) {
00288 *info = -1;
00289 } else if (ijobvr <= 0) {
00290 *info = -2;
00291 } else if (*n < 0) {
00292 *info = -3;
00293 } else if (*lda < max(1,*n)) {
00294 *info = -5;
00295 } else if (*ldb < max(1,*n)) {
00296 *info = -7;
00297 } else if (*ldvl < 1 || ilvl && *ldvl < *n) {
00298 *info = -12;
00299 } else if (*ldvr < 1 || ilvr && *ldvr < *n) {
00300 *info = -14;
00301 }
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311 if (*info == 0) {
00312
00313 i__1 = 1, i__2 = *n << 3;
00314 minwrk = max(i__1,i__2);
00315
00316 i__1 = 1, i__2 = *n * (ilaenv_(&c__1, "SGEQRF", " ", n, &c__1, n, &
00317 c__0) + 7);
00318 maxwrk = max(i__1,i__2);
00319
00320 i__1 = maxwrk, i__2 = *n * (ilaenv_(&c__1, "SORMQR", " ", n, &c__1, n,
00321 &c__0) + 7);
00322 maxwrk = max(i__1,i__2);
00323 if (ilvl) {
00324
00325 i__1 = maxwrk, i__2 = *n * (ilaenv_(&c__1, "SORGQR", " ", n, &
00326 c__1, n, &c_n1) + 7);
00327 maxwrk = max(i__1,i__2);
00328 }
00329 work[1] = (real) maxwrk;
00330
00331 if (*lwork < minwrk && ! lquery) {
00332 *info = -16;
00333 }
00334 }
00335
00336 if (*info != 0) {
00337 i__1 = -(*info);
00338 xerbla_("SGGEV ", &i__1);
00339 return 0;
00340 } else if (lquery) {
00341 return 0;
00342 }
00343
00344
00345
00346 if (*n == 0) {
00347 return 0;
00348 }
00349
00350
00351
00352 eps = slamch_("P");
00353 smlnum = slamch_("S");
00354 bignum = 1.f / smlnum;
00355 slabad_(&smlnum, &bignum);
00356 smlnum = sqrt(smlnum) / eps;
00357 bignum = 1.f / smlnum;
00358
00359
00360
00361 anrm = slange_("M", n, n, &a[a_offset], lda, &work[1]);
00362 ilascl = FALSE_;
00363 if (anrm > 0.f && anrm < smlnum) {
00364 anrmto = smlnum;
00365 ilascl = TRUE_;
00366 } else if (anrm > bignum) {
00367 anrmto = bignum;
00368 ilascl = TRUE_;
00369 }
00370 if (ilascl) {
00371 slascl_("G", &c__0, &c__0, &anrm, &anrmto, n, n, &a[a_offset], lda, &
00372 ierr);
00373 }
00374
00375
00376
00377 bnrm = slange_("M", n, n, &b[b_offset], ldb, &work[1]);
00378 ilbscl = FALSE_;
00379 if (bnrm > 0.f && bnrm < smlnum) {
00380 bnrmto = smlnum;
00381 ilbscl = TRUE_;
00382 } else if (bnrm > bignum) {
00383 bnrmto = bignum;
00384 ilbscl = TRUE_;
00385 }
00386 if (ilbscl) {
00387 slascl_("G", &c__0, &c__0, &bnrm, &bnrmto, n, n, &b[b_offset], ldb, &
00388 ierr);
00389 }
00390
00391
00392
00393
00394 ileft = 1;
00395 iright = *n + 1;
00396 iwrk = iright + *n;
00397 sggbal_("P", n, &a[a_offset], lda, &b[b_offset], ldb, &ilo, &ihi, &work[
00398 ileft], &work[iright], &work[iwrk], &ierr);
00399
00400
00401
00402
00403 irows = ihi + 1 - ilo;
00404 if (ilv) {
00405 icols = *n + 1 - ilo;
00406 } else {
00407 icols = irows;
00408 }
00409 itau = iwrk;
00410 iwrk = itau + irows;
00411 i__1 = *lwork + 1 - iwrk;
00412 sgeqrf_(&irows, &icols, &b[ilo + ilo * b_dim1], ldb, &work[itau], &work[
00413 iwrk], &i__1, &ierr);
00414
00415
00416
00417
00418 i__1 = *lwork + 1 - iwrk;
00419 sormqr_("L", "T", &irows, &icols, &irows, &b[ilo + ilo * b_dim1], ldb, &
00420 work[itau], &a[ilo + ilo * a_dim1], lda, &work[iwrk], &i__1, &
00421 ierr);
00422
00423
00424
00425
00426 if (ilvl) {
00427 slaset_("Full", n, n, &c_b36, &c_b37, &vl[vl_offset], ldvl)
00428 ;
00429 if (irows > 1) {
00430 i__1 = irows - 1;
00431 i__2 = irows - 1;
00432 slacpy_("L", &i__1, &i__2, &b[ilo + 1 + ilo * b_dim1], ldb, &vl[
00433 ilo + 1 + ilo * vl_dim1], ldvl);
00434 }
00435 i__1 = *lwork + 1 - iwrk;
00436 sorgqr_(&irows, &irows, &irows, &vl[ilo + ilo * vl_dim1], ldvl, &work[
00437 itau], &work[iwrk], &i__1, &ierr);
00438 }
00439
00440
00441
00442 if (ilvr) {
00443 slaset_("Full", n, n, &c_b36, &c_b37, &vr[vr_offset], ldvr)
00444 ;
00445 }
00446
00447
00448
00449
00450 if (ilv) {
00451
00452
00453
00454 sgghrd_(jobvl, jobvr, n, &ilo, &ihi, &a[a_offset], lda, &b[b_offset],
00455 ldb, &vl[vl_offset], ldvl, &vr[vr_offset], ldvr, &ierr);
00456 } else {
00457 sgghrd_("N", "N", &irows, &c__1, &irows, &a[ilo + ilo * a_dim1], lda,
00458 &b[ilo + ilo * b_dim1], ldb, &vl[vl_offset], ldvl, &vr[
00459 vr_offset], ldvr, &ierr);
00460 }
00461
00462
00463
00464
00465
00466 iwrk = itau;
00467 if (ilv) {
00468 *(unsigned char *)chtemp = 'S';
00469 } else {
00470 *(unsigned char *)chtemp = 'E';
00471 }
00472 i__1 = *lwork + 1 - iwrk;
00473 shgeqz_(chtemp, jobvl, jobvr, n, &ilo, &ihi, &a[a_offset], lda, &b[
00474 b_offset], ldb, &alphar[1], &alphai[1], &beta[1], &vl[vl_offset],
00475 ldvl, &vr[vr_offset], ldvr, &work[iwrk], &i__1, &ierr);
00476 if (ierr != 0) {
00477 if (ierr > 0 && ierr <= *n) {
00478 *info = ierr;
00479 } else if (ierr > *n && ierr <= *n << 1) {
00480 *info = ierr - *n;
00481 } else {
00482 *info = *n + 1;
00483 }
00484 goto L110;
00485 }
00486
00487
00488
00489
00490 if (ilv) {
00491 if (ilvl) {
00492 if (ilvr) {
00493 *(unsigned char *)chtemp = 'B';
00494 } else {
00495 *(unsigned char *)chtemp = 'L';
00496 }
00497 } else {
00498 *(unsigned char *)chtemp = 'R';
00499 }
00500 stgevc_(chtemp, "B", ldumma, n, &a[a_offset], lda, &b[b_offset], ldb,
00501 &vl[vl_offset], ldvl, &vr[vr_offset], ldvr, n, &in, &work[
00502 iwrk], &ierr);
00503 if (ierr != 0) {
00504 *info = *n + 2;
00505 goto L110;
00506 }
00507
00508
00509
00510
00511 if (ilvl) {
00512 sggbak_("P", "L", n, &ilo, &ihi, &work[ileft], &work[iright], n, &
00513 vl[vl_offset], ldvl, &ierr);
00514 i__1 = *n;
00515 for (jc = 1; jc <= i__1; ++jc) {
00516 if (alphai[jc] < 0.f) {
00517 goto L50;
00518 }
00519 temp = 0.f;
00520 if (alphai[jc] == 0.f) {
00521 i__2 = *n;
00522 for (jr = 1; jr <= i__2; ++jr) {
00523
00524 r__2 = temp, r__3 = (r__1 = vl[jr + jc * vl_dim1],
00525 dabs(r__1));
00526 temp = dmax(r__2,r__3);
00527
00528 }
00529 } else {
00530 i__2 = *n;
00531 for (jr = 1; jr <= i__2; ++jr) {
00532
00533 r__3 = temp, r__4 = (r__1 = vl[jr + jc * vl_dim1],
00534 dabs(r__1)) + (r__2 = vl[jr + (jc + 1) *
00535 vl_dim1], dabs(r__2));
00536 temp = dmax(r__3,r__4);
00537
00538 }
00539 }
00540 if (temp < smlnum) {
00541 goto L50;
00542 }
00543 temp = 1.f / temp;
00544 if (alphai[jc] == 0.f) {
00545 i__2 = *n;
00546 for (jr = 1; jr <= i__2; ++jr) {
00547 vl[jr + jc * vl_dim1] *= temp;
00548
00549 }
00550 } else {
00551 i__2 = *n;
00552 for (jr = 1; jr <= i__2; ++jr) {
00553 vl[jr + jc * vl_dim1] *= temp;
00554 vl[jr + (jc + 1) * vl_dim1] *= temp;
00555
00556 }
00557 }
00558 L50:
00559 ;
00560 }
00561 }
00562 if (ilvr) {
00563 sggbak_("P", "R", n, &ilo, &ihi, &work[ileft], &work[iright], n, &
00564 vr[vr_offset], ldvr, &ierr);
00565 i__1 = *n;
00566 for (jc = 1; jc <= i__1; ++jc) {
00567 if (alphai[jc] < 0.f) {
00568 goto L100;
00569 }
00570 temp = 0.f;
00571 if (alphai[jc] == 0.f) {
00572 i__2 = *n;
00573 for (jr = 1; jr <= i__2; ++jr) {
00574
00575 r__2 = temp, r__3 = (r__1 = vr[jr + jc * vr_dim1],
00576 dabs(r__1));
00577 temp = dmax(r__2,r__3);
00578
00579 }
00580 } else {
00581 i__2 = *n;
00582 for (jr = 1; jr <= i__2; ++jr) {
00583
00584 r__3 = temp, r__4 = (r__1 = vr[jr + jc * vr_dim1],
00585 dabs(r__1)) + (r__2 = vr[jr + (jc + 1) *
00586 vr_dim1], dabs(r__2));
00587 temp = dmax(r__3,r__4);
00588
00589 }
00590 }
00591 if (temp < smlnum) {
00592 goto L100;
00593 }
00594 temp = 1.f / temp;
00595 if (alphai[jc] == 0.f) {
00596 i__2 = *n;
00597 for (jr = 1; jr <= i__2; ++jr) {
00598 vr[jr + jc * vr_dim1] *= temp;
00599
00600 }
00601 } else {
00602 i__2 = *n;
00603 for (jr = 1; jr <= i__2; ++jr) {
00604 vr[jr + jc * vr_dim1] *= temp;
00605 vr[jr + (jc + 1) * vr_dim1] *= temp;
00606
00607 }
00608 }
00609 L100:
00610 ;
00611 }
00612 }
00613
00614
00615
00616 }
00617
00618
00619
00620 if (ilascl) {
00621 slascl_("G", &c__0, &c__0, &anrmto, &anrm, n, &c__1, &alphar[1], n, &
00622 ierr);
00623 slascl_("G", &c__0, &c__0, &anrmto, &anrm, n, &c__1, &alphai[1], n, &
00624 ierr);
00625 }
00626
00627 if (ilbscl) {
00628 slascl_("G", &c__0, &c__0, &bnrmto, &bnrm, n, &c__1, &beta[1], n, &
00629 ierr);
00630 }
00631
00632 L110:
00633
00634 work[1] = (real) maxwrk;
00635
00636 return 0;
00637
00638
00639
00640 }