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