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_b10 = -.125;
516 static real c_b35 = -1.f;
517 static integer c__1 = 1;
519 /* > \brief \b SBBCSD */
521 /* =========== DOCUMENTATION =========== */
523 /* Online html documentation available at */
524 /* http://www.netlib.org/lapack/explore-html/ */
527 /* > Download SBBCSD + dependencies */
528 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/sbbcsd.
531 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/sbbcsd.
534 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/sbbcsd.
542 /* SUBROUTINE SBBCSD( JOBU1, JOBU2, JOBV1T, JOBV2T, TRANS, M, P, Q, */
543 /* THETA, PHI, U1, LDU1, U2, LDU2, V1T, LDV1T, */
544 /* V2T, LDV2T, B11D, B11E, B12D, B12E, B21D, B21E, */
545 /* B22D, B22E, WORK, LWORK, INFO ) */
547 /* CHARACTER JOBU1, JOBU2, JOBV1T, JOBV2T, TRANS */
548 /* INTEGER INFO, LDU1, LDU2, LDV1T, LDV2T, LWORK, M, P, Q */
549 /* REAL B11D( * ), B11E( * ), B12D( * ), B12E( * ), */
550 /* $ B21D( * ), B21E( * ), B22D( * ), B22E( * ), */
551 /* $ PHI( * ), THETA( * ), WORK( * ) */
552 /* REAL U1( LDU1, * ), U2( LDU2, * ), V1T( LDV1T, * ), */
553 /* $ V2T( LDV2T, * ) */
556 /* > \par Purpose: */
561 /* > SBBCSD computes the CS decomposition of an orthogonal matrix in */
562 /* > bidiagonal-block form, */
565 /* > [ B11 | B12 0 0 ] */
566 /* > [ 0 | 0 -I 0 ] */
567 /* > X = [----------------] */
568 /* > [ B21 | B22 0 0 ] */
569 /* > [ 0 | 0 0 I ] */
571 /* > [ C | -S 0 0 ] */
572 /* > [ U1 | ] [ 0 | 0 -I 0 ] [ V1 | ]**T */
573 /* > = [---------] [---------------] [---------] . */
574 /* > [ | U2 ] [ S | C 0 0 ] [ | V2 ] */
575 /* > [ 0 | 0 0 I ] */
577 /* > X is M-by-M, its top-left block is P-by-Q, and Q must be no larger */
578 /* > than P, M-P, or M-Q. (If Q is not the smallest index, then X must be */
579 /* > transposed and/or permuted. This can be done in constant time using */
580 /* > the TRANS and SIGNS options. See SORCSD for details.) */
582 /* > The bidiagonal matrices B11, B12, B21, and B22 are represented */
583 /* > implicitly by angles THETA(1:Q) and PHI(1:Q-1). */
585 /* > The orthogonal matrices U1, U2, V1T, and V2T are input/output. */
586 /* > The input matrices are pre- or post-multiplied by the appropriate */
587 /* > singular vector matrices. */
593 /* > \param[in] JOBU1 */
595 /* > JOBU1 is CHARACTER */
596 /* > = 'Y': U1 is updated; */
597 /* > otherwise: U1 is not updated. */
600 /* > \param[in] JOBU2 */
602 /* > JOBU2 is CHARACTER */
603 /* > = 'Y': U2 is updated; */
604 /* > otherwise: U2 is not updated. */
607 /* > \param[in] JOBV1T */
609 /* > JOBV1T is CHARACTER */
610 /* > = 'Y': V1T is updated; */
611 /* > otherwise: V1T is not updated. */
614 /* > \param[in] JOBV2T */
616 /* > JOBV2T is CHARACTER */
617 /* > = 'Y': V2T is updated; */
618 /* > otherwise: V2T is not updated. */
621 /* > \param[in] TRANS */
623 /* > TRANS is CHARACTER */
624 /* > = 'T': X, U1, U2, V1T, and V2T are stored in row-major */
626 /* > otherwise: X, U1, U2, V1T, and V2T are stored in column- */
633 /* > The number of rows and columns in X, the orthogonal matrix in */
634 /* > bidiagonal-block form. */
640 /* > The number of rows in the top-left block of X. 0 <= P <= M. */
646 /* > The number of columns in the top-left block of X. */
647 /* > 0 <= Q <= MIN(P,M-P,M-Q). */
650 /* > \param[in,out] THETA */
652 /* > THETA is REAL array, dimension (Q) */
653 /* > On entry, the angles THETA(1),...,THETA(Q) that, along with */
654 /* > PHI(1), ...,PHI(Q-1), define the matrix in bidiagonal-block */
655 /* > form. On exit, the angles whose cosines and sines define the */
656 /* > diagonal blocks in the CS decomposition. */
659 /* > \param[in,out] PHI */
661 /* > PHI is REAL array, dimension (Q-1) */
662 /* > The angles PHI(1),...,PHI(Q-1) that, along with THETA(1),..., */
663 /* > THETA(Q), define the matrix in bidiagonal-block form. */
666 /* > \param[in,out] U1 */
668 /* > U1 is REAL array, dimension (LDU1,P) */
669 /* > On entry, a P-by-P matrix. On exit, U1 is postmultiplied */
670 /* > by the left singular vector matrix common to [ B11 ; 0 ] and */
671 /* > [ B12 0 0 ; 0 -I 0 0 ]. */
674 /* > \param[in] LDU1 */
676 /* > LDU1 is INTEGER */
677 /* > The leading dimension of the array U1, LDU1 >= MAX(1,P). */
680 /* > \param[in,out] U2 */
682 /* > U2 is REAL array, dimension (LDU2,M-P) */
683 /* > On entry, an (M-P)-by-(M-P) matrix. On exit, U2 is */
684 /* > postmultiplied by the left singular vector matrix common to */
685 /* > [ B21 ; 0 ] and [ B22 0 0 ; 0 0 I ]. */
688 /* > \param[in] LDU2 */
690 /* > LDU2 is INTEGER */
691 /* > The leading dimension of the array U2, LDU2 >= MAX(1,M-P). */
694 /* > \param[in,out] V1T */
696 /* > V1T is REAL array, dimension (LDV1T,Q) */
697 /* > On entry, a Q-by-Q matrix. On exit, V1T is premultiplied */
698 /* > by the transpose of the right singular vector */
699 /* > matrix common to [ B11 ; 0 ] and [ B21 ; 0 ]. */
702 /* > \param[in] LDV1T */
704 /* > LDV1T is INTEGER */
705 /* > The leading dimension of the array V1T, LDV1T >= MAX(1,Q). */
708 /* > \param[in,out] V2T */
710 /* > V2T is REAL array, dimension (LDV2T,M-Q) */
711 /* > On entry, an (M-Q)-by-(M-Q) matrix. On exit, V2T is */
712 /* > premultiplied by the transpose of the right */
713 /* > singular vector matrix common to [ B12 0 0 ; 0 -I 0 ] and */
714 /* > [ B22 0 0 ; 0 0 I ]. */
717 /* > \param[in] LDV2T */
719 /* > LDV2T is INTEGER */
720 /* > The leading dimension of the array V2T, LDV2T >= MAX(1,M-Q). */
723 /* > \param[out] B11D */
725 /* > B11D is REAL array, dimension (Q) */
726 /* > When SBBCSD converges, B11D contains the cosines of THETA(1), */
727 /* > ..., THETA(Q). If SBBCSD fails to converge, then B11D */
728 /* > contains the diagonal of the partially reduced top-left */
732 /* > \param[out] B11E */
734 /* > B11E is REAL array, dimension (Q-1) */
735 /* > When SBBCSD converges, B11E contains zeros. If SBBCSD fails */
736 /* > to converge, then B11E contains the superdiagonal of the */
737 /* > partially reduced top-left block. */
740 /* > \param[out] B12D */
742 /* > B12D is REAL array, dimension (Q) */
743 /* > When SBBCSD converges, B12D contains the negative sines of */
744 /* > THETA(1), ..., THETA(Q). If SBBCSD fails to converge, then */
745 /* > B12D contains the diagonal of the partially reduced top-right */
749 /* > \param[out] B12E */
751 /* > B12E is REAL array, dimension (Q-1) */
752 /* > When SBBCSD converges, B12E contains zeros. If SBBCSD fails */
753 /* > to converge, then B12E contains the subdiagonal of the */
754 /* > partially reduced top-right block. */
757 /* > \param[out] B21D */
759 /* > B21D is REAL array, dimension (Q) */
760 /* > When SBBCSD converges, B21D contains the negative sines of */
761 /* > THETA(1), ..., THETA(Q). If SBBCSD fails to converge, then */
762 /* > B21D contains the diagonal of the partially reduced bottom-left */
766 /* > \param[out] B21E */
768 /* > B21E is REAL array, dimension (Q-1) */
769 /* > When SBBCSD converges, B21E contains zeros. If SBBCSD fails */
770 /* > to converge, then B21E contains the subdiagonal of the */
771 /* > partially reduced bottom-left block. */
774 /* > \param[out] B22D */
776 /* > B22D is REAL array, dimension (Q) */
777 /* > When SBBCSD converges, B22D contains the negative sines of */
778 /* > THETA(1), ..., THETA(Q). If SBBCSD fails to converge, then */
779 /* > B22D contains the diagonal of the partially reduced bottom-right */
783 /* > \param[out] B22E */
785 /* > B22E is REAL array, dimension (Q-1) */
786 /* > When SBBCSD converges, B22E contains zeros. If SBBCSD fails */
787 /* > to converge, then B22E contains the subdiagonal of the */
788 /* > partially reduced bottom-right block. */
791 /* > \param[out] WORK */
793 /* > WORK is REAL array, dimension (MAX(1,LWORK)) */
794 /* > On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */
797 /* > \param[in] LWORK */
799 /* > LWORK is INTEGER */
800 /* > The dimension of the array WORK. LWORK >= MAX(1,8*Q). */
802 /* > If LWORK = -1, then a workspace query is assumed; the */
803 /* > routine only calculates the optimal size of the WORK array, */
804 /* > returns this value as the first entry of the work array, and */
805 /* > no error message related to LWORK is issued by XERBLA. */
808 /* > \param[out] INFO */
810 /* > INFO is INTEGER */
811 /* > = 0: successful exit. */
812 /* > < 0: if INFO = -i, the i-th argument had an illegal value. */
813 /* > > 0: if SBBCSD did not converge, INFO specifies the number */
814 /* > of nonzero entries in PHI, and B11D, B11E, etc., */
815 /* > contain the partially reduced matrix. */
818 /* > \par Internal Parameters: */
819 /* ========================= */
822 /* > TOLMUL REAL, default = MAX(10,MIN(100,EPS**(-1/8))) */
823 /* > TOLMUL controls the convergence criterion of the QR loop. */
824 /* > Angles THETA(i), PHI(i) are rounded to 0 or PI/2 when they */
825 /* > are within TOLMUL*EPS of either bound. */
828 /* > \par References: */
829 /* ================ */
831 /* > [1] Brian D. Sutton. Computing the complete CS decomposition. Numer. */
832 /* > Algorithms, 50(1):33-65, 2009. */
837 /* > \author Univ. of Tennessee */
838 /* > \author Univ. of California Berkeley */
839 /* > \author Univ. of Colorado Denver */
840 /* > \author NAG Ltd. */
842 /* > \date June 2016 */
844 /* > \ingroup realOTHERcomputational */
846 /* ===================================================================== */
847 /* Subroutine */ int sbbcsd_(char *jobu1, char *jobu2, char *jobv1t, char *
848 jobv2t, char *trans, integer *m, integer *p, integer *q, real *theta,
849 real *phi, real *u1, integer *ldu1, real *u2, integer *ldu2, real *
850 v1t, integer *ldv1t, real *v2t, integer *ldv2t, real *b11d, real *
851 b11e, real *b12d, real *b12e, real *b21d, real *b21e, real *b22d,
852 real *b22e, real *work, integer *lwork, integer *info)
854 /* System generated locals */
855 integer u1_dim1, u1_offset, u2_dim1, u2_offset, v1t_dim1, v1t_offset,
856 v2t_dim1, v2t_offset, i__1, i__2;
857 real r__1, r__2, r__3, r__4;
860 /* Local variables */
861 integer imin, mini, imax, iter;
864 real thetamin, thetamax;
865 logical restart11, restart12, restart21, restart22;
866 integer lworkmin, iu1cs, iu2cs;
867 extern /* Subroutine */ int slas2_(real *, real *, real *, real *, real *)
869 integer iu1sn, iu2sn, lworkopt, i__, j;
871 extern logical lsame_(char *, char *);
872 extern /* Subroutine */ int sscal_(integer *, real *, real *, integer *);
874 extern /* Subroutine */ int slasr_(char *, char *, char *, integer *,
875 integer *, real *, real *, real *, integer *);
877 extern /* Subroutine */ int sswap_(integer *, real *, integer *, real *,
880 integer iv1tcs, iv2tcs;
881 logical wantu1, wantu2;
882 integer iv1tsn, iv2tsn;
883 real mu, nu, sigma11, sigma21;
884 extern real slamch_(char *);
885 extern /* Subroutine */ int xerbla_(char *, integer *, ftnlen);
887 extern /* Subroutine */ int mecago_();
890 logical wantv1t, wantv2t;
891 real b12bulge, b21bulge, b22bulge, eps, tol;
892 extern /* Subroutine */ int slartgp_(real *, real *, real *, real *, real
893 *), slartgs_(real *, real *, real *, real *, real *);
896 /* -- LAPACK computational routine (version 3.7.1) -- */
897 /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
898 /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
902 /* =================================================================== */
906 /* Test input arguments */
908 /* Parameter adjustments */
912 u1_offset = 1 + u1_dim1 * 1;
915 u2_offset = 1 + u2_dim1 * 1;
918 v1t_offset = 1 + v1t_dim1 * 1;
921 v2t_offset = 1 + v2t_dim1 * 1;
935 lquery = *lwork == -1;
936 wantu1 = lsame_(jobu1, "Y");
937 wantu2 = lsame_(jobu2, "Y");
938 wantv1t = lsame_(jobv1t, "Y");
939 wantv2t = lsame_(jobv2t, "Y");
940 colmajor = ! lsame_(trans, "T");
944 } else if (*p < 0 || *p > *m) {
946 } else if (*q < 0 || *q > *m) {
948 } else if (*q > *p || *q > *m - *p || *q > *m - *q) {
950 } else if (wantu1 && *ldu1 < *p) {
952 } else if (wantu2 && *ldu2 < *m - *p) {
954 } else if (wantv1t && *ldv1t < *q) {
956 } else if (wantv2t && *ldv2t < *m - *q) {
960 /* Quick return if Q = 0 */
962 if (*info == 0 && *q == 0) {
964 work[1] = (real) lworkmin;
968 /* Compute workspace */
976 iv1tsn = iv1tcs + *q;
977 iv2tcs = iv1tsn + *q;
978 iv2tsn = iv2tcs + *q;
979 lworkopt = iv2tsn + *q - 1;
981 work[1] = (real) lworkopt;
982 if (*lwork < lworkmin && ! lquery) {
989 xerbla_("SBBCSD", &i__1,(ftnlen)6);
995 /* Get machine constants */
997 eps = slamch_("Epsilon");
998 unfl = slamch_("Safe minimum");
1001 d__1 = (doublereal) eps;
1002 r__3 = 100.f, r__4 = pow_dd(&d__1, &c_b10);
1003 r__1 = 10.f, r__2 = f2cmin(r__3,r__4);
1004 tolmul = f2cmax(r__1,r__2);
1007 r__1 = tol, r__2 = *q * 6 * *q * unfl;
1008 thresh = f2cmax(r__1,r__2);
1010 /* Test for negligible sines or cosines */
1013 for (i__ = 1; i__ <= i__1; ++i__) {
1014 if (theta[i__] < thresh) {
1016 } else if (theta[i__] > 1.57079632679489662f - thresh) {
1017 theta[i__] = 1.57079632679489662f;
1021 for (i__ = 1; i__ <= i__1; ++i__) {
1022 if (phi[i__] < thresh) {
1024 } else if (phi[i__] > 1.57079632679489662f - thresh) {
1025 phi[i__] = 1.57079632679489662f;
1029 /* Initial deflation */
1033 if (phi[imax - 1] != 0.f) {
1040 while(phi[imin - 1] != 0.f) {
1048 /* Initialize iteration counter */
1050 maxit = *q * 6 * *q;
1053 /* Begin main iteration loop */
1057 /* Compute the matrix entries */
1059 b11d[imin] = cos(theta[imin]);
1060 b21d[imin] = -sin(theta[imin]);
1062 for (i__ = imin; i__ <= i__1; ++i__) {
1063 b11e[i__] = -sin(theta[i__]) * sin(phi[i__]);
1064 b11d[i__ + 1] = cos(theta[i__ + 1]) * cos(phi[i__]);
1065 b12d[i__] = sin(theta[i__]) * cos(phi[i__]);
1066 b12e[i__] = cos(theta[i__ + 1]) * sin(phi[i__]);
1067 b21e[i__] = -cos(theta[i__]) * sin(phi[i__]);
1068 b21d[i__ + 1] = -sin(theta[i__ + 1]) * cos(phi[i__]);
1069 b22d[i__] = cos(theta[i__]) * cos(phi[i__]);
1070 b22e[i__] = -sin(theta[i__ + 1]) * sin(phi[i__]);
1072 b12d[imax] = sin(theta[imax]);
1073 b22d[imax] = cos(theta[imax]);
1075 /* Abort if not converging; otherwise, increment ITER */
1080 for (i__ = 1; i__ <= i__1; ++i__) {
1081 if (phi[i__] != 0.f) {
1088 iter = iter + imax - imin;
1090 /* Compute shifts */
1092 thetamax = theta[imin];
1093 thetamin = theta[imin];
1095 for (i__ = imin + 1; i__ <= i__1; ++i__) {
1096 if (theta[i__] > thetamax) {
1097 thetamax = theta[i__];
1099 if (theta[i__] < thetamin) {
1100 thetamin = theta[i__];
1104 if (thetamax > 1.57079632679489662f - thresh) {
1106 /* Zero on diagonals of B11 and B22; induce deflation with a */
1112 } else if (thetamin < thresh) {
1114 /* Zero on diagonals of B12 and B22; induce deflation with a */
1122 /* Compute shifts for B11 and B21 and use the lesser */
1124 slas2_(&b11d[imax - 1], &b11e[imax - 1], &b11d[imax], &sigma11, &
1126 slas2_(&b21d[imax - 1], &b21e[imax - 1], &b21d[imax], &sigma21, &
1129 if (sigma11 <= sigma21) {
1131 /* Computing 2nd power */
1133 nu = sqrt(1.f - r__1 * r__1);
1140 /* Computing 2nd power */
1142 mu = sqrt(1.f - r__1 * r__1);
1150 /* Rotate to produce bulges in B11 and B21 */
1153 slartgs_(&b11d[imin], &b11e[imin], &mu, &work[iv1tcs + imin - 1],
1154 &work[iv1tsn + imin - 1]);
1156 slartgs_(&b21d[imin], &b21e[imin], &nu, &work[iv1tcs + imin - 1],
1157 &work[iv1tsn + imin - 1]);
1160 temp = work[iv1tcs + imin - 1] * b11d[imin] + work[iv1tsn + imin - 1]
1162 b11e[imin] = work[iv1tcs + imin - 1] * b11e[imin] - work[iv1tsn +
1163 imin - 1] * b11d[imin];
1165 b11bulge = work[iv1tsn + imin - 1] * b11d[imin + 1];
1166 b11d[imin + 1] = work[iv1tcs + imin - 1] * b11d[imin + 1];
1167 temp = work[iv1tcs + imin - 1] * b21d[imin] + work[iv1tsn + imin - 1]
1169 b21e[imin] = work[iv1tcs + imin - 1] * b21e[imin] - work[iv1tsn +
1170 imin - 1] * b21d[imin];
1172 b21bulge = work[iv1tsn + imin - 1] * b21d[imin + 1];
1173 b21d[imin + 1] = work[iv1tcs + imin - 1] * b21d[imin + 1];
1175 /* Compute THETA(IMIN) */
1177 /* Computing 2nd power */
1179 /* Computing 2nd power */
1181 /* Computing 2nd power */
1183 /* Computing 2nd power */
1185 theta[imin] = atan2(sqrt(r__1 * r__1 + r__2 * r__2), sqrt(r__3 * r__3
1188 /* Chase the bulges in B11(IMIN+1,IMIN) and B21(IMIN+1,IMIN) */
1190 /* Computing 2nd power */
1192 /* Computing 2nd power */
1194 /* Computing 2nd power */
1196 if (r__1 * r__1 + r__2 * r__2 > r__3 * r__3) {
1197 slartgp_(&b11bulge, &b11d[imin], &work[iu1sn + imin - 1], &work[
1198 iu1cs + imin - 1], &r__);
1199 } else if (mu <= nu) {
1200 slartgs_(&b11e[imin], &b11d[imin + 1], &mu, &work[iu1cs + imin -
1201 1], &work[iu1sn + imin - 1]);
1203 slartgs_(&b12d[imin], &b12e[imin], &nu, &work[iu1cs + imin - 1], &
1204 work[iu1sn + imin - 1]);
1206 /* Computing 2nd power */
1208 /* Computing 2nd power */
1210 /* Computing 2nd power */
1212 if (r__1 * r__1 + r__2 * r__2 > r__3 * r__3) {
1213 slartgp_(&b21bulge, &b21d[imin], &work[iu2sn + imin - 1], &work[
1214 iu2cs + imin - 1], &r__);
1215 } else if (nu < mu) {
1216 slartgs_(&b21e[imin], &b21d[imin + 1], &nu, &work[iu2cs + imin -
1217 1], &work[iu2sn + imin - 1]);
1219 slartgs_(&b22d[imin], &b22e[imin], &mu, &work[iu2cs + imin - 1], &
1220 work[iu2sn + imin - 1]);
1222 work[iu2cs + imin - 1] = -work[iu2cs + imin - 1];
1223 work[iu2sn + imin - 1] = -work[iu2sn + imin - 1];
1225 temp = work[iu1cs + imin - 1] * b11e[imin] + work[iu1sn + imin - 1] *
1227 b11d[imin + 1] = work[iu1cs + imin - 1] * b11d[imin + 1] - work[iu1sn
1228 + imin - 1] * b11e[imin];
1230 if (imax > imin + 1) {
1231 b11bulge = work[iu1sn + imin - 1] * b11e[imin + 1];
1232 b11e[imin + 1] = work[iu1cs + imin - 1] * b11e[imin + 1];
1234 temp = work[iu1cs + imin - 1] * b12d[imin] + work[iu1sn + imin - 1] *
1236 b12e[imin] = work[iu1cs + imin - 1] * b12e[imin] - work[iu1sn + imin
1239 b12bulge = work[iu1sn + imin - 1] * b12d[imin + 1];
1240 b12d[imin + 1] = work[iu1cs + imin - 1] * b12d[imin + 1];
1241 temp = work[iu2cs + imin - 1] * b21e[imin] + work[iu2sn + imin - 1] *
1243 b21d[imin + 1] = work[iu2cs + imin - 1] * b21d[imin + 1] - work[iu2sn
1244 + imin - 1] * b21e[imin];
1246 if (imax > imin + 1) {
1247 b21bulge = work[iu2sn + imin - 1] * b21e[imin + 1];
1248 b21e[imin + 1] = work[iu2cs + imin - 1] * b21e[imin + 1];
1250 temp = work[iu2cs + imin - 1] * b22d[imin] + work[iu2sn + imin - 1] *
1252 b22e[imin] = work[iu2cs + imin - 1] * b22e[imin] - work[iu2sn + imin
1255 b22bulge = work[iu2sn + imin - 1] * b22d[imin + 1];
1256 b22d[imin + 1] = work[iu2cs + imin - 1] * b22d[imin + 1];
1258 /* Inner loop: chase bulges from B11(IMIN,IMIN+2), */
1259 /* B12(IMIN,IMIN+1), B21(IMIN,IMIN+2), and B22(IMIN,IMIN+1) to */
1263 for (i__ = imin + 1; i__ <= i__1; ++i__) {
1265 /* Compute PHI(I-1) */
1267 x1 = sin(theta[i__ - 1]) * b11e[i__ - 1] + cos(theta[i__ - 1]) *
1269 x2 = sin(theta[i__ - 1]) * b11bulge + cos(theta[i__ - 1]) *
1271 y1 = sin(theta[i__ - 1]) * b12d[i__ - 1] + cos(theta[i__ - 1]) *
1273 y2 = sin(theta[i__ - 1]) * b12bulge + cos(theta[i__ - 1]) *
1276 /* Computing 2nd power */
1278 /* Computing 2nd power */
1280 /* Computing 2nd power */
1282 /* Computing 2nd power */
1284 phi[i__ - 1] = atan2(sqrt(r__1 * r__1 + r__2 * r__2), sqrt(r__3 *
1285 r__3 + r__4 * r__4));
1287 /* Determine if there are bulges to chase or if a new direct */
1288 /* summand has been reached */
1290 /* Computing 2nd power */
1291 r__1 = b11e[i__ - 1];
1292 /* Computing 2nd power */
1294 /* Computing 2nd power */
1296 restart11 = r__1 * r__1 + r__2 * r__2 <= r__3 * r__3;
1297 /* Computing 2nd power */
1298 r__1 = b21e[i__ - 1];
1299 /* Computing 2nd power */
1301 /* Computing 2nd power */
1303 restart21 = r__1 * r__1 + r__2 * r__2 <= r__3 * r__3;
1304 /* Computing 2nd power */
1305 r__1 = b12d[i__ - 1];
1306 /* Computing 2nd power */
1308 /* Computing 2nd power */
1310 restart12 = r__1 * r__1 + r__2 * r__2 <= r__3 * r__3;
1311 /* Computing 2nd power */
1312 r__1 = b22d[i__ - 1];
1313 /* Computing 2nd power */
1315 /* Computing 2nd power */
1317 restart22 = r__1 * r__1 + r__2 * r__2 <= r__3 * r__3;
1319 /* If possible, chase bulges from B11(I-1,I+1), B12(I-1,I), */
1320 /* B21(I-1,I+1), and B22(I-1,I). If necessary, restart bulge- */
1321 /* chasing by applying the original shift again. */
1323 if (! restart11 && ! restart21) {
1324 slartgp_(&x2, &x1, &work[iv1tsn + i__ - 1], &work[iv1tcs +
1326 } else if (! restart11 && restart21) {
1327 slartgp_(&b11bulge, &b11e[i__ - 1], &work[iv1tsn + i__ - 1], &
1328 work[iv1tcs + i__ - 1], &r__);
1329 } else if (restart11 && ! restart21) {
1330 slartgp_(&b21bulge, &b21e[i__ - 1], &work[iv1tsn + i__ - 1], &
1331 work[iv1tcs + i__ - 1], &r__);
1332 } else if (mu <= nu) {
1333 slartgs_(&b11d[i__], &b11e[i__], &mu, &work[iv1tcs + i__ - 1],
1334 &work[iv1tsn + i__ - 1]);
1336 slartgs_(&b21d[i__], &b21e[i__], &nu, &work[iv1tcs + i__ - 1],
1337 &work[iv1tsn + i__ - 1]);
1339 work[iv1tcs + i__ - 1] = -work[iv1tcs + i__ - 1];
1340 work[iv1tsn + i__ - 1] = -work[iv1tsn + i__ - 1];
1341 if (! restart12 && ! restart22) {
1342 slartgp_(&y2, &y1, &work[iv2tsn + i__ - 2], &work[iv2tcs +
1344 } else if (! restart12 && restart22) {
1345 slartgp_(&b12bulge, &b12d[i__ - 1], &work[iv2tsn + i__ - 2], &
1346 work[iv2tcs + i__ - 2], &r__);
1347 } else if (restart12 && ! restart22) {
1348 slartgp_(&b22bulge, &b22d[i__ - 1], &work[iv2tsn + i__ - 2], &
1349 work[iv2tcs + i__ - 2], &r__);
1350 } else if (nu < mu) {
1351 slartgs_(&b12e[i__ - 1], &b12d[i__], &nu, &work[iv2tcs + i__
1352 - 2], &work[iv2tsn + i__ - 2]);
1354 slartgs_(&b22e[i__ - 1], &b22d[i__], &mu, &work[iv2tcs + i__
1355 - 2], &work[iv2tsn + i__ - 2]);
1358 temp = work[iv1tcs + i__ - 1] * b11d[i__] + work[iv1tsn + i__ - 1]
1360 b11e[i__] = work[iv1tcs + i__ - 1] * b11e[i__] - work[iv1tsn +
1361 i__ - 1] * b11d[i__];
1363 b11bulge = work[iv1tsn + i__ - 1] * b11d[i__ + 1];
1364 b11d[i__ + 1] = work[iv1tcs + i__ - 1] * b11d[i__ + 1];
1365 temp = work[iv1tcs + i__ - 1] * b21d[i__] + work[iv1tsn + i__ - 1]
1367 b21e[i__] = work[iv1tcs + i__ - 1] * b21e[i__] - work[iv1tsn +
1368 i__ - 1] * b21d[i__];
1370 b21bulge = work[iv1tsn + i__ - 1] * b21d[i__ + 1];
1371 b21d[i__ + 1] = work[iv1tcs + i__ - 1] * b21d[i__ + 1];
1372 temp = work[iv2tcs + i__ - 2] * b12e[i__ - 1] + work[iv2tsn + i__
1374 b12d[i__] = work[iv2tcs + i__ - 2] * b12d[i__] - work[iv2tsn +
1375 i__ - 2] * b12e[i__ - 1];
1376 b12e[i__ - 1] = temp;
1377 b12bulge = work[iv2tsn + i__ - 2] * b12e[i__];
1378 b12e[i__] = work[iv2tcs + i__ - 2] * b12e[i__];
1379 temp = work[iv2tcs + i__ - 2] * b22e[i__ - 1] + work[iv2tsn + i__
1381 b22d[i__] = work[iv2tcs + i__ - 2] * b22d[i__] - work[iv2tsn +
1382 i__ - 2] * b22e[i__ - 1];
1383 b22e[i__ - 1] = temp;
1384 b22bulge = work[iv2tsn + i__ - 2] * b22e[i__];
1385 b22e[i__] = work[iv2tcs + i__ - 2] * b22e[i__];
1387 /* Compute THETA(I) */
1389 x1 = cos(phi[i__ - 1]) * b11d[i__] + sin(phi[i__ - 1]) * b12e[i__
1391 x2 = cos(phi[i__ - 1]) * b11bulge + sin(phi[i__ - 1]) * b12bulge;
1392 y1 = cos(phi[i__ - 1]) * b21d[i__] + sin(phi[i__ - 1]) * b22e[i__
1394 y2 = cos(phi[i__ - 1]) * b21bulge + sin(phi[i__ - 1]) * b22bulge;
1396 /* Computing 2nd power */
1398 /* Computing 2nd power */
1400 /* Computing 2nd power */
1402 /* Computing 2nd power */
1404 theta[i__] = atan2(sqrt(r__1 * r__1 + r__2 * r__2), sqrt(r__3 *
1405 r__3 + r__4 * r__4));
1407 /* Determine if there are bulges to chase or if a new direct */
1408 /* summand has been reached */
1410 /* Computing 2nd power */
1412 /* Computing 2nd power */
1414 /* Computing 2nd power */
1416 restart11 = r__1 * r__1 + r__2 * r__2 <= r__3 * r__3;
1417 /* Computing 2nd power */
1418 r__1 = b12e[i__ - 1];
1419 /* Computing 2nd power */
1421 /* Computing 2nd power */
1423 restart12 = r__1 * r__1 + r__2 * r__2 <= r__3 * r__3;
1424 /* Computing 2nd power */
1426 /* Computing 2nd power */
1428 /* Computing 2nd power */
1430 restart21 = r__1 * r__1 + r__2 * r__2 <= r__3 * r__3;
1431 /* Computing 2nd power */
1432 r__1 = b22e[i__ - 1];
1433 /* Computing 2nd power */
1435 /* Computing 2nd power */
1437 restart22 = r__1 * r__1 + r__2 * r__2 <= r__3 * r__3;
1439 /* If possible, chase bulges from B11(I+1,I), B12(I+1,I-1), */
1440 /* B21(I+1,I), and B22(I+1,I-1). If necessary, restart bulge- */
1441 /* chasing by applying the original shift again. */
1443 if (! restart11 && ! restart12) {
1444 slartgp_(&x2, &x1, &work[iu1sn + i__ - 1], &work[iu1cs + i__
1446 } else if (! restart11 && restart12) {
1447 slartgp_(&b11bulge, &b11d[i__], &work[iu1sn + i__ - 1], &work[
1448 iu1cs + i__ - 1], &r__);
1449 } else if (restart11 && ! restart12) {
1450 slartgp_(&b12bulge, &b12e[i__ - 1], &work[iu1sn + i__ - 1], &
1451 work[iu1cs + i__ - 1], &r__);
1452 } else if (mu <= nu) {
1453 slartgs_(&b11e[i__], &b11d[i__ + 1], &mu, &work[iu1cs + i__ -
1454 1], &work[iu1sn + i__ - 1]);
1456 slartgs_(&b12d[i__], &b12e[i__], &nu, &work[iu1cs + i__ - 1],
1457 &work[iu1sn + i__ - 1]);
1459 if (! restart21 && ! restart22) {
1460 slartgp_(&y2, &y1, &work[iu2sn + i__ - 1], &work[iu2cs + i__
1462 } else if (! restart21 && restart22) {
1463 slartgp_(&b21bulge, &b21d[i__], &work[iu2sn + i__ - 1], &work[
1464 iu2cs + i__ - 1], &r__);
1465 } else if (restart21 && ! restart22) {
1466 slartgp_(&b22bulge, &b22e[i__ - 1], &work[iu2sn + i__ - 1], &
1467 work[iu2cs + i__ - 1], &r__);
1468 } else if (nu < mu) {
1469 slartgs_(&b21e[i__], &b21e[i__ + 1], &nu, &work[iu2cs + i__ -
1470 1], &work[iu2sn + i__ - 1]);
1472 slartgs_(&b22d[i__], &b22e[i__], &mu, &work[iu2cs + i__ - 1],
1473 &work[iu2sn + i__ - 1]);
1475 work[iu2cs + i__ - 1] = -work[iu2cs + i__ - 1];
1476 work[iu2sn + i__ - 1] = -work[iu2sn + i__ - 1];
1478 temp = work[iu1cs + i__ - 1] * b11e[i__] + work[iu1sn + i__ - 1] *
1480 b11d[i__ + 1] = work[iu1cs + i__ - 1] * b11d[i__ + 1] - work[
1481 iu1sn + i__ - 1] * b11e[i__];
1483 if (i__ < imax - 1) {
1484 b11bulge = work[iu1sn + i__ - 1] * b11e[i__ + 1];
1485 b11e[i__ + 1] = work[iu1cs + i__ - 1] * b11e[i__ + 1];
1487 temp = work[iu2cs + i__ - 1] * b21e[i__] + work[iu2sn + i__ - 1] *
1489 b21d[i__ + 1] = work[iu2cs + i__ - 1] * b21d[i__ + 1] - work[
1490 iu2sn + i__ - 1] * b21e[i__];
1492 if (i__ < imax - 1) {
1493 b21bulge = work[iu2sn + i__ - 1] * b21e[i__ + 1];
1494 b21e[i__ + 1] = work[iu2cs + i__ - 1] * b21e[i__ + 1];
1496 temp = work[iu1cs + i__ - 1] * b12d[i__] + work[iu1sn + i__ - 1] *
1498 b12e[i__] = work[iu1cs + i__ - 1] * b12e[i__] - work[iu1sn + i__
1501 b12bulge = work[iu1sn + i__ - 1] * b12d[i__ + 1];
1502 b12d[i__ + 1] = work[iu1cs + i__ - 1] * b12d[i__ + 1];
1503 temp = work[iu2cs + i__ - 1] * b22d[i__] + work[iu2sn + i__ - 1] *
1505 b22e[i__] = work[iu2cs + i__ - 1] * b22e[i__] - work[iu2sn + i__
1508 b22bulge = work[iu2sn + i__ - 1] * b22d[i__ + 1];
1509 b22d[i__ + 1] = work[iu2cs + i__ - 1] * b22d[i__ + 1];
1513 /* Compute PHI(IMAX-1) */
1515 x1 = sin(theta[imax - 1]) * b11e[imax - 1] + cos(theta[imax - 1]) *
1517 y1 = sin(theta[imax - 1]) * b12d[imax - 1] + cos(theta[imax - 1]) *
1519 y2 = sin(theta[imax - 1]) * b12bulge + cos(theta[imax - 1]) *
1522 /* Computing 2nd power */
1524 /* Computing 2nd power */
1526 phi[imax - 1] = atan2((abs(x1)), sqrt(r__1 * r__1 + r__2 * r__2));
1528 /* Chase bulges from B12(IMAX-1,IMAX) and B22(IMAX-1,IMAX) */
1530 /* Computing 2nd power */
1531 r__1 = b12d[imax - 1];
1532 /* Computing 2nd power */
1534 /* Computing 2nd power */
1536 restart12 = r__1 * r__1 + r__2 * r__2 <= r__3 * r__3;
1537 /* Computing 2nd power */
1538 r__1 = b22d[imax - 1];
1539 /* Computing 2nd power */
1541 /* Computing 2nd power */
1543 restart22 = r__1 * r__1 + r__2 * r__2 <= r__3 * r__3;
1545 if (! restart12 && ! restart22) {
1546 slartgp_(&y2, &y1, &work[iv2tsn + imax - 2], &work[iv2tcs + imax
1548 } else if (! restart12 && restart22) {
1549 slartgp_(&b12bulge, &b12d[imax - 1], &work[iv2tsn + imax - 2], &
1550 work[iv2tcs + imax - 2], &r__);
1551 } else if (restart12 && ! restart22) {
1552 slartgp_(&b22bulge, &b22d[imax - 1], &work[iv2tsn + imax - 2], &
1553 work[iv2tcs + imax - 2], &r__);
1554 } else if (nu < mu) {
1555 slartgs_(&b12e[imax - 1], &b12d[imax], &nu, &work[iv2tcs + imax -
1556 2], &work[iv2tsn + imax - 2]);
1558 slartgs_(&b22e[imax - 1], &b22d[imax], &mu, &work[iv2tcs + imax -
1559 2], &work[iv2tsn + imax - 2]);
1562 temp = work[iv2tcs + imax - 2] * b12e[imax - 1] + work[iv2tsn + imax
1564 b12d[imax] = work[iv2tcs + imax - 2] * b12d[imax] - work[iv2tsn +
1565 imax - 2] * b12e[imax - 1];
1566 b12e[imax - 1] = temp;
1567 temp = work[iv2tcs + imax - 2] * b22e[imax - 1] + work[iv2tsn + imax
1569 b22d[imax] = work[iv2tcs + imax - 2] * b22d[imax] - work[iv2tsn +
1570 imax - 2] * b22e[imax - 1];
1571 b22e[imax - 1] = temp;
1573 /* Update singular vectors */
1577 i__1 = imax - imin + 1;
1578 slasr_("R", "V", "F", p, &i__1, &work[iu1cs + imin - 1], &
1579 work[iu1sn + imin - 1], &u1[imin * u1_dim1 + 1], ldu1);
1581 i__1 = imax - imin + 1;
1582 slasr_("L", "V", "F", &i__1, p, &work[iu1cs + imin - 1], &
1583 work[iu1sn + imin - 1], &u1[imin + u1_dim1], ldu1);
1589 i__2 = imax - imin + 1;
1590 slasr_("R", "V", "F", &i__1, &i__2, &work[iu2cs + imin - 1], &
1591 work[iu2sn + imin - 1], &u2[imin * u2_dim1 + 1], ldu2);
1593 i__1 = imax - imin + 1;
1595 slasr_("L", "V", "F", &i__1, &i__2, &work[iu2cs + imin - 1], &
1596 work[iu2sn + imin - 1], &u2[imin + u2_dim1], ldu2);
1601 i__1 = imax - imin + 1;
1602 slasr_("L", "V", "F", &i__1, q, &work[iv1tcs + imin - 1], &
1603 work[iv1tsn + imin - 1], &v1t[imin + v1t_dim1], ldv1t);
1605 i__1 = imax - imin + 1;
1606 slasr_("R", "V", "F", q, &i__1, &work[iv1tcs + imin - 1], &
1607 work[iv1tsn + imin - 1], &v1t[imin * v1t_dim1 + 1],
1613 i__1 = imax - imin + 1;
1615 slasr_("L", "V", "F", &i__1, &i__2, &work[iv2tcs + imin - 1],
1616 &work[iv2tsn + imin - 1], &v2t[imin + v2t_dim1],
1620 i__2 = imax - imin + 1;
1621 slasr_("R", "V", "F", &i__1, &i__2, &work[iv2tcs + imin - 1],
1622 &work[iv2tsn + imin - 1], &v2t[imin * v2t_dim1 + 1],
1627 /* Fix signs on B11(IMAX-1,IMAX) and B21(IMAX-1,IMAX) */
1629 if (b11e[imax - 1] + b21e[imax - 1] > 0.f) {
1630 b11d[imax] = -b11d[imax];
1631 b21d[imax] = -b21d[imax];
1634 sscal_(q, &c_b35, &v1t[imax + v1t_dim1], ldv1t);
1636 sscal_(q, &c_b35, &v1t[imax * v1t_dim1 + 1], &c__1);
1641 /* Compute THETA(IMAX) */
1643 x1 = cos(phi[imax - 1]) * b11d[imax] + sin(phi[imax - 1]) * b12e[imax
1645 y1 = cos(phi[imax - 1]) * b21d[imax] + sin(phi[imax - 1]) * b22e[imax
1648 theta[imax] = atan2((abs(y1)), (abs(x1)));
1650 /* Fix signs on B11(IMAX,IMAX), B12(IMAX,IMAX-1), B21(IMAX,IMAX), */
1651 /* and B22(IMAX,IMAX-1) */
1653 if (b11d[imax] + b12e[imax - 1] < 0.f) {
1654 b12d[imax] = -b12d[imax];
1657 sscal_(p, &c_b35, &u1[imax * u1_dim1 + 1], &c__1);
1659 sscal_(p, &c_b35, &u1[imax + u1_dim1], ldu1);
1663 if (b21d[imax] + b22e[imax - 1] > 0.f) {
1664 b22d[imax] = -b22d[imax];
1668 sscal_(&i__1, &c_b35, &u2[imax * u2_dim1 + 1], &c__1);
1671 sscal_(&i__1, &c_b35, &u2[imax + u2_dim1], ldu2);
1676 /* Fix signs on B12(IMAX,IMAX) and B22(IMAX,IMAX) */
1678 if (b12d[imax] + b22d[imax] < 0.f) {
1682 sscal_(&i__1, &c_b35, &v2t[imax + v2t_dim1], ldv2t);
1685 sscal_(&i__1, &c_b35, &v2t[imax * v2t_dim1 + 1], &c__1);
1690 /* Test for negligible sines or cosines */
1693 for (i__ = imin; i__ <= i__1; ++i__) {
1694 if (theta[i__] < thresh) {
1696 } else if (theta[i__] > 1.57079632679489662f - thresh) {
1697 theta[i__] = 1.57079632679489662f;
1701 for (i__ = imin; i__ <= i__1; ++i__) {
1702 if (phi[i__] < thresh) {
1704 } else if (phi[i__] > 1.57079632679489662f - thresh) {
1705 phi[i__] = 1.57079632679489662f;
1712 while(phi[imax - 1] == 0.f) {
1719 if (imin > imax - 1) {
1723 while(phi[imin - 1] != 0.f) {
1731 /* Repeat main iteration loop */
1735 /* Postprocessing: order THETA from least to greatest */
1738 for (i__ = 1; i__ <= i__1; ++i__) {
1741 thetamin = theta[i__];
1743 for (j = i__ + 1; j <= i__2; ++j) {
1744 if (theta[j] < thetamin) {
1746 thetamin = theta[j];
1751 theta[mini] = theta[i__];
1752 theta[i__] = thetamin;
1755 sswap_(p, &u1[i__ * u1_dim1 + 1], &c__1, &u1[mini *
1756 u1_dim1 + 1], &c__1);
1760 sswap_(&i__2, &u2[i__ * u2_dim1 + 1], &c__1, &u2[mini *
1761 u2_dim1 + 1], &c__1);
1764 sswap_(q, &v1t[i__ + v1t_dim1], ldv1t, &v1t[mini +
1769 sswap_(&i__2, &v2t[i__ + v2t_dim1], ldv2t, &v2t[mini +
1774 sswap_(p, &u1[i__ + u1_dim1], ldu1, &u1[mini + u1_dim1],
1779 sswap_(&i__2, &u2[i__ + u2_dim1], ldu2, &u2[mini +
1783 sswap_(q, &v1t[i__ * v1t_dim1 + 1], &c__1, &v1t[mini *
1784 v1t_dim1 + 1], &c__1);
1788 sswap_(&i__2, &v2t[i__ * v2t_dim1 + 1], &c__1, &v2t[mini *
1789 v2t_dim1 + 1], &c__1);