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