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 doublecomplex c_b1 = {0.,0.};
00019 static integer c__9 = 9;
00020 static integer c__0 = 0;
00021 static integer c__6 = 6;
00022 static integer c_n1 = -1;
00023 static integer c__1 = 1;
00024 static doublereal c_b80 = 0.;
00025
00026 int zgelsd_(integer *m, integer *n, integer *nrhs,
00027 doublecomplex *a, integer *lda, doublecomplex *b, integer *ldb,
00028 doublereal *s, doublereal *rcond, integer *rank, doublecomplex *work,
00029 integer *lwork, doublereal *rwork, integer *iwork, integer *info)
00030 {
00031
00032 integer a_dim1, a_offset, b_dim1, b_offset, i__1, i__2, i__3, i__4;
00033
00034
00035 double log(doublereal);
00036
00037
00038 integer ie, il, mm;
00039 doublereal eps, anrm, bnrm;
00040 integer itau, nlvl, iascl, ibscl;
00041 doublereal sfmin;
00042 integer minmn, maxmn, itaup, itauq, mnthr, nwork;
00043 extern int dlabad_(doublereal *, doublereal *);
00044 extern doublereal dlamch_(char *);
00045 extern int dlascl_(char *, integer *, integer *,
00046 doublereal *, doublereal *, integer *, integer *, doublereal *,
00047 integer *, integer *), dlaset_(char *, integer *, integer
00048 *, doublereal *, doublereal *, doublereal *, integer *),
00049 xerbla_(char *, integer *), zgebrd_(integer *, integer *,
00050 doublecomplex *, integer *, doublereal *, doublereal *,
00051 doublecomplex *, doublecomplex *, doublecomplex *, integer *,
00052 integer *);
00053 extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
00054 integer *, integer *);
00055 extern doublereal zlange_(char *, integer *, integer *, doublecomplex *,
00056 integer *, doublereal *);
00057 doublereal bignum;
00058 extern int zgelqf_(integer *, integer *, doublecomplex *,
00059 integer *, doublecomplex *, doublecomplex *, integer *, integer *
00060 ), zlalsd_(char *, integer *, integer *, integer *, doublereal *,
00061 doublereal *, doublecomplex *, integer *, doublereal *, integer *,
00062 doublecomplex *, doublereal *, integer *, integer *),
00063 zlascl_(char *, integer *, integer *, doublereal *, doublereal *,
00064 integer *, integer *, doublecomplex *, integer *, integer *), zgeqrf_(integer *, integer *, doublecomplex *, integer *,
00065 doublecomplex *, doublecomplex *, integer *, integer *);
00066 integer ldwork;
00067 extern int zlacpy_(char *, integer *, integer *,
00068 doublecomplex *, integer *, doublecomplex *, integer *),
00069 zlaset_(char *, integer *, integer *, doublecomplex *,
00070 doublecomplex *, doublecomplex *, integer *);
00071 integer liwork, minwrk, maxwrk;
00072 doublereal smlnum;
00073 extern int zunmbr_(char *, char *, char *, integer *,
00074 integer *, integer *, doublecomplex *, integer *, doublecomplex *,
00075 doublecomplex *, integer *, doublecomplex *, integer *, integer *
00076 );
00077 integer lrwork;
00078 logical lquery;
00079 integer nrwork, smlsiz;
00080 extern int zunmlq_(char *, char *, integer *, integer *,
00081 integer *, doublecomplex *, integer *, doublecomplex *,
00082 doublecomplex *, integer *, doublecomplex *, integer *, integer *), zunmqr_(char *, char *, integer *, integer *,
00083 integer *, doublecomplex *, integer *, doublecomplex *,
00084 doublecomplex *, integer *, doublecomplex *, integer *, integer *);
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
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
00243 a_dim1 = *lda;
00244 a_offset = 1 + a_dim1;
00245 a -= a_offset;
00246 b_dim1 = *ldb;
00247 b_offset = 1 + b_dim1;
00248 b -= b_offset;
00249 --s;
00250 --work;
00251 --rwork;
00252 --iwork;
00253
00254
00255 *info = 0;
00256 minmn = min(*m,*n);
00257 maxmn = max(*m,*n);
00258 lquery = *lwork == -1;
00259 if (*m < 0) {
00260 *info = -1;
00261 } else if (*n < 0) {
00262 *info = -2;
00263 } else if (*nrhs < 0) {
00264 *info = -3;
00265 } else if (*lda < max(1,*m)) {
00266 *info = -5;
00267 } else if (*ldb < max(1,maxmn)) {
00268 *info = -7;
00269 }
00270
00271
00272
00273
00274
00275
00276
00277
00278 if (*info == 0) {
00279 minwrk = 1;
00280 maxwrk = 1;
00281 liwork = 1;
00282 lrwork = 1;
00283 if (minmn > 0) {
00284 smlsiz = ilaenv_(&c__9, "ZGELSD", " ", &c__0, &c__0, &c__0, &c__0);
00285 mnthr = ilaenv_(&c__6, "ZGELSD", " ", m, n, nrhs, &c_n1);
00286
00287 i__1 = (integer) (log((doublereal) minmn / (doublereal) (smlsiz +
00288 1)) / log(2.)) + 1;
00289 nlvl = max(i__1,0);
00290 liwork = minmn * 3 * nlvl + minmn * 11;
00291 mm = *m;
00292 if (*m >= *n && *m >= mnthr) {
00293
00294
00295
00296
00297 mm = *n;
00298
00299 i__1 = maxwrk, i__2 = *n * ilaenv_(&c__1, "ZGEQRF", " ", m, n,
00300 &c_n1, &c_n1);
00301 maxwrk = max(i__1,i__2);
00302
00303 i__1 = maxwrk, i__2 = *nrhs * ilaenv_(&c__1, "ZUNMQR", "LC",
00304 m, nrhs, n, &c_n1);
00305 maxwrk = max(i__1,i__2);
00306 }
00307 if (*m >= *n) {
00308
00309
00310
00311
00312 i__1 = smlsiz + 1;
00313 lrwork = *n * 10 + (*n << 1) * smlsiz + (*n << 3) * nlvl +
00314 smlsiz * 3 * *nrhs + i__1 * i__1;
00315
00316 i__1 = maxwrk, i__2 = (*n << 1) + (mm + *n) * ilaenv_(&c__1,
00317 "ZGEBRD", " ", &mm, n, &c_n1, &c_n1);
00318 maxwrk = max(i__1,i__2);
00319
00320 i__1 = maxwrk, i__2 = (*n << 1) + *nrhs * ilaenv_(&c__1,
00321 "ZUNMBR", "QLC", &mm, nrhs, n, &c_n1);
00322 maxwrk = max(i__1,i__2);
00323
00324 i__1 = maxwrk, i__2 = (*n << 1) + (*n - 1) * ilaenv_(&c__1,
00325 "ZUNMBR", "PLN", n, nrhs, n, &c_n1);
00326 maxwrk = max(i__1,i__2);
00327
00328 i__1 = maxwrk, i__2 = (*n << 1) + *n * *nrhs;
00329 maxwrk = max(i__1,i__2);
00330
00331 i__1 = (*n << 1) + mm, i__2 = (*n << 1) + *n * *nrhs;
00332 minwrk = max(i__1,i__2);
00333 }
00334 if (*n > *m) {
00335
00336 i__1 = smlsiz + 1;
00337 lrwork = *m * 10 + (*m << 1) * smlsiz + (*m << 3) * nlvl +
00338 smlsiz * 3 * *nrhs + i__1 * i__1;
00339 if (*n >= mnthr) {
00340
00341
00342
00343
00344 maxwrk = *m + *m * ilaenv_(&c__1, "ZGELQF", " ", m, n, &
00345 c_n1, &c_n1);
00346
00347 i__1 = maxwrk, i__2 = *m * *m + (*m << 2) + (*m << 1) *
00348 ilaenv_(&c__1, "ZGEBRD", " ", m, m, &c_n1, &c_n1);
00349 maxwrk = max(i__1,i__2);
00350
00351 i__1 = maxwrk, i__2 = *m * *m + (*m << 2) + *nrhs *
00352 ilaenv_(&c__1, "ZUNMBR", "QLC", m, nrhs, m, &c_n1);
00353 maxwrk = max(i__1,i__2);
00354
00355 i__1 = maxwrk, i__2 = *m * *m + (*m << 2) + (*m - 1) *
00356 ilaenv_(&c__1, "ZUNMLQ", "LC", n, nrhs, m, &c_n1);
00357 maxwrk = max(i__1,i__2);
00358 if (*nrhs > 1) {
00359
00360 i__1 = maxwrk, i__2 = *m * *m + *m + *m * *nrhs;
00361 maxwrk = max(i__1,i__2);
00362 } else {
00363
00364 i__1 = maxwrk, i__2 = *m * *m + (*m << 1);
00365 maxwrk = max(i__1,i__2);
00366 }
00367
00368 i__1 = maxwrk, i__2 = *m * *m + (*m << 2) + *m * *nrhs;
00369 maxwrk = max(i__1,i__2);
00370
00371
00372
00373
00374 i__3 = *m, i__4 = (*m << 1) - 4, i__3 = max(i__3,i__4),
00375 i__3 = max(i__3,*nrhs), i__4 = *n - *m * 3;
00376 i__1 = maxwrk, i__2 = (*m << 2) + *m * *m + max(i__3,i__4)
00377 ;
00378 maxwrk = max(i__1,i__2);
00379 } else {
00380
00381
00382
00383 maxwrk = (*m << 1) + (*n + *m) * ilaenv_(&c__1, "ZGEBRD",
00384 " ", m, n, &c_n1, &c_n1);
00385
00386 i__1 = maxwrk, i__2 = (*m << 1) + *nrhs * ilaenv_(&c__1,
00387 "ZUNMBR", "QLC", m, nrhs, m, &c_n1);
00388 maxwrk = max(i__1,i__2);
00389
00390 i__1 = maxwrk, i__2 = (*m << 1) + *m * ilaenv_(&c__1,
00391 "ZUNMBR", "PLN", n, nrhs, m, &c_n1);
00392 maxwrk = max(i__1,i__2);
00393
00394 i__1 = maxwrk, i__2 = (*m << 1) + *m * *nrhs;
00395 maxwrk = max(i__1,i__2);
00396 }
00397
00398 i__1 = (*m << 1) + *n, i__2 = (*m << 1) + *m * *nrhs;
00399 minwrk = max(i__1,i__2);
00400 }
00401 }
00402 minwrk = min(minwrk,maxwrk);
00403 work[1].r = (doublereal) maxwrk, work[1].i = 0.;
00404 iwork[1] = liwork;
00405 rwork[1] = (doublereal) lrwork;
00406
00407 if (*lwork < minwrk && ! lquery) {
00408 *info = -12;
00409 }
00410 }
00411
00412 if (*info != 0) {
00413 i__1 = -(*info);
00414 xerbla_("ZGELSD", &i__1);
00415 return 0;
00416 } else if (lquery) {
00417 return 0;
00418 }
00419
00420
00421
00422 if (*m == 0 || *n == 0) {
00423 *rank = 0;
00424 return 0;
00425 }
00426
00427
00428
00429 eps = dlamch_("P");
00430 sfmin = dlamch_("S");
00431 smlnum = sfmin / eps;
00432 bignum = 1. / smlnum;
00433 dlabad_(&smlnum, &bignum);
00434
00435
00436
00437 anrm = zlange_("M", m, n, &a[a_offset], lda, &rwork[1]);
00438 iascl = 0;
00439 if (anrm > 0. && anrm < smlnum) {
00440
00441
00442
00443 zlascl_("G", &c__0, &c__0, &anrm, &smlnum, m, n, &a[a_offset], lda,
00444 info);
00445 iascl = 1;
00446 } else if (anrm > bignum) {
00447
00448
00449
00450 zlascl_("G", &c__0, &c__0, &anrm, &bignum, m, n, &a[a_offset], lda,
00451 info);
00452 iascl = 2;
00453 } else if (anrm == 0.) {
00454
00455
00456
00457 i__1 = max(*m,*n);
00458 zlaset_("F", &i__1, nrhs, &c_b1, &c_b1, &b[b_offset], ldb);
00459 dlaset_("F", &minmn, &c__1, &c_b80, &c_b80, &s[1], &c__1);
00460 *rank = 0;
00461 goto L10;
00462 }
00463
00464
00465
00466 bnrm = zlange_("M", m, nrhs, &b[b_offset], ldb, &rwork[1]);
00467 ibscl = 0;
00468 if (bnrm > 0. && bnrm < smlnum) {
00469
00470
00471
00472 zlascl_("G", &c__0, &c__0, &bnrm, &smlnum, m, nrhs, &b[b_offset], ldb,
00473 info);
00474 ibscl = 1;
00475 } else if (bnrm > bignum) {
00476
00477
00478
00479 zlascl_("G", &c__0, &c__0, &bnrm, &bignum, m, nrhs, &b[b_offset], ldb,
00480 info);
00481 ibscl = 2;
00482 }
00483
00484
00485
00486 if (*m < *n) {
00487 i__1 = *n - *m;
00488 zlaset_("F", &i__1, nrhs, &c_b1, &c_b1, &b[*m + 1 + b_dim1], ldb);
00489 }
00490
00491
00492
00493 if (*m >= *n) {
00494
00495
00496
00497 mm = *m;
00498 if (*m >= mnthr) {
00499
00500
00501
00502 mm = *n;
00503 itau = 1;
00504 nwork = itau + *n;
00505
00506
00507
00508
00509
00510 i__1 = *lwork - nwork + 1;
00511 zgeqrf_(m, n, &a[a_offset], lda, &work[itau], &work[nwork], &i__1,
00512 info);
00513
00514
00515
00516
00517
00518 i__1 = *lwork - nwork + 1;
00519 zunmqr_("L", "C", m, nrhs, n, &a[a_offset], lda, &work[itau], &b[
00520 b_offset], ldb, &work[nwork], &i__1, info);
00521
00522
00523
00524 if (*n > 1) {
00525 i__1 = *n - 1;
00526 i__2 = *n - 1;
00527 zlaset_("L", &i__1, &i__2, &c_b1, &c_b1, &a[a_dim1 + 2], lda);
00528 }
00529 }
00530
00531 itauq = 1;
00532 itaup = itauq + *n;
00533 nwork = itaup + *n;
00534 ie = 1;
00535 nrwork = ie + *n;
00536
00537
00538
00539
00540
00541 i__1 = *lwork - nwork + 1;
00542 zgebrd_(&mm, n, &a[a_offset], lda, &s[1], &rwork[ie], &work[itauq], &
00543 work[itaup], &work[nwork], &i__1, info);
00544
00545
00546
00547
00548 i__1 = *lwork - nwork + 1;
00549 zunmbr_("Q", "L", "C", &mm, nrhs, n, &a[a_offset], lda, &work[itauq],
00550 &b[b_offset], ldb, &work[nwork], &i__1, info);
00551
00552
00553
00554 zlalsd_("U", &smlsiz, n, nrhs, &s[1], &rwork[ie], &b[b_offset], ldb,
00555 rcond, rank, &work[nwork], &rwork[nrwork], &iwork[1], info);
00556 if (*info != 0) {
00557 goto L10;
00558 }
00559
00560
00561
00562 i__1 = *lwork - nwork + 1;
00563 zunmbr_("P", "L", "N", n, nrhs, n, &a[a_offset], lda, &work[itaup], &
00564 b[b_offset], ldb, &work[nwork], &i__1, info);
00565
00566 } else {
00567
00568 i__1 = *m, i__2 = (*m << 1) - 4, i__1 = max(i__1,i__2), i__1 = max(
00569 i__1,*nrhs), i__2 = *n - *m * 3;
00570 if (*n >= mnthr && *lwork >= (*m << 2) + *m * *m + max(i__1,i__2)) {
00571
00572
00573
00574
00575 ldwork = *m;
00576
00577
00578 i__3 = *m, i__4 = (*m << 1) - 4, i__3 = max(i__3,i__4), i__3 =
00579 max(i__3,*nrhs), i__4 = *n - *m * 3;
00580 i__1 = (*m << 2) + *m * *lda + max(i__3,i__4), i__2 = *m * *lda +
00581 *m + *m * *nrhs;
00582 if (*lwork >= max(i__1,i__2)) {
00583 ldwork = *lda;
00584 }
00585 itau = 1;
00586 nwork = *m + 1;
00587
00588
00589
00590
00591 i__1 = *lwork - nwork + 1;
00592 zgelqf_(m, n, &a[a_offset], lda, &work[itau], &work[nwork], &i__1,
00593 info);
00594 il = nwork;
00595
00596
00597
00598 zlacpy_("L", m, m, &a[a_offset], lda, &work[il], &ldwork);
00599 i__1 = *m - 1;
00600 i__2 = *m - 1;
00601 zlaset_("U", &i__1, &i__2, &c_b1, &c_b1, &work[il + ldwork], &
00602 ldwork);
00603 itauq = il + ldwork * *m;
00604 itaup = itauq + *m;
00605 nwork = itaup + *m;
00606 ie = 1;
00607 nrwork = ie + *m;
00608
00609
00610
00611
00612
00613 i__1 = *lwork - nwork + 1;
00614 zgebrd_(m, m, &work[il], &ldwork, &s[1], &rwork[ie], &work[itauq],
00615 &work[itaup], &work[nwork], &i__1, info);
00616
00617
00618
00619
00620 i__1 = *lwork - nwork + 1;
00621 zunmbr_("Q", "L", "C", m, nrhs, m, &work[il], &ldwork, &work[
00622 itauq], &b[b_offset], ldb, &work[nwork], &i__1, info);
00623
00624
00625
00626 zlalsd_("U", &smlsiz, m, nrhs, &s[1], &rwork[ie], &b[b_offset],
00627 ldb, rcond, rank, &work[nwork], &rwork[nrwork], &iwork[1],
00628 info);
00629 if (*info != 0) {
00630 goto L10;
00631 }
00632
00633
00634
00635 i__1 = *lwork - nwork + 1;
00636 zunmbr_("P", "L", "N", m, nrhs, m, &work[il], &ldwork, &work[
00637 itaup], &b[b_offset], ldb, &work[nwork], &i__1, info);
00638
00639
00640
00641 i__1 = *n - *m;
00642 zlaset_("F", &i__1, nrhs, &c_b1, &c_b1, &b[*m + 1 + b_dim1], ldb);
00643 nwork = itau + *m;
00644
00645
00646
00647
00648 i__1 = *lwork - nwork + 1;
00649 zunmlq_("L", "C", n, nrhs, m, &a[a_offset], lda, &work[itau], &b[
00650 b_offset], ldb, &work[nwork], &i__1, info);
00651
00652 } else {
00653
00654
00655
00656 itauq = 1;
00657 itaup = itauq + *m;
00658 nwork = itaup + *m;
00659 ie = 1;
00660 nrwork = ie + *m;
00661
00662
00663
00664
00665
00666 i__1 = *lwork - nwork + 1;
00667 zgebrd_(m, n, &a[a_offset], lda, &s[1], &rwork[ie], &work[itauq],
00668 &work[itaup], &work[nwork], &i__1, info);
00669
00670
00671
00672
00673 i__1 = *lwork - nwork + 1;
00674 zunmbr_("Q", "L", "C", m, nrhs, n, &a[a_offset], lda, &work[itauq]
00675 , &b[b_offset], ldb, &work[nwork], &i__1, info);
00676
00677
00678
00679 zlalsd_("L", &smlsiz, m, nrhs, &s[1], &rwork[ie], &b[b_offset],
00680 ldb, rcond, rank, &work[nwork], &rwork[nrwork], &iwork[1],
00681 info);
00682 if (*info != 0) {
00683 goto L10;
00684 }
00685
00686
00687
00688 i__1 = *lwork - nwork + 1;
00689 zunmbr_("P", "L", "N", n, nrhs, m, &a[a_offset], lda, &work[itaup]
00690 , &b[b_offset], ldb, &work[nwork], &i__1, info);
00691
00692 }
00693 }
00694
00695
00696
00697 if (iascl == 1) {
00698 zlascl_("G", &c__0, &c__0, &anrm, &smlnum, n, nrhs, &b[b_offset], ldb,
00699 info);
00700 dlascl_("G", &c__0, &c__0, &smlnum, &anrm, &minmn, &c__1, &s[1], &
00701 minmn, info);
00702 } else if (iascl == 2) {
00703 zlascl_("G", &c__0, &c__0, &anrm, &bignum, n, nrhs, &b[b_offset], ldb,
00704 info);
00705 dlascl_("G", &c__0, &c__0, &bignum, &anrm, &minmn, &c__1, &s[1], &
00706 minmn, info);
00707 }
00708 if (ibscl == 1) {
00709 zlascl_("G", &c__0, &c__0, &smlnum, &bnrm, n, nrhs, &b[b_offset], ldb,
00710 info);
00711 } else if (ibscl == 2) {
00712 zlascl_("G", &c__0, &c__0, &bignum, &bnrm, n, nrhs, &b[b_offset], ldb,
00713 info);
00714 }
00715
00716 L10:
00717 work[1].r = (doublereal) maxwrk, work[1].i = 0.;
00718 iwork[1] = liwork;
00719 rwork[1] = (doublereal) lrwork;
00720 return 0;
00721
00722
00723
00724 }