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 doublereal c_b72 = 0.;
518 static doublereal c_b76 = 1.;
519 static integer c__0 = 0;
520 static logical c_false = FALSE_;
522 /* > \brief <b> DGESVDQ 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 DGESVDQ + dependencies */
532 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dgesvdq
535 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dgesvdq
538 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dgesvdq
546 /* SUBROUTINE DGESVDQ( 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 /* DOUBLE PRECISION A( LDA, * ), U( LDU, * ), V( LDV, * ), WORK( * ) */
555 /* DOUBLE PRECISION S( * ), RWORK( * ) */
556 /* INTEGER IWORK( * ) */
559 /* > \par Purpose: */
564 /* > DGESVDQ 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 = DLAMCH('Epsilon'). This authorises DGESVDQ 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, DGESVD 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 DGESVD. 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 DOUBLE PRECISION 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 DGEQP3. 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 DOUBLE PRECISION 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 DOUBLE PRECISION 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 DOUBLE PRECISION 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 DGESVD. 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 DOUBLE PRECISION 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 DOUBLE PRECISION 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 DGESVD applied to the upper triangular or trapeziodal */
842 /* > R (from the initial QR factorization). In case of early exit (no call to */
843 /* > DGESVD, 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 DBDSQR did not converge, INFO specifies how many superdiagonals */
868 /* > of an intermediate bidiagonal form B (computed in DGESVD) 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 doubleGEsing */
934 /* ===================================================================== */
935 /* Subroutine */ int dgesvdq_(char *joba, char *jobp, char *jobr, char *jobu,
936 char *jobv, integer *m, integer *n, doublereal *a, integer *lda,
937 doublereal *s, doublereal *u, integer *ldu, doublereal *v, integer *
938 ldv, integer *numrank, integer *iwork, integer *liwork, doublereal *
939 work, integer *lwork, doublereal *rwork, integer *lrwork, integer *
942 /* System generated locals */
943 integer a_dim1, a_offset, u_dim1, u_offset, v_dim1, v_offset, i__1, i__2;
944 doublereal d__1, d__2, d__3;
946 /* Local variables */
947 integer lwrk_dormqr__, lwrk_dgesvd2__, ierr, lwrk_dormqr2__;
950 extern doublereal dnrm2_(integer *, doublereal *, integer *);
951 logical lsvc0, accla;
953 logical acclh, acclm;
956 extern /* Subroutine */ int dscal_(integer *, doublereal *, doublereal *,
958 extern logical lsame_(char *, char *);
961 doublereal sfmin, epsln;
964 integer lwlqf, lwqrf, n1, lwsvd;
965 logical dntwu, dntwv, wntua;
967 logical wntuf, wntva, wntur, wntus, wntvr;
968 extern /* Subroutine */ int dgeqp3_(integer *, integer *, doublereal *,
969 integer *, integer *, doublereal *, doublereal *, integer *,
971 integer lwsvd2, lworq2;
972 extern doublereal dlamch_(char *), dlange_(char *, integer *,
973 integer *, doublereal *, integer *, doublereal *);
975 extern /* Subroutine */ int dgelqf_(integer *, integer *, doublereal *,
976 integer *, doublereal *, doublereal *, integer *, integer *),
977 dlascl_(char *, integer *, integer *, doublereal *, doublereal *,
978 integer *, integer *, doublereal *, integer *, integer *);
979 extern integer idamax_(integer *, doublereal *, integer *);
981 extern /* Subroutine */ int dgeqrf_(integer *, integer *, doublereal *,
982 integer *, doublereal *, doublereal *, integer *, integer *),
983 dgesvd_(char *, char *, integer *, integer *, doublereal *,
984 integer *, doublereal *, doublereal *, integer *, doublereal *,
985 integer *, doublereal *, integer *, integer *),
986 dlacpy_(char *, integer *, integer *, doublereal *, integer *,
987 doublereal *, integer *), dlaset_(char *, integer *,
988 integer *, doublereal *, doublereal *, doublereal *, integer *), xerbla_(char *, integer *, ftnlen), dlapmt_(logical *,
989 integer *, integer *, doublereal *, integer *, integer *),
990 dpocon_(char *, integer *, doublereal *, integer *, doublereal *,
991 doublereal *, doublereal *, integer *, integer *),
992 dlaswp_(integer *, doublereal *, integer *, integer *, integer *,
993 integer *, integer *), dormlq_(char *, char *, integer *, integer
994 *, integer *, doublereal *, integer *, doublereal *, doublereal *,
995 integer *, doublereal *, integer *, integer *),
996 dormqr_(char *, char *, integer *, integer *, integer *,
997 doublereal *, integer *, doublereal *, doublereal *, integer *,
998 doublereal *, integer *, integer *);
1001 doublereal rdummy[1];
1009 integer lwrk_dgeqp3__, optwrk2, lwrk_dgelqf__, iminwrk, lwrk_dgeqrf__,
1010 rminwrk, lwrk_dgesvd__, lwrk_dormlq__;
1013 /* ===================================================================== */
1017 /* Test the input arguments */
1019 /* Parameter adjustments */
1021 a_offset = 1 + a_dim1 * 1;
1025 u_offset = 1 + u_dim1 * 1;
1028 v_offset = 1 + v_dim1 * 1;
1035 wntus = lsame_(jobu, "S") || lsame_(jobu, "U");
1036 wntur = lsame_(jobu, "R");
1037 wntua = lsame_(jobu, "A");
1038 wntuf = lsame_(jobu, "F");
1039 lsvc0 = wntus || wntur || wntua;
1040 lsvec = lsvc0 || wntuf;
1041 dntwu = lsame_(jobu, "N");
1043 wntvr = lsame_(jobv, "R");
1044 wntva = lsame_(jobv, "A") || lsame_(jobv, "V");
1045 rsvec = wntvr || wntva;
1046 dntwv = lsame_(jobv, "N");
1048 accla = lsame_(joba, "A");
1049 acclm = lsame_(joba, "M");
1050 conda = lsame_(joba, "E");
1051 acclh = lsame_(joba, "H") || conda;
1053 rowprm = lsame_(jobp, "P");
1054 rtrans = lsame_(jobr, "T");
1059 i__1 = 1, i__2 = *n + *m - 1 + *n;
1060 iminwrk = f2cmax(i__1,i__2);
1063 i__1 = 1, i__2 = *n + *m - 1;
1064 iminwrk = f2cmax(i__1,i__2);
1066 rminwrk = f2cmax(2,*m);
1070 i__1 = 1, i__2 = *n + *n;
1071 iminwrk = f2cmax(i__1,i__2);
1073 iminwrk = f2cmax(1,*n);
1077 lquery = *liwork == -1 || *lwork == -1 || *lrwork == -1;
1079 if (! (accla || acclm || acclh)) {
1081 } else if (! (rowprm || lsame_(jobp, "N"))) {
1083 } else if (! (rtrans || lsame_(jobr, "N"))) {
1085 } else if (! (lsvec || dntwu)) {
1087 } else if (wntur && wntva) {
1089 } else if (! (rsvec || dntwv)) {
1091 } else if (*m < 0) {
1093 } else if (*n < 0 || *n > *m) {
1095 } else if (*lda < f2cmax(1,*m)) {
1097 } else if (*ldu < 1 || lsvc0 && *ldu < *m || wntuf && *ldu < *n) {
1099 } else if (*ldv < 1 || rsvec && *ldv < *n || conda && *ldv < *n) {
1101 } else if (*liwork < iminwrk && ! lquery) {
1107 /* [[The expressions for computing the minimal and the optimal */
1108 /* values of LWORK are written with a lot of redundancy and */
1109 /* can be simplified. However, this detailed form is easier for */
1110 /* maintenance and modifications of the code.]] */
1113 if (wntus || wntur) {
1114 lworq = f2cmax(*n,1);
1116 lworq = f2cmax(*m,1);
1121 lwsvd = f2cmax(i__1,1);
1123 dgeqp3_(m, n, &a[a_offset], lda, &iwork[1], rdummy, rdummy, &c_n1,
1125 lwrk_dgeqp3__ = (integer) rdummy[0];
1126 if (wntus || wntur) {
1127 dormqr_("L", "N", m, n, n, &a[a_offset], lda, rdummy, &u[
1128 u_offset], ldu, rdummy, &c_n1, &ierr);
1129 lwrk_dormqr__ = (integer) rdummy[0];
1131 dormqr_("L", "N", m, m, n, &a[a_offset], lda, rdummy, &u[
1132 u_offset], ldu, rdummy, &c_n1, &ierr);
1133 lwrk_dormqr__ = (integer) rdummy[0];
1140 if (! (lsvec || rsvec)) {
1141 /* only the singular values are requested */
1144 i__1 = *n + lwqp3, i__1 = f2cmax(i__1,lwcon);
1145 minwrk = f2cmax(i__1,lwsvd);
1149 minwrk = f2cmax(i__1,lwsvd);
1152 dgesvd_("N", "N", n, n, &a[a_offset], lda, &s[1], &u[u_offset]
1153 , ldu, &v[v_offset], ldv, rdummy, &c_n1, &ierr);
1154 lwrk_dgesvd__ = (integer) rdummy[0];
1157 i__1 = *n + lwrk_dgeqp3__, i__2 = *n + lwcon, i__1 = f2cmax(
1159 optwrk = f2cmax(i__1,lwrk_dgesvd__);
1162 i__1 = *n + lwrk_dgeqp3__;
1163 optwrk = f2cmax(i__1,lwrk_dgesvd__);
1166 } else if (lsvec && ! rsvec) {
1167 /* singular values and the left singular vectors are requested */
1170 i__1 = f2cmax(lwqp3,lwcon), i__1 = f2cmax(i__1,lwsvd);
1171 minwrk = *n + f2cmax(i__1,lworq);
1174 i__1 = f2cmax(lwqp3,lwsvd);
1175 minwrk = *n + f2cmax(i__1,lworq);
1179 dgesvd_("N", "O", n, n, &a[a_offset], lda, &s[1], &u[
1180 u_offset], ldu, &v[v_offset], ldv, rdummy, &c_n1,
1183 dgesvd_("O", "N", n, n, &a[a_offset], lda, &s[1], &u[
1184 u_offset], ldu, &v[v_offset], ldv, rdummy, &c_n1,
1187 lwrk_dgesvd__ = (integer) rdummy[0];
1190 i__1 = f2cmax(lwrk_dgeqp3__,lwcon), i__1 = f2cmax(i__1,
1192 optwrk = *n + f2cmax(i__1,lwrk_dormqr__);
1195 i__1 = f2cmax(lwrk_dgeqp3__,lwrk_dgesvd__);
1196 optwrk = *n + f2cmax(i__1,lwrk_dormqr__);
1199 } else if (rsvec && ! lsvec) {
1200 /* singular values and the right singular vectors are requested */
1203 i__1 = f2cmax(lwqp3,lwcon);
1204 minwrk = *n + f2cmax(i__1,lwsvd);
1206 minwrk = *n + f2cmax(lwqp3,lwsvd);
1210 dgesvd_("O", "N", n, n, &a[a_offset], lda, &s[1], &u[
1211 u_offset], ldu, &v[v_offset], ldv, rdummy, &c_n1,
1214 dgesvd_("N", "O", n, n, &a[a_offset], lda, &s[1], &u[
1215 u_offset], ldu, &v[v_offset], ldv, rdummy, &c_n1,
1218 lwrk_dgesvd__ = (integer) rdummy[0];
1221 i__1 = f2cmax(lwrk_dgeqp3__,lwcon);
1222 optwrk = *n + f2cmax(i__1,lwrk_dgesvd__);
1224 optwrk = *n + f2cmax(lwrk_dgeqp3__,lwrk_dgesvd__);
1228 /* full SVD is requested */
1231 i__1 = f2cmax(lwqp3,lwsvd);
1232 minwrk = f2cmax(i__1,lworq);
1234 minwrk = f2cmax(minwrk,lwcon);
1240 lwqrf = f2cmax(i__1,1);
1243 lwsvd2 = f2cmax(i__1,1);
1244 lworq2 = f2cmax(*n,1);
1246 i__1 = lwqp3, i__2 = *n / 2 + lwqrf, i__1 = f2cmax(i__1,i__2)
1247 , i__2 = *n / 2 + lwsvd2, i__1 = f2cmax(i__1,i__2),
1248 i__2 = *n / 2 + lworq2, i__1 = f2cmax(i__1,i__2);
1249 minwrk2 = f2cmax(i__1,lworq);
1251 minwrk2 = f2cmax(minwrk2,lwcon);
1253 minwrk2 = *n + minwrk2;
1254 minwrk = f2cmax(minwrk,minwrk2);
1258 i__1 = f2cmax(lwqp3,lwsvd);
1259 minwrk = f2cmax(i__1,lworq);
1261 minwrk = f2cmax(minwrk,lwcon);
1267 lwlqf = f2cmax(i__1,1);
1270 lwsvd2 = f2cmax(i__1,1);
1271 lworlq = f2cmax(*n,1);
1273 i__1 = lwqp3, i__2 = *n / 2 + lwlqf, i__1 = f2cmax(i__1,i__2)
1274 , i__2 = *n / 2 + lwsvd2, i__1 = f2cmax(i__1,i__2),
1275 i__2 = *n / 2 + lworlq, i__1 = f2cmax(i__1,i__2);
1276 minwrk2 = f2cmax(i__1,lworq);
1278 minwrk2 = f2cmax(minwrk2,lwcon);
1280 minwrk2 = *n + minwrk2;
1281 minwrk = f2cmax(minwrk,minwrk2);
1286 dgesvd_("O", "A", n, n, &a[a_offset], lda, &s[1], &u[
1287 u_offset], ldu, &v[v_offset], ldv, rdummy, &c_n1,
1289 lwrk_dgesvd__ = (integer) rdummy[0];
1291 i__1 = f2cmax(lwrk_dgeqp3__,lwrk_dgesvd__);
1292 optwrk = f2cmax(i__1,lwrk_dormqr__);
1294 optwrk = f2cmax(optwrk,lwcon);
1296 optwrk = *n + optwrk;
1299 dgeqrf_(n, &i__1, &u[u_offset], ldu, rdummy, rdummy, &
1301 lwrk_dgeqrf__ = (integer) rdummy[0];
1304 dgesvd_("S", "O", &i__1, &i__2, &v[v_offset], ldv, &s[
1305 1], &u[u_offset], ldu, &v[v_offset], ldv,
1306 rdummy, &c_n1, &ierr);
1307 lwrk_dgesvd2__ = (integer) rdummy[0];
1309 dormqr_("R", "C", n, n, &i__1, &u[u_offset], ldu,
1310 rdummy, &v[v_offset], ldv, rdummy, &c_n1, &
1312 lwrk_dormqr2__ = (integer) rdummy[0];
1314 i__1 = lwrk_dgeqp3__, i__2 = *n / 2 + lwrk_dgeqrf__,
1315 i__1 = f2cmax(i__1,i__2), i__2 = *n / 2 +
1316 lwrk_dgesvd2__, i__1 = f2cmax(i__1,i__2), i__2 =
1317 *n / 2 + lwrk_dormqr2__;
1318 optwrk2 = f2cmax(i__1,i__2);
1320 optwrk2 = f2cmax(optwrk2,lwcon);
1322 optwrk2 = *n + optwrk2;
1323 optwrk = f2cmax(optwrk,optwrk2);
1326 dgesvd_("S", "O", n, n, &a[a_offset], lda, &s[1], &u[
1327 u_offset], ldu, &v[v_offset], ldv, rdummy, &c_n1,
1329 lwrk_dgesvd__ = (integer) rdummy[0];
1331 i__1 = f2cmax(lwrk_dgeqp3__,lwrk_dgesvd__);
1332 optwrk = f2cmax(i__1,lwrk_dormqr__);
1334 optwrk = f2cmax(optwrk,lwcon);
1336 optwrk = *n + optwrk;
1339 dgelqf_(&i__1, n, &u[u_offset], ldu, rdummy, rdummy, &
1341 lwrk_dgelqf__ = (integer) rdummy[0];
1344 dgesvd_("S", "O", &i__1, &i__2, &v[v_offset], ldv, &s[
1345 1], &u[u_offset], ldu, &v[v_offset], ldv,
1346 rdummy, &c_n1, &ierr);
1347 lwrk_dgesvd2__ = (integer) rdummy[0];
1349 dormlq_("R", "N", n, n, &i__1, &u[u_offset], ldu,
1350 rdummy, &v[v_offset], ldv, rdummy, &c_n1, &
1352 lwrk_dormlq__ = (integer) rdummy[0];
1354 i__1 = lwrk_dgeqp3__, i__2 = *n / 2 + lwrk_dgelqf__,
1355 i__1 = f2cmax(i__1,i__2), i__2 = *n / 2 +
1356 lwrk_dgesvd2__, i__1 = f2cmax(i__1,i__2), i__2 =
1357 *n / 2 + lwrk_dormlq__;
1358 optwrk2 = f2cmax(i__1,i__2);
1360 optwrk2 = f2cmax(optwrk2,lwcon);
1362 optwrk2 = *n + optwrk2;
1363 optwrk = f2cmax(optwrk,optwrk2);
1369 minwrk = f2cmax(2,minwrk);
1370 optwrk = f2cmax(2,optwrk);
1371 if (*lwork < minwrk && ! lquery) {
1377 if (*info == 0 && *lrwork < rminwrk && ! lquery) {
1382 xerbla_("DGESVDQ", &i__1, (ftnlen)7);
1384 } else if (lquery) {
1386 /* Return optimal workspace */
1389 work[1] = (doublereal) optwrk;
1390 work[2] = (doublereal) minwrk;
1391 rwork[1] = (doublereal) rminwrk;
1395 /* Quick return if the matrix is void. */
1397 if (*m == 0 || *n == 0) {
1406 /* ell-infinity norm - this enhances numerical robustness in */
1407 /* the case of differently scaled rows. */
1409 for (p = 1; p <= i__1; ++p) {
1410 /* RWORK(p) = ABS( A(p,ICAMAX(N,A(p,1),LDA)) ) */
1411 /* [[DLANGE will return NaN if an entry of the p-th row is Nan]] */
1412 rwork[p] = dlange_("M", &c__1, n, &a[p + a_dim1], lda, rdummy);
1413 if (rwork[p] != rwork[p] || rwork[p] * 0. != 0.) {
1416 xerbla_("DGESVDQ", &i__2, (ftnlen)7);
1422 for (p = 1; p <= i__1; ++p) {
1424 q = idamax_(&i__2, &rwork[p], &c__1) + p - 1;
1428 rwork[p] = rwork[q];
1434 if (rwork[1] == 0.) {
1435 /* Quick return: A is the M x N zero matrix. */
1437 dlaset_("G", n, &c__1, &c_b72, &c_b72, &s[1], n);
1439 dlaset_("G", m, n, &c_b72, &c_b76, &u[u_offset], ldu);
1442 dlaset_("G", m, m, &c_b72, &c_b76, &u[u_offset], ldu);
1445 dlaset_("G", n, n, &c_b72, &c_b76, &v[v_offset], ldv);
1448 dlaset_("G", n, &c__1, &c_b72, &c_b72, &work[1], n)
1450 dlaset_("G", m, n, &c_b72, &c_b76, &u[u_offset], ldu);
1453 for (p = 1; p <= i__1; ++p) {
1459 for (p = *n + 1; p <= i__1; ++p) {
1471 if (rwork[1] > big / sqrt((doublereal) (*m))) {
1472 /* matrix by 1/sqrt(M) if too large entry detected */
1473 d__1 = sqrt((doublereal) (*m));
1474 dlascl_("G", &c__0, &c__0, &d__1, &c_b76, m, n, &a[a_offset], lda,
1479 dlaswp_(n, &a[a_offset], lda, &c__1, &i__1, &iwork[*n + 1], &c__1);
1482 /* norms overflows during the QR factorization. The SVD procedure should */
1483 /* have its own scaling to save the singular values from overflows and */
1484 /* underflows. That depends on the SVD procedure. */
1487 rtmp = dlange_("M", m, n, &a[a_offset], lda, rdummy);
1488 if (rtmp != rtmp || rtmp * 0. != 0.) {
1491 xerbla_("DGESVDQ", &i__1, (ftnlen)7);
1494 if (rtmp > big / sqrt((doublereal) (*m))) {
1495 /* matrix by 1/sqrt(M) if too large entry detected */
1496 d__1 = sqrt((doublereal) (*m));
1497 dlascl_("G", &c__0, &c__0, &d__1, &c_b76, m, n, &a[a_offset], lda,
1504 /* A * P = Q * [ R ] */
1508 for (p = 1; p <= i__1; ++p) {
1513 dgeqp3_(m, n, &a[a_offset], lda, &iwork[1], &work[1], &work[*n + 1], &
1516 /* If the user requested accuracy level allows truncation in the */
1517 /* computed upper triangular factor, the matrix R is examined and, */
1518 /* if possible, replaced with its leading upper trapezoidal part. */
1520 epsln = dlamch_("E");
1521 sfmin = dlamch_("S");
1522 /* SMALL = SFMIN / EPSLN */
1527 /* Standard absolute error bound suffices. All sigma_i with */
1528 /* sigma_i < N*EPS*||A||_F are flushed to zero. This is an */
1529 /* aggressive enforcement of lower numerical rank by introducing a */
1530 /* backward error of the order of N*EPS*||A||_F. */
1532 rtmp = sqrt((doublereal) (*n)) * epsln;
1534 for (p = 2; p <= i__1; ++p) {
1535 if ((d__2 = a[p + p * a_dim1], abs(d__2)) < rtmp * (d__1 = a[
1536 a_dim1 + 1], abs(d__1))) {
1546 /* Sudden drop on the diagonal of R is used as the criterion for being */
1547 /* close-to-rank-deficient. The threshold is set to EPSLN=DLAMCH('E'). */
1548 /* [[This can be made more flexible by replacing this hard-coded value */
1549 /* with a user specified threshold.]] Also, the values that underflow */
1550 /* will be truncated. */
1553 for (p = 2; p <= i__1; ++p) {
1554 if ((d__2 = a[p + p * a_dim1], abs(d__2)) < epsln * (d__1 = a[p -
1555 1 + (p - 1) * a_dim1], abs(d__1)) || (d__3 = a[p + p *
1556 a_dim1], abs(d__3)) < sfmin) {
1566 /* obvious case of zero pivots. */
1567 /* R(i,i)=0 => R(i:N,i:N)=0. */
1570 for (p = 2; p <= i__1; ++p) {
1571 if ((d__1 = a[p + p * a_dim1], abs(d__1)) == 0.) {
1580 /* Estimate the scaled condition number of A. Use the fact that it is */
1581 /* the same as the scaled condition number of R. */
1582 dlacpy_("U", n, n, &a[a_offset], lda, &v[v_offset], ldv);
1583 /* Only the leading NR x NR submatrix of the triangular factor */
1584 /* is considered. Only if NR=N will this give a reliable error */
1585 /* bound. However, even for NR < N, this can be used on an */
1586 /* expert level and obtain useful information in the sense of */
1587 /* perturbation theory. */
1589 for (p = 1; p <= i__1; ++p) {
1590 rtmp = dnrm2_(&p, &v[p * v_dim1 + 1], &c__1);
1592 dscal_(&p, &d__1, &v[p * v_dim1 + 1], &c__1);
1595 if (! (lsvec || rsvec)) {
1596 dpocon_("U", &nr, &v[v_offset], ldv, &c_b76, &rtmp, &work[1],
1597 &iwork[*n + iwoff], &ierr);
1599 dpocon_("U", &nr, &v[v_offset], ldv, &c_b76, &rtmp, &work[*n
1600 + 1], &iwork[*n + iwoff], &ierr);
1602 sconda = 1. / sqrt(rtmp);
1603 /* For NR=N, SCONDA is an estimate of SQRT(||(R^* * R)^(-1)||_1), */
1604 /* N^(-1/4) * SCONDA <= ||R^(-1)||_2 <= N^(1/4) * SCONDA */
1605 /* See the reference [1] for more details. */
1612 } else if (wntus || wntuf) {
1618 if (! (rsvec || lsvec)) {
1619 /* ....................................................................... */
1620 /* ....................................................................... */
1623 /* the upper triangle of [A] to zero. */
1624 i__1 = f2cmin(*n,nr);
1625 for (p = 1; p <= i__1; ++p) {
1627 for (q = p + 1; q <= i__2; ++q) {
1628 a[q + p * a_dim1] = a[p + q * a_dim1];
1630 a[p + q * a_dim1] = 0.;
1637 dgesvd_("N", "N", n, &nr, &a[a_offset], lda, &s[1], &u[u_offset],
1638 ldu, &v[v_offset], ldv, &work[1], lwork, info);
1646 dlaset_("L", &i__1, &i__2, &c_b72, &c_b72, &a[a_dim1 + 2],
1649 dgesvd_("N", "N", &nr, n, &a[a_offset], lda, &s[1], &u[u_offset],
1650 ldu, &v[v_offset], ldv, &work[1], lwork, info);
1654 } else if (lsvec && ! rsvec) {
1655 /* ....................................................................... */
1656 /* ......................................................................."""""""" */
1660 for (p = 1; p <= i__1; ++p) {
1662 for (q = p; q <= i__2; ++q) {
1663 u[q + p * u_dim1] = a[p + q * a_dim1];
1671 dlaset_("U", &i__1, &i__2, &c_b72, &c_b72, &u[(u_dim1 << 1) +
1674 /* vectors overwrite [U](1:NR,1:NR) as transposed. These */
1675 /* will be pre-multiplied by Q to build the left singular vectors of A. */
1677 dgesvd_("N", "O", n, &nr, &u[u_offset], ldu, &s[1], &u[u_offset],
1678 ldu, &u[u_offset], ldu, &work[*n + 1], &i__1, info);
1681 for (p = 1; p <= i__1; ++p) {
1683 for (q = p + 1; q <= i__2; ++q) {
1684 rtmp = u[q + p * u_dim1];
1685 u[q + p * u_dim1] = u[p + q * u_dim1];
1686 u[p + q * u_dim1] = rtmp;
1693 dlacpy_("U", &nr, n, &a[a_offset], lda, &u[u_offset], ldu);
1697 dlaset_("L", &i__1, &i__2, &c_b72, &c_b72, &u[u_dim1 + 2],
1700 /* vectors overwrite [U](1:NR,1:NR) */
1702 dgesvd_("O", "N", &nr, n, &u[u_offset], ldu, &s[1], &u[u_offset],
1703 ldu, &v[v_offset], ldv, &work[*n + 1], &i__1, info);
1704 /* R. These will be pre-multiplied by Q to build the left singular */
1708 /* (M x NR) or (M x N) or (M x M). */
1709 if (nr < *m && ! wntuf) {
1711 dlaset_("A", &i__1, &nr, &c_b72, &c_b72, &u[nr + 1 + u_dim1], ldu);
1714 dlaset_("A", &nr, &i__1, &c_b72, &c_b72, &u[(nr + 1) * u_dim1
1718 dlaset_("A", &i__1, &i__2, &c_b72, &c_b76, &u[nr + 1 + (nr +
1723 /* The Q matrix from the first QRF is built into the left singular */
1724 /* vectors matrix U. */
1728 dormqr_("L", "N", m, &n1, n, &a[a_offset], lda, &work[1], &u[
1729 u_offset], ldu, &work[*n + 1], &i__1, &ierr);
1731 if (rowprm && ! wntuf) {
1733 dlaswp_(&n1, &u[u_offset], ldu, &c__1, &i__1, &iwork[*n + 1], &
1737 } else if (rsvec && ! lsvec) {
1738 /* ....................................................................... */
1739 /* ....................................................................... */
1742 for (p = 1; p <= i__1; ++p) {
1744 for (q = p; q <= i__2; ++q) {
1745 v[q + p * v_dim1] = a[p + q * a_dim1];
1753 dlaset_("U", &i__1, &i__2, &c_b72, &c_b72, &v[(v_dim1 << 1) +
1756 /* vectors not computed */
1757 if (wntvr || nr == *n) {
1759 dgesvd_("O", "N", n, &nr, &v[v_offset], ldv, &s[1], &u[
1760 u_offset], ldu, &u[u_offset], ldu, &work[*n + 1], &
1764 for (p = 1; p <= i__1; ++p) {
1766 for (q = p + 1; q <= i__2; ++q) {
1767 rtmp = v[q + p * v_dim1];
1768 v[q + p * v_dim1] = v[p + q * v_dim1];
1769 v[p + q * v_dim1] = rtmp;
1777 for (p = 1; p <= i__1; ++p) {
1779 for (q = nr + 1; q <= i__2; ++q) {
1780 v[p + q * v_dim1] = v[q + p * v_dim1];
1786 dlapmt_(&c_false, &nr, n, &v[v_offset], ldv, &iwork[1]);
1788 /* [!] This is simple implementation that augments [V](1:N,1:NR) */
1789 /* by padding a zero block. In the case NR << N, a more efficient */
1790 /* way is to first use the QR factorization. For more details */
1791 /* how to implement this, see the " FULL SVD " branch. */
1793 dlaset_("G", n, &i__1, &c_b72, &c_b72, &v[(nr + 1) * v_dim1 +
1796 dgesvd_("O", "N", n, n, &v[v_offset], ldv, &s[1], &u[u_offset]
1797 , ldu, &u[u_offset], ldu, &work[*n + 1], &i__1, info);
1800 for (p = 1; p <= i__1; ++p) {
1802 for (q = p + 1; q <= i__2; ++q) {
1803 rtmp = v[q + p * v_dim1];
1804 v[q + p * v_dim1] = v[p + q * v_dim1];
1805 v[p + q * v_dim1] = rtmp;
1810 dlapmt_(&c_false, n, n, &v[v_offset], ldv, &iwork[1]);
1814 dlacpy_("U", &nr, n, &a[a_offset], lda, &v[v_offset], ldv);
1818 dlaset_("L", &i__1, &i__2, &c_b72, &c_b72, &v[v_dim1 + 2],
1821 /* vectors stored in U(1:NR,1:NR) */
1822 if (wntvr || nr == *n) {
1824 dgesvd_("N", "O", &nr, n, &v[v_offset], ldv, &s[1], &u[
1825 u_offset], ldu, &v[v_offset], ldv, &work[*n + 1], &
1827 dlapmt_(&c_false, &nr, n, &v[v_offset], ldv, &iwork[1]);
1829 /* [!] This is simple implementation that augments [V](1:NR,1:N) */
1830 /* by padding a zero block. In the case NR << N, a more efficient */
1831 /* way is to first use the LQ factorization. For more details */
1832 /* how to implement this, see the " FULL SVD " branch. */
1834 dlaset_("G", &i__1, n, &c_b72, &c_b72, &v[nr + 1 + v_dim1],
1837 dgesvd_("N", "O", n, n, &v[v_offset], ldv, &s[1], &u[u_offset]
1838 , ldu, &v[v_offset], ldv, &work[*n + 1], &i__1, info);
1839 dlapmt_(&c_false, n, n, &v[v_offset], ldv, &iwork[1]);
1845 /* ....................................................................... */
1846 /* ....................................................................... */
1850 if (wntvr || nr == *n) {
1851 /* vectors of R**T */
1853 for (p = 1; p <= i__1; ++p) {
1855 for (q = p; q <= i__2; ++q) {
1856 v[q + p * v_dim1] = a[p + q * a_dim1];
1864 dlaset_("U", &i__1, &i__2, &c_b72, &c_b72, &v[(v_dim1 <<
1868 /* singular vectors of R**T stored in [U](1:NR,1:NR) as transposed */
1870 dgesvd_("O", "A", n, &nr, &v[v_offset], ldv, &s[1], &v[
1871 v_offset], ldv, &u[u_offset], ldu, &work[*n + 1], &
1874 for (p = 1; p <= i__1; ++p) {
1876 for (q = p + 1; q <= i__2; ++q) {
1877 rtmp = v[q + p * v_dim1];
1878 v[q + p * v_dim1] = v[p + q * v_dim1];
1879 v[p + q * v_dim1] = rtmp;
1886 for (p = 1; p <= i__1; ++p) {
1888 for (q = nr + 1; q <= i__2; ++q) {
1889 v[p + q * v_dim1] = v[q + p * v_dim1];
1895 dlapmt_(&c_false, &nr, n, &v[v_offset], ldv, &iwork[1]);
1898 for (p = 1; p <= i__1; ++p) {
1900 for (q = p + 1; q <= i__2; ++q) {
1901 rtmp = u[q + p * u_dim1];
1902 u[q + p * u_dim1] = u[p + q * u_dim1];
1903 u[p + q * u_dim1] = rtmp;
1909 if (nr < *m && ! wntuf) {
1911 dlaset_("A", &i__1, &nr, &c_b72, &c_b72, &u[nr + 1 +
1915 dlaset_("A", &nr, &i__1, &c_b72, &c_b72, &u[(nr + 1) *
1919 dlaset_("A", &i__1, &i__2, &c_b72, &c_b76, &u[nr + 1
1920 + (nr + 1) * u_dim1], ldu);
1925 /* vectors of R**T */
1926 /* [[The optimal ratio N/NR for using QRF instead of padding */
1927 /* with zeros. Here hard coded to 2; it must be at least */
1928 /* two due to work space constraints.]] */
1929 /* OPTRATIO = ILAENV(6, 'DGESVD', 'S' // 'O', NR,N,0,0) */
1930 /* OPTRATIO = MAX( OPTRATIO, 2 ) */
1932 if (optratio * nr > *n) {
1934 for (p = 1; p <= i__1; ++p) {
1936 for (q = p; q <= i__2; ++q) {
1937 v[q + p * v_dim1] = a[p + q * a_dim1];
1945 dlaset_("U", &i__1, &i__2, &c_b72, &c_b72, &v[(v_dim1
1950 dlaset_("A", n, &i__1, &c_b72, &c_b72, &v[(nr + 1) *
1953 dgesvd_("O", "A", n, n, &v[v_offset], ldv, &s[1], &v[
1954 v_offset], ldv, &u[u_offset], ldu, &work[*n + 1],
1958 for (p = 1; p <= i__1; ++p) {
1960 for (q = p + 1; q <= i__2; ++q) {
1961 rtmp = v[q + p * v_dim1];
1962 v[q + p * v_dim1] = v[p + q * v_dim1];
1963 v[p + q * v_dim1] = rtmp;
1968 dlapmt_(&c_false, n, n, &v[v_offset], ldv, &iwork[1]);
1969 /* (M x N1), i.e. (M x N) or (M x M). */
1972 for (p = 1; p <= i__1; ++p) {
1974 for (q = p + 1; q <= i__2; ++q) {
1975 rtmp = u[q + p * u_dim1];
1976 u[q + p * u_dim1] = u[p + q * u_dim1];
1977 u[p + q * u_dim1] = rtmp;
1983 if (*n < *m && ! wntuf) {
1985 dlaset_("A", &i__1, n, &c_b72, &c_b72, &u[*n + 1 +
1989 dlaset_("A", n, &i__1, &c_b72, &c_b72, &u[(*n + 1)
1990 * u_dim1 + 1], ldu);
1993 dlaset_("A", &i__1, &i__2, &c_b72, &c_b76, &u[*n
1994 + 1 + (*n + 1) * u_dim1], ldu);
1998 /* singular vectors of R */
2000 for (p = 1; p <= i__1; ++p) {
2002 for (q = p; q <= i__2; ++q) {
2003 u[q + (nr + p) * u_dim1] = a[p + q * a_dim1];
2011 dlaset_("U", &i__1, &i__2, &c_b72, &c_b72, &u[(nr + 2)
2012 * u_dim1 + 1], ldu);
2014 i__1 = *lwork - *n - nr;
2015 dgeqrf_(n, &nr, &u[(nr + 1) * u_dim1 + 1], ldu, &work[*n
2016 + 1], &work[*n + nr + 1], &i__1, &ierr);
2018 for (p = 1; p <= i__1; ++p) {
2020 for (q = 1; q <= i__2; ++q) {
2021 v[q + p * v_dim1] = u[p + (nr + q) * u_dim1];
2028 dlaset_("U", &i__1, &i__2, &c_b72, &c_b72, &v[(v_dim1 <<
2030 i__1 = *lwork - *n - nr;
2031 dgesvd_("S", "O", &nr, &nr, &v[v_offset], ldv, &s[1], &u[
2032 u_offset], ldu, &v[v_offset], ldv, &work[*n + nr
2035 dlaset_("A", &i__1, &nr, &c_b72, &c_b72, &v[nr + 1 +
2038 dlaset_("A", &nr, &i__1, &c_b72, &c_b72, &v[(nr + 1) *
2042 dlaset_("A", &i__1, &i__2, &c_b72, &c_b76, &v[nr + 1 + (
2043 nr + 1) * v_dim1], ldv);
2044 i__1 = *lwork - *n - nr;
2045 dormqr_("R", "C", n, n, &nr, &u[(nr + 1) * u_dim1 + 1],
2046 ldu, &work[*n + 1], &v[v_offset], ldv, &work[*n +
2047 nr + 1], &i__1, &ierr);
2048 dlapmt_(&c_false, n, n, &v[v_offset], ldv, &iwork[1]);
2049 /* (M x NR) or (M x N) or (M x M). */
2050 if (nr < *m && ! wntuf) {
2052 dlaset_("A", &i__1, &nr, &c_b72, &c_b72, &u[nr + 1 +
2056 dlaset_("A", &nr, &i__1, &c_b72, &c_b72, &u[(nr +
2057 1) * u_dim1 + 1], ldu);
2060 dlaset_("A", &i__1, &i__2, &c_b72, &c_b76, &u[nr
2061 + 1 + (nr + 1) * u_dim1], ldu);
2070 if (wntvr || nr == *n) {
2071 dlacpy_("U", &nr, n, &a[a_offset], lda, &v[v_offset], ldv);
2075 dlaset_("L", &i__1, &i__2, &c_b72, &c_b72, &v[v_dim1 + 2],
2078 /* singular vectors of R stored in [U](1:NR,1:NR) */
2080 dgesvd_("S", "O", &nr, n, &v[v_offset], ldv, &s[1], &u[
2081 u_offset], ldu, &v[v_offset], ldv, &work[*n + 1], &
2083 dlapmt_(&c_false, &nr, n, &v[v_offset], ldv, &iwork[1]);
2084 /* (M x NR) or (M x N) or (M x M). */
2085 if (nr < *m && ! wntuf) {
2087 dlaset_("A", &i__1, &nr, &c_b72, &c_b72, &u[nr + 1 +
2091 dlaset_("A", &nr, &i__1, &c_b72, &c_b72, &u[(nr + 1) *
2095 dlaset_("A", &i__1, &i__2, &c_b72, &c_b76, &u[nr + 1
2096 + (nr + 1) * u_dim1], ldu);
2101 /* is then N1 (N or M) */
2102 /* [[The optimal ratio N/NR for using LQ instead of padding */
2103 /* with zeros. Here hard coded to 2; it must be at least */
2104 /* two due to work space constraints.]] */
2105 /* OPTRATIO = ILAENV(6, 'DGESVD', 'S' // 'O', NR,N,0,0) */
2106 /* OPTRATIO = MAX( OPTRATIO, 2 ) */
2108 if (optratio * nr > *n) {
2109 dlacpy_("U", &nr, n, &a[a_offset], lda, &v[v_offset], ldv);
2113 dlaset_("L", &i__1, &i__2, &c_b72, &c_b72, &v[v_dim1
2116 /* singular vectors of R stored in [U](1:NR,1:NR) */
2118 dlaset_("A", &i__1, n, &c_b72, &c_b72, &v[nr + 1 + v_dim1]
2121 dgesvd_("S", "O", n, n, &v[v_offset], ldv, &s[1], &u[
2122 u_offset], ldu, &v[v_offset], ldv, &work[*n + 1],
2124 dlapmt_(&c_false, n, n, &v[v_offset], ldv, &iwork[1]);
2125 /* singular vectors of A. The leading N left singular vectors */
2126 /* are in [U](1:N,1:N) */
2127 /* (M x N1), i.e. (M x N) or (M x M). */
2128 if (*n < *m && ! wntuf) {
2130 dlaset_("A", &i__1, n, &c_b72, &c_b72, &u[*n + 1 +
2134 dlaset_("A", n, &i__1, &c_b72, &c_b72, &u[(*n + 1)
2135 * u_dim1 + 1], ldu);
2138 dlaset_("A", &i__1, &i__2, &c_b72, &c_b76, &u[*n
2139 + 1 + (*n + 1) * u_dim1], ldu);
2143 dlacpy_("U", &nr, n, &a[a_offset], lda, &u[nr + 1 +
2148 dlaset_("L", &i__1, &i__2, &c_b72, &c_b72, &u[nr + 2
2151 i__1 = *lwork - *n - nr;
2152 dgelqf_(&nr, n, &u[nr + 1 + u_dim1], ldu, &work[*n + 1], &
2153 work[*n + nr + 1], &i__1, &ierr);
2154 dlacpy_("L", &nr, &nr, &u[nr + 1 + u_dim1], ldu, &v[
2159 dlaset_("U", &i__1, &i__2, &c_b72, &c_b72, &v[(v_dim1
2162 i__1 = *lwork - *n - nr;
2163 dgesvd_("S", "O", &nr, &nr, &v[v_offset], ldv, &s[1], &u[
2164 u_offset], ldu, &v[v_offset], ldv, &work[*n + nr
2167 dlaset_("A", &i__1, &nr, &c_b72, &c_b72, &v[nr + 1 +
2170 dlaset_("A", &nr, &i__1, &c_b72, &c_b72, &v[(nr + 1) *
2174 dlaset_("A", &i__1, &i__2, &c_b72, &c_b76, &v[nr + 1 + (
2175 nr + 1) * v_dim1], ldv);
2176 i__1 = *lwork - *n - nr;
2177 dormlq_("R", "N", n, n, &nr, &u[nr + 1 + u_dim1], ldu, &
2178 work[*n + 1], &v[v_offset], ldv, &work[*n + nr +
2180 dlapmt_(&c_false, n, n, &v[v_offset], ldv, &iwork[1]);
2181 /* (M x NR) or (M x N) or (M x M). */
2182 if (nr < *m && ! wntuf) {
2184 dlaset_("A", &i__1, &nr, &c_b72, &c_b72, &u[nr + 1 +
2188 dlaset_("A", &nr, &i__1, &c_b72, &c_b72, &u[(nr +
2189 1) * u_dim1 + 1], ldu);
2192 dlaset_("A", &i__1, &i__2, &c_b72, &c_b76, &u[nr
2193 + 1 + (nr + 1) * u_dim1], ldu);
2200 /* The Q matrix from the first QRF is built into the left singular */
2201 /* vectors matrix U. */
2205 dormqr_("L", "N", m, &n1, n, &a[a_offset], lda, &work[1], &u[
2206 u_offset], ldu, &work[*n + 1], &i__1, &ierr);
2208 if (rowprm && ! wntuf) {
2210 dlaswp_(&n1, &u[u_offset], ldu, &c__1, &i__1, &iwork[*n + 1], &
2214 /* ... end of the "full SVD" branch */
2217 /* Check whether some singular values are returned as zeros, e.g. */
2218 /* due to underflow, and update the numerical rank. */
2220 for (q = p; q >= 1; --q) {
2229 /* singular values are set to zero. */
2232 dlaset_("G", &i__1, &c__1, &c_b72, &c_b72, &s[nr + 1], n);
2236 d__1 = sqrt((doublereal) (*m));
2237 dlascl_("G", &c__0, &c__0, &c_b76, &d__1, &nr, &c__1, &s[1], n, &ierr);
2242 rwork[2] = (doublereal) (p - nr);
2243 /* exact zeros in DGESVD() applied to the (possibly truncated) */
2244 /* full row rank triangular (trapezoidal) factor of A. */
2249 /* End of DGESVDQ */