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 doublereal c_b34 = 0.;
00020 static doublereal c_b35 = 1.;
00021 static integer c__0 = 0;
00022 static integer c_n1 = -1;
00023
00024 int dgejsv_(char *joba, char *jobu, char *jobv, char *jobr,
00025 char *jobt, char *jobp, integer *m, integer *n, doublereal *a,
00026 integer *lda, doublereal *sva, doublereal *u, integer *ldu,
00027 doublereal *v, integer *ldv, doublereal *work, integer *lwork,
00028 integer *iwork, integer *info)
00029 {
00030
00031 integer a_dim1, a_offset, u_dim1, u_offset, v_dim1, v_offset, i__1, i__2,
00032 i__3, i__4, i__5, i__6, i__7, i__8, i__9, i__10;
00033 doublereal d__1, d__2, d__3, d__4;
00034
00035
00036 double sqrt(doublereal), log(doublereal), d_sign(doublereal *, doublereal
00037 *);
00038 integer i_dnnt(doublereal *);
00039
00040
00041 integer p, q, n1, nr;
00042 doublereal big, xsc, big1;
00043 logical defr;
00044 doublereal aapp, aaqq;
00045 logical kill;
00046 integer ierr;
00047 extern doublereal dnrm2_(integer *, doublereal *, integer *);
00048 doublereal temp1;
00049 logical jracc;
00050 extern int dscal_(integer *, doublereal *, doublereal *,
00051 integer *);
00052 extern logical lsame_(char *, char *);
00053 doublereal small, entra, sfmin;
00054 logical lsvec;
00055 extern int dcopy_(integer *, doublereal *, integer *,
00056 doublereal *, integer *), dswap_(integer *, doublereal *, integer
00057 *, doublereal *, integer *);
00058 doublereal epsln;
00059 logical rsvec;
00060 extern int dtrsm_(char *, char *, char *, char *,
00061 integer *, integer *, doublereal *, doublereal *, integer *,
00062 doublereal *, integer *);
00063 logical l2aber;
00064 extern int dgeqp3_(integer *, integer *, doublereal *,
00065 integer *, integer *, doublereal *, doublereal *, integer *,
00066 integer *);
00067 doublereal condr1, condr2, uscal1, uscal2;
00068 logical l2kill, l2rank, l2tran, l2pert;
00069 extern doublereal dlamch_(char *);
00070 extern int dgelqf_(integer *, integer *, doublereal *,
00071 integer *, doublereal *, doublereal *, integer *, integer *);
00072 extern integer idamax_(integer *, doublereal *, integer *);
00073 doublereal scalem;
00074 extern int dlascl_(char *, integer *, integer *,
00075 doublereal *, doublereal *, integer *, integer *, doublereal *,
00076 integer *, integer *);
00077 doublereal sconda;
00078 logical goscal;
00079 doublereal aatmin;
00080 extern int dgeqrf_(integer *, integer *, doublereal *,
00081 integer *, doublereal *, doublereal *, integer *, integer *);
00082 doublereal aatmax;
00083 extern int dlacpy_(char *, integer *, integer *,
00084 doublereal *, integer *, doublereal *, integer *),
00085 dlaset_(char *, integer *, integer *, doublereal *, doublereal *,
00086 doublereal *, integer *), xerbla_(char *, integer *);
00087 logical noscal;
00088 extern int dpocon_(char *, integer *, doublereal *,
00089 integer *, doublereal *, doublereal *, doublereal *, integer *,
00090 integer *), dgesvj_(char *, char *, char *, integer *,
00091 integer *, doublereal *, integer *, doublereal *, integer *,
00092 doublereal *, integer *, doublereal *, integer *, integer *), dlassq_(integer *, doublereal *, integer
00093 *, doublereal *, doublereal *), dlaswp_(integer *, doublereal *,
00094 integer *, integer *, integer *, integer *, integer *);
00095 doublereal entrat;
00096 logical almort;
00097 extern int dorgqr_(integer *, integer *, integer *,
00098 doublereal *, integer *, doublereal *, doublereal *, integer *,
00099 integer *), dormlq_(char *, char *, integer *, integer *, integer
00100 *, doublereal *, integer *, doublereal *, doublereal *, integer *,
00101 doublereal *, integer *, integer *);
00102 doublereal maxprj;
00103 logical errest;
00104 extern int dormqr_(char *, char *, integer *, integer *,
00105 integer *, doublereal *, integer *, doublereal *, doublereal *,
00106 integer *, doublereal *, integer *, integer *);
00107 logical transp, rowpiv;
00108 doublereal cond_ok__;
00109 integer warning, numrank;
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
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409
00410
00411
00412
00413
00414
00415
00416
00417
00418
00419
00420
00421
00422
00423
00424
00425
00426
00427
00428
00429
00430
00431
00432
00433
00434
00435
00436
00437
00438
00439
00440
00441
00442
00443
00444
00445
00446
00447
00448
00449
00450
00451
00452
00453
00454
00455
00456
00457
00458
00459
00460
00461
00462
00463
00464
00465
00466
00467
00468
00469
00470
00471
00472
00473
00474
00475
00476
00477
00478
00479
00480
00481
00482
00483
00484
00485
00486
00487
00488
00489
00490
00491
00492 --sva;
00493 a_dim1 = *lda;
00494 a_offset = 1 + a_dim1;
00495 a -= a_offset;
00496 u_dim1 = *ldu;
00497 u_offset = 1 + u_dim1;
00498 u -= u_offset;
00499 v_dim1 = *ldv;
00500 v_offset = 1 + v_dim1;
00501 v -= v_offset;
00502 --work;
00503 --iwork;
00504
00505
00506 lsvec = lsame_(jobu, "U") || lsame_(jobu, "F");
00507 jracc = lsame_(jobv, "J");
00508 rsvec = lsame_(jobv, "V") || jracc;
00509 rowpiv = lsame_(joba, "F") || lsame_(joba, "G");
00510 l2rank = lsame_(joba, "R");
00511 l2aber = lsame_(joba, "A");
00512 errest = lsame_(joba, "E") || lsame_(joba, "G");
00513 l2tran = lsame_(jobt, "T");
00514 l2kill = lsame_(jobr, "R");
00515 defr = lsame_(jobr, "N");
00516 l2pert = lsame_(jobp, "P");
00517
00518 if (! (rowpiv || l2rank || l2aber || errest || lsame_(joba, "C"))) {
00519 *info = -1;
00520 } else if (! (lsvec || lsame_(jobu, "N") || lsame_(
00521 jobu, "W"))) {
00522 *info = -2;
00523 } else if (! (rsvec || lsame_(jobv, "N") || lsame_(
00524 jobv, "W")) || jracc && ! lsvec) {
00525 *info = -3;
00526 } else if (! (l2kill || defr)) {
00527 *info = -4;
00528 } else if (! (l2tran || lsame_(jobt, "N"))) {
00529 *info = -5;
00530 } else if (! (l2pert || lsame_(jobp, "N"))) {
00531 *info = -6;
00532 } else if (*m < 0) {
00533 *info = -7;
00534 } else if (*n < 0 || *n > *m) {
00535 *info = -8;
00536 } else if (*lda < *m) {
00537 *info = -10;
00538 } else if (lsvec && *ldu < *m) {
00539 *info = -13;
00540 } else if (rsvec && *ldv < *n) {
00541 *info = -14;
00542 } else {
00543
00544 i__1 = 7, i__2 = (*n << 2) + 1, i__1 = max(i__1,i__2), i__2 = (*m <<
00545 1) + *n;
00546
00547 i__3 = 7, i__4 = (*n << 2) + *n * *n, i__3 = max(i__3,i__4), i__4 = (*
00548 m << 1) + *n;
00549
00550 i__5 = 7, i__6 = (*n << 1) + *m;
00551
00552 i__7 = 7, i__8 = (*n << 1) + *m;
00553
00554 i__9 = 7, i__10 = *m + *n * 3 + *n * *n;
00555 if (! (lsvec || rsvec || errest) && *lwork < max(i__1,i__2) || ! (
00556 lsvec || lsvec) && errest && *lwork < max(i__3,i__4) || lsvec
00557 && ! rsvec && *lwork < max(i__5,i__6) || rsvec && ! lsvec && *
00558 lwork < max(i__7,i__8) || lsvec && rsvec && ! jracc && *lwork
00559 < *n * 6 + (*n << 1) * *n || lsvec && rsvec && jracc && *
00560 lwork < max(i__9,i__10)) {
00561 *info = -17;
00562 } else {
00563
00564 *info = 0;
00565 }
00566 }
00567
00568 if (*info != 0) {
00569
00570 i__1 = -(*info);
00571 xerbla_("DGEJSV", &i__1);
00572 }
00573
00574
00575
00576 if (*m == 0 || *n == 0) {
00577 return 0;
00578 }
00579
00580
00581
00582 if (lsvec) {
00583 n1 = *n;
00584 if (lsame_(jobu, "F")) {
00585 n1 = *m;
00586 }
00587 }
00588
00589
00590
00591
00592
00593 epsln = dlamch_("Epsilon");
00594 sfmin = dlamch_("SafeMinimum");
00595 small = sfmin / epsln;
00596 big = dlamch_("O");
00597
00598
00599
00600
00601
00602
00603
00604
00605 scalem = 1. / sqrt((doublereal) (*m) * (doublereal) (*n));
00606 noscal = TRUE_;
00607 goscal = TRUE_;
00608 i__1 = *n;
00609 for (p = 1; p <= i__1; ++p) {
00610 aapp = 0.;
00611 aaqq = 0.;
00612 dlassq_(m, &a[p * a_dim1 + 1], &c__1, &aapp, &aaqq);
00613 if (aapp > big) {
00614 *info = -9;
00615 i__2 = -(*info);
00616 xerbla_("DGEJSV", &i__2);
00617 return 0;
00618 }
00619 aaqq = sqrt(aaqq);
00620 if (aapp < big / aaqq && noscal) {
00621 sva[p] = aapp * aaqq;
00622 } else {
00623 noscal = FALSE_;
00624 sva[p] = aapp * (aaqq * scalem);
00625 if (goscal) {
00626 goscal = FALSE_;
00627 i__2 = p - 1;
00628 dscal_(&i__2, &scalem, &sva[1], &c__1);
00629 }
00630 }
00631
00632 }
00633
00634 if (noscal) {
00635 scalem = 1.;
00636 }
00637
00638 aapp = 0.;
00639 aaqq = big;
00640 i__1 = *n;
00641 for (p = 1; p <= i__1; ++p) {
00642
00643 d__1 = aapp, d__2 = sva[p];
00644 aapp = max(d__1,d__2);
00645 if (sva[p] != 0.) {
00646
00647 d__1 = aaqq, d__2 = sva[p];
00648 aaqq = min(d__1,d__2);
00649 }
00650
00651 }
00652
00653
00654
00655 if (aapp == 0.) {
00656 if (lsvec) {
00657 dlaset_("G", m, &n1, &c_b34, &c_b35, &u[u_offset], ldu)
00658 ;
00659 }
00660 if (rsvec) {
00661 dlaset_("G", n, n, &c_b34, &c_b35, &v[v_offset], ldv);
00662 }
00663 work[1] = 1.;
00664 work[2] = 1.;
00665 if (errest) {
00666 work[3] = 1.;
00667 }
00668 if (lsvec && rsvec) {
00669 work[4] = 1.;
00670 work[5] = 1.;
00671 }
00672 if (l2tran) {
00673 work[6] = 0.;
00674 work[7] = 0.;
00675 }
00676 iwork[1] = 0;
00677 iwork[2] = 0;
00678 return 0;
00679 }
00680
00681
00682
00683
00684
00685 warning = 0;
00686 if (aaqq <= sfmin) {
00687 l2rank = TRUE_;
00688 l2kill = TRUE_;
00689 warning = 1;
00690 }
00691
00692
00693
00694 if (*n == 1) {
00695
00696 if (lsvec) {
00697 dlascl_("G", &c__0, &c__0, &sva[1], &scalem, m, &c__1, &a[a_dim1
00698 + 1], lda, &ierr);
00699 dlacpy_("A", m, &c__1, &a[a_offset], lda, &u[u_offset], ldu);
00700
00701 if (n1 != *n) {
00702 i__1 = *lwork - *n;
00703 dgeqrf_(m, n, &u[u_offset], ldu, &work[1], &work[*n + 1], &
00704 i__1, &ierr);
00705 i__1 = *lwork - *n;
00706 dorgqr_(m, &n1, &c__1, &u[u_offset], ldu, &work[1], &work[*n
00707 + 1], &i__1, &ierr);
00708 dcopy_(m, &a[a_dim1 + 1], &c__1, &u[u_dim1 + 1], &c__1);
00709 }
00710 }
00711 if (rsvec) {
00712 v[v_dim1 + 1] = 1.;
00713 }
00714 if (sva[1] < big * scalem) {
00715 sva[1] /= scalem;
00716 scalem = 1.;
00717 }
00718 work[1] = 1. / scalem;
00719 work[2] = 1.;
00720 if (sva[1] != 0.) {
00721 iwork[1] = 1;
00722 if (sva[1] / scalem >= sfmin) {
00723 iwork[2] = 1;
00724 } else {
00725 iwork[2] = 0;
00726 }
00727 } else {
00728 iwork[1] = 0;
00729 iwork[2] = 0;
00730 }
00731 if (errest) {
00732 work[3] = 1.;
00733 }
00734 if (lsvec && rsvec) {
00735 work[4] = 1.;
00736 work[5] = 1.;
00737 }
00738 if (l2tran) {
00739 work[6] = 0.;
00740 work[7] = 0.;
00741 }
00742 return 0;
00743
00744 }
00745
00746 transp = FALSE_;
00747 l2tran = l2tran && *m == *n;
00748
00749 aatmax = -1.;
00750 aatmin = big;
00751 if (rowpiv || l2tran) {
00752
00753
00754
00755
00756
00757
00758 if (l2tran) {
00759 i__1 = *m;
00760 for (p = 1; p <= i__1; ++p) {
00761 xsc = 0.;
00762 temp1 = 0.;
00763 dlassq_(n, &a[p + a_dim1], lda, &xsc, &temp1);
00764
00765
00766 work[*m + *n + p] = xsc * scalem;
00767 work[*n + p] = xsc * (scalem * sqrt(temp1));
00768
00769 d__1 = aatmax, d__2 = work[*n + p];
00770 aatmax = max(d__1,d__2);
00771 if (work[*n + p] != 0.) {
00772
00773 d__1 = aatmin, d__2 = work[*n + p];
00774 aatmin = min(d__1,d__2);
00775 }
00776
00777 }
00778 } else {
00779 i__1 = *m;
00780 for (p = 1; p <= i__1; ++p) {
00781 work[*m + *n + p] = scalem * (d__1 = a[p + idamax_(n, &a[p +
00782 a_dim1], lda) * a_dim1], abs(d__1));
00783
00784 d__1 = aatmax, d__2 = work[*m + *n + p];
00785 aatmax = max(d__1,d__2);
00786
00787 d__1 = aatmin, d__2 = work[*m + *n + p];
00788 aatmin = min(d__1,d__2);
00789
00790 }
00791 }
00792
00793 }
00794
00795
00796
00797
00798
00799
00800
00801
00802 entra = 0.;
00803 entrat = 0.;
00804 if (l2tran) {
00805
00806 xsc = 0.;
00807 temp1 = 0.;
00808 dlassq_(n, &sva[1], &c__1, &xsc, &temp1);
00809 temp1 = 1. / temp1;
00810
00811 entra = 0.;
00812 i__1 = *n;
00813 for (p = 1; p <= i__1; ++p) {
00814
00815 d__1 = sva[p] / xsc;
00816 big1 = d__1 * d__1 * temp1;
00817 if (big1 != 0.) {
00818 entra += big1 * log(big1);
00819 }
00820
00821 }
00822 entra = -entra / log((doublereal) (*n));
00823
00824
00825
00826
00827
00828
00829
00830 entrat = 0.;
00831 i__1 = *n + *m;
00832 for (p = *n + 1; p <= i__1; ++p) {
00833
00834 d__1 = work[p] / xsc;
00835 big1 = d__1 * d__1 * temp1;
00836 if (big1 != 0.) {
00837 entrat += big1 * log(big1);
00838 }
00839
00840 }
00841 entrat = -entrat / log((doublereal) (*m));
00842
00843
00844
00845
00846 transp = entrat < entra;
00847
00848
00849
00850 if (transp) {
00851
00852
00853 i__1 = *n - 1;
00854 for (p = 1; p <= i__1; ++p) {
00855 i__2 = *n;
00856 for (q = p + 1; q <= i__2; ++q) {
00857 temp1 = a[q + p * a_dim1];
00858 a[q + p * a_dim1] = a[p + q * a_dim1];
00859 a[p + q * a_dim1] = temp1;
00860
00861 }
00862
00863 }
00864 i__1 = *n;
00865 for (p = 1; p <= i__1; ++p) {
00866 work[*m + *n + p] = sva[p];
00867 sva[p] = work[*n + p];
00868
00869 }
00870 temp1 = aapp;
00871 aapp = aatmax;
00872 aatmax = temp1;
00873 temp1 = aaqq;
00874 aaqq = aatmin;
00875 aatmin = temp1;
00876 kill = lsvec;
00877 lsvec = rsvec;
00878 rsvec = kill;
00879
00880 rowpiv = TRUE_;
00881 }
00882
00883 }
00884
00885
00886
00887
00888
00889
00890
00891
00892
00893
00894
00895
00896 big1 = sqrt(big);
00897 temp1 = sqrt(big / (doublereal) (*n));
00898
00899 dlascl_("G", &c__0, &c__0, &aapp, &temp1, n, &c__1, &sva[1], n, &ierr);
00900 if (aaqq > aapp * sfmin) {
00901 aaqq = aaqq / aapp * temp1;
00902 } else {
00903 aaqq = aaqq * temp1 / aapp;
00904 }
00905 temp1 *= scalem;
00906 dlascl_("G", &c__0, &c__0, &aapp, &temp1, m, n, &a[a_offset], lda, &ierr);
00907
00908
00909
00910
00911 uscal1 = temp1;
00912 uscal2 = aapp;
00913
00914 if (l2kill) {
00915
00916
00917
00918 xsc = sqrt(sfmin);
00919 } else {
00920 xsc = small;
00921
00922
00923
00924
00925
00926
00927
00928
00929
00930 if (aaqq < sqrt(sfmin) && lsvec && rsvec) {
00931 jracc = TRUE_;
00932 }
00933
00934 }
00935 if (aaqq < xsc) {
00936 i__1 = *n;
00937 for (p = 1; p <= i__1; ++p) {
00938 if (sva[p] < xsc) {
00939 dlaset_("A", m, &c__1, &c_b34, &c_b34, &a[p * a_dim1 + 1],
00940 lda);
00941 sva[p] = 0.;
00942 }
00943
00944 }
00945 }
00946
00947
00948
00949 if (rowpiv) {
00950
00951
00952
00953
00954
00955 i__1 = *m - 1;
00956 for (p = 1; p <= i__1; ++p) {
00957 i__2 = *m - p + 1;
00958 q = idamax_(&i__2, &work[*m + *n + p], &c__1) + p - 1;
00959 iwork[(*n << 1) + p] = q;
00960 if (p != q) {
00961 temp1 = work[*m + *n + p];
00962 work[*m + *n + p] = work[*m + *n + q];
00963 work[*m + *n + q] = temp1;
00964 }
00965
00966 }
00967 i__1 = *m - 1;
00968 dlaswp_(n, &a[a_offset], lda, &c__1, &i__1, &iwork[(*n << 1) + 1], &
00969 c__1);
00970 }
00971
00972
00973
00974
00975
00976
00977
00978
00979
00980
00981
00982
00983
00984
00985
00986
00987 i__1 = *n;
00988 for (p = 1; p <= i__1; ++p) {
00989
00990 iwork[p] = 0;
00991
00992 }
00993 i__1 = *lwork - *n;
00994 dgeqp3_(m, n, &a[a_offset], lda, &iwork[1], &work[1], &work[*n + 1], &
00995 i__1, &ierr);
00996
00997
00998
00999
01000
01001
01002
01003
01004
01005 nr = 1;
01006 if (l2aber) {
01007
01008
01009
01010
01011 temp1 = sqrt((doublereal) (*n)) * epsln;
01012 i__1 = *n;
01013 for (p = 2; p <= i__1; ++p) {
01014 if ((d__2 = a[p + p * a_dim1], abs(d__2)) >= temp1 * (d__1 = a[
01015 a_dim1 + 1], abs(d__1))) {
01016 ++nr;
01017 } else {
01018 goto L3002;
01019 }
01020
01021 }
01022 L3002:
01023 ;
01024 } else if (l2rank) {
01025
01026
01027
01028 temp1 = sqrt(sfmin);
01029 i__1 = *n;
01030 for (p = 2; p <= i__1; ++p) {
01031 if ((d__2 = a[p + p * a_dim1], abs(d__2)) < epsln * (d__1 = a[p -
01032 1 + (p - 1) * a_dim1], abs(d__1)) || (d__3 = a[p + p *
01033 a_dim1], abs(d__3)) < small || l2kill && (d__4 = a[p + p *
01034 a_dim1], abs(d__4)) < temp1) {
01035 goto L3402;
01036 }
01037 ++nr;
01038
01039 }
01040 L3402:
01041
01042 ;
01043 } else {
01044
01045
01046
01047
01048
01049
01050
01051 temp1 = sqrt(sfmin);
01052 i__1 = *n;
01053 for (p = 2; p <= i__1; ++p) {
01054 if ((d__1 = a[p + p * a_dim1], abs(d__1)) < small || l2kill && (
01055 d__2 = a[p + p * a_dim1], abs(d__2)) < temp1) {
01056 goto L3302;
01057 }
01058 ++nr;
01059
01060 }
01061 L3302:
01062
01063 ;
01064 }
01065
01066 almort = FALSE_;
01067 if (nr == *n) {
01068 maxprj = 1.;
01069 i__1 = *n;
01070 for (p = 2; p <= i__1; ++p) {
01071 temp1 = (d__1 = a[p + p * a_dim1], abs(d__1)) / sva[iwork[p]];
01072 maxprj = min(maxprj,temp1);
01073
01074 }
01075
01076 d__1 = maxprj;
01077 if (d__1 * d__1 >= 1. - (doublereal) (*n) * epsln) {
01078 almort = TRUE_;
01079 }
01080 }
01081
01082
01083 sconda = -1.;
01084 condr1 = -1.;
01085 condr2 = -1.;
01086
01087 if (errest) {
01088 if (*n == nr) {
01089 if (rsvec) {
01090
01091 dlacpy_("U", n, n, &a[a_offset], lda, &v[v_offset], ldv);
01092 i__1 = *n;
01093 for (p = 1; p <= i__1; ++p) {
01094 temp1 = sva[iwork[p]];
01095 d__1 = 1. / temp1;
01096 dscal_(&p, &d__1, &v[p * v_dim1 + 1], &c__1);
01097
01098 }
01099 dpocon_("U", n, &v[v_offset], ldv, &c_b35, &temp1, &work[*n +
01100 1], &iwork[(*n << 1) + *m + 1], &ierr);
01101 } else if (lsvec) {
01102
01103 dlacpy_("U", n, n, &a[a_offset], lda, &u[u_offset], ldu);
01104 i__1 = *n;
01105 for (p = 1; p <= i__1; ++p) {
01106 temp1 = sva[iwork[p]];
01107 d__1 = 1. / temp1;
01108 dscal_(&p, &d__1, &u[p * u_dim1 + 1], &c__1);
01109
01110 }
01111 dpocon_("U", n, &u[u_offset], ldu, &c_b35, &temp1, &work[*n +
01112 1], &iwork[(*n << 1) + *m + 1], &ierr);
01113 } else {
01114 dlacpy_("U", n, n, &a[a_offset], lda, &work[*n + 1], n);
01115 i__1 = *n;
01116 for (p = 1; p <= i__1; ++p) {
01117 temp1 = sva[iwork[p]];
01118 d__1 = 1. / temp1;
01119 dscal_(&p, &d__1, &work[*n + (p - 1) * *n + 1], &c__1);
01120
01121 }
01122
01123 dpocon_("U", n, &work[*n + 1], n, &c_b35, &temp1, &work[*n + *
01124 n * *n + 1], &iwork[(*n << 1) + *m + 1], &ierr);
01125 }
01126 sconda = 1. / sqrt(temp1);
01127
01128
01129 } else {
01130 sconda = -1.;
01131 }
01132 }
01133
01134 l2pert = l2pert && (d__1 = a[a_dim1 + 1] / a[nr + nr * a_dim1], abs(d__1))
01135 > sqrt(big1);
01136
01137
01138
01139
01140 if (! (rsvec || lsvec)) {
01141
01142
01143
01144
01145
01146 i__2 = *n - 1;
01147 i__1 = min(i__2,nr);
01148 for (p = 1; p <= i__1; ++p) {
01149 i__2 = *n - p;
01150 dcopy_(&i__2, &a[p + (p + 1) * a_dim1], lda, &a[p + 1 + p *
01151 a_dim1], &c__1);
01152
01153 }
01154
01155
01156
01157
01158
01159
01160
01161
01162
01163
01164
01165
01166
01167 if (! almort) {
01168
01169 if (l2pert) {
01170
01171 xsc = epsln / (doublereal) (*n);
01172 i__1 = nr;
01173 for (q = 1; q <= i__1; ++q) {
01174 temp1 = xsc * (d__1 = a[q + q * a_dim1], abs(d__1));
01175 i__2 = *n;
01176 for (p = 1; p <= i__2; ++p) {
01177 if (p > q && (d__1 = a[p + q * a_dim1], abs(d__1)) <=
01178 temp1 || p < q) {
01179 a[p + q * a_dim1] = d_sign(&temp1, &a[p + q *
01180 a_dim1]);
01181 }
01182
01183 }
01184
01185 }
01186 } else {
01187 i__1 = nr - 1;
01188 i__2 = nr - 1;
01189 dlaset_("U", &i__1, &i__2, &c_b34, &c_b34, &a[(a_dim1 << 1) +
01190 1], lda);
01191 }
01192
01193
01194
01195 i__1 = *lwork - *n;
01196 dgeqrf_(n, &nr, &a[a_offset], lda, &work[1], &work[*n + 1], &i__1,
01197 &ierr);
01198
01199
01200 i__1 = nr - 1;
01201 for (p = 1; p <= i__1; ++p) {
01202 i__2 = nr - p;
01203 dcopy_(&i__2, &a[p + (p + 1) * a_dim1], lda, &a[p + 1 + p *
01204 a_dim1], &c__1);
01205
01206 }
01207
01208 }
01209
01210
01211
01212
01213
01214 if (l2pert) {
01215
01216 xsc = epsln / (doublereal) (*n);
01217 i__1 = nr;
01218 for (q = 1; q <= i__1; ++q) {
01219 temp1 = xsc * (d__1 = a[q + q * a_dim1], abs(d__1));
01220 i__2 = nr;
01221 for (p = 1; p <= i__2; ++p) {
01222 if (p > q && (d__1 = a[p + q * a_dim1], abs(d__1)) <=
01223 temp1 || p < q) {
01224 a[p + q * a_dim1] = d_sign(&temp1, &a[p + q * a_dim1])
01225 ;
01226 }
01227
01228 }
01229
01230 }
01231 } else {
01232 i__1 = nr - 1;
01233 i__2 = nr - 1;
01234 dlaset_("U", &i__1, &i__2, &c_b34, &c_b34, &a[(a_dim1 << 1) + 1],
01235 lda);
01236 }
01237
01238
01239
01240
01241
01242 dgesvj_("L", "NoU", "NoV", &nr, &nr, &a[a_offset], lda, &sva[1], n, &
01243 v[v_offset], ldv, &work[1], lwork, info);
01244
01245 scalem = work[1];
01246 numrank = i_dnnt(&work[2]);
01247
01248
01249 } else if (rsvec && ! lsvec) {
01250
01251
01252
01253 if (almort) {
01254
01255
01256 i__1 = nr;
01257 for (p = 1; p <= i__1; ++p) {
01258 i__2 = *n - p + 1;
01259 dcopy_(&i__2, &a[p + p * a_dim1], lda, &v[p + p * v_dim1], &
01260 c__1);
01261
01262 }
01263 i__1 = nr - 1;
01264 i__2 = nr - 1;
01265 dlaset_("Upper", &i__1, &i__2, &c_b34, &c_b34, &v[(v_dim1 << 1) +
01266 1], ldv);
01267
01268 dgesvj_("L", "U", "N", n, &nr, &v[v_offset], ldv, &sva[1], &nr, &
01269 a[a_offset], lda, &work[1], lwork, info);
01270 scalem = work[1];
01271 numrank = i_dnnt(&work[2]);
01272 } else {
01273
01274
01275
01276
01277 i__1 = nr - 1;
01278 i__2 = nr - 1;
01279 dlaset_("Lower", &i__1, &i__2, &c_b34, &c_b34, &a[a_dim1 + 2],
01280 lda);
01281 i__1 = *lwork - *n;
01282 dgelqf_(&nr, n, &a[a_offset], lda, &work[1], &work[*n + 1], &i__1,
01283 &ierr);
01284 dlacpy_("Lower", &nr, &nr, &a[a_offset], lda, &v[v_offset], ldv);
01285 i__1 = nr - 1;
01286 i__2 = nr - 1;
01287 dlaset_("Upper", &i__1, &i__2, &c_b34, &c_b34, &v[(v_dim1 << 1) +
01288 1], ldv);
01289 i__1 = *lwork - (*n << 1);
01290 dgeqrf_(&nr, &nr, &v[v_offset], ldv, &work[*n + 1], &work[(*n <<
01291 1) + 1], &i__1, &ierr);
01292 i__1 = nr;
01293 for (p = 1; p <= i__1; ++p) {
01294 i__2 = nr - p + 1;
01295 dcopy_(&i__2, &v[p + p * v_dim1], ldv, &v[p + p * v_dim1], &
01296 c__1);
01297
01298 }
01299 i__1 = nr - 1;
01300 i__2 = nr - 1;
01301 dlaset_("Upper", &i__1, &i__2, &c_b34, &c_b34, &v[(v_dim1 << 1) +
01302 1], ldv);
01303
01304 dgesvj_("Lower", "U", "N", &nr, &nr, &v[v_offset], ldv, &sva[1], &
01305 nr, &u[u_offset], ldu, &work[*n + 1], lwork, info);
01306 scalem = work[*n + 1];
01307 numrank = i_dnnt(&work[*n + 2]);
01308 if (nr < *n) {
01309 i__1 = *n - nr;
01310 dlaset_("A", &i__1, &nr, &c_b34, &c_b34, &v[nr + 1 + v_dim1],
01311 ldv);
01312 i__1 = *n - nr;
01313 dlaset_("A", &nr, &i__1, &c_b34, &c_b34, &v[(nr + 1) * v_dim1
01314 + 1], ldv);
01315 i__1 = *n - nr;
01316 i__2 = *n - nr;
01317 dlaset_("A", &i__1, &i__2, &c_b34, &c_b35, &v[nr + 1 + (nr +
01318 1) * v_dim1], ldv);
01319 }
01320
01321 i__1 = *lwork - *n;
01322 dormlq_("Left", "Transpose", n, n, &nr, &a[a_offset], lda, &work[
01323 1], &v[v_offset], ldv, &work[*n + 1], &i__1, &ierr);
01324
01325 }
01326
01327 i__1 = *n;
01328 for (p = 1; p <= i__1; ++p) {
01329 dcopy_(n, &v[p + v_dim1], ldv, &a[iwork[p] + a_dim1], lda);
01330
01331 }
01332 dlacpy_("All", n, n, &a[a_offset], lda, &v[v_offset], ldv);
01333
01334 if (transp) {
01335 dlacpy_("All", n, n, &v[v_offset], ldv, &u[u_offset], ldu);
01336 }
01337
01338 } else if (lsvec && ! rsvec) {
01339
01340
01341
01342
01343
01344 i__1 = nr;
01345 for (p = 1; p <= i__1; ++p) {
01346 i__2 = *n - p + 1;
01347 dcopy_(&i__2, &a[p + p * a_dim1], lda, &u[p + p * u_dim1], &c__1);
01348
01349 }
01350 i__1 = nr - 1;
01351 i__2 = nr - 1;
01352 dlaset_("Upper", &i__1, &i__2, &c_b34, &c_b34, &u[(u_dim1 << 1) + 1],
01353 ldu);
01354
01355 i__1 = *lwork - (*n << 1);
01356 dgeqrf_(n, &nr, &u[u_offset], ldu, &work[*n + 1], &work[(*n << 1) + 1]
01357 , &i__1, &ierr);
01358
01359 i__1 = nr - 1;
01360 for (p = 1; p <= i__1; ++p) {
01361 i__2 = nr - p;
01362 dcopy_(&i__2, &u[p + (p + 1) * u_dim1], ldu, &u[p + 1 + p *
01363 u_dim1], &c__1);
01364
01365 }
01366 i__1 = nr - 1;
01367 i__2 = nr - 1;
01368 dlaset_("Upper", &i__1, &i__2, &c_b34, &c_b34, &u[(u_dim1 << 1) + 1],
01369 ldu);
01370
01371 i__1 = *lwork - *n;
01372 dgesvj_("Lower", "U", "N", &nr, &nr, &u[u_offset], ldu, &sva[1], &nr,
01373 &a[a_offset], lda, &work[*n + 1], &i__1, info);
01374 scalem = work[*n + 1];
01375 numrank = i_dnnt(&work[*n + 2]);
01376
01377 if (nr < *m) {
01378 i__1 = *m - nr;
01379 dlaset_("A", &i__1, &nr, &c_b34, &c_b34, &u[nr + 1 + u_dim1], ldu);
01380 if (nr < n1) {
01381 i__1 = n1 - nr;
01382 dlaset_("A", &nr, &i__1, &c_b34, &c_b34, &u[(nr + 1) * u_dim1
01383 + 1], ldu);
01384 i__1 = *m - nr;
01385 i__2 = n1 - nr;
01386 dlaset_("A", &i__1, &i__2, &c_b34, &c_b35, &u[nr + 1 + (nr +
01387 1) * u_dim1], ldu);
01388 }
01389 }
01390
01391 i__1 = *lwork - *n;
01392 dormqr_("Left", "No Tr", m, &n1, n, &a[a_offset], lda, &work[1], &u[
01393 u_offset], ldu, &work[*n + 1], &i__1, &ierr);
01394
01395 if (rowpiv) {
01396 i__1 = *m - 1;
01397 dlaswp_(&n1, &u[u_offset], ldu, &c__1, &i__1, &iwork[(*n << 1) +
01398 1], &c_n1);
01399 }
01400
01401 i__1 = n1;
01402 for (p = 1; p <= i__1; ++p) {
01403 xsc = 1. / dnrm2_(m, &u[p * u_dim1 + 1], &c__1);
01404 dscal_(m, &xsc, &u[p * u_dim1 + 1], &c__1);
01405
01406 }
01407
01408 if (transp) {
01409 dlacpy_("All", n, n, &u[u_offset], ldu, &v[v_offset], ldv);
01410 }
01411
01412 } else {
01413
01414
01415
01416 if (! jracc) {
01417
01418 if (! almort) {
01419
01420
01421
01422
01423
01424
01425
01426
01427 i__1 = nr;
01428 for (p = 1; p <= i__1; ++p) {
01429 i__2 = *n - p + 1;
01430 dcopy_(&i__2, &a[p + p * a_dim1], lda, &v[p + p * v_dim1],
01431 &c__1);
01432
01433 }
01434
01435
01436
01437
01438
01439
01440
01441
01442
01443
01444
01445
01446
01447 if (l2pert) {
01448 xsc = sqrt(small);
01449 i__1 = nr;
01450 for (q = 1; q <= i__1; ++q) {
01451 temp1 = xsc * (d__1 = v[q + q * v_dim1], abs(d__1));
01452 i__2 = *n;
01453 for (p = 1; p <= i__2; ++p) {
01454 if (p > q && (d__1 = v[p + q * v_dim1], abs(d__1))
01455 <= temp1 || p < q) {
01456 v[p + q * v_dim1] = d_sign(&temp1, &v[p + q *
01457 v_dim1]);
01458 }
01459 if (p < q) {
01460 v[p + q * v_dim1] = -v[p + q * v_dim1];
01461 }
01462
01463 }
01464
01465 }
01466 } else {
01467 i__1 = nr - 1;
01468 i__2 = nr - 1;
01469 dlaset_("U", &i__1, &i__2, &c_b34, &c_b34, &v[(v_dim1 <<
01470 1) + 1], ldv);
01471 }
01472
01473
01474
01475
01476
01477 dlacpy_("L", &nr, &nr, &v[v_offset], ldv, &work[(*n << 1) + 1]
01478 , &nr);
01479 i__1 = nr;
01480 for (p = 1; p <= i__1; ++p) {
01481 i__2 = nr - p + 1;
01482 temp1 = dnrm2_(&i__2, &work[(*n << 1) + (p - 1) * nr + p],
01483 &c__1);
01484 i__2 = nr - p + 1;
01485 d__1 = 1. / temp1;
01486 dscal_(&i__2, &d__1, &work[(*n << 1) + (p - 1) * nr + p],
01487 &c__1);
01488
01489 }
01490 dpocon_("Lower", &nr, &work[(*n << 1) + 1], &nr, &c_b35, &
01491 temp1, &work[(*n << 1) + nr * nr + 1], &iwork[*m + (*
01492 n << 1) + 1], &ierr);
01493 condr1 = 1. / sqrt(temp1);
01494
01495
01496
01497
01498
01499 cond_ok__ = sqrt((doublereal) nr);
01500
01501 if (condr1 < cond_ok__) {
01502
01503
01504
01505
01506 i__1 = *lwork - (*n << 1);
01507 dgeqrf_(n, &nr, &v[v_offset], ldv, &work[*n + 1], &work[(*
01508 n << 1) + 1], &i__1, &ierr);
01509
01510 if (l2pert) {
01511 xsc = sqrt(small) / epsln;
01512 i__1 = nr;
01513 for (p = 2; p <= i__1; ++p) {
01514 i__2 = p - 1;
01515 for (q = 1; q <= i__2; ++q) {
01516
01517 d__3 = (d__1 = v[p + p * v_dim1], abs(d__1)),
01518 d__4 = (d__2 = v[q + q * v_dim1], abs(
01519 d__2));
01520 temp1 = xsc * min(d__3,d__4);
01521 if ((d__1 = v[q + p * v_dim1], abs(d__1)) <=
01522 temp1) {
01523 v[q + p * v_dim1] = d_sign(&temp1, &v[q +
01524 p * v_dim1]);
01525 }
01526
01527 }
01528
01529 }
01530 }
01531
01532 if (nr != *n) {
01533 dlacpy_("A", n, &nr, &v[v_offset], ldv, &work[(*n <<
01534 1) + 1], n);
01535 }
01536
01537
01538
01539 i__1 = nr - 1;
01540 for (p = 1; p <= i__1; ++p) {
01541 i__2 = nr - p;
01542 dcopy_(&i__2, &v[p + (p + 1) * v_dim1], ldv, &v[p + 1
01543 + p * v_dim1], &c__1);
01544
01545 }
01546
01547 condr2 = condr1;
01548
01549 } else {
01550
01551
01552
01553
01554
01555
01556
01557
01558
01559 i__1 = nr;
01560 for (p = 1; p <= i__1; ++p) {
01561 iwork[*n + p] = 0;
01562
01563 }
01564 i__1 = *lwork - (*n << 1);
01565 dgeqp3_(n, &nr, &v[v_offset], ldv, &iwork[*n + 1], &work[*
01566 n + 1], &work[(*n << 1) + 1], &i__1, &ierr);
01567
01568
01569 if (l2pert) {
01570 xsc = sqrt(small);
01571 i__1 = nr;
01572 for (p = 2; p <= i__1; ++p) {
01573 i__2 = p - 1;
01574 for (q = 1; q <= i__2; ++q) {
01575
01576 d__3 = (d__1 = v[p + p * v_dim1], abs(d__1)),
01577 d__4 = (d__2 = v[q + q * v_dim1], abs(
01578 d__2));
01579 temp1 = xsc * min(d__3,d__4);
01580 if ((d__1 = v[q + p * v_dim1], abs(d__1)) <=
01581 temp1) {
01582 v[q + p * v_dim1] = d_sign(&temp1, &v[q +
01583 p * v_dim1]);
01584 }
01585
01586 }
01587
01588 }
01589 }
01590
01591 dlacpy_("A", n, &nr, &v[v_offset], ldv, &work[(*n << 1) +
01592 1], n);
01593
01594 if (l2pert) {
01595 xsc = sqrt(small);
01596 i__1 = nr;
01597 for (p = 2; p <= i__1; ++p) {
01598 i__2 = p - 1;
01599 for (q = 1; q <= i__2; ++q) {
01600
01601 d__3 = (d__1 = v[p + p * v_dim1], abs(d__1)),
01602 d__4 = (d__2 = v[q + q * v_dim1], abs(
01603 d__2));
01604 temp1 = xsc * min(d__3,d__4);
01605 v[p + q * v_dim1] = -d_sign(&temp1, &v[q + p *
01606 v_dim1]);
01607
01608 }
01609
01610 }
01611 } else {
01612 i__1 = nr - 1;
01613 i__2 = nr - 1;
01614 dlaset_("L", &i__1, &i__2, &c_b34, &c_b34, &v[v_dim1
01615 + 2], ldv);
01616 }
01617
01618 i__1 = *lwork - (*n << 1) - *n * nr - nr;
01619 dgelqf_(&nr, &nr, &v[v_offset], ldv, &work[(*n << 1) + *n
01620 * nr + 1], &work[(*n << 1) + *n * nr + nr + 1], &
01621 i__1, &ierr);
01622
01623 dlacpy_("L", &nr, &nr, &v[v_offset], ldv, &work[(*n << 1)
01624 + *n * nr + nr + 1], &nr);
01625 i__1 = nr;
01626 for (p = 1; p <= i__1; ++p) {
01627 temp1 = dnrm2_(&p, &work[(*n << 1) + *n * nr + nr + p]
01628 , &nr);
01629 d__1 = 1. / temp1;
01630 dscal_(&p, &d__1, &work[(*n << 1) + *n * nr + nr + p],
01631 &nr);
01632
01633 }
01634 dpocon_("L", &nr, &work[(*n << 1) + *n * nr + nr + 1], &
01635 nr, &c_b35, &temp1, &work[(*n << 1) + *n * nr +
01636 nr + nr * nr + 1], &iwork[*m + (*n << 1) + 1], &
01637 ierr);
01638 condr2 = 1. / sqrt(temp1);
01639
01640 if (condr2 >= cond_ok__) {
01641
01642
01643
01644
01645 dlacpy_("U", &nr, &nr, &v[v_offset], ldv, &work[(*n <<
01646 1) + 1], n);
01647
01648
01649 }
01650
01651 }
01652
01653 if (l2pert) {
01654 xsc = sqrt(small);
01655 i__1 = nr;
01656 for (q = 2; q <= i__1; ++q) {
01657 temp1 = xsc * v[q + q * v_dim1];
01658 i__2 = q - 1;
01659 for (p = 1; p <= i__2; ++p) {
01660
01661 v[p + q * v_dim1] = -d_sign(&temp1, &v[p + q *
01662 v_dim1]);
01663
01664 }
01665
01666 }
01667 } else {
01668 i__1 = nr - 1;
01669 i__2 = nr - 1;
01670 dlaset_("U", &i__1, &i__2, &c_b34, &c_b34, &v[(v_dim1 <<
01671 1) + 1], ldv);
01672 }
01673
01674
01675
01676
01677
01678
01679
01680 if (condr1 < cond_ok__) {
01681
01682 i__1 = *lwork - (*n << 1) - *n * nr - nr;
01683 dgesvj_("L", "U", "N", &nr, &nr, &v[v_offset], ldv, &sva[
01684 1], &nr, &u[u_offset], ldu, &work[(*n << 1) + *n *
01685 nr + nr + 1], &i__1, info);
01686 scalem = work[(*n << 1) + *n * nr + nr + 1];
01687 numrank = i_dnnt(&work[(*n << 1) + *n * nr + nr + 2]);
01688 i__1 = nr;
01689 for (p = 1; p <= i__1; ++p) {
01690 dcopy_(&nr, &v[p * v_dim1 + 1], &c__1, &u[p * u_dim1
01691 + 1], &c__1);
01692 dscal_(&nr, &sva[p], &v[p * v_dim1 + 1], &c__1);
01693
01694 }
01695
01696
01697 if (nr == *n) {
01698
01699
01700
01701
01702 dtrsm_("L", "U", "N", "N", &nr, &nr, &c_b35, &a[
01703 a_offset], lda, &v[v_offset], ldv);
01704 } else {
01705
01706
01707
01708
01709 dtrsm_("L", "U", "T", "N", &nr, &nr, &c_b35, &work[(*
01710 n << 1) + 1], n, &v[v_offset], ldv);
01711 if (nr < *n) {
01712 i__1 = *n - nr;
01713 dlaset_("A", &i__1, &nr, &c_b34, &c_b34, &v[nr +
01714 1 + v_dim1], ldv);
01715 i__1 = *n - nr;
01716 dlaset_("A", &nr, &i__1, &c_b34, &c_b34, &v[(nr +
01717 1) * v_dim1 + 1], ldv);
01718 i__1 = *n - nr;
01719 i__2 = *n - nr;
01720 dlaset_("A", &i__1, &i__2, &c_b34, &c_b35, &v[nr
01721 + 1 + (nr + 1) * v_dim1], ldv);
01722 }
01723 i__1 = *lwork - (*n << 1) - *n * nr - nr;
01724 dormqr_("L", "N", n, n, &nr, &work[(*n << 1) + 1], n,
01725 &work[*n + 1], &v[v_offset], ldv, &work[(*n <<
01726 1) + *n * nr + nr + 1], &i__1, &ierr);
01727 }
01728
01729 } else if (condr2 < cond_ok__) {
01730
01731
01732
01733
01734
01735
01736
01737 i__1 = *lwork - (*n << 1) - *n * nr - nr;
01738 dgesvj_("L", "U", "N", &nr, &nr, &v[v_offset], ldv, &sva[
01739 1], &nr, &u[u_offset], ldu, &work[(*n << 1) + *n *
01740 nr + nr + 1], &i__1, info);
01741 scalem = work[(*n << 1) + *n * nr + nr + 1];
01742 numrank = i_dnnt(&work[(*n << 1) + *n * nr + nr + 2]);
01743 i__1 = nr;
01744 for (p = 1; p <= i__1; ++p) {
01745 dcopy_(&nr, &v[p * v_dim1 + 1], &c__1, &u[p * u_dim1
01746 + 1], &c__1);
01747 dscal_(&nr, &sva[p], &u[p * u_dim1 + 1], &c__1);
01748
01749 }
01750 dtrsm_("L", "U", "N", "N", &nr, &nr, &c_b35, &work[(*n <<
01751 1) + 1], n, &u[u_offset], ldu);
01752
01753 i__1 = nr;
01754 for (q = 1; q <= i__1; ++q) {
01755 i__2 = nr;
01756 for (p = 1; p <= i__2; ++p) {
01757 work[(*n << 1) + *n * nr + nr + iwork[*n + p]] =
01758 u[p + q * u_dim1];
01759
01760 }
01761 i__2 = nr;
01762 for (p = 1; p <= i__2; ++p) {
01763 u[p + q * u_dim1] = work[(*n << 1) + *n * nr + nr
01764 + p];
01765
01766 }
01767
01768 }
01769 if (nr < *n) {
01770 i__1 = *n - nr;
01771 dlaset_("A", &i__1, &nr, &c_b34, &c_b34, &v[nr + 1 +
01772 v_dim1], ldv);
01773 i__1 = *n - nr;
01774 dlaset_("A", &nr, &i__1, &c_b34, &c_b34, &v[(nr + 1) *
01775 v_dim1 + 1], ldv);
01776 i__1 = *n - nr;
01777 i__2 = *n - nr;
01778 dlaset_("A", &i__1, &i__2, &c_b34, &c_b35, &v[nr + 1
01779 + (nr + 1) * v_dim1], ldv);
01780 }
01781 i__1 = *lwork - (*n << 1) - *n * nr - nr;
01782 dormqr_("L", "N", n, n, &nr, &work[(*n << 1) + 1], n, &
01783 work[*n + 1], &v[v_offset], ldv, &work[(*n << 1)
01784 + *n * nr + nr + 1], &i__1, &ierr);
01785 } else {
01786
01787
01788
01789
01790
01791
01792
01793
01794
01795
01796
01797 i__1 = *lwork - (*n << 1) - *n * nr - nr;
01798 dgesvj_("L", "U", "V", &nr, &nr, &v[v_offset], ldv, &sva[
01799 1], &nr, &u[u_offset], ldu, &work[(*n << 1) + *n *
01800 nr + nr + 1], &i__1, info);
01801 scalem = work[(*n << 1) + *n * nr + nr + 1];
01802 numrank = i_dnnt(&work[(*n << 1) + *n * nr + nr + 2]);
01803 if (nr < *n) {
01804 i__1 = *n - nr;
01805 dlaset_("A", &i__1, &nr, &c_b34, &c_b34, &v[nr + 1 +
01806 v_dim1], ldv);
01807 i__1 = *n - nr;
01808 dlaset_("A", &nr, &i__1, &c_b34, &c_b34, &v[(nr + 1) *
01809 v_dim1 + 1], ldv);
01810 i__1 = *n - nr;
01811 i__2 = *n - nr;
01812 dlaset_("A", &i__1, &i__2, &c_b34, &c_b35, &v[nr + 1
01813 + (nr + 1) * v_dim1], ldv);
01814 }
01815 i__1 = *lwork - (*n << 1) - *n * nr - nr;
01816 dormqr_("L", "N", n, n, &nr, &work[(*n << 1) + 1], n, &
01817 work[*n + 1], &v[v_offset], ldv, &work[(*n << 1)
01818 + *n * nr + nr + 1], &i__1, &ierr);
01819
01820 i__1 = *lwork - (*n << 1) - *n * nr - nr;
01821 dormlq_("L", "T", &nr, &nr, &nr, &work[(*n << 1) + 1], n,
01822 &work[(*n << 1) + *n * nr + 1], &u[u_offset], ldu,
01823 &work[(*n << 1) + *n * nr + nr + 1], &i__1, &
01824 ierr);
01825 i__1 = nr;
01826 for (q = 1; q <= i__1; ++q) {
01827 i__2 = nr;
01828 for (p = 1; p <= i__2; ++p) {
01829 work[(*n << 1) + *n * nr + nr + iwork[*n + p]] =
01830 u[p + q * u_dim1];
01831
01832 }
01833 i__2 = nr;
01834 for (p = 1; p <= i__2; ++p) {
01835 u[p + q * u_dim1] = work[(*n << 1) + *n * nr + nr
01836 + p];
01837
01838 }
01839
01840 }
01841
01842 }
01843
01844
01845
01846
01847
01848 temp1 = sqrt((doublereal) (*n)) * epsln;
01849 i__1 = *n;
01850 for (q = 1; q <= i__1; ++q) {
01851 i__2 = *n;
01852 for (p = 1; p <= i__2; ++p) {
01853 work[(*n << 1) + *n * nr + nr + iwork[p]] = v[p + q *
01854 v_dim1];
01855
01856 }
01857 i__2 = *n;
01858 for (p = 1; p <= i__2; ++p) {
01859 v[p + q * v_dim1] = work[(*n << 1) + *n * nr + nr + p]
01860 ;
01861
01862 }
01863 xsc = 1. / dnrm2_(n, &v[q * v_dim1 + 1], &c__1);
01864 if (xsc < 1. - temp1 || xsc > temp1 + 1.) {
01865 dscal_(n, &xsc, &v[q * v_dim1 + 1], &c__1);
01866 }
01867
01868 }
01869
01870
01871 if (nr < *m) {
01872 i__1 = *m - nr;
01873 dlaset_("A", &i__1, &nr, &c_b34, &c_b34, &u[nr + 1 +
01874 u_dim1], ldu);
01875 if (nr < n1) {
01876 i__1 = n1 - nr;
01877 dlaset_("A", &nr, &i__1, &c_b34, &c_b34, &u[(nr + 1) *
01878 u_dim1 + 1], ldu);
01879 i__1 = *m - nr;
01880 i__2 = n1 - nr;
01881 dlaset_("A", &i__1, &i__2, &c_b34, &c_b35, &u[nr + 1
01882 + (nr + 1) * u_dim1], ldu);
01883 }
01884 }
01885
01886
01887
01888
01889 i__1 = *lwork - *n;
01890 dormqr_("Left", "No_Tr", m, &n1, n, &a[a_offset], lda, &work[
01891 1], &u[u_offset], ldu, &work[*n + 1], &i__1, &ierr);
01892
01893 temp1 = sqrt((doublereal) (*m)) * epsln;
01894 i__1 = nr;
01895 for (p = 1; p <= i__1; ++p) {
01896 xsc = 1. / dnrm2_(m, &u[p * u_dim1 + 1], &c__1);
01897 if (xsc < 1. - temp1 || xsc > temp1 + 1.) {
01898 dscal_(m, &xsc, &u[p * u_dim1 + 1], &c__1);
01899 }
01900
01901 }
01902
01903
01904
01905
01906 if (rowpiv) {
01907 i__1 = *m - 1;
01908 dlaswp_(&n1, &u[u_offset], ldu, &c__1, &i__1, &iwork[(*n
01909 << 1) + 1], &c_n1);
01910 }
01911
01912 } else {
01913
01914
01915
01916
01917 dlacpy_("Upper", n, n, &a[a_offset], lda, &work[*n + 1], n);
01918 if (l2pert) {
01919 xsc = sqrt(small);
01920 i__1 = *n;
01921 for (p = 2; p <= i__1; ++p) {
01922 temp1 = xsc * work[*n + (p - 1) * *n + p];
01923 i__2 = p - 1;
01924 for (q = 1; q <= i__2; ++q) {
01925 work[*n + (q - 1) * *n + p] = -d_sign(&temp1, &
01926 work[*n + (p - 1) * *n + q]);
01927
01928 }
01929
01930 }
01931 } else {
01932 i__1 = *n - 1;
01933 i__2 = *n - 1;
01934 dlaset_("Lower", &i__1, &i__2, &c_b34, &c_b34, &work[*n +
01935 2], n);
01936 }
01937
01938 i__1 = *lwork - *n - *n * *n;
01939 dgesvj_("Upper", "U", "N", n, n, &work[*n + 1], n, &sva[1], n,
01940 &u[u_offset], ldu, &work[*n + *n * *n + 1], &i__1,
01941 info);
01942
01943 scalem = work[*n + *n * *n + 1];
01944 numrank = i_dnnt(&work[*n + *n * *n + 2]);
01945 i__1 = *n;
01946 for (p = 1; p <= i__1; ++p) {
01947 dcopy_(n, &work[*n + (p - 1) * *n + 1], &c__1, &u[p *
01948 u_dim1 + 1], &c__1);
01949 dscal_(n, &sva[p], &work[*n + (p - 1) * *n + 1], &c__1);
01950
01951 }
01952
01953 dtrsm_("Left", "Upper", "NoTrans", "No UD", n, n, &c_b35, &a[
01954 a_offset], lda, &work[*n + 1], n);
01955 i__1 = *n;
01956 for (p = 1; p <= i__1; ++p) {
01957 dcopy_(n, &work[*n + p], n, &v[iwork[p] + v_dim1], ldv);
01958
01959 }
01960 temp1 = sqrt((doublereal) (*n)) * epsln;
01961 i__1 = *n;
01962 for (p = 1; p <= i__1; ++p) {
01963 xsc = 1. / dnrm2_(n, &v[p * v_dim1 + 1], &c__1);
01964 if (xsc < 1. - temp1 || xsc > temp1 + 1.) {
01965 dscal_(n, &xsc, &v[p * v_dim1 + 1], &c__1);
01966 }
01967
01968 }
01969
01970
01971
01972 if (*n < *m) {
01973 i__1 = *m - *n;
01974 dlaset_("A", &i__1, n, &c_b34, &c_b34, &u[nr + 1 + u_dim1]
01975 , ldu);
01976 if (*n < n1) {
01977 i__1 = n1 - *n;
01978 dlaset_("A", n, &i__1, &c_b34, &c_b34, &u[(*n + 1) *
01979 u_dim1 + 1], ldu);
01980 i__1 = *m - *n;
01981 i__2 = n1 - *n;
01982 dlaset_("A", &i__1, &i__2, &c_b34, &c_b35, &u[nr + 1
01983 + (*n + 1) * u_dim1], ldu);
01984 }
01985 }
01986 i__1 = *lwork - *n;
01987 dormqr_("Left", "No Tr", m, &n1, n, &a[a_offset], lda, &work[
01988 1], &u[u_offset], ldu, &work[*n + 1], &i__1, &ierr);
01989 temp1 = sqrt((doublereal) (*m)) * epsln;
01990 i__1 = n1;
01991 for (p = 1; p <= i__1; ++p) {
01992 xsc = 1. / dnrm2_(m, &u[p * u_dim1 + 1], &c__1);
01993 if (xsc < 1. - temp1 || xsc > temp1 + 1.) {
01994 dscal_(m, &xsc, &u[p * u_dim1 + 1], &c__1);
01995 }
01996
01997 }
01998
01999 if (rowpiv) {
02000 i__1 = *m - 1;
02001 dlaswp_(&n1, &u[u_offset], ldu, &c__1, &i__1, &iwork[(*n
02002 << 1) + 1], &c_n1);
02003 }
02004
02005 }
02006
02007
02008
02009 } else {
02010
02011
02012
02013
02014
02015
02016
02017
02018
02019
02020
02021 i__1 = nr;
02022 for (p = 1; p <= i__1; ++p) {
02023 i__2 = *n - p + 1;
02024 dcopy_(&i__2, &a[p + p * a_dim1], lda, &v[p + p * v_dim1], &
02025 c__1);
02026
02027 }
02028
02029 if (l2pert) {
02030 xsc = sqrt(small / epsln);
02031 i__1 = nr;
02032 for (q = 1; q <= i__1; ++q) {
02033 temp1 = xsc * (d__1 = v[q + q * v_dim1], abs(d__1));
02034 i__2 = *n;
02035 for (p = 1; p <= i__2; ++p) {
02036 if (p > q && (d__1 = v[p + q * v_dim1], abs(d__1)) <=
02037 temp1 || p < q) {
02038 v[p + q * v_dim1] = d_sign(&temp1, &v[p + q *
02039 v_dim1]);
02040 }
02041 if (p < q) {
02042 v[p + q * v_dim1] = -v[p + q * v_dim1];
02043 }
02044
02045 }
02046
02047 }
02048 } else {
02049 i__1 = nr - 1;
02050 i__2 = nr - 1;
02051 dlaset_("U", &i__1, &i__2, &c_b34, &c_b34, &v[(v_dim1 << 1) +
02052 1], ldv);
02053 }
02054 i__1 = *lwork - (*n << 1);
02055 dgeqrf_(n, &nr, &v[v_offset], ldv, &work[*n + 1], &work[(*n << 1)
02056 + 1], &i__1, &ierr);
02057 dlacpy_("L", n, &nr, &v[v_offset], ldv, &work[(*n << 1) + 1], n);
02058
02059 i__1 = nr;
02060 for (p = 1; p <= i__1; ++p) {
02061 i__2 = nr - p + 1;
02062 dcopy_(&i__2, &v[p + p * v_dim1], ldv, &u[p + p * u_dim1], &
02063 c__1);
02064
02065 }
02066 if (l2pert) {
02067 xsc = sqrt(small / epsln);
02068 i__1 = nr;
02069 for (q = 2; q <= i__1; ++q) {
02070 i__2 = q - 1;
02071 for (p = 1; p <= i__2; ++p) {
02072
02073 d__3 = (d__1 = u[p + p * u_dim1], abs(d__1)), d__4 = (
02074 d__2 = u[q + q * u_dim1], abs(d__2));
02075 temp1 = xsc * min(d__3,d__4);
02076 u[p + q * u_dim1] = -d_sign(&temp1, &u[q + p * u_dim1]
02077 );
02078
02079 }
02080
02081 }
02082 } else {
02083 i__1 = nr - 1;
02084 i__2 = nr - 1;
02085 dlaset_("U", &i__1, &i__2, &c_b34, &c_b34, &u[(u_dim1 << 1) +
02086 1], ldu);
02087 }
02088 i__1 = *lwork - (*n << 1) - *n * nr;
02089 dgesvj_("G", "U", "V", &nr, &nr, &u[u_offset], ldu, &sva[1], n, &
02090 v[v_offset], ldv, &work[(*n << 1) + *n * nr + 1], &i__1,
02091 info);
02092 scalem = work[(*n << 1) + *n * nr + 1];
02093 numrank = i_dnnt(&work[(*n << 1) + *n * nr + 2]);
02094 if (nr < *n) {
02095 i__1 = *n - nr;
02096 dlaset_("A", &i__1, &nr, &c_b34, &c_b34, &v[nr + 1 + v_dim1],
02097 ldv);
02098 i__1 = *n - nr;
02099 dlaset_("A", &nr, &i__1, &c_b34, &c_b34, &v[(nr + 1) * v_dim1
02100 + 1], ldv);
02101 i__1 = *n - nr;
02102 i__2 = *n - nr;
02103 dlaset_("A", &i__1, &i__2, &c_b34, &c_b35, &v[nr + 1 + (nr +
02104 1) * v_dim1], ldv);
02105 }
02106 i__1 = *lwork - (*n << 1) - *n * nr - nr;
02107 dormqr_("L", "N", n, n, &nr, &work[(*n << 1) + 1], n, &work[*n +
02108 1], &v[v_offset], ldv, &work[(*n << 1) + *n * nr + nr + 1]
02109 , &i__1, &ierr);
02110
02111
02112
02113
02114
02115 temp1 = sqrt((doublereal) (*n)) * epsln;
02116 i__1 = *n;
02117 for (q = 1; q <= i__1; ++q) {
02118 i__2 = *n;
02119 for (p = 1; p <= i__2; ++p) {
02120 work[(*n << 1) + *n * nr + nr + iwork[p]] = v[p + q *
02121 v_dim1];
02122
02123 }
02124 i__2 = *n;
02125 for (p = 1; p <= i__2; ++p) {
02126 v[p + q * v_dim1] = work[(*n << 1) + *n * nr + nr + p];
02127
02128 }
02129 xsc = 1. / dnrm2_(n, &v[q * v_dim1 + 1], &c__1);
02130 if (xsc < 1. - temp1 || xsc > temp1 + 1.) {
02131 dscal_(n, &xsc, &v[q * v_dim1 + 1], &c__1);
02132 }
02133
02134 }
02135
02136
02137
02138
02139 if (*n < *m) {
02140 i__1 = *m - *n;
02141 dlaset_("A", &i__1, n, &c_b34, &c_b34, &u[nr + 1 + u_dim1],
02142 ldu);
02143 if (*n < n1) {
02144 i__1 = n1 - *n;
02145 dlaset_("A", n, &i__1, &c_b34, &c_b34, &u[(*n + 1) *
02146 u_dim1 + 1], ldu);
02147 i__1 = *m - *n;
02148 i__2 = n1 - *n;
02149 dlaset_("A", &i__1, &i__2, &c_b34, &c_b35, &u[nr + 1 + (*
02150 n + 1) * u_dim1], ldu);
02151 }
02152 }
02153
02154 i__1 = *lwork - *n;
02155 dormqr_("Left", "No Tr", m, &n1, n, &a[a_offset], lda, &work[1], &
02156 u[u_offset], ldu, &work[*n + 1], &i__1, &ierr);
02157
02158 if (rowpiv) {
02159 i__1 = *m - 1;
02160 dlaswp_(&n1, &u[u_offset], ldu, &c__1, &i__1, &iwork[(*n << 1)
02161 + 1], &c_n1);
02162 }
02163
02164
02165 }
02166 if (transp) {
02167
02168 i__1 = *n;
02169 for (p = 1; p <= i__1; ++p) {
02170 dswap_(n, &u[p * u_dim1 + 1], &c__1, &v[p * v_dim1 + 1], &
02171 c__1);
02172
02173 }
02174 }
02175
02176 }
02177
02178
02179
02180
02181 if (uscal2 <= big / sva[1] * uscal1) {
02182 dlascl_("G", &c__0, &c__0, &uscal1, &uscal2, &nr, &c__1, &sva[1], n, &
02183 ierr);
02184 uscal1 = 1.;
02185 uscal2 = 1.;
02186 }
02187
02188 if (nr < *n) {
02189 i__1 = *n;
02190 for (p = nr + 1; p <= i__1; ++p) {
02191 sva[p] = 0.;
02192
02193 }
02194 }
02195
02196 work[1] = uscal2 * scalem;
02197 work[2] = uscal1;
02198 if (errest) {
02199 work[3] = sconda;
02200 }
02201 if (lsvec && rsvec) {
02202 work[4] = condr1;
02203 work[5] = condr2;
02204 }
02205 if (l2tran) {
02206 work[6] = entra;
02207 work[7] = entrat;
02208 }
02209
02210 iwork[1] = nr;
02211 iwork[2] = numrank;
02212 iwork[3] = warning;
02213
02214 return 0;
02215
02216
02217
02218 }