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
00022 int sgeev_(char *jobvl, char *jobvr, integer *n, real *a,
00023 integer *lda, real *wr, real *wi, real *vl, integer *ldvl, real *vr,
00024 integer *ldvr, real *work, integer *lwork, integer *info)
00025 {
00026
00027 integer a_dim1, a_offset, vl_dim1, vl_offset, vr_dim1, vr_offset, i__1,
00028 i__2, i__3;
00029 real r__1, r__2;
00030
00031
00032 double sqrt(doublereal);
00033
00034
00035 integer i__, k;
00036 real r__, cs, sn;
00037 integer ihi;
00038 real scl;
00039 integer ilo;
00040 real dum[1], eps;
00041 integer ibal;
00042 char side[1];
00043 real anrm;
00044 integer ierr, itau, iwrk, nout;
00045 extern int srot_(integer *, real *, integer *, real *,
00046 integer *, real *, real *);
00047 extern doublereal snrm2_(integer *, real *, integer *);
00048 extern logical lsame_(char *, char *);
00049 extern int sscal_(integer *, real *, real *, integer *);
00050 extern doublereal slapy2_(real *, real *);
00051 extern int slabad_(real *, real *);
00052 logical scalea;
00053 real cscale;
00054 extern int sgebak_(char *, char *, integer *, integer *,
00055 integer *, real *, integer *, real *, integer *, integer *), sgebal_(char *, integer *, real *, integer *,
00056 integer *, integer *, real *, integer *);
00057 extern doublereal slamch_(char *), slange_(char *, integer *,
00058 integer *, real *, integer *, real *);
00059 extern int sgehrd_(integer *, integer *, integer *, real
00060 *, integer *, real *, real *, integer *, integer *), xerbla_(char
00061 *, integer *);
00062 extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
00063 integer *, integer *);
00064 logical select[1];
00065 real bignum;
00066 extern int slascl_(char *, integer *, integer *, real *,
00067 real *, integer *, integer *, real *, integer *, integer *);
00068 extern integer isamax_(integer *, real *, integer *);
00069 extern int slacpy_(char *, integer *, integer *, real *,
00070 integer *, real *, integer *), slartg_(real *, real *,
00071 real *, real *, real *), sorghr_(integer *, integer *, integer *,
00072 real *, integer *, real *, real *, integer *, integer *), shseqr_(
00073 char *, char *, integer *, integer *, integer *, real *, integer *
00074 , real *, real *, real *, integer *, real *, integer *, integer *), strevc_(char *, char *, logical *, integer *,
00075 real *, integer *, real *, integer *, real *, integer *, integer *
00076 , integer *, real *, integer *);
00077 integer minwrk, maxwrk;
00078 logical wantvl;
00079 real smlnum;
00080 integer hswork;
00081 logical lquery, wantvr;
00082
00083
00084
00085
00086
00087
00088
00089
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 a_dim1 = *lda;
00209 a_offset = 1 + a_dim1;
00210 a -= a_offset;
00211 --wr;
00212 --wi;
00213 vl_dim1 = *ldvl;
00214 vl_offset = 1 + vl_dim1;
00215 vl -= vl_offset;
00216 vr_dim1 = *ldvr;
00217 vr_offset = 1 + vr_dim1;
00218 vr -= vr_offset;
00219 --work;
00220
00221
00222 *info = 0;
00223 lquery = *lwork == -1;
00224 wantvl = lsame_(jobvl, "V");
00225 wantvr = lsame_(jobvr, "V");
00226 if (! wantvl && ! lsame_(jobvl, "N")) {
00227 *info = -1;
00228 } else if (! wantvr && ! lsame_(jobvr, "N")) {
00229 *info = -2;
00230 } else if (*n < 0) {
00231 *info = -3;
00232 } else if (*lda < max(1,*n)) {
00233 *info = -5;
00234 } else if (*ldvl < 1 || wantvl && *ldvl < *n) {
00235 *info = -9;
00236 } else if (*ldvr < 1 || wantvr && *ldvr < *n) {
00237 *info = -11;
00238 }
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250 if (*info == 0) {
00251 if (*n == 0) {
00252 minwrk = 1;
00253 maxwrk = 1;
00254 } else {
00255 maxwrk = (*n << 1) + *n * ilaenv_(&c__1, "SGEHRD", " ", n, &c__1,
00256 n, &c__0);
00257 if (wantvl) {
00258 minwrk = *n << 2;
00259
00260 i__1 = maxwrk, i__2 = (*n << 1) + (*n - 1) * ilaenv_(&c__1,
00261 "SORGHR", " ", n, &c__1, n, &c_n1);
00262 maxwrk = max(i__1,i__2);
00263 shseqr_("S", "V", n, &c__1, n, &a[a_offset], lda, &wr[1], &wi[
00264 1], &vl[vl_offset], ldvl, &work[1], &c_n1, info);
00265 hswork = work[1];
00266
00267 i__1 = maxwrk, i__2 = *n + 1, i__1 = max(i__1,i__2), i__2 = *
00268 n + hswork;
00269 maxwrk = max(i__1,i__2);
00270
00271 i__1 = maxwrk, i__2 = *n << 2;
00272 maxwrk = max(i__1,i__2);
00273 } else if (wantvr) {
00274 minwrk = *n << 2;
00275
00276 i__1 = maxwrk, i__2 = (*n << 1) + (*n - 1) * ilaenv_(&c__1,
00277 "SORGHR", " ", n, &c__1, n, &c_n1);
00278 maxwrk = max(i__1,i__2);
00279 shseqr_("S", "V", n, &c__1, n, &a[a_offset], lda, &wr[1], &wi[
00280 1], &vr[vr_offset], ldvr, &work[1], &c_n1, info);
00281 hswork = work[1];
00282
00283 i__1 = maxwrk, i__2 = *n + 1, i__1 = max(i__1,i__2), i__2 = *
00284 n + hswork;
00285 maxwrk = max(i__1,i__2);
00286
00287 i__1 = maxwrk, i__2 = *n << 2;
00288 maxwrk = max(i__1,i__2);
00289 } else {
00290 minwrk = *n * 3;
00291 shseqr_("E", "N", n, &c__1, n, &a[a_offset], lda, &wr[1], &wi[
00292 1], &vr[vr_offset], ldvr, &work[1], &c_n1, info);
00293 hswork = work[1];
00294
00295 i__1 = maxwrk, i__2 = *n + 1, i__1 = max(i__1,i__2), i__2 = *
00296 n + hswork;
00297 maxwrk = max(i__1,i__2);
00298 }
00299 maxwrk = max(maxwrk,minwrk);
00300 }
00301 work[1] = (real) maxwrk;
00302
00303 if (*lwork < minwrk && ! lquery) {
00304 *info = -13;
00305 }
00306 }
00307
00308 if (*info != 0) {
00309 i__1 = -(*info);
00310 xerbla_("SGEEV ", &i__1);
00311 return 0;
00312 } else if (lquery) {
00313 return 0;
00314 }
00315
00316
00317
00318 if (*n == 0) {
00319 return 0;
00320 }
00321
00322
00323
00324 eps = slamch_("P");
00325 smlnum = slamch_("S");
00326 bignum = 1.f / smlnum;
00327 slabad_(&smlnum, &bignum);
00328 smlnum = sqrt(smlnum) / eps;
00329 bignum = 1.f / smlnum;
00330
00331
00332
00333 anrm = slange_("M", n, n, &a[a_offset], lda, dum);
00334 scalea = FALSE_;
00335 if (anrm > 0.f && anrm < smlnum) {
00336 scalea = TRUE_;
00337 cscale = smlnum;
00338 } else if (anrm > bignum) {
00339 scalea = TRUE_;
00340 cscale = bignum;
00341 }
00342 if (scalea) {
00343 slascl_("G", &c__0, &c__0, &anrm, &cscale, n, n, &a[a_offset], lda, &
00344 ierr);
00345 }
00346
00347
00348
00349
00350 ibal = 1;
00351 sgebal_("B", n, &a[a_offset], lda, &ilo, &ihi, &work[ibal], &ierr);
00352
00353
00354
00355
00356 itau = ibal + *n;
00357 iwrk = itau + *n;
00358 i__1 = *lwork - iwrk + 1;
00359 sgehrd_(n, &ilo, &ihi, &a[a_offset], lda, &work[itau], &work[iwrk], &i__1,
00360 &ierr);
00361
00362 if (wantvl) {
00363
00364
00365
00366
00367 *(unsigned char *)side = 'L';
00368 slacpy_("L", n, n, &a[a_offset], lda, &vl[vl_offset], ldvl)
00369 ;
00370
00371
00372
00373
00374 i__1 = *lwork - iwrk + 1;
00375 sorghr_(n, &ilo, &ihi, &vl[vl_offset], ldvl, &work[itau], &work[iwrk],
00376 &i__1, &ierr);
00377
00378
00379
00380
00381 iwrk = itau;
00382 i__1 = *lwork - iwrk + 1;
00383 shseqr_("S", "V", n, &ilo, &ihi, &a[a_offset], lda, &wr[1], &wi[1], &
00384 vl[vl_offset], ldvl, &work[iwrk], &i__1, info);
00385
00386 if (wantvr) {
00387
00388
00389
00390
00391 *(unsigned char *)side = 'B';
00392 slacpy_("F", n, n, &vl[vl_offset], ldvl, &vr[vr_offset], ldvr);
00393 }
00394
00395 } else if (wantvr) {
00396
00397
00398
00399
00400 *(unsigned char *)side = 'R';
00401 slacpy_("L", n, n, &a[a_offset], lda, &vr[vr_offset], ldvr)
00402 ;
00403
00404
00405
00406
00407 i__1 = *lwork - iwrk + 1;
00408 sorghr_(n, &ilo, &ihi, &vr[vr_offset], ldvr, &work[itau], &work[iwrk],
00409 &i__1, &ierr);
00410
00411
00412
00413
00414 iwrk = itau;
00415 i__1 = *lwork - iwrk + 1;
00416 shseqr_("S", "V", n, &ilo, &ihi, &a[a_offset], lda, &wr[1], &wi[1], &
00417 vr[vr_offset], ldvr, &work[iwrk], &i__1, info);
00418
00419 } else {
00420
00421
00422
00423
00424 iwrk = itau;
00425 i__1 = *lwork - iwrk + 1;
00426 shseqr_("E", "N", n, &ilo, &ihi, &a[a_offset], lda, &wr[1], &wi[1], &
00427 vr[vr_offset], ldvr, &work[iwrk], &i__1, info);
00428 }
00429
00430
00431
00432 if (*info > 0) {
00433 goto L50;
00434 }
00435
00436 if (wantvl || wantvr) {
00437
00438
00439
00440
00441 strevc_(side, "B", select, n, &a[a_offset], lda, &vl[vl_offset], ldvl,
00442 &vr[vr_offset], ldvr, n, &nout, &work[iwrk], &ierr);
00443 }
00444
00445 if (wantvl) {
00446
00447
00448
00449
00450 sgebak_("B", "L", n, &ilo, &ihi, &work[ibal], n, &vl[vl_offset], ldvl,
00451 &ierr);
00452
00453
00454
00455 i__1 = *n;
00456 for (i__ = 1; i__ <= i__1; ++i__) {
00457 if (wi[i__] == 0.f) {
00458 scl = 1.f / snrm2_(n, &vl[i__ * vl_dim1 + 1], &c__1);
00459 sscal_(n, &scl, &vl[i__ * vl_dim1 + 1], &c__1);
00460 } else if (wi[i__] > 0.f) {
00461 r__1 = snrm2_(n, &vl[i__ * vl_dim1 + 1], &c__1);
00462 r__2 = snrm2_(n, &vl[(i__ + 1) * vl_dim1 + 1], &c__1);
00463 scl = 1.f / slapy2_(&r__1, &r__2);
00464 sscal_(n, &scl, &vl[i__ * vl_dim1 + 1], &c__1);
00465 sscal_(n, &scl, &vl[(i__ + 1) * vl_dim1 + 1], &c__1);
00466 i__2 = *n;
00467 for (k = 1; k <= i__2; ++k) {
00468
00469 r__1 = vl[k + i__ * vl_dim1];
00470
00471 r__2 = vl[k + (i__ + 1) * vl_dim1];
00472 work[iwrk + k - 1] = r__1 * r__1 + r__2 * r__2;
00473
00474 }
00475 k = isamax_(n, &work[iwrk], &c__1);
00476 slartg_(&vl[k + i__ * vl_dim1], &vl[k + (i__ + 1) * vl_dim1],
00477 &cs, &sn, &r__);
00478 srot_(n, &vl[i__ * vl_dim1 + 1], &c__1, &vl[(i__ + 1) *
00479 vl_dim1 + 1], &c__1, &cs, &sn);
00480 vl[k + (i__ + 1) * vl_dim1] = 0.f;
00481 }
00482
00483 }
00484 }
00485
00486 if (wantvr) {
00487
00488
00489
00490
00491 sgebak_("B", "R", n, &ilo, &ihi, &work[ibal], n, &vr[vr_offset], ldvr,
00492 &ierr);
00493
00494
00495
00496 i__1 = *n;
00497 for (i__ = 1; i__ <= i__1; ++i__) {
00498 if (wi[i__] == 0.f) {
00499 scl = 1.f / snrm2_(n, &vr[i__ * vr_dim1 + 1], &c__1);
00500 sscal_(n, &scl, &vr[i__ * vr_dim1 + 1], &c__1);
00501 } else if (wi[i__] > 0.f) {
00502 r__1 = snrm2_(n, &vr[i__ * vr_dim1 + 1], &c__1);
00503 r__2 = snrm2_(n, &vr[(i__ + 1) * vr_dim1 + 1], &c__1);
00504 scl = 1.f / slapy2_(&r__1, &r__2);
00505 sscal_(n, &scl, &vr[i__ * vr_dim1 + 1], &c__1);
00506 sscal_(n, &scl, &vr[(i__ + 1) * vr_dim1 + 1], &c__1);
00507 i__2 = *n;
00508 for (k = 1; k <= i__2; ++k) {
00509
00510 r__1 = vr[k + i__ * vr_dim1];
00511
00512 r__2 = vr[k + (i__ + 1) * vr_dim1];
00513 work[iwrk + k - 1] = r__1 * r__1 + r__2 * r__2;
00514
00515 }
00516 k = isamax_(n, &work[iwrk], &c__1);
00517 slartg_(&vr[k + i__ * vr_dim1], &vr[k + (i__ + 1) * vr_dim1],
00518 &cs, &sn, &r__);
00519 srot_(n, &vr[i__ * vr_dim1 + 1], &c__1, &vr[(i__ + 1) *
00520 vr_dim1 + 1], &c__1, &cs, &sn);
00521 vr[k + (i__ + 1) * vr_dim1] = 0.f;
00522 }
00523
00524 }
00525 }
00526
00527
00528
00529 L50:
00530 if (scalea) {
00531 i__1 = *n - *info;
00532
00533 i__3 = *n - *info;
00534 i__2 = max(i__3,1);
00535 slascl_("G", &c__0, &c__0, &cscale, &anrm, &i__1, &c__1, &wr[*info +
00536 1], &i__2, &ierr);
00537 i__1 = *n - *info;
00538
00539 i__3 = *n - *info;
00540 i__2 = max(i__3,1);
00541 slascl_("G", &c__0, &c__0, &cscale, &anrm, &i__1, &c__1, &wi[*info +
00542 1], &i__2, &ierr);
00543 if (*info > 0) {
00544 i__1 = ilo - 1;
00545 slascl_("G", &c__0, &c__0, &cscale, &anrm, &i__1, &c__1, &wr[1],
00546 n, &ierr);
00547 i__1 = ilo - 1;
00548 slascl_("G", &c__0, &c__0, &cscale, &anrm, &i__1, &c__1, &wi[1],
00549 n, &ierr);
00550 }
00551 }
00552
00553 work[1] = (real) maxwrk;
00554 return 0;
00555
00556
00557
00558 }