14 typedef long long BLASLONG;
15 typedef unsigned long long BLASULONG;
17 typedef long BLASLONG;
18 typedef unsigned long BLASULONG;
22 typedef BLASLONG blasint;
24 #define blasabs(x) llabs(x)
26 #define blasabs(x) labs(x)
30 #define blasabs(x) abs(x)
33 typedef blasint integer;
35 typedef unsigned int uinteger;
36 typedef char *address;
37 typedef short int shortint;
39 typedef double doublereal;
40 typedef struct { real r, i; } complex;
41 typedef struct { doublereal r, i; } doublecomplex;
43 static inline _Fcomplex Cf(complex *z) {_Fcomplex zz={z->r , z->i}; return zz;}
44 static inline _Dcomplex Cd(doublecomplex *z) {_Dcomplex zz={z->r , z->i};return zz;}
45 static inline _Fcomplex * _pCf(complex *z) {return (_Fcomplex*)z;}
46 static inline _Dcomplex * _pCd(doublecomplex *z) {return (_Dcomplex*)z;}
48 static inline _Complex float Cf(complex *z) {return z->r + z->i*_Complex_I;}
49 static inline _Complex double Cd(doublecomplex *z) {return z->r + z->i*_Complex_I;}
50 static inline _Complex float * _pCf(complex *z) {return (_Complex float*)z;}
51 static inline _Complex double * _pCd(doublecomplex *z) {return (_Complex double*)z;}
53 #define pCf(z) (*_pCf(z))
54 #define pCd(z) (*_pCd(z))
56 typedef short int shortlogical;
57 typedef char logical1;
58 typedef char integer1;
63 /* Extern is for use with -E */
74 /*external read, write*/
83 /*internal read, write*/
113 /*rewind, backspace, endfile*/
125 ftnint *inex; /*parameters in standard's order*/
151 union Multitype { /* for multiple entry points */
162 typedef union Multitype Multitype;
164 struct Vardesc { /* for Namelist */
170 typedef struct Vardesc Vardesc;
177 typedef struct Namelist Namelist;
179 #define abs(x) ((x) >= 0 ? (x) : -(x))
180 #define dabs(x) (fabs(x))
181 #define f2cmin(a,b) ((a) <= (b) ? (a) : (b))
182 #define f2cmax(a,b) ((a) >= (b) ? (a) : (b))
183 #define dmin(a,b) (f2cmin(a,b))
184 #define dmax(a,b) (f2cmax(a,b))
185 #define bit_test(a,b) ((a) >> (b) & 1)
186 #define bit_clear(a,b) ((a) & ~((uinteger)1 << (b)))
187 #define bit_set(a,b) ((a) | ((uinteger)1 << (b)))
189 #define abort_() { sig_die("Fortran abort routine called", 1); }
190 #define c_abs(z) (cabsf(Cf(z)))
191 #define c_cos(R,Z) { pCf(R)=ccos(Cf(Z)); }
193 #define c_div(c, a, b) {Cf(c)._Val[0] = (Cf(a)._Val[0]/Cf(b)._Val[0]); Cf(c)._Val[1]=(Cf(a)._Val[1]/Cf(b)._Val[1]);}
194 #define z_div(c, a, b) {Cd(c)._Val[0] = (Cd(a)._Val[0]/Cd(b)._Val[0]); Cd(c)._Val[1]=(Cd(a)._Val[1]/df(b)._Val[1]);}
196 #define c_div(c, a, b) {pCf(c) = Cf(a)/Cf(b);}
197 #define z_div(c, a, b) {pCd(c) = Cd(a)/Cd(b);}
199 #define c_exp(R, Z) {pCf(R) = cexpf(Cf(Z));}
200 #define c_log(R, Z) {pCf(R) = clogf(Cf(Z));}
201 #define c_sin(R, Z) {pCf(R) = csinf(Cf(Z));}
202 //#define c_sqrt(R, Z) {*(R) = csqrtf(Cf(Z));}
203 #define c_sqrt(R, Z) {pCf(R) = csqrtf(Cf(Z));}
204 #define d_abs(x) (fabs(*(x)))
205 #define d_acos(x) (acos(*(x)))
206 #define d_asin(x) (asin(*(x)))
207 #define d_atan(x) (atan(*(x)))
208 #define d_atn2(x, y) (atan2(*(x),*(y)))
209 #define d_cnjg(R, Z) { pCd(R) = conj(Cd(Z)); }
210 #define r_cnjg(R, Z) { pCf(R) = conjf(Cf(Z)); }
211 #define d_cos(x) (cos(*(x)))
212 #define d_cosh(x) (cosh(*(x)))
213 #define d_dim(__a, __b) ( *(__a) > *(__b) ? *(__a) - *(__b) : 0.0 )
214 #define d_exp(x) (exp(*(x)))
215 #define d_imag(z) (cimag(Cd(z)))
216 #define r_imag(z) (cimagf(Cf(z)))
217 #define d_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
218 #define r_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
219 #define d_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
220 #define r_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
221 #define d_log(x) (log(*(x)))
222 #define d_mod(x, y) (fmod(*(x), *(y)))
223 #define u_nint(__x) ((__x)>=0 ? floor((__x) + .5) : -floor(.5 - (__x)))
224 #define d_nint(x) u_nint(*(x))
225 #define u_sign(__a,__b) ((__b) >= 0 ? ((__a) >= 0 ? (__a) : -(__a)) : -((__a) >= 0 ? (__a) : -(__a)))
226 #define d_sign(a,b) u_sign(*(a),*(b))
227 #define r_sign(a,b) u_sign(*(a),*(b))
228 #define d_sin(x) (sin(*(x)))
229 #define d_sinh(x) (sinh(*(x)))
230 #define d_sqrt(x) (sqrt(*(x)))
231 #define d_tan(x) (tan(*(x)))
232 #define d_tanh(x) (tanh(*(x)))
233 #define i_abs(x) abs(*(x))
234 #define i_dnnt(x) ((integer)u_nint(*(x)))
235 #define i_len(s, n) (n)
236 #define i_nint(x) ((integer)u_nint(*(x)))
237 #define i_sign(a,b) ((integer)u_sign((integer)*(a),(integer)*(b)))
238 #define pow_dd(ap, bp) ( pow(*(ap), *(bp)))
239 #define pow_si(B,E) spow_ui(*(B),*(E))
240 #define pow_ri(B,E) spow_ui(*(B),*(E))
241 #define pow_di(B,E) dpow_ui(*(B),*(E))
242 #define pow_zi(p, a, b) {pCd(p) = zpow_ui(Cd(a), *(b));}
243 #define pow_ci(p, a, b) {pCf(p) = cpow_ui(Cf(a), *(b));}
244 #define pow_zz(R,A,B) {pCd(R) = cpow(Cd(A),*(B));}
245 #define s_cat(lpp, rpp, rnp, np, llp) { ftnlen i, nc, ll; char *f__rp, *lp; ll = (llp); lp = (lpp); for(i=0; i < (int)*(np); ++i) { nc = ll; if((rnp)[i] < nc) nc = (rnp)[i]; ll -= nc; f__rp = (rpp)[i]; while(--nc >= 0) *lp++ = *(f__rp)++; } while(--ll >= 0) *lp++ = ' '; }
246 #define s_cmp(a,b,c,d) ((integer)strncmp((a),(b),f2cmin((c),(d))))
247 #define s_copy(A,B,C,D) { int __i,__m; for (__i=0, __m=f2cmin((C),(D)); __i<__m && (B)[__i] != 0; ++__i) (A)[__i] = (B)[__i]; }
248 #define sig_die(s, kill) { exit(1); }
249 #define s_stop(s, n) {exit(0);}
250 static char junk[] = "\n@(#)LIBF77 VERSION 19990503\n";
251 #define z_abs(z) (cabs(Cd(z)))
252 #define z_exp(R, Z) {pCd(R) = cexp(Cd(Z));}
253 #define z_sqrt(R, Z) {pCd(R) = csqrt(Cd(Z));}
254 #define myexit_() break;
255 #define mycycle() continue;
256 #define myceiling(w) {ceil(w)}
257 #define myhuge(w) {HUGE_VAL}
258 //#define mymaxloc_(w,s,e,n) {if (sizeof(*(w)) == sizeof(double)) dmaxloc_((w),*(s),*(e),n); else dmaxloc_((w),*(s),*(e),n);}
259 #define mymaxloc(w,s,e,n) {dmaxloc_(w,*(s),*(e),n)}
261 /* procedure parameter types for -A and -C++ */
263 #define F2C_proc_par_types 1
265 typedef logical (*L_fp)(...);
267 typedef logical (*L_fp)();
270 static float spow_ui(float x, integer n) {
271 float pow=1.0; unsigned long int u;
273 if(n < 0) n = -n, x = 1/x;
282 static double dpow_ui(double x, integer n) {
283 double pow=1.0; unsigned long int u;
285 if(n < 0) n = -n, x = 1/x;
295 static _Fcomplex cpow_ui(complex x, integer n) {
296 complex pow={1.0,0.0}; unsigned long int u;
298 if(n < 0) n = -n, x.r = 1/x.r, x.i=1/x.i;
300 if(u & 01) pow.r *= x.r, pow.i *= x.i;
301 if(u >>= 1) x.r *= x.r, x.i *= x.i;
305 _Fcomplex p={pow.r, pow.i};
309 static _Complex float cpow_ui(_Complex float x, integer n) {
310 _Complex float pow=1.0; unsigned long int u;
312 if(n < 0) n = -n, x = 1/x;
323 static _Dcomplex zpow_ui(_Dcomplex x, integer n) {
324 _Dcomplex pow={1.0,0.0}; unsigned long int u;
326 if(n < 0) n = -n, x._Val[0] = 1/x._Val[0], x._Val[1] =1/x._Val[1];
328 if(u & 01) pow._Val[0] *= x._Val[0], pow._Val[1] *= x._Val[1];
329 if(u >>= 1) x._Val[0] *= x._Val[0], x._Val[1] *= x._Val[1];
333 _Dcomplex p = {pow._Val[0], pow._Val[1]};
337 static _Complex double zpow_ui(_Complex double x, integer n) {
338 _Complex double pow=1.0; unsigned long int u;
340 if(n < 0) n = -n, x = 1/x;
350 static integer pow_ii(integer x, integer n) {
351 integer pow; unsigned long int u;
353 if (n == 0 || x == 1) pow = 1;
354 else if (x != -1) pow = x == 0 ? 1/x : 0;
357 if ((n > 0) || !(n == 0 || x == 1 || x != -1)) {
367 static integer dmaxloc_(double *w, integer s, integer e, integer *n)
369 double m; integer i, mi;
370 for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
371 if (w[i-1]>m) mi=i ,m=w[i-1];
374 static integer smaxloc_(float *w, integer s, integer e, integer *n)
376 float m; integer i, mi;
377 for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
378 if (w[i-1]>m) mi=i ,m=w[i-1];
381 static inline void cdotc_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
382 integer n = *n_, incx = *incx_, incy = *incy_, i;
384 _Fcomplex zdotc = {0.0, 0.0};
385 if (incx == 1 && incy == 1) {
386 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
387 zdotc._Val[0] += conjf(Cf(&x[i]))._Val[0] * Cf(&y[i])._Val[0];
388 zdotc._Val[1] += conjf(Cf(&x[i]))._Val[1] * Cf(&y[i])._Val[1];
391 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
392 zdotc._Val[0] += conjf(Cf(&x[i*incx]))._Val[0] * Cf(&y[i*incy])._Val[0];
393 zdotc._Val[1] += conjf(Cf(&x[i*incx]))._Val[1] * Cf(&y[i*incy])._Val[1];
399 _Complex float zdotc = 0.0;
400 if (incx == 1 && incy == 1) {
401 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
402 zdotc += conjf(Cf(&x[i])) * Cf(&y[i]);
405 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
406 zdotc += conjf(Cf(&x[i*incx])) * Cf(&y[i*incy]);
412 static inline void zdotc_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
413 integer n = *n_, incx = *incx_, incy = *incy_, i;
415 _Dcomplex zdotc = {0.0, 0.0};
416 if (incx == 1 && incy == 1) {
417 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
418 zdotc._Val[0] += conj(Cd(&x[i]))._Val[0] * Cd(&y[i])._Val[0];
419 zdotc._Val[1] += conj(Cd(&x[i]))._Val[1] * Cd(&y[i])._Val[1];
422 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
423 zdotc._Val[0] += conj(Cd(&x[i*incx]))._Val[0] * Cd(&y[i*incy])._Val[0];
424 zdotc._Val[1] += conj(Cd(&x[i*incx]))._Val[1] * Cd(&y[i*incy])._Val[1];
430 _Complex double zdotc = 0.0;
431 if (incx == 1 && incy == 1) {
432 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
433 zdotc += conj(Cd(&x[i])) * Cd(&y[i]);
436 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
437 zdotc += conj(Cd(&x[i*incx])) * Cd(&y[i*incy]);
443 static inline void cdotu_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
444 integer n = *n_, incx = *incx_, incy = *incy_, i;
446 _Fcomplex zdotc = {0.0, 0.0};
447 if (incx == 1 && incy == 1) {
448 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
449 zdotc._Val[0] += Cf(&x[i])._Val[0] * Cf(&y[i])._Val[0];
450 zdotc._Val[1] += Cf(&x[i])._Val[1] * Cf(&y[i])._Val[1];
453 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
454 zdotc._Val[0] += Cf(&x[i*incx])._Val[0] * Cf(&y[i*incy])._Val[0];
455 zdotc._Val[1] += Cf(&x[i*incx])._Val[1] * Cf(&y[i*incy])._Val[1];
461 _Complex float zdotc = 0.0;
462 if (incx == 1 && incy == 1) {
463 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
464 zdotc += Cf(&x[i]) * Cf(&y[i]);
467 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
468 zdotc += Cf(&x[i*incx]) * Cf(&y[i*incy]);
474 static inline void zdotu_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
475 integer n = *n_, incx = *incx_, incy = *incy_, i;
477 _Dcomplex zdotc = {0.0, 0.0};
478 if (incx == 1 && incy == 1) {
479 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
480 zdotc._Val[0] += Cd(&x[i])._Val[0] * Cd(&y[i])._Val[0];
481 zdotc._Val[1] += Cd(&x[i])._Val[1] * Cd(&y[i])._Val[1];
484 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
485 zdotc._Val[0] += Cd(&x[i*incx])._Val[0] * Cd(&y[i*incy])._Val[0];
486 zdotc._Val[1] += Cd(&x[i*incx])._Val[1] * Cd(&y[i*incy])._Val[1];
492 _Complex double zdotc = 0.0;
493 if (incx == 1 && incy == 1) {
494 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
495 zdotc += Cd(&x[i]) * Cd(&y[i]);
498 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
499 zdotc += Cd(&x[i*incx]) * Cd(&y[i*incy]);
505 /* -- translated by f2c (version 20000121).
506 You must link the resulting object file with the libraries:
507 -lf2c -lm (in that order)
513 /* Table of constant values */
515 static doublereal c_b17 = 0.;
516 static doublereal c_b18 = 1.;
517 static integer c__1 = 1;
518 static integer c__0 = 0;
519 static integer c__2 = 2;
521 /* > \brief \b DGESVJ */
523 /* =========== DOCUMENTATION =========== */
525 /* Online html documentation available at */
526 /* http://www.netlib.org/lapack/explore-html/ */
529 /* > Download DGESVJ + dependencies */
530 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dgesvj.
533 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dgesvj.
536 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dgesvj.
544 /* SUBROUTINE DGESVJ( JOBA, JOBU, JOBV, M, N, A, LDA, SVA, MV, V, */
545 /* LDV, WORK, LWORK, INFO ) */
547 /* INTEGER INFO, LDA, LDV, LWORK, M, MV, N */
548 /* CHARACTER*1 JOBA, JOBU, JOBV */
549 /* DOUBLE PRECISION A( LDA, * ), SVA( N ), V( LDV, * ), */
550 /* $ WORK( LWORK ) */
553 /* > \par Purpose: */
558 /* > DGESVJ computes the singular value decomposition (SVD) of a real */
559 /* > M-by-N matrix A, where M >= N. The SVD of A is written as */
560 /* > [++] [xx] [x0] [xx] */
561 /* > A = U * SIGMA * V^t, [++] = [xx] * [ox] * [xx] */
563 /* > where SIGMA is an N-by-N diagonal matrix, U is an M-by-N orthonormal */
564 /* > matrix, and V is an N-by-N orthogonal matrix. The diagonal elements */
565 /* > of SIGMA are the singular values of A. The columns of U and V are the */
566 /* > left and the right singular vectors of A, respectively. */
567 /* > DGESVJ can sometimes compute tiny singular values and their singular vectors much */
568 /* > more accurately than other SVD routines, see below under Further Details. */
574 /* > \param[in] JOBA */
576 /* > JOBA is CHARACTER*1 */
577 /* > Specifies the structure of A. */
578 /* > = 'L': The input matrix A is lower triangular; */
579 /* > = 'U': The input matrix A is upper triangular; */
580 /* > = 'G': The input matrix A is general M-by-N matrix, M >= N. */
583 /* > \param[in] JOBU */
585 /* > JOBU is CHARACTER*1 */
586 /* > Specifies whether to compute the left singular vectors */
587 /* > (columns of U): */
588 /* > = 'U': The left singular vectors corresponding to the nonzero */
589 /* > singular values are computed and returned in the leading */
590 /* > columns of A. See more details in the description of A. */
591 /* > The default numerical orthogonality threshold is set to */
592 /* > approximately TOL=CTOL*EPS, CTOL=DSQRT(M), EPS=DLAMCH('E'). */
593 /* > = 'C': Analogous to JOBU='U', except that user can control the */
594 /* > level of numerical orthogonality of the computed left */
595 /* > singular vectors. TOL can be set to TOL = CTOL*EPS, where */
596 /* > CTOL is given on input in the array WORK. */
597 /* > No CTOL smaller than ONE is allowed. CTOL greater */
598 /* > than 1 / EPS is meaningless. The option 'C' */
599 /* > can be used if M*EPS is satisfactory orthogonality */
600 /* > of the computed left singular vectors, so CTOL=M could */
601 /* > save few sweeps of Jacobi rotations. */
602 /* > See the descriptions of A and WORK(1). */
603 /* > = 'N': The matrix U is not computed. However, see the */
604 /* > description of A. */
607 /* > \param[in] JOBV */
609 /* > JOBV is CHARACTER*1 */
610 /* > Specifies whether to compute the right singular vectors, that */
611 /* > is, the matrix V: */
612 /* > = 'V': the matrix V is computed and returned in the array V */
613 /* > = 'A': the Jacobi rotations are applied to the MV-by-N */
614 /* > array V. In other words, the right singular vector */
615 /* > matrix V is not computed explicitly, instead it is */
616 /* > applied to an MV-by-N matrix initially stored in the */
617 /* > first MV rows of V. */
618 /* > = 'N': the matrix V is not computed and the array V is not */
625 /* > The number of rows of the input matrix A. 1/DLAMCH('E') > M >= 0. */
631 /* > The number of columns of the input matrix A. */
635 /* > \param[in,out] A */
637 /* > A is DOUBLE PRECISION array, dimension (LDA,N) */
638 /* > On entry, the M-by-N matrix A. */
640 /* > If JOBU = 'U' .OR. JOBU = 'C' : */
641 /* > If INFO = 0 : */
642 /* > RANKA orthonormal columns of U are returned in the */
643 /* > leading RANKA columns of the array A. Here RANKA <= N */
644 /* > is the number of computed singular values of A that are */
645 /* > above the underflow threshold DLAMCH('S'). The singular */
646 /* > vectors corresponding to underflowed or zero singular */
647 /* > values are not computed. The value of RANKA is returned */
648 /* > in the array WORK as RANKA=NINT(WORK(2)). Also see the */
649 /* > descriptions of SVA and WORK. The computed columns of U */
650 /* > are mutually numerically orthogonal up to approximately */
651 /* > TOL=DSQRT(M)*EPS (default); or TOL=CTOL*EPS (JOBU = 'C'), */
652 /* > see the description of JOBU. */
653 /* > If INFO > 0 : */
654 /* > the procedure DGESVJ did not converge in the given number */
655 /* > of iterations (sweeps). In that case, the computed */
656 /* > columns of U may not be orthogonal up to TOL. The output */
657 /* > U (stored in A), SIGMA (given by the computed singular */
658 /* > values in SVA(1:N)) and V is still a decomposition of the */
659 /* > input matrix A in the sense that the residual */
660 /* > ||A-SCALE*U*SIGMA*V^T||_2 / ||A||_2 is small. */
662 /* > If JOBU = 'N' : */
663 /* > If INFO = 0 : */
664 /* > Note that the left singular vectors are 'for free' in the */
665 /* > one-sided Jacobi SVD algorithm. However, if only the */
666 /* > singular values are needed, the level of numerical */
667 /* > orthogonality of U is not an issue and iterations are */
668 /* > stopped when the columns of the iterated matrix are */
669 /* > numerically orthogonal up to approximately M*EPS. Thus, */
670 /* > on exit, A contains the columns of U scaled with the */
671 /* > corresponding singular values. */
672 /* > If INFO > 0 : */
673 /* > the procedure DGESVJ did not converge in the given number */
674 /* > of iterations (sweeps). */
677 /* > \param[in] LDA */
679 /* > LDA is INTEGER */
680 /* > The leading dimension of the array A. LDA >= f2cmax(1,M). */
683 /* > \param[out] SVA */
685 /* > SVA is DOUBLE PRECISION array, dimension (N) */
687 /* > If INFO = 0 : */
688 /* > depending on the value SCALE = WORK(1), we have: */
689 /* > If SCALE = ONE : */
690 /* > SVA(1:N) contains the computed singular values of A. */
691 /* > During the computation SVA contains the Euclidean column */
692 /* > norms of the iterated matrices in the array A. */
693 /* > If SCALE .NE. ONE : */
694 /* > The singular values of A are SCALE*SVA(1:N), and this */
695 /* > factored representation is due to the fact that some of the */
696 /* > singular values of A might underflow or overflow. */
697 /* > If INFO > 0 : */
698 /* > the procedure DGESVJ did not converge in the given number of */
699 /* > iterations (sweeps) and SCALE*SVA(1:N) may not be accurate. */
702 /* > \param[in] MV */
704 /* > MV is INTEGER */
705 /* > If JOBV = 'A', then the product of Jacobi rotations in DGESVJ */
706 /* > is applied to the first MV rows of V. See the description of JOBV. */
709 /* > \param[in,out] V */
711 /* > V is DOUBLE PRECISION array, dimension (LDV,N) */
712 /* > If JOBV = 'V', then V contains on exit the N-by-N matrix of */
713 /* > the right singular vectors; */
714 /* > If JOBV = 'A', then V contains the product of the computed right */
715 /* > singular vector matrix and the initial matrix in */
717 /* > If JOBV = 'N', then V is not referenced. */
720 /* > \param[in] LDV */
722 /* > LDV is INTEGER */
723 /* > The leading dimension of the array V, LDV >= 1. */
724 /* > If JOBV = 'V', then LDV >= f2cmax(1,N). */
725 /* > If JOBV = 'A', then LDV >= f2cmax(1,MV) . */
728 /* > \param[in,out] WORK */
730 /* > WORK is DOUBLE PRECISION array, dimension (LWORK) */
732 /* > If JOBU = 'C' : */
733 /* > WORK(1) = CTOL, where CTOL defines the threshold for convergence. */
734 /* > The process stops if all columns of A are mutually */
735 /* > orthogonal up to CTOL*EPS, EPS=DLAMCH('E'). */
736 /* > It is required that CTOL >= ONE, i.e. it is not */
737 /* > allowed to force the routine to obtain orthogonality */
740 /* > WORK(1) = SCALE is the scaling factor such that SCALE*SVA(1:N) */
741 /* > are the computed singular values of A. */
742 /* > (See description of SVA().) */
743 /* > WORK(2) = NINT(WORK(2)) is the number of the computed nonzero */
744 /* > singular values. */
745 /* > WORK(3) = NINT(WORK(3)) is the number of the computed singular */
746 /* > values that are larger than the underflow threshold. */
747 /* > WORK(4) = NINT(WORK(4)) is the number of sweeps of Jacobi */
748 /* > rotations needed for numerical convergence. */
749 /* > WORK(5) = max_{i.NE.j} |COS(A(:,i),A(:,j))| in the last sweep. */
750 /* > This is useful information in cases when DGESVJ did */
751 /* > not converge, as it can be used to estimate whether */
752 /* > the output is still useful and for post festum analysis. */
753 /* > WORK(6) = the largest absolute value over all sines of the */
754 /* > Jacobi rotation angles in the last sweep. It can be */
755 /* > useful for a post festum analysis. */
758 /* > \param[in] LWORK */
760 /* > LWORK is INTEGER */
761 /* > length of WORK, WORK >= MAX(6,M+N) */
764 /* > \param[out] INFO */
766 /* > INFO is INTEGER */
767 /* > = 0: successful exit. */
768 /* > < 0: if INFO = -i, then the i-th argument had an illegal value */
769 /* > > 0: DGESVJ did not converge in the maximal allowed number (30) */
770 /* > of sweeps. The output may still be useful. See the */
771 /* > description of WORK. */
777 /* > \author Univ. of Tennessee */
778 /* > \author Univ. of California Berkeley */
779 /* > \author Univ. of Colorado Denver */
780 /* > \author NAG Ltd. */
782 /* > \date June 2017 */
784 /* > \ingroup doubleGEcomputational */
786 /* > \par Further Details: */
787 /* ===================== */
791 /* > The orthogonal N-by-N matrix V is obtained as a product of Jacobi plane */
792 /* > rotations. The rotations are implemented as fast scaled rotations of */
793 /* > Anda and Park [1]. In the case of underflow of the Jacobi angle, a */
794 /* > modified Jacobi transformation of Drmac [4] is used. Pivot strategy uses */
795 /* > column interchanges of de Rijk [2]. The relative accuracy of the computed */
796 /* > singular values and the accuracy of the computed singular vectors (in */
797 /* > angle metric) is as guaranteed by the theory of Demmel and Veselic [3]. */
798 /* > The condition number that determines the accuracy in the full rank case */
799 /* > is essentially min_{D=diag} kappa(A*D), where kappa(.) is the */
800 /* > spectral condition number. The best performance of this Jacobi SVD */
801 /* > procedure is achieved if used in an accelerated version of Drmac and */
802 /* > Veselic [5,6], and it is the kernel routine in the SIGMA library [7]. */
803 /* > Some tunning parameters (marked with [TP]) are available for the */
805 /* > The computational range for the nonzero singular values is the machine */
806 /* > number interval ( UNDERFLOW , OVERFLOW ). In extreme cases, even */
807 /* > denormalized singular values can be computed with the corresponding */
808 /* > gradual loss of accurate digits. */
811 /* > \par Contributors: */
812 /* ================== */
818 /* > Zlatko Drmac (Zagreb, Croatia) and Kresimir Veselic (Hagen, Germany) */
821 /* > \par References: */
822 /* ================ */
826 /* > [1] A. A. Anda and H. Park: Fast plane rotations with dynamic scaling. */
827 /* > SIAM J. matrix Anal. Appl., Vol. 15 (1994), pp. 162-174. */
828 /* > [2] P. P. M. De Rijk: A one-sided Jacobi algorithm for computing the */
829 /* > singular value decomposition on a vector computer. */
830 /* > SIAM J. Sci. Stat. Comp., Vol. 10 (1998), pp. 359-371. */
831 /* > [3] J. Demmel and K. Veselic: Jacobi method is more accurate than QR. */
832 /* > [4] Z. Drmac: Implementation of Jacobi rotations for accurate singular */
833 /* > value computation in floating point arithmetic. */
834 /* > SIAM J. Sci. Comp., Vol. 18 (1997), pp. 1200-1222. */
835 /* > [5] Z. Drmac and K. Veselic: New fast and accurate Jacobi SVD algorithm I. */
836 /* > SIAM J. Matrix Anal. Appl. Vol. 35, No. 2 (2008), pp. 1322-1342. */
837 /* > LAPACK Working note 169. */
838 /* > [6] Z. Drmac and K. Veselic: New fast and accurate Jacobi SVD algorithm II. */
839 /* > SIAM J. Matrix Anal. Appl. Vol. 35, No. 2 (2008), pp. 1343-1362. */
840 /* > LAPACK Working note 170. */
841 /* > [7] Z. Drmac: SIGMA - mathematical software library for accurate SVD, PSV, */
842 /* > QSVD, (H,K)-SVD computations. */
843 /* > Department of Mathematics, University of Zagreb, 2008. */
846 /* > \par Bugs, examples and comments: */
847 /* ================================= */
850 /* > =========================== */
851 /* > Please report all bugs and send interesting test examples and comments to */
852 /* > drmac@math.hr. Thank you. */
855 /* ===================================================================== */
856 /* Subroutine */ int dgesvj_(char *joba, char *jobu, char *jobv, integer *m,
857 integer *n, doublereal *a, integer *lda, doublereal *sva, integer *mv,
858 doublereal *v, integer *ldv, doublereal *work, integer *lwork,
861 /* System generated locals */
862 integer a_dim1, a_offset, v_dim1, v_offset, i__1, i__2, i__3, i__4, i__5;
863 doublereal d__1, d__2;
865 /* Local variables */
866 doublereal aapp, aapq, aaqq;
867 extern doublereal ddot_(integer *, doublereal *, integer *, doublereal *,
874 extern doublereal dnrm2_(integer *, doublereal *, integer *);
878 extern /* Subroutine */ int dscal_(integer *, doublereal *, doublereal *,
880 doublereal large, apoaq, aqoap;
881 extern logical lsame_(char *, char *);
882 doublereal theta, small, sfmin;
884 extern /* Subroutine */ int dcopy_(integer *, doublereal *, integer *,
885 doublereal *, integer *);
887 extern /* Subroutine */ int dswap_(integer *, doublereal *, integer *,
888 doublereal *, integer *);
890 logical applv, rsvec;
891 extern /* Subroutine */ int daxpy_(integer *, doublereal *, doublereal *,
892 integer *, doublereal *, integer *);
894 extern /* Subroutine */ int drotm_(integer *, doublereal *, integer *,
895 doublereal *, integer *, doublereal *);
896 logical lower, upper, rotok;
898 extern /* Subroutine */ int dgsvj0_(char *, integer *, integer *,
899 doublereal *, integer *, doublereal *, doublereal *, integer *,
900 doublereal *, integer *, doublereal *, doublereal *, doublereal *,
901 integer *, doublereal *, integer *, integer *), dgsvj1_(
902 char *, integer *, integer *, integer *, doublereal *, integer *,
903 doublereal *, doublereal *, integer *, doublereal *, integer *,
904 doublereal *, doublereal *, doublereal *, integer *, doublereal *,
905 integer *, integer *);
906 doublereal rootsfmin;
909 extern doublereal dlamch_(char *);
911 extern /* Subroutine */ int dlascl_(char *, integer *, integer *,
912 doublereal *, doublereal *, integer *, integer *, doublereal *,
913 integer *, integer *);
914 extern integer idamax_(integer *, doublereal *, integer *);
915 extern /* Subroutine */ int dlaset_(char *, integer *, integer *,
916 doublereal *, doublereal *, doublereal *, integer *),
917 xerbla_(char *, integer *, ftnlen);
918 integer ijblsk, swband, blskip;
920 extern /* Subroutine */ int dlassq_(integer *, doublereal *, integer *,
921 doublereal *, doublereal *);
922 doublereal thsign, mxsinj;
923 integer ir1, emptsw, notrot, iswrot, jbc;
925 integer kbl, lkahead, igl, ibr, jgl, nbl;
931 doublereal rootbig, rooteps;
936 /* -- LAPACK computational routine (version 3.7.1) -- */
937 /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
938 /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
942 /* ===================================================================== */
950 /* Test the input arguments */
952 /* Parameter adjustments */
955 a_offset = 1 + a_dim1 * 1;
958 v_offset = 1 + v_dim1 * 1;
963 lsvec = lsame_(jobu, "U");
964 uctol = lsame_(jobu, "C");
965 rsvec = lsame_(jobv, "V");
966 applv = lsame_(jobv, "A");
967 upper = lsame_(joba, "U");
968 lower = lsame_(joba, "L");
970 if (! (upper || lower || lsame_(joba, "G"))) {
972 } else if (! (lsvec || uctol || lsame_(jobu, "N")))
975 } else if (! (rsvec || applv || lsame_(jobv, "N")))
980 } else if (*n < 0 || *n > *m) {
982 } else if (*lda < *m) {
984 } else if (*mv < 0) {
986 } else if (rsvec && *ldv < *n || applv && *ldv < *mv) {
988 } else if (uctol && work[1] <= 1.) {
990 } else /* if(complicated condition) */ {
993 if (*lwork < f2cmax(i__1,6)) {
1003 xerbla_("DGESVJ", &i__1, (ftnlen)6);
1007 /* #:) Quick return for void matrix */
1009 if (*m == 0 || *n == 0) {
1013 /* Set numerical parameters */
1014 /* The stopping criterion for Jacobi rotations is */
1016 /* max_{i<>j}|A(:,i)^T * A(:,j)|/(||A(:,i)||*||A(:,j)||) < CTOL*EPS */
1018 /* where EPS is the round-off and CTOL is defined as follows: */
1021 /* ... user controlled */
1025 if (lsvec || rsvec || applv) {
1026 ctol = sqrt((doublereal) (*m));
1028 ctol = (doublereal) (*m);
1031 /* ... and the machine dependent parameters are */
1032 /* [!] (Make sure that DLAMCH() works properly on the target machine.) */
1034 epsln = dlamch_("Epsilon");
1035 rooteps = sqrt(epsln);
1036 sfmin = dlamch_("SafeMinimum");
1037 rootsfmin = sqrt(sfmin);
1038 small = sfmin / epsln;
1039 big = dlamch_("Overflow");
1040 /* BIG = ONE / SFMIN */
1041 rootbig = 1. / rootsfmin;
1042 large = big / sqrt((doublereal) (*m * *n));
1043 bigtheta = 1. / rooteps;
1046 roottol = sqrt(tol);
1048 if ((doublereal) (*m) * epsln >= 1.) {
1051 xerbla_("DGESVJ", &i__1, (ftnlen)6);
1055 /* Initialize the right singular vector matrix. */
1059 dlaset_("A", &mvl, n, &c_b17, &c_b18, &v[v_offset], ldv);
1063 rsvec = rsvec || applv;
1065 /* Initialize SVA( 1:N ) = ( ||A e_i||_2, i = 1:N ) */
1066 /* (!) If necessary, scale A to protect the largest singular value */
1067 /* from overflow. It is possible that saving the largest singular */
1068 /* value destroys the information about the small ones. */
1069 /* This initial scaling is almost minimal in the sense that the */
1070 /* goal is to make sure that no column norm overflows, and that */
1071 /* DSQRT(N)*max_i SVA(i) does not overflow. If INFinite entries */
1072 /* in A are detected, the procedure returns with INFO=-6. */
1074 skl = 1. / sqrt((doublereal) (*m) * (doublereal) (*n));
1079 /* the input matrix is M-by-N lower triangular (trapezoidal) */
1081 for (p = 1; p <= i__1; ++p) {
1085 dlassq_(&i__2, &a[p + p * a_dim1], &c__1, &aapp, &aaqq);
1089 xerbla_("DGESVJ", &i__2, (ftnlen)6);
1093 if (aapp < big / aaqq && noscale) {
1094 sva[p] = aapp * aaqq;
1097 sva[p] = aapp * (aaqq * skl);
1101 for (q = 1; q <= i__2; ++q) {
1110 /* the input matrix is M-by-N upper triangular (trapezoidal) */
1112 for (p = 1; p <= i__1; ++p) {
1115 dlassq_(&p, &a[p * a_dim1 + 1], &c__1, &aapp, &aaqq);
1119 xerbla_("DGESVJ", &i__2, (ftnlen)6);
1123 if (aapp < big / aaqq && noscale) {
1124 sva[p] = aapp * aaqq;
1127 sva[p] = aapp * (aaqq * skl);
1131 for (q = 1; q <= i__2; ++q) {
1140 /* the input matrix is M-by-N general dense */
1142 for (p = 1; p <= i__1; ++p) {
1145 dlassq_(m, &a[p * a_dim1 + 1], &c__1, &aapp, &aaqq);
1149 xerbla_("DGESVJ", &i__2, (ftnlen)6);
1153 if (aapp < big / aaqq && noscale) {
1154 sva[p] = aapp * aaqq;
1157 sva[p] = aapp * (aaqq * skl);
1161 for (q = 1; q <= i__2; ++q) {
1175 /* Move the smaller part of the spectrum from the underflow threshold */
1176 /* (!) Start by determining the position of the nonzero entries of the */
1177 /* array SVA() relative to ( SFMIN, BIG ). */
1182 for (p = 1; p <= i__1; ++p) {
1185 d__1 = aaqq, d__2 = sva[p];
1186 aaqq = f2cmin(d__1,d__2);
1189 d__1 = aapp, d__2 = sva[p];
1190 aapp = f2cmax(d__1,d__2);
1194 /* #:) Quick return for zero matrix */
1198 dlaset_("G", m, n, &c_b17, &c_b18, &a[a_offset], lda);
1209 /* #:) Quick return for one-column matrix */
1213 dlascl_("G", &c__0, &c__0, &sva[1], &skl, m, &c__1, &a[a_dim1 + 1]
1217 if (sva[1] >= sfmin) {
1229 /* Protect small singular values from underflow, and try to */
1230 /* avoid underflows/overflows in computing Jacobi rotations. */
1232 sn = sqrt(sfmin / epsln);
1233 temp1 = sqrt(big / (doublereal) (*n));
1234 if (aapp <= sn || aaqq >= temp1 || sn <= aaqq && aapp <= temp1) {
1236 d__1 = big, d__2 = temp1 / aapp;
1237 temp1 = f2cmin(d__1,d__2);
1238 /* AAQQ = AAQQ*TEMP1 */
1239 /* AAPP = AAPP*TEMP1 */
1240 } else if (aaqq <= sn && aapp <= temp1) {
1242 d__1 = sn / aaqq, d__2 = big / (aapp * sqrt((doublereal) (*n)));
1243 temp1 = f2cmin(d__1,d__2);
1244 /* AAQQ = AAQQ*TEMP1 */
1245 /* AAPP = AAPP*TEMP1 */
1246 } else if (aaqq >= sn && aapp >= temp1) {
1248 d__1 = sn / aaqq, d__2 = temp1 / aapp;
1249 temp1 = f2cmax(d__1,d__2);
1250 /* AAQQ = AAQQ*TEMP1 */
1251 /* AAPP = AAPP*TEMP1 */
1252 } else if (aaqq <= sn && aapp >= temp1) {
1254 d__1 = sn / aaqq, d__2 = big / (sqrt((doublereal) (*n)) * aapp);
1255 temp1 = f2cmin(d__1,d__2);
1256 /* AAQQ = AAQQ*TEMP1 */
1257 /* AAPP = AAPP*TEMP1 */
1262 /* Scale, if necessary */
1265 dlascl_("G", &c__0, &c__0, &c_b18, &temp1, n, &c__1, &sva[1], n, &
1270 dlascl_(joba, &c__0, &c__0, &c_b18, &skl, m, n, &a[a_offset], lda, &
1275 /* Row-cyclic Jacobi SVD algorithm with column pivoting */
1277 emptsw = *n * (*n - 1) / 2;
1281 /* A is represented in factored form A = A * diag(WORK), where diag(WORK) */
1282 /* is initialized to identity. WORK is updated during fast scaled */
1286 for (q = 1; q <= i__1; ++q) {
1293 /* [TP] SWBAND is a tuning parameter [TP]. It is meaningful and effective */
1294 /* if DGESVJ is used as a computational routine in the preconditioned */
1295 /* Jacobi SVD algorithm DGESVJ. For sweeps i=1:SWBAND the procedure */
1296 /* works on pivots inside a band-like region around the diagonal. */
1297 /* The boundaries are determined dynamically, based on the number of */
1298 /* pivots above a threshold. */
1301 /* [TP] KBL is a tuning parameter that defines the tile size in the */
1302 /* tiling of the p-q loops of pivot pairs. In general, an optimal */
1303 /* value of KBL depends on the matrix dimensions and on the */
1304 /* parameters of the computer's memory. */
1307 if (nbl * kbl != *n) {
1311 /* Computing 2nd power */
1313 blskip = i__1 * i__1;
1314 /* [TP] BLKSKIP is a tuning parameter that depends on SWBAND and KBL. */
1316 rowskip = f2cmin(5,kbl);
1317 /* [TP] ROWSKIP is a tuning parameter. */
1320 /* [TP] LKAHEAD is a tuning parameter. */
1322 /* Quasi block transformations, using the lower (upper) triangular */
1323 /* structure of the input matrix. The quasi-block-cycling usually */
1324 /* invokes cubic convergence. Big part of this cycle is done inside */
1325 /* canonical subspaces of dimensions less than M. */
1328 i__1 = 64, i__2 = kbl << 2;
1329 if ((lower || upper) && *n > f2cmax(i__1,i__2)) {
1330 /* [TP] The number of partition levels and the actual partition are */
1331 /* tuning parameters. */
1343 /* This works very well on lower triangular matrices, in particular */
1344 /* in the framework of the preconditioned Jacobi SVD (xGEJSV). */
1345 /* The idea is simple: */
1346 /* [+ 0 0 0] Note that Jacobi transformations of [0 0] */
1347 /* [+ + 0 0] [0 0] */
1348 /* [+ + x 0] actually work on [x 0] [x 0] */
1349 /* [+ + x x] [x x]. [x x] */
1354 dgsvj0_(jobv, &i__1, &i__2, &a[n34 + 1 + (n34 + 1) * a_dim1], lda,
1355 &work[n34 + 1], &sva[n34 + 1], &mvl, &v[n34 * q + 1 + (
1356 n34 + 1) * v_dim1], ldv, &epsln, &sfmin, &tol, &c__2, &
1357 work[*n + 1], &i__3, &ierr);
1362 dgsvj0_(jobv, &i__1, &i__2, &a[n2 + 1 + (n2 + 1) * a_dim1], lda, &
1363 work[n2 + 1], &sva[n2 + 1], &mvl, &v[n2 * q + 1 + (n2 + 1)
1364 * v_dim1], ldv, &epsln, &sfmin, &tol, &c__2, &work[*n +
1370 dgsvj1_(jobv, &i__1, &i__2, &n4, &a[n2 + 1 + (n2 + 1) * a_dim1],
1371 lda, &work[n2 + 1], &sva[n2 + 1], &mvl, &v[n2 * q + 1 + (
1372 n2 + 1) * v_dim1], ldv, &epsln, &sfmin, &tol, &c__1, &
1373 work[*n + 1], &i__3, &ierr);
1378 dgsvj0_(jobv, &i__1, &i__2, &a[n4 + 1 + (n4 + 1) * a_dim1], lda, &
1379 work[n4 + 1], &sva[n4 + 1], &mvl, &v[n4 * q + 1 + (n4 + 1)
1380 * v_dim1], ldv, &epsln, &sfmin, &tol, &c__1, &work[*n +
1384 dgsvj0_(jobv, m, &n4, &a[a_offset], lda, &work[1], &sva[1], &mvl,
1385 &v[v_offset], ldv, &epsln, &sfmin, &tol, &c__1, &work[*n
1386 + 1], &i__1, &ierr);
1389 dgsvj1_(jobv, m, &n2, &n4, &a[a_offset], lda, &work[1], &sva[1], &
1390 mvl, &v[v_offset], ldv, &epsln, &sfmin, &tol, &c__1, &
1391 work[*n + 1], &i__1, &ierr);
1398 dgsvj0_(jobv, &n4, &n4, &a[a_offset], lda, &work[1], &sva[1], &
1399 mvl, &v[v_offset], ldv, &epsln, &sfmin, &tol, &c__2, &
1400 work[*n + 1], &i__1, &ierr);
1403 dgsvj0_(jobv, &n2, &n4, &a[(n4 + 1) * a_dim1 + 1], lda, &work[n4
1404 + 1], &sva[n4 + 1], &mvl, &v[n4 * q + 1 + (n4 + 1) *
1405 v_dim1], ldv, &epsln, &sfmin, &tol, &c__1, &work[*n + 1],
1409 dgsvj1_(jobv, &n2, &n2, &n4, &a[a_offset], lda, &work[1], &sva[1],
1410 &mvl, &v[v_offset], ldv, &epsln, &sfmin, &tol, &c__1, &
1411 work[*n + 1], &i__1, &ierr);
1415 dgsvj0_(jobv, &i__1, &n4, &a[(n2 + 1) * a_dim1 + 1], lda, &work[
1416 n2 + 1], &sva[n2 + 1], &mvl, &v[n2 * q + 1 + (n2 + 1) *
1417 v_dim1], ldv, &epsln, &sfmin, &tol, &c__1, &work[*n + 1],
1424 for (i__ = 1; i__ <= 30; ++i__) {
1434 /* Each sweep is unrolled using KBL-by-KBL tiles over the pivot pairs */
1435 /* 1 <= p < q <= N. This is the first step toward a blocked implementation */
1436 /* of the rotations. New implementation, based on block transformations, */
1437 /* is under development. */
1440 for (ibr = 1; ibr <= i__1; ++ibr) {
1442 igl = (ibr - 1) * kbl + 1;
1445 i__3 = lkahead, i__4 = nbl - ibr;
1446 i__2 = f2cmin(i__3,i__4);
1447 for (ir1 = 0; ir1 <= i__2; ++ir1) {
1452 i__4 = igl + kbl - 1, i__5 = *n - 1;
1453 i__3 = f2cmin(i__4,i__5);
1454 for (p = igl; p <= i__3; ++p) {
1458 q = idamax_(&i__4, &sva[p], &c__1) + p - 1;
1460 dswap_(m, &a[p * a_dim1 + 1], &c__1, &a[q * a_dim1 +
1463 dswap_(&mvl, &v[p * v_dim1 + 1], &c__1, &v[q *
1464 v_dim1 + 1], &c__1);
1476 /* Column norms are periodically updated by explicit */
1477 /* norm computation. */
1479 /* Unfortunately, some BLAS implementations compute DNRM2(M,A(1,p),1) */
1480 /* as DSQRT(DDOT(M,A(1,p),1,A(1,p),1)), which may cause the result to */
1481 /* overflow for ||A(:,p)||_2 > DSQRT(overflow_threshold), and to */
1482 /* underflow for ||A(:,p)||_2 < DSQRT(underflow_threshold). */
1483 /* Hence, DNRM2 cannot be trusted, not even in the case when */
1484 /* the true norm is far from the under(over)flow boundaries. */
1485 /* If properly implemented DNRM2 is available, the IF-THEN-ELSE */
1486 /* below should read "AAPP = DNRM2( M, A(1,p), 1 ) * WORK(p)". */
1488 if (sva[p] < rootbig && sva[p] > rootsfmin) {
1489 sva[p] = dnrm2_(m, &a[p * a_dim1 + 1], &c__1) *
1494 dlassq_(m, &a[p * a_dim1 + 1], &c__1, &temp1, &
1496 sva[p] = temp1 * sqrt(aapp) * work[p];
1508 i__5 = igl + kbl - 1;
1509 i__4 = f2cmin(i__5,*n);
1510 for (q = p + 1; q <= i__4; ++q) {
1518 rotok = small * aapp <= aaqq;
1519 if (aapp < big / aaqq) {
1520 aapq = ddot_(m, &a[p * a_dim1 + 1], &
1521 c__1, &a[q * a_dim1 + 1], &
1522 c__1) * work[p] * work[q] /
1525 dcopy_(m, &a[p * a_dim1 + 1], &c__1, &
1526 work[*n + 1], &c__1);
1527 dlascl_("G", &c__0, &c__0, &aapp, &
1528 work[p], m, &c__1, &work[*n +
1530 aapq = ddot_(m, &work[*n + 1], &c__1,
1531 &a[q * a_dim1 + 1], &c__1) *
1535 rotok = aapp <= aaqq / small;
1536 if (aapp > small / aaqq) {
1537 aapq = ddot_(m, &a[p * a_dim1 + 1], &
1538 c__1, &a[q * a_dim1 + 1], &
1539 c__1) * work[p] * work[q] /
1542 dcopy_(m, &a[q * a_dim1 + 1], &c__1, &
1543 work[*n + 1], &c__1);
1544 dlascl_("G", &c__0, &c__0, &aaqq, &
1545 work[q], m, &c__1, &work[*n +
1547 aapq = ddot_(m, &work[*n + 1], &c__1,
1548 &a[p * a_dim1 + 1], &c__1) *
1554 d__1 = mxaapq, d__2 = abs(aapq);
1555 mxaapq = f2cmax(d__1,d__2);
1557 /* TO rotate or NOT to rotate, THAT is the question ... */
1559 if (abs(aapq) > tol) {
1561 /* [RTD] ROTATED = ROTATED + ONE */
1571 aqoap = aaqq / aapp;
1572 apoaq = aapp / aaqq;
1573 theta = (d__1 = aqoap - apoaq, abs(
1574 d__1)) * -.5 / aapq;
1576 if (abs(theta) > bigtheta) {
1579 fastr[2] = t * work[p] / work[q];
1580 fastr[3] = -t * work[q] / work[p];
1581 drotm_(m, &a[p * a_dim1 + 1], &
1582 c__1, &a[q * a_dim1 + 1],
1585 drotm_(&mvl, &v[p * v_dim1 + 1], &c__1, &v[q *
1586 v_dim1 + 1], &c__1, fastr);
1589 d__1 = 0., d__2 = t * apoaq *
1591 sva[q] = aaqq * sqrt((f2cmax(d__1,
1594 d__1 = 0., d__2 = 1. - t * aqoap *
1596 aapp *= sqrt((f2cmax(d__1,d__2)));
1598 d__1 = mxsinj, d__2 = abs(t);
1599 mxsinj = f2cmax(d__1,d__2);
1604 thsign = -d_sign(&c_b18, &aapq);
1605 t = 1. / (theta + thsign * sqrt(
1606 theta * theta + 1.));
1607 cs = sqrt(1. / (t * t + 1.));
1611 d__1 = mxsinj, d__2 = abs(sn);
1612 mxsinj = f2cmax(d__1,d__2);
1614 d__1 = 0., d__2 = t * apoaq *
1616 sva[q] = aaqq * sqrt((f2cmax(d__1,
1619 d__1 = 0., d__2 = 1. - t * aqoap *
1621 aapp *= sqrt((f2cmax(d__1,d__2)));
1623 apoaq = work[p] / work[q];
1624 aqoap = work[q] / work[p];
1625 if (work[p] >= 1.) {
1626 if (work[q] >= 1.) {
1627 fastr[2] = t * apoaq;
1628 fastr[3] = -t * aqoap;
1631 drotm_(m, &a[p * a_dim1 + 1], &c__1, &a[q *
1632 a_dim1 + 1], &c__1, fastr);
1634 drotm_(&mvl, &v[p * v_dim1 + 1], &c__1, &v[
1635 q * v_dim1 + 1], &c__1, fastr);
1639 daxpy_(m, &d__1, &a[q * a_dim1 + 1], &c__1, &a[
1640 p * a_dim1 + 1], &c__1);
1641 d__1 = cs * sn * apoaq;
1642 daxpy_(m, &d__1, &a[p * a_dim1 + 1], &c__1, &a[
1643 q * a_dim1 + 1], &c__1);
1648 daxpy_(&mvl, &d__1, &v[q * v_dim1 + 1], &
1649 c__1, &v[p * v_dim1 + 1], &c__1);
1650 d__1 = cs * sn * apoaq;
1651 daxpy_(&mvl, &d__1, &v[p * v_dim1 + 1], &
1652 c__1, &v[q * v_dim1 + 1], &c__1);
1656 if (work[q] >= 1.) {
1658 daxpy_(m, &d__1, &a[p * a_dim1 + 1], &c__1, &a[
1659 q * a_dim1 + 1], &c__1);
1660 d__1 = -cs * sn * aqoap;
1661 daxpy_(m, &d__1, &a[q * a_dim1 + 1], &c__1, &a[
1662 p * a_dim1 + 1], &c__1);
1667 daxpy_(&mvl, &d__1, &v[p * v_dim1 + 1], &
1668 c__1, &v[q * v_dim1 + 1], &c__1);
1669 d__1 = -cs * sn * aqoap;
1670 daxpy_(&mvl, &d__1, &v[q * v_dim1 + 1], &
1671 c__1, &v[p * v_dim1 + 1], &c__1);
1674 if (work[p] >= work[q]) {
1676 daxpy_(m, &d__1, &a[q * a_dim1 + 1], &c__1,
1677 &a[p * a_dim1 + 1], &c__1);
1678 d__1 = cs * sn * apoaq;
1679 daxpy_(m, &d__1, &a[p * a_dim1 + 1], &c__1,
1680 &a[q * a_dim1 + 1], &c__1);
1685 daxpy_(&mvl, &d__1, &v[q * v_dim1 + 1],
1686 &c__1, &v[p * v_dim1 + 1], &
1688 d__1 = cs * sn * apoaq;
1689 daxpy_(&mvl, &d__1, &v[p * v_dim1 + 1],
1690 &c__1, &v[q * v_dim1 + 1], &
1695 daxpy_(m, &d__1, &a[p * a_dim1 + 1], &c__1,
1696 &a[q * a_dim1 + 1], &c__1);
1697 d__1 = -cs * sn * aqoap;
1698 daxpy_(m, &d__1, &a[q * a_dim1 + 1], &c__1,
1699 &a[p * a_dim1 + 1], &c__1);
1704 daxpy_(&mvl, &d__1, &v[p * v_dim1 + 1],
1705 &c__1, &v[q * v_dim1 + 1], &
1707 d__1 = -cs * sn * aqoap;
1708 daxpy_(&mvl, &d__1, &v[q * v_dim1 + 1],
1709 &c__1, &v[p * v_dim1 + 1], &
1718 dcopy_(m, &a[p * a_dim1 + 1], &c__1, &
1719 work[*n + 1], &c__1);
1720 dlascl_("G", &c__0, &c__0, &aapp, &
1721 c_b18, m, &c__1, &work[*n + 1]
1723 dlascl_("G", &c__0, &c__0, &aaqq, &
1724 c_b18, m, &c__1, &a[q *
1725 a_dim1 + 1], lda, &ierr);
1726 temp1 = -aapq * work[p] / work[q];
1727 daxpy_(m, &temp1, &work[*n + 1], &
1728 c__1, &a[q * a_dim1 + 1], &
1730 dlascl_("G", &c__0, &c__0, &c_b18, &
1731 aaqq, m, &c__1, &a[q * a_dim1
1734 d__1 = 0., d__2 = 1. - aapq * aapq;
1735 sva[q] = aaqq * sqrt((f2cmax(d__1,d__2)))
1737 mxsinj = f2cmax(mxsinj,sfmin);
1739 /* END IF ROTOK THEN ... ELSE */
1741 /* In the case of cancellation in updating SVA(q), SVA(p) */
1742 /* recompute SVA(q), SVA(p). */
1744 /* Computing 2nd power */
1745 d__1 = sva[q] / aaqq;
1746 if (d__1 * d__1 <= rooteps) {
1747 if (aaqq < rootbig && aaqq >
1749 sva[q] = dnrm2_(m, &a[q * a_dim1
1750 + 1], &c__1) * work[q];
1754 dlassq_(m, &a[q * a_dim1 + 1], &
1756 sva[q] = t * sqrt(aaqq) * work[q];
1759 if (aapp / aapp0 <= rooteps) {
1760 if (aapp < rootbig && aapp >
1762 aapp = dnrm2_(m, &a[p * a_dim1 +
1763 1], &c__1) * work[p];
1767 dlassq_(m, &a[p * a_dim1 + 1], &
1769 aapp = t * sqrt(aapp) * work[p];
1775 /* A(:,p) and A(:,q) already numerically orthogonal */
1779 /* [RTD] SKIPPED = SKIPPED + 1 */
1783 /* A(:,q) is zero column */
1790 if (i__ <= swband && pskipped > rowskip) {
1803 /* bailed out of q-loop */
1809 if (ir1 == 0 && aapp == 0.) {
1811 i__4 = igl + kbl - 1;
1812 notrot = notrot + f2cmin(i__4,*n) - p;
1818 /* end of the p-loop */
1819 /* end of doing the block ( ibr, ibr ) */
1822 /* end of ir1-loop */
1824 /* ... go to the off diagonal blocks */
1826 igl = (ibr - 1) * kbl + 1;
1829 for (jbc = ibr + 1; jbc <= i__2; ++jbc) {
1831 jgl = (jbc - 1) * kbl + 1;
1833 /* doing the block at ( ibr, jbc ) */
1837 i__4 = igl + kbl - 1;
1838 i__3 = f2cmin(i__4,*n);
1839 for (p = igl; p <= i__3; ++p) {
1847 i__5 = jgl + kbl - 1;
1848 i__4 = f2cmin(i__5,*n);
1849 for (q = jgl; q <= i__4; ++q) {
1856 /* Safe Gram matrix computation */
1860 rotok = small * aapp <= aaqq;
1862 rotok = small * aaqq <= aapp;
1864 if (aapp < big / aaqq) {
1865 aapq = ddot_(m, &a[p * a_dim1 + 1], &
1866 c__1, &a[q * a_dim1 + 1], &
1867 c__1) * work[p] * work[q] /
1870 dcopy_(m, &a[p * a_dim1 + 1], &c__1, &
1871 work[*n + 1], &c__1);
1872 dlascl_("G", &c__0, &c__0, &aapp, &
1873 work[p], m, &c__1, &work[*n +
1875 aapq = ddot_(m, &work[*n + 1], &c__1,
1876 &a[q * a_dim1 + 1], &c__1) *
1881 rotok = aapp <= aaqq / small;
1883 rotok = aaqq <= aapp / small;
1885 if (aapp > small / aaqq) {
1886 aapq = ddot_(m, &a[p * a_dim1 + 1], &
1887 c__1, &a[q * a_dim1 + 1], &
1888 c__1) * work[p] * work[q] /
1891 dcopy_(m, &a[q * a_dim1 + 1], &c__1, &
1892 work[*n + 1], &c__1);
1893 dlascl_("G", &c__0, &c__0, &aaqq, &
1894 work[q], m, &c__1, &work[*n +
1896 aapq = ddot_(m, &work[*n + 1], &c__1,
1897 &a[p * a_dim1 + 1], &c__1) *
1903 d__1 = mxaapq, d__2 = abs(aapq);
1904 mxaapq = f2cmax(d__1,d__2);
1906 /* TO rotate or NOT to rotate, THAT is the question ... */
1908 if (abs(aapq) > tol) {
1910 /* [RTD] ROTATED = ROTATED + 1 */
1916 aqoap = aaqq / aapp;
1917 apoaq = aapp / aaqq;
1918 theta = (d__1 = aqoap - apoaq, abs(
1919 d__1)) * -.5 / aapq;
1924 if (abs(theta) > bigtheta) {
1926 fastr[2] = t * work[p] / work[q];
1927 fastr[3] = -t * work[q] / work[p];
1928 drotm_(m, &a[p * a_dim1 + 1], &
1929 c__1, &a[q * a_dim1 + 1],
1932 drotm_(&mvl, &v[p * v_dim1 + 1], &c__1, &v[q *
1933 v_dim1 + 1], &c__1, fastr);
1936 d__1 = 0., d__2 = t * apoaq *
1938 sva[q] = aaqq * sqrt((f2cmax(d__1,
1941 d__1 = 0., d__2 = 1. - t * aqoap *
1943 aapp *= sqrt((f2cmax(d__1,d__2)));
1945 d__1 = mxsinj, d__2 = abs(t);
1946 mxsinj = f2cmax(d__1,d__2);
1950 thsign = -d_sign(&c_b18, &aapq);
1954 t = 1. / (theta + thsign * sqrt(
1955 theta * theta + 1.));
1956 cs = sqrt(1. / (t * t + 1.));
1959 d__1 = mxsinj, d__2 = abs(sn);
1960 mxsinj = f2cmax(d__1,d__2);
1962 d__1 = 0., d__2 = t * apoaq *
1964 sva[q] = aaqq * sqrt((f2cmax(d__1,
1967 d__1 = 0., d__2 = 1. - t * aqoap *
1969 aapp *= sqrt((f2cmax(d__1,d__2)));
1971 apoaq = work[p] / work[q];
1972 aqoap = work[q] / work[p];
1973 if (work[p] >= 1.) {
1975 if (work[q] >= 1.) {
1976 fastr[2] = t * apoaq;
1977 fastr[3] = -t * aqoap;
1980 drotm_(m, &a[p * a_dim1 + 1], &c__1, &a[q *
1981 a_dim1 + 1], &c__1, fastr);
1983 drotm_(&mvl, &v[p * v_dim1 + 1], &c__1, &v[
1984 q * v_dim1 + 1], &c__1, fastr);
1988 daxpy_(m, &d__1, &a[q * a_dim1 + 1], &c__1, &a[
1989 p * a_dim1 + 1], &c__1);
1990 d__1 = cs * sn * apoaq;
1991 daxpy_(m, &d__1, &a[p * a_dim1 + 1], &c__1, &a[
1992 q * a_dim1 + 1], &c__1);
1995 daxpy_(&mvl, &d__1, &v[q * v_dim1 + 1], &
1996 c__1, &v[p * v_dim1 + 1], &c__1);
1997 d__1 = cs * sn * apoaq;
1998 daxpy_(&mvl, &d__1, &v[p * v_dim1 + 1], &
1999 c__1, &v[q * v_dim1 + 1], &c__1);
2005 if (work[q] >= 1.) {
2007 daxpy_(m, &d__1, &a[p * a_dim1 + 1], &c__1, &a[
2008 q * a_dim1 + 1], &c__1);
2009 d__1 = -cs * sn * aqoap;
2010 daxpy_(m, &d__1, &a[q * a_dim1 + 1], &c__1, &a[
2011 p * a_dim1 + 1], &c__1);
2014 daxpy_(&mvl, &d__1, &v[p * v_dim1 + 1], &
2015 c__1, &v[q * v_dim1 + 1], &c__1);
2016 d__1 = -cs * sn * aqoap;
2017 daxpy_(&mvl, &d__1, &v[q * v_dim1 + 1], &
2018 c__1, &v[p * v_dim1 + 1], &c__1);
2023 if (work[p] >= work[q]) {
2025 daxpy_(m, &d__1, &a[q * a_dim1 + 1], &c__1,
2026 &a[p * a_dim1 + 1], &c__1);
2027 d__1 = cs * sn * apoaq;
2028 daxpy_(m, &d__1, &a[p * a_dim1 + 1], &c__1,
2029 &a[q * a_dim1 + 1], &c__1);
2034 daxpy_(&mvl, &d__1, &v[q * v_dim1 + 1],
2035 &c__1, &v[p * v_dim1 + 1], &
2037 d__1 = cs * sn * apoaq;
2038 daxpy_(&mvl, &d__1, &v[p * v_dim1 + 1],
2039 &c__1, &v[q * v_dim1 + 1], &
2044 daxpy_(m, &d__1, &a[p * a_dim1 + 1], &c__1,
2045 &a[q * a_dim1 + 1], &c__1);
2046 d__1 = -cs * sn * aqoap;
2047 daxpy_(m, &d__1, &a[q * a_dim1 + 1], &c__1,
2048 &a[p * a_dim1 + 1], &c__1);
2053 daxpy_(&mvl, &d__1, &v[p * v_dim1 + 1],
2054 &c__1, &v[q * v_dim1 + 1], &
2056 d__1 = -cs * sn * aqoap;
2057 daxpy_(&mvl, &d__1, &v[q * v_dim1 + 1],
2058 &c__1, &v[p * v_dim1 + 1], &
2068 dcopy_(m, &a[p * a_dim1 + 1], &
2069 c__1, &work[*n + 1], &
2071 dlascl_("G", &c__0, &c__0, &aapp,
2072 &c_b18, m, &c__1, &work[*
2073 n + 1], lda, &ierr);
2074 dlascl_("G", &c__0, &c__0, &aaqq,
2075 &c_b18, m, &c__1, &a[q *
2076 a_dim1 + 1], lda, &ierr);
2077 temp1 = -aapq * work[p] / work[q];
2078 daxpy_(m, &temp1, &work[*n + 1], &
2079 c__1, &a[q * a_dim1 + 1],
2081 dlascl_("G", &c__0, &c__0, &c_b18,
2082 &aaqq, m, &c__1, &a[q *
2083 a_dim1 + 1], lda, &ierr);
2085 d__1 = 0., d__2 = 1. - aapq *
2087 sva[q] = aaqq * sqrt((f2cmax(d__1,
2089 mxsinj = f2cmax(mxsinj,sfmin);
2091 dcopy_(m, &a[q * a_dim1 + 1], &
2092 c__1, &work[*n + 1], &
2094 dlascl_("G", &c__0, &c__0, &aaqq,
2095 &c_b18, m, &c__1, &work[*
2096 n + 1], lda, &ierr);
2097 dlascl_("G", &c__0, &c__0, &aapp,
2098 &c_b18, m, &c__1, &a[p *
2099 a_dim1 + 1], lda, &ierr);
2100 temp1 = -aapq * work[q] / work[p];
2101 daxpy_(m, &temp1, &work[*n + 1], &
2102 c__1, &a[p * a_dim1 + 1],
2104 dlascl_("G", &c__0, &c__0, &c_b18,
2105 &aapp, m, &c__1, &a[p *
2106 a_dim1 + 1], lda, &ierr);
2108 d__1 = 0., d__2 = 1. - aapq *
2110 sva[p] = aapp * sqrt((f2cmax(d__1,
2112 mxsinj = f2cmax(mxsinj,sfmin);
2115 /* END IF ROTOK THEN ... ELSE */
2117 /* In the case of cancellation in updating SVA(q) */
2118 /* Computing 2nd power */
2119 d__1 = sva[q] / aaqq;
2120 if (d__1 * d__1 <= rooteps) {
2121 if (aaqq < rootbig && aaqq >
2123 sva[q] = dnrm2_(m, &a[q * a_dim1
2124 + 1], &c__1) * work[q];
2128 dlassq_(m, &a[q * a_dim1 + 1], &
2130 sva[q] = t * sqrt(aaqq) * work[q];
2133 /* Computing 2nd power */
2134 d__1 = aapp / aapp0;
2135 if (d__1 * d__1 <= rooteps) {
2136 if (aapp < rootbig && aapp >
2138 aapp = dnrm2_(m, &a[p * a_dim1 +
2139 1], &c__1) * work[p];
2143 dlassq_(m, &a[p * a_dim1 + 1], &
2145 aapp = t * sqrt(aapp) * work[p];
2149 /* end of OK rotation */
2152 /* [RTD] SKIPPED = SKIPPED + 1 */
2162 if (i__ <= swband && ijblsk >= blskip) {
2167 if (i__ <= swband && pskipped > rowskip) {
2175 /* end of the q-loop */
2184 i__4 = jgl + kbl - 1;
2185 notrot = notrot + f2cmin(i__4,*n) - jgl + 1;
2195 /* end of the p-loop */
2198 /* end of the jbc-loop */
2200 /* 2011 bailed out of the jbc-loop */
2202 i__3 = igl + kbl - 1;
2203 i__2 = f2cmin(i__3,*n);
2204 for (p = igl; p <= i__2; ++p) {
2205 sva[p] = (d__1 = sva[p], abs(d__1));
2211 /* 2000 :: end of the ibr-loop */
2213 if (sva[*n] < rootbig && sva[*n] > rootsfmin) {
2214 sva[*n] = dnrm2_(m, &a[*n * a_dim1 + 1], &c__1) * work[*n];
2218 dlassq_(m, &a[*n * a_dim1 + 1], &c__1, &t, &aapp);
2219 sva[*n] = t * sqrt(aapp) * work[*n];
2222 /* Additional steering devices */
2224 if (i__ < swband && (mxaapq <= roottol || iswrot <= *n)) {
2228 if (i__ > swband + 1 && mxaapq < sqrt((doublereal) (*n)) * tol && (
2229 doublereal) (*n) * mxaapq * mxsinj < tol) {
2233 if (notrot >= emptsw) {
2239 /* end i=1:NSWEEP loop */
2241 /* #:( Reaching this point means that the procedure has not converged. */
2246 /* #:) Reaching this point means numerical convergence after the i-th */
2250 /* #:) INFO = 0 confirms successful iterations. */
2253 /* Sort the singular values and find how many are above */
2254 /* the underflow threshold. */
2259 for (p = 1; p <= i__1; ++p) {
2261 q = idamax_(&i__2, &sva[p], &c__1) + p - 1;
2269 dswap_(m, &a[p * a_dim1 + 1], &c__1, &a[q * a_dim1 + 1], &c__1);
2271 dswap_(&mvl, &v[p * v_dim1 + 1], &c__1, &v[q * v_dim1 + 1], &
2277 if (sva[p] * skl > sfmin) {
2283 if (sva[*n] != 0.) {
2285 if (sva[*n] * skl > sfmin) {
2290 /* Normalize the left singular vectors. */
2292 if (lsvec || uctol) {
2294 for (p = 1; p <= i__1; ++p) {
2295 d__1 = work[p] / sva[p];
2296 dscal_(m, &d__1, &a[p * a_dim1 + 1], &c__1);
2301 /* Scale the product of Jacobi rotations (assemble the fast rotations). */
2306 for (p = 1; p <= i__1; ++p) {
2307 dscal_(&mvl, &work[p], &v[p * v_dim1 + 1], &c__1);
2312 for (p = 1; p <= i__1; ++p) {
2313 temp1 = 1. / dnrm2_(&mvl, &v[p * v_dim1 + 1], &c__1);
2314 dscal_(&mvl, &temp1, &v[p * v_dim1 + 1], &c__1);
2320 /* Undo scaling, if necessary (and possible). */
2321 if (skl > 1. && sva[1] < big / skl || skl < 1. && sva[f2cmax(n2,1)] > sfmin /
2324 for (p = 1; p <= i__1; ++p) {
2325 sva[p] = skl * sva[p];
2332 /* The singular values of A are SKL*SVA(1:N). If SKL.NE.ONE */
2333 /* then some of the singular values may overflow or underflow and */
2334 /* the spectrum is given in this factored representation. */
2336 work[2] = (doublereal) n4;
2337 /* N4 is the number of computed nonzero singular values of A. */
2339 work[3] = (doublereal) n2;
2340 /* N2 is the number of singular values of A greater than SFMIN. */
2341 /* If N2<N, SVA(N2:N) contains ZEROS and/or denormalized numbers */
2342 /* that may carry some information. */
2344 work[4] = (doublereal) i__;
2345 /* i is the index of the last sweep before declaring convergence. */
2348 /* MXAAPQ is the largest absolute value of scaled pivots in the */
2352 /* MXSINJ is the largest absolute value of the sines of Jacobi angles */
2353 /* in the last sweep */