14 typedef long long BLASLONG;
15 typedef unsigned long long BLASULONG;
17 typedef long BLASLONG;
18 typedef unsigned long BLASULONG;
22 typedef BLASLONG blasint;
24 #define blasabs(x) llabs(x)
26 #define blasabs(x) labs(x)
30 #define blasabs(x) abs(x)
33 typedef blasint integer;
35 typedef unsigned int uinteger;
36 typedef char *address;
37 typedef short int shortint;
39 typedef double doublereal;
40 typedef struct { real r, i; } complex;
41 typedef struct { doublereal r, i; } doublecomplex;
43 static inline _Fcomplex Cf(complex *z) {_Fcomplex zz={z->r , z->i}; return zz;}
44 static inline _Dcomplex Cd(doublecomplex *z) {_Dcomplex zz={z->r , z->i};return zz;}
45 static inline _Fcomplex * _pCf(complex *z) {return (_Fcomplex*)z;}
46 static inline _Dcomplex * _pCd(doublecomplex *z) {return (_Dcomplex*)z;}
48 static inline _Complex float Cf(complex *z) {return z->r + z->i*_Complex_I;}
49 static inline _Complex double Cd(doublecomplex *z) {return z->r + z->i*_Complex_I;}
50 static inline _Complex float * _pCf(complex *z) {return (_Complex float*)z;}
51 static inline _Complex double * _pCd(doublecomplex *z) {return (_Complex double*)z;}
53 #define pCf(z) (*_pCf(z))
54 #define pCd(z) (*_pCd(z))
56 typedef short int shortlogical;
57 typedef char logical1;
58 typedef char integer1;
63 /* Extern is for use with -E */
74 /*external read, write*/
83 /*internal read, write*/
113 /*rewind, backspace, endfile*/
125 ftnint *inex; /*parameters in standard's order*/
151 union Multitype { /* for multiple entry points */
162 typedef union Multitype Multitype;
164 struct Vardesc { /* for Namelist */
170 typedef struct Vardesc Vardesc;
177 typedef struct Namelist Namelist;
179 #define abs(x) ((x) >= 0 ? (x) : -(x))
180 #define dabs(x) (fabs(x))
181 #define f2cmin(a,b) ((a) <= (b) ? (a) : (b))
182 #define f2cmax(a,b) ((a) >= (b) ? (a) : (b))
183 #define dmin(a,b) (f2cmin(a,b))
184 #define dmax(a,b) (f2cmax(a,b))
185 #define bit_test(a,b) ((a) >> (b) & 1)
186 #define bit_clear(a,b) ((a) & ~((uinteger)1 << (b)))
187 #define bit_set(a,b) ((a) | ((uinteger)1 << (b)))
189 #define abort_() { sig_die("Fortran abort routine called", 1); }
190 #define c_abs(z) (cabsf(Cf(z)))
191 #define c_cos(R,Z) { pCf(R)=ccos(Cf(Z)); }
193 #define c_div(c, a, b) {Cf(c)._Val[0] = (Cf(a)._Val[0]/Cf(b)._Val[0]); Cf(c)._Val[1]=(Cf(a)._Val[1]/Cf(b)._Val[1]);}
194 #define z_div(c, a, b) {Cd(c)._Val[0] = (Cd(a)._Val[0]/Cd(b)._Val[0]); Cd(c)._Val[1]=(Cd(a)._Val[1]/df(b)._Val[1]);}
196 #define c_div(c, a, b) {pCf(c) = Cf(a)/Cf(b);}
197 #define z_div(c, a, b) {pCd(c) = Cd(a)/Cd(b);}
199 #define c_exp(R, Z) {pCf(R) = cexpf(Cf(Z));}
200 #define c_log(R, Z) {pCf(R) = clogf(Cf(Z));}
201 #define c_sin(R, Z) {pCf(R) = csinf(Cf(Z));}
202 //#define c_sqrt(R, Z) {*(R) = csqrtf(Cf(Z));}
203 #define c_sqrt(R, Z) {pCf(R) = csqrtf(Cf(Z));}
204 #define d_abs(x) (fabs(*(x)))
205 #define d_acos(x) (acos(*(x)))
206 #define d_asin(x) (asin(*(x)))
207 #define d_atan(x) (atan(*(x)))
208 #define d_atn2(x, y) (atan2(*(x),*(y)))
209 #define d_cnjg(R, Z) { pCd(R) = conj(Cd(Z)); }
210 #define r_cnjg(R, Z) { pCf(R) = conjf(Cf(Z)); }
211 #define d_cos(x) (cos(*(x)))
212 #define d_cosh(x) (cosh(*(x)))
213 #define d_dim(__a, __b) ( *(__a) > *(__b) ? *(__a) - *(__b) : 0.0 )
214 #define d_exp(x) (exp(*(x)))
215 #define d_imag(z) (cimag(Cd(z)))
216 #define r_imag(z) (cimagf(Cf(z)))
217 #define d_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
218 #define r_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
219 #define d_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
220 #define r_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
221 #define d_log(x) (log(*(x)))
222 #define d_mod(x, y) (fmod(*(x), *(y)))
223 #define u_nint(__x) ((__x)>=0 ? floor((__x) + .5) : -floor(.5 - (__x)))
224 #define d_nint(x) u_nint(*(x))
225 #define u_sign(__a,__b) ((__b) >= 0 ? ((__a) >= 0 ? (__a) : -(__a)) : -((__a) >= 0 ? (__a) : -(__a)))
226 #define d_sign(a,b) u_sign(*(a),*(b))
227 #define r_sign(a,b) u_sign(*(a),*(b))
228 #define d_sin(x) (sin(*(x)))
229 #define d_sinh(x) (sinh(*(x)))
230 #define d_sqrt(x) (sqrt(*(x)))
231 #define d_tan(x) (tan(*(x)))
232 #define d_tanh(x) (tanh(*(x)))
233 #define i_abs(x) abs(*(x))
234 #define i_dnnt(x) ((integer)u_nint(*(x)))
235 #define i_len(s, n) (n)
236 #define i_nint(x) ((integer)u_nint(*(x)))
237 #define i_sign(a,b) ((integer)u_sign((integer)*(a),(integer)*(b)))
238 #define pow_dd(ap, bp) ( pow(*(ap), *(bp)))
239 #define pow_si(B,E) spow_ui(*(B),*(E))
240 #define pow_ri(B,E) spow_ui(*(B),*(E))
241 #define pow_di(B,E) dpow_ui(*(B),*(E))
242 #define pow_zi(p, a, b) {pCd(p) = zpow_ui(Cd(a), *(b));}
243 #define pow_ci(p, a, b) {pCf(p) = cpow_ui(Cf(a), *(b));}
244 #define pow_zz(R,A,B) {pCd(R) = cpow(Cd(A),*(B));}
245 #define s_cat(lpp, rpp, rnp, np, llp) { ftnlen i, nc, ll; char *f__rp, *lp; ll = (llp); lp = (lpp); for(i=0; i < (int)*(np); ++i) { nc = ll; if((rnp)[i] < nc) nc = (rnp)[i]; ll -= nc; f__rp = (rpp)[i]; while(--nc >= 0) *lp++ = *(f__rp)++; } while(--ll >= 0) *lp++ = ' '; }
246 #define s_cmp(a,b,c,d) ((integer)strncmp((a),(b),f2cmin((c),(d))))
247 #define s_copy(A,B,C,D) { int __i,__m; for (__i=0, __m=f2cmin((C),(D)); __i<__m && (B)[__i] != 0; ++__i) (A)[__i] = (B)[__i]; }
248 #define sig_die(s, kill) { exit(1); }
249 #define s_stop(s, n) {exit(0);}
250 static char junk[] = "\n@(#)LIBF77 VERSION 19990503\n";
251 #define z_abs(z) (cabs(Cd(z)))
252 #define z_exp(R, Z) {pCd(R) = cexp(Cd(Z));}
253 #define z_sqrt(R, Z) {pCd(R) = csqrt(Cd(Z));}
254 #define myexit_() break;
255 #define mycycle() continue;
256 #define myceiling(w) {ceil(w)}
257 #define myhuge(w) {HUGE_VAL}
258 //#define mymaxloc_(w,s,e,n) {if (sizeof(*(w)) == sizeof(double)) dmaxloc_((w),*(s),*(e),n); else dmaxloc_((w),*(s),*(e),n);}
259 #define mymaxloc(w,s,e,n) {dmaxloc_(w,*(s),*(e),n)}
261 /* procedure parameter types for -A and -C++ */
263 #define F2C_proc_par_types 1
265 typedef logical (*L_fp)(...);
267 typedef logical (*L_fp)();
270 static float spow_ui(float x, integer n) {
271 float pow=1.0; unsigned long int u;
273 if(n < 0) n = -n, x = 1/x;
282 static double dpow_ui(double x, integer n) {
283 double pow=1.0; unsigned long int u;
285 if(n < 0) n = -n, x = 1/x;
295 static _Fcomplex cpow_ui(complex x, integer n) {
296 complex pow={1.0,0.0}; unsigned long int u;
298 if(n < 0) n = -n, x.r = 1/x.r, x.i=1/x.i;
300 if(u & 01) pow.r *= x.r, pow.i *= x.i;
301 if(u >>= 1) x.r *= x.r, x.i *= x.i;
305 _Fcomplex p={pow.r, pow.i};
309 static _Complex float cpow_ui(_Complex float x, integer n) {
310 _Complex float pow=1.0; unsigned long int u;
312 if(n < 0) n = -n, x = 1/x;
323 static _Dcomplex zpow_ui(_Dcomplex x, integer n) {
324 _Dcomplex pow={1.0,0.0}; unsigned long int u;
326 if(n < 0) n = -n, x._Val[0] = 1/x._Val[0], x._Val[1] =1/x._Val[1];
328 if(u & 01) pow._Val[0] *= x._Val[0], pow._Val[1] *= x._Val[1];
329 if(u >>= 1) x._Val[0] *= x._Val[0], x._Val[1] *= x._Val[1];
333 _Dcomplex p = {pow._Val[0], pow._Val[1]};
337 static _Complex double zpow_ui(_Complex double x, integer n) {
338 _Complex double pow=1.0; unsigned long int u;
340 if(n < 0) n = -n, x = 1/x;
350 static integer pow_ii(integer x, integer n) {
351 integer pow; unsigned long int u;
353 if (n == 0 || x == 1) pow = 1;
354 else if (x != -1) pow = x == 0 ? 1/x : 0;
357 if ((n > 0) || !(n == 0 || x == 1 || x != -1)) {
367 static integer dmaxloc_(double *w, integer s, integer e, integer *n)
369 double m; integer i, mi;
370 for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
371 if (w[i-1]>m) mi=i ,m=w[i-1];
374 static integer smaxloc_(float *w, integer s, integer e, integer *n)
376 float m; integer i, mi;
377 for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
378 if (w[i-1]>m) mi=i ,m=w[i-1];
381 static inline void cdotc_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
382 integer n = *n_, incx = *incx_, incy = *incy_, i;
384 _Fcomplex zdotc = {0.0, 0.0};
385 if (incx == 1 && incy == 1) {
386 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
387 zdotc._Val[0] += conjf(Cf(&x[i]))._Val[0] * Cf(&y[i])._Val[0];
388 zdotc._Val[1] += conjf(Cf(&x[i]))._Val[1] * Cf(&y[i])._Val[1];
391 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
392 zdotc._Val[0] += conjf(Cf(&x[i*incx]))._Val[0] * Cf(&y[i*incy])._Val[0];
393 zdotc._Val[1] += conjf(Cf(&x[i*incx]))._Val[1] * Cf(&y[i*incy])._Val[1];
399 _Complex float zdotc = 0.0;
400 if (incx == 1 && incy == 1) {
401 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
402 zdotc += conjf(Cf(&x[i])) * Cf(&y[i]);
405 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
406 zdotc += conjf(Cf(&x[i*incx])) * Cf(&y[i*incy]);
412 static inline void zdotc_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
413 integer n = *n_, incx = *incx_, incy = *incy_, i;
415 _Dcomplex zdotc = {0.0, 0.0};
416 if (incx == 1 && incy == 1) {
417 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
418 zdotc._Val[0] += conj(Cd(&x[i]))._Val[0] * Cd(&y[i])._Val[0];
419 zdotc._Val[1] += conj(Cd(&x[i]))._Val[1] * Cd(&y[i])._Val[1];
422 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
423 zdotc._Val[0] += conj(Cd(&x[i*incx]))._Val[0] * Cd(&y[i*incy])._Val[0];
424 zdotc._Val[1] += conj(Cd(&x[i*incx]))._Val[1] * Cd(&y[i*incy])._Val[1];
430 _Complex double zdotc = 0.0;
431 if (incx == 1 && incy == 1) {
432 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
433 zdotc += conj(Cd(&x[i])) * Cd(&y[i]);
436 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
437 zdotc += conj(Cd(&x[i*incx])) * Cd(&y[i*incy]);
443 static inline void cdotu_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
444 integer n = *n_, incx = *incx_, incy = *incy_, i;
446 _Fcomplex zdotc = {0.0, 0.0};
447 if (incx == 1 && incy == 1) {
448 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
449 zdotc._Val[0] += Cf(&x[i])._Val[0] * Cf(&y[i])._Val[0];
450 zdotc._Val[1] += Cf(&x[i])._Val[1] * Cf(&y[i])._Val[1];
453 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
454 zdotc._Val[0] += Cf(&x[i*incx])._Val[0] * Cf(&y[i*incy])._Val[0];
455 zdotc._Val[1] += Cf(&x[i*incx])._Val[1] * Cf(&y[i*incy])._Val[1];
461 _Complex float zdotc = 0.0;
462 if (incx == 1 && incy == 1) {
463 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
464 zdotc += Cf(&x[i]) * Cf(&y[i]);
467 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
468 zdotc += Cf(&x[i*incx]) * Cf(&y[i*incy]);
474 static inline void zdotu_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
475 integer n = *n_, incx = *incx_, incy = *incy_, i;
477 _Dcomplex zdotc = {0.0, 0.0};
478 if (incx == 1 && incy == 1) {
479 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
480 zdotc._Val[0] += Cd(&x[i])._Val[0] * Cd(&y[i])._Val[0];
481 zdotc._Val[1] += Cd(&x[i])._Val[1] * Cd(&y[i])._Val[1];
484 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
485 zdotc._Val[0] += Cd(&x[i*incx])._Val[0] * Cd(&y[i*incy])._Val[0];
486 zdotc._Val[1] += Cd(&x[i*incx])._Val[1] * Cd(&y[i*incy])._Val[1];
492 _Complex double zdotc = 0.0;
493 if (incx == 1 && incy == 1) {
494 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
495 zdotc += Cd(&x[i]) * Cd(&y[i]);
498 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
499 zdotc += Cd(&x[i*incx]) * Cd(&y[i*incy]);
505 /* -- translated by f2c (version 20000121).
506 You must link the resulting object file with the libraries:
507 -lf2c -lm (in that order)
513 /* Table of constant values */
515 static integer c__1 = 1;
516 static integer c__0 = 0;
517 static real c_b35 = 1.f;
519 /* > \brief \b SGSVJ1 pre-processor for the routine sgesvj, applies Jacobi rotations targeting only particular
522 /* =========== DOCUMENTATION =========== */
524 /* Online html documentation available at */
525 /* http://www.netlib.org/lapack/explore-html/ */
528 /* > Download SGSVJ1 + dependencies */
529 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/sgsvj1.
532 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/sgsvj1.
535 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/sgsvj1.
543 /* SUBROUTINE SGSVJ1( JOBV, M, N, N1, A, LDA, D, SVA, MV, V, LDV, */
544 /* EPS, SFMIN, TOL, NSWEEP, WORK, LWORK, INFO ) */
546 /* REAL EPS, SFMIN, TOL */
547 /* INTEGER INFO, LDA, LDV, LWORK, M, MV, N, N1, NSWEEP */
548 /* CHARACTER*1 JOBV */
549 /* REAL A( LDA, * ), D( N ), SVA( N ), V( LDV, * ), */
550 /* $ WORK( LWORK ) */
553 /* > \par Purpose: */
558 /* > SGSVJ1 is called from SGESVJ as a pre-processor and that is its main */
559 /* > purpose. It applies Jacobi rotations in the same way as SGESVJ does, but */
560 /* > it targets only particular pivots and it does not check convergence */
561 /* > (stopping criterion). Few tunning parameters (marked by [TP]) are */
562 /* > available for the implementer. */
564 /* > Further Details */
565 /* > ~~~~~~~~~~~~~~~ */
566 /* > SGSVJ1 applies few sweeps of Jacobi rotations in the column space of */
567 /* > the input M-by-N matrix A. The pivot pairs are taken from the (1,2) */
568 /* > off-diagonal block in the corresponding N-by-N Gram matrix A^T * A. The */
569 /* > block-entries (tiles) of the (1,2) off-diagonal block are marked by the */
570 /* > [x]'s in the following scheme: */
572 /* > | * * * [x] [x] [x]| */
573 /* > | * * * [x] [x] [x]| Row-cycling in the nblr-by-nblc [x] blocks. */
574 /* > | * * * [x] [x] [x]| Row-cyclic pivoting inside each [x] block. */
575 /* > |[x] [x] [x] * * * | */
576 /* > |[x] [x] [x] * * * | */
577 /* > |[x] [x] [x] * * * | */
579 /* > In terms of the columns of A, the first N1 columns are rotated 'against' */
580 /* > the remaining N-N1 columns, trying to increase the angle between the */
581 /* > corresponding subspaces. The off-diagonal block is N1-by(N-N1) and it is */
582 /* > tiled using quadratic tiles of side KBL. Here, KBL is a tunning parameter. */
583 /* > The number of sweeps is given in NSWEEP and the orthogonality threshold */
584 /* > is given in TOL. */
590 /* > \param[in] JOBV */
592 /* > JOBV is CHARACTER*1 */
593 /* > Specifies whether the output from this procedure is used */
594 /* > to compute the matrix V: */
595 /* > = 'V': the product of the Jacobi rotations is accumulated */
596 /* > by postmulyiplying the N-by-N array V. */
597 /* > (See the description of V.) */
598 /* > = 'A': the product of the Jacobi rotations is accumulated */
599 /* > by postmulyiplying the MV-by-N array V. */
600 /* > (See the descriptions of MV and V.) */
601 /* > = 'N': the Jacobi rotations are not accumulated. */
607 /* > The number of rows of the input matrix A. M >= 0. */
613 /* > The number of columns of the input matrix A. */
617 /* > \param[in] N1 */
619 /* > N1 is INTEGER */
620 /* > N1 specifies the 2 x 2 block partition, the first N1 columns are */
621 /* > rotated 'against' the remaining N-N1 columns of A. */
624 /* > \param[in,out] A */
626 /* > A is REAL array, dimension (LDA,N) */
627 /* > On entry, M-by-N matrix A, such that A*diag(D) represents */
628 /* > the input matrix. */
630 /* > A_onexit * D_onexit represents the input matrix A*diag(D) */
631 /* > post-multiplied by a sequence of Jacobi rotations, where the */
632 /* > rotation threshold and the total number of sweeps are given in */
633 /* > TOL and NSWEEP, respectively. */
634 /* > (See the descriptions of N1, D, TOL and NSWEEP.) */
637 /* > \param[in] LDA */
639 /* > LDA is INTEGER */
640 /* > The leading dimension of the array A. LDA >= f2cmax(1,M). */
643 /* > \param[in,out] D */
645 /* > D is REAL array, dimension (N) */
646 /* > The array D accumulates the scaling factors from the fast scaled */
647 /* > Jacobi rotations. */
648 /* > On entry, A*diag(D) represents the input matrix. */
649 /* > On exit, A_onexit*diag(D_onexit) represents the input matrix */
650 /* > post-multiplied by a sequence of Jacobi rotations, where the */
651 /* > rotation threshold and the total number of sweeps are given in */
652 /* > TOL and NSWEEP, respectively. */
653 /* > (See the descriptions of N1, A, TOL and NSWEEP.) */
656 /* > \param[in,out] SVA */
658 /* > SVA is REAL array, dimension (N) */
659 /* > On entry, SVA contains the Euclidean norms of the columns of */
660 /* > the matrix A*diag(D). */
661 /* > On exit, SVA contains the Euclidean norms of the columns of */
662 /* > the matrix onexit*diag(D_onexit). */
665 /* > \param[in] MV */
667 /* > MV is INTEGER */
668 /* > If JOBV = 'A', then MV rows of V are post-multipled by a */
669 /* > sequence of Jacobi rotations. */
670 /* > If JOBV = 'N', then MV is not referenced. */
673 /* > \param[in,out] V */
675 /* > V is REAL array, dimension (LDV,N) */
676 /* > If JOBV = 'V' then N rows of V are post-multipled by a */
677 /* > sequence of Jacobi rotations. */
678 /* > If JOBV = 'A' then MV rows of V are post-multipled by a */
679 /* > sequence of Jacobi rotations. */
680 /* > If JOBV = 'N', then V is not referenced. */
683 /* > \param[in] LDV */
685 /* > LDV is INTEGER */
686 /* > The leading dimension of the array V, LDV >= 1. */
687 /* > If JOBV = 'V', LDV >= N. */
688 /* > If JOBV = 'A', LDV >= MV. */
691 /* > \param[in] EPS */
694 /* > EPS = SLAMCH('Epsilon') */
697 /* > \param[in] SFMIN */
699 /* > SFMIN is REAL */
700 /* > SFMIN = SLAMCH('Safe Minimum') */
703 /* > \param[in] TOL */
706 /* > TOL is the threshold for Jacobi rotations. For a pair */
707 /* > A(:,p), A(:,q) of pivot columns, the Jacobi rotation is */
708 /* > applied only if ABS(COS(angle(A(:,p),A(:,q)))) > TOL. */
711 /* > \param[in] NSWEEP */
713 /* > NSWEEP is INTEGER */
714 /* > NSWEEP is the number of sweeps of Jacobi rotations to be */
718 /* > \param[out] WORK */
720 /* > WORK is REAL array, dimension (LWORK) */
723 /* > \param[in] LWORK */
725 /* > LWORK is INTEGER */
726 /* > LWORK is the dimension of WORK. LWORK >= M. */
729 /* > \param[out] INFO */
731 /* > INFO is INTEGER */
732 /* > = 0: successful exit. */
733 /* > < 0: if INFO = -i, then the i-th argument had an illegal value */
739 /* > \author Univ. of Tennessee */
740 /* > \author Univ. of California Berkeley */
741 /* > \author Univ. of Colorado Denver */
742 /* > \author NAG Ltd. */
744 /* > \date November 2017 */
746 /* > \ingroup realOTHERcomputational */
748 /* > \par Contributors: */
749 /* ================== */
751 /* > Zlatko Drmac (Zagreb, Croatia) and Kresimir Veselic (Hagen, Germany) */
753 /* ===================================================================== */
754 /* Subroutine */ int sgsvj1_(char *jobv, integer *m, integer *n, integer *n1,
755 real *a, integer *lda, real *d__, real *sva, integer *mv, real *v,
756 integer *ldv, real *eps, real *sfmin, real *tol, integer *nsweep,
757 real *work, integer *lwork, integer *info)
759 /* System generated locals */
760 integer a_dim1, a_offset, v_dim1, v_offset, i__1, i__2, i__3, i__4, i__5,
764 /* Local variables */
766 real aapp, aapq, aaqq;
769 extern real sdot_(integer *, real *, integer *, real *, integer *);
772 extern real snrm2_(integer *, real *, integer *);
774 real t, large, apoaq, aqoap;
775 extern logical lsame_(char *, char *);
776 real theta, small, fastr[5];
777 logical applv, rsvec;
778 extern /* Subroutine */ int scopy_(integer *, real *, integer *, real *,
781 extern /* Subroutine */ int sswap_(integer *, real *, integer *, real *,
782 integer *), saxpy_(integer *, real *, real *, integer *, real *,
783 integer *), srotm_(integer *, real *, integer *, real *, integer *
785 real rootsfmin, cs, sn;
786 extern /* Subroutine */ int xerbla_(char *, integer *, ftnlen);
787 integer ijblsk, swband;
788 extern /* Subroutine */ int slascl_(char *, integer *, integer *, real *,
789 real *, integer *, integer *, real *, integer *, integer *);
790 extern integer isamax_(integer *, real *, integer *);
793 extern /* Subroutine */ int slassq_(integer *, real *, integer *, real *,
796 integer emptsw, notrot, iswrot, jbc;
798 integer kbl, igl, ibr, jgl, mvl;
799 real rootbig, rooteps;
804 /* -- LAPACK computational routine (version 3.8.0) -- */
805 /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
806 /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
810 /* ===================================================================== */
813 /* Test the input parameters. */
815 /* Parameter adjustments */
819 a_offset = 1 + a_dim1 * 1;
822 v_offset = 1 + v_dim1 * 1;
827 applv = lsame_(jobv, "A");
828 rsvec = lsame_(jobv, "V");
829 if (! (rsvec || applv || lsame_(jobv, "N"))) {
833 } else if (*n < 0 || *n > *m) {
835 } else if (*n1 < 0) {
837 } else if (*lda < *m) {
839 } else if ((rsvec || applv) && *mv < 0) {
841 } else if (rsvec && *ldv < *n || applv && *ldv < *mv) {
843 } else if (*tol <= *eps) {
845 } else if (*nsweep < 0) {
847 } else if (*lwork < *m) {
856 xerbla_("SGSVJ1", &i__1, (ftnlen)6);
865 rsvec = rsvec || applv;
866 rooteps = sqrt(*eps);
867 rootsfmin = sqrt(*sfmin);
868 small = *sfmin / *eps;
870 rootbig = 1.f / rootsfmin;
871 large = big / sqrt((real) (*m * *n));
872 bigtheta = 1.f / rooteps;
873 roottol = sqrt(*tol);
876 /* RSVEC = LSAME( JOBV, 'Y' ) */
878 emptsw = *n1 * (*n - *n1);
885 if (nblr * kbl != *n1) {
888 nblc = (*n - *n1) / kbl;
889 if (nblc * kbl != *n - *n1) {
892 /* Computing 2nd power */
894 blskip = i__1 * i__1 + 1;
895 /* [TP] BLKSKIP is a tuning parameter that depends on SWBAND and KBL. */
896 rowskip = f2cmin(5,kbl);
897 /* [TP] ROWSKIP is a tuning parameter. */
899 /* [TP] SWBAND is a tuning parameter. It is meaningful and effective */
900 /* if SGESVJ is used as a computational routine in the preconditioned */
901 /* Jacobi SVD algorithm SGESVJ. */
904 /* | * * * [x] [x] [x]| */
905 /* | * * * [x] [x] [x]| Row-cycling in the nblr-by-nblc [x] blocks. */
906 /* | * * * [x] [x] [x]| Row-cyclic pivoting inside each [x] block. */
907 /* |[x] [x] [x] * * * | */
908 /* |[x] [x] [x] * * * | */
909 /* |[x] [x] [x] * * * | */
913 for (i__ = 1; i__ <= i__1; ++i__) {
923 for (ibr = 1; ibr <= i__2; ++ibr) {
924 igl = (ibr - 1) * kbl + 1;
927 /* ........................................................ */
928 /* ... go to the off diagonal blocks */
929 igl = (ibr - 1) * kbl + 1;
931 for (jbc = 1; jbc <= i__3; ++jbc) {
932 jgl = *n1 + (jbc - 1) * kbl + 1;
933 /* doing the block at ( ibr, jbc ) */
936 i__5 = igl + kbl - 1;
937 i__4 = f2cmin(i__5,*n1);
938 for (p = igl; p <= i__4; ++p) {
943 i__6 = jgl + kbl - 1;
944 i__5 = f2cmin(i__6,*n);
945 for (q = jgl; q <= i__5; ++q) {
955 rotok = small * aapp <= aaqq;
957 rotok = small * aaqq <= aapp;
959 if (aapp < big / aaqq) {
960 aapq = sdot_(m, &a[p * a_dim1 + 1], &
961 c__1, &a[q * a_dim1 + 1], &
962 c__1) * d__[p] * d__[q] /
965 scopy_(m, &a[p * a_dim1 + 1], &c__1, &
967 slascl_("G", &c__0, &c__0, &aapp, &
968 d__[p], m, &c__1, &work[1],
970 aapq = sdot_(m, &work[1], &c__1, &a[q
971 * a_dim1 + 1], &c__1) * d__[q]
976 rotok = aapp <= aaqq / small;
978 rotok = aaqq <= aapp / small;
980 if (aapp > small / aaqq) {
981 aapq = sdot_(m, &a[p * a_dim1 + 1], &
982 c__1, &a[q * a_dim1 + 1], &
983 c__1) * d__[p] * d__[q] /
986 scopy_(m, &a[q * a_dim1 + 1], &c__1, &
988 slascl_("G", &c__0, &c__0, &aaqq, &
989 d__[q], m, &c__1, &work[1],
991 aapq = sdot_(m, &work[1], &c__1, &a[p
992 * a_dim1 + 1], &c__1) * d__[p]
997 r__1 = mxaapq, r__2 = abs(aapq);
998 mxaapq = f2cmax(r__1,r__2);
999 /* TO rotate or NOT to rotate, THAT is the question ... */
1001 if (abs(aapq) > *tol) {
1003 /* ROTATED = ROTATED + 1 */
1009 aqoap = aaqq / aapp;
1010 apoaq = aapp / aaqq;
1011 theta = (r__1 = aqoap - apoaq, abs(
1012 r__1)) * -.5f / aapq;
1016 if (abs(theta) > bigtheta) {
1018 fastr[2] = t * d__[p] / d__[q];
1019 fastr[3] = -t * d__[q] / d__[p];
1020 srotm_(m, &a[p * a_dim1 + 1], &
1021 c__1, &a[q * a_dim1 + 1],
1024 srotm_(&mvl, &v[p * v_dim1 + 1], &c__1, &v[q *
1025 v_dim1 + 1], &c__1, fastr);
1028 r__1 = 0.f, r__2 = t * apoaq *
1030 sva[q] = aaqq * sqrt((f2cmax(r__1,
1033 r__1 = 0.f, r__2 = 1.f - t *
1035 aapp *= sqrt((f2cmax(r__1,r__2)));
1037 r__1 = mxsinj, r__2 = abs(t);
1038 mxsinj = f2cmax(r__1,r__2);
1042 thsign = -r_sign(&c_b35, &aapq);
1046 t = 1.f / (theta + thsign * sqrt(
1047 theta * theta + 1.f));
1048 cs = sqrt(1.f / (t * t + 1.f));
1051 r__1 = mxsinj, r__2 = abs(sn);
1052 mxsinj = f2cmax(r__1,r__2);
1054 r__1 = 0.f, r__2 = t * apoaq *
1056 sva[q] = aaqq * sqrt((f2cmax(r__1,
1059 r__1 = 0.f, r__2 = 1.f - t *
1061 aapp *= sqrt((f2cmax(r__1,r__2)));
1062 apoaq = d__[p] / d__[q];
1063 aqoap = d__[q] / d__[p];
1064 if (d__[p] >= 1.f) {
1066 if (d__[q] >= 1.f) {
1067 fastr[2] = t * apoaq;
1068 fastr[3] = -t * aqoap;
1071 srotm_(m, &a[p * a_dim1 + 1], &c__1, &a[q *
1072 a_dim1 + 1], &c__1, fastr);
1074 srotm_(&mvl, &v[p * v_dim1 + 1], &c__1, &v[
1075 q * v_dim1 + 1], &c__1, fastr);
1079 saxpy_(m, &r__1, &a[q * a_dim1 + 1], &c__1, &a[
1080 p * a_dim1 + 1], &c__1);
1081 r__1 = cs * sn * apoaq;
1082 saxpy_(m, &r__1, &a[p * a_dim1 + 1], &c__1, &a[
1083 q * a_dim1 + 1], &c__1);
1086 saxpy_(&mvl, &r__1, &v[q * v_dim1 + 1], &
1087 c__1, &v[p * v_dim1 + 1], &c__1);
1088 r__1 = cs * sn * apoaq;
1089 saxpy_(&mvl, &r__1, &v[p * v_dim1 + 1], &
1090 c__1, &v[q * v_dim1 + 1], &c__1);
1096 if (d__[q] >= 1.f) {
1098 saxpy_(m, &r__1, &a[p * a_dim1 + 1], &c__1, &a[
1099 q * a_dim1 + 1], &c__1);
1100 r__1 = -cs * sn * aqoap;
1101 saxpy_(m, &r__1, &a[q * a_dim1 + 1], &c__1, &a[
1102 p * a_dim1 + 1], &c__1);
1105 saxpy_(&mvl, &r__1, &v[p * v_dim1 + 1], &
1106 c__1, &v[q * v_dim1 + 1], &c__1);
1107 r__1 = -cs * sn * aqoap;
1108 saxpy_(&mvl, &r__1, &v[q * v_dim1 + 1], &
1109 c__1, &v[p * v_dim1 + 1], &c__1);
1114 if (d__[p] >= d__[q]) {
1116 saxpy_(m, &r__1, &a[q * a_dim1 + 1], &c__1,
1117 &a[p * a_dim1 + 1], &c__1);
1118 r__1 = cs * sn * apoaq;
1119 saxpy_(m, &r__1, &a[p * a_dim1 + 1], &c__1,
1120 &a[q * a_dim1 + 1], &c__1);
1125 saxpy_(&mvl, &r__1, &v[q * v_dim1 + 1],
1126 &c__1, &v[p * v_dim1 + 1], &
1128 r__1 = cs * sn * apoaq;
1129 saxpy_(&mvl, &r__1, &v[p * v_dim1 + 1],
1130 &c__1, &v[q * v_dim1 + 1], &
1135 saxpy_(m, &r__1, &a[p * a_dim1 + 1], &c__1,
1136 &a[q * a_dim1 + 1], &c__1);
1137 r__1 = -cs * sn * aqoap;
1138 saxpy_(m, &r__1, &a[q * a_dim1 + 1], &c__1,
1139 &a[p * a_dim1 + 1], &c__1);
1144 saxpy_(&mvl, &r__1, &v[p * v_dim1 + 1],
1145 &c__1, &v[q * v_dim1 + 1], &
1147 r__1 = -cs * sn * aqoap;
1148 saxpy_(&mvl, &r__1, &v[q * v_dim1 + 1],
1149 &c__1, &v[p * v_dim1 + 1], &
1158 scopy_(m, &a[p * a_dim1 + 1], &
1159 c__1, &work[1], &c__1);
1160 slascl_("G", &c__0, &c__0, &aapp,
1161 &c_b35, m, &c__1, &work[1]
1163 slascl_("G", &c__0, &c__0, &aaqq,
1164 &c_b35, m, &c__1, &a[q *
1165 a_dim1 + 1], lda, &ierr);
1166 temp1 = -aapq * d__[p] / d__[q];
1167 saxpy_(m, &temp1, &work[1], &c__1,
1168 &a[q * a_dim1 + 1], &
1170 slascl_("G", &c__0, &c__0, &c_b35,
1171 &aaqq, m, &c__1, &a[q *
1172 a_dim1 + 1], lda, &ierr);
1174 r__1 = 0.f, r__2 = 1.f - aapq *
1176 sva[q] = aaqq * sqrt((f2cmax(r__1,
1178 mxsinj = f2cmax(mxsinj,*sfmin);
1180 scopy_(m, &a[q * a_dim1 + 1], &
1181 c__1, &work[1], &c__1);
1182 slascl_("G", &c__0, &c__0, &aaqq,
1183 &c_b35, m, &c__1, &work[1]
1185 slascl_("G", &c__0, &c__0, &aapp,
1186 &c_b35, m, &c__1, &a[p *
1187 a_dim1 + 1], lda, &ierr);
1188 temp1 = -aapq * d__[q] / d__[p];
1189 saxpy_(m, &temp1, &work[1], &c__1,
1190 &a[p * a_dim1 + 1], &
1192 slascl_("G", &c__0, &c__0, &c_b35,
1193 &aapp, m, &c__1, &a[p *
1194 a_dim1 + 1], lda, &ierr);
1196 r__1 = 0.f, r__2 = 1.f - aapq *
1198 sva[p] = aapp * sqrt((f2cmax(r__1,
1200 mxsinj = f2cmax(mxsinj,*sfmin);
1203 /* END IF ROTOK THEN ... ELSE */
1205 /* In the case of cancellation in updating SVA(q) */
1206 /* Computing 2nd power */
1207 r__1 = sva[q] / aaqq;
1208 if (r__1 * r__1 <= rooteps) {
1209 if (aaqq < rootbig && aaqq >
1211 sva[q] = snrm2_(m, &a[q * a_dim1
1212 + 1], &c__1) * d__[q];
1216 slassq_(m, &a[q * a_dim1 + 1], &
1218 sva[q] = t * sqrt(aaqq) * d__[q];
1221 /* Computing 2nd power */
1222 r__1 = aapp / aapp0;
1223 if (r__1 * r__1 <= rooteps) {
1224 if (aapp < rootbig && aapp >
1226 aapp = snrm2_(m, &a[p * a_dim1 +
1227 1], &c__1) * d__[p];
1231 slassq_(m, &a[p * a_dim1 + 1], &
1233 aapp = t * sqrt(aapp) * d__[p];
1237 /* end of OK rotation */
1240 /* SKIPPED = SKIPPED + 1 */
1249 /* IF ( NOTROT .GE. EMPTSW ) GO TO 2011 */
1250 if (i__ <= swband && ijblsk >= blskip) {
1255 if (i__ <= swband && pskipped > rowskip) {
1263 /* end of the q-loop */
1270 i__5 = jgl + kbl - 1;
1271 notrot = notrot + f2cmin(i__5,*n) - jgl + 1;
1276 /* ** IF ( NOTROT .GE. EMPTSW ) GO TO 2011 */
1280 /* end of the p-loop */
1283 /* end of the jbc-loop */
1285 /* 2011 bailed out of the jbc-loop */
1287 i__4 = igl + kbl - 1;
1288 i__3 = f2cmin(i__4,*n);
1289 for (p = igl; p <= i__3; ++p) {
1290 sva[p] = (r__1 = sva[p], abs(r__1));
1293 /* ** IF ( NOTROT .GE. EMPTSW ) GO TO 1994 */
1296 /* 2000 :: end of the ibr-loop */
1298 if (sva[*n] < rootbig && sva[*n] > rootsfmin) {
1299 sva[*n] = snrm2_(m, &a[*n * a_dim1 + 1], &c__1) * d__[*n];
1303 slassq_(m, &a[*n * a_dim1 + 1], &c__1, &t, &aapp);
1304 sva[*n] = t * sqrt(aapp) * d__[*n];
1307 /* Additional steering devices */
1309 if (i__ < swband && (mxaapq <= roottol || iswrot <= *n)) {
1312 if (i__ > swband + 1 && mxaapq < (real) (*n) * *tol && (real) (*n) *
1313 mxaapq * mxsinj < *tol) {
1317 if (notrot >= emptsw) {
1322 /* end i=1:NSWEEP loop */
1323 /* #:) Reaching this point means that the procedure has completed the given */
1324 /* number of sweeps. */
1325 *info = *nsweep - 1;
1328 /* #:) Reaching this point means that during the i-th sweep all pivots were */
1329 /* below the given threshold, causing early exit. */
1331 /* #:) INFO = 0 confirms successful iterations. */
1334 /* Sort the vector D */
1337 for (p = 1; p <= i__1; ++p) {
1339 q = isamax_(&i__2, &sva[p], &c__1) + p - 1;
1347 sswap_(m, &a[p * a_dim1 + 1], &c__1, &a[q * a_dim1 + 1], &c__1);
1349 sswap_(&mvl, &v[p * v_dim1 + 1], &c__1, &v[q * v_dim1 + 1], &