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 doublecomplex c_b1 = {-1.,0.};
516 static doublereal c_b11 = -.125;
517 static integer c__1 = 1;
519 /* > \brief \b ZBBCSD */
521 /* =========== DOCUMENTATION =========== */
523 /* Online html documentation available at */
524 /* http://www.netlib.org/lapack/explore-html/ */
527 /* > Download ZBBCSD + dependencies */
528 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/zbbcsd.
531 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/zbbcsd.
534 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/zbbcsd.
542 /* SUBROUTINE ZBBCSD( 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, RWORK, LRWORK, INFO ) */
547 /* CHARACTER JOBU1, JOBU2, JOBV1T, JOBV2T, TRANS */
548 /* INTEGER INFO, LDU1, LDU2, LDV1T, LDV2T, LRWORK, M, P, Q */
549 /* DOUBLE PRECISION B11D( * ), B11E( * ), B12D( * ), B12E( * ), */
550 /* $ B21D( * ), B21E( * ), B22D( * ), B22E( * ), */
551 /* $ PHI( * ), THETA( * ), RWORK( * ) */
552 /* COMPLEX*16 U1( LDU1, * ), U2( LDU2, * ), V1T( LDV1T, * ), */
553 /* $ V2T( LDV2T, * ) */
556 /* > \par Purpose: */
561 /* > ZBBCSD computes the CS decomposition of a unitary 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 | ]**H */
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 ZUNCSD 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 unitary 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 unitary 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 COMPLEX*16 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 COMPLEX*16 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 COMPLEX*16 array, dimension (LDV1T,Q) */
697 /* > On entry, a Q-by-Q matrix. On exit, V1T is premultiplied */
698 /* > by the conjugate 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 COMPLEX*16 array, dimension (LDV2T,M-Q) */
711 /* > On entry, an (M-Q)-by-(M-Q) matrix. On exit, V2T is */
712 /* > premultiplied by the conjugate 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 ZBBCSD converges, B11D contains the cosines of THETA(1), */
727 /* > ..., THETA(Q). If ZBBCSD 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 ZBBCSD converges, B11E contains zeros. If ZBBCSD 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 ZBBCSD converges, B12D contains the negative sines of */
744 /* > THETA(1), ..., THETA(Q). If ZBBCSD 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 ZBBCSD converges, B12E contains zeros. If ZBBCSD 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 ZBBCSD converges, B21D contains the negative sines of */
761 /* > THETA(1), ..., THETA(Q). If ZBBCSD 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 ZBBCSD converges, B21E contains zeros. If ZBBCSD 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 ZBBCSD converges, B22D contains the negative sines of */
778 /* > THETA(1), ..., THETA(Q). If ZBBCSD 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 ZBBCSD converges, B22E contains zeros. If ZBBCSD fails */
787 /* > to converge, then B22E contains the subdiagonal of the */
788 /* > partially reduced bottom-right block. */
791 /* > \param[out] RWORK */
793 /* > RWORK is DOUBLE PRECISION array, dimension (MAX(1,LRWORK)) */
794 /* > On exit, if INFO = 0, RWORK(1) returns the optimal LRWORK. */
797 /* > \param[in] LRWORK */
799 /* > LRWORK is INTEGER */
800 /* > The dimension of the array RWORK. LRWORK >= MAX(1,8*Q). */
802 /* > If LRWORK = -1, then a workspace query is assumed; the */
803 /* > routine only calculates the optimal size of the RWORK array, */
804 /* > returns this value as the first entry of the work array, and */
805 /* > no error message related to LRWORK 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 ZBBCSD 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 complex16OTHERcomputational */
846 /* ===================================================================== */
847 /* Subroutine */ int zbbcsd_(char *jobu1, char *jobu2, char *jobv1t, char *
848 jobv2t, char *trans, integer *m, integer *p, integer *q, doublereal *
849 theta, doublereal *phi, doublecomplex *u1, integer *ldu1,
850 doublecomplex *u2, integer *ldu2, doublecomplex *v1t, integer *ldv1t,
851 doublecomplex *v2t, integer *ldv2t, doublereal *b11d, doublereal *
852 b11e, doublereal *b12d, doublereal *b12e, doublereal *b21d,
853 doublereal *b21e, doublereal *b22d, doublereal *b22e, doublereal *
854 rwork, integer *lrwork, integer *info)
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 iu1cs, iu2cs, iu1sn, iu2sn, i__, j;
871 extern logical lsame_(char *, char *);
872 extern /* Subroutine */ int zscal_(integer *, doublecomplex *,
873 doublecomplex *, integer *);
876 extern /* Subroutine */ int zlasr_(char *, char *, char *, integer *,
877 integer *, doublereal *, doublereal *, doublecomplex *, integer *), zswap_(integer *, doublecomplex *,
878 integer *, doublecomplex *, integer *);
879 doublereal x1, x2, y1, y2;
880 integer lrworkmin, iv1tcs, iv2tcs;
881 logical wantu1, wantu2;
882 integer lrworkopt, iv1tsn, iv2tsn;
883 extern doublereal dlamch_(char *);
884 doublereal mu, nu, sigma11, sigma21;
885 extern /* Subroutine */ int xerbla_(char *, integer *, ftnlen);
886 doublereal thresh, tolmul;
887 extern /* Subroutine */ int mecago_();
890 logical wantv1t, wantv2t;
891 doublereal b12bulge, b21bulge, b22bulge, eps, tol;
892 extern /* Subroutine */ int dlartgp_(doublereal *, doublereal *,
893 doublereal *, doublereal *, doublereal *), dlartgs_(doublereal *,
894 doublereal *, doublereal *, doublereal *, doublereal *);
897 /* -- LAPACK computational routine (version 3.7.1) -- */
898 /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
899 /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
903 /* =================================================================== */
907 /* Test input arguments */
909 /* Parameter adjustments */
913 u1_offset = 1 + u1_dim1 * 1;
916 u2_offset = 1 + u2_dim1 * 1;
919 v1t_offset = 1 + v1t_dim1 * 1;
922 v2t_offset = 1 + v2t_dim1 * 1;
936 lquery = *lrwork == -1;
937 wantu1 = lsame_(jobu1, "Y");
938 wantu2 = lsame_(jobu2, "Y");
939 wantv1t = lsame_(jobv1t, "Y");
940 wantv2t = lsame_(jobv2t, "Y");
941 colmajor = ! lsame_(trans, "T");
945 } else if (*p < 0 || *p > *m) {
947 } else if (*q < 0 || *q > *m) {
949 } else if (*q > *p || *q > *m - *p || *q > *m - *q) {
951 } else if (wantu1 && *ldu1 < *p) {
953 } else if (wantu2 && *ldu2 < *m - *p) {
955 } else if (wantv1t && *ldv1t < *q) {
957 } else if (wantv2t && *ldv2t < *m - *q) {
961 /* Quick return if Q = 0 */
963 if (*info == 0 && *q == 0) {
965 rwork[1] = (doublereal) lrworkmin;
969 /* Compute workspace */
977 iv1tsn = iv1tcs + *q;
978 iv2tcs = iv1tsn + *q;
979 iv2tsn = iv2tcs + *q;
980 lrworkopt = iv2tsn + *q - 1;
981 lrworkmin = lrworkopt;
982 rwork[1] = (doublereal) lrworkopt;
983 if (*lrwork < lrworkmin && ! lquery) {
990 xerbla_("ZBBCSD", &i__1, (ftnlen)6);
996 /* Get machine constants */
998 eps = dlamch_("Epsilon");
999 unfl = dlamch_("Safe minimum");
1002 d__3 = 100., d__4 = pow_dd(&eps, &c_b11);
1003 d__1 = 10., d__2 = f2cmin(d__3,d__4);
1004 tolmul = f2cmax(d__1,d__2);
1007 d__1 = tol, d__2 = *q * 6 * *q * unfl;
1008 thresh = f2cmax(d__1,d__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.57079632679489662 - thresh) {
1017 theta[i__] = 1.57079632679489662;
1021 for (i__ = 1; i__ <= i__1; ++i__) {
1022 if (phi[i__] < thresh) {
1024 } else if (phi[i__] > 1.57079632679489662 - thresh) {
1025 phi[i__] = 1.57079632679489662;
1029 /* Initial deflation */
1033 if (phi[imax - 1] != 0.) {
1040 while(phi[imin - 1] != 0.) {
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.) {
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.57079632679489662 - 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 dlas2_(&b11d[imax - 1], &b11e[imax - 1], &b11d[imax], &sigma11, &
1126 dlas2_(&b21d[imax - 1], &b21e[imax - 1], &b21d[imax], &sigma21, &
1129 if (sigma11 <= sigma21) {
1131 /* Computing 2nd power */
1133 nu = sqrt(1. - d__1 * d__1);
1140 /* Computing 2nd power */
1142 mu = sqrt(1.f - d__1 * d__1);
1150 /* Rotate to produce bulges in B11 and B21 */
1153 dlartgs_(&b11d[imin], &b11e[imin], &mu, &rwork[iv1tcs + imin - 1],
1154 &rwork[iv1tsn + imin - 1]);
1156 dlartgs_(&b21d[imin], &b21e[imin], &nu, &rwork[iv1tcs + imin - 1],
1157 &rwork[iv1tsn + imin - 1]);
1160 temp = rwork[iv1tcs + imin - 1] * b11d[imin] + rwork[iv1tsn + imin -
1162 b11e[imin] = rwork[iv1tcs + imin - 1] * b11e[imin] - rwork[iv1tsn +
1163 imin - 1] * b11d[imin];
1165 b11bulge = rwork[iv1tsn + imin - 1] * b11d[imin + 1];
1166 b11d[imin + 1] = rwork[iv1tcs + imin - 1] * b11d[imin + 1];
1167 temp = rwork[iv1tcs + imin - 1] * b21d[imin] + rwork[iv1tsn + imin -
1169 b21e[imin] = rwork[iv1tcs + imin - 1] * b21e[imin] - rwork[iv1tsn +
1170 imin - 1] * b21d[imin];
1172 b21bulge = rwork[iv1tsn + imin - 1] * b21d[imin + 1];
1173 b21d[imin + 1] = rwork[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(d__1 * d__1 + d__2 * d__2), sqrt(d__3 * d__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 (d__1 * d__1 + d__2 * d__2 > d__3 * d__3) {
1197 dlartgp_(&b11bulge, &b11d[imin], &rwork[iu1sn + imin - 1], &rwork[
1198 iu1cs + imin - 1], &r__);
1199 } else if (mu <= nu) {
1200 dlartgs_(&b11e[imin], &b11d[imin + 1], &mu, &rwork[iu1cs + imin -
1201 1], &rwork[iu1sn + imin - 1]);
1203 dlartgs_(&b12d[imin], &b12e[imin], &nu, &rwork[iu1cs + imin - 1],
1204 &rwork[iu1sn + imin - 1]);
1206 /* Computing 2nd power */
1208 /* Computing 2nd power */
1210 /* Computing 2nd power */
1212 if (d__1 * d__1 + d__2 * d__2 > d__3 * d__3) {
1213 dlartgp_(&b21bulge, &b21d[imin], &rwork[iu2sn + imin - 1], &rwork[
1214 iu2cs + imin - 1], &r__);
1215 } else if (nu < mu) {
1216 dlartgs_(&b21e[imin], &b21d[imin + 1], &nu, &rwork[iu2cs + imin -
1217 1], &rwork[iu2sn + imin - 1]);
1219 dlartgs_(&b22d[imin], &b22e[imin], &mu, &rwork[iu2cs + imin - 1],
1220 &rwork[iu2sn + imin - 1]);
1222 rwork[iu2cs + imin - 1] = -rwork[iu2cs + imin - 1];
1223 rwork[iu2sn + imin - 1] = -rwork[iu2sn + imin - 1];
1225 temp = rwork[iu1cs + imin - 1] * b11e[imin] + rwork[iu1sn + imin - 1]
1227 b11d[imin + 1] = rwork[iu1cs + imin - 1] * b11d[imin + 1] - rwork[
1228 iu1sn + imin - 1] * b11e[imin];
1230 if (imax > imin + 1) {
1231 b11bulge = rwork[iu1sn + imin - 1] * b11e[imin + 1];
1232 b11e[imin + 1] = rwork[iu1cs + imin - 1] * b11e[imin + 1];
1234 temp = rwork[iu1cs + imin - 1] * b12d[imin] + rwork[iu1sn + imin - 1]
1236 b12e[imin] = rwork[iu1cs + imin - 1] * b12e[imin] - rwork[iu1sn +
1237 imin - 1] * b12d[imin];
1239 b12bulge = rwork[iu1sn + imin - 1] * b12d[imin + 1];
1240 b12d[imin + 1] = rwork[iu1cs + imin - 1] * b12d[imin + 1];
1241 temp = rwork[iu2cs + imin - 1] * b21e[imin] + rwork[iu2sn + imin - 1]
1243 b21d[imin + 1] = rwork[iu2cs + imin - 1] * b21d[imin + 1] - rwork[
1244 iu2sn + imin - 1] * b21e[imin];
1246 if (imax > imin + 1) {
1247 b21bulge = rwork[iu2sn + imin - 1] * b21e[imin + 1];
1248 b21e[imin + 1] = rwork[iu2cs + imin - 1] * b21e[imin + 1];
1250 temp = rwork[iu2cs + imin - 1] * b22d[imin] + rwork[iu2sn + imin - 1]
1252 b22e[imin] = rwork[iu2cs + imin - 1] * b22e[imin] - rwork[iu2sn +
1253 imin - 1] * b22d[imin];
1255 b22bulge = rwork[iu2sn + imin - 1] * b22d[imin + 1];
1256 b22d[imin + 1] = rwork[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(d__1 * d__1 + d__2 * d__2), sqrt(d__3 *
1285 d__3 + d__4 * d__4));
1287 /* Determine if there are bulges to chase or if a new direct */
1288 /* summand has been reached */
1290 /* Computing 2nd power */
1291 d__1 = b11e[i__ - 1];
1292 /* Computing 2nd power */
1294 /* Computing 2nd power */
1296 restart11 = d__1 * d__1 + d__2 * d__2 <= d__3 * d__3;
1297 /* Computing 2nd power */
1298 d__1 = b21e[i__ - 1];
1299 /* Computing 2nd power */
1301 /* Computing 2nd power */
1303 restart21 = d__1 * d__1 + d__2 * d__2 <= d__3 * d__3;
1304 /* Computing 2nd power */
1305 d__1 = b12d[i__ - 1];
1306 /* Computing 2nd power */
1308 /* Computing 2nd power */
1310 restart12 = d__1 * d__1 + d__2 * d__2 <= d__3 * d__3;
1311 /* Computing 2nd power */
1312 d__1 = b22d[i__ - 1];
1313 /* Computing 2nd power */
1315 /* Computing 2nd power */
1317 restart22 = d__1 * d__1 + d__2 * d__2 <= d__3 * d__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 dlartgp_(&x2, &x1, &rwork[iv1tsn + i__ - 1], &rwork[iv1tcs +
1326 } else if (! restart11 && restart21) {
1327 dlartgp_(&b11bulge, &b11e[i__ - 1], &rwork[iv1tsn + i__ - 1],
1328 &rwork[iv1tcs + i__ - 1], &r__);
1329 } else if (restart11 && ! restart21) {
1330 dlartgp_(&b21bulge, &b21e[i__ - 1], &rwork[iv1tsn + i__ - 1],
1331 &rwork[iv1tcs + i__ - 1], &r__);
1332 } else if (mu <= nu) {
1333 dlartgs_(&b11d[i__], &b11e[i__], &mu, &rwork[iv1tcs + i__ - 1]
1334 , &rwork[iv1tsn + i__ - 1]);
1336 dlartgs_(&b21d[i__], &b21e[i__], &nu, &rwork[iv1tcs + i__ - 1]
1337 , &rwork[iv1tsn + i__ - 1]);
1339 rwork[iv1tcs + i__ - 1] = -rwork[iv1tcs + i__ - 1];
1340 rwork[iv1tsn + i__ - 1] = -rwork[iv1tsn + i__ - 1];
1341 if (! restart12 && ! restart22) {
1342 dlartgp_(&y2, &y1, &rwork[iv2tsn + i__ - 2], &rwork[iv2tcs +
1344 } else if (! restart12 && restart22) {
1345 dlartgp_(&b12bulge, &b12d[i__ - 1], &rwork[iv2tsn + i__ - 2],
1346 &rwork[iv2tcs + i__ - 2], &r__);
1347 } else if (restart12 && ! restart22) {
1348 dlartgp_(&b22bulge, &b22d[i__ - 1], &rwork[iv2tsn + i__ - 2],
1349 &rwork[iv2tcs + i__ - 2], &r__);
1350 } else if (nu < mu) {
1351 dlartgs_(&b12e[i__ - 1], &b12d[i__], &nu, &rwork[iv2tcs + i__
1352 - 2], &rwork[iv2tsn + i__ - 2]);
1354 dlartgs_(&b22e[i__ - 1], &b22d[i__], &mu, &rwork[iv2tcs + i__
1355 - 2], &rwork[iv2tsn + i__ - 2]);
1358 temp = rwork[iv1tcs + i__ - 1] * b11d[i__] + rwork[iv1tsn + i__ -
1360 b11e[i__] = rwork[iv1tcs + i__ - 1] * b11e[i__] - rwork[iv1tsn +
1361 i__ - 1] * b11d[i__];
1363 b11bulge = rwork[iv1tsn + i__ - 1] * b11d[i__ + 1];
1364 b11d[i__ + 1] = rwork[iv1tcs + i__ - 1] * b11d[i__ + 1];
1365 temp = rwork[iv1tcs + i__ - 1] * b21d[i__] + rwork[iv1tsn + i__ -
1367 b21e[i__] = rwork[iv1tcs + i__ - 1] * b21e[i__] - rwork[iv1tsn +
1368 i__ - 1] * b21d[i__];
1370 b21bulge = rwork[iv1tsn + i__ - 1] * b21d[i__ + 1];
1371 b21d[i__ + 1] = rwork[iv1tcs + i__ - 1] * b21d[i__ + 1];
1372 temp = rwork[iv2tcs + i__ - 2] * b12e[i__ - 1] + rwork[iv2tsn +
1373 i__ - 2] * b12d[i__];
1374 b12d[i__] = rwork[iv2tcs + i__ - 2] * b12d[i__] - rwork[iv2tsn +
1375 i__ - 2] * b12e[i__ - 1];
1376 b12e[i__ - 1] = temp;
1377 b12bulge = rwork[iv2tsn + i__ - 2] * b12e[i__];
1378 b12e[i__] = rwork[iv2tcs + i__ - 2] * b12e[i__];
1379 temp = rwork[iv2tcs + i__ - 2] * b22e[i__ - 1] + rwork[iv2tsn +
1380 i__ - 2] * b22d[i__];
1381 b22d[i__] = rwork[iv2tcs + i__ - 2] * b22d[i__] - rwork[iv2tsn +
1382 i__ - 2] * b22e[i__ - 1];
1383 b22e[i__ - 1] = temp;
1384 b22bulge = rwork[iv2tsn + i__ - 2] * b22e[i__];
1385 b22e[i__] = rwork[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(d__1 * d__1 + d__2 * d__2), sqrt(d__3 *
1405 d__3 + d__4 * d__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 = d__1 * d__1 + d__2 * d__2 <= d__3 * d__3;
1417 /* Computing 2nd power */
1418 d__1 = b12e[i__ - 1];
1419 /* Computing 2nd power */
1421 /* Computing 2nd power */
1423 restart12 = d__1 * d__1 + d__2 * d__2 <= d__3 * d__3;
1424 /* Computing 2nd power */
1426 /* Computing 2nd power */
1428 /* Computing 2nd power */
1430 restart21 = d__1 * d__1 + d__2 * d__2 <= d__3 * d__3;
1431 /* Computing 2nd power */
1432 d__1 = b22e[i__ - 1];
1433 /* Computing 2nd power */
1435 /* Computing 2nd power */
1437 restart22 = d__1 * d__1 + d__2 * d__2 <= d__3 * d__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 dlartgp_(&x2, &x1, &rwork[iu1sn + i__ - 1], &rwork[iu1cs +
1446 } else if (! restart11 && restart12) {
1447 dlartgp_(&b11bulge, &b11d[i__], &rwork[iu1sn + i__ - 1], &
1448 rwork[iu1cs + i__ - 1], &r__);
1449 } else if (restart11 && ! restart12) {
1450 dlartgp_(&b12bulge, &b12e[i__ - 1], &rwork[iu1sn + i__ - 1], &
1451 rwork[iu1cs + i__ - 1], &r__);
1452 } else if (mu <= nu) {
1453 dlartgs_(&b11e[i__], &b11d[i__ + 1], &mu, &rwork[iu1cs + i__
1454 - 1], &rwork[iu1sn + i__ - 1]);
1456 dlartgs_(&b12d[i__], &b12e[i__], &nu, &rwork[iu1cs + i__ - 1],
1457 &rwork[iu1sn + i__ - 1]);
1459 if (! restart21 && ! restart22) {
1460 dlartgp_(&y2, &y1, &rwork[iu2sn + i__ - 1], &rwork[iu2cs +
1462 } else if (! restart21 && restart22) {
1463 dlartgp_(&b21bulge, &b21d[i__], &rwork[iu2sn + i__ - 1], &
1464 rwork[iu2cs + i__ - 1], &r__);
1465 } else if (restart21 && ! restart22) {
1466 dlartgp_(&b22bulge, &b22e[i__ - 1], &rwork[iu2sn + i__ - 1], &
1467 rwork[iu2cs + i__ - 1], &r__);
1468 } else if (nu < mu) {
1469 dlartgs_(&b21e[i__], &b21e[i__ + 1], &nu, &rwork[iu2cs + i__
1470 - 1], &rwork[iu2sn + i__ - 1]);
1472 dlartgs_(&b22d[i__], &b22e[i__], &mu, &rwork[iu2cs + i__ - 1],
1473 &rwork[iu2sn + i__ - 1]);
1475 rwork[iu2cs + i__ - 1] = -rwork[iu2cs + i__ - 1];
1476 rwork[iu2sn + i__ - 1] = -rwork[iu2sn + i__ - 1];
1478 temp = rwork[iu1cs + i__ - 1] * b11e[i__] + rwork[iu1sn + i__ - 1]
1480 b11d[i__ + 1] = rwork[iu1cs + i__ - 1] * b11d[i__ + 1] - rwork[
1481 iu1sn + i__ - 1] * b11e[i__];
1483 if (i__ < imax - 1) {
1484 b11bulge = rwork[iu1sn + i__ - 1] * b11e[i__ + 1];
1485 b11e[i__ + 1] = rwork[iu1cs + i__ - 1] * b11e[i__ + 1];
1487 temp = rwork[iu2cs + i__ - 1] * b21e[i__] + rwork[iu2sn + i__ - 1]
1489 b21d[i__ + 1] = rwork[iu2cs + i__ - 1] * b21d[i__ + 1] - rwork[
1490 iu2sn + i__ - 1] * b21e[i__];
1492 if (i__ < imax - 1) {
1493 b21bulge = rwork[iu2sn + i__ - 1] * b21e[i__ + 1];
1494 b21e[i__ + 1] = rwork[iu2cs + i__ - 1] * b21e[i__ + 1];
1496 temp = rwork[iu1cs + i__ - 1] * b12d[i__] + rwork[iu1sn + i__ - 1]
1498 b12e[i__] = rwork[iu1cs + i__ - 1] * b12e[i__] - rwork[iu1sn +
1499 i__ - 1] * b12d[i__];
1501 b12bulge = rwork[iu1sn + i__ - 1] * b12d[i__ + 1];
1502 b12d[i__ + 1] = rwork[iu1cs + i__ - 1] * b12d[i__ + 1];
1503 temp = rwork[iu2cs + i__ - 1] * b22d[i__] + rwork[iu2sn + i__ - 1]
1505 b22e[i__] = rwork[iu2cs + i__ - 1] * b22e[i__] - rwork[iu2sn +
1506 i__ - 1] * b22d[i__];
1508 b22bulge = rwork[iu2sn + i__ - 1] * b22d[i__ + 1];
1509 b22d[i__ + 1] = rwork[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(d__1 * d__1 + d__2 * d__2));
1528 /* Chase bulges from B12(IMAX-1,IMAX) and B22(IMAX-1,IMAX) */
1530 /* Computing 2nd power */
1531 d__1 = b12d[imax - 1];
1532 /* Computing 2nd power */
1534 /* Computing 2nd power */
1536 restart12 = d__1 * d__1 + d__2 * d__2 <= d__3 * d__3;
1537 /* Computing 2nd power */
1538 d__1 = b22d[imax - 1];
1539 /* Computing 2nd power */
1541 /* Computing 2nd power */
1543 restart22 = d__1 * d__1 + d__2 * d__2 <= d__3 * d__3;
1545 if (! restart12 && ! restart22) {
1546 dlartgp_(&y2, &y1, &rwork[iv2tsn + imax - 2], &rwork[iv2tcs +
1548 } else if (! restart12 && restart22) {
1549 dlartgp_(&b12bulge, &b12d[imax - 1], &rwork[iv2tsn + imax - 2], &
1550 rwork[iv2tcs + imax - 2], &r__);
1551 } else if (restart12 && ! restart22) {
1552 dlartgp_(&b22bulge, &b22d[imax - 1], &rwork[iv2tsn + imax - 2], &
1553 rwork[iv2tcs + imax - 2], &r__);
1554 } else if (nu < mu) {
1555 dlartgs_(&b12e[imax - 1], &b12d[imax], &nu, &rwork[iv2tcs + imax
1556 - 2], &rwork[iv2tsn + imax - 2]);
1558 dlartgs_(&b22e[imax - 1], &b22d[imax], &mu, &rwork[iv2tcs + imax
1559 - 2], &rwork[iv2tsn + imax - 2]);
1562 temp = rwork[iv2tcs + imax - 2] * b12e[imax - 1] + rwork[iv2tsn +
1563 imax - 2] * b12d[imax];
1564 b12d[imax] = rwork[iv2tcs + imax - 2] * b12d[imax] - rwork[iv2tsn +
1565 imax - 2] * b12e[imax - 1];
1566 b12e[imax - 1] = temp;
1567 temp = rwork[iv2tcs + imax - 2] * b22e[imax - 1] + rwork[iv2tsn +
1568 imax - 2] * b22d[imax];
1569 b22d[imax] = rwork[iv2tcs + imax - 2] * b22d[imax] - rwork[iv2tsn +
1570 imax - 2] * b22e[imax - 1];
1571 b22e[imax - 1] = temp;
1573 /* Update singular vectors */
1577 i__1 = imax - imin + 1;
1578 zlasr_("R", "V", "F", p, &i__1, &rwork[iu1cs + imin - 1], &
1579 rwork[iu1sn + imin - 1], &u1[imin * u1_dim1 + 1],
1582 i__1 = imax - imin + 1;
1583 zlasr_("L", "V", "F", &i__1, p, &rwork[iu1cs + imin - 1], &
1584 rwork[iu1sn + imin - 1], &u1[imin + u1_dim1], ldu1);
1590 i__2 = imax - imin + 1;
1591 zlasr_("R", "V", "F", &i__1, &i__2, &rwork[iu2cs + imin - 1],
1592 &rwork[iu2sn + imin - 1], &u2[imin * u2_dim1 + 1],
1595 i__1 = imax - imin + 1;
1597 zlasr_("L", "V", "F", &i__1, &i__2, &rwork[iu2cs + imin - 1],
1598 &rwork[iu2sn + imin - 1], &u2[imin + u2_dim1], ldu2);
1603 i__1 = imax - imin + 1;
1604 zlasr_("L", "V", "F", &i__1, q, &rwork[iv1tcs + imin - 1], &
1605 rwork[iv1tsn + imin - 1], &v1t[imin + v1t_dim1],
1608 i__1 = imax - imin + 1;
1609 zlasr_("R", "V", "F", q, &i__1, &rwork[iv1tcs + imin - 1], &
1610 rwork[iv1tsn + imin - 1], &v1t[imin * v1t_dim1 + 1],
1616 i__1 = imax - imin + 1;
1618 zlasr_("L", "V", "F", &i__1, &i__2, &rwork[iv2tcs + imin - 1],
1619 &rwork[iv2tsn + imin - 1], &v2t[imin + v2t_dim1],
1623 i__2 = imax - imin + 1;
1624 zlasr_("R", "V", "F", &i__1, &i__2, &rwork[iv2tcs + imin - 1],
1625 &rwork[iv2tsn + imin - 1], &v2t[imin * v2t_dim1 + 1],
1630 /* Fix signs on B11(IMAX-1,IMAX) and B21(IMAX-1,IMAX) */
1632 if (b11e[imax - 1] + b21e[imax - 1] > 0.) {
1633 b11d[imax] = -b11d[imax];
1634 b21d[imax] = -b21d[imax];
1637 zscal_(q, &c_b1, &v1t[imax + v1t_dim1], ldv1t);
1639 zscal_(q, &c_b1, &v1t[imax * v1t_dim1 + 1], &c__1);
1644 /* Compute THETA(IMAX) */
1646 x1 = cos(phi[imax - 1]) * b11d[imax] + sin(phi[imax - 1]) * b12e[imax
1648 y1 = cos(phi[imax - 1]) * b21d[imax] + sin(phi[imax - 1]) * b22e[imax
1651 theta[imax] = atan2((abs(y1)), (abs(x1)));
1653 /* Fix signs on B11(IMAX,IMAX), B12(IMAX,IMAX-1), B21(IMAX,IMAX), */
1654 /* and B22(IMAX,IMAX-1) */
1656 if (b11d[imax] + b12e[imax - 1] < 0.) {
1657 b12d[imax] = -b12d[imax];
1660 zscal_(p, &c_b1, &u1[imax * u1_dim1 + 1], &c__1);
1662 zscal_(p, &c_b1, &u1[imax + u1_dim1], ldu1);
1666 if (b21d[imax] + b22e[imax - 1] > 0.) {
1667 b22d[imax] = -b22d[imax];
1671 zscal_(&i__1, &c_b1, &u2[imax * u2_dim1 + 1], &c__1);
1674 zscal_(&i__1, &c_b1, &u2[imax + u2_dim1], ldu2);
1679 /* Fix signs on B12(IMAX,IMAX) and B22(IMAX,IMAX) */
1681 if (b12d[imax] + b22d[imax] < 0.) {
1685 zscal_(&i__1, &c_b1, &v2t[imax + v2t_dim1], ldv2t);
1688 zscal_(&i__1, &c_b1, &v2t[imax * v2t_dim1 + 1], &c__1);
1693 /* Test for negligible sines or cosines */
1696 for (i__ = imin; i__ <= i__1; ++i__) {
1697 if (theta[i__] < thresh) {
1699 } else if (theta[i__] > 1.57079632679489662 - thresh) {
1700 theta[i__] = 1.57079632679489662;
1704 for (i__ = imin; i__ <= i__1; ++i__) {
1705 if (phi[i__] < thresh) {
1707 } else if (phi[i__] > 1.57079632679489662 - thresh) {
1708 phi[i__] = 1.57079632679489662;
1715 while(phi[imax - 1] == 0.) {
1722 if (imin > imax - 1) {
1726 while(phi[imin - 1] != 0.) {
1734 /* Repeat main iteration loop */
1738 /* Postprocessing: order THETA from least to greatest */
1741 for (i__ = 1; i__ <= i__1; ++i__) {
1744 thetamin = theta[i__];
1746 for (j = i__ + 1; j <= i__2; ++j) {
1747 if (theta[j] < thetamin) {
1749 thetamin = theta[j];
1754 theta[mini] = theta[i__];
1755 theta[i__] = thetamin;
1758 zswap_(p, &u1[i__ * u1_dim1 + 1], &c__1, &u1[mini *
1759 u1_dim1 + 1], &c__1);
1763 zswap_(&i__2, &u2[i__ * u2_dim1 + 1], &c__1, &u2[mini *
1764 u2_dim1 + 1], &c__1);
1767 zswap_(q, &v1t[i__ + v1t_dim1], ldv1t, &v1t[mini +
1772 zswap_(&i__2, &v2t[i__ + v2t_dim1], ldv2t, &v2t[mini +
1777 zswap_(p, &u1[i__ + u1_dim1], ldu1, &u1[mini + u1_dim1],
1782 zswap_(&i__2, &u2[i__ + u2_dim1], ldu2, &u2[mini +
1786 zswap_(q, &v1t[i__ * v1t_dim1 + 1], &c__1, &v1t[mini *
1787 v1t_dim1 + 1], &c__1);
1791 zswap_(&i__2, &v2t[i__ * v2t_dim1 + 1], &c__1, &v2t[mini *
1792 v2t_dim1 + 1], &c__1);