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)
514 /* Table of constant values */
516 static complex c_b1 = {0.f,0.f};
517 static complex c_b2 = {1.f,0.f};
518 static integer c_n1 = -1;
519 static integer c__1 = 1;
520 static integer c__0 = 0;
521 static real c_b141 = 1.f;
522 static logical c_false = FALSE_;
524 /* > \brief \b CGEJSV */
526 /* =========== DOCUMENTATION =========== */
528 /* Online html documentation available at */
529 /* http://www.netlib.org/lapack/explore-html/ */
532 /* > Download CGEJSV + dependencies */
533 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/cgejsv.
536 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/cgejsv.
539 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/cgejsv.
547 /* SUBROUTINE CGEJSV( JOBA, JOBU, JOBV, JOBR, JOBT, JOBP, */
548 /* M, N, A, LDA, SVA, U, LDU, V, LDV, */
549 /* CWORK, LWORK, RWORK, LRWORK, IWORK, INFO ) */
552 /* INTEGER INFO, LDA, LDU, LDV, LWORK, M, N */
553 /* COMPLEX A( LDA, * ), U( LDU, * ), V( LDV, * ), CWORK( LWORK ) */
554 /* REAL SVA( N ), RWORK( LRWORK ) */
555 /* INTEGER IWORK( * ) */
556 /* CHARACTER*1 JOBA, JOBP, JOBR, JOBT, JOBU, JOBV */
559 /* > \par Purpose: */
564 /* > CGEJSV computes the singular value decomposition (SVD) of a complex M-by-N */
565 /* > matrix [A], where M >= N. The SVD of [A] is written as */
567 /* > [A] = [U] * [SIGMA] * [V]^*, */
569 /* > where [SIGMA] is an N-by-N (M-by-N) matrix which is zero except for its N */
570 /* > diagonal elements, [U] is an M-by-N (or M-by-M) unitary matrix, and */
571 /* > [V] is an N-by-N unitary matrix. The diagonal elements of [SIGMA] are */
572 /* > the singular values of [A]. The columns of [U] and [V] are the left and */
573 /* > the right singular vectors of [A], respectively. The matrices [U] and [V] */
574 /* > are computed and stored in the arrays U and V, respectively. The diagonal */
575 /* > of [SIGMA] is computed and stored in the array SVA. */
581 /* > \param[in] JOBA */
583 /* > JOBA is CHARACTER*1 */
584 /* > Specifies the level of accuracy: */
585 /* > = 'C': This option works well (high relative accuracy) if A = B * D, */
586 /* > with well-conditioned B and arbitrary diagonal matrix D. */
587 /* > The accuracy cannot be spoiled by COLUMN scaling. The */
588 /* > accuracy of the computed output depends on the condition of */
589 /* > B, and the procedure aims at the best theoretical accuracy. */
590 /* > The relative error max_{i=1:N}|d sigma_i| / sigma_i is */
591 /* > bounded by f(M,N)*epsilon* cond(B), independent of D. */
592 /* > The input matrix is preprocessed with the QRF with column */
593 /* > pivoting. This initial preprocessing and preconditioning by */
594 /* > a rank revealing QR factorization is common for all values of */
595 /* > JOBA. Additional actions are specified as follows: */
596 /* > = 'E': Computation as with 'C' with an additional estimate of the */
597 /* > condition number of B. It provides a realistic error bound. */
598 /* > = 'F': If A = D1 * C * D2 with ill-conditioned diagonal scalings */
599 /* > D1, D2, and well-conditioned matrix C, this option gives */
600 /* > higher accuracy than the 'C' option. If the structure of the */
601 /* > input matrix is not known, and relative accuracy is */
602 /* > desirable, then this option is advisable. The input matrix A */
603 /* > is preprocessed with QR factorization with FULL (row and */
604 /* > column) pivoting. */
605 /* > = 'G': Computation as with 'F' with an additional estimate of the */
606 /* > condition number of B, where A=B*D. If A has heavily weighted */
607 /* > rows, then using this condition number gives too pessimistic */
609 /* > = 'A': Small singular values are not well determined by the data */
610 /* > and are considered as noisy; the matrix is treated as */
611 /* > numerically rank deficient. The error in the computed */
612 /* > singular values is bounded by f(m,n)*epsilon*||A||. */
613 /* > The computed SVD A = U * S * V^* restores A up to */
614 /* > f(m,n)*epsilon*||A||. */
615 /* > This gives the procedure the licence to discard (set to zero) */
616 /* > all singular values below N*epsilon*||A||. */
617 /* > = 'R': Similar as in 'A'. Rank revealing property of the initial */
618 /* > QR factorization is used do reveal (using triangular factor) */
619 /* > a gap sigma_{r+1} < epsilon * sigma_r in which case the */
620 /* > numerical RANK is declared to be r. The SVD is computed with */
621 /* > absolute error bounds, but more accurately than with 'A'. */
624 /* > \param[in] JOBU */
626 /* > JOBU is CHARACTER*1 */
627 /* > Specifies whether to compute the columns of U: */
628 /* > = 'U': N columns of U are returned in the array U. */
629 /* > = 'F': full set of M left sing. vectors is returned in the array U. */
630 /* > = 'W': U may be used as workspace of length M*N. See the description */
632 /* > = 'N': U is not computed. */
635 /* > \param[in] JOBV */
637 /* > JOBV is CHARACTER*1 */
638 /* > Specifies whether to compute the matrix V: */
639 /* > = 'V': N columns of V are returned in the array V; Jacobi rotations */
640 /* > are not explicitly accumulated. */
641 /* > = 'J': N columns of V are returned in the array V, but they are */
642 /* > computed as the product of Jacobi rotations, if JOBT = 'N'. */
643 /* > = 'W': V may be used as workspace of length N*N. See the description */
645 /* > = 'N': V is not computed. */
648 /* > \param[in] JOBR */
650 /* > JOBR is CHARACTER*1 */
651 /* > Specifies the RANGE for the singular values. Issues the licence to */
652 /* > set to zero small positive singular values if they are outside */
653 /* > specified range. If A .NE. 0 is scaled so that the largest singular */
654 /* > value of c*A is around SQRT(BIG), BIG=SLAMCH('O'), then JOBR issues */
655 /* > the licence to kill columns of A whose norm in c*A is less than */
656 /* > SQRT(SFMIN) (for JOBR = 'R'), or less than SMALL=SFMIN/EPSLN, */
657 /* > where SFMIN=SLAMCH('S'), EPSLN=SLAMCH('E'). */
658 /* > = 'N': Do not kill small columns of c*A. This option assumes that */
659 /* > BLAS and QR factorizations and triangular solvers are */
660 /* > implemented to work in that range. If the condition of A */
661 /* > is greater than BIG, use CGESVJ. */
662 /* > = 'R': RESTRICTED range for sigma(c*A) is [SQRT(SFMIN), SQRT(BIG)] */
663 /* > (roughly, as described above). This option is recommended. */
664 /* > =========================== */
665 /* > For computing the singular values in the FULL range [SFMIN,BIG] */
669 /* > \param[in] JOBT */
671 /* > JOBT is CHARACTER*1 */
672 /* > If the matrix is square then the procedure may determine to use */
673 /* > transposed A if A^* seems to be better with respect to convergence. */
674 /* > If the matrix is not square, JOBT is ignored. */
675 /* > The decision is based on two values of entropy over the adjoint */
676 /* > orbit of A^* * A. See the descriptions of WORK(6) and WORK(7). */
677 /* > = 'T': transpose if entropy test indicates possibly faster */
678 /* > convergence of Jacobi process if A^* is taken as input. If A is */
679 /* > replaced with A^*, then the row pivoting is included automatically. */
680 /* > = 'N': do not speculate. */
681 /* > The option 'T' can be used to compute only the singular values, or */
682 /* > the full SVD (U, SIGMA and V). For only one set of singular vectors */
683 /* > (U or V), the caller should provide both U and V, as one of the */
684 /* > matrices is used as workspace if the matrix A is transposed. */
685 /* > The implementer can easily remove this constraint and make the */
686 /* > code more complicated. See the descriptions of U and V. */
687 /* > In general, this option is considered experimental, and 'N'; should */
688 /* > be preferred. This is subject to changes in the future. */
691 /* > \param[in] JOBP */
693 /* > JOBP is CHARACTER*1 */
694 /* > Issues the licence to introduce structured perturbations to drown */
695 /* > denormalized numbers. This licence should be active if the */
696 /* > denormals are poorly implemented, causing slow computation, */
697 /* > especially in cases of fast convergence (!). For details see [1,2]. */
698 /* > For the sake of simplicity, this perturbations are included only */
699 /* > when the full SVD or only the singular values are requested. The */
700 /* > implementer/user can easily add the perturbation for the cases of */
701 /* > computing one set of singular vectors. */
702 /* > = 'P': introduce perturbation */
703 /* > = 'N': do not perturb */
709 /* > The number of rows of the input matrix A. M >= 0. */
715 /* > The number of columns of the input matrix A. M >= N >= 0. */
718 /* > \param[in,out] A */
720 /* > A is COMPLEX array, dimension (LDA,N) */
721 /* > On entry, the M-by-N matrix A. */
724 /* > \param[in] LDA */
726 /* > LDA is INTEGER */
727 /* > The leading dimension of the array A. LDA >= f2cmax(1,M). */
730 /* > \param[out] SVA */
732 /* > SVA is REAL array, dimension (N) */
734 /* > - For WORK(1)/WORK(2) = ONE: The singular values of A. During the */
735 /* > computation SVA contains Euclidean column norms of the */
736 /* > iterated matrices in the array A. */
737 /* > - For WORK(1) .NE. WORK(2): The singular values of A are */
738 /* > (WORK(1)/WORK(2)) * SVA(1:N). This factored form is used if */
739 /* > sigma_max(A) overflows or if small singular values have been */
740 /* > saved from underflow by scaling the input matrix A. */
741 /* > - If JOBR='R' then some of the singular values may be returned */
742 /* > as exact zeros obtained by "set to zero" because they are */
743 /* > below the numerical rank threshold or are denormalized numbers. */
746 /* > \param[out] U */
748 /* > U is COMPLEX array, dimension ( LDU, N ) or ( LDU, M ) */
749 /* > If JOBU = 'U', then U contains on exit the M-by-N matrix of */
750 /* > the left singular vectors. */
751 /* > If JOBU = 'F', then U contains on exit the M-by-M matrix of */
752 /* > the left singular vectors, including an ONB */
753 /* > of the orthogonal complement of the Range(A). */
754 /* > If JOBU = 'W' .AND. (JOBV = 'V' .AND. JOBT = 'T' .AND. M = N), */
755 /* > then U is used as workspace if the procedure */
756 /* > replaces A with A^*. In that case, [V] is computed */
757 /* > in U as left singular vectors of A^* and then */
758 /* > copied back to the V array. This 'W' option is just */
759 /* > a reminder to the caller that in this case U is */
760 /* > reserved as workspace of length N*N. */
761 /* > If JOBU = 'N' U is not referenced, unless JOBT='T'. */
764 /* > \param[in] LDU */
766 /* > LDU is INTEGER */
767 /* > The leading dimension of the array U, LDU >= 1. */
768 /* > IF JOBU = 'U' or 'F' or 'W', then LDU >= M. */
771 /* > \param[out] V */
773 /* > V is COMPLEX array, dimension ( LDV, N ) */
774 /* > If JOBV = 'V', 'J' then V contains on exit the N-by-N matrix of */
775 /* > the right singular vectors; */
776 /* > If JOBV = 'W', AND (JOBU = 'U' AND JOBT = 'T' AND M = N), */
777 /* > then V is used as workspace if the pprocedure */
778 /* > replaces A with A^*. In that case, [U] is computed */
779 /* > in V as right singular vectors of A^* and then */
780 /* > copied back to the U array. This 'W' option is just */
781 /* > a reminder to the caller that in this case V is */
782 /* > reserved as workspace of length N*N. */
783 /* > If JOBV = 'N' V is not referenced, unless JOBT='T'. */
786 /* > \param[in] LDV */
788 /* > LDV is INTEGER */
789 /* > The leading dimension of the array V, LDV >= 1. */
790 /* > If JOBV = 'V' or 'J' or 'W', then LDV >= N. */
793 /* > \param[out] CWORK */
795 /* > CWORK is COMPLEX array, dimension (MAX(2,LWORK)) */
796 /* > If the call to CGEJSV is a workspace query (indicated by LWORK=-1 or */
797 /* > LRWORK=-1), then on exit CWORK(1) contains the required length of */
798 /* > CWORK for the job parameters used in the call. */
801 /* > \param[in] LWORK */
803 /* > LWORK is INTEGER */
804 /* > Length of CWORK to confirm proper allocation of workspace. */
805 /* > LWORK depends on the job: */
807 /* > 1. If only SIGMA is needed ( JOBU = 'N', JOBV = 'N' ) and */
808 /* > 1.1 .. no scaled condition estimate required (JOBA.NE.'E'.AND.JOBA.NE.'G'): */
809 /* > LWORK >= 2*N+1. This is the minimal requirement. */
810 /* > ->> For optimal performance (blocked code) the optimal value */
811 /* > is LWORK >= N + (N+1)*NB. Here NB is the optimal */
812 /* > block size for CGEQP3 and CGEQRF. */
813 /* > In general, optimal LWORK is computed as */
814 /* > LWORK >= f2cmax(N+LWORK(CGEQP3),N+LWORK(CGEQRF), LWORK(CGESVJ)). */
815 /* > 1.2. .. an estimate of the scaled condition number of A is */
816 /* > required (JOBA='E', or 'G'). In this case, LWORK the minimal */
817 /* > requirement is LWORK >= N*N + 2*N. */
818 /* > ->> For optimal performance (blocked code) the optimal value */
819 /* > is LWORK >= f2cmax(N+(N+1)*NB, N*N+2*N)=N**2+2*N. */
820 /* > In general, the optimal length LWORK is computed as */
821 /* > LWORK >= f2cmax(N+LWORK(CGEQP3),N+LWORK(CGEQRF), LWORK(CGESVJ), */
822 /* > N*N+LWORK(CPOCON)). */
823 /* > 2. If SIGMA and the right singular vectors are needed (JOBV = 'V'), */
825 /* > 2.1 .. no scaled condition estimate requested (JOBE = 'N'): */
826 /* > -> the minimal requirement is LWORK >= 3*N. */
827 /* > -> For optimal performance, */
828 /* > LWORK >= f2cmax(N+(N+1)*NB, 2*N+N*NB)=2*N+N*NB, */
829 /* > where NB is the optimal block size for CGEQP3, CGEQRF, CGELQ, */
830 /* > CUNMLQ. In general, the optimal length LWORK is computed as */
831 /* > LWORK >= f2cmax(N+LWORK(CGEQP3), N+LWORK(CGESVJ), */
832 /* > N+LWORK(CGELQF), 2*N+LWORK(CGEQRF), N+LWORK(CUNMLQ)). */
833 /* > 2.2 .. an estimate of the scaled condition number of A is */
834 /* > required (JOBA='E', or 'G'). */
835 /* > -> the minimal requirement is LWORK >= 3*N. */
836 /* > -> For optimal performance, */
837 /* > LWORK >= f2cmax(N+(N+1)*NB, 2*N,2*N+N*NB)=2*N+N*NB, */
838 /* > where NB is the optimal block size for CGEQP3, CGEQRF, CGELQ, */
839 /* > CUNMLQ. In general, the optimal length LWORK is computed as */
840 /* > LWORK >= f2cmax(N+LWORK(CGEQP3), LWORK(CPOCON), N+LWORK(CGESVJ), */
841 /* > N+LWORK(CGELQF), 2*N+LWORK(CGEQRF), N+LWORK(CUNMLQ)). */
842 /* > 3. If SIGMA and the left singular vectors are needed */
843 /* > 3.1 .. no scaled condition estimate requested (JOBE = 'N'): */
844 /* > -> the minimal requirement is LWORK >= 3*N. */
845 /* > -> For optimal performance: */
846 /* > if JOBU = 'U' :: LWORK >= f2cmax(3*N, N+(N+1)*NB, 2*N+N*NB)=2*N+N*NB, */
847 /* > where NB is the optimal block size for CGEQP3, CGEQRF, CUNMQR. */
848 /* > In general, the optimal length LWORK is computed as */
849 /* > LWORK >= f2cmax(N+LWORK(CGEQP3), 2*N+LWORK(CGEQRF), N+LWORK(CUNMQR)). */
850 /* > 3.2 .. an estimate of the scaled condition number of A is */
851 /* > required (JOBA='E', or 'G'). */
852 /* > -> the minimal requirement is LWORK >= 3*N. */
853 /* > -> For optimal performance: */
854 /* > if JOBU = 'U' :: LWORK >= f2cmax(3*N, N+(N+1)*NB, 2*N+N*NB)=2*N+N*NB, */
855 /* > where NB is the optimal block size for CGEQP3, CGEQRF, CUNMQR. */
856 /* > In general, the optimal length LWORK is computed as */
857 /* > LWORK >= f2cmax(N+LWORK(CGEQP3),N+LWORK(CPOCON), */
858 /* > 2*N+LWORK(CGEQRF), N+LWORK(CUNMQR)). */
860 /* > 4. If the full SVD is needed: (JOBU = 'U' or JOBU = 'F') and */
861 /* > 4.1. if JOBV = 'V' */
862 /* > the minimal requirement is LWORK >= 5*N+2*N*N. */
863 /* > 4.2. if JOBV = 'J' the minimal requirement is */
864 /* > LWORK >= 4*N+N*N. */
865 /* > In both cases, the allocated CWORK can accommodate blocked runs */
866 /* > of CGEQP3, CGEQRF, CGELQF, CUNMQR, CUNMLQ. */
868 /* > If the call to CGEJSV is a workspace query (indicated by LWORK=-1 or */
869 /* > LRWORK=-1), then on exit CWORK(1) contains the optimal and CWORK(2) contains the */
870 /* > minimal length of CWORK for the job parameters used in the call. */
873 /* > \param[out] RWORK */
875 /* > RWORK is REAL array, dimension (MAX(7,LWORK)) */
877 /* > RWORK(1) = Determines the scaling factor SCALE = RWORK(2) / RWORK(1) */
878 /* > such that SCALE*SVA(1:N) are the computed singular values */
879 /* > of A. (See the description of SVA().) */
880 /* > RWORK(2) = See the description of RWORK(1). */
881 /* > RWORK(3) = SCONDA is an estimate for the condition number of */
882 /* > column equilibrated A. (If JOBA = 'E' or 'G') */
883 /* > SCONDA is an estimate of SQRT(||(R^* * R)^(-1)||_1). */
884 /* > It is computed using SPOCON. It holds */
885 /* > N^(-1/4) * SCONDA <= ||R^(-1)||_2 <= N^(1/4) * SCONDA */
886 /* > where R is the triangular factor from the QRF of A. */
887 /* > However, if R is truncated and the numerical rank is */
888 /* > determined to be strictly smaller than N, SCONDA is */
889 /* > returned as -1, thus indicating that the smallest */
890 /* > singular values might be lost. */
892 /* > If full SVD is needed, the following two condition numbers are */
893 /* > useful for the analysis of the algorithm. They are provied for */
894 /* > a developer/implementer who is familiar with the details of */
897 /* > RWORK(4) = an estimate of the scaled condition number of the */
898 /* > triangular factor in the first QR factorization. */
899 /* > RWORK(5) = an estimate of the scaled condition number of the */
900 /* > triangular factor in the second QR factorization. */
901 /* > The following two parameters are computed if JOBT = 'T'. */
902 /* > They are provided for a developer/implementer who is familiar */
903 /* > with the details of the method. */
904 /* > RWORK(6) = the entropy of A^* * A :: this is the Shannon entropy */
905 /* > of diag(A^* * A) / Trace(A^* * A) taken as point in the */
906 /* > probability simplex. */
907 /* > RWORK(7) = the entropy of A * A^*. (See the description of RWORK(6).) */
908 /* > If the call to CGEJSV is a workspace query (indicated by LWORK=-1 or */
909 /* > LRWORK=-1), then on exit RWORK(1) contains the required length of */
910 /* > RWORK for the job parameters used in the call. */
913 /* > \param[in] LRWORK */
915 /* > LRWORK is INTEGER */
916 /* > Length of RWORK to confirm proper allocation of workspace. */
917 /* > LRWORK depends on the job: */
919 /* > 1. If only the singular values are requested i.e. if */
920 /* > LSAME(JOBU,'N') .AND. LSAME(JOBV,'N') */
922 /* > 1.1. If LSAME(JOBT,'T') .OR. LSAME(JOBA,'F') .OR. LSAME(JOBA,'G'), */
923 /* > then: LRWORK = f2cmax( 7, 2 * M ). */
924 /* > 1.2. Otherwise, LRWORK = f2cmax( 7, N ). */
925 /* > 2. If singular values with the right singular vectors are requested */
927 /* > (LSAME(JOBV,'V').OR.LSAME(JOBV,'J')) .AND. */
928 /* > .NOT.(LSAME(JOBU,'U').OR.LSAME(JOBU,'F')) */
930 /* > 2.1. If LSAME(JOBT,'T') .OR. LSAME(JOBA,'F') .OR. LSAME(JOBA,'G'), */
931 /* > then LRWORK = f2cmax( 7, 2 * M ). */
932 /* > 2.2. Otherwise, LRWORK = f2cmax( 7, N ). */
933 /* > 3. If singular values with the left singular vectors are requested, i.e. if */
934 /* > (LSAME(JOBU,'U').OR.LSAME(JOBU,'F')) .AND. */
935 /* > .NOT.(LSAME(JOBV,'V').OR.LSAME(JOBV,'J')) */
937 /* > 3.1. If LSAME(JOBT,'T') .OR. LSAME(JOBA,'F') .OR. LSAME(JOBA,'G'), */
938 /* > then LRWORK = f2cmax( 7, 2 * M ). */
939 /* > 3.2. Otherwise, LRWORK = f2cmax( 7, N ). */
940 /* > 4. If singular values with both the left and the right singular vectors */
941 /* > are requested, i.e. if */
942 /* > (LSAME(JOBU,'U').OR.LSAME(JOBU,'F')) .AND. */
943 /* > (LSAME(JOBV,'V').OR.LSAME(JOBV,'J')) */
945 /* > 4.1. If LSAME(JOBT,'T') .OR. LSAME(JOBA,'F') .OR. LSAME(JOBA,'G'), */
946 /* > then LRWORK = f2cmax( 7, 2 * M ). */
947 /* > 4.2. Otherwise, LRWORK = f2cmax( 7, N ). */
949 /* > If, on entry, LRWORK = -1 or LWORK=-1, a workspace query is assumed and */
950 /* > the length of RWORK is returned in RWORK(1). */
953 /* > \param[out] IWORK */
955 /* > IWORK is INTEGER array, of dimension at least 4, that further depends */
958 /* > 1. If only the singular values are requested then: */
959 /* > If ( LSAME(JOBT,'T') .OR. LSAME(JOBA,'F') .OR. LSAME(JOBA,'G') ) */
960 /* > then the length of IWORK is N+M; otherwise the length of IWORK is N. */
961 /* > 2. If the singular values and the right singular vectors are requested then: */
962 /* > If ( LSAME(JOBT,'T') .OR. LSAME(JOBA,'F') .OR. LSAME(JOBA,'G') ) */
963 /* > then the length of IWORK is N+M; otherwise the length of IWORK is N. */
964 /* > 3. If the singular values and the left singular vectors are requested then: */
965 /* > If ( LSAME(JOBT,'T') .OR. LSAME(JOBA,'F') .OR. LSAME(JOBA,'G') ) */
966 /* > then the length of IWORK is N+M; otherwise the length of IWORK is N. */
967 /* > 4. If the singular values with both the left and the right singular vectors */
968 /* > are requested, then: */
969 /* > 4.1. If LSAME(JOBV,'J') the length of IWORK is determined as follows: */
970 /* > If ( LSAME(JOBT,'T') .OR. LSAME(JOBA,'F') .OR. LSAME(JOBA,'G') ) */
971 /* > then the length of IWORK is N+M; otherwise the length of IWORK is N. */
972 /* > 4.2. If LSAME(JOBV,'V') the length of IWORK is determined as follows: */
973 /* > If ( LSAME(JOBT,'T') .OR. LSAME(JOBA,'F') .OR. LSAME(JOBA,'G') ) */
974 /* > then the length of IWORK is 2*N+M; otherwise the length of IWORK is 2*N. */
977 /* > IWORK(1) = the numerical rank determined after the initial */
978 /* > QR factorization with pivoting. See the descriptions */
979 /* > of JOBA and JOBR. */
980 /* > IWORK(2) = the number of the computed nonzero singular values */
981 /* > IWORK(3) = if nonzero, a warning message: */
982 /* > If IWORK(3) = 1 then some of the column norms of A */
983 /* > were denormalized floats. The requested high accuracy */
984 /* > is not warranted by the data. */
985 /* > IWORK(4) = 1 or -1. If IWORK(4) = 1, then the procedure used A^* to */
986 /* > do the job as specified by the JOB parameters. */
987 /* > If the call to CGEJSV is a workspace query (indicated by LWORK = -1 and */
988 /* > LRWORK = -1), then on exit IWORK(1) contains the required length of */
989 /* > IWORK for the job parameters used in the call. */
992 /* > \param[out] INFO */
994 /* > INFO is INTEGER */
995 /* > < 0: if INFO = -i, then the i-th argument had an illegal value. */
996 /* > = 0: successful exit; */
997 /* > > 0: CGEJSV did not converge in the maximal allowed number */
998 /* > of sweeps. The computed values may be inaccurate. */
1004 /* > \author Univ. of Tennessee */
1005 /* > \author Univ. of California Berkeley */
1006 /* > \author Univ. of Colorado Denver */
1007 /* > \author NAG Ltd. */
1009 /* > \date June 2016 */
1011 /* > \ingroup complexGEsing */
1013 /* > \par Further Details: */
1014 /* ===================== */
1017 /* > CGEJSV implements a preconditioned Jacobi SVD algorithm. It uses CGEQP3, */
1018 /* > CGEQRF, and CGELQF as preprocessors and preconditioners. Optionally, an */
1019 /* > additional row pivoting can be used as a preprocessor, which in some */
1020 /* > cases results in much higher accuracy. An example is matrix A with the */
1021 /* > structure A = D1 * C * D2, where D1, D2 are arbitrarily ill-conditioned */
1022 /* > diagonal matrices and C is well-conditioned matrix. In that case, complete */
1023 /* > pivoting in the first QR factorizations provides accuracy dependent on the */
1024 /* > condition number of C, and independent of D1, D2. Such higher accuracy is */
1025 /* > not completely understood theoretically, but it works well in practice. */
1026 /* > Further, if A can be written as A = B*D, with well-conditioned B and some */
1027 /* > diagonal D, then the high accuracy is guaranteed, both theoretically and */
1028 /* > in software, independent of D. For more details see [1], [2]. */
1029 /* > The computational range for the singular values can be the full range */
1030 /* > ( UNDERFLOW,OVERFLOW ), provided that the machine arithmetic and the BLAS */
1031 /* > & LAPACK routines called by CGEJSV are implemented to work in that range. */
1032 /* > If that is not the case, then the restriction for safe computation with */
1033 /* > the singular values in the range of normalized IEEE numbers is that the */
1034 /* > spectral condition number kappa(A)=sigma_max(A)/sigma_min(A) does not */
1035 /* > overflow. This code (CGEJSV) is best used in this restricted range, */
1036 /* > meaning that singular values of magnitude below ||A||_2 / SLAMCH('O') are */
1037 /* > returned as zeros. See JOBR for details on this. */
1038 /* > Further, this implementation is somewhat slower than the one described */
1039 /* > in [1,2] due to replacement of some non-LAPACK components, and because */
1040 /* > the choice of some tuning parameters in the iterative part (CGESVJ) is */
1041 /* > left to the implementer on a particular machine. */
1042 /* > The rank revealing QR factorization (in this code: CGEQP3) should be */
1043 /* > implemented as in [3]. We have a new version of CGEQP3 under development */
1044 /* > that is more robust than the current one in LAPACK, with a cleaner cut in */
1045 /* > rank deficient cases. It will be available in the SIGMA library [4]. */
1046 /* > If M is much larger than N, it is obvious that the initial QRF with */
1047 /* > column pivoting can be preprocessed by the QRF without pivoting. That */
1048 /* > well known trick is not used in CGEJSV because in some cases heavy row */
1049 /* > weighting can be treated with complete pivoting. The overhead in cases */
1050 /* > M much larger than N is then only due to pivoting, but the benefits in */
1051 /* > terms of accuracy have prevailed. The implementer/user can incorporate */
1052 /* > this extra QRF step easily. The implementer can also improve data movement */
1053 /* > (matrix transpose, matrix copy, matrix transposed copy) - this */
1054 /* > implementation of CGEJSV uses only the simplest, naive data movement. */
1055 /* > \endverbatim */
1057 /* > \par Contributor: */
1058 /* ================== */
1060 /* > Zlatko Drmac (Zagreb, Croatia) */
1062 /* > \par References: */
1063 /* ================ */
1067 /* > [1] Z. Drmac and K. Veselic: New fast and accurate Jacobi SVD algorithm I. */
1068 /* > SIAM J. Matrix Anal. Appl. Vol. 35, No. 2 (2008), pp. 1322-1342. */
1069 /* > LAPACK Working note 169. */
1070 /* > [2] Z. Drmac and K. Veselic: New fast and accurate Jacobi SVD algorithm II. */
1071 /* > SIAM J. Matrix Anal. Appl. Vol. 35, No. 2 (2008), pp. 1343-1362. */
1072 /* > LAPACK Working note 170. */
1073 /* > [3] Z. Drmac and Z. Bujanovic: On the failure of rank-revealing QR */
1074 /* > factorization software - a case study. */
1075 /* > ACM Trans. Math. Softw. Vol. 35, No 2 (2008), pp. 1-28. */
1076 /* > LAPACK Working note 176. */
1077 /* > [4] Z. Drmac: SIGMA - mathematical software library for accurate SVD, PSV, */
1078 /* > QSVD, (H,K)-SVD computations. */
1079 /* > Department of Mathematics, University of Zagreb, 2008, 2016. */
1080 /* > \endverbatim */
1082 /* > \par Bugs, examples and comments: */
1083 /* ================================= */
1085 /* > Please report all bugs and send interesting examples and/or comments to */
1086 /* > drmac@math.hr. Thank you. */
1088 /* ===================================================================== */
1089 /* Subroutine */ int cgejsv_(char *joba, char *jobu, char *jobv, char *jobr,
1090 char *jobt, char *jobp, integer *m, integer *n, complex *a, integer *
1091 lda, real *sva, complex *u, integer *ldu, complex *v, integer *ldv,
1092 complex *cwork, integer *lwork, real *rwork, integer *lrwork, integer
1093 *iwork, integer *info)
1095 /* System generated locals */
1096 integer a_dim1, a_offset, u_dim1, u_offset, v_dim1, v_offset, i__1, i__2,
1097 i__3, i__4, i__5, i__6, i__7, i__8, i__9, i__10, i__11;
1098 real r__1, r__2, r__3;
1101 /* Local variables */
1102 integer lwrk_cunmqr__;
1106 integer ierr, lwrk_cgeqp3n__;
1108 integer lwunmqrm, lwrk_cgesvju__, lwrk_cgesvjv__, lwqp3, lwrk_cunmqrm__,
1111 extern logical lsame_(char *, char *);
1112 extern /* Subroutine */ int sscal_(integer *, real *, real *, integer *);
1118 extern /* Subroutine */ int ccopy_(integer *, complex *, integer *,
1119 complex *, integer *), cswap_(integer *, complex *, integer *,
1120 complex *, integer *);
1123 integer lwcon, lwlqf;
1124 extern /* Subroutine */ int ctrsm_(char *, char *, char *, char *,
1125 integer *, integer *, complex *, complex *, integer *, complex *,
1129 extern /* Subroutine */ int cgeqp3_(integer *, integer *, complex *,
1130 integer *, integer *, complex *, complex *, integer *, real *,
1132 real condr1, condr2, uscal1, uscal2;
1133 logical l2kill, l2rank, l2tran;
1134 extern real scnrm2_(integer *, complex *, integer *);
1137 extern /* Subroutine */ int clacgv_(integer *, complex *, integer *);
1139 extern /* Subroutine */ int cgelqf_(integer *, integer *, complex *,
1140 integer *, complex *, complex *, integer *, integer *);
1141 extern integer icamax_(integer *, complex *, integer *);
1142 extern /* Subroutine */ int clascl_(char *, integer *, integer *, real *,
1143 real *, integer *, integer *, complex *, integer *, integer *);
1144 real scalem, sconda;
1147 extern real slamch_(char *);
1149 extern /* Subroutine */ int cgeqrf_(integer *, integer *, complex *,
1150 integer *, complex *, complex *, integer *, integer *), clacpy_(
1151 char *, integer *, integer *, complex *, integer *, complex *,
1152 integer *), clapmr_(logical *, integer *, integer *,
1153 complex *, integer *, integer *);
1155 extern /* Subroutine */ int claset_(char *, integer *, integer *, complex
1156 *, complex *, complex *, integer *);
1157 extern integer isamax_(integer *, real *, integer *);
1158 extern /* Subroutine */ int slascl_(char *, integer *, integer *, real *,
1159 real *, integer *, integer *, real *, integer *, integer *), cpocon_(char *, integer *, complex *, integer *, real *,
1160 real *, complex *, real *, integer *), csscal_(integer *,
1161 real *, complex *, integer *), classq_(integer *, complex *,
1162 integer *, real *, real *), xerbla_(char *, integer *, ftnlen),
1163 cgesvj_(char *, char *, char *, integer *, integer *, complex *,
1164 integer *, real *, integer *, complex *, integer *, complex *,
1165 integer *, real *, integer *, integer *),
1166 claswp_(integer *, complex *, integer *, integer *, integer *,
1167 integer *, integer *);
1171 extern /* Subroutine */ int cungqr_(integer *, integer *, integer *,
1172 complex *, integer *, complex *, complex *, integer *, integer *);
1174 extern /* Subroutine */ int cunmlq_(char *, char *, integer *, integer *,
1175 integer *, complex *, integer *, complex *, complex *, integer *,
1176 complex *, integer *, integer *);
1179 extern /* Subroutine */ int slassq_(integer *, real *, integer *, real *,
1182 integer minwrk, lwsvdj;
1183 extern /* Subroutine */ int cunmqr_(char *, char *, integer *, integer *,
1184 integer *, complex *, integer *, complex *, complex *, integer *,
1185 complex *, integer *, integer *);
1187 logical lquery, rowpiv;
1190 integer lwrk_cgeqp3__;
1191 real cond_ok__, xsc, big1;
1192 integer warning, numrank, lwrk_cgelqf__, miniwrk, lwrk_cgeqrf__, minrwrk,
1193 lrwsvdj, lwunmlq, lwsvdjv, lwrk_cgesvj__, lwunmqr, lwrk_cunmlq__;
1196 /* -- LAPACK computational routine (version 3.7.1) -- */
1197 /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
1198 /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
1202 /* =========================================================================== */
1208 /* Test the input arguments */
1210 /* Parameter adjustments */
1213 a_offset = 1 + a_dim1 * 1;
1216 u_offset = 1 + u_dim1 * 1;
1219 v_offset = 1 + v_dim1 * 1;
1226 lsvec = lsame_(jobu, "U") || lsame_(jobu, "F");
1227 jracc = lsame_(jobv, "J");
1228 rsvec = lsame_(jobv, "V") || jracc;
1229 rowpiv = lsame_(joba, "F") || lsame_(joba, "G");
1230 l2rank = lsame_(joba, "R");
1231 l2aber = lsame_(joba, "A");
1232 errest = lsame_(joba, "E") || lsame_(joba, "G");
1233 l2tran = lsame_(jobt, "T") && *m == *n;
1234 l2kill = lsame_(jobr, "R");
1235 defr = lsame_(jobr, "N");
1236 l2pert = lsame_(jobp, "P");
1238 lquery = *lwork == -1 || *lrwork == -1;
1240 if (! (rowpiv || l2rank || l2aber || errest || lsame_(joba, "C"))) {
1242 } else if (! (lsvec || lsame_(jobu, "N") || lsame_(
1243 jobu, "W") && rsvec && l2tran)) {
1245 } else if (! (rsvec || lsame_(jobv, "N") || lsame_(
1246 jobv, "W") && lsvec && l2tran)) {
1248 } else if (! (l2kill || defr)) {
1250 } else if (! (lsame_(jobt, "T") || lsame_(jobt,
1253 } else if (! (l2pert || lsame_(jobp, "N"))) {
1255 } else if (*m < 0) {
1257 } else if (*n < 0 || *n > *m) {
1259 } else if (*lda < *m) {
1261 } else if (lsvec && *ldu < *m) {
1263 } else if (rsvec && *ldv < *n) {
1271 /* [[The expressions for computing the minimal and the optimal */
1272 /* values of LCWORK, LRWORK are written with a lot of redundancy and */
1273 /* can be simplified. However, this verbose form is useful for */
1274 /* maintenance and modifications of the code.]] */
1276 /* CGEQRF of an N x N matrix, CGELQF of an N x N matrix, */
1277 /* CUNMLQ for computing N x N matrix, CUNMQR for computing N x N */
1278 /* matrix, CUNMQR for computing M x N matrix, respectively. */
1280 lwqrf = f2cmax(1,*n);
1281 lwlqf = f2cmax(1,*n);
1282 lwunmlq = f2cmax(1,*n);
1283 lwunmqr = f2cmax(1,*n);
1284 lwunmqrm = f2cmax(1,*m);
1286 /* without and with explicit accumulation of Jacobi rotations */
1289 lwsvdj = f2cmax(i__1,1);
1292 lwsvdjv = f2cmax(i__1,1);
1297 cgeqp3_(m, n, &a[a_offset], lda, &iwork[1], cdummy, cdummy, &c_n1,
1299 lwrk_cgeqp3__ = cdummy[0].r;
1300 cgeqrf_(n, n, &a[a_offset], lda, cdummy, cdummy, &c_n1, &ierr);
1301 lwrk_cgeqrf__ = cdummy[0].r;
1302 cgelqf_(n, n, &a[a_offset], lda, cdummy, cdummy, &c_n1, &ierr);
1303 lwrk_cgelqf__ = cdummy[0].r;
1308 if (! (lsvec || rsvec)) {
1309 /* only the singular values are requested */
1312 /* Computing 2nd power */
1314 i__1 = *n + lwqp3, i__2 = i__3 * i__3 + lwcon, i__1 = f2cmax(
1315 i__1,i__2), i__2 = *n + lwqrf, i__1 = f2cmax(i__1,i__2);
1316 minwrk = f2cmax(i__1,lwsvdj);
1319 i__1 = *n + lwqp3, i__2 = *n + lwqrf, i__1 = f2cmax(i__1,i__2);
1320 minwrk = f2cmax(i__1,lwsvdj);
1323 cgesvj_("L", "N", "N", n, n, &a[a_offset], lda, &sva[1], n, &
1324 v[v_offset], ldv, cdummy, &c_n1, rdummy, &c_n1, &ierr);
1325 lwrk_cgesvj__ = cdummy[0].r;
1328 /* Computing 2nd power */
1330 i__1 = *n + lwrk_cgeqp3__, i__2 = i__3 * i__3 + lwcon,
1331 i__1 = f2cmax(i__1,i__2), i__2 = *n + lwrk_cgeqrf__,
1332 i__1 = f2cmax(i__1,i__2);
1333 optwrk = f2cmax(i__1,lwrk_cgesvj__);
1336 i__1 = *n + lwrk_cgeqp3__, i__2 = *n + lwrk_cgeqrf__,
1337 i__1 = f2cmax(i__1,i__2);
1338 optwrk = f2cmax(i__1,lwrk_cgesvj__);
1341 if (l2tran || rowpiv) {
1344 i__1 = 7, i__2 = *m << 1, i__1 = f2cmax(i__1,i__2), i__1 =
1345 f2cmax(i__1,lrwqp3), i__1 = f2cmax(i__1,lrwcon);
1346 minrwrk = f2cmax(i__1,lrwsvdj);
1349 i__1 = 7, i__2 = *m << 1, i__1 = f2cmax(i__1,i__2), i__1 =
1350 f2cmax(i__1,lrwqp3);
1351 minrwrk = f2cmax(i__1,lrwsvdj);
1356 i__1 = f2cmax(7,lrwqp3), i__1 = f2cmax(i__1,lrwcon);
1357 minrwrk = f2cmax(i__1,lrwsvdj);
1360 i__1 = f2cmax(7,lrwqp3);
1361 minrwrk = f2cmax(i__1,lrwsvdj);
1364 if (rowpiv || l2tran) {
1367 } else if (rsvec && ! lsvec) {
1368 /* singular values and the right singular vectors are requested */
1371 i__1 = *n + lwqp3, i__1 = f2cmax(i__1,lwcon), i__1 = f2cmax(i__1,
1372 lwsvdj), i__2 = *n + lwlqf, i__1 = f2cmax(i__1,i__2),
1373 i__2 = (*n << 1) + lwqrf, i__1 = f2cmax(i__1,i__2), i__2
1374 = *n + lwsvdj, i__1 = f2cmax(i__1,i__2), i__2 = *n +
1376 minwrk = f2cmax(i__1,i__2);
1379 i__1 = *n + lwqp3, i__1 = f2cmax(i__1,lwsvdj), i__2 = *n + lwlqf,
1380 i__1 = f2cmax(i__1,i__2), i__2 = (*n << 1) + lwqrf,
1381 i__1 = f2cmax(i__1,i__2), i__2 = *n + lwsvdj, i__1 = f2cmax(
1382 i__1,i__2), i__2 = *n + lwunmlq;
1383 minwrk = f2cmax(i__1,i__2);
1386 cgesvj_("L", "U", "N", n, n, &u[u_offset], ldu, &sva[1], n, &
1387 a[a_offset], lda, cdummy, &c_n1, rdummy, &c_n1, &ierr);
1388 lwrk_cgesvj__ = cdummy[0].r;
1389 cunmlq_("L", "C", n, n, n, &a[a_offset], lda, cdummy, &v[
1390 v_offset], ldv, cdummy, &c_n1, &ierr);
1391 lwrk_cunmlq__ = cdummy[0].r;
1394 i__1 = *n + lwrk_cgeqp3__, i__1 = f2cmax(i__1,lwcon), i__1 =
1395 f2cmax(i__1,lwrk_cgesvj__), i__2 = *n +
1396 lwrk_cgelqf__, i__1 = f2cmax(i__1,i__2), i__2 = (*n
1397 << 1) + lwrk_cgeqrf__, i__1 = f2cmax(i__1,i__2),
1398 i__2 = *n + lwrk_cgesvj__, i__1 = f2cmax(i__1,i__2),
1399 i__2 = *n + lwrk_cunmlq__;
1400 optwrk = f2cmax(i__1,i__2);
1403 i__1 = *n + lwrk_cgeqp3__, i__1 = f2cmax(i__1,lwrk_cgesvj__),
1404 i__2 = *n + lwrk_cgelqf__, i__1 = f2cmax(i__1,i__2),
1405 i__2 = (*n << 1) + lwrk_cgeqrf__, i__1 = f2cmax(
1406 i__1,i__2), i__2 = *n + lwrk_cgesvj__, i__1 = f2cmax(
1407 i__1,i__2), i__2 = *n + lwrk_cunmlq__;
1408 optwrk = f2cmax(i__1,i__2);
1411 if (l2tran || rowpiv) {
1414 i__1 = 7, i__2 = *m << 1, i__1 = f2cmax(i__1,i__2), i__1 =
1415 f2cmax(i__1,lrwqp3), i__1 = f2cmax(i__1,lrwsvdj);
1416 minrwrk = f2cmax(i__1,lrwcon);
1419 i__1 = 7, i__2 = *m << 1, i__1 = f2cmax(i__1,i__2), i__1 =
1420 f2cmax(i__1,lrwqp3);
1421 minrwrk = f2cmax(i__1,lrwsvdj);
1426 i__1 = f2cmax(7,lrwqp3), i__1 = f2cmax(i__1,lrwsvdj);
1427 minrwrk = f2cmax(i__1,lrwcon);
1430 i__1 = f2cmax(7,lrwqp3);
1431 minrwrk = f2cmax(i__1,lrwsvdj);
1434 if (rowpiv || l2tran) {
1437 } else if (lsvec && ! rsvec) {
1438 /* singular values and the left singular vectors are requested */
1441 i__1 = f2cmax(lwqp3,lwcon), i__2 = *n + lwqrf, i__1 = f2cmax(i__1,
1442 i__2), i__1 = f2cmax(i__1,lwsvdj);
1443 minwrk = *n + f2cmax(i__1,lwunmqrm);
1446 i__1 = lwqp3, i__2 = *n + lwqrf, i__1 = f2cmax(i__1,i__2), i__1 =
1447 f2cmax(i__1,lwsvdj);
1448 minwrk = *n + f2cmax(i__1,lwunmqrm);
1451 cgesvj_("L", "U", "N", n, n, &u[u_offset], ldu, &sva[1], n, &
1452 a[a_offset], lda, cdummy, &c_n1, rdummy, &c_n1, &ierr);
1453 lwrk_cgesvj__ = cdummy[0].r;
1454 cunmqr_("L", "N", m, n, n, &a[a_offset], lda, cdummy, &u[
1455 u_offset], ldu, cdummy, &c_n1, &ierr);
1456 lwrk_cunmqrm__ = cdummy[0].r;
1459 i__1 = f2cmax(lwrk_cgeqp3__,lwcon), i__2 = *n +
1460 lwrk_cgeqrf__, i__1 = f2cmax(i__1,i__2), i__1 = f2cmax(
1461 i__1,lwrk_cgesvj__);
1462 optwrk = *n + f2cmax(i__1,lwrk_cunmqrm__);
1465 i__1 = lwrk_cgeqp3__, i__2 = *n + lwrk_cgeqrf__, i__1 =
1466 f2cmax(i__1,i__2), i__1 = f2cmax(i__1,lwrk_cgesvj__);
1467 optwrk = *n + f2cmax(i__1,lwrk_cunmqrm__);
1470 if (l2tran || rowpiv) {
1473 i__1 = 7, i__2 = *m << 1, i__1 = f2cmax(i__1,i__2), i__1 =
1474 f2cmax(i__1,lrwqp3), i__1 = f2cmax(i__1,lrwsvdj);
1475 minrwrk = f2cmax(i__1,lrwcon);
1478 i__1 = 7, i__2 = *m << 1, i__1 = f2cmax(i__1,i__2), i__1 =
1479 f2cmax(i__1,lrwqp3);
1480 minrwrk = f2cmax(i__1,lrwsvdj);
1485 i__1 = f2cmax(7,lrwqp3), i__1 = f2cmax(i__1,lrwsvdj);
1486 minrwrk = f2cmax(i__1,lrwcon);
1489 i__1 = f2cmax(7,lrwqp3);
1490 minrwrk = f2cmax(i__1,lrwsvdj);
1493 if (rowpiv || l2tran) {
1497 /* full SVD is requested */
1501 /* Computing 2nd power */
1503 /* Computing 2nd power */
1505 /* Computing 2nd power */
1507 /* Computing 2nd power */
1509 /* Computing 2nd power */
1511 /* Computing 2nd power */
1513 /* Computing 2nd power */
1515 /* Computing 2nd power */
1517 /* Computing 2nd power */
1519 i__1 = *n + lwqp3, i__2 = *n + lwcon, i__1 = f2cmax(i__1,
1520 i__2), i__2 = (*n << 1) + i__3 * i__3 + lwcon,
1521 i__1 = f2cmax(i__1,i__2), i__2 = (*n << 1) + lwqrf,
1522 i__1 = f2cmax(i__1,i__2), i__2 = (*n << 1) + lwqp3,
1523 i__1 = f2cmax(i__1,i__2), i__2 = (*n << 1) + i__4 *
1524 i__4 + *n + lwlqf, i__1 = f2cmax(i__1,i__2), i__2 = (
1525 *n << 1) + i__5 * i__5 + *n + i__6 * i__6 + lwcon,
1526 i__1 = f2cmax(i__1,i__2), i__2 = (*n << 1) + i__7 *
1527 i__7 + *n + lwsvdj, i__1 = f2cmax(i__1,i__2), i__2 =
1528 (*n << 1) + i__8 * i__8 + *n + lwsvdjv, i__1 =
1529 f2cmax(i__1,i__2), i__2 = (*n << 1) + i__9 * i__9 + *
1530 n + lwunmqr, i__1 = f2cmax(i__1,i__2), i__2 = (*n <<
1531 1) + i__10 * i__10 + *n + lwunmlq, i__1 = f2cmax(
1532 i__1,i__2), i__2 = *n + i__11 * i__11 + lwsvdj,
1533 i__1 = f2cmax(i__1,i__2), i__2 = *n + lwunmqrm;
1534 minwrk = f2cmax(i__1,i__2);
1537 /* Computing 2nd power */
1539 /* Computing 2nd power */
1541 /* Computing 2nd power */
1543 /* Computing 2nd power */
1545 /* Computing 2nd power */
1547 /* Computing 2nd power */
1549 /* Computing 2nd power */
1551 /* Computing 2nd power */
1553 /* Computing 2nd power */
1555 i__1 = *n + lwqp3, i__2 = (*n << 1) + i__3 * i__3 + lwcon,
1556 i__1 = f2cmax(i__1,i__2), i__2 = (*n << 1) + lwqrf,
1557 i__1 = f2cmax(i__1,i__2), i__2 = (*n << 1) + lwqp3,
1558 i__1 = f2cmax(i__1,i__2), i__2 = (*n << 1) + i__4 *
1559 i__4 + *n + lwlqf, i__1 = f2cmax(i__1,i__2), i__2 = (
1560 *n << 1) + i__5 * i__5 + *n + i__6 * i__6 + lwcon,
1561 i__1 = f2cmax(i__1,i__2), i__2 = (*n << 1) + i__7 *
1562 i__7 + *n + lwsvdj, i__1 = f2cmax(i__1,i__2), i__2 =
1563 (*n << 1) + i__8 * i__8 + *n + lwsvdjv, i__1 =
1564 f2cmax(i__1,i__2), i__2 = (*n << 1) + i__9 * i__9 + *
1565 n + lwunmqr, i__1 = f2cmax(i__1,i__2), i__2 = (*n <<
1566 1) + i__10 * i__10 + *n + lwunmlq, i__1 = f2cmax(
1567 i__1,i__2), i__2 = *n + i__11 * i__11 + lwsvdj,
1568 i__1 = f2cmax(i__1,i__2), i__2 = *n + lwunmqrm;
1569 minwrk = f2cmax(i__1,i__2);
1572 if (rowpiv || l2tran) {
1578 /* Computing 2nd power */
1580 /* Computing 2nd power */
1582 i__1 = *n + lwqp3, i__2 = *n + lwcon, i__1 = f2cmax(i__1,
1583 i__2), i__2 = (*n << 1) + lwqrf, i__1 = f2cmax(i__1,
1584 i__2), i__2 = (*n << 1) + i__3 * i__3 + lwsvdjv,
1585 i__1 = f2cmax(i__1,i__2), i__2 = (*n << 1) + i__4 *
1586 i__4 + *n + lwunmqr, i__1 = f2cmax(i__1,i__2), i__2 =
1588 minwrk = f2cmax(i__1,i__2);
1591 /* Computing 2nd power */
1593 /* Computing 2nd power */
1595 i__1 = *n + lwqp3, i__2 = (*n << 1) + lwqrf, i__1 = f2cmax(
1596 i__1,i__2), i__2 = (*n << 1) + i__3 * i__3 +
1597 lwsvdjv, i__1 = f2cmax(i__1,i__2), i__2 = (*n << 1)
1598 + i__4 * i__4 + *n + lwunmqr, i__1 = f2cmax(i__1,
1599 i__2), i__2 = *n + lwunmqrm;
1600 minwrk = f2cmax(i__1,i__2);
1602 if (rowpiv || l2tran) {
1607 cunmqr_("L", "N", m, n, n, &a[a_offset], lda, cdummy, &u[
1608 u_offset], ldu, cdummy, &c_n1, &ierr);
1609 lwrk_cunmqrm__ = cdummy[0].r;
1610 cunmqr_("L", "N", n, n, n, &a[a_offset], lda, cdummy, &u[
1611 u_offset], ldu, cdummy, &c_n1, &ierr);
1612 lwrk_cunmqr__ = cdummy[0].r;
1614 cgeqp3_(n, n, &a[a_offset], lda, &iwork[1], cdummy,
1615 cdummy, &c_n1, rdummy, &ierr);
1616 lwrk_cgeqp3n__ = cdummy[0].r;
1617 cgesvj_("L", "U", "N", n, n, &u[u_offset], ldu, &sva[1],
1618 n, &v[v_offset], ldv, cdummy, &c_n1, rdummy, &
1620 lwrk_cgesvj__ = cdummy[0].r;
1621 cgesvj_("U", "U", "N", n, n, &u[u_offset], ldu, &sva[1],
1622 n, &v[v_offset], ldv, cdummy, &c_n1, rdummy, &
1624 lwrk_cgesvju__ = cdummy[0].r;
1625 cgesvj_("L", "U", "V", n, n, &u[u_offset], ldu, &sva[1],
1626 n, &v[v_offset], ldv, cdummy, &c_n1, rdummy, &
1628 lwrk_cgesvjv__ = cdummy[0].r;
1629 cunmlq_("L", "C", n, n, n, &a[a_offset], lda, cdummy, &v[
1630 v_offset], ldv, cdummy, &c_n1, &ierr);
1631 lwrk_cunmlq__ = cdummy[0].r;
1634 /* Computing 2nd power */
1636 /* Computing 2nd power */
1638 /* Computing 2nd power */
1640 /* Computing 2nd power */
1642 /* Computing 2nd power */
1644 /* Computing 2nd power */
1646 /* Computing 2nd power */
1648 /* Computing 2nd power */
1650 /* Computing 2nd power */
1652 i__1 = *n + lwrk_cgeqp3__, i__2 = *n + lwcon, i__1 =
1653 f2cmax(i__1,i__2), i__2 = (*n << 1) + i__3 *
1654 i__3 + lwcon, i__1 = f2cmax(i__1,i__2), i__2 = (*
1655 n << 1) + lwrk_cgeqrf__, i__1 = f2cmax(i__1,i__2)
1656 , i__2 = (*n << 1) + lwrk_cgeqp3n__, i__1 =
1657 f2cmax(i__1,i__2), i__2 = (*n << 1) + i__4 *
1658 i__4 + *n + lwrk_cgelqf__, i__1 = f2cmax(i__1,
1659 i__2), i__2 = (*n << 1) + i__5 * i__5 + *n +
1660 i__6 * i__6 + lwcon, i__1 = f2cmax(i__1,i__2),
1661 i__2 = (*n << 1) + i__7 * i__7 + *n +
1662 lwrk_cgesvj__, i__1 = f2cmax(i__1,i__2), i__2 = (
1663 *n << 1) + i__8 * i__8 + *n + lwrk_cgesvjv__,
1664 i__1 = f2cmax(i__1,i__2), i__2 = (*n << 1) +
1665 i__9 * i__9 + *n + lwrk_cunmqr__, i__1 = f2cmax(
1666 i__1,i__2), i__2 = (*n << 1) + i__10 * i__10
1667 + *n + lwrk_cunmlq__, i__1 = f2cmax(i__1,i__2),
1668 i__2 = *n + i__11 * i__11 + lwrk_cgesvju__,
1669 i__1 = f2cmax(i__1,i__2), i__2 = *n +
1671 optwrk = f2cmax(i__1,i__2);
1674 /* Computing 2nd power */
1676 /* Computing 2nd power */
1678 /* Computing 2nd power */
1680 /* Computing 2nd power */
1682 /* Computing 2nd power */
1684 /* Computing 2nd power */
1686 /* Computing 2nd power */
1688 /* Computing 2nd power */
1690 /* Computing 2nd power */
1692 i__1 = *n + lwrk_cgeqp3__, i__2 = (*n << 1) + i__3 *
1693 i__3 + lwcon, i__1 = f2cmax(i__1,i__2), i__2 = (*
1694 n << 1) + lwrk_cgeqrf__, i__1 = f2cmax(i__1,i__2)
1695 , i__2 = (*n << 1) + lwrk_cgeqp3n__, i__1 =
1696 f2cmax(i__1,i__2), i__2 = (*n << 1) + i__4 *
1697 i__4 + *n + lwrk_cgelqf__, i__1 = f2cmax(i__1,
1698 i__2), i__2 = (*n << 1) + i__5 * i__5 + *n +
1699 i__6 * i__6 + lwcon, i__1 = f2cmax(i__1,i__2),
1700 i__2 = (*n << 1) + i__7 * i__7 + *n +
1701 lwrk_cgesvj__, i__1 = f2cmax(i__1,i__2), i__2 = (
1702 *n << 1) + i__8 * i__8 + *n + lwrk_cgesvjv__,
1703 i__1 = f2cmax(i__1,i__2), i__2 = (*n << 1) +
1704 i__9 * i__9 + *n + lwrk_cunmqr__, i__1 = f2cmax(
1705 i__1,i__2), i__2 = (*n << 1) + i__10 * i__10
1706 + *n + lwrk_cunmlq__, i__1 = f2cmax(i__1,i__2),
1707 i__2 = *n + i__11 * i__11 + lwrk_cgesvju__,
1708 i__1 = f2cmax(i__1,i__2), i__2 = *n +
1710 optwrk = f2cmax(i__1,i__2);
1713 cgesvj_("L", "U", "V", n, n, &u[u_offset], ldu, &sva[1],
1714 n, &v[v_offset], ldv, cdummy, &c_n1, rdummy, &
1716 lwrk_cgesvjv__ = cdummy[0].r;
1717 cunmqr_("L", "N", n, n, n, cdummy, n, cdummy, &v[v_offset]
1718 , ldv, cdummy, &c_n1, &ierr)
1720 lwrk_cunmqr__ = cdummy[0].r;
1721 cunmqr_("L", "N", m, n, n, &a[a_offset], lda, cdummy, &u[
1722 u_offset], ldu, cdummy, &c_n1, &ierr);
1723 lwrk_cunmqrm__ = cdummy[0].r;
1726 /* Computing 2nd power */
1728 /* Computing 2nd power */
1730 /* Computing 2nd power */
1732 i__1 = *n + lwrk_cgeqp3__, i__2 = *n + lwcon, i__1 =
1733 f2cmax(i__1,i__2), i__2 = (*n << 1) +
1734 lwrk_cgeqrf__, i__1 = f2cmax(i__1,i__2), i__2 = (
1735 *n << 1) + i__3 * i__3, i__1 = f2cmax(i__1,i__2),
1736 i__2 = (*n << 1) + i__4 * i__4 +
1737 lwrk_cgesvjv__, i__1 = f2cmax(i__1,i__2), i__2 =
1738 (*n << 1) + i__5 * i__5 + *n + lwrk_cunmqr__,
1739 i__1 = f2cmax(i__1,i__2), i__2 = *n +
1741 optwrk = f2cmax(i__1,i__2);
1744 /* Computing 2nd power */
1746 /* Computing 2nd power */
1748 /* Computing 2nd power */
1750 i__1 = *n + lwrk_cgeqp3__, i__2 = (*n << 1) +
1751 lwrk_cgeqrf__, i__1 = f2cmax(i__1,i__2), i__2 = (
1752 *n << 1) + i__3 * i__3, i__1 = f2cmax(i__1,i__2),
1753 i__2 = (*n << 1) + i__4 * i__4 +
1754 lwrk_cgesvjv__, i__1 = f2cmax(i__1,i__2), i__2 =
1755 (*n << 1) + i__5 * i__5 + *n + lwrk_cunmqr__,
1756 i__1 = f2cmax(i__1,i__2), i__2 = *n +
1758 optwrk = f2cmax(i__1,i__2);
1762 if (l2tran || rowpiv) {
1764 i__1 = 7, i__2 = *m << 1, i__1 = f2cmax(i__1,i__2), i__1 = f2cmax(
1765 i__1,lrwqp3), i__1 = f2cmax(i__1,lrwsvdj);
1766 minrwrk = f2cmax(i__1,lrwcon);
1769 i__1 = f2cmax(7,lrwqp3), i__1 = f2cmax(i__1,lrwsvdj);
1770 minrwrk = f2cmax(i__1,lrwcon);
1773 minwrk = f2cmax(2,minwrk);
1774 optwrk = f2cmax(optwrk,minwrk);
1775 if (*lwork < minwrk && ! lquery) {
1778 if (*lrwork < minrwrk && ! lquery) {
1786 xerbla_("CGEJSV", &i__1, (ftnlen)6);
1788 } else if (lquery) {
1789 cwork[1].r = (real) optwrk, cwork[1].i = 0.f;
1790 cwork[2].r = (real) minwrk, cwork[2].i = 0.f;
1791 rwork[1] = (real) minrwrk;
1792 iwork[1] = f2cmax(4,miniwrk);
1796 /* Quick return for void matrix (Y3K safe) */
1798 if (*m == 0 || *n == 0) {
1813 /* Determine whether the matrix U should be M x N or M x M */
1817 if (lsame_(jobu, "F")) {
1822 /* Set numerical parameters */
1824 /* ! NOTE: Make sure SLAMCH() does not fail on the target architecture. */
1826 epsln = slamch_("Epsilon");
1827 sfmin = slamch_("SafeMinimum");
1828 small = sfmin / epsln;
1830 /* BIG = ONE / SFMIN */
1832 /* Initialize SVA(1:N) = diag( ||A e_i||_2 )_1^N */
1834 /* (!) If necessary, scale SVA() to protect the largest norm from */
1835 /* overflow. It is possible that this scaling pushes the smallest */
1836 /* column norm left from the underflow threshold (extreme case). */
1838 scalem = 1.f / sqrt((real) (*m) * (real) (*n));
1842 for (p = 1; p <= i__1; ++p) {
1845 classq_(m, &a[p * a_dim1 + 1], &c__1, &aapp, &aaqq);
1849 xerbla_("CGEJSV", &i__2, (ftnlen)6);
1853 if (aapp < big / aaqq && noscal) {
1854 sva[p] = aapp * aaqq;
1857 sva[p] = aapp * (aaqq * scalem);
1861 sscal_(&i__2, &scalem, &sva[1], &c__1);
1874 for (p = 1; p <= i__1; ++p) {
1876 r__1 = aapp, r__2 = sva[p];
1877 aapp = f2cmax(r__1,r__2);
1878 if (sva[p] != 0.f) {
1880 r__1 = aaqq, r__2 = sva[p];
1881 aaqq = f2cmin(r__1,r__2);
1886 /* Quick return for zero M x N matrix */
1890 claset_("G", m, &n1, &c_b1, &c_b2, &u[u_offset], ldu);
1893 claset_("G", n, n, &c_b1, &c_b2, &v[v_offset], ldv);
1900 if (lsvec && rsvec) {
1915 /* Issue warning if denormalized column norms detected. Override the */
1916 /* high relative accuracy request. Issue licence to kill nonzero columns */
1917 /* (set them to zero) whose norm is less than sigma_max / BIG (roughly). */
1920 if (aaqq <= sfmin) {
1926 /* Quick return for one-column matrix */
1931 clascl_("G", &c__0, &c__0, &sva[1], &scalem, m, &c__1, &a[a_dim1
1933 clacpy_("A", m, &c__1, &a[a_offset], lda, &u[u_offset], ldu);
1934 /* computing all M left singular vectors of the M x 1 matrix */
1937 cgeqrf_(m, n, &u[u_offset], ldu, &cwork[1], &cwork[*n + 1], &
1940 cungqr_(m, &n1, &c__1, &u[u_offset], ldu, &cwork[1], &cwork[*
1941 n + 1], &i__1, &ierr);
1942 ccopy_(m, &a[a_dim1 + 1], &c__1, &u[u_dim1 + 1], &c__1);
1947 v[i__1].r = 1.f, v[i__1].i = 0.f;
1949 if (sva[1] < big * scalem) {
1953 rwork[1] = 1.f / scalem;
1955 if (sva[1] != 0.f) {
1957 if (sva[1] / scalem >= sfmin) {
1971 if (lsvec && rsvec) {
1987 if (rowpiv || l2tran) {
1989 /* Compute the row norms, needed to determine row pivoting sequence */
1990 /* (in the case of heavily row weighted A, row pivoting is strongly */
1991 /* advised) and to collect information needed to compare the */
1992 /* structures of A * A^* and A^* * A (in the case L2TRAN.EQ..TRUE.). */
1996 for (p = 1; p <= i__1; ++p) {
1999 classq_(n, &a[p + a_dim1], lda, &xsc, &temp1);
2000 /* CLASSQ gets both the ell_2 and the ell_infinity norm */
2001 /* in one pass through the vector */
2002 rwork[*m + p] = xsc * scalem;
2003 rwork[p] = xsc * (scalem * sqrt(temp1));
2005 r__1 = aatmax, r__2 = rwork[p];
2006 aatmax = f2cmax(r__1,r__2);
2007 if (rwork[p] != 0.f) {
2009 r__1 = aatmin, r__2 = rwork[p];
2010 aatmin = f2cmin(r__1,r__2);
2016 for (p = 1; p <= i__1; ++p) {
2017 rwork[*m + p] = scalem * c_abs(&a[p + icamax_(n, &a[p +
2018 a_dim1], lda) * a_dim1]);
2020 r__1 = aatmax, r__2 = rwork[*m + p];
2021 aatmax = f2cmax(r__1,r__2);
2023 r__1 = aatmin, r__2 = rwork[*m + p];
2024 aatmin = f2cmin(r__1,r__2);
2031 /* For square matrix A try to determine whether A^* would be better */
2032 /* input for the preconditioned Jacobi SVD, with faster convergence. */
2033 /* The decision is based on an O(N) function of the vector of column */
2034 /* and row norms of A, based on the Shannon entropy. This should give */
2035 /* the right choice in most cases when the difference actually matters. */
2036 /* It may fail and pick the slower converging side. */
2044 slassq_(n, &sva[1], &c__1, &xsc, &temp1);
2045 temp1 = 1.f / temp1;
2049 for (p = 1; p <= i__1; ++p) {
2050 /* Computing 2nd power */
2051 r__1 = sva[p] / xsc;
2052 big1 = r__1 * r__1 * temp1;
2054 entra += big1 * log(big1);
2058 entra = -entra / log((real) (*n));
2060 /* Now, SVA().^2/Trace(A^* * A) is a point in the probability simplex. */
2061 /* It is derived from the diagonal of A^* * A. Do the same with the */
2062 /* diagonal of A * A^*, compute the entropy of the corresponding */
2063 /* probability distribution. Note that A * A^* and A^* * A have the */
2068 for (p = 1; p <= i__1; ++p) {
2069 /* Computing 2nd power */
2070 r__1 = rwork[p] / xsc;
2071 big1 = r__1 * r__1 * temp1;
2073 entrat += big1 * log(big1);
2077 entrat = -entrat / log((real) (*m));
2079 /* Analyze the entropies and decide A or A^*. Smaller entropy */
2080 /* usually means better input for the algorithm. */
2082 transp = entrat < entra;
2084 /* If A^* is better than A, take the adjoint of A. This is allowed */
2085 /* only for square matrices, M=N. */
2087 /* In an optimal implementation, this trivial transpose */
2088 /* should be replaced with faster transpose. */
2090 for (p = 1; p <= i__1; ++p) {
2091 i__2 = p + p * a_dim1;
2092 r_cnjg(&q__1, &a[p + p * a_dim1]);
2093 a[i__2].r = q__1.r, a[i__2].i = q__1.i;
2095 for (q = p + 1; q <= i__2; ++q) {
2096 r_cnjg(&q__1, &a[q + p * a_dim1]);
2097 ctemp.r = q__1.r, ctemp.i = q__1.i;
2098 i__3 = q + p * a_dim1;
2099 r_cnjg(&q__1, &a[p + q * a_dim1]);
2100 a[i__3].r = q__1.r, a[i__3].i = q__1.i;
2101 i__3 = p + q * a_dim1;
2102 a[i__3].r = ctemp.r, a[i__3].i = ctemp.i;
2107 i__1 = *n + *n * a_dim1;
2108 r_cnjg(&q__1, &a[*n + *n * a_dim1]);
2109 a[i__1].r = q__1.r, a[i__1].i = q__1.i;
2111 for (p = 1; p <= i__1; ++p) {
2112 rwork[*m + p] = sva[p];
2114 /* previously computed row 2-norms are now column 2-norms */
2115 /* of the transposed matrix */
2137 /* Scale the matrix so that its maximal singular value remains less */
2138 /* than SQRT(BIG) -- the matrix is scaled so that its maximal column */
2139 /* has Euclidean norm equal to SQRT(BIG/N). The only reason to keep */
2140 /* SQRT(BIG) instead of BIG is the fact that CGEJSV uses LAPACK and */
2141 /* BLAS routines that, in some implementations, are not capable of */
2142 /* working in the full interval [SFMIN,BIG] and that they may provoke */
2143 /* overflows in the intermediate results. If the singular values spread */
2144 /* from SFMIN to BIG, then CGESVJ will compute them. So, in that case, */
2145 /* one should use CGESVJ instead of CGEJSV. */
2147 temp1 = sqrt(big / (real) (*n));
2148 /* >> for future updates: allow bigger range, i.e. the largest column */
2149 /* will be allowed up to BIG/N and CGESVJ will do the rest. However, for */
2150 /* this all other (LAPACK) components must allow such a range. */
2151 /* TEMP1 = BIG/REAL(N) */
2152 /* TEMP1 = BIG * EPSLN this should 'almost' work with current LAPACK components */
2153 slascl_("G", &c__0, &c__0, &aapp, &temp1, n, &c__1, &sva[1], n, &ierr);
2154 if (aaqq > aapp * sfmin) {
2155 aaqq = aaqq / aapp * temp1;
2157 aaqq = aaqq * temp1 / aapp;
2160 clascl_("G", &c__0, &c__0, &aapp, &temp1, m, n, &a[a_offset], lda, &ierr);
2162 /* To undo scaling at the end of this procedure, multiply the */
2163 /* computed singular values with USCAL2 / USCAL1. */
2169 /* L2KILL enforces computation of nonzero singular values in */
2170 /* the restricted range of condition number of the initial A, */
2171 /* sigma_max(A) / sigma_min(A) approx. SQRT(BIG)/SQRT(SFMIN). */
2176 /* Now, if the condition number of A is too big, */
2177 /* sigma_max(A) / sigma_min(A) .GT. SQRT(BIG/N) * EPSLN / SFMIN, */
2178 /* as a precaution measure, the full SVD is computed using CGESVJ */
2179 /* with accumulated Jacobi rotations. This provides numerically */
2180 /* more robust computation, at the cost of slightly increased run */
2181 /* time. Depending on the concrete implementation of BLAS and LAPACK */
2182 /* (i.e. how they behave in presence of extreme ill-conditioning) the */
2183 /* implementor may decide to remove this switch. */
2184 if (aaqq < sqrt(sfmin) && lsvec && rsvec) {
2191 for (p = 1; p <= i__1; ++p) {
2193 claset_("A", m, &c__1, &c_b1, &c_b1, &a[p * a_dim1 + 1], lda);
2200 /* Preconditioning using QR factorization with pivoting */
2203 /* Optional row permutation (Bjoerck row pivoting): */
2204 /* A result by Cox and Higham shows that the Bjoerck's */
2205 /* row pivoting combined with standard column pivoting */
2206 /* has similar effect as Powell-Reid complete pivoting. */
2207 /* The ell-infinity norms of A are made nonincreasing. */
2208 if (lsvec && rsvec && ! jracc) {
2214 for (p = 1; p <= i__1; ++p) {
2216 q = isamax_(&i__2, &rwork[*m + p], &c__1) + p - 1;
2217 iwork[iwoff + p] = q;
2219 temp1 = rwork[*m + p];
2220 rwork[*m + p] = rwork[*m + q];
2221 rwork[*m + q] = temp1;
2226 claswp_(n, &a[a_offset], lda, &c__1, &i__1, &iwork[iwoff + 1], &c__1);
2229 /* End of the preparation phase (scaling, optional sorting and */
2230 /* transposing, optional flushing of small columns). */
2232 /* Preconditioning */
2234 /* If the full SVD is needed, the right singular vectors are computed */
2235 /* from a matrix equation, and for that we need theoretical analysis */
2236 /* of the Businger-Golub pivoting. So we use CGEQP3 as the first RR QRF. */
2237 /* In all other cases the first RR QRF can be chosen by other criteria */
2238 /* (eg speed by replacing global with restricted window pivoting, such */
2239 /* as in xGEQPX from TOMS # 782). Good results will be obtained using */
2240 /* xGEQPX with properly (!) chosen numerical parameters. */
2241 /* Any improvement of CGEQP3 improves overal performance of CGEJSV. */
2243 /* A * P1 = Q1 * [ R1^* 0]^*: */
2245 for (p = 1; p <= i__1; ++p) {
2250 cgeqp3_(m, n, &a[a_offset], lda, &iwork[1], &cwork[1], &cwork[*n + 1], &
2251 i__1, &rwork[1], &ierr);
2253 /* The upper triangular matrix R1 from the first QRF is inspected for */
2254 /* rank deficiency and possibilities for deflation, or possible */
2255 /* ill-conditioning. Depending on the user specified flag L2RANK, */
2256 /* the procedure explores possibilities to reduce the numerical */
2257 /* rank by inspecting the computed upper triangular factor. If */
2258 /* L2RANK or L2ABER are up, then CGEJSV will compute the SVD of */
2259 /* A + dA, where ||dA|| <= f(M,N)*EPSLN. */
2263 /* Standard absolute error bound suffices. All sigma_i with */
2264 /* sigma_i < N*EPSLN*||A|| are flushed to zero. This is an */
2265 /* aggressive enforcement of lower numerical rank by introducing a */
2266 /* backward error of the order of N*EPSLN*||A||. */
2267 temp1 = sqrt((real) (*n)) * epsln;
2269 for (p = 2; p <= i__1; ++p) {
2270 if (c_abs(&a[p + p * a_dim1]) >= temp1 * c_abs(&a[a_dim1 + 1])) {
2279 } else if (l2rank) {
2280 /* Sudden drop on the diagonal of R1 is used as the criterion for */
2281 /* close-to-rank-deficient. */
2282 temp1 = sqrt(sfmin);
2284 for (p = 2; p <= i__1; ++p) {
2285 if (c_abs(&a[p + p * a_dim1]) < epsln * c_abs(&a[p - 1 + (p - 1) *
2286 a_dim1]) || c_abs(&a[p + p * a_dim1]) < small || l2kill
2287 && c_abs(&a[p + p * a_dim1]) < temp1) {
2297 /* The goal is high relative accuracy. However, if the matrix */
2298 /* has high scaled condition number the relative accuracy is in */
2299 /* general not feasible. Later on, a condition number estimator */
2300 /* will be deployed to estimate the scaled condition number. */
2301 /* Here we just remove the underflowed part of the triangular */
2302 /* factor. This prevents the situation in which the code is */
2303 /* working hard to get the accuracy not warranted by the data. */
2304 temp1 = sqrt(sfmin);
2306 for (p = 2; p <= i__1; ++p) {
2307 if (c_abs(&a[p + p * a_dim1]) < small || l2kill && c_abs(&a[p + p
2308 * a_dim1]) < temp1) {
2323 for (p = 2; p <= i__1; ++p) {
2324 temp1 = c_abs(&a[p + p * a_dim1]) / sva[iwork[p]];
2325 maxprj = f2cmin(maxprj,temp1);
2328 /* Computing 2nd power */
2330 if (r__1 * r__1 >= 1.f - (real) (*n) * epsln) {
2343 clacpy_("U", n, n, &a[a_offset], lda, &v[v_offset], ldv);
2345 for (p = 1; p <= i__1; ++p) {
2346 temp1 = sva[iwork[p]];
2348 csscal_(&p, &r__1, &v[p * v_dim1 + 1], &c__1);
2352 cpocon_("U", n, &v[v_offset], ldv, &c_b141, &temp1, &
2353 cwork[*n + 1], &rwork[1], &ierr);
2355 cpocon_("U", n, &v[v_offset], ldv, &c_b141, &temp1, &
2356 cwork[1], &rwork[1], &ierr);
2360 clacpy_("U", n, n, &a[a_offset], lda, &u[u_offset], ldu);
2362 for (p = 1; p <= i__1; ++p) {
2363 temp1 = sva[iwork[p]];
2365 csscal_(&p, &r__1, &u[p * u_dim1 + 1], &c__1);
2368 cpocon_("U", n, &u[u_offset], ldu, &c_b141, &temp1, &cwork[*n
2369 + 1], &rwork[1], &ierr);
2371 clacpy_("U", n, n, &a[a_offset], lda, &cwork[1], n)
2373 /* [] CALL CLACPY( 'U', N, N, A, LDA, CWORK(N+1), N ) */
2374 /* Change: here index shifted by N to the left, CWORK(1:N) */
2375 /* not needed for SIGMA only computation */
2377 for (p = 1; p <= i__1; ++p) {
2378 temp1 = sva[iwork[p]];
2379 /* [] CALL CSSCAL( p, ONE/TEMP1, CWORK(N+(p-1)*N+1), 1 ) */
2381 csscal_(&p, &r__1, &cwork[(p - 1) * *n + 1], &c__1);
2384 /* [] CALL CPOCON( 'U', N, CWORK(N+1), N, ONE, TEMP1, */
2385 /* [] $ CWORK(N+N*N+1), RWORK, IERR ) */
2386 cpocon_("U", n, &cwork[1], n, &c_b141, &temp1, &cwork[*n * *n
2387 + 1], &rwork[1], &ierr);
2391 sconda = 1.f / sqrt(temp1);
2395 /* SCONDA is an estimate of SQRT(||(R^* * R)^(-1)||_1). */
2396 /* N^(-1/4) * SCONDA <= ||R^(-1)||_2 <= N^(1/4) * SCONDA */
2402 c_div(&q__1, &a[a_dim1 + 1], &a[nr + nr * a_dim1]);
2403 l2pert = l2pert && c_abs(&q__1) > sqrt(big1);
2404 /* If there is no violent scaling, artificial perturbation is not needed. */
2408 if (! (rsvec || lsvec)) {
2410 /* Singular Values only */
2414 i__1 = f2cmin(i__2,nr);
2415 for (p = 1; p <= i__1; ++p) {
2417 ccopy_(&i__2, &a[p + (p + 1) * a_dim1], lda, &a[p + 1 + p *
2420 clacgv_(&i__2, &a[p + p * a_dim1], &c__1);
2424 i__1 = *n + *n * a_dim1;
2425 r_cnjg(&q__1, &a[*n + *n * a_dim1]);
2426 a[i__1].r = q__1.r, a[i__1].i = q__1.i;
2429 /* The following two DO-loops introduce small relative perturbation */
2430 /* into the strict upper triangle of the lower triangular matrix. */
2431 /* Small entries below the main diagonal are also changed. */
2432 /* This modification is useful if the computing environment does not */
2433 /* provide/allow FLUSH TO ZERO underflow, for it prevents many */
2434 /* annoying denormalized numbers in case of strongly scaled matrices. */
2435 /* The perturbation is structured so that it does not introduce any */
2436 /* new perturbation of the singular values, and it does not destroy */
2437 /* the job done by the preconditioner. */
2438 /* The licence for this perturbation is in the variable L2PERT, which */
2439 /* should be .FALSE. if FLUSH TO ZERO underflow is active. */
2444 /* XSC = SQRT(SMALL) */
2445 xsc = epsln / (real) (*n);
2447 for (q = 1; q <= i__1; ++q) {
2448 r__1 = xsc * c_abs(&a[q + q * a_dim1]);
2449 q__1.r = r__1, q__1.i = 0.f;
2450 ctemp.r = q__1.r, ctemp.i = q__1.i;
2452 for (p = 1; p <= i__2; ++p) {
2453 if (p > q && c_abs(&a[p + q * a_dim1]) <= temp1 || p <
2455 i__3 = p + q * a_dim1;
2456 a[i__3].r = ctemp.r, a[i__3].i = ctemp.i;
2458 /* $ A(p,q) = TEMP1 * ( A(p,q) / ABS(A(p,q)) ) */
2466 claset_("U", &i__1, &i__2, &c_b1, &c_b1, &a[(a_dim1 << 1) + 1]
2472 cgeqrf_(n, &nr, &a[a_offset], lda, &cwork[1], &cwork[*n + 1], &
2476 for (p = 1; p <= i__1; ++p) {
2478 ccopy_(&i__2, &a[p + (p + 1) * a_dim1], lda, &a[p + 1 + p *
2481 clacgv_(&i__2, &a[p + p * a_dim1], &c__1);
2487 /* Row-cyclic Jacobi SVD algorithm with column pivoting */
2489 /* to drown denormals */
2491 /* XSC = SQRT(SMALL) */
2492 xsc = epsln / (real) (*n);
2494 for (q = 1; q <= i__1; ++q) {
2495 r__1 = xsc * c_abs(&a[q + q * a_dim1]);
2496 q__1.r = r__1, q__1.i = 0.f;
2497 ctemp.r = q__1.r, ctemp.i = q__1.i;
2499 for (p = 1; p <= i__2; ++p) {
2500 if (p > q && c_abs(&a[p + q * a_dim1]) <= temp1 || p < q)
2502 i__3 = p + q * a_dim1;
2503 a[i__3].r = ctemp.r, a[i__3].i = ctemp.i;
2505 /* $ A(p,q) = TEMP1 * ( A(p,q) / ABS(A(p,q)) ) */
2513 claset_("U", &i__1, &i__2, &c_b1, &c_b1, &a[(a_dim1 << 1) + 1],
2517 /* triangular matrix (plus perturbation which is ignored in */
2518 /* the part which destroys triangular form (confusing?!)) */
2520 cgesvj_("L", "N", "N", &nr, &nr, &a[a_offset], lda, &sva[1], n, &v[
2521 v_offset], ldv, &cwork[1], lwork, &rwork[1], lrwork, info);
2524 numrank = i_nint(&rwork[2]);
2527 } else if (rsvec && ! lsvec && ! jracc || jracc && ! lsvec && nr != *n) {
2529 /* -> Singular Values and Right Singular Vectors <- */
2534 for (p = 1; p <= i__1; ++p) {
2536 ccopy_(&i__2, &a[p + p * a_dim1], lda, &v[p + p * v_dim1], &
2539 clacgv_(&i__2, &v[p + p * v_dim1], &c__1);
2544 claset_("U", &i__1, &i__2, &c_b1, &c_b1, &v[(v_dim1 << 1) + 1],
2547 cgesvj_("L", "U", "N", n, &nr, &v[v_offset], ldv, &sva[1], &nr, &
2548 a[a_offset], lda, &cwork[1], lwork, &rwork[1], lrwork,
2551 numrank = i_nint(&rwork[2]);
2554 /* accumulated product of Jacobi rotations, three are perfect ) */
2558 claset_("L", &i__1, &i__2, &c_b1, &c_b1, &a[a_dim1 + 2], lda);
2560 cgelqf_(&nr, n, &a[a_offset], lda, &cwork[1], &cwork[*n + 1], &
2562 clacpy_("L", &nr, &nr, &a[a_offset], lda, &v[v_offset], ldv);
2565 claset_("U", &i__1, &i__2, &c_b1, &c_b1, &v[(v_dim1 << 1) + 1],
2567 i__1 = *lwork - (*n << 1);
2568 cgeqrf_(&nr, &nr, &v[v_offset], ldv, &cwork[*n + 1], &cwork[(*n <<
2569 1) + 1], &i__1, &ierr);
2571 for (p = 1; p <= i__1; ++p) {
2573 ccopy_(&i__2, &v[p + p * v_dim1], ldv, &v[p + p * v_dim1], &
2576 clacgv_(&i__2, &v[p + p * v_dim1], &c__1);
2581 claset_("U", &i__1, &i__2, &c_b1, &c_b1, &v[(v_dim1 << 1) + 1],
2585 cgesvj_("L", "U", "N", &nr, &nr, &v[v_offset], ldv, &sva[1], &nr,
2586 &u[u_offset], ldu, &cwork[*n + 1], &i__1, &rwork[1],
2589 numrank = i_nint(&rwork[2]);
2592 claset_("A", &i__1, &nr, &c_b1, &c_b1, &v[nr + 1 + v_dim1],
2595 claset_("A", &nr, &i__1, &c_b1, &c_b1, &v[(nr + 1) * v_dim1 +
2599 claset_("A", &i__1, &i__2, &c_b1, &c_b2, &v[nr + 1 + (nr + 1)
2604 cunmlq_("L", "C", n, n, &nr, &a[a_offset], lda, &cwork[1], &v[
2605 v_offset], ldv, &cwork[*n + 1], &i__1, &ierr);
2608 /* DO 8991 p = 1, N */
2609 /* CALL CCOPY( N, V(p,1), LDV, A(IWORK(p),1), LDA ) */
2611 /* CALL CLACPY( 'All', N, N, A, LDA, V, LDV ) */
2612 clapmr_(&c_false, n, n, &v[v_offset], ldv, &iwork[1]);
2615 clacpy_("A", n, n, &v[v_offset], ldv, &u[u_offset], ldu);
2618 } else if (jracc && ! lsvec && nr == *n) {
2622 claset_("L", &i__1, &i__2, &c_b1, &c_b1, &a[a_dim1 + 2], lda);
2624 cgesvj_("U", "N", "V", n, n, &a[a_offset], lda, &sva[1], n, &v[
2625 v_offset], ldv, &cwork[1], lwork, &rwork[1], lrwork, info);
2627 numrank = i_nint(&rwork[2]);
2628 clapmr_(&c_false, n, n, &v[v_offset], ldv, &iwork[1]);
2630 } else if (lsvec && ! rsvec) {
2633 /* Jacobi rotations in the Jacobi iterations. */
2635 for (p = 1; p <= i__1; ++p) {
2637 ccopy_(&i__2, &a[p + p * a_dim1], lda, &u[p + p * u_dim1], &c__1);
2639 clacgv_(&i__2, &u[p + p * u_dim1], &c__1);
2644 claset_("U", &i__1, &i__2, &c_b1, &c_b1, &u[(u_dim1 << 1) + 1], ldu);
2646 i__1 = *lwork - (*n << 1);
2647 cgeqrf_(n, &nr, &u[u_offset], ldu, &cwork[*n + 1], &cwork[(*n << 1) +
2651 for (p = 1; p <= i__1; ++p) {
2653 ccopy_(&i__2, &u[p + (p + 1) * u_dim1], ldu, &u[p + 1 + p *
2656 clacgv_(&i__2, &u[p + p * u_dim1], &c__1);
2661 claset_("U", &i__1, &i__2, &c_b1, &c_b1, &u[(u_dim1 << 1) + 1], ldu);
2664 cgesvj_("L", "U", "N", &nr, &nr, &u[u_offset], ldu, &sva[1], &nr, &a[
2665 a_offset], lda, &cwork[*n + 1], &i__1, &rwork[1], lrwork,
2668 numrank = i_nint(&rwork[2]);
2672 claset_("A", &i__1, &nr, &c_b1, &c_b1, &u[nr + 1 + u_dim1], ldu);
2675 claset_("A", &nr, &i__1, &c_b1, &c_b1, &u[(nr + 1) * u_dim1 +
2679 claset_("A", &i__1, &i__2, &c_b1, &c_b2, &u[nr + 1 + (nr + 1)
2685 cunmqr_("L", "N", m, &n1, n, &a[a_offset], lda, &cwork[1], &u[
2686 u_offset], ldu, &cwork[*n + 1], &i__1, &ierr);
2690 claswp_(&n1, &u[u_offset], ldu, &c__1, &i__1, &iwork[iwoff + 1], &
2695 for (p = 1; p <= i__1; ++p) {
2696 xsc = 1.f / scnrm2_(m, &u[p * u_dim1 + 1], &c__1);
2697 csscal_(m, &xsc, &u[p * u_dim1 + 1], &c__1);
2702 clacpy_("A", n, n, &u[u_offset], ldu, &v[v_offset], ldv);
2712 /* Second Preconditioning Step (QRF [with pivoting]) */
2713 /* Note that the composition of TRANSPOSE, QRF and TRANSPOSE is */
2714 /* equivalent to an LQF CALL. Since in many libraries the QRF */
2715 /* seems to be better optimized than the LQF, we do explicit */
2716 /* transpose and use the QRF. This is subject to changes in an */
2717 /* optimized implementation of CGEJSV. */
2720 for (p = 1; p <= i__1; ++p) {
2722 ccopy_(&i__2, &a[p + p * a_dim1], lda, &v[p + p * v_dim1],
2725 clacgv_(&i__2, &v[p + p * v_dim1], &c__1);
2729 /* denormals in the second QR factorization, where they are */
2730 /* as good as zeros. This is done to avoid painfully slow */
2731 /* computation with denormals. The relative size of the perturbation */
2732 /* is a parameter that can be changed by the implementer. */
2733 /* This perturbation device will be obsolete on machines with */
2734 /* properly implemented arithmetic. */
2735 /* To switch it off, set L2PERT=.FALSE. To remove it from the */
2736 /* code, remove the action under L2PERT=.TRUE., leave the ELSE part. */
2737 /* The following two loops should be blocked and fused with the */
2738 /* transposed copy above. */
2743 for (q = 1; q <= i__1; ++q) {
2744 r__1 = xsc * c_abs(&v[q + q * v_dim1]);
2745 q__1.r = r__1, q__1.i = 0.f;
2746 ctemp.r = q__1.r, ctemp.i = q__1.i;
2748 for (p = 1; p <= i__2; ++p) {
2749 if (p > q && c_abs(&v[p + q * v_dim1]) <= temp1 ||
2751 i__3 = p + q * v_dim1;
2752 v[i__3].r = ctemp.r, v[i__3].i = ctemp.i;
2754 /* $ V(p,q) = TEMP1 * ( V(p,q) / ABS(V(p,q)) ) */
2756 i__3 = p + q * v_dim1;
2757 i__4 = p + q * v_dim1;
2758 q__1.r = -v[i__4].r, q__1.i = -v[i__4].i;
2759 v[i__3].r = q__1.r, v[i__3].i = q__1.i;
2768 claset_("U", &i__1, &i__2, &c_b1, &c_b1, &v[(v_dim1 << 1)
2772 /* Estimate the row scaled condition number of R1 */
2773 /* (If R1 is rectangular, N > NR, then the condition number */
2774 /* of the leading NR x NR submatrix is estimated.) */
2776 clacpy_("L", &nr, &nr, &v[v_offset], ldv, &cwork[(*n << 1) +
2779 for (p = 1; p <= i__1; ++p) {
2781 temp1 = scnrm2_(&i__2, &cwork[(*n << 1) + (p - 1) * nr +
2785 csscal_(&i__2, &r__1, &cwork[(*n << 1) + (p - 1) * nr + p]
2789 cpocon_("L", &nr, &cwork[(*n << 1) + 1], &nr, &c_b141, &temp1,
2790 &cwork[(*n << 1) + nr * nr + 1], &rwork[1], &ierr);
2791 condr1 = 1.f / sqrt(temp1);
2792 /* R1 is OK for inverse <=> CONDR1 .LT. REAL(N) */
2793 /* more conservative <=> CONDR1 .LT. SQRT(REAL(N)) */
2795 cond_ok__ = sqrt(sqrt((real) nr));
2796 /* [TP] COND_OK is a tuning parameter. */
2798 if (condr1 < cond_ok__) {
2799 /* implementation, this QRF should be implemented as the QRF */
2800 /* of a lower triangular matrix. */
2801 /* R1^* = Q2 * R2 */
2802 i__1 = *lwork - (*n << 1);
2803 cgeqrf_(n, &nr, &v[v_offset], ldv, &cwork[*n + 1], &cwork[
2804 (*n << 1) + 1], &i__1, &ierr);
2807 xsc = sqrt(small) / epsln;
2809 for (p = 2; p <= i__1; ++p) {
2811 for (q = 1; q <= i__2; ++q) {
2813 r__2 = c_abs(&v[p + p * v_dim1]), r__3 =
2814 c_abs(&v[q + q * v_dim1]);
2815 r__1 = xsc * f2cmin(r__2,r__3);
2816 q__1.r = r__1, q__1.i = 0.f;
2817 ctemp.r = q__1.r, ctemp.i = q__1.i;
2818 if (c_abs(&v[q + p * v_dim1]) <= temp1) {
2819 i__3 = q + p * v_dim1;
2820 v[i__3].r = ctemp.r, v[i__3].i = ctemp.i;
2822 /* $ V(q,p) = TEMP1 * ( V(q,p) / ABS(V(q,p)) ) */
2830 clacpy_("A", n, &nr, &v[v_offset], ldv, &cwork[(*n <<
2835 for (p = 1; p <= i__1; ++p) {
2837 ccopy_(&i__2, &v[p + (p + 1) * v_dim1], ldv, &v[p + 1
2838 + p * v_dim1], &c__1);
2840 clacgv_(&i__2, &v[p + p * v_dim1], &c__1);
2843 i__1 = nr + nr * v_dim1;
2844 r_cnjg(&q__1, &v[nr + nr * v_dim1]);
2845 v[i__1].r = q__1.r, v[i__1].i = q__1.i;
2851 /* Note that windowed pivoting would be equally good */
2852 /* numerically, and more run-time efficient. So, in */
2853 /* an optimal implementation, the next call to CGEQP3 */
2854 /* should be replaced with eg. CALL CGEQPX (ACM TOMS #782) */
2855 /* with properly (carefully) chosen parameters. */
2857 /* R1^* * P2 = Q2 * R2 */
2859 for (p = 1; p <= i__1; ++p) {
2863 i__1 = *lwork - (*n << 1);
2864 cgeqp3_(n, &nr, &v[v_offset], ldv, &iwork[*n + 1], &cwork[
2865 *n + 1], &cwork[(*n << 1) + 1], &i__1, &rwork[1],
2867 /* * CALL CGEQRF( N, NR, V, LDV, CWORK(N+1), CWORK(2*N+1), */
2868 /* * $ LWORK-2*N, IERR ) */
2872 for (p = 2; p <= i__1; ++p) {
2874 for (q = 1; q <= i__2; ++q) {
2876 r__2 = c_abs(&v[p + p * v_dim1]), r__3 =
2877 c_abs(&v[q + q * v_dim1]);
2878 r__1 = xsc * f2cmin(r__2,r__3);
2879 q__1.r = r__1, q__1.i = 0.f;
2880 ctemp.r = q__1.r, ctemp.i = q__1.i;
2881 if (c_abs(&v[q + p * v_dim1]) <= temp1) {
2882 i__3 = q + p * v_dim1;
2883 v[i__3].r = ctemp.r, v[i__3].i = ctemp.i;
2885 /* $ V(q,p) = TEMP1 * ( V(q,p) / ABS(V(q,p)) ) */
2892 clacpy_("A", n, &nr, &v[v_offset], ldv, &cwork[(*n << 1)
2898 for (p = 2; p <= i__1; ++p) {
2900 for (q = 1; q <= i__2; ++q) {
2902 r__2 = c_abs(&v[p + p * v_dim1]), r__3 =
2903 c_abs(&v[q + q * v_dim1]);
2904 r__1 = xsc * f2cmin(r__2,r__3);
2905 q__1.r = r__1, q__1.i = 0.f;
2906 ctemp.r = q__1.r, ctemp.i = q__1.i;
2907 /* V(p,q) = - TEMP1*( V(q,p) / ABS(V(q,p)) ) */
2908 i__3 = p + q * v_dim1;
2909 q__1.r = -ctemp.r, q__1.i = -ctemp.i;
2910 v[i__3].r = q__1.r, v[i__3].i = q__1.i;
2918 claset_("L", &i__1, &i__2, &c_b1, &c_b1, &v[v_dim1 +
2921 /* Now, compute R2 = L3 * Q3, the LQ factorization. */
2922 i__1 = *lwork - (*n << 1) - *n * nr - nr;
2923 cgelqf_(&nr, &nr, &v[v_offset], ldv, &cwork[(*n << 1) + *
2924 n * nr + 1], &cwork[(*n << 1) + *n * nr + nr + 1],
2926 clacpy_("L", &nr, &nr, &v[v_offset], ldv, &cwork[(*n << 1)
2927 + *n * nr + nr + 1], &nr);
2929 for (p = 1; p <= i__1; ++p) {
2930 temp1 = scnrm2_(&p, &cwork[(*n << 1) + *n * nr + nr +
2933 csscal_(&p, &r__1, &cwork[(*n << 1) + *n * nr + nr +
2937 cpocon_("L", &nr, &cwork[(*n << 1) + *n * nr + nr + 1], &
2938 nr, &c_b141, &temp1, &cwork[(*n << 1) + *n * nr +
2939 nr + nr * nr + 1], &rwork[1], &ierr);
2940 condr2 = 1.f / sqrt(temp1);
2943 if (condr2 >= cond_ok__) {
2944 /* (this overwrites the copy of R2, as it will not be */
2945 /* needed in this branch, but it does not overwritte the */
2946 /* Huseholder vectors of Q2.). */
2947 clacpy_("U", &nr, &nr, &v[v_offset], ldv, &cwork[(*n
2949 /* WORK(2*N+N*NR+1:2*N+N*NR+N) */
2957 for (q = 2; q <= i__1; ++q) {
2958 i__2 = q + q * v_dim1;
2959 q__1.r = xsc * v[i__2].r, q__1.i = xsc * v[i__2].i;
2960 ctemp.r = q__1.r, ctemp.i = q__1.i;
2962 for (p = 1; p <= i__2; ++p) {
2963 /* V(p,q) = - TEMP1*( V(p,q) / ABS(V(p,q)) ) */
2964 i__3 = p + q * v_dim1;
2965 q__1.r = -ctemp.r, q__1.i = -ctemp.i;
2966 v[i__3].r = q__1.r, v[i__3].i = q__1.i;
2974 claset_("U", &i__1, &i__2, &c_b1, &c_b1, &v[(v_dim1 << 1)
2978 /* Second preconditioning finished; continue with Jacobi SVD */
2979 /* The input matrix is lower trinagular. */
2981 /* Recover the right singular vectors as solution of a well */
2982 /* conditioned triangular matrix equation. */
2984 if (condr1 < cond_ok__) {
2986 i__1 = *lwork - (*n << 1) - *n * nr - nr;
2987 cgesvj_("L", "U", "N", &nr, &nr, &v[v_offset], ldv, &sva[
2988 1], &nr, &u[u_offset], ldu, &cwork[(*n << 1) + *n
2989 * nr + nr + 1], &i__1, &rwork[1], lrwork, info);
2991 numrank = i_nint(&rwork[2]);
2993 for (p = 1; p <= i__1; ++p) {
2994 ccopy_(&nr, &v[p * v_dim1 + 1], &c__1, &u[p * u_dim1
2996 csscal_(&nr, &sva[p], &v[p * v_dim1 + 1], &c__1);
3001 /* :)) .. best case, R1 is inverted. The solution of this matrix */
3002 /* equation is Q2*V2 = the product of the Jacobi rotations */
3003 /* used in CGESVJ, premultiplied with the orthogonal matrix */
3004 /* from the second QR factorization. */
3005 ctrsm_("L", "U", "N", "N", &nr, &nr, &c_b2, &a[
3006 a_offset], lda, &v[v_offset], ldv);
3008 /* is inverted to get the product of the Jacobi rotations */
3009 /* used in CGESVJ. The Q-factor from the second QR */
3010 /* factorization is then built in explicitly. */
3011 ctrsm_("L", "U", "C", "N", &nr, &nr, &c_b2, &cwork[(*
3012 n << 1) + 1], n, &v[v_offset], ldv);
3015 claset_("A", &i__1, &nr, &c_b1, &c_b1, &v[nr + 1
3018 claset_("A", &nr, &i__1, &c_b1, &c_b1, &v[(nr + 1)
3019 * v_dim1 + 1], ldv);
3022 claset_("A", &i__1, &i__2, &c_b1, &c_b2, &v[nr +
3023 1 + (nr + 1) * v_dim1], ldv);
3025 i__1 = *lwork - (*n << 1) - *n * nr - nr;
3026 cunmqr_("L", "N", n, n, &nr, &cwork[(*n << 1) + 1], n,
3027 &cwork[*n + 1], &v[v_offset], ldv, &cwork[(*
3028 n << 1) + *n * nr + nr + 1], &i__1, &ierr);
3031 } else if (condr2 < cond_ok__) {
3033 /* The matrix R2 is inverted. The solution of the matrix equation */
3034 /* is Q3^* * V3 = the product of the Jacobi rotations (appplied to */
3035 /* the lower triangular L3 from the LQ factorization of */
3036 /* R2=L3*Q3), pre-multiplied with the transposed Q3. */
3037 i__1 = *lwork - (*n << 1) - *n * nr - nr;
3038 cgesvj_("L", "U", "N", &nr, &nr, &v[v_offset], ldv, &sva[
3039 1], &nr, &u[u_offset], ldu, &cwork[(*n << 1) + *n
3040 * nr + nr + 1], &i__1, &rwork[1], lrwork, info);
3042 numrank = i_nint(&rwork[2]);
3044 for (p = 1; p <= i__1; ++p) {
3045 ccopy_(&nr, &v[p * v_dim1 + 1], &c__1, &u[p * u_dim1
3047 csscal_(&nr, &sva[p], &u[p * u_dim1 + 1], &c__1);
3050 ctrsm_("L", "U", "N", "N", &nr, &nr, &c_b2, &cwork[(*n <<
3051 1) + 1], n, &u[u_offset], ldu);
3053 for (q = 1; q <= i__1; ++q) {
3055 for (p = 1; p <= i__2; ++p) {
3056 i__3 = (*n << 1) + *n * nr + nr + iwork[*n + p];
3057 i__4 = p + q * u_dim1;
3058 cwork[i__3].r = u[i__4].r, cwork[i__3].i = u[i__4]
3063 for (p = 1; p <= i__2; ++p) {
3064 i__3 = p + q * u_dim1;
3065 i__4 = (*n << 1) + *n * nr + nr + p;
3066 u[i__3].r = cwork[i__4].r, u[i__3].i = cwork[i__4]
3074 claset_("A", &i__1, &nr, &c_b1, &c_b1, &v[nr + 1 +
3077 claset_("A", &nr, &i__1, &c_b1, &c_b1, &v[(nr + 1) *
3081 claset_("A", &i__1, &i__2, &c_b1, &c_b2, &v[nr + 1 + (
3082 nr + 1) * v_dim1], ldv);
3084 i__1 = *lwork - (*n << 1) - *n * nr - nr;
3085 cunmqr_("L", "N", n, n, &nr, &cwork[(*n << 1) + 1], n, &
3086 cwork[*n + 1], &v[v_offset], ldv, &cwork[(*n << 1)
3087 + *n * nr + nr + 1], &i__1, &ierr);
3089 /* Last line of defense. */
3090 /* #:( This is a rather pathological case: no scaled condition */
3091 /* improvement after two pivoted QR factorizations. Other */
3092 /* possibility is that the rank revealing QR factorization */
3093 /* or the condition estimator has failed, or the COND_OK */
3094 /* is set very close to ONE (which is unnecessary). Normally, */
3095 /* this branch should never be executed, but in rare cases of */
3096 /* failure of the RRQR or condition estimator, the last line of */
3097 /* defense ensures that CGEJSV completes the task. */
3098 /* Compute the full SVD of L3 using CGESVJ with explicit */
3099 /* accumulation of Jacobi rotations. */
3100 i__1 = *lwork - (*n << 1) - *n * nr - nr;
3101 cgesvj_("L", "U", "V", &nr, &nr, &v[v_offset], ldv, &sva[
3102 1], &nr, &u[u_offset], ldu, &cwork[(*n << 1) + *n
3103 * nr + nr + 1], &i__1, &rwork[1], lrwork, info);
3105 numrank = i_nint(&rwork[2]);
3108 claset_("A", &i__1, &nr, &c_b1, &c_b1, &v[nr + 1 +
3111 claset_("A", &nr, &i__1, &c_b1, &c_b1, &v[(nr + 1) *
3115 claset_("A", &i__1, &i__2, &c_b1, &c_b2, &v[nr + 1 + (
3116 nr + 1) * v_dim1], ldv);
3118 i__1 = *lwork - (*n << 1) - *n * nr - nr;
3119 cunmqr_("L", "N", n, n, &nr, &cwork[(*n << 1) + 1], n, &
3120 cwork[*n + 1], &v[v_offset], ldv, &cwork[(*n << 1)
3121 + *n * nr + nr + 1], &i__1, &ierr);
3123 i__1 = *lwork - (*n << 1) - *n * nr - nr;
3124 cunmlq_("L", "C", &nr, &nr, &nr, &cwork[(*n << 1) + 1], n,
3125 &cwork[(*n << 1) + *n * nr + 1], &u[u_offset],
3126 ldu, &cwork[(*n << 1) + *n * nr + nr + 1], &i__1,
3129 for (q = 1; q <= i__1; ++q) {
3131 for (p = 1; p <= i__2; ++p) {
3132 i__3 = (*n << 1) + *n * nr + nr + iwork[*n + p];
3133 i__4 = p + q * u_dim1;
3134 cwork[i__3].r = u[i__4].r, cwork[i__3].i = u[i__4]
3139 for (p = 1; p <= i__2; ++p) {
3140 i__3 = p + q * u_dim1;
3141 i__4 = (*n << 1) + *n * nr + nr + p;
3142 u[i__3].r = cwork[i__4].r, u[i__3].i = cwork[i__4]
3151 /* Permute the rows of V using the (column) permutation from the */
3152 /* first QRF. Also, scale the columns to make them unit in */
3153 /* Euclidean norm. This applies to all cases. */
3155 temp1 = sqrt((real) (*n)) * epsln;
3157 for (q = 1; q <= i__1; ++q) {
3159 for (p = 1; p <= i__2; ++p) {
3160 i__3 = (*n << 1) + *n * nr + nr + iwork[p];
3161 i__4 = p + q * v_dim1;
3162 cwork[i__3].r = v[i__4].r, cwork[i__3].i = v[i__4].i;
3166 for (p = 1; p <= i__2; ++p) {
3167 i__3 = p + q * v_dim1;
3168 i__4 = (*n << 1) + *n * nr + nr + p;
3169 v[i__3].r = cwork[i__4].r, v[i__3].i = cwork[i__4].i;
3172 xsc = 1.f / scnrm2_(n, &v[q * v_dim1 + 1], &c__1);
3173 if (xsc < 1.f - temp1 || xsc > temp1 + 1.f) {
3174 csscal_(n, &xsc, &v[q * v_dim1 + 1], &c__1);
3178 /* At this moment, V contains the right singular vectors of A. */
3179 /* Next, assemble the left singular vector matrix U (M x N). */
3182 claset_("A", &i__1, &nr, &c_b1, &c_b1, &u[nr + 1 + u_dim1]
3186 claset_("A", &nr, &i__1, &c_b1, &c_b1, &u[(nr + 1) *
3190 claset_("A", &i__1, &i__2, &c_b1, &c_b2, &u[nr + 1 + (
3191 nr + 1) * u_dim1], ldu);
3195 /* The Q matrix from the first QRF is built into the left singular */
3196 /* matrix U. This applies to all cases. */
3199 cunmqr_("L", "N", m, &n1, n, &a[a_offset], lda, &cwork[1], &u[
3200 u_offset], ldu, &cwork[*n + 1], &i__1, &ierr);
3201 /* The columns of U are normalized. The cost is O(M*N) flops. */
3202 temp1 = sqrt((real) (*m)) * epsln;
3204 for (p = 1; p <= i__1; ++p) {
3205 xsc = 1.f / scnrm2_(m, &u[p * u_dim1 + 1], &c__1);
3206 if (xsc < 1.f - temp1 || xsc > temp1 + 1.f) {
3207 csscal_(m, &xsc, &u[p * u_dim1 + 1], &c__1);
3212 /* If the initial QRF is computed with row pivoting, the left */
3213 /* singular vectors must be adjusted. */
3217 claswp_(&n1, &u[u_offset], ldu, &c__1, &i__1, &iwork[
3223 /* the second QRF is not needed */
3225 clacpy_("U", n, n, &a[a_offset], lda, &cwork[*n + 1], n);
3229 for (p = 2; p <= i__1; ++p) {
3230 i__2 = *n + (p - 1) * *n + p;
3231 q__1.r = xsc * cwork[i__2].r, q__1.i = xsc * cwork[
3233 ctemp.r = q__1.r, ctemp.i = q__1.i;
3235 for (q = 1; q <= i__2; ++q) {
3236 /* CWORK(N+(q-1)*N+p)=-TEMP1 * ( CWORK(N+(p-1)*N+q) / */
3237 /* $ ABS(CWORK(N+(p-1)*N+q)) ) */
3238 i__3 = *n + (q - 1) * *n + p;
3239 q__1.r = -ctemp.r, q__1.i = -ctemp.i;
3240 cwork[i__3].r = q__1.r, cwork[i__3].i = q__1.i;
3248 claset_("L", &i__1, &i__2, &c_b1, &c_b1, &cwork[*n + 2],
3252 i__1 = *lwork - *n - *n * *n;
3253 cgesvj_("U", "U", "N", n, n, &cwork[*n + 1], n, &sva[1], n, &
3254 u[u_offset], ldu, &cwork[*n + *n * *n + 1], &i__1, &
3255 rwork[1], lrwork, info);
3258 numrank = i_nint(&rwork[2]);
3260 for (p = 1; p <= i__1; ++p) {
3261 ccopy_(n, &cwork[*n + (p - 1) * *n + 1], &c__1, &u[p *
3262 u_dim1 + 1], &c__1);
3263 csscal_(n, &sva[p], &cwork[*n + (p - 1) * *n + 1], &c__1);
3267 ctrsm_("L", "U", "N", "N", n, n, &c_b2, &a[a_offset], lda, &
3270 for (p = 1; p <= i__1; ++p) {
3271 ccopy_(n, &cwork[*n + p], n, &v[iwork[p] + v_dim1], ldv);
3274 temp1 = sqrt((real) (*n)) * epsln;
3276 for (p = 1; p <= i__1; ++p) {
3277 xsc = 1.f / scnrm2_(n, &v[p * v_dim1 + 1], &c__1);
3278 if (xsc < 1.f - temp1 || xsc > temp1 + 1.f) {
3279 csscal_(n, &xsc, &v[p * v_dim1 + 1], &c__1);
3284 /* Assemble the left singular vector matrix U (M x N). */
3288 claset_("A", &i__1, n, &c_b1, &c_b1, &u[*n + 1 + u_dim1],
3292 claset_("A", n, &i__1, &c_b1, &c_b1, &u[(*n + 1) *
3296 claset_("A", &i__1, &i__2, &c_b1, &c_b2, &u[*n + 1 + (
3297 *n + 1) * u_dim1], ldu);
3301 cunmqr_("L", "N", m, &n1, n, &a[a_offset], lda, &cwork[1], &u[
3302 u_offset], ldu, &cwork[*n + 1], &i__1, &ierr);
3303 temp1 = sqrt((real) (*m)) * epsln;
3305 for (p = 1; p <= i__1; ++p) {
3306 xsc = 1.f / scnrm2_(m, &u[p * u_dim1 + 1], &c__1);
3307 if (xsc < 1.f - temp1 || xsc > temp1 + 1.f) {
3308 csscal_(m, &xsc, &u[p * u_dim1 + 1], &c__1);
3315 claswp_(&n1, &u[u_offset], ldu, &c__1, &i__1, &iwork[
3321 /* end of the >> almost orthogonal case << in the full SVD */
3325 /* This branch deploys a preconditioned Jacobi SVD with explicitly */
3326 /* accumulated rotations. It is included as optional, mainly for */
3327 /* experimental purposes. It does perform well, and can also be used. */
3328 /* In this implementation, this branch will be automatically activated */
3329 /* if the condition number sigma_max(A) / sigma_min(A) is predicted */
3330 /* to be greater than the overflow threshold. This is because the */
3331 /* a posteriori computation of the singular vectors assumes robust */
3332 /* implementation of BLAS and some LAPACK procedures, capable of working */
3333 /* in presence of extreme values, e.g. when the singular values spread from */
3334 /* the underflow to the overflow threshold. */
3337 for (p = 1; p <= i__1; ++p) {
3339 ccopy_(&i__2, &a[p + p * a_dim1], lda, &v[p + p * v_dim1], &
3342 clacgv_(&i__2, &v[p + p * v_dim1], &c__1);
3347 xsc = sqrt(small / epsln);
3349 for (q = 1; q <= i__1; ++q) {
3350 r__1 = xsc * c_abs(&v[q + q * v_dim1]);
3351 q__1.r = r__1, q__1.i = 0.f;
3352 ctemp.r = q__1.r, ctemp.i = q__1.i;
3354 for (p = 1; p <= i__2; ++p) {
3355 if (p > q && c_abs(&v[p + q * v_dim1]) <= temp1 || p <
3357 i__3 = p + q * v_dim1;
3358 v[i__3].r = ctemp.r, v[i__3].i = ctemp.i;
3360 /* $ V(p,q) = TEMP1 * ( V(p,q) / ABS(V(p,q)) ) */
3362 i__3 = p + q * v_dim1;
3363 i__4 = p + q * v_dim1;
3364 q__1.r = -v[i__4].r, q__1.i = -v[i__4].i;
3365 v[i__3].r = q__1.r, v[i__3].i = q__1.i;
3374 claset_("U", &i__1, &i__2, &c_b1, &c_b1, &v[(v_dim1 << 1) + 1]
3377 i__1 = *lwork - (*n << 1);
3378 cgeqrf_(n, &nr, &v[v_offset], ldv, &cwork[*n + 1], &cwork[(*n <<
3379 1) + 1], &i__1, &ierr);
3380 clacpy_("L", n, &nr, &v[v_offset], ldv, &cwork[(*n << 1) + 1], n);
3383 for (p = 1; p <= i__1; ++p) {
3385 ccopy_(&i__2, &v[p + p * v_dim1], ldv, &u[p + p * u_dim1], &
3388 clacgv_(&i__2, &u[p + p * u_dim1], &c__1);
3392 xsc = sqrt(small / epsln);
3394 for (q = 2; q <= i__1; ++q) {
3396 for (p = 1; p <= i__2; ++p) {
3398 r__2 = c_abs(&u[p + p * u_dim1]), r__3 = c_abs(&u[q +
3400 r__1 = xsc * f2cmin(r__2,r__3);
3401 q__1.r = r__1, q__1.i = 0.f;
3402 ctemp.r = q__1.r, ctemp.i = q__1.i;
3403 /* U(p,q) = - TEMP1 * ( U(q,p) / ABS(U(q,p)) ) */
3404 i__3 = p + q * u_dim1;
3405 q__1.r = -ctemp.r, q__1.i = -ctemp.i;
3406 u[i__3].r = q__1.r, u[i__3].i = q__1.i;
3414 claset_("U", &i__1, &i__2, &c_b1, &c_b1, &u[(u_dim1 << 1) + 1]
3417 i__1 = *lwork - (*n << 1) - *n * nr;
3418 cgesvj_("L", "U", "V", &nr, &nr, &u[u_offset], ldu, &sva[1], n, &
3419 v[v_offset], ldv, &cwork[(*n << 1) + *n * nr + 1], &i__1,
3420 &rwork[1], lrwork, info);
3422 numrank = i_nint(&rwork[2]);
3425 claset_("A", &i__1, &nr, &c_b1, &c_b1, &v[nr + 1 + v_dim1],
3428 claset_("A", &nr, &i__1, &c_b1, &c_b1, &v[(nr + 1) * v_dim1 +
3432 claset_("A", &i__1, &i__2, &c_b1, &c_b2, &v[nr + 1 + (nr + 1)
3435 i__1 = *lwork - (*n << 1) - *n * nr - nr;
3436 cunmqr_("L", "N", n, n, &nr, &cwork[(*n << 1) + 1], n, &cwork[*n
3437 + 1], &v[v_offset], ldv, &cwork[(*n << 1) + *n * nr + nr
3438 + 1], &i__1, &ierr);
3440 /* Permute the rows of V using the (column) permutation from the */
3441 /* first QRF. Also, scale the columns to make them unit in */
3442 /* Euclidean norm. This applies to all cases. */
3444 temp1 = sqrt((real) (*n)) * epsln;
3446 for (q = 1; q <= i__1; ++q) {
3448 for (p = 1; p <= i__2; ++p) {
3449 i__3 = (*n << 1) + *n * nr + nr + iwork[p];
3450 i__4 = p + q * v_dim1;
3451 cwork[i__3].r = v[i__4].r, cwork[i__3].i = v[i__4].i;
3455 for (p = 1; p <= i__2; ++p) {
3456 i__3 = p + q * v_dim1;
3457 i__4 = (*n << 1) + *n * nr + nr + p;
3458 v[i__3].r = cwork[i__4].r, v[i__3].i = cwork[i__4].i;
3461 xsc = 1.f / scnrm2_(n, &v[q * v_dim1 + 1], &c__1);
3462 if (xsc < 1.f - temp1 || xsc > temp1 + 1.f) {
3463 csscal_(n, &xsc, &v[q * v_dim1 + 1], &c__1);
3468 /* At this moment, V contains the right singular vectors of A. */
3469 /* Next, assemble the left singular vector matrix U (M x N). */
3473 claset_("A", &i__1, &nr, &c_b1, &c_b1, &u[nr + 1 + u_dim1],
3477 claset_("A", &nr, &i__1, &c_b1, &c_b1, &u[(nr + 1) *
3481 claset_("A", &i__1, &i__2, &c_b1, &c_b2, &u[nr + 1 + (nr
3482 + 1) * u_dim1], ldu);
3487 cunmqr_("L", "N", m, &n1, n, &a[a_offset], lda, &cwork[1], &u[
3488 u_offset], ldu, &cwork[*n + 1], &i__1, &ierr);
3492 claswp_(&n1, &u[u_offset], ldu, &c__1, &i__1, &iwork[iwoff +
3500 for (p = 1; p <= i__1; ++p) {
3501 cswap_(n, &u[p * u_dim1 + 1], &c__1, &v[p * v_dim1 + 1], &
3508 /* end of the full SVD */
3510 /* Undo scaling, if necessary (and possible) */
3512 if (uscal2 <= big / sva[1] * uscal1) {
3513 slascl_("G", &c__0, &c__0, &uscal1, &uscal2, &nr, &c__1, &sva[1], n, &
3521 for (p = nr + 1; p <= i__1; ++p) {
3527 rwork[1] = uscal2 * scalem;
3532 if (lsvec && rsvec) {