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 doublereal c_b35 = -1.;
517 static integer c__1 = 1;
519 /* > \brief \b DBBCSD */
521 /* =========== DOCUMENTATION =========== */
523 /* Online html documentation available at */
524 /* http://www.netlib.org/lapack/explore-html/ */
527 /* > Download DBBCSD + dependencies */
528 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dbbcsd.
531 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dbbcsd.
534 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dbbcsd.
542 /* SUBROUTINE DBBCSD( 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 /* DOUBLE PRECISION B11D( * ), B11E( * ), B12D( * ), B12E( * ), */
550 /* $ B21D( * ), B21E( * ), B22D( * ), B22E( * ), */
551 /* $ PHI( * ), THETA( * ), WORK( * ) */
552 /* DOUBLE PRECISION U1( LDU1, * ), U2( LDU2, * ), V1T( LDV1T, * ), */
553 /* $ V2T( LDV2T, * ) */
556 /* > \par Purpose: */
561 /* > DBBCSD 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 DORCSD 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 DOUBLE PRECISION 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 DOUBLE PRECISION 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 DOUBLE PRECISION 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 DOUBLE PRECISION 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 DOUBLE PRECISION 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 DOUBLE PRECISION 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 DOUBLE PRECISION array, dimension (Q) */
726 /* > When DBBCSD converges, B11D contains the cosines of THETA(1), */
727 /* > ..., THETA(Q). If DBBCSD fails to converge, then B11D */
728 /* > contains the diagonal of the partially reduced top-left */
732 /* > \param[out] B11E */
734 /* > B11E is DOUBLE PRECISION array, dimension (Q-1) */
735 /* > When DBBCSD converges, B11E contains zeros. If DBBCSD fails */
736 /* > to converge, then B11E contains the superdiagonal of the */
737 /* > partially reduced top-left block. */
740 /* > \param[out] B12D */
742 /* > B12D is DOUBLE PRECISION array, dimension (Q) */
743 /* > When DBBCSD converges, B12D contains the negative sines of */
744 /* > THETA(1), ..., THETA(Q). If DBBCSD fails to converge, then */
745 /* > B12D contains the diagonal of the partially reduced top-right */
749 /* > \param[out] B12E */
751 /* > B12E is DOUBLE PRECISION array, dimension (Q-1) */
752 /* > When DBBCSD converges, B12E contains zeros. If DBBCSD fails */
753 /* > to converge, then B12E contains the subdiagonal of the */
754 /* > partially reduced top-right block. */
757 /* > \param[out] B21D */
759 /* > B21D is DOUBLE PRECISION array, dimension (Q) */
760 /* > When DBBCSD converges, B21D contains the negative sines of */
761 /* > THETA(1), ..., THETA(Q). If DBBCSD fails to converge, then */
762 /* > B21D contains the diagonal of the partially reduced bottom-left */
766 /* > \param[out] B21E */
768 /* > B21E is DOUBLE PRECISION array, dimension (Q-1) */
769 /* > When DBBCSD converges, B21E contains zeros. If DBBCSD fails */
770 /* > to converge, then B21E contains the subdiagonal of the */
771 /* > partially reduced bottom-left block. */
774 /* > \param[out] B22D */
776 /* > B22D is DOUBLE PRECISION array, dimension (Q) */
777 /* > When DBBCSD converges, B22D contains the negative sines of */
778 /* > THETA(1), ..., THETA(Q). If DBBCSD fails to converge, then */
779 /* > B22D contains the diagonal of the partially reduced bottom-right */
783 /* > \param[out] B22E */
785 /* > B22E is DOUBLE PRECISION array, dimension (Q-1) */
786 /* > When DBBCSD converges, B22E contains zeros. If DBBCSD fails */
787 /* > to converge, then B22E contains the subdiagonal of the */
788 /* > partially reduced bottom-right block. */
791 /* > \param[out] WORK */
793 /* > WORK is DOUBLE PRECISION 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 DBBCSD 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 DOUBLE PRECISION, 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 doubleOTHERcomputational */
846 /* ===================================================================== */
847 /* Subroutine */ int dbbcsd_(char *jobu1, char *jobu2, char *jobv1t, char *
848 jobv2t, char *trans, integer *m, integer *p, integer *q, doublereal *
849 theta, doublereal *phi, doublereal *u1, integer *ldu1, doublereal *u2,
850 integer *ldu2, doublereal *v1t, integer *ldv1t, doublereal *v2t,
851 integer *ldv2t, doublereal *b11d, doublereal *b11e, doublereal *b12d,
852 doublereal *b12e, doublereal *b21d, doublereal *b21e, doublereal *
853 b22d, doublereal *b22e, doublereal *work, integer *lwork, integer *
856 /* System generated locals */
857 integer u1_dim1, u1_offset, u2_dim1, u2_offset, v1t_dim1, v1t_offset,
858 v2t_dim1, v2t_offset, i__1, i__2;
859 doublereal d__1, d__2, d__3, d__4;
861 /* Local variables */
862 integer imin, mini, imax, iter;
863 doublereal unfl, temp;
865 doublereal thetamin, thetamax;
866 logical restart11, restart12, restart21, restart22;
867 extern /* Subroutine */ int dlas2_(doublereal *, doublereal *, doublereal
868 *, doublereal *, doublereal *);
869 integer lworkmin, iu1cs, iu2cs, iu1sn, iu2sn, lworkopt, i__, j;
871 extern /* Subroutine */ int dscal_(integer *, doublereal *, doublereal *,
873 extern logical lsame_(char *, char *);
874 extern /* Subroutine */ int dlasr_(char *, char *, char *, integer *,
875 integer *, doublereal *, doublereal *, doublereal *, integer *), dswap_(integer *, doublereal *, integer *
876 , doublereal *, integer *);
878 doublereal dummy, x1, x2, y1, y2;
879 integer iv1tcs, iv2tcs;
880 logical wantu1, wantu2;
881 integer iv1tsn, iv2tsn;
882 extern doublereal dlamch_(char *);
883 doublereal mu, nu, sigma11, sigma21;
884 extern /* Subroutine */ int xerbla_(char *, integer *, ftnlen);
885 doublereal thresh, tolmul;
886 extern /* Subroutine */ int mecago_();
889 logical wantv1t, wantv2t;
890 doublereal b12bulge, b21bulge, b22bulge, eps, tol;
891 extern /* Subroutine */ int dlartgp_(doublereal *, doublereal *,
892 doublereal *, doublereal *, doublereal *), dlartgs_(doublereal *,
893 doublereal *, doublereal *, doublereal *, doublereal *);
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] = (doublereal) lworkmin;
968 /* Compute workspace */
976 iv1tsn = iv1tcs + *q;
977 iv2tcs = iv1tsn + *q;
978 iv2tsn = iv2tcs + *q;
979 lworkopt = iv2tsn + *q - 1;
981 work[1] = (doublereal) lworkopt;
982 if (*lwork < lworkmin && ! lquery) {
989 xerbla_("DBBCSD", &i__1, (ftnlen)6);
995 /* Get machine constants */
997 eps = dlamch_("Epsilon");
998 unfl = dlamch_("Safe minimum");
1001 d__3 = 100., d__4 = pow_dd(&eps, &c_b10);
1002 d__1 = 10., d__2 = f2cmin(d__3,d__4);
1003 tolmul = f2cmax(d__1,d__2);
1006 d__1 = tol, d__2 = *q * 6 * *q * unfl;
1007 thresh = f2cmax(d__1,d__2);
1009 /* Test for negligible sines or cosines */
1012 for (i__ = 1; i__ <= i__1; ++i__) {
1013 if (theta[i__] < thresh) {
1015 } else if (theta[i__] > 1.57079632679489662 - thresh) {
1016 theta[i__] = 1.57079632679489662;
1020 for (i__ = 1; i__ <= i__1; ++i__) {
1021 if (phi[i__] < thresh) {
1023 } else if (phi[i__] > 1.57079632679489662 - thresh) {
1024 phi[i__] = 1.57079632679489662;
1028 /* Initial deflation */
1032 if (phi[imax - 1] != 0.) {
1039 while(phi[imin - 1] != 0.) {
1047 /* Initialize iteration counter */
1049 maxit = *q * 6 * *q;
1052 /* Begin main iteration loop */
1056 /* Compute the matrix entries */
1058 b11d[imin] = cos(theta[imin]);
1059 b21d[imin] = -sin(theta[imin]);
1061 for (i__ = imin; i__ <= i__1; ++i__) {
1062 b11e[i__] = -sin(theta[i__]) * sin(phi[i__]);
1063 b11d[i__ + 1] = cos(theta[i__ + 1]) * cos(phi[i__]);
1064 b12d[i__] = sin(theta[i__]) * cos(phi[i__]);
1065 b12e[i__] = cos(theta[i__ + 1]) * sin(phi[i__]);
1066 b21e[i__] = -cos(theta[i__]) * sin(phi[i__]);
1067 b21d[i__ + 1] = -sin(theta[i__ + 1]) * cos(phi[i__]);
1068 b22d[i__] = cos(theta[i__]) * cos(phi[i__]);
1069 b22e[i__] = -sin(theta[i__ + 1]) * sin(phi[i__]);
1071 b12d[imax] = sin(theta[imax]);
1072 b22d[imax] = cos(theta[imax]);
1074 /* Abort if not converging; otherwise, increment ITER */
1079 for (i__ = 1; i__ <= i__1; ++i__) {
1080 if (phi[i__] != 0.) {
1087 iter = iter + imax - imin;
1089 /* Compute shifts */
1091 thetamax = theta[imin];
1092 thetamin = theta[imin];
1094 for (i__ = imin + 1; i__ <= i__1; ++i__) {
1095 if (theta[i__] > thetamax) {
1096 thetamax = theta[i__];
1098 if (theta[i__] < thetamin) {
1099 thetamin = theta[i__];
1103 if (thetamax > 1.57079632679489662 - thresh) {
1105 /* Zero on diagonals of B11 and B22; induce deflation with a */
1111 } else if (thetamin < thresh) {
1113 /* Zero on diagonals of B12 and B22; induce deflation with a */
1121 /* Compute shifts for B11 and B21 and use the lesser */
1123 dlas2_(&b11d[imax - 1], &b11e[imax - 1], &b11d[imax], &sigma11, &
1125 dlas2_(&b21d[imax - 1], &b21e[imax - 1], &b21d[imax], &sigma21, &
1128 if (sigma11 <= sigma21) {
1130 /* Computing 2nd power */
1132 nu = sqrt(1. - d__1 * d__1);
1139 /* Computing 2nd power */
1141 mu = sqrt(1.f - d__1 * d__1);
1149 /* Rotate to produce bulges in B11 and B21 */
1152 dlartgs_(&b11d[imin], &b11e[imin], &mu, &work[iv1tcs + imin - 1],
1153 &work[iv1tsn + imin - 1]);
1155 dlartgs_(&b21d[imin], &b21e[imin], &nu, &work[iv1tcs + imin - 1],
1156 &work[iv1tsn + imin - 1]);
1159 temp = work[iv1tcs + imin - 1] * b11d[imin] + work[iv1tsn + imin - 1]
1161 b11e[imin] = work[iv1tcs + imin - 1] * b11e[imin] - work[iv1tsn +
1162 imin - 1] * b11d[imin];
1164 b11bulge = work[iv1tsn + imin - 1] * b11d[imin + 1];
1165 b11d[imin + 1] = work[iv1tcs + imin - 1] * b11d[imin + 1];
1166 temp = work[iv1tcs + imin - 1] * b21d[imin] + work[iv1tsn + imin - 1]
1168 b21e[imin] = work[iv1tcs + imin - 1] * b21e[imin] - work[iv1tsn +
1169 imin - 1] * b21d[imin];
1171 b21bulge = work[iv1tsn + imin - 1] * b21d[imin + 1];
1172 b21d[imin + 1] = work[iv1tcs + imin - 1] * b21d[imin + 1];
1174 /* Compute THETA(IMIN) */
1176 /* Computing 2nd power */
1178 /* Computing 2nd power */
1180 /* Computing 2nd power */
1182 /* Computing 2nd power */
1184 theta[imin] = atan2(sqrt(d__1 * d__1 + d__2 * d__2), sqrt(d__3 * d__3
1187 /* Chase the bulges in B11(IMIN+1,IMIN) and B21(IMIN+1,IMIN) */
1189 /* Computing 2nd power */
1191 /* Computing 2nd power */
1193 /* Computing 2nd power */
1195 if (d__1 * d__1 + d__2 * d__2 > d__3 * d__3) {
1196 dlartgp_(&b11bulge, &b11d[imin], &work[iu1sn + imin - 1], &work[
1197 iu1cs + imin - 1], &r__);
1198 } else if (mu <= nu) {
1199 dlartgs_(&b11e[imin], &b11d[imin + 1], &mu, &work[iu1cs + imin -
1200 1], &work[iu1sn + imin - 1]);
1202 dlartgs_(&b12d[imin], &b12e[imin], &nu, &work[iu1cs + imin - 1], &
1203 work[iu1sn + imin - 1]);
1205 /* Computing 2nd power */
1207 /* Computing 2nd power */
1209 /* Computing 2nd power */
1211 if (d__1 * d__1 + d__2 * d__2 > d__3 * d__3) {
1212 dlartgp_(&b21bulge, &b21d[imin], &work[iu2sn + imin - 1], &work[
1213 iu2cs + imin - 1], &r__);
1214 } else if (nu < mu) {
1215 dlartgs_(&b21e[imin], &b21d[imin + 1], &nu, &work[iu2cs + imin -
1216 1], &work[iu2sn + imin - 1]);
1218 dlartgs_(&b22d[imin], &b22e[imin], &mu, &work[iu2cs + imin - 1], &
1219 work[iu2sn + imin - 1]);
1221 work[iu2cs + imin - 1] = -work[iu2cs + imin - 1];
1222 work[iu2sn + imin - 1] = -work[iu2sn + imin - 1];
1224 temp = work[iu1cs + imin - 1] * b11e[imin] + work[iu1sn + imin - 1] *
1226 b11d[imin + 1] = work[iu1cs + imin - 1] * b11d[imin + 1] - work[iu1sn
1227 + imin - 1] * b11e[imin];
1229 if (imax > imin + 1) {
1230 b11bulge = work[iu1sn + imin - 1] * b11e[imin + 1];
1231 b11e[imin + 1] = work[iu1cs + imin - 1] * b11e[imin + 1];
1233 temp = work[iu1cs + imin - 1] * b12d[imin] + work[iu1sn + imin - 1] *
1235 b12e[imin] = work[iu1cs + imin - 1] * b12e[imin] - work[iu1sn + imin
1238 b12bulge = work[iu1sn + imin - 1] * b12d[imin + 1];
1239 b12d[imin + 1] = work[iu1cs + imin - 1] * b12d[imin + 1];
1240 temp = work[iu2cs + imin - 1] * b21e[imin] + work[iu2sn + imin - 1] *
1242 b21d[imin + 1] = work[iu2cs + imin - 1] * b21d[imin + 1] - work[iu2sn
1243 + imin - 1] * b21e[imin];
1245 if (imax > imin + 1) {
1246 b21bulge = work[iu2sn + imin - 1] * b21e[imin + 1];
1247 b21e[imin + 1] = work[iu2cs + imin - 1] * b21e[imin + 1];
1249 temp = work[iu2cs + imin - 1] * b22d[imin] + work[iu2sn + imin - 1] *
1251 b22e[imin] = work[iu2cs + imin - 1] * b22e[imin] - work[iu2sn + imin
1254 b22bulge = work[iu2sn + imin - 1] * b22d[imin + 1];
1255 b22d[imin + 1] = work[iu2cs + imin - 1] * b22d[imin + 1];
1257 /* Inner loop: chase bulges from B11(IMIN,IMIN+2), */
1258 /* B12(IMIN,IMIN+1), B21(IMIN,IMIN+2), and B22(IMIN,IMIN+1) to */
1262 for (i__ = imin + 1; i__ <= i__1; ++i__) {
1264 /* Compute PHI(I-1) */
1266 x1 = sin(theta[i__ - 1]) * b11e[i__ - 1] + cos(theta[i__ - 1]) *
1268 x2 = sin(theta[i__ - 1]) * b11bulge + cos(theta[i__ - 1]) *
1270 y1 = sin(theta[i__ - 1]) * b12d[i__ - 1] + cos(theta[i__ - 1]) *
1272 y2 = sin(theta[i__ - 1]) * b12bulge + cos(theta[i__ - 1]) *
1275 /* Computing 2nd power */
1277 /* Computing 2nd power */
1279 /* Computing 2nd power */
1281 /* Computing 2nd power */
1283 phi[i__ - 1] = atan2(sqrt(d__1 * d__1 + d__2 * d__2), sqrt(d__3 *
1284 d__3 + d__4 * d__4));
1286 /* Determine if there are bulges to chase or if a new direct */
1287 /* summand has been reached */
1289 /* Computing 2nd power */
1290 d__1 = b11e[i__ - 1];
1291 /* Computing 2nd power */
1293 /* Computing 2nd power */
1295 restart11 = d__1 * d__1 + d__2 * d__2 <= d__3 * d__3;
1296 /* Computing 2nd power */
1297 d__1 = b21e[i__ - 1];
1298 /* Computing 2nd power */
1300 /* Computing 2nd power */
1302 restart21 = d__1 * d__1 + d__2 * d__2 <= d__3 * d__3;
1303 /* Computing 2nd power */
1304 d__1 = b12d[i__ - 1];
1305 /* Computing 2nd power */
1307 /* Computing 2nd power */
1309 restart12 = d__1 * d__1 + d__2 * d__2 <= d__3 * d__3;
1310 /* Computing 2nd power */
1311 d__1 = b22d[i__ - 1];
1312 /* Computing 2nd power */
1314 /* Computing 2nd power */
1316 restart22 = d__1 * d__1 + d__2 * d__2 <= d__3 * d__3;
1318 /* If possible, chase bulges from B11(I-1,I+1), B12(I-1,I), */
1319 /* B21(I-1,I+1), and B22(I-1,I). If necessary, restart bulge- */
1320 /* chasing by applying the original shift again. */
1322 if (! restart11 && ! restart21) {
1323 dlartgp_(&x2, &x1, &work[iv1tsn + i__ - 1], &work[iv1tcs +
1325 } else if (! restart11 && restart21) {
1326 dlartgp_(&b11bulge, &b11e[i__ - 1], &work[iv1tsn + i__ - 1], &
1327 work[iv1tcs + i__ - 1], &r__);
1328 } else if (restart11 && ! restart21) {
1329 dlartgp_(&b21bulge, &b21e[i__ - 1], &work[iv1tsn + i__ - 1], &
1330 work[iv1tcs + i__ - 1], &r__);
1331 } else if (mu <= nu) {
1332 dlartgs_(&b11d[i__], &b11e[i__], &mu, &work[iv1tcs + i__ - 1],
1333 &work[iv1tsn + i__ - 1]);
1335 dlartgs_(&b21d[i__], &b21e[i__], &nu, &work[iv1tcs + i__ - 1],
1336 &work[iv1tsn + i__ - 1]);
1338 work[iv1tcs + i__ - 1] = -work[iv1tcs + i__ - 1];
1339 work[iv1tsn + i__ - 1] = -work[iv1tsn + i__ - 1];
1340 if (! restart12 && ! restart22) {
1341 dlartgp_(&y2, &y1, &work[iv2tsn + i__ - 2], &work[iv2tcs +
1343 } else if (! restart12 && restart22) {
1344 dlartgp_(&b12bulge, &b12d[i__ - 1], &work[iv2tsn + i__ - 2], &
1345 work[iv2tcs + i__ - 2], &r__);
1346 } else if (restart12 && ! restart22) {
1347 dlartgp_(&b22bulge, &b22d[i__ - 1], &work[iv2tsn + i__ - 2], &
1348 work[iv2tcs + i__ - 2], &r__);
1349 } else if (nu < mu) {
1350 dlartgs_(&b12e[i__ - 1], &b12d[i__], &nu, &work[iv2tcs + i__
1351 - 2], &work[iv2tsn + i__ - 2]);
1353 dlartgs_(&b22e[i__ - 1], &b22d[i__], &mu, &work[iv2tcs + i__
1354 - 2], &work[iv2tsn + i__ - 2]);
1357 temp = work[iv1tcs + i__ - 1] * b11d[i__] + work[iv1tsn + i__ - 1]
1359 b11e[i__] = work[iv1tcs + i__ - 1] * b11e[i__] - work[iv1tsn +
1360 i__ - 1] * b11d[i__];
1362 b11bulge = work[iv1tsn + i__ - 1] * b11d[i__ + 1];
1363 b11d[i__ + 1] = work[iv1tcs + i__ - 1] * b11d[i__ + 1];
1364 temp = work[iv1tcs + i__ - 1] * b21d[i__] + work[iv1tsn + i__ - 1]
1366 b21e[i__] = work[iv1tcs + i__ - 1] * b21e[i__] - work[iv1tsn +
1367 i__ - 1] * b21d[i__];
1369 b21bulge = work[iv1tsn + i__ - 1] * b21d[i__ + 1];
1370 b21d[i__ + 1] = work[iv1tcs + i__ - 1] * b21d[i__ + 1];
1371 temp = work[iv2tcs + i__ - 2] * b12e[i__ - 1] + work[iv2tsn + i__
1373 b12d[i__] = work[iv2tcs + i__ - 2] * b12d[i__] - work[iv2tsn +
1374 i__ - 2] * b12e[i__ - 1];
1375 b12e[i__ - 1] = temp;
1376 b12bulge = work[iv2tsn + i__ - 2] * b12e[i__];
1377 b12e[i__] = work[iv2tcs + i__ - 2] * b12e[i__];
1378 temp = work[iv2tcs + i__ - 2] * b22e[i__ - 1] + work[iv2tsn + i__
1380 b22d[i__] = work[iv2tcs + i__ - 2] * b22d[i__] - work[iv2tsn +
1381 i__ - 2] * b22e[i__ - 1];
1382 b22e[i__ - 1] = temp;
1383 b22bulge = work[iv2tsn + i__ - 2] * b22e[i__];
1384 b22e[i__] = work[iv2tcs + i__ - 2] * b22e[i__];
1386 /* Compute THETA(I) */
1388 x1 = cos(phi[i__ - 1]) * b11d[i__] + sin(phi[i__ - 1]) * b12e[i__
1390 x2 = cos(phi[i__ - 1]) * b11bulge + sin(phi[i__ - 1]) * b12bulge;
1391 y1 = cos(phi[i__ - 1]) * b21d[i__] + sin(phi[i__ - 1]) * b22e[i__
1393 y2 = cos(phi[i__ - 1]) * b21bulge + sin(phi[i__ - 1]) * b22bulge;
1395 /* Computing 2nd power */
1397 /* Computing 2nd power */
1399 /* Computing 2nd power */
1401 /* Computing 2nd power */
1403 theta[i__] = atan2(sqrt(d__1 * d__1 + d__2 * d__2), sqrt(d__3 *
1404 d__3 + d__4 * d__4));
1406 /* Determine if there are bulges to chase or if a new direct */
1407 /* summand has been reached */
1409 /* Computing 2nd power */
1411 /* Computing 2nd power */
1413 /* Computing 2nd power */
1415 restart11 = d__1 * d__1 + d__2 * d__2 <= d__3 * d__3;
1416 /* Computing 2nd power */
1417 d__1 = b12e[i__ - 1];
1418 /* Computing 2nd power */
1420 /* Computing 2nd power */
1422 restart12 = d__1 * d__1 + d__2 * d__2 <= d__3 * d__3;
1423 /* Computing 2nd power */
1425 /* Computing 2nd power */
1427 /* Computing 2nd power */
1429 restart21 = d__1 * d__1 + d__2 * d__2 <= d__3 * d__3;
1430 /* Computing 2nd power */
1431 d__1 = b22e[i__ - 1];
1432 /* Computing 2nd power */
1434 /* Computing 2nd power */
1436 restart22 = d__1 * d__1 + d__2 * d__2 <= d__3 * d__3;
1438 /* If possible, chase bulges from B11(I+1,I), B12(I+1,I-1), */
1439 /* B21(I+1,I), and B22(I+1,I-1). If necessary, restart bulge- */
1440 /* chasing by applying the original shift again. */
1442 if (! restart11 && ! restart12) {
1443 dlartgp_(&x2, &x1, &work[iu1sn + i__ - 1], &work[iu1cs + i__
1445 } else if (! restart11 && restart12) {
1446 dlartgp_(&b11bulge, &b11d[i__], &work[iu1sn + i__ - 1], &work[
1447 iu1cs + i__ - 1], &r__);
1448 } else if (restart11 && ! restart12) {
1449 dlartgp_(&b12bulge, &b12e[i__ - 1], &work[iu1sn + i__ - 1], &
1450 work[iu1cs + i__ - 1], &r__);
1451 } else if (mu <= nu) {
1452 dlartgs_(&b11e[i__], &b11d[i__ + 1], &mu, &work[iu1cs + i__ -
1453 1], &work[iu1sn + i__ - 1]);
1455 dlartgs_(&b12d[i__], &b12e[i__], &nu, &work[iu1cs + i__ - 1],
1456 &work[iu1sn + i__ - 1]);
1458 if (! restart21 && ! restart22) {
1459 dlartgp_(&y2, &y1, &work[iu2sn + i__ - 1], &work[iu2cs + i__
1461 } else if (! restart21 && restart22) {
1462 dlartgp_(&b21bulge, &b21d[i__], &work[iu2sn + i__ - 1], &work[
1463 iu2cs + i__ - 1], &r__);
1464 } else if (restart21 && ! restart22) {
1465 dlartgp_(&b22bulge, &b22e[i__ - 1], &work[iu2sn + i__ - 1], &
1466 work[iu2cs + i__ - 1], &r__);
1467 } else if (nu < mu) {
1468 dlartgs_(&b21e[i__], &b21e[i__ + 1], &nu, &work[iu2cs + i__ -
1469 1], &work[iu2sn + i__ - 1]);
1471 dlartgs_(&b22d[i__], &b22e[i__], &mu, &work[iu2cs + i__ - 1],
1472 &work[iu2sn + i__ - 1]);
1474 work[iu2cs + i__ - 1] = -work[iu2cs + i__ - 1];
1475 work[iu2sn + i__ - 1] = -work[iu2sn + i__ - 1];
1477 temp = work[iu1cs + i__ - 1] * b11e[i__] + work[iu1sn + i__ - 1] *
1479 b11d[i__ + 1] = work[iu1cs + i__ - 1] * b11d[i__ + 1] - work[
1480 iu1sn + i__ - 1] * b11e[i__];
1482 if (i__ < imax - 1) {
1483 b11bulge = work[iu1sn + i__ - 1] * b11e[i__ + 1];
1484 b11e[i__ + 1] = work[iu1cs + i__ - 1] * b11e[i__ + 1];
1486 temp = work[iu2cs + i__ - 1] * b21e[i__] + work[iu2sn + i__ - 1] *
1488 b21d[i__ + 1] = work[iu2cs + i__ - 1] * b21d[i__ + 1] - work[
1489 iu2sn + i__ - 1] * b21e[i__];
1491 if (i__ < imax - 1) {
1492 b21bulge = work[iu2sn + i__ - 1] * b21e[i__ + 1];
1493 b21e[i__ + 1] = work[iu2cs + i__ - 1] * b21e[i__ + 1];
1495 temp = work[iu1cs + i__ - 1] * b12d[i__] + work[iu1sn + i__ - 1] *
1497 b12e[i__] = work[iu1cs + i__ - 1] * b12e[i__] - work[iu1sn + i__
1500 b12bulge = work[iu1sn + i__ - 1] * b12d[i__ + 1];
1501 b12d[i__ + 1] = work[iu1cs + i__ - 1] * b12d[i__ + 1];
1502 temp = work[iu2cs + i__ - 1] * b22d[i__] + work[iu2sn + i__ - 1] *
1504 b22e[i__] = work[iu2cs + i__ - 1] * b22e[i__] - work[iu2sn + i__
1507 b22bulge = work[iu2sn + i__ - 1] * b22d[i__ + 1];
1508 b22d[i__ + 1] = work[iu2cs + i__ - 1] * b22d[i__ + 1];
1512 /* Compute PHI(IMAX-1) */
1514 x1 = sin(theta[imax - 1]) * b11e[imax - 1] + cos(theta[imax - 1]) *
1516 y1 = sin(theta[imax - 1]) * b12d[imax - 1] + cos(theta[imax - 1]) *
1518 y2 = sin(theta[imax - 1]) * b12bulge + cos(theta[imax - 1]) *
1521 /* Computing 2nd power */
1523 /* Computing 2nd power */
1525 phi[imax - 1] = atan2((abs(x1)), sqrt(d__1 * d__1 + d__2 * d__2));
1527 /* Chase bulges from B12(IMAX-1,IMAX) and B22(IMAX-1,IMAX) */
1529 /* Computing 2nd power */
1530 d__1 = b12d[imax - 1];
1531 /* Computing 2nd power */
1533 /* Computing 2nd power */
1535 restart12 = d__1 * d__1 + d__2 * d__2 <= d__3 * d__3;
1536 /* Computing 2nd power */
1537 d__1 = b22d[imax - 1];
1538 /* Computing 2nd power */
1540 /* Computing 2nd power */
1542 restart22 = d__1 * d__1 + d__2 * d__2 <= d__3 * d__3;
1544 if (! restart12 && ! restart22) {
1545 dlartgp_(&y2, &y1, &work[iv2tsn + imax - 2], &work[iv2tcs + imax
1547 } else if (! restart12 && restart22) {
1548 dlartgp_(&b12bulge, &b12d[imax - 1], &work[iv2tsn + imax - 2], &
1549 work[iv2tcs + imax - 2], &r__);
1550 } else if (restart12 && ! restart22) {
1551 dlartgp_(&b22bulge, &b22d[imax - 1], &work[iv2tsn + imax - 2], &
1552 work[iv2tcs + imax - 2], &r__);
1553 } else if (nu < mu) {
1554 dlartgs_(&b12e[imax - 1], &b12d[imax], &nu, &work[iv2tcs + imax -
1555 2], &work[iv2tsn + imax - 2]);
1557 dlartgs_(&b22e[imax - 1], &b22d[imax], &mu, &work[iv2tcs + imax -
1558 2], &work[iv2tsn + imax - 2]);
1561 temp = work[iv2tcs + imax - 2] * b12e[imax - 1] + work[iv2tsn + imax
1563 b12d[imax] = work[iv2tcs + imax - 2] * b12d[imax] - work[iv2tsn +
1564 imax - 2] * b12e[imax - 1];
1565 b12e[imax - 1] = temp;
1566 temp = work[iv2tcs + imax - 2] * b22e[imax - 1] + work[iv2tsn + imax
1568 b22d[imax] = work[iv2tcs + imax - 2] * b22d[imax] - work[iv2tsn +
1569 imax - 2] * b22e[imax - 1];
1570 b22e[imax - 1] = temp;
1572 /* Update singular vectors */
1576 i__1 = imax - imin + 1;
1577 dlasr_("R", "V", "F", p, &i__1, &work[iu1cs + imin - 1], &
1578 work[iu1sn + imin - 1], &u1[imin * u1_dim1 + 1], ldu1);
1580 i__1 = imax - imin + 1;
1581 dlasr_("L", "V", "F", &i__1, p, &work[iu1cs + imin - 1], &
1582 work[iu1sn + imin - 1], &u1[imin + u1_dim1], ldu1);
1588 i__2 = imax - imin + 1;
1589 dlasr_("R", "V", "F", &i__1, &i__2, &work[iu2cs + imin - 1], &
1590 work[iu2sn + imin - 1], &u2[imin * u2_dim1 + 1], ldu2);
1592 i__1 = imax - imin + 1;
1594 dlasr_("L", "V", "F", &i__1, &i__2, &work[iu2cs + imin - 1], &
1595 work[iu2sn + imin - 1], &u2[imin + u2_dim1], ldu2);
1600 i__1 = imax - imin + 1;
1601 dlasr_("L", "V", "F", &i__1, q, &work[iv1tcs + imin - 1], &
1602 work[iv1tsn + imin - 1], &v1t[imin + v1t_dim1], ldv1t);
1604 i__1 = imax - imin + 1;
1605 dlasr_("R", "V", "F", q, &i__1, &work[iv1tcs + imin - 1], &
1606 work[iv1tsn + imin - 1], &v1t[imin * v1t_dim1 + 1],
1612 i__1 = imax - imin + 1;
1614 dlasr_("L", "V", "F", &i__1, &i__2, &work[iv2tcs + imin - 1],
1615 &work[iv2tsn + imin - 1], &v2t[imin + v2t_dim1],
1619 i__2 = imax - imin + 1;
1620 dlasr_("R", "V", "F", &i__1, &i__2, &work[iv2tcs + imin - 1],
1621 &work[iv2tsn + imin - 1], &v2t[imin * v2t_dim1 + 1],
1626 /* Fix signs on B11(IMAX-1,IMAX) and B21(IMAX-1,IMAX) */
1628 if (b11e[imax - 1] + b21e[imax - 1] > 0.) {
1629 b11d[imax] = -b11d[imax];
1630 b21d[imax] = -b21d[imax];
1633 dscal_(q, &c_b35, &v1t[imax + v1t_dim1], ldv1t);
1635 dscal_(q, &c_b35, &v1t[imax * v1t_dim1 + 1], &c__1);
1640 /* Compute THETA(IMAX) */
1642 x1 = cos(phi[imax - 1]) * b11d[imax] + sin(phi[imax - 1]) * b12e[imax
1644 y1 = cos(phi[imax - 1]) * b21d[imax] + sin(phi[imax - 1]) * b22e[imax
1647 theta[imax] = atan2((abs(y1)), (abs(x1)));
1649 /* Fix signs on B11(IMAX,IMAX), B12(IMAX,IMAX-1), B21(IMAX,IMAX), */
1650 /* and B22(IMAX,IMAX-1) */
1652 if (b11d[imax] + b12e[imax - 1] < 0.) {
1653 b12d[imax] = -b12d[imax];
1656 dscal_(p, &c_b35, &u1[imax * u1_dim1 + 1], &c__1);
1658 dscal_(p, &c_b35, &u1[imax + u1_dim1], ldu1);
1662 if (b21d[imax] + b22e[imax - 1] > 0.) {
1663 b22d[imax] = -b22d[imax];
1667 dscal_(&i__1, &c_b35, &u2[imax * u2_dim1 + 1], &c__1);
1670 dscal_(&i__1, &c_b35, &u2[imax + u2_dim1], ldu2);
1675 /* Fix signs on B12(IMAX,IMAX) and B22(IMAX,IMAX) */
1677 if (b12d[imax] + b22d[imax] < 0.) {
1681 dscal_(&i__1, &c_b35, &v2t[imax + v2t_dim1], ldv2t);
1684 dscal_(&i__1, &c_b35, &v2t[imax * v2t_dim1 + 1], &c__1);
1689 /* Test for negligible sines or cosines */
1692 for (i__ = imin; i__ <= i__1; ++i__) {
1693 if (theta[i__] < thresh) {
1695 } else if (theta[i__] > 1.57079632679489662 - thresh) {
1696 theta[i__] = 1.57079632679489662;
1700 for (i__ = imin; i__ <= i__1; ++i__) {
1701 if (phi[i__] < thresh) {
1703 } else if (phi[i__] > 1.57079632679489662 - thresh) {
1704 phi[i__] = 1.57079632679489662;
1711 while(phi[imax - 1] == 0.) {
1718 if (imin > imax - 1) {
1722 while(phi[imin - 1] != 0.) {
1730 /* Repeat main iteration loop */
1734 /* Postprocessing: order THETA from least to greatest */
1737 for (i__ = 1; i__ <= i__1; ++i__) {
1740 thetamin = theta[i__];
1742 for (j = i__ + 1; j <= i__2; ++j) {
1743 if (theta[j] < thetamin) {
1745 thetamin = theta[j];
1750 theta[mini] = theta[i__];
1751 theta[i__] = thetamin;
1754 dswap_(p, &u1[i__ * u1_dim1 + 1], &c__1, &u1[mini *
1755 u1_dim1 + 1], &c__1);
1759 dswap_(&i__2, &u2[i__ * u2_dim1 + 1], &c__1, &u2[mini *
1760 u2_dim1 + 1], &c__1);
1763 dswap_(q, &v1t[i__ + v1t_dim1], ldv1t, &v1t[mini +
1768 dswap_(&i__2, &v2t[i__ + v2t_dim1], ldv2t, &v2t[mini +
1773 dswap_(p, &u1[i__ + u1_dim1], ldu1, &u1[mini + u1_dim1],
1778 dswap_(&i__2, &u2[i__ + u2_dim1], ldu2, &u2[mini +
1782 dswap_(q, &v1t[i__ * v1t_dim1 + 1], &c__1, &v1t[mini *
1783 v1t_dim1 + 1], &c__1);
1787 dswap_(&i__2, &v2t[i__ * v2t_dim1 + 1], &c__1, &v2t[mini *
1788 v2t_dim1 + 1], &c__1);