14 typedef long long BLASLONG;
15 typedef unsigned long long BLASULONG;
17 typedef long BLASLONG;
18 typedef unsigned long BLASULONG;
22 typedef BLASLONG blasint;
24 #define blasabs(x) llabs(x)
26 #define blasabs(x) labs(x)
30 #define blasabs(x) abs(x)
33 typedef blasint integer;
35 typedef unsigned int uinteger;
36 typedef char *address;
37 typedef short int shortint;
39 typedef double doublereal;
40 typedef struct { real r, i; } complex;
41 typedef struct { doublereal r, i; } doublecomplex;
43 static inline _Fcomplex Cf(complex *z) {_Fcomplex zz={z->r , z->i}; return zz;}
44 static inline _Dcomplex Cd(doublecomplex *z) {_Dcomplex zz={z->r , z->i};return zz;}
45 static inline _Fcomplex * _pCf(complex *z) {return (_Fcomplex*)z;}
46 static inline _Dcomplex * _pCd(doublecomplex *z) {return (_Dcomplex*)z;}
48 static inline _Complex float Cf(complex *z) {return z->r + z->i*_Complex_I;}
49 static inline _Complex double Cd(doublecomplex *z) {return z->r + z->i*_Complex_I;}
50 static inline _Complex float * _pCf(complex *z) {return (_Complex float*)z;}
51 static inline _Complex double * _pCd(doublecomplex *z) {return (_Complex double*)z;}
53 #define pCf(z) (*_pCf(z))
54 #define pCd(z) (*_pCd(z))
56 typedef short int shortlogical;
57 typedef char logical1;
58 typedef char integer1;
63 /* Extern is for use with -E */
74 /*external read, write*/
83 /*internal read, write*/
113 /*rewind, backspace, endfile*/
125 ftnint *inex; /*parameters in standard's order*/
151 union Multitype { /* for multiple entry points */
162 typedef union Multitype Multitype;
164 struct Vardesc { /* for Namelist */
170 typedef struct Vardesc Vardesc;
177 typedef struct Namelist Namelist;
179 #define abs(x) ((x) >= 0 ? (x) : -(x))
180 #define dabs(x) (fabs(x))
181 #define f2cmin(a,b) ((a) <= (b) ? (a) : (b))
182 #define f2cmax(a,b) ((a) >= (b) ? (a) : (b))
183 #define dmin(a,b) (f2cmin(a,b))
184 #define dmax(a,b) (f2cmax(a,b))
185 #define bit_test(a,b) ((a) >> (b) & 1)
186 #define bit_clear(a,b) ((a) & ~((uinteger)1 << (b)))
187 #define bit_set(a,b) ((a) | ((uinteger)1 << (b)))
189 #define abort_() { sig_die("Fortran abort routine called", 1); }
190 #define c_abs(z) (cabsf(Cf(z)))
191 #define c_cos(R,Z) { pCf(R)=ccos(Cf(Z)); }
193 #define c_div(c, a, b) {Cf(c)._Val[0] = (Cf(a)._Val[0]/Cf(b)._Val[0]); Cf(c)._Val[1]=(Cf(a)._Val[1]/Cf(b)._Val[1]);}
194 #define z_div(c, a, b) {Cd(c)._Val[0] = (Cd(a)._Val[0]/Cd(b)._Val[0]); Cd(c)._Val[1]=(Cd(a)._Val[1]/df(b)._Val[1]);}
196 #define c_div(c, a, b) {pCf(c) = Cf(a)/Cf(b);}
197 #define z_div(c, a, b) {pCd(c) = Cd(a)/Cd(b);}
199 #define c_exp(R, Z) {pCf(R) = cexpf(Cf(Z));}
200 #define c_log(R, Z) {pCf(R) = clogf(Cf(Z));}
201 #define c_sin(R, Z) {pCf(R) = csinf(Cf(Z));}
202 //#define c_sqrt(R, Z) {*(R) = csqrtf(Cf(Z));}
203 #define c_sqrt(R, Z) {pCf(R) = csqrtf(Cf(Z));}
204 #define d_abs(x) (fabs(*(x)))
205 #define d_acos(x) (acos(*(x)))
206 #define d_asin(x) (asin(*(x)))
207 #define d_atan(x) (atan(*(x)))
208 #define d_atn2(x, y) (atan2(*(x),*(y)))
209 #define d_cnjg(R, Z) { pCd(R) = conj(Cd(Z)); }
210 #define r_cnjg(R, Z) { pCf(R) = conjf(Cf(Z)); }
211 #define d_cos(x) (cos(*(x)))
212 #define d_cosh(x) (cosh(*(x)))
213 #define d_dim(__a, __b) ( *(__a) > *(__b) ? *(__a) - *(__b) : 0.0 )
214 #define d_exp(x) (exp(*(x)))
215 #define d_imag(z) (cimag(Cd(z)))
216 #define r_imag(z) (cimagf(Cf(z)))
217 #define d_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
218 #define r_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
219 #define d_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
220 #define r_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
221 #define d_log(x) (log(*(x)))
222 #define d_mod(x, y) (fmod(*(x), *(y)))
223 #define u_nint(__x) ((__x)>=0 ? floor((__x) + .5) : -floor(.5 - (__x)))
224 #define d_nint(x) u_nint(*(x))
225 #define u_sign(__a,__b) ((__b) >= 0 ? ((__a) >= 0 ? (__a) : -(__a)) : -((__a) >= 0 ? (__a) : -(__a)))
226 #define d_sign(a,b) u_sign(*(a),*(b))
227 #define r_sign(a,b) u_sign(*(a),*(b))
228 #define d_sin(x) (sin(*(x)))
229 #define d_sinh(x) (sinh(*(x)))
230 #define d_sqrt(x) (sqrt(*(x)))
231 #define d_tan(x) (tan(*(x)))
232 #define d_tanh(x) (tanh(*(x)))
233 #define i_abs(x) abs(*(x))
234 #define i_dnnt(x) ((integer)u_nint(*(x)))
235 #define i_len(s, n) (n)
236 #define i_nint(x) ((integer)u_nint(*(x)))
237 #define i_sign(a,b) ((integer)u_sign((integer)*(a),(integer)*(b)))
238 #define pow_dd(ap, bp) ( pow(*(ap), *(bp)))
239 #define pow_si(B,E) spow_ui(*(B),*(E))
240 #define pow_ri(B,E) spow_ui(*(B),*(E))
241 #define pow_di(B,E) dpow_ui(*(B),*(E))
242 #define pow_zi(p, a, b) {pCd(p) = zpow_ui(Cd(a), *(b));}
243 #define pow_ci(p, a, b) {pCf(p) = cpow_ui(Cf(a), *(b));}
244 #define pow_zz(R,A,B) {pCd(R) = cpow(Cd(A),*(B));}
245 #define s_cat(lpp, rpp, rnp, np, llp) { ftnlen i, nc, ll; char *f__rp, *lp; ll = (llp); lp = (lpp); for(i=0; i < (int)*(np); ++i) { nc = ll; if((rnp)[i] < nc) nc = (rnp)[i]; ll -= nc; f__rp = (rpp)[i]; while(--nc >= 0) *lp++ = *(f__rp)++; } while(--ll >= 0) *lp++ = ' '; }
246 #define s_cmp(a,b,c,d) ((integer)strncmp((a),(b),f2cmin((c),(d))))
247 #define s_copy(A,B,C,D) { int __i,__m; for (__i=0, __m=f2cmin((C),(D)); __i<__m && (B)[__i] != 0; ++__i) (A)[__i] = (B)[__i]; }
248 #define sig_die(s, kill) { exit(1); }
249 #define s_stop(s, n) {exit(0);}
250 static char junk[] = "\n@(#)LIBF77 VERSION 19990503\n";
251 #define z_abs(z) (cabs(Cd(z)))
252 #define z_exp(R, Z) {pCd(R) = cexp(Cd(Z));}
253 #define z_sqrt(R, Z) {pCd(R) = csqrt(Cd(Z));}
254 #define myexit_() break;
255 #define mycycle() continue;
256 #define myceiling(w) {ceil(w)}
257 #define myhuge(w) {HUGE_VAL}
258 //#define mymaxloc_(w,s,e,n) {if (sizeof(*(w)) == sizeof(double)) dmaxloc_((w),*(s),*(e),n); else dmaxloc_((w),*(s),*(e),n);}
259 #define mymaxloc(w,s,e,n) {dmaxloc_(w,*(s),*(e),n)}
261 /* procedure parameter types for -A and -C++ */
263 #define F2C_proc_par_types 1
265 typedef logical (*L_fp)(...);
267 typedef logical (*L_fp)();
270 static float spow_ui(float x, integer n) {
271 float pow=1.0; unsigned long int u;
273 if(n < 0) n = -n, x = 1/x;
282 static double dpow_ui(double x, integer n) {
283 double pow=1.0; unsigned long int u;
285 if(n < 0) n = -n, x = 1/x;
295 static _Fcomplex cpow_ui(complex x, integer n) {
296 complex pow={1.0,0.0}; unsigned long int u;
298 if(n < 0) n = -n, x.r = 1/x.r, x.i=1/x.i;
300 if(u & 01) pow.r *= x.r, pow.i *= x.i;
301 if(u >>= 1) x.r *= x.r, x.i *= x.i;
305 _Fcomplex p={pow.r, pow.i};
309 static _Complex float cpow_ui(_Complex float x, integer n) {
310 _Complex float pow=1.0; unsigned long int u;
312 if(n < 0) n = -n, x = 1/x;
323 static _Dcomplex zpow_ui(_Dcomplex x, integer n) {
324 _Dcomplex pow={1.0,0.0}; unsigned long int u;
326 if(n < 0) n = -n, x._Val[0] = 1/x._Val[0], x._Val[1] =1/x._Val[1];
328 if(u & 01) pow._Val[0] *= x._Val[0], pow._Val[1] *= x._Val[1];
329 if(u >>= 1) x._Val[0] *= x._Val[0], x._Val[1] *= x._Val[1];
333 _Dcomplex p = {pow._Val[0], pow._Val[1]};
337 static _Complex double zpow_ui(_Complex double x, integer n) {
338 _Complex double pow=1.0; unsigned long int u;
340 if(n < 0) n = -n, x = 1/x;
350 static integer pow_ii(integer x, integer n) {
351 integer pow; unsigned long int u;
353 if (n == 0 || x == 1) pow = 1;
354 else if (x != -1) pow = x == 0 ? 1/x : 0;
357 if ((n > 0) || !(n == 0 || x == 1 || x != -1)) {
367 static integer dmaxloc_(double *w, integer s, integer e, integer *n)
369 double m; integer i, mi;
370 for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
371 if (w[i-1]>m) mi=i ,m=w[i-1];
374 static integer smaxloc_(float *w, integer s, integer e, integer *n)
376 float m; integer i, mi;
377 for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
378 if (w[i-1]>m) mi=i ,m=w[i-1];
381 static inline void cdotc_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
382 integer n = *n_, incx = *incx_, incy = *incy_, i;
384 _Fcomplex zdotc = {0.0, 0.0};
385 if (incx == 1 && incy == 1) {
386 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
387 zdotc._Val[0] += conjf(Cf(&x[i]))._Val[0] * Cf(&y[i])._Val[0];
388 zdotc._Val[1] += conjf(Cf(&x[i]))._Val[1] * Cf(&y[i])._Val[1];
391 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
392 zdotc._Val[0] += conjf(Cf(&x[i*incx]))._Val[0] * Cf(&y[i*incy])._Val[0];
393 zdotc._Val[1] += conjf(Cf(&x[i*incx]))._Val[1] * Cf(&y[i*incy])._Val[1];
399 _Complex float zdotc = 0.0;
400 if (incx == 1 && incy == 1) {
401 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
402 zdotc += conjf(Cf(&x[i])) * Cf(&y[i]);
405 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
406 zdotc += conjf(Cf(&x[i*incx])) * Cf(&y[i*incy]);
412 static inline void zdotc_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
413 integer n = *n_, incx = *incx_, incy = *incy_, i;
415 _Dcomplex zdotc = {0.0, 0.0};
416 if (incx == 1 && incy == 1) {
417 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
418 zdotc._Val[0] += conj(Cd(&x[i]))._Val[0] * Cd(&y[i])._Val[0];
419 zdotc._Val[1] += conj(Cd(&x[i]))._Val[1] * Cd(&y[i])._Val[1];
422 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
423 zdotc._Val[0] += conj(Cd(&x[i*incx]))._Val[0] * Cd(&y[i*incy])._Val[0];
424 zdotc._Val[1] += conj(Cd(&x[i*incx]))._Val[1] * Cd(&y[i*incy])._Val[1];
430 _Complex double zdotc = 0.0;
431 if (incx == 1 && incy == 1) {
432 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
433 zdotc += conj(Cd(&x[i])) * Cd(&y[i]);
436 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
437 zdotc += conj(Cd(&x[i*incx])) * Cd(&y[i*incy]);
443 static inline void cdotu_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
444 integer n = *n_, incx = *incx_, incy = *incy_, i;
446 _Fcomplex zdotc = {0.0, 0.0};
447 if (incx == 1 && incy == 1) {
448 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
449 zdotc._Val[0] += Cf(&x[i])._Val[0] * Cf(&y[i])._Val[0];
450 zdotc._Val[1] += Cf(&x[i])._Val[1] * Cf(&y[i])._Val[1];
453 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
454 zdotc._Val[0] += Cf(&x[i*incx])._Val[0] * Cf(&y[i*incy])._Val[0];
455 zdotc._Val[1] += Cf(&x[i*incx])._Val[1] * Cf(&y[i*incy])._Val[1];
461 _Complex float zdotc = 0.0;
462 if (incx == 1 && incy == 1) {
463 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
464 zdotc += Cf(&x[i]) * Cf(&y[i]);
467 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
468 zdotc += Cf(&x[i*incx]) * Cf(&y[i*incy]);
474 static inline void zdotu_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
475 integer n = *n_, incx = *incx_, incy = *incy_, i;
477 _Dcomplex zdotc = {0.0, 0.0};
478 if (incx == 1 && incy == 1) {
479 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
480 zdotc._Val[0] += Cd(&x[i])._Val[0] * Cd(&y[i])._Val[0];
481 zdotc._Val[1] += Cd(&x[i])._Val[1] * Cd(&y[i])._Val[1];
484 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
485 zdotc._Val[0] += Cd(&x[i*incx])._Val[0] * Cd(&y[i*incy])._Val[0];
486 zdotc._Val[1] += Cd(&x[i*incx])._Val[1] * Cd(&y[i*incy])._Val[1];
492 _Complex double zdotc = 0.0;
493 if (incx == 1 && incy == 1) {
494 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
495 zdotc += Cd(&x[i]) * Cd(&y[i]);
498 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
499 zdotc += Cd(&x[i*incx]) * Cd(&y[i*incy]);
505 /* -- translated by f2c (version 20000121).
506 You must link the resulting object file with the libraries:
507 -lf2c -lm (in that order)
513 /* Table of constant values */
515 static integer c_n1 = -1;
516 static integer c__1 = 1;
517 static real c_b72 = 0.f;
518 static real c_b76 = 1.f;
519 static integer c__0 = 0;
520 static logical c_false = FALSE_;
522 /* > \brief <b> SGESVDQ computes the singular value decomposition (SVD) with a QR-Preconditioned QR SVD Method
523 for GE matrices</b> */
525 /* =========== DOCUMENTATION =========== */
527 /* Online html documentation available at */
528 /* http://www.netlib.org/lapack/explore-html/ */
531 /* > Download SGESVDQ + dependencies */
532 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/sgesvdq
535 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/sgesvdq
538 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/sgesvdq
546 /* SUBROUTINE SGESVDQ( JOBA, JOBP, JOBR, JOBU, JOBV, M, N, A, LDA, */
547 /* S, U, LDU, V, LDV, NUMRANK, IWORK, LIWORK, */
548 /* WORK, LWORK, RWORK, LRWORK, INFO ) */
551 /* CHARACTER JOBA, JOBP, JOBR, JOBU, JOBV */
552 /* INTEGER M, N, LDA, LDU, LDV, NUMRANK, LIWORK, LWORK, LRWORK, */
554 /* REAL A( LDA, * ), U( LDU, * ), V( LDV, * ), WORK( * ) */
555 /* REAL S( * ), RWORK( * ) */
556 /* INTEGER IWORK( * ) */
559 /* > \par Purpose: */
564 /* > SGESVDQ computes the singular value decomposition (SVD) of a real */
565 /* > M-by-N matrix A, where M >= N. The SVD of A is written as */
566 /* > [++] [xx] [x0] [xx] */
567 /* > A = U * SIGMA * V^*, [++] = [xx] * [ox] * [xx] */
569 /* > where SIGMA is an N-by-N diagonal matrix, U is an M-by-N orthonormal */
570 /* > matrix, and V is an N-by-N orthogonal matrix. The diagonal elements */
571 /* > of SIGMA are the singular values of A. The columns of U and V are the */
572 /* > left and the right singular vectors of A, respectively. */
578 /* > \param[in] JOBA */
580 /* > JOBA is CHARACTER*1 */
581 /* > Specifies the level of accuracy in the computed SVD */
582 /* > = 'A' The requested accuracy corresponds to having the backward */
583 /* > error bounded by || delta A ||_F <= f(m,n) * EPS * || A ||_F, */
584 /* > where EPS = SLAMCH('Epsilon'). This authorises CGESVDQ to */
585 /* > truncate the computed triangular factor in a rank revealing */
586 /* > QR factorization whenever the truncated part is below the */
587 /* > threshold of the order of EPS * ||A||_F. This is aggressive */
588 /* > truncation level. */
589 /* > = 'M' Similarly as with 'A', but the truncation is more gentle: it */
590 /* > is allowed only when there is a drop on the diagonal of the */
591 /* > triangular factor in the QR factorization. This is medium */
592 /* > truncation level. */
593 /* > = 'H' High accuracy requested. No numerical rank determination based */
594 /* > on the rank revealing QR factorization is attempted. */
595 /* > = 'E' Same as 'H', and in addition the condition number of column */
596 /* > scaled A is estimated and returned in RWORK(1). */
597 /* > N^(-1/4)*RWORK(1) <= ||pinv(A_scaled)||_2 <= N^(1/4)*RWORK(1) */
600 /* > \param[in] JOBP */
602 /* > JOBP is CHARACTER*1 */
603 /* > = 'P' The rows of A are ordered in decreasing order with respect to */
604 /* > ||A(i,:)||_\infty. This enhances numerical accuracy at the cost */
605 /* > of extra data movement. Recommended for numerical robustness. */
606 /* > = 'N' No row pivoting. */
609 /* > \param[in] JOBR */
611 /* > JOBR is CHARACTER*1 */
612 /* > = 'T' After the initial pivoted QR factorization, SGESVD is applied to */
613 /* > the transposed R**T of the computed triangular factor R. This involves */
614 /* > some extra data movement (matrix transpositions). Useful for */
615 /* > experiments, research and development. */
616 /* > = 'N' The triangular factor R is given as input to SGESVD. This may be */
617 /* > preferred as it involves less data movement. */
620 /* > \param[in] JOBU */
622 /* > JOBU is CHARACTER*1 */
623 /* > = 'A' All M left singular vectors are computed and returned in the */
624 /* > matrix U. See the description of U. */
625 /* > = 'S' or 'U' N = f2cmin(M,N) left singular vectors are computed and returned */
626 /* > in the matrix U. See the description of U. */
627 /* > = 'R' Numerical rank NUMRANK is determined and only NUMRANK left singular */
628 /* > vectors are computed and returned in the matrix U. */
629 /* > = 'F' The N left singular vectors are returned in factored form as the */
630 /* > product of the Q factor from the initial QR factorization and the */
631 /* > N left singular vectors of (R**T , 0)**T. If row pivoting is used, */
632 /* > then the necessary information on the row pivoting is stored in */
633 /* > IWORK(N+1:N+M-1). */
634 /* > = 'N' The left singular vectors are not computed. */
637 /* > \param[in] JOBV */
639 /* > JOBV is CHARACTER*1 */
640 /* > = 'A', 'V' All N right singular vectors are computed and returned in */
641 /* > the matrix V. */
642 /* > = 'R' Numerical rank NUMRANK is determined and only NUMRANK right singular */
643 /* > vectors are computed and returned in the matrix V. This option is */
644 /* > allowed only if JOBU = 'R' or JOBU = 'N'; otherwise it is illegal. */
645 /* > = 'N' The right singular vectors are not computed. */
651 /* > The number of rows of the input matrix A. M >= 0. */
657 /* > The number of columns of the input matrix A. M >= N >= 0. */
660 /* > \param[in,out] A */
662 /* > A is REAL array of dimensions LDA x N */
663 /* > On entry, the input matrix A. */
664 /* > On exit, if JOBU .NE. 'N' or JOBV .NE. 'N', the lower triangle of A contains */
665 /* > the Householder vectors as stored by SGEQP3. If JOBU = 'F', these Householder */
666 /* > vectors together with WORK(1:N) can be used to restore the Q factors from */
667 /* > the initial pivoted QR factorization of A. See the description of U. */
670 /* > \param[in] LDA */
672 /* > LDA is INTEGER. */
673 /* > The leading dimension of the array A. LDA >= f2cmax(1,M). */
676 /* > \param[out] S */
678 /* > S is REAL array of dimension N. */
679 /* > The singular values of A, ordered so that S(i) >= S(i+1). */
682 /* > \param[out] U */
684 /* > U is REAL array, dimension */
685 /* > LDU x M if JOBU = 'A'; see the description of LDU. In this case, */
686 /* > on exit, U contains the M left singular vectors. */
687 /* > LDU x N if JOBU = 'S', 'U', 'R' ; see the description of LDU. In this */
688 /* > case, U contains the leading N or the leading NUMRANK left singular vectors. */
689 /* > LDU x N if JOBU = 'F' ; see the description of LDU. In this case U */
690 /* > contains N x N orthogonal matrix that can be used to form the left */
691 /* > singular vectors. */
692 /* > If JOBU = 'N', U is not referenced. */
695 /* > \param[in] LDU */
697 /* > LDU is INTEGER. */
698 /* > The leading dimension of the array U. */
699 /* > If JOBU = 'A', 'S', 'U', 'R', LDU >= f2cmax(1,M). */
700 /* > If JOBU = 'F', LDU >= f2cmax(1,N). */
701 /* > Otherwise, LDU >= 1. */
704 /* > \param[out] V */
706 /* > V is REAL array, dimension */
707 /* > LDV x N if JOBV = 'A', 'V', 'R' or if JOBA = 'E' . */
708 /* > If JOBV = 'A', or 'V', V contains the N-by-N orthogonal matrix V**T; */
709 /* > If JOBV = 'R', V contains the first NUMRANK rows of V**T (the right */
710 /* > singular vectors, stored rowwise, of the NUMRANK largest singular values). */
711 /* > If JOBV = 'N' and JOBA = 'E', V is used as a workspace. */
712 /* > If JOBV = 'N', and JOBA.NE.'E', V is not referenced. */
715 /* > \param[in] LDV */
717 /* > LDV is INTEGER */
718 /* > The leading dimension of the array V. */
719 /* > If JOBV = 'A', 'V', 'R', or JOBA = 'E', LDV >= f2cmax(1,N). */
720 /* > Otherwise, LDV >= 1. */
723 /* > \param[out] NUMRANK */
725 /* > NUMRANK is INTEGER */
726 /* > NUMRANK is the numerical rank first determined after the rank */
727 /* > revealing QR factorization, following the strategy specified by the */
728 /* > value of JOBA. If JOBV = 'R' and JOBU = 'R', only NUMRANK */
729 /* > leading singular values and vectors are then requested in the call */
730 /* > of SGESVD. The final value of NUMRANK might be further reduced if */
731 /* > some singular values are computed as zeros. */
734 /* > \param[out] IWORK */
736 /* > IWORK is INTEGER array, dimension (f2cmax(1, LIWORK)). */
737 /* > On exit, IWORK(1:N) contains column pivoting permutation of the */
738 /* > rank revealing QR factorization. */
739 /* > If JOBP = 'P', IWORK(N+1:N+M-1) contains the indices of the sequence */
740 /* > of row swaps used in row pivoting. These can be used to restore the */
741 /* > left singular vectors in the case JOBU = 'F'. */
743 /* > If LIWORK, LWORK, or LRWORK = -1, then on exit, if INFO = 0, */
744 /* > LIWORK(1) returns the minimal LIWORK. */
747 /* > \param[in] LIWORK */
749 /* > LIWORK is INTEGER */
750 /* > The dimension of the array IWORK. */
751 /* > LIWORK >= N + M - 1, if JOBP = 'P' and JOBA .NE. 'E'; */
752 /* > LIWORK >= N if JOBP = 'N' and JOBA .NE. 'E'; */
753 /* > LIWORK >= N + M - 1 + N, if JOBP = 'P' and JOBA = 'E'; */
754 /* > LIWORK >= N + N if JOBP = 'N' and JOBA = 'E'. */
756 /* > If LIWORK = -1, then a workspace query is assumed; the routine */
757 /* > only calculates and returns the optimal and minimal sizes */
758 /* > for the WORK, IWORK, and RWORK arrays, and no error */
759 /* > message related to LWORK is issued by XERBLA. */
762 /* > \param[out] WORK */
764 /* > WORK is REAL array, dimension (f2cmax(2, LWORK)), used as a workspace. */
765 /* > On exit, if, on entry, LWORK.NE.-1, WORK(1:N) contains parameters */
766 /* > needed to recover the Q factor from the QR factorization computed by */
769 /* > If LIWORK, LWORK, or LRWORK = -1, then on exit, if INFO = 0, */
770 /* > WORK(1) returns the optimal LWORK, and */
771 /* > WORK(2) returns the minimal LWORK. */
774 /* > \param[in,out] LWORK */
776 /* > LWORK is INTEGER */
777 /* > The dimension of the array WORK. It is determined as follows: */
778 /* > Let LWQP3 = 3*N+1, LWCON = 3*N, and let */
779 /* > LWORQ = { MAX( N, 1 ), if JOBU = 'R', 'S', or 'U' */
780 /* > { MAX( M, 1 ), if JOBU = 'A' */
781 /* > LWSVD = MAX( 5*N, 1 ) */
782 /* > LWLQF = MAX( N/2, 1 ), LWSVD2 = MAX( 5*(N/2), 1 ), LWORLQ = MAX( N, 1 ), */
783 /* > LWQRF = MAX( N/2, 1 ), LWORQ2 = MAX( N, 1 ) */
784 /* > Then the minimal value of LWORK is: */
785 /* > = MAX( N + LWQP3, LWSVD ) if only the singular values are needed; */
786 /* > = MAX( N + LWQP3, LWCON, LWSVD ) if only the singular values are needed, */
787 /* > and a scaled condition estimate requested; */
789 /* > = N + MAX( LWQP3, LWSVD, LWORQ ) if the singular values and the left */
790 /* > singular vectors are requested; */
791 /* > = N + MAX( LWQP3, LWCON, LWSVD, LWORQ ) if the singular values and the left */
792 /* > singular vectors are requested, and also */
793 /* > a scaled condition estimate requested; */
795 /* > = N + MAX( LWQP3, LWSVD ) if the singular values and the right */
796 /* > singular vectors are requested; */
797 /* > = N + MAX( LWQP3, LWCON, LWSVD ) if the singular values and the right */
798 /* > singular vectors are requested, and also */
799 /* > a scaled condition etimate requested; */
801 /* > = N + MAX( LWQP3, LWSVD, LWORQ ) if the full SVD is requested with JOBV = 'R'; */
802 /* > independent of JOBR; */
803 /* > = N + MAX( LWQP3, LWCON, LWSVD, LWORQ ) if the full SVD is requested, */
804 /* > JOBV = 'R' and, also a scaled condition */
805 /* > estimate requested; independent of JOBR; */
806 /* > = MAX( N + MAX( LWQP3, LWSVD, LWORQ ), */
807 /* > N + MAX( LWQP3, N/2+LWLQF, N/2+LWSVD2, N/2+LWORLQ, LWORQ) ) if the */
808 /* > full SVD is requested with JOBV = 'A' or 'V', and */
810 /* > = MAX( N + MAX( LWQP3, LWCON, LWSVD, LWORQ ), */
811 /* > N + MAX( LWQP3, LWCON, N/2+LWLQF, N/2+LWSVD2, N/2+LWORLQ, LWORQ ) ) */
812 /* > if the full SVD is requested with JOBV = 'A' or 'V', and */
813 /* > JOBR ='N', and also a scaled condition number estimate */
815 /* > = MAX( N + MAX( LWQP3, LWSVD, LWORQ ), */
816 /* > N + MAX( LWQP3, N/2+LWQRF, N/2+LWSVD2, N/2+LWORQ2, LWORQ ) ) if the */
817 /* > full SVD is requested with JOBV = 'A', 'V', and JOBR ='T' */
818 /* > = MAX( N + MAX( LWQP3, LWCON, LWSVD, LWORQ ), */
819 /* > N + MAX( LWQP3, LWCON, N/2+LWQRF, N/2+LWSVD2, N/2+LWORQ2, LWORQ ) ) */
820 /* > if the full SVD is requested with JOBV = 'A' or 'V', and */
821 /* > JOBR ='T', and also a scaled condition number estimate */
823 /* > Finally, LWORK must be at least two: LWORK = MAX( 2, LWORK ). */
825 /* > If LWORK = -1, then a workspace query is assumed; the routine */
826 /* > only calculates and returns the optimal and minimal sizes */
827 /* > for the WORK, IWORK, and RWORK arrays, and no error */
828 /* > message related to LWORK is issued by XERBLA. */
831 /* > \param[out] RWORK */
833 /* > RWORK is REAL array, dimension (f2cmax(1, LRWORK)). */
835 /* > 1. If JOBA = 'E', RWORK(1) contains an estimate of the condition */
836 /* > number of column scaled A. If A = C * D where D is diagonal and C */
837 /* > has unit columns in the Euclidean norm, then, assuming full column rank, */
838 /* > N^(-1/4) * RWORK(1) <= ||pinv(C)||_2 <= N^(1/4) * RWORK(1). */
839 /* > Otherwise, RWORK(1) = -1. */
840 /* > 2. RWORK(2) contains the number of singular values computed as */
841 /* > exact zeros in SGESVD applied to the upper triangular or trapeziodal */
842 /* > R (from the initial QR factorization). In case of early exit (no call to */
843 /* > SGESVD, such as in the case of zero matrix) RWORK(2) = -1. */
845 /* > If LIWORK, LWORK, or LRWORK = -1, then on exit, if INFO = 0, */
846 /* > RWORK(1) returns the minimal LRWORK. */
849 /* > \param[in] LRWORK */
851 /* > LRWORK is INTEGER. */
852 /* > The dimension of the array RWORK. */
853 /* > If JOBP ='P', then LRWORK >= MAX(2, M). */
854 /* > Otherwise, LRWORK >= 2 */
856 /* > If LRWORK = -1, then a workspace query is assumed; the routine */
857 /* > only calculates and returns the optimal and minimal sizes */
858 /* > for the WORK, IWORK, and RWORK arrays, and no error */
859 /* > message related to LWORK is issued by XERBLA. */
862 /* > \param[out] INFO */
864 /* > INFO is INTEGER */
865 /* > = 0: successful exit. */
866 /* > < 0: if INFO = -i, the i-th argument had an illegal value. */
867 /* > > 0: if SBDSQR did not converge, INFO specifies how many superdiagonals */
868 /* > of an intermediate bidiagonal form B (computed in SGESVD) did not */
869 /* > converge to zero. */
872 /* > \par Further Details: */
873 /* ======================== */
877 /* > 1. The data movement (matrix transpose) is coded using simple nested */
878 /* > DO-loops because BLAS and LAPACK do not provide corresponding subroutines. */
879 /* > Those DO-loops are easily identified in this source code - by the CONTINUE */
880 /* > statements labeled with 11**. In an optimized version of this code, the */
881 /* > nested DO loops should be replaced with calls to an optimized subroutine. */
882 /* > 2. This code scales A by 1/SQRT(M) if the largest ABS(A(i,j)) could cause */
883 /* > column norm overflow. This is the minial precaution and it is left to the */
884 /* > SVD routine (CGESVD) to do its own preemptive scaling if potential over- */
885 /* > or underflows are detected. To avoid repeated scanning of the array A, */
886 /* > an optimal implementation would do all necessary scaling before calling */
887 /* > CGESVD and the scaling in CGESVD can be switched off. */
888 /* > 3. Other comments related to code optimization are given in comments in the */
889 /* > code, enlosed in [[double brackets]]. */
892 /* > \par Bugs, examples and comments */
893 /* =========================== */
896 /* > Please report all bugs and send interesting examples and/or comments to */
897 /* > drmac@math.hr. Thank you. */
900 /* > \par References */
901 /* =============== */
904 /* > [1] Zlatko Drmac, Algorithm 977: A QR-Preconditioned QR SVD Method for */
905 /* > Computing the SVD with High Accuracy. ACM Trans. Math. Softw. */
906 /* > 44(1): 11:1-11:30 (2017) */
908 /* > SIGMA library, xGESVDQ section updated February 2016. */
909 /* > Developed and coded by Zlatko Drmac, Department of Mathematics */
910 /* > University of Zagreb, Croatia, drmac@math.hr */
914 /* > \par Contributors: */
915 /* ================== */
918 /* > Developed and coded by Zlatko Drmac, Department of Mathematics */
919 /* > University of Zagreb, Croatia, drmac@math.hr */
925 /* > \author Univ. of Tennessee */
926 /* > \author Univ. of California Berkeley */
927 /* > \author Univ. of Colorado Denver */
928 /* > \author NAG Ltd. */
930 /* > \date November 2018 */
932 /* > \ingroup realGEsing */
934 /* ===================================================================== */
935 /* Subroutine */ int sgesvdq_(char *joba, char *jobp, char *jobr, char *jobu,
936 char *jobv, integer *m, integer *n, real *a, integer *lda, real *s,
937 real *u, integer *ldu, real *v, integer *ldv, integer *numrank,
938 integer *iwork, integer *liwork, real *work, integer *lwork, real *
939 rwork, integer *lrwork, integer *info)
941 /* System generated locals */
942 integer a_dim1, a_offset, u_dim1, u_offset, v_dim1, v_offset, i__1, i__2;
943 real r__1, r__2, r__3;
945 /* Local variables */
946 integer lwrk_sormlq__, lwrk_sormqr__, ierr, lwrk_sgesvd2__;
948 integer lwrk_sormqr2__, optratio;
950 extern real snrm2_(integer *, real *, integer *);
953 logical acclh, acclm;
956 extern logical lsame_(char *, char *);
957 extern /* Subroutine */ int sscal_(integer *, real *, real *, integer *);
963 integer lwlqf, lwqrf, n1, lwsvd;
964 logical dntwu, dntwv, wntua;
966 logical wntuf, wntva, wntur, wntus, wntvr;
967 extern /* Subroutine */ int sgeqp3_(integer *, integer *, real *, integer
968 *, integer *, real *, real *, integer *, integer *);
969 integer lwsvd2, lworq2, nr;
971 extern real slamch_(char *), slange_(char *, integer *, integer *,
972 real *, integer *, real *);
973 extern /* Subroutine */ int xerbla_(char *, integer *, ftnlen), sgelqf_(
974 integer *, integer *, real *, integer *, real *, real *, integer *
975 , integer *), slascl_(char *, integer *, integer *, real *, real *
976 , integer *, integer *, real *, integer *, integer *);
977 extern integer isamax_(integer *, real *, integer *);
978 extern /* Subroutine */ int sgeqrf_(integer *, integer *, real *, integer
979 *, real *, real *, integer *, integer *), sgesvd_(char *, char *,
980 integer *, integer *, real *, integer *, real *, real *, integer *
981 , real *, integer *, real *, integer *, integer *)
982 , slacpy_(char *, integer *, integer *, real *, integer *, real *,
983 integer *), slaset_(char *, integer *, integer *, real *,
984 real *, real *, integer *), slapmt_(logical *, integer *,
985 integer *, real *, integer *, integer *), spocon_(char *,
986 integer *, real *, integer *, real *, real *, real *, integer *,
990 extern /* Subroutine */ int slaswp_(integer *, real *, integer *, integer
991 *, integer *, integer *, integer *);
993 extern /* Subroutine */ int sormlq_(char *, char *, integer *, integer *,
994 integer *, real *, integer *, real *, real *, integer *, real *,
995 integer *, integer *);
998 extern /* Subroutine */ int sormqr_(char *, char *, integer *, integer *,
999 integer *, real *, integer *, real *, real *, integer *, real *,
1000 integer *, integer *);
1006 integer optwrk2, lwrk_sgeqp3__, iminwrk, rminwrk, lwrk_sgelqf__,
1007 lwrk_sgeqrf__, lwrk_sgesvd__;
1010 /* ===================================================================== */
1013 /* Test the input arguments */
1015 /* Parameter adjustments */
1017 a_offset = 1 + a_dim1 * 1;
1021 u_offset = 1 + u_dim1 * 1;
1024 v_offset = 1 + v_dim1 * 1;
1031 wntus = lsame_(jobu, "S") || lsame_(jobu, "U");
1032 wntur = lsame_(jobu, "R");
1033 wntua = lsame_(jobu, "A");
1034 wntuf = lsame_(jobu, "F");
1035 lsvc0 = wntus || wntur || wntua;
1036 lsvec = lsvc0 || wntuf;
1037 dntwu = lsame_(jobu, "N");
1039 wntvr = lsame_(jobv, "R");
1040 wntva = lsame_(jobv, "A") || lsame_(jobv, "V");
1041 rsvec = wntvr || wntva;
1042 dntwv = lsame_(jobv, "N");
1044 accla = lsame_(joba, "A");
1045 acclm = lsame_(joba, "M");
1046 conda = lsame_(joba, "E");
1047 acclh = lsame_(joba, "H") || conda;
1049 rowprm = lsame_(jobp, "P");
1050 rtrans = lsame_(jobr, "T");
1055 i__1 = 1, i__2 = *n + *m - 1 + *n;
1056 iminwrk = f2cmax(i__1,i__2);
1059 i__1 = 1, i__2 = *n + *m - 1;
1060 iminwrk = f2cmax(i__1,i__2);
1062 rminwrk = f2cmax(2,*m);
1066 i__1 = 1, i__2 = *n + *n;
1067 iminwrk = f2cmax(i__1,i__2);
1069 iminwrk = f2cmax(1,*n);
1073 lquery = *liwork == -1 || *lwork == -1 || *lrwork == -1;
1075 if (! (accla || acclm || acclh)) {
1077 } else if (! (rowprm || lsame_(jobp, "N"))) {
1079 } else if (! (rtrans || lsame_(jobr, "N"))) {
1081 } else if (! (lsvec || dntwu)) {
1083 } else if (wntur && wntva) {
1085 } else if (! (rsvec || dntwv)) {
1087 } else if (*m < 0) {
1089 } else if (*n < 0 || *n > *m) {
1091 } else if (*lda < f2cmax(1,*m)) {
1093 } else if (*ldu < 1 || lsvc0 && *ldu < *m || wntuf && *ldu < *n) {
1095 } else if (*ldv < 1 || rsvec && *ldv < *n || conda && *ldv < *n) {
1097 } else if (*liwork < iminwrk && ! lquery) {
1103 /* [[The expressions for computing the minimal and the optimal */
1104 /* values of LWORK are written with a lot of redundancy and */
1105 /* can be simplified. However, this detailed form is easier for */
1106 /* maintenance and modifications of the code.]] */
1109 if (wntus || wntur) {
1110 lworq = f2cmax(*n,1);
1112 lworq = f2cmax(*m,1);
1117 lwsvd = f2cmax(i__1,1);
1119 sgeqp3_(m, n, &a[a_offset], lda, &iwork[1], rdummy, rdummy, &c_n1,
1121 lwrk_sgeqp3__ = (integer) rdummy[0];
1122 if (wntus || wntur) {
1123 sormqr_("L", "N", m, n, n, &a[a_offset], lda, rdummy, &u[
1124 u_offset], ldu, rdummy, &c_n1, &ierr);
1125 lwrk_sormqr__ = (integer) rdummy[0];
1127 sormqr_("L", "N", m, m, n, &a[a_offset], lda, rdummy, &u[
1128 u_offset], ldu, rdummy, &c_n1, &ierr);
1129 lwrk_sormqr__ = (integer) rdummy[0];
1136 if (! (lsvec || rsvec)) {
1137 /* only the singular values are requested */
1140 i__1 = *n + lwqp3, i__1 = f2cmax(i__1,lwcon);
1141 minwrk = f2cmax(i__1,lwsvd);
1145 minwrk = f2cmax(i__1,lwsvd);
1148 sgesvd_("N", "N", n, n, &a[a_offset], lda, &s[1], &u[u_offset]
1149 , ldu, &v[v_offset], ldv, rdummy, &c_n1, &ierr);
1150 lwrk_sgesvd__ = (integer) rdummy[0];
1153 i__1 = *n + lwrk_sgeqp3__, i__2 = *n + lwcon, i__1 = f2cmax(
1155 optwrk = f2cmax(i__1,lwrk_sgesvd__);
1158 i__1 = *n + lwrk_sgeqp3__;
1159 optwrk = f2cmax(i__1,lwrk_sgesvd__);
1162 } else if (lsvec && ! rsvec) {
1163 /* singular values and the left singular vectors are requested */
1166 i__1 = f2cmax(lwqp3,lwcon), i__1 = f2cmax(i__1,lwsvd);
1167 minwrk = *n + f2cmax(i__1,lworq);
1170 i__1 = f2cmax(lwqp3,lwsvd);
1171 minwrk = *n + f2cmax(i__1,lworq);
1175 sgesvd_("N", "O", n, n, &a[a_offset], lda, &s[1], &u[
1176 u_offset], ldu, &v[v_offset], ldv, rdummy, &c_n1,
1179 sgesvd_("O", "N", n, n, &a[a_offset], lda, &s[1], &u[
1180 u_offset], ldu, &v[v_offset], ldv, rdummy, &c_n1,
1183 lwrk_sgesvd__ = (integer) rdummy[0];
1186 i__1 = f2cmax(lwrk_sgeqp3__,lwcon), i__1 = f2cmax(i__1,
1188 optwrk = *n + f2cmax(i__1,lwrk_sormqr__);
1191 i__1 = f2cmax(lwrk_sgeqp3__,lwrk_sgesvd__);
1192 optwrk = *n + f2cmax(i__1,lwrk_sormqr__);
1195 } else if (rsvec && ! lsvec) {
1196 /* singular values and the right singular vectors are requested */
1199 i__1 = f2cmax(lwqp3,lwcon);
1200 minwrk = *n + f2cmax(i__1,lwsvd);
1202 minwrk = *n + f2cmax(lwqp3,lwsvd);
1206 sgesvd_("O", "N", n, n, &a[a_offset], lda, &s[1], &u[
1207 u_offset], ldu, &v[v_offset], ldv, rdummy, &c_n1,
1210 sgesvd_("N", "O", n, n, &a[a_offset], lda, &s[1], &u[
1211 u_offset], ldu, &v[v_offset], ldv, rdummy, &c_n1,
1214 lwrk_sgesvd__ = (integer) rdummy[0];
1217 i__1 = f2cmax(lwrk_sgeqp3__,lwcon);
1218 optwrk = *n + f2cmax(i__1,lwrk_sgesvd__);
1220 optwrk = *n + f2cmax(lwrk_sgeqp3__,lwrk_sgesvd__);
1224 /* full SVD is requested */
1227 i__1 = f2cmax(lwqp3,lwsvd);
1228 minwrk = f2cmax(i__1,lworq);
1230 minwrk = f2cmax(minwrk,lwcon);
1236 lwqrf = f2cmax(i__1,1);
1239 lwsvd2 = f2cmax(i__1,1);
1240 lworq2 = f2cmax(*n,1);
1242 i__1 = lwqp3, i__2 = *n / 2 + lwqrf, i__1 = f2cmax(i__1,i__2)
1243 , i__2 = *n / 2 + lwsvd2, i__1 = f2cmax(i__1,i__2),
1244 i__2 = *n / 2 + lworq2, i__1 = f2cmax(i__1,i__2);
1245 minwrk2 = f2cmax(i__1,lworq);
1247 minwrk2 = f2cmax(minwrk2,lwcon);
1249 minwrk2 = *n + minwrk2;
1250 minwrk = f2cmax(minwrk,minwrk2);
1254 i__1 = f2cmax(lwqp3,lwsvd);
1255 minwrk = f2cmax(i__1,lworq);
1257 minwrk = f2cmax(minwrk,lwcon);
1263 lwlqf = f2cmax(i__1,1);
1266 lwsvd2 = f2cmax(i__1,1);
1267 lwunlq = f2cmax(*n,1);
1269 i__1 = lwqp3, i__2 = *n / 2 + lwlqf, i__1 = f2cmax(i__1,i__2)
1270 , i__2 = *n / 2 + lwsvd2, i__1 = f2cmax(i__1,i__2),
1271 i__2 = *n / 2 + lwunlq, i__1 = f2cmax(i__1,i__2);
1272 minwrk2 = f2cmax(i__1,lworq);
1274 minwrk2 = f2cmax(minwrk2,lwcon);
1276 minwrk2 = *n + minwrk2;
1277 minwrk = f2cmax(minwrk,minwrk2);
1282 sgesvd_("O", "A", n, n, &a[a_offset], lda, &s[1], &u[
1283 u_offset], ldu, &v[v_offset], ldv, rdummy, &c_n1,
1285 lwrk_sgesvd__ = (integer) rdummy[0];
1287 i__1 = f2cmax(lwrk_sgeqp3__,lwrk_sgesvd__);
1288 optwrk = f2cmax(i__1,lwrk_sormqr__);
1290 optwrk = f2cmax(optwrk,lwcon);
1292 optwrk = *n + optwrk;
1295 sgeqrf_(n, &i__1, &u[u_offset], ldu, rdummy, rdummy, &
1297 lwrk_sgeqrf__ = (integer) rdummy[0];
1300 sgesvd_("S", "O", &i__1, &i__2, &v[v_offset], ldv, &s[
1301 1], &u[u_offset], ldu, &v[v_offset], ldv,
1302 rdummy, &c_n1, &ierr);
1303 lwrk_sgesvd2__ = (integer) rdummy[0];
1305 sormqr_("R", "C", n, n, &i__1, &u[u_offset], ldu,
1306 rdummy, &v[v_offset], ldv, rdummy, &c_n1, &
1308 lwrk_sormqr2__ = (integer) rdummy[0];
1310 i__1 = lwrk_sgeqp3__, i__2 = *n / 2 + lwrk_sgeqrf__,
1311 i__1 = f2cmax(i__1,i__2), i__2 = *n / 2 +
1312 lwrk_sgesvd2__, i__1 = f2cmax(i__1,i__2), i__2 =
1313 *n / 2 + lwrk_sormqr2__;
1314 optwrk2 = f2cmax(i__1,i__2);
1316 optwrk2 = f2cmax(optwrk2,lwcon);
1318 optwrk2 = *n + optwrk2;
1319 optwrk = f2cmax(optwrk,optwrk2);
1322 sgesvd_("S", "O", n, n, &a[a_offset], lda, &s[1], &u[
1323 u_offset], ldu, &v[v_offset], ldv, rdummy, &c_n1,
1325 lwrk_sgesvd__ = (integer) rdummy[0];
1327 i__1 = f2cmax(lwrk_sgeqp3__,lwrk_sgesvd__);
1328 optwrk = f2cmax(i__1,lwrk_sormqr__);
1330 optwrk = f2cmax(optwrk,lwcon);
1332 optwrk = *n + optwrk;
1335 sgelqf_(&i__1, n, &u[u_offset], ldu, rdummy, rdummy, &
1337 lwrk_sgelqf__ = (integer) rdummy[0];
1340 sgesvd_("S", "O", &i__1, &i__2, &v[v_offset], ldv, &s[
1341 1], &u[u_offset], ldu, &v[v_offset], ldv,
1342 rdummy, &c_n1, &ierr);
1343 lwrk_sgesvd2__ = (integer) rdummy[0];
1345 sormlq_("R", "N", n, n, &i__1, &u[u_offset], ldu,
1346 rdummy, &v[v_offset], ldv, rdummy, &c_n1, &
1348 lwrk_sormlq__ = (integer) rdummy[0];
1350 i__1 = lwrk_sgeqp3__, i__2 = *n / 2 + lwrk_sgelqf__,
1351 i__1 = f2cmax(i__1,i__2), i__2 = *n / 2 +
1352 lwrk_sgesvd2__, i__1 = f2cmax(i__1,i__2), i__2 =
1353 *n / 2 + lwrk_sormlq__;
1354 optwrk2 = f2cmax(i__1,i__2);
1356 optwrk2 = f2cmax(optwrk2,lwcon);
1358 optwrk2 = *n + optwrk2;
1359 optwrk = f2cmax(optwrk,optwrk2);
1365 minwrk = f2cmax(2,minwrk);
1366 optwrk = f2cmax(2,optwrk);
1367 if (*lwork < minwrk && ! lquery) {
1373 if (*info == 0 && *lrwork < rminwrk && ! lquery) {
1378 xerbla_("SGESVDQ", &i__1, (ftnlen)7);
1380 } else if (lquery) {
1382 /* Return optimal workspace */
1385 work[1] = (real) optwrk;
1386 work[2] = (real) minwrk;
1387 rwork[1] = (real) rminwrk;
1391 /* Quick return if the matrix is void. */
1393 if (*m == 0 || *n == 0) {
1402 /* ell-infinity norm - this enhances numerical robustness in */
1403 /* the case of differently scaled rows. */
1405 for (p = 1; p <= i__1; ++p) {
1406 /* RWORK(p) = ABS( A(p,ICAMAX(N,A(p,1),LDA)) ) */
1407 /* [[SLANGE will return NaN if an entry of the p-th row is Nan]] */
1408 rwork[p] = slange_("M", &c__1, n, &a[p + a_dim1], lda, rdummy);
1409 if (rwork[p] != rwork[p] || rwork[p] * 0.f != 0.f) {
1412 xerbla_("SGESVDQ", &i__2, (ftnlen)7);
1418 for (p = 1; p <= i__1; ++p) {
1420 q = isamax_(&i__2, &rwork[p], &c__1) + p - 1;
1424 rwork[p] = rwork[q];
1430 if (rwork[1] == 0.f) {
1431 /* Quick return: A is the M x N zero matrix. */
1433 slaset_("G", n, &c__1, &c_b72, &c_b72, &s[1], n);
1435 slaset_("G", m, n, &c_b72, &c_b76, &u[u_offset], ldu);
1438 slaset_("G", m, m, &c_b72, &c_b76, &u[u_offset], ldu);
1441 slaset_("G", n, n, &c_b72, &c_b76, &v[v_offset], ldv);
1444 slaset_("G", n, &c__1, &c_b72, &c_b72, &work[1], n)
1446 slaset_("G", m, n, &c_b72, &c_b76, &u[u_offset], ldu);
1449 for (p = 1; p <= i__1; ++p) {
1455 for (p = *n + 1; p <= i__1; ++p) {
1467 if (rwork[1] > big / sqrt((real) (*m))) {
1468 /* matrix by 1/sqrt(M) if too large entry detected */
1469 r__1 = sqrt((real) (*m));
1470 slascl_("G", &c__0, &c__0, &r__1, &c_b76, m, n, &a[a_offset], lda,
1475 slaswp_(n, &a[a_offset], lda, &c__1, &i__1, &iwork[*n + 1], &c__1);
1478 /* norms overflows during the QR factorization. The SVD procedure should */
1479 /* have its own scaling to save the singular values from overflows and */
1480 /* underflows. That depends on the SVD procedure. */
1483 rtmp = slange_("M", m, n, &a[a_offset], lda, rdummy);
1484 if (rtmp != rtmp || rtmp * 0.f != 0.f) {
1487 xerbla_("SGESVDQ", &i__1, (ftnlen)7);
1490 if (rtmp > big / sqrt((real) (*m))) {
1491 /* matrix by 1/sqrt(M) if too large entry detected */
1492 r__1 = sqrt((real) (*m));
1493 slascl_("G", &c__0, &c__0, &r__1, &c_b76, m, n, &a[a_offset], lda,
1500 /* A * P = Q * [ R ] */
1504 for (p = 1; p <= i__1; ++p) {
1509 sgeqp3_(m, n, &a[a_offset], lda, &iwork[1], &work[1], &work[*n + 1], &
1512 /* If the user requested accuracy level allows truncation in the */
1513 /* computed upper triangular factor, the matrix R is examined and, */
1514 /* if possible, replaced with its leading upper trapezoidal part. */
1516 epsln = slamch_("E");
1517 sfmin = slamch_("S");
1518 /* SMALL = SFMIN / EPSLN */
1523 /* Standard absolute error bound suffices. All sigma_i with */
1524 /* sigma_i < N*EPS*||A||_F are flushed to zero. This is an */
1525 /* aggressive enforcement of lower numerical rank by introducing a */
1526 /* backward error of the order of N*EPS*||A||_F. */
1528 rtmp = sqrt((real) (*n)) * epsln;
1530 for (p = 2; p <= i__1; ++p) {
1531 if ((r__2 = a[p + p * a_dim1], abs(r__2)) < rtmp * (r__1 = a[
1532 a_dim1 + 1], abs(r__1))) {
1542 /* Sudden drop on the diagonal of R is used as the criterion for being */
1543 /* close-to-rank-deficient. The threshold is set to EPSLN=SLAMCH('E'). */
1544 /* [[This can be made more flexible by replacing this hard-coded value */
1545 /* with a user specified threshold.]] Also, the values that underflow */
1546 /* will be truncated. */
1549 for (p = 2; p <= i__1; ++p) {
1550 if ((r__2 = a[p + p * a_dim1], abs(r__2)) < epsln * (r__1 = a[p -
1551 1 + (p - 1) * a_dim1], abs(r__1)) || (r__3 = a[p + p *
1552 a_dim1], abs(r__3)) < sfmin) {
1562 /* obvious case of zero pivots. */
1563 /* R(i,i)=0 => R(i:N,i:N)=0. */
1566 for (p = 2; p <= i__1; ++p) {
1567 if ((r__1 = a[p + p * a_dim1], abs(r__1)) == 0.f) {
1576 /* Estimate the scaled condition number of A. Use the fact that it is */
1577 /* the same as the scaled condition number of R. */
1578 slacpy_("U", n, n, &a[a_offset], lda, &v[v_offset], ldv);
1579 /* Only the leading NR x NR submatrix of the triangular factor */
1580 /* is considered. Only if NR=N will this give a reliable error */
1581 /* bound. However, even for NR < N, this can be used on an */
1582 /* expert level and obtain useful information in the sense of */
1583 /* perturbation theory. */
1585 for (p = 1; p <= i__1; ++p) {
1586 rtmp = snrm2_(&p, &v[p * v_dim1 + 1], &c__1);
1588 sscal_(&p, &r__1, &v[p * v_dim1 + 1], &c__1);
1591 if (! (lsvec || rsvec)) {
1592 spocon_("U", &nr, &v[v_offset], ldv, &c_b76, &rtmp, &work[1],
1593 &iwork[*n + iwoff], &ierr);
1595 spocon_("U", &nr, &v[v_offset], ldv, &c_b76, &rtmp, &work[*n
1596 + 1], &iwork[*n + iwoff], &ierr);
1598 sconda = 1.f / sqrt(rtmp);
1599 /* For NR=N, SCONDA is an estimate of SQRT(||(R^* * R)^(-1)||_1), */
1600 /* N^(-1/4) * SCONDA <= ||R^(-1)||_2 <= N^(1/4) * SCONDA */
1601 /* See the reference [1] for more details. */
1608 } else if (wntus || wntuf) {
1614 if (! (rsvec || lsvec)) {
1615 /* ....................................................................... */
1616 /* ....................................................................... */
1619 /* the upper triangle of [A] to zero. */
1620 i__1 = f2cmin(*n,nr);
1621 for (p = 1; p <= i__1; ++p) {
1623 for (q = p + 1; q <= i__2; ++q) {
1624 a[q + p * a_dim1] = a[p + q * a_dim1];
1626 a[p + q * a_dim1] = 0.f;
1633 sgesvd_("N", "N", n, &nr, &a[a_offset], lda, &s[1], &u[u_offset],
1634 ldu, &v[v_offset], ldv, &work[1], lwork, info);
1642 slaset_("L", &i__1, &i__2, &c_b72, &c_b72, &a[a_dim1 + 2],
1645 sgesvd_("N", "N", &nr, n, &a[a_offset], lda, &s[1], &u[u_offset],
1646 ldu, &v[v_offset], ldv, &work[1], lwork, info);
1650 } else if (lsvec && ! rsvec) {
1651 /* ....................................................................... */
1652 /* ......................................................................."""""""" */
1656 for (p = 1; p <= i__1; ++p) {
1658 for (q = p; q <= i__2; ++q) {
1659 u[q + p * u_dim1] = a[p + q * a_dim1];
1667 slaset_("U", &i__1, &i__2, &c_b72, &c_b72, &u[(u_dim1 << 1) +
1670 /* vectors overwrite [U](1:NR,1:NR) as transposed. These */
1671 /* will be pre-multiplied by Q to build the left singular vectors of A. */
1673 sgesvd_("N", "O", n, &nr, &u[u_offset], ldu, &s[1], &u[u_offset],
1674 ldu, &u[u_offset], ldu, &work[*n + 1], &i__1, info);
1677 for (p = 1; p <= i__1; ++p) {
1679 for (q = p + 1; q <= i__2; ++q) {
1680 rtmp = u[q + p * u_dim1];
1681 u[q + p * u_dim1] = u[p + q * u_dim1];
1682 u[p + q * u_dim1] = rtmp;
1689 slacpy_("U", &nr, n, &a[a_offset], lda, &u[u_offset], ldu);
1693 slaset_("L", &i__1, &i__2, &c_b72, &c_b72, &u[u_dim1 + 2],
1696 /* vectors overwrite [U](1:NR,1:NR) */
1698 sgesvd_("O", "N", &nr, n, &u[u_offset], ldu, &s[1], &u[u_offset],
1699 ldu, &v[v_offset], ldv, &work[*n + 1], &i__1, info);
1700 /* R. These will be pre-multiplied by Q to build the left singular */
1704 /* (M x NR) or (M x N) or (M x M). */
1705 if (nr < *m && ! wntuf) {
1707 slaset_("A", &i__1, &nr, &c_b72, &c_b72, &u[nr + 1 + u_dim1], ldu);
1710 slaset_("A", &nr, &i__1, &c_b72, &c_b72, &u[(nr + 1) * u_dim1
1714 slaset_("A", &i__1, &i__2, &c_b72, &c_b76, &u[nr + 1 + (nr +
1719 /* The Q matrix from the first QRF is built into the left singular */
1720 /* vectors matrix U. */
1724 sormqr_("L", "N", m, &n1, n, &a[a_offset], lda, &work[1], &u[
1725 u_offset], ldu, &work[*n + 1], &i__1, &ierr);
1727 if (rowprm && ! wntuf) {
1729 slaswp_(&n1, &u[u_offset], ldu, &c__1, &i__1, &iwork[*n + 1], &
1733 } else if (rsvec && ! lsvec) {
1734 /* ....................................................................... */
1735 /* ....................................................................... */
1738 for (p = 1; p <= i__1; ++p) {
1740 for (q = p; q <= i__2; ++q) {
1741 v[q + p * v_dim1] = a[p + q * a_dim1];
1749 slaset_("U", &i__1, &i__2, &c_b72, &c_b72, &v[(v_dim1 << 1) +
1752 /* vectors not computed */
1753 if (wntvr || nr == *n) {
1755 sgesvd_("O", "N", n, &nr, &v[v_offset], ldv, &s[1], &u[
1756 u_offset], ldu, &u[u_offset], ldu, &work[*n + 1], &
1760 for (p = 1; p <= i__1; ++p) {
1762 for (q = p + 1; q <= i__2; ++q) {
1763 rtmp = v[q + p * v_dim1];
1764 v[q + p * v_dim1] = v[p + q * v_dim1];
1765 v[p + q * v_dim1] = rtmp;
1773 for (p = 1; p <= i__1; ++p) {
1775 for (q = nr + 1; q <= i__2; ++q) {
1776 v[p + q * v_dim1] = v[q + p * v_dim1];
1782 slapmt_(&c_false, &nr, n, &v[v_offset], ldv, &iwork[1]);
1784 /* [!] This is simple implementation that augments [V](1:N,1:NR) */
1785 /* by padding a zero block. In the case NR << N, a more efficient */
1786 /* way is to first use the QR factorization. For more details */
1787 /* how to implement this, see the " FULL SVD " branch. */
1789 slaset_("G", n, &i__1, &c_b72, &c_b72, &v[(nr + 1) * v_dim1 +
1792 sgesvd_("O", "N", n, n, &v[v_offset], ldv, &s[1], &u[u_offset]
1793 , ldu, &u[u_offset], ldu, &work[*n + 1], &i__1, info);
1796 for (p = 1; p <= i__1; ++p) {
1798 for (q = p + 1; q <= i__2; ++q) {
1799 rtmp = v[q + p * v_dim1];
1800 v[q + p * v_dim1] = v[p + q * v_dim1];
1801 v[p + q * v_dim1] = rtmp;
1806 slapmt_(&c_false, n, n, &v[v_offset], ldv, &iwork[1]);
1810 slacpy_("U", &nr, n, &a[a_offset], lda, &v[v_offset], ldv);
1814 slaset_("L", &i__1, &i__2, &c_b72, &c_b72, &v[v_dim1 + 2],
1817 /* vectors stored in U(1:NR,1:NR) */
1818 if (wntvr || nr == *n) {
1820 sgesvd_("N", "O", &nr, n, &v[v_offset], ldv, &s[1], &u[
1821 u_offset], ldu, &v[v_offset], ldv, &work[*n + 1], &
1823 slapmt_(&c_false, &nr, n, &v[v_offset], ldv, &iwork[1]);
1825 /* [!] This is simple implementation that augments [V](1:NR,1:N) */
1826 /* by padding a zero block. In the case NR << N, a more efficient */
1827 /* way is to first use the LQ factorization. For more details */
1828 /* how to implement this, see the " FULL SVD " branch. */
1830 slaset_("G", &i__1, n, &c_b72, &c_b72, &v[nr + 1 + v_dim1],
1833 sgesvd_("N", "O", n, n, &v[v_offset], ldv, &s[1], &u[u_offset]
1834 , ldu, &v[v_offset], ldv, &work[*n + 1], &i__1, info);
1835 slapmt_(&c_false, n, n, &v[v_offset], ldv, &iwork[1]);
1841 /* ....................................................................... */
1842 /* ....................................................................... */
1846 if (wntvr || nr == *n) {
1847 /* vectors of R**T */
1849 for (p = 1; p <= i__1; ++p) {
1851 for (q = p; q <= i__2; ++q) {
1852 v[q + p * v_dim1] = a[p + q * a_dim1];
1860 slaset_("U", &i__1, &i__2, &c_b72, &c_b72, &v[(v_dim1 <<
1864 /* singular vectors of R**T stored in [U](1:NR,1:NR) as transposed */
1866 sgesvd_("O", "A", n, &nr, &v[v_offset], ldv, &s[1], &v[
1867 v_offset], ldv, &u[u_offset], ldu, &work[*n + 1], &
1870 for (p = 1; p <= i__1; ++p) {
1872 for (q = p + 1; q <= i__2; ++q) {
1873 rtmp = v[q + p * v_dim1];
1874 v[q + p * v_dim1] = v[p + q * v_dim1];
1875 v[p + q * v_dim1] = rtmp;
1882 for (p = 1; p <= i__1; ++p) {
1884 for (q = nr + 1; q <= i__2; ++q) {
1885 v[p + q * v_dim1] = v[q + p * v_dim1];
1891 slapmt_(&c_false, &nr, n, &v[v_offset], ldv, &iwork[1]);
1894 for (p = 1; p <= i__1; ++p) {
1896 for (q = p + 1; q <= i__2; ++q) {
1897 rtmp = u[q + p * u_dim1];
1898 u[q + p * u_dim1] = u[p + q * u_dim1];
1899 u[p + q * u_dim1] = rtmp;
1905 if (nr < *m && ! wntuf) {
1907 slaset_("A", &i__1, &nr, &c_b72, &c_b72, &u[nr + 1 +
1911 slaset_("A", &nr, &i__1, &c_b72, &c_b72, &u[(nr + 1) *
1915 slaset_("A", &i__1, &i__2, &c_b72, &c_b76, &u[nr + 1
1916 + (nr + 1) * u_dim1], ldu);
1921 /* vectors of R**T */
1922 /* [[The optimal ratio N/NR for using QRF instead of padding */
1923 /* with zeros. Here hard coded to 2; it must be at least */
1924 /* two due to work space constraints.]] */
1925 /* OPTRATIO = ILAENV(6, 'SGESVD', 'S' // 'O', NR,N,0,0) */
1926 /* OPTRATIO = MAX( OPTRATIO, 2 ) */
1928 if (optratio * nr > *n) {
1930 for (p = 1; p <= i__1; ++p) {
1932 for (q = p; q <= i__2; ++q) {
1933 v[q + p * v_dim1] = a[p + q * a_dim1];
1941 slaset_("U", &i__1, &i__2, &c_b72, &c_b72, &v[(v_dim1
1946 slaset_("A", n, &i__1, &c_b72, &c_b72, &v[(nr + 1) *
1949 sgesvd_("O", "A", n, n, &v[v_offset], ldv, &s[1], &v[
1950 v_offset], ldv, &u[u_offset], ldu, &work[*n + 1],
1954 for (p = 1; p <= i__1; ++p) {
1956 for (q = p + 1; q <= i__2; ++q) {
1957 rtmp = v[q + p * v_dim1];
1958 v[q + p * v_dim1] = v[p + q * v_dim1];
1959 v[p + q * v_dim1] = rtmp;
1964 slapmt_(&c_false, n, n, &v[v_offset], ldv, &iwork[1]);
1965 /* (M x N1), i.e. (M x N) or (M x M). */
1968 for (p = 1; p <= i__1; ++p) {
1970 for (q = p + 1; q <= i__2; ++q) {
1971 rtmp = u[q + p * u_dim1];
1972 u[q + p * u_dim1] = u[p + q * u_dim1];
1973 u[p + q * u_dim1] = rtmp;
1979 if (*n < *m && ! wntuf) {
1981 slaset_("A", &i__1, n, &c_b72, &c_b72, &u[*n + 1 +
1985 slaset_("A", n, &i__1, &c_b72, &c_b72, &u[(*n + 1)
1986 * u_dim1 + 1], ldu);
1989 slaset_("A", &i__1, &i__2, &c_b72, &c_b76, &u[*n
1990 + 1 + (*n + 1) * u_dim1], ldu);
1994 /* singular vectors of R */
1996 for (p = 1; p <= i__1; ++p) {
1998 for (q = p; q <= i__2; ++q) {
1999 u[q + (nr + p) * u_dim1] = a[p + q * a_dim1];
2007 slaset_("U", &i__1, &i__2, &c_b72, &c_b72, &u[(nr + 2)
2008 * u_dim1 + 1], ldu);
2010 i__1 = *lwork - *n - nr;
2011 sgeqrf_(n, &nr, &u[(nr + 1) * u_dim1 + 1], ldu, &work[*n
2012 + 1], &work[*n + nr + 1], &i__1, &ierr);
2014 for (p = 1; p <= i__1; ++p) {
2016 for (q = 1; q <= i__2; ++q) {
2017 v[q + p * v_dim1] = u[p + (nr + q) * u_dim1];
2024 slaset_("U", &i__1, &i__2, &c_b72, &c_b72, &v[(v_dim1 <<
2026 i__1 = *lwork - *n - nr;
2027 sgesvd_("S", "O", &nr, &nr, &v[v_offset], ldv, &s[1], &u[
2028 u_offset], ldu, &v[v_offset], ldv, &work[*n + nr
2031 slaset_("A", &i__1, &nr, &c_b72, &c_b72, &v[nr + 1 +
2034 slaset_("A", &nr, &i__1, &c_b72, &c_b72, &v[(nr + 1) *
2038 slaset_("A", &i__1, &i__2, &c_b72, &c_b76, &v[nr + 1 + (
2039 nr + 1) * v_dim1], ldv);
2040 i__1 = *lwork - *n - nr;
2041 sormqr_("R", "C", n, n, &nr, &u[(nr + 1) * u_dim1 + 1],
2042 ldu, &work[*n + 1], &v[v_offset], ldv, &work[*n +
2043 nr + 1], &i__1, &ierr);
2044 slapmt_(&c_false, n, n, &v[v_offset], ldv, &iwork[1]);
2045 /* (M x NR) or (M x N) or (M x M). */
2046 if (nr < *m && ! wntuf) {
2048 slaset_("A", &i__1, &nr, &c_b72, &c_b72, &u[nr + 1 +
2052 slaset_("A", &nr, &i__1, &c_b72, &c_b72, &u[(nr +
2053 1) * u_dim1 + 1], ldu);
2056 slaset_("A", &i__1, &i__2, &c_b72, &c_b76, &u[nr
2057 + 1 + (nr + 1) * u_dim1], ldu);
2066 if (wntvr || nr == *n) {
2067 slacpy_("U", &nr, n, &a[a_offset], lda, &v[v_offset], ldv);
2071 slaset_("L", &i__1, &i__2, &c_b72, &c_b72, &v[v_dim1 + 2],
2074 /* singular vectors of R stored in [U](1:NR,1:NR) */
2076 sgesvd_("S", "O", &nr, n, &v[v_offset], ldv, &s[1], &u[
2077 u_offset], ldu, &v[v_offset], ldv, &work[*n + 1], &
2079 slapmt_(&c_false, &nr, n, &v[v_offset], ldv, &iwork[1]);
2080 /* (M x NR) or (M x N) or (M x M). */
2081 if (nr < *m && ! wntuf) {
2083 slaset_("A", &i__1, &nr, &c_b72, &c_b72, &u[nr + 1 +
2087 slaset_("A", &nr, &i__1, &c_b72, &c_b72, &u[(nr + 1) *
2091 slaset_("A", &i__1, &i__2, &c_b72, &c_b76, &u[nr + 1
2092 + (nr + 1) * u_dim1], ldu);
2097 /* is then N1 (N or M) */
2098 /* [[The optimal ratio N/NR for using LQ instead of padding */
2099 /* with zeros. Here hard coded to 2; it must be at least */
2100 /* two due to work space constraints.]] */
2101 /* OPTRATIO = ILAENV(6, 'SGESVD', 'S' // 'O', NR,N,0,0) */
2102 /* OPTRATIO = MAX( OPTRATIO, 2 ) */
2104 if (optratio * nr > *n) {
2105 slacpy_("U", &nr, n, &a[a_offset], lda, &v[v_offset], ldv);
2109 slaset_("L", &i__1, &i__2, &c_b72, &c_b72, &v[v_dim1
2112 /* singular vectors of R stored in [U](1:NR,1:NR) */
2114 slaset_("A", &i__1, n, &c_b72, &c_b72, &v[nr + 1 + v_dim1]
2117 sgesvd_("S", "O", n, n, &v[v_offset], ldv, &s[1], &u[
2118 u_offset], ldu, &v[v_offset], ldv, &work[*n + 1],
2120 slapmt_(&c_false, n, n, &v[v_offset], ldv, &iwork[1]);
2121 /* singular vectors of A. The leading N left singular vectors */
2122 /* are in [U](1:N,1:N) */
2123 /* (M x N1), i.e. (M x N) or (M x M). */
2124 if (*n < *m && ! wntuf) {
2126 slaset_("A", &i__1, n, &c_b72, &c_b72, &u[*n + 1 +
2130 slaset_("A", n, &i__1, &c_b72, &c_b72, &u[(*n + 1)
2131 * u_dim1 + 1], ldu);
2134 slaset_("A", &i__1, &i__2, &c_b72, &c_b76, &u[*n
2135 + 1 + (*n + 1) * u_dim1], ldu);
2139 slacpy_("U", &nr, n, &a[a_offset], lda, &u[nr + 1 +
2144 slaset_("L", &i__1, &i__2, &c_b72, &c_b72, &u[nr + 2
2147 i__1 = *lwork - *n - nr;
2148 sgelqf_(&nr, n, &u[nr + 1 + u_dim1], ldu, &work[*n + 1], &
2149 work[*n + nr + 1], &i__1, &ierr);
2150 slacpy_("L", &nr, &nr, &u[nr + 1 + u_dim1], ldu, &v[
2155 slaset_("U", &i__1, &i__2, &c_b72, &c_b72, &v[(v_dim1
2158 i__1 = *lwork - *n - nr;
2159 sgesvd_("S", "O", &nr, &nr, &v[v_offset], ldv, &s[1], &u[
2160 u_offset], ldu, &v[v_offset], ldv, &work[*n + nr
2163 slaset_("A", &i__1, &nr, &c_b72, &c_b72, &v[nr + 1 +
2166 slaset_("A", &nr, &i__1, &c_b72, &c_b72, &v[(nr + 1) *
2170 slaset_("A", &i__1, &i__2, &c_b72, &c_b76, &v[nr + 1 + (
2171 nr + 1) * v_dim1], ldv);
2172 i__1 = *lwork - *n - nr;
2173 sormlq_("R", "N", n, n, &nr, &u[nr + 1 + u_dim1], ldu, &
2174 work[*n + 1], &v[v_offset], ldv, &work[*n + nr +
2176 slapmt_(&c_false, n, n, &v[v_offset], ldv, &iwork[1]);
2177 /* (M x NR) or (M x N) or (M x M). */
2178 if (nr < *m && ! wntuf) {
2180 slaset_("A", &i__1, &nr, &c_b72, &c_b72, &u[nr + 1 +
2184 slaset_("A", &nr, &i__1, &c_b72, &c_b72, &u[(nr +
2185 1) * u_dim1 + 1], ldu);
2188 slaset_("A", &i__1, &i__2, &c_b72, &c_b76, &u[nr
2189 + 1 + (nr + 1) * u_dim1], ldu);
2196 /* The Q matrix from the first QRF is built into the left singular */
2197 /* vectors matrix U. */
2201 sormqr_("L", "N", m, &n1, n, &a[a_offset], lda, &work[1], &u[
2202 u_offset], ldu, &work[*n + 1], &i__1, &ierr);
2204 if (rowprm && ! wntuf) {
2206 slaswp_(&n1, &u[u_offset], ldu, &c__1, &i__1, &iwork[*n + 1], &
2210 /* ... end of the "full SVD" branch */
2213 /* Check whether some singular values are returned as zeros, e.g. */
2214 /* due to underflow, and update the numerical rank. */
2216 for (q = p; q >= 1; --q) {
2225 /* singular values are set to zero. */
2228 slaset_("G", &i__1, &c__1, &c_b72, &c_b72, &s[nr + 1], n);
2232 r__1 = sqrt((real) (*m));
2233 slascl_("G", &c__0, &c__0, &c_b76, &r__1, &nr, &c__1, &s[1], n, &ierr);
2238 rwork[2] = (real) (p - nr);
2239 /* exact zeros in SGESVD() applied to the (possibly truncated) */
2240 /* full row rank triangular (trapezoidal) factor of A. */
2245 /* End of SGESVDQ */