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)
511 /* -- translated by f2c (version 20000121).
512 You must link the resulting object file with the libraries:
513 -lf2c -lm (in that order)
518 /* Table of constant values */
520 static complex c_b1 = {-1.f,0.f};
521 static doublereal c_b11 = -.125;
522 static integer c__1 = 1;
524 /* > \brief \b CBBCSD */
526 /* =========== DOCUMENTATION =========== */
528 /* Online html documentation available at */
529 /* http://www.netlib.org/lapack/explore-html/ */
532 /* > Download CBBCSD + dependencies */
533 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/cbbcsd.
536 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/cbbcsd.
539 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/cbbcsd.
547 /* SUBROUTINE CBBCSD( JOBU1, JOBU2, JOBV1T, JOBV2T, TRANS, M, P, Q, */
548 /* THETA, PHI, U1, LDU1, U2, LDU2, V1T, LDV1T, */
549 /* V2T, LDV2T, B11D, B11E, B12D, B12E, B21D, B21E, */
550 /* B22D, B22E, RWORK, LRWORK, INFO ) */
552 /* CHARACTER JOBU1, JOBU2, JOBV1T, JOBV2T, TRANS */
553 /* INTEGER INFO, LDU1, LDU2, LDV1T, LDV2T, LRWORK, M, P, Q */
554 /* REAL B11D( * ), B11E( * ), B12D( * ), B12E( * ), */
555 /* $ B21D( * ), B21E( * ), B22D( * ), B22E( * ), */
556 /* $ PHI( * ), THETA( * ), RWORK( * ) */
557 /* COMPLEX U1( LDU1, * ), U2( LDU2, * ), V1T( LDV1T, * ), */
558 /* $ V2T( LDV2T, * ) */
561 /* > \par Purpose: */
566 /* > CBBCSD computes the CS decomposition of a unitary matrix in */
567 /* > bidiagonal-block form, */
570 /* > [ B11 | B12 0 0 ] */
571 /* > [ 0 | 0 -I 0 ] */
572 /* > X = [----------------] */
573 /* > [ B21 | B22 0 0 ] */
574 /* > [ 0 | 0 0 I ] */
576 /* > [ C | -S 0 0 ] */
577 /* > [ U1 | ] [ 0 | 0 -I 0 ] [ V1 | ]**H */
578 /* > = [---------] [---------------] [---------] . */
579 /* > [ | U2 ] [ S | C 0 0 ] [ | V2 ] */
580 /* > [ 0 | 0 0 I ] */
582 /* > X is M-by-M, its top-left block is P-by-Q, and Q must be no larger */
583 /* > than P, M-P, or M-Q. (If Q is not the smallest index, then X must be */
584 /* > transposed and/or permuted. This can be done in constant time using */
585 /* > the TRANS and SIGNS options. See CUNCSD for details.) */
587 /* > The bidiagonal matrices B11, B12, B21, and B22 are represented */
588 /* > implicitly by angles THETA(1:Q) and PHI(1:Q-1). */
590 /* > The unitary matrices U1, U2, V1T, and V2T are input/output. */
591 /* > The input matrices are pre- or post-multiplied by the appropriate */
592 /* > singular vector matrices. */
598 /* > \param[in] JOBU1 */
600 /* > JOBU1 is CHARACTER */
601 /* > = 'Y': U1 is updated; */
602 /* > otherwise: U1 is not updated. */
605 /* > \param[in] JOBU2 */
607 /* > JOBU2 is CHARACTER */
608 /* > = 'Y': U2 is updated; */
609 /* > otherwise: U2 is not updated. */
612 /* > \param[in] JOBV1T */
614 /* > JOBV1T is CHARACTER */
615 /* > = 'Y': V1T is updated; */
616 /* > otherwise: V1T is not updated. */
619 /* > \param[in] JOBV2T */
621 /* > JOBV2T is CHARACTER */
622 /* > = 'Y': V2T is updated; */
623 /* > otherwise: V2T is not updated. */
626 /* > \param[in] TRANS */
628 /* > TRANS is CHARACTER */
629 /* > = 'T': X, U1, U2, V1T, and V2T are stored in row-major */
631 /* > otherwise: X, U1, U2, V1T, and V2T are stored in column- */
638 /* > The number of rows and columns in X, the unitary matrix in */
639 /* > bidiagonal-block form. */
645 /* > The number of rows in the top-left block of X. 0 <= P <= M. */
651 /* > The number of columns in the top-left block of X. */
652 /* > 0 <= Q <= MIN(P,M-P,M-Q). */
655 /* > \param[in,out] THETA */
657 /* > THETA is REAL array, dimension (Q) */
658 /* > On entry, the angles THETA(1),...,THETA(Q) that, along with */
659 /* > PHI(1), ...,PHI(Q-1), define the matrix in bidiagonal-block */
660 /* > form. On exit, the angles whose cosines and sines define the */
661 /* > diagonal blocks in the CS decomposition. */
664 /* > \param[in,out] PHI */
666 /* > PHI is REAL array, dimension (Q-1) */
667 /* > The angles PHI(1),...,PHI(Q-1) that, along with THETA(1),..., */
668 /* > THETA(Q), define the matrix in bidiagonal-block form. */
671 /* > \param[in,out] U1 */
673 /* > U1 is COMPLEX array, dimension (LDU1,P) */
674 /* > On entry, a P-by-P matrix. On exit, U1 is postmultiplied */
675 /* > by the left singular vector matrix common to [ B11 ; 0 ] and */
676 /* > [ B12 0 0 ; 0 -I 0 0 ]. */
679 /* > \param[in] LDU1 */
681 /* > LDU1 is INTEGER */
682 /* > The leading dimension of the array U1, LDU1 >= MAX(1,P). */
685 /* > \param[in,out] U2 */
687 /* > U2 is COMPLEX array, dimension (LDU2,M-P) */
688 /* > On entry, an (M-P)-by-(M-P) matrix. On exit, U2 is */
689 /* > postmultiplied by the left singular vector matrix common to */
690 /* > [ B21 ; 0 ] and [ B22 0 0 ; 0 0 I ]. */
693 /* > \param[in] LDU2 */
695 /* > LDU2 is INTEGER */
696 /* > The leading dimension of the array U2, LDU2 >= MAX(1,M-P). */
699 /* > \param[in,out] V1T */
701 /* > V1T is COMPLEX array, dimension (LDV1T,Q) */
702 /* > On entry, a Q-by-Q matrix. On exit, V1T is premultiplied */
703 /* > by the conjugate transpose of the right singular vector */
704 /* > matrix common to [ B11 ; 0 ] and [ B21 ; 0 ]. */
707 /* > \param[in] LDV1T */
709 /* > LDV1T is INTEGER */
710 /* > The leading dimension of the array V1T, LDV1T >= MAX(1,Q). */
713 /* > \param[in,out] V2T */
715 /* > V2T is COMPLEX array, dimension (LDV2T,M-Q) */
716 /* > On entry, an (M-Q)-by-(M-Q) matrix. On exit, V2T is */
717 /* > premultiplied by the conjugate transpose of the right */
718 /* > singular vector matrix common to [ B12 0 0 ; 0 -I 0 ] and */
719 /* > [ B22 0 0 ; 0 0 I ]. */
722 /* > \param[in] LDV2T */
724 /* > LDV2T is INTEGER */
725 /* > The leading dimension of the array V2T, LDV2T >= MAX(1,M-Q). */
728 /* > \param[out] B11D */
730 /* > B11D is REAL array, dimension (Q) */
731 /* > When CBBCSD converges, B11D contains the cosines of THETA(1), */
732 /* > ..., THETA(Q). If CBBCSD fails to converge, then B11D */
733 /* > contains the diagonal of the partially reduced top-left */
737 /* > \param[out] B11E */
739 /* > B11E is REAL array, dimension (Q-1) */
740 /* > When CBBCSD converges, B11E contains zeros. If CBBCSD fails */
741 /* > to converge, then B11E contains the superdiagonal of the */
742 /* > partially reduced top-left block. */
745 /* > \param[out] B12D */
747 /* > B12D is REAL array, dimension (Q) */
748 /* > When CBBCSD converges, B12D contains the negative sines of */
749 /* > THETA(1), ..., THETA(Q). If CBBCSD fails to converge, then */
750 /* > B12D contains the diagonal of the partially reduced top-right */
754 /* > \param[out] B12E */
756 /* > B12E is REAL array, dimension (Q-1) */
757 /* > When CBBCSD converges, B12E contains zeros. If CBBCSD fails */
758 /* > to converge, then B12E contains the subdiagonal of the */
759 /* > partially reduced top-right block. */
762 /* > \param[out] B21D */
764 /* > B21D is REAL array, dimension (Q) */
765 /* > When CBBCSD converges, B21D contains the negative sines of */
766 /* > THETA(1), ..., THETA(Q). If CBBCSD fails to converge, then */
767 /* > B21D contains the diagonal of the partially reduced bottom-left */
771 /* > \param[out] B21E */
773 /* > B21E is REAL array, dimension (Q-1) */
774 /* > When CBBCSD converges, B21E contains zeros. If CBBCSD fails */
775 /* > to converge, then B21E contains the subdiagonal of the */
776 /* > partially reduced bottom-left block. */
779 /* > \param[out] B22D */
781 /* > B22D is REAL array, dimension (Q) */
782 /* > When CBBCSD converges, B22D contains the negative sines of */
783 /* > THETA(1), ..., THETA(Q). If CBBCSD fails to converge, then */
784 /* > B22D contains the diagonal of the partially reduced bottom-right */
788 /* > \param[out] B22E */
790 /* > B22E is REAL array, dimension (Q-1) */
791 /* > When CBBCSD converges, B22E contains zeros. If CBBCSD fails */
792 /* > to converge, then B22E contains the subdiagonal of the */
793 /* > partially reduced bottom-right block. */
796 /* > \param[out] RWORK */
798 /* > RWORK is REAL array, dimension (MAX(1,LRWORK)) */
799 /* > On exit, if INFO = 0, RWORK(1) returns the optimal LRWORK. */
802 /* > \param[in] LRWORK */
804 /* > LRWORK is INTEGER */
805 /* > The dimension of the array RWORK. LRWORK >= MAX(1,8*Q). */
807 /* > If LRWORK = -1, then a workspace query is assumed; the */
808 /* > routine only calculates the optimal size of the RWORK array, */
809 /* > returns this value as the first entry of the work array, and */
810 /* > no error message related to LRWORK is issued by XERBLA. */
813 /* > \param[out] INFO */
815 /* > INFO is INTEGER */
816 /* > = 0: successful exit. */
817 /* > < 0: if INFO = -i, the i-th argument had an illegal value. */
818 /* > > 0: if CBBCSD did not converge, INFO specifies the number */
819 /* > of nonzero entries in PHI, and B11D, B11E, etc., */
820 /* > contain the partially reduced matrix. */
823 /* > \par Internal Parameters: */
824 /* ========================= */
827 /* > TOLMUL REAL, default = MAX(10,MIN(100,EPS**(-1/8))) */
828 /* > TOLMUL controls the convergence criterion of the QR loop. */
829 /* > Angles THETA(i), PHI(i) are rounded to 0 or PI/2 when they */
830 /* > are within TOLMUL*EPS of either bound. */
833 /* > \par References: */
834 /* ================ */
836 /* > [1] Brian D. Sutton. Computing the complete CS decomposition. Numer. */
837 /* > Algorithms, 50(1):33-65, 2009. */
842 /* > \author Univ. of Tennessee */
843 /* > \author Univ. of California Berkeley */
844 /* > \author Univ. of Colorado Denver */
845 /* > \author NAG Ltd. */
847 /* > \date June 2016 */
849 /* > \ingroup complexOTHERcomputational */
851 /* ===================================================================== */
852 /* Subroutine */ int cbbcsd_(char *jobu1, char *jobu2, char *jobv1t, char *
853 jobv2t, char *trans, integer *m, integer *p, integer *q, real *theta,
854 real *phi, complex *u1, integer *ldu1, complex *u2, integer *ldu2,
855 complex *v1t, integer *ldv1t, complex *v2t, integer *ldv2t, real *
856 b11d, real *b11e, real *b12d, real *b12e, real *b21d, real *b21e,
857 real *b22d, real *b22e, real *rwork, integer *lrwork, integer *info)
859 /* System generated locals */
860 integer u1_dim1, u1_offset, u2_dim1, u2_offset, v1t_dim1, v1t_offset,
861 v2t_dim1, v2t_offset, i__1, i__2;
862 real r__1, r__2, r__3, r__4;
865 /* Local variables */
866 integer imin, mini, imax, iter;
869 real thetamin, thetamax;
870 logical restart11, restart12, restart21, restart22;
871 integer iu1cs, iu2cs;
872 extern /* Subroutine */ int slas2_(real *, real *, real *, real *, real *)
874 integer iu1sn, iu2sn, i__, j;
876 extern /* Subroutine */ int cscal_(integer *, complex *, complex *,
878 extern logical lsame_(char *, char *);
879 extern /* Subroutine */ int clasr_(char *, char *, char *, integer *,
880 integer *, real *, real *, complex *, integer *), cswap_(integer *, complex *, integer *, complex *,
883 real dummy, x1, x2, y1, y2;
884 integer lrworkmin, iv1tcs, iv2tcs;
885 logical wantu1, wantu2;
886 integer lrworkopt, iv1tsn, iv2tsn;
887 real mu, nu, sigma11, sigma21;
888 extern real slamch_(char *);
889 extern /* Subroutine */ int xerbla_(char *, integer *, ftnlen);
891 extern /* Subroutine */ int mecago_();
894 logical wantv1t, wantv2t;
895 real b12bulge, b21bulge, b22bulge, eps, tol;
896 extern /* Subroutine */ int slartgp_(real *, real *, real *, real *, real
897 *), slartgs_(real *, real *, real *, real *, real *);
900 /* -- LAPACK computational routine (version 3.7.1) -- */
901 /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
902 /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
906 /* =================================================================== */
910 /* Test input arguments */
912 /* Parameter adjustments */
916 u1_offset = 1 + u1_dim1 * 1;
919 u2_offset = 1 + u2_dim1 * 1;
922 v1t_offset = 1 + v1t_dim1 * 1;
925 v2t_offset = 1 + v2t_dim1 * 1;
939 lquery = *lrwork == -1;
940 wantu1 = lsame_(jobu1, "Y");
941 wantu2 = lsame_(jobu2, "Y");
942 wantv1t = lsame_(jobv1t, "Y");
943 wantv2t = lsame_(jobv2t, "Y");
944 colmajor = ! lsame_(trans, "T");
948 } else if (*p < 0 || *p > *m) {
950 } else if (*q < 0 || *q > *m) {
952 } else if (*q > *p || *q > *m - *p || *q > *m - *q) {
954 } else if (wantu1 && *ldu1 < *p) {
956 } else if (wantu2 && *ldu2 < *m - *p) {
958 } else if (wantv1t && *ldv1t < *q) {
960 } else if (wantv2t && *ldv2t < *m - *q) {
964 /* Quick return if Q = 0 */
966 if (*info == 0 && *q == 0) {
968 rwork[1] = (real) lrworkmin;
972 /* Compute workspace */
980 iv1tsn = iv1tcs + *q;
981 iv2tcs = iv1tsn + *q;
982 iv2tsn = iv2tcs + *q;
983 lrworkopt = iv2tsn + *q - 1;
984 lrworkmin = lrworkopt;
985 rwork[1] = (real) lrworkopt;
986 if (*lrwork < lrworkmin && ! lquery) {
993 xerbla_("CBBCSD", &i__1, (ftnlen)6);
999 /* Get machine constants */
1001 eps = slamch_("Epsilon");
1002 unfl = slamch_("Safe minimum");
1005 d__1 = (doublereal) eps;
1006 r__3 = 100.f, r__4 = pow_dd(&d__1, &c_b11);
1007 r__1 = 10.f, r__2 = f2cmin(r__3,r__4);
1008 tolmul = f2cmax(r__1,r__2);
1011 r__1 = tol, r__2 = *q * 6 * *q * unfl;
1012 thresh = f2cmax(r__1,r__2);
1014 /* Test for negligible sines or cosines */
1017 for (i__ = 1; i__ <= i__1; ++i__) {
1018 if (theta[i__] < thresh) {
1020 } else if (theta[i__] > 1.57079632679489662f - thresh) {
1021 theta[i__] = 1.57079632679489662f;
1025 for (i__ = 1; i__ <= i__1; ++i__) {
1026 if (phi[i__] < thresh) {
1028 } else if (phi[i__] > 1.57079632679489662f - thresh) {
1029 phi[i__] = 1.57079632679489662f;
1033 /* Initial deflation */
1037 if (phi[imax - 1] != 0.f) {
1044 while(phi[imin - 1] != 0.f) {
1052 /* Initialize iteration counter */
1054 maxit = *q * 6 * *q;
1057 /* Begin main iteration loop */
1061 /* Compute the matrix entries */
1063 b11d[imin] = cos(theta[imin]);
1064 b21d[imin] = -sin(theta[imin]);
1066 for (i__ = imin; i__ <= i__1; ++i__) {
1067 b11e[i__] = -sin(theta[i__]) * sin(phi[i__]);
1068 b11d[i__ + 1] = cos(theta[i__ + 1]) * cos(phi[i__]);
1069 b12d[i__] = sin(theta[i__]) * cos(phi[i__]);
1070 b12e[i__] = cos(theta[i__ + 1]) * sin(phi[i__]);
1071 b21e[i__] = -cos(theta[i__]) * sin(phi[i__]);
1072 b21d[i__ + 1] = -sin(theta[i__ + 1]) * cos(phi[i__]);
1073 b22d[i__] = cos(theta[i__]) * cos(phi[i__]);
1074 b22e[i__] = -sin(theta[i__ + 1]) * sin(phi[i__]);
1076 b12d[imax] = sin(theta[imax]);
1077 b22d[imax] = cos(theta[imax]);
1079 /* Abort if not converging; otherwise, increment ITER */
1084 for (i__ = 1; i__ <= i__1; ++i__) {
1085 if (phi[i__] != 0.f) {
1092 iter = iter + imax - imin;
1094 /* Compute shifts */
1096 thetamax = theta[imin];
1097 thetamin = theta[imin];
1099 for (i__ = imin + 1; i__ <= i__1; ++i__) {
1100 if (theta[i__] > thetamax) {
1101 thetamax = theta[i__];
1103 if (theta[i__] < thetamin) {
1104 thetamin = theta[i__];
1108 if (thetamax > 1.57079632679489662f - thresh) {
1110 /* Zero on diagonals of B11 and B22; induce deflation with a */
1116 } else if (thetamin < thresh) {
1118 /* Zero on diagonals of B12 and B22; induce deflation with a */
1126 /* Compute shifts for B11 and B21 and use the lesser */
1128 slas2_(&b11d[imax - 1], &b11e[imax - 1], &b11d[imax], &sigma11, &
1130 slas2_(&b21d[imax - 1], &b21e[imax - 1], &b21d[imax], &sigma21, &
1133 if (sigma11 <= sigma21) {
1135 /* Computing 2nd power */
1137 nu = sqrt(1.f - r__1 * r__1);
1144 /* Computing 2nd power */
1146 mu = sqrt(1.f - r__1 * r__1);
1154 /* Rotate to produce bulges in B11 and B21 */
1157 slartgs_(&b11d[imin], &b11e[imin], &mu, &rwork[iv1tcs + imin - 1],
1158 &rwork[iv1tsn + imin - 1]);
1160 slartgs_(&b21d[imin], &b21e[imin], &nu, &rwork[iv1tcs + imin - 1],
1161 &rwork[iv1tsn + imin - 1]);
1164 temp = rwork[iv1tcs + imin - 1] * b11d[imin] + rwork[iv1tsn + imin -
1166 b11e[imin] = rwork[iv1tcs + imin - 1] * b11e[imin] - rwork[iv1tsn +
1167 imin - 1] * b11d[imin];
1169 b11bulge = rwork[iv1tsn + imin - 1] * b11d[imin + 1];
1170 b11d[imin + 1] = rwork[iv1tcs + imin - 1] * b11d[imin + 1];
1171 temp = rwork[iv1tcs + imin - 1] * b21d[imin] + rwork[iv1tsn + imin -
1173 b21e[imin] = rwork[iv1tcs + imin - 1] * b21e[imin] - rwork[iv1tsn +
1174 imin - 1] * b21d[imin];
1176 b21bulge = rwork[iv1tsn + imin - 1] * b21d[imin + 1];
1177 b21d[imin + 1] = rwork[iv1tcs + imin - 1] * b21d[imin + 1];
1179 /* Compute THETA(IMIN) */
1181 /* Computing 2nd power */
1183 /* Computing 2nd power */
1185 /* Computing 2nd power */
1187 /* Computing 2nd power */
1189 theta[imin] = atan2(sqrt(r__1 * r__1 + r__2 * r__2), sqrt(r__3 * r__3
1192 /* Chase the bulges in B11(IMIN+1,IMIN) and B21(IMIN+1,IMIN) */
1194 /* Computing 2nd power */
1196 /* Computing 2nd power */
1198 /* Computing 2nd power */
1200 if (r__1 * r__1 + r__2 * r__2 > r__3 * r__3) {
1201 slartgp_(&b11bulge, &b11d[imin], &rwork[iu1sn + imin - 1], &rwork[
1202 iu1cs + imin - 1], &r__);
1203 } else if (mu <= nu) {
1204 slartgs_(&b11e[imin], &b11d[imin + 1], &mu, &rwork[iu1cs + imin -
1205 1], &rwork[iu1sn + imin - 1]);
1207 slartgs_(&b12d[imin], &b12e[imin], &nu, &rwork[iu1cs + imin - 1],
1208 &rwork[iu1sn + imin - 1]);
1210 /* Computing 2nd power */
1212 /* Computing 2nd power */
1214 /* Computing 2nd power */
1216 if (r__1 * r__1 + r__2 * r__2 > r__3 * r__3) {
1217 slartgp_(&b21bulge, &b21d[imin], &rwork[iu2sn + imin - 1], &rwork[
1218 iu2cs + imin - 1], &r__);
1219 } else if (nu < mu) {
1220 slartgs_(&b21e[imin], &b21d[imin + 1], &nu, &rwork[iu2cs + imin -
1221 1], &rwork[iu2sn + imin - 1]);
1223 slartgs_(&b22d[imin], &b22e[imin], &mu, &rwork[iu2cs + imin - 1],
1224 &rwork[iu2sn + imin - 1]);
1226 rwork[iu2cs + imin - 1] = -rwork[iu2cs + imin - 1];
1227 rwork[iu2sn + imin - 1] = -rwork[iu2sn + imin - 1];
1229 temp = rwork[iu1cs + imin - 1] * b11e[imin] + rwork[iu1sn + imin - 1]
1231 b11d[imin + 1] = rwork[iu1cs + imin - 1] * b11d[imin + 1] - rwork[
1232 iu1sn + imin - 1] * b11e[imin];
1234 if (imax > imin + 1) {
1235 b11bulge = rwork[iu1sn + imin - 1] * b11e[imin + 1];
1236 b11e[imin + 1] = rwork[iu1cs + imin - 1] * b11e[imin + 1];
1238 temp = rwork[iu1cs + imin - 1] * b12d[imin] + rwork[iu1sn + imin - 1]
1240 b12e[imin] = rwork[iu1cs + imin - 1] * b12e[imin] - rwork[iu1sn +
1241 imin - 1] * b12d[imin];
1243 b12bulge = rwork[iu1sn + imin - 1] * b12d[imin + 1];
1244 b12d[imin + 1] = rwork[iu1cs + imin - 1] * b12d[imin + 1];
1245 temp = rwork[iu2cs + imin - 1] * b21e[imin] + rwork[iu2sn + imin - 1]
1247 b21d[imin + 1] = rwork[iu2cs + imin - 1] * b21d[imin + 1] - rwork[
1248 iu2sn + imin - 1] * b21e[imin];
1250 if (imax > imin + 1) {
1251 b21bulge = rwork[iu2sn + imin - 1] * b21e[imin + 1];
1252 b21e[imin + 1] = rwork[iu2cs + imin - 1] * b21e[imin + 1];
1254 temp = rwork[iu2cs + imin - 1] * b22d[imin] + rwork[iu2sn + imin - 1]
1256 b22e[imin] = rwork[iu2cs + imin - 1] * b22e[imin] - rwork[iu2sn +
1257 imin - 1] * b22d[imin];
1259 b22bulge = rwork[iu2sn + imin - 1] * b22d[imin + 1];
1260 b22d[imin + 1] = rwork[iu2cs + imin - 1] * b22d[imin + 1];
1262 /* Inner loop: chase bulges from B11(IMIN,IMIN+2), */
1263 /* B12(IMIN,IMIN+1), B21(IMIN,IMIN+2), and B22(IMIN,IMIN+1) to */
1267 for (i__ = imin + 1; i__ <= i__1; ++i__) {
1269 /* Compute PHI(I-1) */
1271 x1 = sin(theta[i__ - 1]) * b11e[i__ - 1] + cos(theta[i__ - 1]) *
1273 x2 = sin(theta[i__ - 1]) * b11bulge + cos(theta[i__ - 1]) *
1275 y1 = sin(theta[i__ - 1]) * b12d[i__ - 1] + cos(theta[i__ - 1]) *
1277 y2 = sin(theta[i__ - 1]) * b12bulge + cos(theta[i__ - 1]) *
1280 /* Computing 2nd power */
1282 /* Computing 2nd power */
1284 /* Computing 2nd power */
1286 /* Computing 2nd power */
1288 phi[i__ - 1] = atan2(sqrt(r__1 * r__1 + r__2 * r__2), sqrt(r__3 *
1289 r__3 + r__4 * r__4));
1291 /* Determine if there are bulges to chase or if a new direct */
1292 /* summand has been reached */
1294 /* Computing 2nd power */
1295 r__1 = b11e[i__ - 1];
1296 /* Computing 2nd power */
1298 /* Computing 2nd power */
1300 restart11 = r__1 * r__1 + r__2 * r__2 <= r__3 * r__3;
1301 /* Computing 2nd power */
1302 r__1 = b21e[i__ - 1];
1303 /* Computing 2nd power */
1305 /* Computing 2nd power */
1307 restart21 = r__1 * r__1 + r__2 * r__2 <= r__3 * r__3;
1308 /* Computing 2nd power */
1309 r__1 = b12d[i__ - 1];
1310 /* Computing 2nd power */
1312 /* Computing 2nd power */
1314 restart12 = r__1 * r__1 + r__2 * r__2 <= r__3 * r__3;
1315 /* Computing 2nd power */
1316 r__1 = b22d[i__ - 1];
1317 /* Computing 2nd power */
1319 /* Computing 2nd power */
1321 restart22 = r__1 * r__1 + r__2 * r__2 <= r__3 * r__3;
1323 /* If possible, chase bulges from B11(I-1,I+1), B12(I-1,I), */
1324 /* B21(I-1,I+1), and B22(I-1,I). If necessary, restart bulge- */
1325 /* chasing by applying the original shift again. */
1327 if (! restart11 && ! restart21) {
1328 slartgp_(&x2, &x1, &rwork[iv1tsn + i__ - 1], &rwork[iv1tcs +
1330 } else if (! restart11 && restart21) {
1331 slartgp_(&b11bulge, &b11e[i__ - 1], &rwork[iv1tsn + i__ - 1],
1332 &rwork[iv1tcs + i__ - 1], &r__);
1333 } else if (restart11 && ! restart21) {
1334 slartgp_(&b21bulge, &b21e[i__ - 1], &rwork[iv1tsn + i__ - 1],
1335 &rwork[iv1tcs + i__ - 1], &r__);
1336 } else if (mu <= nu) {
1337 slartgs_(&b11d[i__], &b11e[i__], &mu, &rwork[iv1tcs + i__ - 1]
1338 , &rwork[iv1tsn + i__ - 1]);
1340 slartgs_(&b21d[i__], &b21e[i__], &nu, &rwork[iv1tcs + i__ - 1]
1341 , &rwork[iv1tsn + i__ - 1]);
1343 rwork[iv1tcs + i__ - 1] = -rwork[iv1tcs + i__ - 1];
1344 rwork[iv1tsn + i__ - 1] = -rwork[iv1tsn + i__ - 1];
1345 if (! restart12 && ! restart22) {
1346 slartgp_(&y2, &y1, &rwork[iv2tsn + i__ - 2], &rwork[iv2tcs +
1348 } else if (! restart12 && restart22) {
1349 slartgp_(&b12bulge, &b12d[i__ - 1], &rwork[iv2tsn + i__ - 2],
1350 &rwork[iv2tcs + i__ - 2], &r__);
1351 } else if (restart12 && ! restart22) {
1352 slartgp_(&b22bulge, &b22d[i__ - 1], &rwork[iv2tsn + i__ - 2],
1353 &rwork[iv2tcs + i__ - 2], &r__);
1354 } else if (nu < mu) {
1355 slartgs_(&b12e[i__ - 1], &b12d[i__], &nu, &rwork[iv2tcs + i__
1356 - 2], &rwork[iv2tsn + i__ - 2]);
1358 slartgs_(&b22e[i__ - 1], &b22d[i__], &mu, &rwork[iv2tcs + i__
1359 - 2], &rwork[iv2tsn + i__ - 2]);
1362 temp = rwork[iv1tcs + i__ - 1] * b11d[i__] + rwork[iv1tsn + i__ -
1364 b11e[i__] = rwork[iv1tcs + i__ - 1] * b11e[i__] - rwork[iv1tsn +
1365 i__ - 1] * b11d[i__];
1367 b11bulge = rwork[iv1tsn + i__ - 1] * b11d[i__ + 1];
1368 b11d[i__ + 1] = rwork[iv1tcs + i__ - 1] * b11d[i__ + 1];
1369 temp = rwork[iv1tcs + i__ - 1] * b21d[i__] + rwork[iv1tsn + i__ -
1371 b21e[i__] = rwork[iv1tcs + i__ - 1] * b21e[i__] - rwork[iv1tsn +
1372 i__ - 1] * b21d[i__];
1374 b21bulge = rwork[iv1tsn + i__ - 1] * b21d[i__ + 1];
1375 b21d[i__ + 1] = rwork[iv1tcs + i__ - 1] * b21d[i__ + 1];
1376 temp = rwork[iv2tcs + i__ - 2] * b12e[i__ - 1] + rwork[iv2tsn +
1377 i__ - 2] * b12d[i__];
1378 b12d[i__] = rwork[iv2tcs + i__ - 2] * b12d[i__] - rwork[iv2tsn +
1379 i__ - 2] * b12e[i__ - 1];
1380 b12e[i__ - 1] = temp;
1381 b12bulge = rwork[iv2tsn + i__ - 2] * b12e[i__];
1382 b12e[i__] = rwork[iv2tcs + i__ - 2] * b12e[i__];
1383 temp = rwork[iv2tcs + i__ - 2] * b22e[i__ - 1] + rwork[iv2tsn +
1384 i__ - 2] * b22d[i__];
1385 b22d[i__] = rwork[iv2tcs + i__ - 2] * b22d[i__] - rwork[iv2tsn +
1386 i__ - 2] * b22e[i__ - 1];
1387 b22e[i__ - 1] = temp;
1388 b22bulge = rwork[iv2tsn + i__ - 2] * b22e[i__];
1389 b22e[i__] = rwork[iv2tcs + i__ - 2] * b22e[i__];
1391 /* Compute THETA(I) */
1393 x1 = cos(phi[i__ - 1]) * b11d[i__] + sin(phi[i__ - 1]) * b12e[i__
1395 x2 = cos(phi[i__ - 1]) * b11bulge + sin(phi[i__ - 1]) * b12bulge;
1396 y1 = cos(phi[i__ - 1]) * b21d[i__] + sin(phi[i__ - 1]) * b22e[i__
1398 y2 = cos(phi[i__ - 1]) * b21bulge + sin(phi[i__ - 1]) * b22bulge;
1400 /* Computing 2nd power */
1402 /* Computing 2nd power */
1404 /* Computing 2nd power */
1406 /* Computing 2nd power */
1408 theta[i__] = atan2(sqrt(r__1 * r__1 + r__2 * r__2), sqrt(r__3 *
1409 r__3 + r__4 * r__4));
1411 /* Determine if there are bulges to chase or if a new direct */
1412 /* summand has been reached */
1414 /* Computing 2nd power */
1416 /* Computing 2nd power */
1418 /* Computing 2nd power */
1420 restart11 = r__1 * r__1 + r__2 * r__2 <= r__3 * r__3;
1421 /* Computing 2nd power */
1422 r__1 = b12e[i__ - 1];
1423 /* Computing 2nd power */
1425 /* Computing 2nd power */
1427 restart12 = r__1 * r__1 + r__2 * r__2 <= r__3 * r__3;
1428 /* Computing 2nd power */
1430 /* Computing 2nd power */
1432 /* Computing 2nd power */
1434 restart21 = r__1 * r__1 + r__2 * r__2 <= r__3 * r__3;
1435 /* Computing 2nd power */
1436 r__1 = b22e[i__ - 1];
1437 /* Computing 2nd power */
1439 /* Computing 2nd power */
1441 restart22 = r__1 * r__1 + r__2 * r__2 <= r__3 * r__3;
1443 /* If possible, chase bulges from B11(I+1,I), B12(I+1,I-1), */
1444 /* B21(I+1,I), and B22(I+1,I-1). If necessary, restart bulge- */
1445 /* chasing by applying the original shift again. */
1447 if (! restart11 && ! restart12) {
1448 slartgp_(&x2, &x1, &rwork[iu1sn + i__ - 1], &rwork[iu1cs +
1450 } else if (! restart11 && restart12) {
1451 slartgp_(&b11bulge, &b11d[i__], &rwork[iu1sn + i__ - 1], &
1452 rwork[iu1cs + i__ - 1], &r__);
1453 } else if (restart11 && ! restart12) {
1454 slartgp_(&b12bulge, &b12e[i__ - 1], &rwork[iu1sn + i__ - 1], &
1455 rwork[iu1cs + i__ - 1], &r__);
1456 } else if (mu <= nu) {
1457 slartgs_(&b11e[i__], &b11d[i__ + 1], &mu, &rwork[iu1cs + i__
1458 - 1], &rwork[iu1sn + i__ - 1]);
1460 slartgs_(&b12d[i__], &b12e[i__], &nu, &rwork[iu1cs + i__ - 1],
1461 &rwork[iu1sn + i__ - 1]);
1463 if (! restart21 && ! restart22) {
1464 slartgp_(&y2, &y1, &rwork[iu2sn + i__ - 1], &rwork[iu2cs +
1466 } else if (! restart21 && restart22) {
1467 slartgp_(&b21bulge, &b21d[i__], &rwork[iu2sn + i__ - 1], &
1468 rwork[iu2cs + i__ - 1], &r__);
1469 } else if (restart21 && ! restart22) {
1470 slartgp_(&b22bulge, &b22e[i__ - 1], &rwork[iu2sn + i__ - 1], &
1471 rwork[iu2cs + i__ - 1], &r__);
1472 } else if (nu < mu) {
1473 slartgs_(&b21e[i__], &b21e[i__ + 1], &nu, &rwork[iu2cs + i__
1474 - 1], &rwork[iu2sn + i__ - 1]);
1476 slartgs_(&b22d[i__], &b22e[i__], &mu, &rwork[iu2cs + i__ - 1],
1477 &rwork[iu2sn + i__ - 1]);
1479 rwork[iu2cs + i__ - 1] = -rwork[iu2cs + i__ - 1];
1480 rwork[iu2sn + i__ - 1] = -rwork[iu2sn + i__ - 1];
1482 temp = rwork[iu1cs + i__ - 1] * b11e[i__] + rwork[iu1sn + i__ - 1]
1484 b11d[i__ + 1] = rwork[iu1cs + i__ - 1] * b11d[i__ + 1] - rwork[
1485 iu1sn + i__ - 1] * b11e[i__];
1487 if (i__ < imax - 1) {
1488 b11bulge = rwork[iu1sn + i__ - 1] * b11e[i__ + 1];
1489 b11e[i__ + 1] = rwork[iu1cs + i__ - 1] * b11e[i__ + 1];
1491 temp = rwork[iu2cs + i__ - 1] * b21e[i__] + rwork[iu2sn + i__ - 1]
1493 b21d[i__ + 1] = rwork[iu2cs + i__ - 1] * b21d[i__ + 1] - rwork[
1494 iu2sn + i__ - 1] * b21e[i__];
1496 if (i__ < imax - 1) {
1497 b21bulge = rwork[iu2sn + i__ - 1] * b21e[i__ + 1];
1498 b21e[i__ + 1] = rwork[iu2cs + i__ - 1] * b21e[i__ + 1];
1500 temp = rwork[iu1cs + i__ - 1] * b12d[i__] + rwork[iu1sn + i__ - 1]
1502 b12e[i__] = rwork[iu1cs + i__ - 1] * b12e[i__] - rwork[iu1sn +
1503 i__ - 1] * b12d[i__];
1505 b12bulge = rwork[iu1sn + i__ - 1] * b12d[i__ + 1];
1506 b12d[i__ + 1] = rwork[iu1cs + i__ - 1] * b12d[i__ + 1];
1507 temp = rwork[iu2cs + i__ - 1] * b22d[i__] + rwork[iu2sn + i__ - 1]
1509 b22e[i__] = rwork[iu2cs + i__ - 1] * b22e[i__] - rwork[iu2sn +
1510 i__ - 1] * b22d[i__];
1512 b22bulge = rwork[iu2sn + i__ - 1] * b22d[i__ + 1];
1513 b22d[i__ + 1] = rwork[iu2cs + i__ - 1] * b22d[i__ + 1];
1517 /* Compute PHI(IMAX-1) */
1519 x1 = sin(theta[imax - 1]) * b11e[imax - 1] + cos(theta[imax - 1]) *
1521 y1 = sin(theta[imax - 1]) * b12d[imax - 1] + cos(theta[imax - 1]) *
1523 y2 = sin(theta[imax - 1]) * b12bulge + cos(theta[imax - 1]) *
1526 /* Computing 2nd power */
1528 /* Computing 2nd power */
1530 phi[imax - 1] = atan2((abs(x1)), sqrt(r__1 * r__1 + r__2 * r__2));
1532 /* Chase bulges from B12(IMAX-1,IMAX) and B22(IMAX-1,IMAX) */
1534 /* Computing 2nd power */
1535 r__1 = b12d[imax - 1];
1536 /* Computing 2nd power */
1538 /* Computing 2nd power */
1540 restart12 = r__1 * r__1 + r__2 * r__2 <= r__3 * r__3;
1541 /* Computing 2nd power */
1542 r__1 = b22d[imax - 1];
1543 /* Computing 2nd power */
1545 /* Computing 2nd power */
1547 restart22 = r__1 * r__1 + r__2 * r__2 <= r__3 * r__3;
1549 if (! restart12 && ! restart22) {
1550 slartgp_(&y2, &y1, &rwork[iv2tsn + imax - 2], &rwork[iv2tcs +
1552 } else if (! restart12 && restart22) {
1553 slartgp_(&b12bulge, &b12d[imax - 1], &rwork[iv2tsn + imax - 2], &
1554 rwork[iv2tcs + imax - 2], &r__);
1555 } else if (restart12 && ! restart22) {
1556 slartgp_(&b22bulge, &b22d[imax - 1], &rwork[iv2tsn + imax - 2], &
1557 rwork[iv2tcs + imax - 2], &r__);
1558 } else if (nu < mu) {
1559 slartgs_(&b12e[imax - 1], &b12d[imax], &nu, &rwork[iv2tcs + imax
1560 - 2], &rwork[iv2tsn + imax - 2]);
1562 slartgs_(&b22e[imax - 1], &b22d[imax], &mu, &rwork[iv2tcs + imax
1563 - 2], &rwork[iv2tsn + imax - 2]);
1566 temp = rwork[iv2tcs + imax - 2] * b12e[imax - 1] + rwork[iv2tsn +
1567 imax - 2] * b12d[imax];
1568 b12d[imax] = rwork[iv2tcs + imax - 2] * b12d[imax] - rwork[iv2tsn +
1569 imax - 2] * b12e[imax - 1];
1570 b12e[imax - 1] = temp;
1571 temp = rwork[iv2tcs + imax - 2] * b22e[imax - 1] + rwork[iv2tsn +
1572 imax - 2] * b22d[imax];
1573 b22d[imax] = rwork[iv2tcs + imax - 2] * b22d[imax] - rwork[iv2tsn +
1574 imax - 2] * b22e[imax - 1];
1575 b22e[imax - 1] = temp;
1577 /* Update singular vectors */
1581 i__1 = imax - imin + 1;
1582 clasr_("R", "V", "F", p, &i__1, &rwork[iu1cs + imin - 1], &
1583 rwork[iu1sn + imin - 1], &u1[imin * u1_dim1 + 1],
1586 i__1 = imax - imin + 1;
1587 clasr_("L", "V", "F", &i__1, p, &rwork[iu1cs + imin - 1], &
1588 rwork[iu1sn + imin - 1], &u1[imin + u1_dim1], ldu1);
1594 i__2 = imax - imin + 1;
1595 clasr_("R", "V", "F", &i__1, &i__2, &rwork[iu2cs + imin - 1],
1596 &rwork[iu2sn + imin - 1], &u2[imin * u2_dim1 + 1],
1599 i__1 = imax - imin + 1;
1601 clasr_("L", "V", "F", &i__1, &i__2, &rwork[iu2cs + imin - 1],
1602 &rwork[iu2sn + imin - 1], &u2[imin + u2_dim1], ldu2);
1607 i__1 = imax - imin + 1;
1608 clasr_("L", "V", "F", &i__1, q, &rwork[iv1tcs + imin - 1], &
1609 rwork[iv1tsn + imin - 1], &v1t[imin + v1t_dim1],
1612 i__1 = imax - imin + 1;
1613 clasr_("R", "V", "F", q, &i__1, &rwork[iv1tcs + imin - 1], &
1614 rwork[iv1tsn + imin - 1], &v1t[imin * v1t_dim1 + 1],
1620 i__1 = imax - imin + 1;
1622 clasr_("L", "V", "F", &i__1, &i__2, &rwork[iv2tcs + imin - 1],
1623 &rwork[iv2tsn + imin - 1], &v2t[imin + v2t_dim1],
1627 i__2 = imax - imin + 1;
1628 clasr_("R", "V", "F", &i__1, &i__2, &rwork[iv2tcs + imin - 1],
1629 &rwork[iv2tsn + imin - 1], &v2t[imin * v2t_dim1 + 1],
1634 /* Fix signs on B11(IMAX-1,IMAX) and B21(IMAX-1,IMAX) */
1636 if (b11e[imax - 1] + b21e[imax - 1] > 0.f) {
1637 b11d[imax] = -b11d[imax];
1638 b21d[imax] = -b21d[imax];
1641 cscal_(q, &c_b1, &v1t[imax + v1t_dim1], ldv1t);
1643 cscal_(q, &c_b1, &v1t[imax * v1t_dim1 + 1], &c__1);
1648 /* Compute THETA(IMAX) */
1650 x1 = cos(phi[imax - 1]) * b11d[imax] + sin(phi[imax - 1]) * b12e[imax
1652 y1 = cos(phi[imax - 1]) * b21d[imax] + sin(phi[imax - 1]) * b22e[imax
1655 theta[imax] = atan2((abs(y1)), (abs(x1)));
1657 /* Fix signs on B11(IMAX,IMAX), B12(IMAX,IMAX-1), B21(IMAX,IMAX), */
1658 /* and B22(IMAX,IMAX-1) */
1660 if (b11d[imax] + b12e[imax - 1] < 0.f) {
1661 b12d[imax] = -b12d[imax];
1664 cscal_(p, &c_b1, &u1[imax * u1_dim1 + 1], &c__1);
1666 cscal_(p, &c_b1, &u1[imax + u1_dim1], ldu1);
1670 if (b21d[imax] + b22e[imax - 1] > 0.f) {
1671 b22d[imax] = -b22d[imax];
1675 cscal_(&i__1, &c_b1, &u2[imax * u2_dim1 + 1], &c__1);
1678 cscal_(&i__1, &c_b1, &u2[imax + u2_dim1], ldu2);
1683 /* Fix signs on B12(IMAX,IMAX) and B22(IMAX,IMAX) */
1685 if (b12d[imax] + b22d[imax] < 0.f) {
1689 cscal_(&i__1, &c_b1, &v2t[imax + v2t_dim1], ldv2t);
1692 cscal_(&i__1, &c_b1, &v2t[imax * v2t_dim1 + 1], &c__1);
1697 /* Test for negligible sines or cosines */
1700 for (i__ = imin; i__ <= i__1; ++i__) {
1701 if (theta[i__] < thresh) {
1703 } else if (theta[i__] > 1.57079632679489662f - thresh) {
1704 theta[i__] = 1.57079632679489662f;
1708 for (i__ = imin; i__ <= i__1; ++i__) {
1709 if (phi[i__] < thresh) {
1711 } else if (phi[i__] > 1.57079632679489662f - thresh) {
1712 phi[i__] = 1.57079632679489662f;
1719 while(phi[imax - 1] == 0.f) {
1726 if (imin > imax - 1) {
1730 while(phi[imin - 1] != 0.f) {
1738 /* Repeat main iteration loop */
1742 /* Postprocessing: order THETA from least to greatest */
1745 for (i__ = 1; i__ <= i__1; ++i__) {
1748 thetamin = theta[i__];
1750 for (j = i__ + 1; j <= i__2; ++j) {
1751 if (theta[j] < thetamin) {
1753 thetamin = theta[j];
1758 theta[mini] = theta[i__];
1759 theta[i__] = thetamin;
1762 cswap_(p, &u1[i__ * u1_dim1 + 1], &c__1, &u1[mini *
1763 u1_dim1 + 1], &c__1);
1767 cswap_(&i__2, &u2[i__ * u2_dim1 + 1], &c__1, &u2[mini *
1768 u2_dim1 + 1], &c__1);
1771 cswap_(q, &v1t[i__ + v1t_dim1], ldv1t, &v1t[mini +
1776 cswap_(&i__2, &v2t[i__ + v2t_dim1], ldv2t, &v2t[mini +
1781 cswap_(p, &u1[i__ + u1_dim1], ldu1, &u1[mini + u1_dim1],
1786 cswap_(&i__2, &u2[i__ + u2_dim1], ldu2, &u2[mini +
1790 cswap_(q, &v1t[i__ * v1t_dim1 + 1], &c__1, &v1t[mini *
1791 v1t_dim1 + 1], &c__1);
1795 cswap_(&i__2, &v2t[i__ * v2t_dim1 + 1], &c__1, &v2t[mini *
1796 v2t_dim1 + 1], &c__1);