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__0 = 0;
517 static real c_b63 = 0.f;
518 static integer c__1 = 1;
519 static real c_b84 = 1.f;
521 /* > \brief \b SGESDD */
523 /* =========== DOCUMENTATION =========== */
525 /* Online html documentation available at */
526 /* http://www.netlib.org/lapack/explore-html/ */
529 /* > Download SGESDD + dependencies */
530 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/sgesdd.
533 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/sgesdd.
536 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/sgesdd.
544 /* SUBROUTINE SGESDD( JOBZ, M, N, A, LDA, S, U, LDU, VT, LDVT, */
545 /* WORK, LWORK, IWORK, INFO ) */
548 /* INTEGER INFO, LDA, LDU, LDVT, LWORK, M, N */
549 /* INTEGER IWORK( * ) */
550 /* REAL A( LDA, * ), S( * ), U( LDU, * ), */
551 /* $ VT( LDVT, * ), WORK( * ) */
554 /* > \par Purpose: */
559 /* > SGESDD computes the singular value decomposition (SVD) of a real */
560 /* > M-by-N matrix A, optionally computing the left and right singular */
561 /* > vectors. If singular vectors are desired, it uses a */
562 /* > divide-and-conquer algorithm. */
564 /* > The SVD is written */
566 /* > A = U * SIGMA * transpose(V) */
568 /* > where SIGMA is an M-by-N matrix which is zero except for its */
569 /* > f2cmin(m,n) diagonal elements, U is an M-by-M orthogonal matrix, and */
570 /* > V is an N-by-N orthogonal matrix. The diagonal elements of SIGMA */
571 /* > are the singular values of A; they are real and non-negative, and */
572 /* > are returned in descending order. The first f2cmin(m,n) columns of */
573 /* > U and V are the left and right singular vectors of A. */
575 /* > Note that the routine returns VT = V**T, not V. */
577 /* > The divide and conquer algorithm makes very mild assumptions about */
578 /* > floating point arithmetic. It will work on machines with a guard */
579 /* > digit in add/subtract, or on those binary machines without guard */
580 /* > digits which subtract like the Cray X-MP, Cray Y-MP, Cray C-90, or */
581 /* > Cray-2. It could conceivably fail on hexadecimal or decimal machines */
582 /* > without guard digits, but we know of none. */
588 /* > \param[in] JOBZ */
590 /* > JOBZ is CHARACTER*1 */
591 /* > Specifies options for computing all or part of the matrix U: */
592 /* > = 'A': all M columns of U and all N rows of V**T are */
593 /* > returned in the arrays U and VT; */
594 /* > = 'S': the first f2cmin(M,N) columns of U and the first */
595 /* > f2cmin(M,N) rows of V**T are returned in the arrays U */
597 /* > = 'O': If M >= N, the first N columns of U are overwritten */
598 /* > on the array A and all rows of V**T are returned in */
599 /* > the array VT; */
600 /* > otherwise, all columns of U are returned in the */
601 /* > array U and the first M rows of V**T are overwritten */
602 /* > in the array A; */
603 /* > = 'N': no columns of U or rows of V**T are computed. */
609 /* > The number of rows of the input matrix A. M >= 0. */
615 /* > The number of columns of the input matrix A. N >= 0. */
618 /* > \param[in,out] A */
620 /* > A is REAL array, dimension (LDA,N) */
621 /* > On entry, the M-by-N matrix A. */
623 /* > if JOBZ = 'O', A is overwritten with the first N columns */
624 /* > of U (the left singular vectors, stored */
625 /* > columnwise) if M >= N; */
626 /* > A is overwritten with the first M rows */
627 /* > of V**T (the right singular vectors, stored */
628 /* > rowwise) otherwise. */
629 /* > if JOBZ .ne. 'O', the contents of A are destroyed. */
632 /* > \param[in] LDA */
634 /* > LDA is INTEGER */
635 /* > The leading dimension of the array A. LDA >= f2cmax(1,M). */
638 /* > \param[out] S */
640 /* > S is REAL array, dimension (f2cmin(M,N)) */
641 /* > The singular values of A, sorted so that S(i) >= S(i+1). */
644 /* > \param[out] U */
646 /* > U is REAL array, dimension (LDU,UCOL) */
647 /* > UCOL = M if JOBZ = 'A' or JOBZ = 'O' and M < N; */
648 /* > UCOL = f2cmin(M,N) if JOBZ = 'S'. */
649 /* > If JOBZ = 'A' or JOBZ = 'O' and M < N, U contains the M-by-M */
650 /* > orthogonal matrix U; */
651 /* > if JOBZ = 'S', U contains the first f2cmin(M,N) columns of U */
652 /* > (the left singular vectors, stored columnwise); */
653 /* > if JOBZ = 'O' and M >= N, or JOBZ = 'N', U is not referenced. */
656 /* > \param[in] LDU */
658 /* > LDU is INTEGER */
659 /* > The leading dimension of the array U. LDU >= 1; if */
660 /* > JOBZ = 'S' or 'A' or JOBZ = 'O' and M < N, LDU >= M. */
663 /* > \param[out] VT */
665 /* > VT is REAL array, dimension (LDVT,N) */
666 /* > If JOBZ = 'A' or JOBZ = 'O' and M >= N, VT contains the */
667 /* > N-by-N orthogonal matrix V**T; */
668 /* > if JOBZ = 'S', VT contains the first f2cmin(M,N) rows of */
669 /* > V**T (the right singular vectors, stored rowwise); */
670 /* > if JOBZ = 'O' and M < N, or JOBZ = 'N', VT is not referenced. */
673 /* > \param[in] LDVT */
675 /* > LDVT is INTEGER */
676 /* > The leading dimension of the array VT. LDVT >= 1; */
677 /* > if JOBZ = 'A' or JOBZ = 'O' and M >= N, LDVT >= N; */
678 /* > if JOBZ = 'S', LDVT >= f2cmin(M,N). */
681 /* > \param[out] WORK */
683 /* > WORK is REAL array, dimension (MAX(1,LWORK)) */
684 /* > On exit, if INFO = 0, WORK(1) returns the optimal LWORK; */
687 /* > \param[in] LWORK */
689 /* > LWORK is INTEGER */
690 /* > The dimension of the array WORK. LWORK >= 1. */
691 /* > If LWORK = -1, a workspace query is assumed. The optimal */
692 /* > size for the WORK array is calculated and stored in WORK(1), */
693 /* > and no other work except argument checking is performed. */
695 /* > Let mx = f2cmax(M,N) and mn = f2cmin(M,N). */
696 /* > If JOBZ = 'N', LWORK >= 3*mn + f2cmax( mx, 7*mn ). */
697 /* > If JOBZ = 'O', LWORK >= 3*mn + f2cmax( mx, 5*mn*mn + 4*mn ). */
698 /* > If JOBZ = 'S', LWORK >= 4*mn*mn + 7*mn. */
699 /* > If JOBZ = 'A', LWORK >= 4*mn*mn + 6*mn + mx. */
700 /* > These are not tight minimums in all cases; see comments inside code. */
701 /* > For good performance, LWORK should generally be larger; */
702 /* > a query is recommended. */
705 /* > \param[out] IWORK */
707 /* > IWORK is INTEGER array, dimension (8*f2cmin(M,N)) */
710 /* > \param[out] INFO */
712 /* > INFO is INTEGER */
713 /* > = 0: successful exit. */
714 /* > < 0: if INFO = -i, the i-th argument had an illegal value. */
715 /* > > 0: SBDSDC did not converge, updating process failed. */
721 /* > \author Univ. of Tennessee */
722 /* > \author Univ. of California Berkeley */
723 /* > \author Univ. of Colorado Denver */
724 /* > \author NAG Ltd. */
726 /* > \date June 2016 */
728 /* > \ingroup realGEsing */
730 /* > \par Contributors: */
731 /* ================== */
733 /* > Ming Gu and Huan Ren, Computer Science Division, University of */
734 /* > California at Berkeley, USA */
736 /* ===================================================================== */
737 /* Subroutine */ int sgesdd_(char *jobz, integer *m, integer *n, real *a,
738 integer *lda, real *s, real *u, integer *ldu, real *vt, integer *ldvt,
739 real *work, integer *lwork, integer *iwork, integer *info)
741 /* System generated locals */
742 integer a_dim1, a_offset, u_dim1, u_offset, vt_dim1, vt_offset, i__1,
745 /* Local variables */
746 integer lwork_sgelqf_mn__, lwork_sgeqrf_mn__, iscl, lwork_sorglq_mn__,
749 integer idum[1], ierr, itau, lwork_sorgqr_mm__, lwork_sorgqr_mn__,
750 lwork_sormbr_qln_mm__, lwork_sormbr_qln_mn__,
751 lwork_sormbr_qln_nn__, lwork_sormbr_prt_mm__,
752 lwork_sormbr_prt_mn__, lwork_sormbr_prt_nn__, i__;
753 extern logical lsame_(char *, char *);
755 extern /* Subroutine */ int sgemm_(char *, char *, integer *, integer *,
756 integer *, real *, real *, integer *, real *, integer *, real *,
758 integer minmn, wrkbl, itaup, itauq, mnthr;
761 logical wntqn, wntqo, wntqs;
762 integer ie, il, ir, bdspac, iu, lwork_sorgbr_p_mm__;
763 extern /* Subroutine */ int sbdsdc_(char *, char *, integer *, real *,
764 real *, real *, integer *, real *, integer *, real *, integer *,
765 real *, integer *, integer *);
766 integer lwork_sorgbr_q_nn__;
767 extern /* Subroutine */ int sgebrd_(integer *, integer *, real *, integer
768 *, real *, real *, real *, real *, real *, integer *, integer *);
769 extern real slamch_(char *), slange_(char *, integer *, integer *,
770 real *, integer *, real *);
771 extern /* Subroutine */ int xerbla_(char *, integer *, ftnlen);
773 extern /* Subroutine */ int sgelqf_(integer *, integer *, real *, integer
774 *, real *, real *, integer *, integer *), slascl_(char *, integer
775 *, integer *, real *, real *, integer *, integer *, real *,
776 integer *, integer *), sgeqrf_(integer *, integer *, real
777 *, integer *, real *, real *, integer *, integer *), slacpy_(char
778 *, integer *, integer *, real *, integer *, real *, integer *), slaset_(char *, integer *, integer *, real *, real *,
780 extern logical sisnan_(real *);
781 extern /* Subroutine */ int sorgbr_(char *, integer *, integer *, integer
782 *, real *, integer *, real *, real *, integer *, integer *);
784 extern /* Subroutine */ int sormbr_(char *, char *, char *, integer *,
785 integer *, integer *, real *, integer *, real *, real *, integer *
786 , real *, integer *, integer *);
787 integer ldwrkr, minwrk, ldwrku, maxwrk;
788 extern /* Subroutine */ int sorglq_(integer *, integer *, integer *, real
789 *, integer *, real *, real *, integer *, integer *);
793 extern /* Subroutine */ int sorgqr_(integer *, integer *, integer *, real
794 *, integer *, real *, real *, integer *, integer *);
798 integer ivt, lwork_sgebrd_mm__, lwork_sgebrd_mn__, lwork_sgebrd_nn__;
801 /* -- LAPACK driver routine (version 3.7.0) -- */
802 /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
803 /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
807 /* ===================================================================== */
810 /* Test the input arguments */
812 /* Parameter adjustments */
814 a_offset = 1 + a_dim1 * 1;
818 u_offset = 1 + u_dim1 * 1;
821 vt_offset = 1 + vt_dim1 * 1;
828 minmn = f2cmin(*m,*n);
829 wntqa = lsame_(jobz, "A");
830 wntqs = lsame_(jobz, "S");
831 wntqas = wntqa || wntqs;
832 wntqo = lsame_(jobz, "O");
833 wntqn = lsame_(jobz, "N");
834 lquery = *lwork == -1;
836 if (! (wntqa || wntqs || wntqo || wntqn)) {
842 } else if (*lda < f2cmax(1,*m)) {
844 } else if (*ldu < 1 || wntqas && *ldu < *m || wntqo && *m < *n && *ldu < *
847 } else if (*ldvt < 1 || wntqa && *ldvt < *n || wntqs && *ldvt < minmn ||
848 wntqo && *m >= *n && *ldvt < *n) {
852 /* Compute workspace */
853 /* Note: Comments in the code beginning "Workspace:" describe the */
854 /* minimal amount of workspace allocated at that point in the code, */
855 /* as well as the preferred amount for good performance. */
856 /* NB refers to the optimal block size for the immediately */
857 /* following subroutine, as returned by ILAENV. */
863 mnthr = (integer) (minmn * 11.f / 6.f);
864 if (*m >= *n && minmn > 0) {
866 /* Compute space needed for SBDSDC */
869 /* sbdsdc needs only 4*N (or 6*N for uplo=L for LAPACK <= 3.6) */
870 /* keep 7*N for backwards compatibility. */
873 bdspac = *n * 3 * *n + (*n << 2);
876 /* Compute space preferred for each routine */
877 sgebrd_(m, n, dum, m, dum, dum, dum, dum, dum, &c_n1, &ierr);
878 lwork_sgebrd_mn__ = (integer) dum[0];
880 sgebrd_(n, n, dum, n, dum, dum, dum, dum, dum, &c_n1, &ierr);
881 lwork_sgebrd_nn__ = (integer) dum[0];
883 sgeqrf_(m, n, dum, m, dum, dum, &c_n1, &ierr);
884 lwork_sgeqrf_mn__ = (integer) dum[0];
886 sorgbr_("Q", n, n, n, dum, n, dum, dum, &c_n1, &ierr);
887 lwork_sorgbr_q_nn__ = (integer) dum[0];
889 sorgqr_(m, m, n, dum, m, dum, dum, &c_n1, &ierr);
890 lwork_sorgqr_mm__ = (integer) dum[0];
892 sorgqr_(m, n, n, dum, m, dum, dum, &c_n1, &ierr);
893 lwork_sorgqr_mn__ = (integer) dum[0];
895 sormbr_("P", "R", "T", n, n, n, dum, n, dum, dum, n, dum, &c_n1, &
897 lwork_sormbr_prt_nn__ = (integer) dum[0];
899 sormbr_("Q", "L", "N", n, n, n, dum, n, dum, dum, n, dum, &c_n1, &
901 lwork_sormbr_qln_nn__ = (integer) dum[0];
903 sormbr_("Q", "L", "N", m, n, n, dum, m, dum, dum, m, dum, &c_n1, &
905 lwork_sormbr_qln_mn__ = (integer) dum[0];
907 sormbr_("Q", "L", "N", m, m, n, dum, m, dum, dum, m, dum, &c_n1, &
909 lwork_sormbr_qln_mm__ = (integer) dum[0];
914 /* Path 1 (M >> N, JOBZ='N') */
916 wrkbl = *n + lwork_sgeqrf_mn__;
918 i__1 = wrkbl, i__2 = *n * 3 + lwork_sgebrd_nn__;
919 wrkbl = f2cmax(i__1,i__2);
921 i__1 = wrkbl, i__2 = bdspac + *n;
922 maxwrk = f2cmax(i__1,i__2);
923 minwrk = bdspac + *n;
926 /* Path 2 (M >> N, JOBZ='O') */
928 wrkbl = *n + lwork_sgeqrf_mn__;
930 i__1 = wrkbl, i__2 = *n + lwork_sorgqr_mn__;
931 wrkbl = f2cmax(i__1,i__2);
933 i__1 = wrkbl, i__2 = *n * 3 + lwork_sgebrd_nn__;
934 wrkbl = f2cmax(i__1,i__2);
936 i__1 = wrkbl, i__2 = *n * 3 + lwork_sormbr_qln_nn__;
937 wrkbl = f2cmax(i__1,i__2);
939 i__1 = wrkbl, i__2 = *n * 3 + lwork_sormbr_prt_nn__;
940 wrkbl = f2cmax(i__1,i__2);
942 i__1 = wrkbl, i__2 = *n * 3 + bdspac;
943 wrkbl = f2cmax(i__1,i__2);
944 maxwrk = wrkbl + (*n << 1) * *n;
945 minwrk = bdspac + (*n << 1) * *n + *n * 3;
948 /* Path 3 (M >> N, JOBZ='S') */
950 wrkbl = *n + lwork_sgeqrf_mn__;
952 i__1 = wrkbl, i__2 = *n + lwork_sorgqr_mn__;
953 wrkbl = f2cmax(i__1,i__2);
955 i__1 = wrkbl, i__2 = *n * 3 + lwork_sgebrd_nn__;
956 wrkbl = f2cmax(i__1,i__2);
958 i__1 = wrkbl, i__2 = *n * 3 + lwork_sormbr_qln_nn__;
959 wrkbl = f2cmax(i__1,i__2);
961 i__1 = wrkbl, i__2 = *n * 3 + lwork_sormbr_prt_nn__;
962 wrkbl = f2cmax(i__1,i__2);
964 i__1 = wrkbl, i__2 = *n * 3 + bdspac;
965 wrkbl = f2cmax(i__1,i__2);
966 maxwrk = wrkbl + *n * *n;
967 minwrk = bdspac + *n * *n + *n * 3;
970 /* Path 4 (M >> N, JOBZ='A') */
972 wrkbl = *n + lwork_sgeqrf_mn__;
974 i__1 = wrkbl, i__2 = *n + lwork_sorgqr_mm__;
975 wrkbl = f2cmax(i__1,i__2);
977 i__1 = wrkbl, i__2 = *n * 3 + lwork_sgebrd_nn__;
978 wrkbl = f2cmax(i__1,i__2);
980 i__1 = wrkbl, i__2 = *n * 3 + lwork_sormbr_qln_nn__;
981 wrkbl = f2cmax(i__1,i__2);
983 i__1 = wrkbl, i__2 = *n * 3 + lwork_sormbr_prt_nn__;
984 wrkbl = f2cmax(i__1,i__2);
986 i__1 = wrkbl, i__2 = *n * 3 + bdspac;
987 wrkbl = f2cmax(i__1,i__2);
988 maxwrk = wrkbl + *n * *n;
990 i__1 = *n * 3 + bdspac, i__2 = *n + *m;
991 minwrk = *n * *n + f2cmax(i__1,i__2);
995 /* Path 5 (M >= N, but not much larger) */
997 wrkbl = *n * 3 + lwork_sgebrd_mn__;
999 /* Path 5n (M >= N, jobz='N') */
1001 i__1 = wrkbl, i__2 = *n * 3 + bdspac;
1002 maxwrk = f2cmax(i__1,i__2);
1003 minwrk = *n * 3 + f2cmax(*m,bdspac);
1005 /* Path 5o (M >= N, jobz='O') */
1007 i__1 = wrkbl, i__2 = *n * 3 + lwork_sormbr_prt_nn__;
1008 wrkbl = f2cmax(i__1,i__2);
1010 i__1 = wrkbl, i__2 = *n * 3 + lwork_sormbr_qln_mn__;
1011 wrkbl = f2cmax(i__1,i__2);
1013 i__1 = wrkbl, i__2 = *n * 3 + bdspac;
1014 wrkbl = f2cmax(i__1,i__2);
1015 maxwrk = wrkbl + *m * *n;
1017 i__1 = *m, i__2 = *n * *n + bdspac;
1018 minwrk = *n * 3 + f2cmax(i__1,i__2);
1020 /* Path 5s (M >= N, jobz='S') */
1022 i__1 = wrkbl, i__2 = *n * 3 + lwork_sormbr_qln_mn__;
1023 wrkbl = f2cmax(i__1,i__2);
1025 i__1 = wrkbl, i__2 = *n * 3 + lwork_sormbr_prt_nn__;
1026 wrkbl = f2cmax(i__1,i__2);
1028 i__1 = wrkbl, i__2 = *n * 3 + bdspac;
1029 maxwrk = f2cmax(i__1,i__2);
1030 minwrk = *n * 3 + f2cmax(*m,bdspac);
1032 /* Path 5a (M >= N, jobz='A') */
1034 i__1 = wrkbl, i__2 = *n * 3 + lwork_sormbr_qln_mm__;
1035 wrkbl = f2cmax(i__1,i__2);
1037 i__1 = wrkbl, i__2 = *n * 3 + lwork_sormbr_prt_nn__;
1038 wrkbl = f2cmax(i__1,i__2);
1040 i__1 = wrkbl, i__2 = *n * 3 + bdspac;
1041 maxwrk = f2cmax(i__1,i__2);
1042 minwrk = *n * 3 + f2cmax(*m,bdspac);
1045 } else if (minmn > 0) {
1047 /* Compute space needed for SBDSDC */
1050 /* sbdsdc needs only 4*N (or 6*N for uplo=L for LAPACK <= 3.6) */
1051 /* keep 7*N for backwards compatibility. */
1054 bdspac = *m * 3 * *m + (*m << 2);
1057 /* Compute space preferred for each routine */
1058 sgebrd_(m, n, dum, m, dum, dum, dum, dum, dum, &c_n1, &ierr);
1059 lwork_sgebrd_mn__ = (integer) dum[0];
1061 sgebrd_(m, m, &a[a_offset], m, &s[1], dum, dum, dum, dum, &c_n1, &
1063 lwork_sgebrd_mm__ = (integer) dum[0];
1065 sgelqf_(m, n, &a[a_offset], m, dum, dum, &c_n1, &ierr);
1066 lwork_sgelqf_mn__ = (integer) dum[0];
1068 sorglq_(n, n, m, dum, n, dum, dum, &c_n1, &ierr);
1069 lwork_sorglq_nn__ = (integer) dum[0];
1071 sorglq_(m, n, m, &a[a_offset], m, dum, dum, &c_n1, &ierr);
1072 lwork_sorglq_mn__ = (integer) dum[0];
1074 sorgbr_("P", m, m, m, &a[a_offset], n, dum, dum, &c_n1, &ierr);
1075 lwork_sorgbr_p_mm__ = (integer) dum[0];
1077 sormbr_("P", "R", "T", m, m, m, dum, m, dum, dum, m, dum, &c_n1, &
1079 lwork_sormbr_prt_mm__ = (integer) dum[0];
1081 sormbr_("P", "R", "T", m, n, m, dum, m, dum, dum, m, dum, &c_n1, &
1083 lwork_sormbr_prt_mn__ = (integer) dum[0];
1085 sormbr_("P", "R", "T", n, n, m, dum, n, dum, dum, n, dum, &c_n1, &
1087 lwork_sormbr_prt_nn__ = (integer) dum[0];
1089 sormbr_("Q", "L", "N", m, m, m, dum, m, dum, dum, m, dum, &c_n1, &
1091 lwork_sormbr_qln_mm__ = (integer) dum[0];
1096 /* Path 1t (N >> M, JOBZ='N') */
1098 wrkbl = *m + lwork_sgelqf_mn__;
1100 i__1 = wrkbl, i__2 = *m * 3 + lwork_sgebrd_mm__;
1101 wrkbl = f2cmax(i__1,i__2);
1103 i__1 = wrkbl, i__2 = bdspac + *m;
1104 maxwrk = f2cmax(i__1,i__2);
1105 minwrk = bdspac + *m;
1108 /* Path 2t (N >> M, JOBZ='O') */
1110 wrkbl = *m + lwork_sgelqf_mn__;
1112 i__1 = wrkbl, i__2 = *m + lwork_sorglq_mn__;
1113 wrkbl = f2cmax(i__1,i__2);
1115 i__1 = wrkbl, i__2 = *m * 3 + lwork_sgebrd_mm__;
1116 wrkbl = f2cmax(i__1,i__2);
1118 i__1 = wrkbl, i__2 = *m * 3 + lwork_sormbr_qln_mm__;
1119 wrkbl = f2cmax(i__1,i__2);
1121 i__1 = wrkbl, i__2 = *m * 3 + lwork_sormbr_prt_mm__;
1122 wrkbl = f2cmax(i__1,i__2);
1124 i__1 = wrkbl, i__2 = *m * 3 + bdspac;
1125 wrkbl = f2cmax(i__1,i__2);
1126 maxwrk = wrkbl + (*m << 1) * *m;
1127 minwrk = bdspac + (*m << 1) * *m + *m * 3;
1130 /* Path 3t (N >> M, JOBZ='S') */
1132 wrkbl = *m + lwork_sgelqf_mn__;
1134 i__1 = wrkbl, i__2 = *m + lwork_sorglq_mn__;
1135 wrkbl = f2cmax(i__1,i__2);
1137 i__1 = wrkbl, i__2 = *m * 3 + lwork_sgebrd_mm__;
1138 wrkbl = f2cmax(i__1,i__2);
1140 i__1 = wrkbl, i__2 = *m * 3 + lwork_sormbr_qln_mm__;
1141 wrkbl = f2cmax(i__1,i__2);
1143 i__1 = wrkbl, i__2 = *m * 3 + lwork_sormbr_prt_mm__;
1144 wrkbl = f2cmax(i__1,i__2);
1146 i__1 = wrkbl, i__2 = *m * 3 + bdspac;
1147 wrkbl = f2cmax(i__1,i__2);
1148 maxwrk = wrkbl + *m * *m;
1149 minwrk = bdspac + *m * *m + *m * 3;
1152 /* Path 4t (N >> M, JOBZ='A') */
1154 wrkbl = *m + lwork_sgelqf_mn__;
1156 i__1 = wrkbl, i__2 = *m + lwork_sorglq_nn__;
1157 wrkbl = f2cmax(i__1,i__2);
1159 i__1 = wrkbl, i__2 = *m * 3 + lwork_sgebrd_mm__;
1160 wrkbl = f2cmax(i__1,i__2);
1162 i__1 = wrkbl, i__2 = *m * 3 + lwork_sormbr_qln_mm__;
1163 wrkbl = f2cmax(i__1,i__2);
1165 i__1 = wrkbl, i__2 = *m * 3 + lwork_sormbr_prt_mm__;
1166 wrkbl = f2cmax(i__1,i__2);
1168 i__1 = wrkbl, i__2 = *m * 3 + bdspac;
1169 wrkbl = f2cmax(i__1,i__2);
1170 maxwrk = wrkbl + *m * *m;
1172 i__1 = *m * 3 + bdspac, i__2 = *m + *n;
1173 minwrk = *m * *m + f2cmax(i__1,i__2);
1177 /* Path 5t (N > M, but not much larger) */
1179 wrkbl = *m * 3 + lwork_sgebrd_mn__;
1181 /* Path 5tn (N > M, jobz='N') */
1183 i__1 = wrkbl, i__2 = *m * 3 + bdspac;
1184 maxwrk = f2cmax(i__1,i__2);
1185 minwrk = *m * 3 + f2cmax(*n,bdspac);
1187 /* Path 5to (N > M, jobz='O') */
1189 i__1 = wrkbl, i__2 = *m * 3 + lwork_sormbr_qln_mm__;
1190 wrkbl = f2cmax(i__1,i__2);
1192 i__1 = wrkbl, i__2 = *m * 3 + lwork_sormbr_prt_mn__;
1193 wrkbl = f2cmax(i__1,i__2);
1195 i__1 = wrkbl, i__2 = *m * 3 + bdspac;
1196 wrkbl = f2cmax(i__1,i__2);
1197 maxwrk = wrkbl + *m * *n;
1199 i__1 = *n, i__2 = *m * *m + bdspac;
1200 minwrk = *m * 3 + f2cmax(i__1,i__2);
1202 /* Path 5ts (N > M, jobz='S') */
1204 i__1 = wrkbl, i__2 = *m * 3 + lwork_sormbr_qln_mm__;
1205 wrkbl = f2cmax(i__1,i__2);
1207 i__1 = wrkbl, i__2 = *m * 3 + lwork_sormbr_prt_mn__;
1208 wrkbl = f2cmax(i__1,i__2);
1210 i__1 = wrkbl, i__2 = *m * 3 + bdspac;
1211 maxwrk = f2cmax(i__1,i__2);
1212 minwrk = *m * 3 + f2cmax(*n,bdspac);
1214 /* Path 5ta (N > M, jobz='A') */
1216 i__1 = wrkbl, i__2 = *m * 3 + lwork_sormbr_qln_mm__;
1217 wrkbl = f2cmax(i__1,i__2);
1219 i__1 = wrkbl, i__2 = *m * 3 + lwork_sormbr_prt_nn__;
1220 wrkbl = f2cmax(i__1,i__2);
1222 i__1 = wrkbl, i__2 = *m * 3 + bdspac;
1223 maxwrk = f2cmax(i__1,i__2);
1224 minwrk = *m * 3 + f2cmax(*n,bdspac);
1228 maxwrk = f2cmax(maxwrk,minwrk);
1229 work[1] = (real) maxwrk;
1231 if (*lwork < minwrk && ! lquery) {
1238 xerbla_("SGESDD", &i__1, (ftnlen)6);
1240 } else if (lquery) {
1244 /* Quick return if possible */
1246 if (*m == 0 || *n == 0) {
1250 /* Get machine constants */
1253 smlnum = sqrt(slamch_("S")) / eps;
1254 bignum = 1.f / smlnum;
1256 /* Scale A if f2cmax element outside range [SMLNUM,BIGNUM] */
1258 anrm = slange_("M", m, n, &a[a_offset], lda, dum);
1259 if (sisnan_(&anrm)) {
1264 if (anrm > 0.f && anrm < smlnum) {
1266 slascl_("G", &c__0, &c__0, &anrm, &smlnum, m, n, &a[a_offset], lda, &
1268 } else if (anrm > bignum) {
1270 slascl_("G", &c__0, &c__0, &anrm, &bignum, m, n, &a[a_offset], lda, &
1276 /* A has at least as many rows as columns. If A has sufficiently */
1277 /* more rows than columns, first reduce using the QR */
1278 /* decomposition (if sufficient workspace available) */
1284 /* Path 1 (M >> N, JOBZ='N') */
1285 /* No singular vectors to be computed */
1291 /* Workspace: need N [tau] + N [work] */
1292 /* Workspace: prefer N [tau] + N*NB [work] */
1294 i__1 = *lwork - nwork + 1;
1295 sgeqrf_(m, n, &a[a_offset], lda, &work[itau], &work[nwork], &
1298 /* Zero out below R */
1302 slaset_("L", &i__1, &i__2, &c_b63, &c_b63, &a[a_dim1 + 2],
1309 /* Bidiagonalize R in A */
1310 /* Workspace: need 3*N [e, tauq, taup] + N [work] */
1311 /* Workspace: prefer 3*N [e, tauq, taup] + 2*N*NB [work] */
1313 i__1 = *lwork - nwork + 1;
1314 sgebrd_(n, n, &a[a_offset], lda, &s[1], &work[ie], &work[
1315 itauq], &work[itaup], &work[nwork], &i__1, &ierr);
1318 /* Perform bidiagonal SVD, computing singular values only */
1319 /* Workspace: need N [e] + BDSPAC */
1321 sbdsdc_("U", "N", n, &s[1], &work[ie], dum, &c__1, dum, &c__1,
1322 dum, idum, &work[nwork], &iwork[1], info);
1326 /* Path 2 (M >> N, JOBZ = 'O') */
1327 /* N left singular vectors to be overwritten on A and */
1328 /* N right singular vectors to be computed in VT */
1332 /* WORK(IR) is LDWRKR by N */
1334 if (*lwork >= *lda * *n + *n * *n + *n * 3 + bdspac) {
1337 ldwrkr = (*lwork - *n * *n - *n * 3 - bdspac) / *n;
1339 itau = ir + ldwrkr * *n;
1343 /* Workspace: need N*N [R] + N [tau] + N [work] */
1344 /* Workspace: prefer N*N [R] + N [tau] + N*NB [work] */
1346 i__1 = *lwork - nwork + 1;
1347 sgeqrf_(m, n, &a[a_offset], lda, &work[itau], &work[nwork], &
1350 /* Copy R to WORK(IR), zeroing out below it */
1352 slacpy_("U", n, n, &a[a_offset], lda, &work[ir], &ldwrkr);
1355 slaset_("L", &i__1, &i__2, &c_b63, &c_b63, &work[ir + 1], &
1358 /* Generate Q in A */
1359 /* Workspace: need N*N [R] + N [tau] + N [work] */
1360 /* Workspace: prefer N*N [R] + N [tau] + N*NB [work] */
1362 i__1 = *lwork - nwork + 1;
1363 sorgqr_(m, n, n, &a[a_offset], lda, &work[itau], &work[nwork],
1370 /* Bidiagonalize R in WORK(IR) */
1371 /* Workspace: need N*N [R] + 3*N [e, tauq, taup] + N [work] */
1372 /* Workspace: prefer N*N [R] + 3*N [e, tauq, taup] + 2*N*NB [work] */
1374 i__1 = *lwork - nwork + 1;
1375 sgebrd_(n, n, &work[ir], &ldwrkr, &s[1], &work[ie], &work[
1376 itauq], &work[itaup], &work[nwork], &i__1, &ierr);
1378 /* WORK(IU) is N by N */
1381 nwork = iu + *n * *n;
1383 /* Perform bidiagonal SVD, computing left singular vectors */
1384 /* of bidiagonal matrix in WORK(IU) and computing right */
1385 /* singular vectors of bidiagonal matrix in VT */
1386 /* Workspace: need N*N [R] + 3*N [e, tauq, taup] + N*N [U] + BDSPAC */
1388 sbdsdc_("U", "I", n, &s[1], &work[ie], &work[iu], n, &vt[
1389 vt_offset], ldvt, dum, idum, &work[nwork], &iwork[1],
1392 /* Overwrite WORK(IU) by left singular vectors of R */
1393 /* and VT by right singular vectors of R */
1394 /* Workspace: need N*N [R] + 3*N [e, tauq, taup] + N*N [U] + N [work] */
1395 /* Workspace: prefer N*N [R] + 3*N [e, tauq, taup] + N*N [U] + N*NB [work] */
1397 i__1 = *lwork - nwork + 1;
1398 sormbr_("Q", "L", "N", n, n, n, &work[ir], &ldwrkr, &work[
1399 itauq], &work[iu], n, &work[nwork], &i__1, &ierr);
1400 i__1 = *lwork - nwork + 1;
1401 sormbr_("P", "R", "T", n, n, n, &work[ir], &ldwrkr, &work[
1402 itaup], &vt[vt_offset], ldvt, &work[nwork], &i__1, &
1405 /* Multiply Q in A by left singular vectors of R in */
1406 /* WORK(IU), storing result in WORK(IR) and copying to A */
1407 /* Workspace: need N*N [R] + 3*N [e, tauq, taup] + N*N [U] */
1408 /* Workspace: prefer M*N [R] + 3*N [e, tauq, taup] + N*N [U] */
1412 for (i__ = 1; i__2 < 0 ? i__ >= i__1 : i__ <= i__1; i__ +=
1415 i__3 = *m - i__ + 1;
1416 chunk = f2cmin(i__3,ldwrkr);
1417 sgemm_("N", "N", &chunk, n, n, &c_b84, &a[i__ + a_dim1],
1418 lda, &work[iu], n, &c_b63, &work[ir], &ldwrkr);
1419 slacpy_("F", &chunk, n, &work[ir], &ldwrkr, &a[i__ +
1426 /* Path 3 (M >> N, JOBZ='S') */
1427 /* N left singular vectors to be computed in U and */
1428 /* N right singular vectors to be computed in VT */
1432 /* WORK(IR) is N by N */
1435 itau = ir + ldwrkr * *n;
1439 /* Workspace: need N*N [R] + N [tau] + N [work] */
1440 /* Workspace: prefer N*N [R] + N [tau] + N*NB [work] */
1442 i__2 = *lwork - nwork + 1;
1443 sgeqrf_(m, n, &a[a_offset], lda, &work[itau], &work[nwork], &
1446 /* Copy R to WORK(IR), zeroing out below it */
1448 slacpy_("U", n, n, &a[a_offset], lda, &work[ir], &ldwrkr);
1451 slaset_("L", &i__2, &i__1, &c_b63, &c_b63, &work[ir + 1], &
1454 /* Generate Q in A */
1455 /* Workspace: need N*N [R] + N [tau] + N [work] */
1456 /* Workspace: prefer N*N [R] + N [tau] + N*NB [work] */
1458 i__2 = *lwork - nwork + 1;
1459 sorgqr_(m, n, n, &a[a_offset], lda, &work[itau], &work[nwork],
1466 /* Bidiagonalize R in WORK(IR) */
1467 /* Workspace: need N*N [R] + 3*N [e, tauq, taup] + N [work] */
1468 /* Workspace: prefer N*N [R] + 3*N [e, tauq, taup] + 2*N*NB [work] */
1470 i__2 = *lwork - nwork + 1;
1471 sgebrd_(n, n, &work[ir], &ldwrkr, &s[1], &work[ie], &work[
1472 itauq], &work[itaup], &work[nwork], &i__2, &ierr);
1474 /* Perform bidiagonal SVD, computing left singular vectors */
1475 /* of bidiagoal matrix in U and computing right singular */
1476 /* vectors of bidiagonal matrix in VT */
1477 /* Workspace: need N*N [R] + 3*N [e, tauq, taup] + BDSPAC */
1479 sbdsdc_("U", "I", n, &s[1], &work[ie], &u[u_offset], ldu, &vt[
1480 vt_offset], ldvt, dum, idum, &work[nwork], &iwork[1],
1483 /* Overwrite U by left singular vectors of R and VT */
1484 /* by right singular vectors of R */
1485 /* Workspace: need N*N [R] + 3*N [e, tauq, taup] + N [work] */
1486 /* Workspace: prefer N*N [R] + 3*N [e, tauq, taup] + N*NB [work] */
1488 i__2 = *lwork - nwork + 1;
1489 sormbr_("Q", "L", "N", n, n, n, &work[ir], &ldwrkr, &work[
1490 itauq], &u[u_offset], ldu, &work[nwork], &i__2, &ierr);
1492 i__2 = *lwork - nwork + 1;
1493 sormbr_("P", "R", "T", n, n, n, &work[ir], &ldwrkr, &work[
1494 itaup], &vt[vt_offset], ldvt, &work[nwork], &i__2, &
1497 /* Multiply Q in A by left singular vectors of R in */
1498 /* WORK(IR), storing result in U */
1499 /* Workspace: need N*N [R] */
1501 slacpy_("F", n, n, &u[u_offset], ldu, &work[ir], &ldwrkr);
1502 sgemm_("N", "N", m, n, n, &c_b84, &a[a_offset], lda, &work[ir]
1503 , &ldwrkr, &c_b63, &u[u_offset], ldu);
1507 /* Path 4 (M >> N, JOBZ='A') */
1508 /* M left singular vectors to be computed in U and */
1509 /* N right singular vectors to be computed in VT */
1513 /* WORK(IU) is N by N */
1516 itau = iu + ldwrku * *n;
1519 /* Compute A=Q*R, copying result to U */
1520 /* Workspace: need N*N [U] + N [tau] + N [work] */
1521 /* Workspace: prefer N*N [U] + N [tau] + N*NB [work] */
1523 i__2 = *lwork - nwork + 1;
1524 sgeqrf_(m, n, &a[a_offset], lda, &work[itau], &work[nwork], &
1526 slacpy_("L", m, n, &a[a_offset], lda, &u[u_offset], ldu);
1528 /* Generate Q in U */
1529 /* Workspace: need N*N [U] + N [tau] + M [work] */
1530 /* Workspace: prefer N*N [U] + N [tau] + M*NB [work] */
1531 i__2 = *lwork - nwork + 1;
1532 sorgqr_(m, m, n, &u[u_offset], ldu, &work[itau], &work[nwork],
1535 /* Produce R in A, zeroing out other entries */
1539 slaset_("L", &i__2, &i__1, &c_b63, &c_b63, &a[a_dim1 + 2],
1546 /* Bidiagonalize R in A */
1547 /* Workspace: need N*N [U] + 3*N [e, tauq, taup] + N [work] */
1548 /* Workspace: prefer N*N [U] + 3*N [e, tauq, taup] + 2*N*NB [work] */
1550 i__2 = *lwork - nwork + 1;
1551 sgebrd_(n, n, &a[a_offset], lda, &s[1], &work[ie], &work[
1552 itauq], &work[itaup], &work[nwork], &i__2, &ierr);
1554 /* Perform bidiagonal SVD, computing left singular vectors */
1555 /* of bidiagonal matrix in WORK(IU) and computing right */
1556 /* singular vectors of bidiagonal matrix in VT */
1557 /* Workspace: need N*N [U] + 3*N [e, tauq, taup] + BDSPAC */
1559 sbdsdc_("U", "I", n, &s[1], &work[ie], &work[iu], n, &vt[
1560 vt_offset], ldvt, dum, idum, &work[nwork], &iwork[1],
1563 /* Overwrite WORK(IU) by left singular vectors of R and VT */
1564 /* by right singular vectors of R */
1565 /* Workspace: need N*N [U] + 3*N [e, tauq, taup] + N [work] */
1566 /* Workspace: prefer N*N [U] + 3*N [e, tauq, taup] + N*NB [work] */
1568 i__2 = *lwork - nwork + 1;
1569 sormbr_("Q", "L", "N", n, n, n, &a[a_offset], lda, &work[
1570 itauq], &work[iu], &ldwrku, &work[nwork], &i__2, &
1572 i__2 = *lwork - nwork + 1;
1573 sormbr_("P", "R", "T", n, n, n, &a[a_offset], lda, &work[
1574 itaup], &vt[vt_offset], ldvt, &work[nwork], &i__2, &
1577 /* Multiply Q in U by left singular vectors of R in */
1578 /* WORK(IU), storing result in A */
1579 /* Workspace: need N*N [U] */
1581 sgemm_("N", "N", m, n, n, &c_b84, &u[u_offset], ldu, &work[iu]
1582 , &ldwrku, &c_b63, &a[a_offset], lda);
1584 /* Copy left singular vectors of A from A to U */
1586 slacpy_("F", m, n, &a[a_offset], lda, &u[u_offset], ldu);
1594 /* Path 5 (M >= N, but not much larger) */
1595 /* Reduce to bidiagonal form without QR decomposition */
1602 /* Bidiagonalize A */
1603 /* Workspace: need 3*N [e, tauq, taup] + M [work] */
1604 /* Workspace: prefer 3*N [e, tauq, taup] + (M+N)*NB [work] */
1606 i__2 = *lwork - nwork + 1;
1607 sgebrd_(m, n, &a[a_offset], lda, &s[1], &work[ie], &work[itauq], &
1608 work[itaup], &work[nwork], &i__2, &ierr);
1611 /* Path 5n (M >= N, JOBZ='N') */
1612 /* Perform bidiagonal SVD, only computing singular values */
1613 /* Workspace: need 3*N [e, tauq, taup] + BDSPAC */
1615 sbdsdc_("U", "N", n, &s[1], &work[ie], dum, &c__1, dum, &c__1,
1616 dum, idum, &work[nwork], &iwork[1], info);
1618 /* Path 5o (M >= N, JOBZ='O') */
1620 if (*lwork >= *m * *n + *n * 3 + bdspac) {
1622 /* WORK( IU ) is M by N */
1625 nwork = iu + ldwrku * *n;
1626 slaset_("F", m, n, &c_b63, &c_b63, &work[iu], &ldwrku);
1627 /* IR is unused; silence compile warnings */
1631 /* WORK( IU ) is N by N */
1634 nwork = iu + ldwrku * *n;
1636 /* WORK(IR) is LDWRKR by N */
1639 ldwrkr = (*lwork - *n * *n - *n * 3) / *n;
1641 nwork = iu + ldwrku * *n;
1643 /* Perform bidiagonal SVD, computing left singular vectors */
1644 /* of bidiagonal matrix in WORK(IU) and computing right */
1645 /* singular vectors of bidiagonal matrix in VT */
1646 /* Workspace: need 3*N [e, tauq, taup] + N*N [U] + BDSPAC */
1648 sbdsdc_("U", "I", n, &s[1], &work[ie], &work[iu], &ldwrku, &
1649 vt[vt_offset], ldvt, dum, idum, &work[nwork], &iwork[
1652 /* Overwrite VT by right singular vectors of A */
1653 /* Workspace: need 3*N [e, tauq, taup] + N*N [U] + N [work] */
1654 /* Workspace: prefer 3*N [e, tauq, taup] + N*N [U] + N*NB [work] */
1656 i__2 = *lwork - nwork + 1;
1657 sormbr_("P", "R", "T", n, n, n, &a[a_offset], lda, &work[
1658 itaup], &vt[vt_offset], ldvt, &work[nwork], &i__2, &
1661 if (*lwork >= *m * *n + *n * 3 + bdspac) {
1664 /* Overwrite WORK(IU) by left singular vectors of A */
1665 /* Workspace: need 3*N [e, tauq, taup] + M*N [U] + N [work] */
1666 /* Workspace: prefer 3*N [e, tauq, taup] + M*N [U] + N*NB [work] */
1668 i__2 = *lwork - nwork + 1;
1669 sormbr_("Q", "L", "N", m, n, n, &a[a_offset], lda, &work[
1670 itauq], &work[iu], &ldwrku, &work[nwork], &i__2, &
1673 /* Copy left singular vectors of A from WORK(IU) to A */
1675 slacpy_("F", m, n, &work[iu], &ldwrku, &a[a_offset], lda);
1679 /* Generate Q in A */
1680 /* Workspace: need 3*N [e, tauq, taup] + N*N [U] + N [work] */
1681 /* Workspace: prefer 3*N [e, tauq, taup] + N*N [U] + N*NB [work] */
1683 i__2 = *lwork - nwork + 1;
1684 sorgbr_("Q", m, n, n, &a[a_offset], lda, &work[itauq], &
1685 work[nwork], &i__2, &ierr);
1687 /* Multiply Q in A by left singular vectors of */
1688 /* bidiagonal matrix in WORK(IU), storing result in */
1689 /* WORK(IR) and copying to A */
1690 /* Workspace: need 3*N [e, tauq, taup] + N*N [U] + NB*N [R] */
1691 /* Workspace: prefer 3*N [e, tauq, taup] + N*N [U] + M*N [R] */
1695 for (i__ = 1; i__1 < 0 ? i__ >= i__2 : i__ <= i__2; i__ +=
1698 i__3 = *m - i__ + 1;
1699 chunk = f2cmin(i__3,ldwrkr);
1700 sgemm_("N", "N", &chunk, n, n, &c_b84, &a[i__ +
1701 a_dim1], lda, &work[iu], &ldwrku, &c_b63, &
1703 slacpy_("F", &chunk, n, &work[ir], &ldwrkr, &a[i__ +
1711 /* Path 5s (M >= N, JOBZ='S') */
1712 /* Perform bidiagonal SVD, computing left singular vectors */
1713 /* of bidiagonal matrix in U and computing right singular */
1714 /* vectors of bidiagonal matrix in VT */
1715 /* Workspace: need 3*N [e, tauq, taup] + BDSPAC */
1717 slaset_("F", m, n, &c_b63, &c_b63, &u[u_offset], ldu);
1718 sbdsdc_("U", "I", n, &s[1], &work[ie], &u[u_offset], ldu, &vt[
1719 vt_offset], ldvt, dum, idum, &work[nwork], &iwork[1],
1722 /* Overwrite U by left singular vectors of A and VT */
1723 /* by right singular vectors of A */
1724 /* Workspace: need 3*N [e, tauq, taup] + N [work] */
1725 /* Workspace: prefer 3*N [e, tauq, taup] + N*NB [work] */
1727 i__1 = *lwork - nwork + 1;
1728 sormbr_("Q", "L", "N", m, n, n, &a[a_offset], lda, &work[
1729 itauq], &u[u_offset], ldu, &work[nwork], &i__1, &ierr);
1730 i__1 = *lwork - nwork + 1;
1731 sormbr_("P", "R", "T", n, n, n, &a[a_offset], lda, &work[
1732 itaup], &vt[vt_offset], ldvt, &work[nwork], &i__1, &
1736 /* Path 5a (M >= N, JOBZ='A') */
1737 /* Perform bidiagonal SVD, computing left singular vectors */
1738 /* of bidiagonal matrix in U and computing right singular */
1739 /* vectors of bidiagonal matrix in VT */
1740 /* Workspace: need 3*N [e, tauq, taup] + BDSPAC */
1742 slaset_("F", m, m, &c_b63, &c_b63, &u[u_offset], ldu);
1743 sbdsdc_("U", "I", n, &s[1], &work[ie], &u[u_offset], ldu, &vt[
1744 vt_offset], ldvt, dum, idum, &work[nwork], &iwork[1],
1747 /* Set the right corner of U to identity matrix */
1752 slaset_("F", &i__1, &i__2, &c_b63, &c_b84, &u[*n + 1 + (*
1753 n + 1) * u_dim1], ldu);
1756 /* Overwrite U by left singular vectors of A and VT */
1757 /* by right singular vectors of A */
1758 /* Workspace: need 3*N [e, tauq, taup] + M [work] */
1759 /* Workspace: prefer 3*N [e, tauq, taup] + M*NB [work] */
1761 i__1 = *lwork - nwork + 1;
1762 sormbr_("Q", "L", "N", m, m, n, &a[a_offset], lda, &work[
1763 itauq], &u[u_offset], ldu, &work[nwork], &i__1, &ierr);
1764 i__1 = *lwork - nwork + 1;
1765 sormbr_("P", "R", "T", n, n, m, &a[a_offset], lda, &work[
1766 itaup], &vt[vt_offset], ldvt, &work[nwork], &i__1, &
1774 /* A has more columns than rows. If A has sufficiently more */
1775 /* columns than rows, first reduce using the LQ decomposition (if */
1776 /* sufficient workspace available) */
1782 /* Path 1t (N >> M, JOBZ='N') */
1783 /* No singular vectors to be computed */
1789 /* Workspace: need M [tau] + M [work] */
1790 /* Workspace: prefer M [tau] + M*NB [work] */
1792 i__1 = *lwork - nwork + 1;
1793 sgelqf_(m, n, &a[a_offset], lda, &work[itau], &work[nwork], &
1796 /* Zero out above L */
1800 slaset_("U", &i__1, &i__2, &c_b63, &c_b63, &a[(a_dim1 << 1) +
1807 /* Bidiagonalize L in A */
1808 /* Workspace: need 3*M [e, tauq, taup] + M [work] */
1809 /* Workspace: prefer 3*M [e, tauq, taup] + 2*M*NB [work] */
1811 i__1 = *lwork - nwork + 1;
1812 sgebrd_(m, m, &a[a_offset], lda, &s[1], &work[ie], &work[
1813 itauq], &work[itaup], &work[nwork], &i__1, &ierr);
1816 /* Perform bidiagonal SVD, computing singular values only */
1817 /* Workspace: need M [e] + BDSPAC */
1819 sbdsdc_("U", "N", m, &s[1], &work[ie], dum, &c__1, dum, &c__1,
1820 dum, idum, &work[nwork], &iwork[1], info);
1824 /* Path 2t (N >> M, JOBZ='O') */
1825 /* M right singular vectors to be overwritten on A and */
1826 /* M left singular vectors to be computed in U */
1830 /* WORK(IVT) is M by M */
1831 /* WORK(IL) is M by M; it is later resized to M by chunk for gemm */
1834 if (*lwork >= *m * *n + *m * *m + *m * 3 + bdspac) {
1839 chunk = (*lwork - *m * *m) / *m;
1841 itau = il + ldwrkl * *m;
1845 /* Workspace: need M*M [VT] + M*M [L] + M [tau] + M [work] */
1846 /* Workspace: prefer M*M [VT] + M*M [L] + M [tau] + M*NB [work] */
1848 i__1 = *lwork - nwork + 1;
1849 sgelqf_(m, n, &a[a_offset], lda, &work[itau], &work[nwork], &
1852 /* Copy L to WORK(IL), zeroing about above it */
1854 slacpy_("L", m, m, &a[a_offset], lda, &work[il], &ldwrkl);
1857 slaset_("U", &i__1, &i__2, &c_b63, &c_b63, &work[il + ldwrkl],
1860 /* Generate Q in A */
1861 /* Workspace: need M*M [VT] + M*M [L] + M [tau] + M [work] */
1862 /* Workspace: prefer M*M [VT] + M*M [L] + M [tau] + M*NB [work] */
1864 i__1 = *lwork - nwork + 1;
1865 sorglq_(m, n, m, &a[a_offset], lda, &work[itau], &work[nwork],
1872 /* Bidiagonalize L in WORK(IL) */
1873 /* Workspace: need M*M [VT] + M*M [L] + 3*M [e, tauq, taup] + M [work] */
1874 /* Workspace: prefer M*M [VT] + M*M [L] + 3*M [e, tauq, taup] + 2*M*NB [work] */
1876 i__1 = *lwork - nwork + 1;
1877 sgebrd_(m, m, &work[il], &ldwrkl, &s[1], &work[ie], &work[
1878 itauq], &work[itaup], &work[nwork], &i__1, &ierr);
1880 /* Perform bidiagonal SVD, computing left singular vectors */
1881 /* of bidiagonal matrix in U, and computing right singular */
1882 /* vectors of bidiagonal matrix in WORK(IVT) */
1883 /* Workspace: need M*M [VT] + M*M [L] + 3*M [e, tauq, taup] + BDSPAC */
1885 sbdsdc_("U", "I", m, &s[1], &work[ie], &u[u_offset], ldu, &
1886 work[ivt], m, dum, idum, &work[nwork], &iwork[1],
1889 /* Overwrite U by left singular vectors of L and WORK(IVT) */
1890 /* by right singular vectors of L */
1891 /* Workspace: need M*M [VT] + M*M [L] + 3*M [e, tauq, taup] + M [work] */
1892 /* Workspace: prefer M*M [VT] + M*M [L] + 3*M [e, tauq, taup] + M*NB [work] */
1894 i__1 = *lwork - nwork + 1;
1895 sormbr_("Q", "L", "N", m, m, m, &work[il], &ldwrkl, &work[
1896 itauq], &u[u_offset], ldu, &work[nwork], &i__1, &ierr);
1897 i__1 = *lwork - nwork + 1;
1898 sormbr_("P", "R", "T", m, m, m, &work[il], &ldwrkl, &work[
1899 itaup], &work[ivt], m, &work[nwork], &i__1, &ierr);
1901 /* Multiply right singular vectors of L in WORK(IVT) by Q */
1902 /* in A, storing result in WORK(IL) and copying to A */
1903 /* Workspace: need M*M [VT] + M*M [L] */
1904 /* Workspace: prefer M*M [VT] + M*N [L] */
1905 /* At this point, L is resized as M by chunk. */
1909 for (i__ = 1; i__2 < 0 ? i__ >= i__1 : i__ <= i__1; i__ +=
1912 i__3 = *n - i__ + 1;
1913 blk = f2cmin(i__3,chunk);
1914 sgemm_("N", "N", m, &blk, m, &c_b84, &work[ivt], m, &a[
1915 i__ * a_dim1 + 1], lda, &c_b63, &work[il], &
1917 slacpy_("F", m, &blk, &work[il], &ldwrkl, &a[i__ * a_dim1
1924 /* Path 3t (N >> M, JOBZ='S') */
1925 /* M right singular vectors to be computed in VT and */
1926 /* M left singular vectors to be computed in U */
1930 /* WORK(IL) is M by M */
1933 itau = il + ldwrkl * *m;
1937 /* Workspace: need M*M [L] + M [tau] + M [work] */
1938 /* Workspace: prefer M*M [L] + M [tau] + M*NB [work] */
1940 i__2 = *lwork - nwork + 1;
1941 sgelqf_(m, n, &a[a_offset], lda, &work[itau], &work[nwork], &
1944 /* Copy L to WORK(IL), zeroing out above it */
1946 slacpy_("L", m, m, &a[a_offset], lda, &work[il], &ldwrkl);
1949 slaset_("U", &i__2, &i__1, &c_b63, &c_b63, &work[il + ldwrkl],
1952 /* Generate Q in A */
1953 /* Workspace: need M*M [L] + M [tau] + M [work] */
1954 /* Workspace: prefer M*M [L] + M [tau] + M*NB [work] */
1956 i__2 = *lwork - nwork + 1;
1957 sorglq_(m, n, m, &a[a_offset], lda, &work[itau], &work[nwork],
1964 /* Bidiagonalize L in WORK(IU). */
1965 /* Workspace: need M*M [L] + 3*M [e, tauq, taup] + M [work] */
1966 /* Workspace: prefer M*M [L] + 3*M [e, tauq, taup] + 2*M*NB [work] */
1968 i__2 = *lwork - nwork + 1;
1969 sgebrd_(m, m, &work[il], &ldwrkl, &s[1], &work[ie], &work[
1970 itauq], &work[itaup], &work[nwork], &i__2, &ierr);
1972 /* Perform bidiagonal SVD, computing left singular vectors */
1973 /* of bidiagonal matrix in U and computing right singular */
1974 /* vectors of bidiagonal matrix in VT */
1975 /* Workspace: need M*M [L] + 3*M [e, tauq, taup] + BDSPAC */
1977 sbdsdc_("U", "I", m, &s[1], &work[ie], &u[u_offset], ldu, &vt[
1978 vt_offset], ldvt, dum, idum, &work[nwork], &iwork[1],
1981 /* Overwrite U by left singular vectors of L and VT */
1982 /* by right singular vectors of L */
1983 /* Workspace: need M*M [L] + 3*M [e, tauq, taup] + M [work] */
1984 /* Workspace: prefer M*M [L] + 3*M [e, tauq, taup] + M*NB [work] */
1986 i__2 = *lwork - nwork + 1;
1987 sormbr_("Q", "L", "N", m, m, m, &work[il], &ldwrkl, &work[
1988 itauq], &u[u_offset], ldu, &work[nwork], &i__2, &ierr);
1989 i__2 = *lwork - nwork + 1;
1990 sormbr_("P", "R", "T", m, m, m, &work[il], &ldwrkl, &work[
1991 itaup], &vt[vt_offset], ldvt, &work[nwork], &i__2, &
1994 /* Multiply right singular vectors of L in WORK(IL) by */
1995 /* Q in A, storing result in VT */
1996 /* Workspace: need M*M [L] */
1998 slacpy_("F", m, m, &vt[vt_offset], ldvt, &work[il], &ldwrkl);
1999 sgemm_("N", "N", m, n, m, &c_b84, &work[il], &ldwrkl, &a[
2000 a_offset], lda, &c_b63, &vt[vt_offset], ldvt);
2004 /* Path 4t (N >> M, JOBZ='A') */
2005 /* N right singular vectors to be computed in VT and */
2006 /* M left singular vectors to be computed in U */
2010 /* WORK(IVT) is M by M */
2013 itau = ivt + ldwkvt * *m;
2016 /* Compute A=L*Q, copying result to VT */
2017 /* Workspace: need M*M [VT] + M [tau] + M [work] */
2018 /* Workspace: prefer M*M [VT] + M [tau] + M*NB [work] */
2020 i__2 = *lwork - nwork + 1;
2021 sgelqf_(m, n, &a[a_offset], lda, &work[itau], &work[nwork], &
2023 slacpy_("U", m, n, &a[a_offset], lda, &vt[vt_offset], ldvt);
2025 /* Generate Q in VT */
2026 /* Workspace: need M*M [VT] + M [tau] + N [work] */
2027 /* Workspace: prefer M*M [VT] + M [tau] + N*NB [work] */
2029 i__2 = *lwork - nwork + 1;
2030 sorglq_(n, n, m, &vt[vt_offset], ldvt, &work[itau], &work[
2031 nwork], &i__2, &ierr);
2033 /* Produce L in A, zeroing out other entries */
2037 slaset_("U", &i__2, &i__1, &c_b63, &c_b63, &a[(a_dim1 << 1) +
2044 /* Bidiagonalize L in A */
2045 /* Workspace: need M*M [VT] + 3*M [e, tauq, taup] + M [work] */
2046 /* Workspace: prefer M*M [VT] + 3*M [e, tauq, taup] + 2*M*NB [work] */
2048 i__2 = *lwork - nwork + 1;
2049 sgebrd_(m, m, &a[a_offset], lda, &s[1], &work[ie], &work[
2050 itauq], &work[itaup], &work[nwork], &i__2, &ierr);
2052 /* Perform bidiagonal SVD, computing left singular vectors */
2053 /* of bidiagonal matrix in U and computing right singular */
2054 /* vectors of bidiagonal matrix in WORK(IVT) */
2055 /* Workspace: need M*M [VT] + 3*M [e, tauq, taup] + BDSPAC */
2057 sbdsdc_("U", "I", m, &s[1], &work[ie], &u[u_offset], ldu, &
2058 work[ivt], &ldwkvt, dum, idum, &work[nwork], &iwork[1]
2061 /* Overwrite U by left singular vectors of L and WORK(IVT) */
2062 /* by right singular vectors of L */
2063 /* Workspace: need M*M [VT] + 3*M [e, tauq, taup]+ M [work] */
2064 /* Workspace: prefer M*M [VT] + 3*M [e, tauq, taup]+ M*NB [work] */
2066 i__2 = *lwork - nwork + 1;
2067 sormbr_("Q", "L", "N", m, m, m, &a[a_offset], lda, &work[
2068 itauq], &u[u_offset], ldu, &work[nwork], &i__2, &ierr);
2069 i__2 = *lwork - nwork + 1;
2070 sormbr_("P", "R", "T", m, m, m, &a[a_offset], lda, &work[
2071 itaup], &work[ivt], &ldwkvt, &work[nwork], &i__2, &
2074 /* Multiply right singular vectors of L in WORK(IVT) by */
2075 /* Q in VT, storing result in A */
2076 /* Workspace: need M*M [VT] */
2078 sgemm_("N", "N", m, n, m, &c_b84, &work[ivt], &ldwkvt, &vt[
2079 vt_offset], ldvt, &c_b63, &a[a_offset], lda);
2081 /* Copy right singular vectors of A from A to VT */
2083 slacpy_("F", m, n, &a[a_offset], lda, &vt[vt_offset], ldvt);
2091 /* Path 5t (N > M, but not much larger) */
2092 /* Reduce to bidiagonal form without LQ decomposition */
2099 /* Bidiagonalize A */
2100 /* Workspace: need 3*M [e, tauq, taup] + N [work] */
2101 /* Workspace: prefer 3*M [e, tauq, taup] + (M+N)*NB [work] */
2103 i__2 = *lwork - nwork + 1;
2104 sgebrd_(m, n, &a[a_offset], lda, &s[1], &work[ie], &work[itauq], &
2105 work[itaup], &work[nwork], &i__2, &ierr);
2108 /* Path 5tn (N > M, JOBZ='N') */
2109 /* Perform bidiagonal SVD, only computing singular values */
2110 /* Workspace: need 3*M [e, tauq, taup] + BDSPAC */
2112 sbdsdc_("L", "N", m, &s[1], &work[ie], dum, &c__1, dum, &c__1,
2113 dum, idum, &work[nwork], &iwork[1], info);
2115 /* Path 5to (N > M, JOBZ='O') */
2118 if (*lwork >= *m * *n + *m * 3 + bdspac) {
2120 /* WORK( IVT ) is M by N */
2122 slaset_("F", m, n, &c_b63, &c_b63, &work[ivt], &ldwkvt);
2123 nwork = ivt + ldwkvt * *n;
2124 /* IL is unused; silence compile warnings */
2128 /* WORK( IVT ) is M by M */
2130 nwork = ivt + ldwkvt * *m;
2133 /* WORK(IL) is M by CHUNK */
2135 chunk = (*lwork - *m * *m - *m * 3) / *m;
2138 /* Perform bidiagonal SVD, computing left singular vectors */
2139 /* of bidiagonal matrix in U and computing right singular */
2140 /* vectors of bidiagonal matrix in WORK(IVT) */
2141 /* Workspace: need 3*M [e, tauq, taup] + M*M [VT] + BDSPAC */
2143 sbdsdc_("L", "I", m, &s[1], &work[ie], &u[u_offset], ldu, &
2144 work[ivt], &ldwkvt, dum, idum, &work[nwork], &iwork[1]
2147 /* Overwrite U by left singular vectors of A */
2148 /* Workspace: need 3*M [e, tauq, taup] + M*M [VT] + M [work] */
2149 /* Workspace: prefer 3*M [e, tauq, taup] + M*M [VT] + M*NB [work] */
2151 i__2 = *lwork - nwork + 1;
2152 sormbr_("Q", "L", "N", m, m, n, &a[a_offset], lda, &work[
2153 itauq], &u[u_offset], ldu, &work[nwork], &i__2, &ierr);
2155 if (*lwork >= *m * *n + *m * 3 + bdspac) {
2158 /* Overwrite WORK(IVT) by left singular vectors of A */
2159 /* Workspace: need 3*M [e, tauq, taup] + M*N [VT] + M [work] */
2160 /* Workspace: prefer 3*M [e, tauq, taup] + M*N [VT] + M*NB [work] */
2162 i__2 = *lwork - nwork + 1;
2163 sormbr_("P", "R", "T", m, n, m, &a[a_offset], lda, &work[
2164 itaup], &work[ivt], &ldwkvt, &work[nwork], &i__2,
2167 /* Copy right singular vectors of A from WORK(IVT) to A */
2169 slacpy_("F", m, n, &work[ivt], &ldwkvt, &a[a_offset], lda);
2173 /* Generate P**T in A */
2174 /* Workspace: need 3*M [e, tauq, taup] + M*M [VT] + M [work] */
2175 /* Workspace: prefer 3*M [e, tauq, taup] + M*M [VT] + M*NB [work] */
2177 i__2 = *lwork - nwork + 1;
2178 sorgbr_("P", m, n, m, &a[a_offset], lda, &work[itaup], &
2179 work[nwork], &i__2, &ierr);
2181 /* Multiply Q in A by right singular vectors of */
2182 /* bidiagonal matrix in WORK(IVT), storing result in */
2183 /* WORK(IL) and copying to A */
2184 /* Workspace: need 3*M [e, tauq, taup] + M*M [VT] + M*NB [L] */
2185 /* Workspace: prefer 3*M [e, tauq, taup] + M*M [VT] + M*N [L] */
2189 for (i__ = 1; i__1 < 0 ? i__ >= i__2 : i__ <= i__2; i__ +=
2192 i__3 = *n - i__ + 1;
2193 blk = f2cmin(i__3,chunk);
2194 sgemm_("N", "N", m, &blk, m, &c_b84, &work[ivt], &
2195 ldwkvt, &a[i__ * a_dim1 + 1], lda, &c_b63, &
2197 slacpy_("F", m, &blk, &work[il], m, &a[i__ * a_dim1 +
2204 /* Path 5ts (N > M, JOBZ='S') */
2205 /* Perform bidiagonal SVD, computing left singular vectors */
2206 /* of bidiagonal matrix in U and computing right singular */
2207 /* vectors of bidiagonal matrix in VT */
2208 /* Workspace: need 3*M [e, tauq, taup] + BDSPAC */
2210 slaset_("F", m, n, &c_b63, &c_b63, &vt[vt_offset], ldvt);
2211 sbdsdc_("L", "I", m, &s[1], &work[ie], &u[u_offset], ldu, &vt[
2212 vt_offset], ldvt, dum, idum, &work[nwork], &iwork[1],
2215 /* Overwrite U by left singular vectors of A and VT */
2216 /* by right singular vectors of A */
2217 /* Workspace: need 3*M [e, tauq, taup] + M [work] */
2218 /* Workspace: prefer 3*M [e, tauq, taup] + M*NB [work] */
2220 i__1 = *lwork - nwork + 1;
2221 sormbr_("Q", "L", "N", m, m, n, &a[a_offset], lda, &work[
2222 itauq], &u[u_offset], ldu, &work[nwork], &i__1, &ierr);
2223 i__1 = *lwork - nwork + 1;
2224 sormbr_("P", "R", "T", m, n, m, &a[a_offset], lda, &work[
2225 itaup], &vt[vt_offset], ldvt, &work[nwork], &i__1, &
2229 /* Path 5ta (N > M, JOBZ='A') */
2230 /* Perform bidiagonal SVD, computing left singular vectors */
2231 /* of bidiagonal matrix in U and computing right singular */
2232 /* vectors of bidiagonal matrix in VT */
2233 /* Workspace: need 3*M [e, tauq, taup] + BDSPAC */
2235 slaset_("F", n, n, &c_b63, &c_b63, &vt[vt_offset], ldvt);
2236 sbdsdc_("L", "I", m, &s[1], &work[ie], &u[u_offset], ldu, &vt[
2237 vt_offset], ldvt, dum, idum, &work[nwork], &iwork[1],
2240 /* Set the right corner of VT to identity matrix */
2245 slaset_("F", &i__1, &i__2, &c_b63, &c_b84, &vt[*m + 1 + (*
2246 m + 1) * vt_dim1], ldvt);
2249 /* Overwrite U by left singular vectors of A and VT */
2250 /* by right singular vectors of A */
2251 /* Workspace: need 3*M [e, tauq, taup] + N [work] */
2252 /* Workspace: prefer 3*M [e, tauq, taup] + N*NB [work] */
2254 i__1 = *lwork - nwork + 1;
2255 sormbr_("Q", "L", "N", m, m, n, &a[a_offset], lda, &work[
2256 itauq], &u[u_offset], ldu, &work[nwork], &i__1, &ierr);
2257 i__1 = *lwork - nwork + 1;
2258 sormbr_("P", "R", "T", n, n, m, &a[a_offset], lda, &work[
2259 itaup], &vt[vt_offset], ldvt, &work[nwork], &i__1, &
2267 /* Undo scaling if necessary */
2270 if (anrm > bignum) {
2271 slascl_("G", &c__0, &c__0, &bignum, &anrm, &minmn, &c__1, &s[1], &
2274 if (anrm < smlnum) {
2275 slascl_("G", &c__0, &c__0, &smlnum, &anrm, &minmn, &c__1, &s[1], &
2280 /* Return optimal workspace in WORK(1) */
2282 work[1] = (real) maxwrk;