14 typedef long long BLASLONG;
15 typedef unsigned long long BLASULONG;
17 typedef long BLASLONG;
18 typedef unsigned long BLASULONG;
22 typedef BLASLONG blasint;
24 #define blasabs(x) llabs(x)
26 #define blasabs(x) labs(x)
30 #define blasabs(x) abs(x)
33 typedef blasint integer;
35 typedef unsigned int uinteger;
36 typedef char *address;
37 typedef short int shortint;
39 typedef double doublereal;
40 typedef struct { real r, i; } complex;
41 typedef struct { doublereal r, i; } doublecomplex;
43 static inline _Fcomplex Cf(complex *z) {_Fcomplex zz={z->r , z->i}; return zz;}
44 static inline _Dcomplex Cd(doublecomplex *z) {_Dcomplex zz={z->r , z->i};return zz;}
45 static inline _Fcomplex * _pCf(complex *z) {return (_Fcomplex*)z;}
46 static inline _Dcomplex * _pCd(doublecomplex *z) {return (_Dcomplex*)z;}
48 static inline _Complex float Cf(complex *z) {return z->r + z->i*_Complex_I;}
49 static inline _Complex double Cd(doublecomplex *z) {return z->r + z->i*_Complex_I;}
50 static inline _Complex float * _pCf(complex *z) {return (_Complex float*)z;}
51 static inline _Complex double * _pCd(doublecomplex *z) {return (_Complex double*)z;}
53 #define pCf(z) (*_pCf(z))
54 #define pCd(z) (*_pCd(z))
56 typedef short int shortlogical;
57 typedef char logical1;
58 typedef char integer1;
63 /* Extern is for use with -E */
74 /*external read, write*/
83 /*internal read, write*/
113 /*rewind, backspace, endfile*/
125 ftnint *inex; /*parameters in standard's order*/
151 union Multitype { /* for multiple entry points */
162 typedef union Multitype Multitype;
164 struct Vardesc { /* for Namelist */
170 typedef struct Vardesc Vardesc;
177 typedef struct Namelist Namelist;
179 #define abs(x) ((x) >= 0 ? (x) : -(x))
180 #define dabs(x) (fabs(x))
181 #define f2cmin(a,b) ((a) <= (b) ? (a) : (b))
182 #define f2cmax(a,b) ((a) >= (b) ? (a) : (b))
183 #define dmin(a,b) (f2cmin(a,b))
184 #define dmax(a,b) (f2cmax(a,b))
185 #define bit_test(a,b) ((a) >> (b) & 1)
186 #define bit_clear(a,b) ((a) & ~((uinteger)1 << (b)))
187 #define bit_set(a,b) ((a) | ((uinteger)1 << (b)))
189 #define abort_() { sig_die("Fortran abort routine called", 1); }
190 #define c_abs(z) (cabsf(Cf(z)))
191 #define c_cos(R,Z) { pCf(R)=ccos(Cf(Z)); }
193 #define c_div(c, a, b) {Cf(c)._Val[0] = (Cf(a)._Val[0]/Cf(b)._Val[0]); Cf(c)._Val[1]=(Cf(a)._Val[1]/Cf(b)._Val[1]);}
194 #define z_div(c, a, b) {Cd(c)._Val[0] = (Cd(a)._Val[0]/Cd(b)._Val[0]); Cd(c)._Val[1]=(Cd(a)._Val[1]/df(b)._Val[1]);}
196 #define c_div(c, a, b) {pCf(c) = Cf(a)/Cf(b);}
197 #define z_div(c, a, b) {pCd(c) = Cd(a)/Cd(b);}
199 #define c_exp(R, Z) {pCf(R) = cexpf(Cf(Z));}
200 #define c_log(R, Z) {pCf(R) = clogf(Cf(Z));}
201 #define c_sin(R, Z) {pCf(R) = csinf(Cf(Z));}
202 //#define c_sqrt(R, Z) {*(R) = csqrtf(Cf(Z));}
203 #define c_sqrt(R, Z) {pCf(R) = csqrtf(Cf(Z));}
204 #define d_abs(x) (fabs(*(x)))
205 #define d_acos(x) (acos(*(x)))
206 #define d_asin(x) (asin(*(x)))
207 #define d_atan(x) (atan(*(x)))
208 #define d_atn2(x, y) (atan2(*(x),*(y)))
209 #define d_cnjg(R, Z) { pCd(R) = conj(Cd(Z)); }
210 #define r_cnjg(R, Z) { pCf(R) = conjf(Cf(Z)); }
211 #define d_cos(x) (cos(*(x)))
212 #define d_cosh(x) (cosh(*(x)))
213 #define d_dim(__a, __b) ( *(__a) > *(__b) ? *(__a) - *(__b) : 0.0 )
214 #define d_exp(x) (exp(*(x)))
215 #define d_imag(z) (cimag(Cd(z)))
216 #define r_imag(z) (cimagf(Cf(z)))
217 #define d_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
218 #define r_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
219 #define d_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
220 #define r_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
221 #define d_log(x) (log(*(x)))
222 #define d_mod(x, y) (fmod(*(x), *(y)))
223 #define u_nint(__x) ((__x)>=0 ? floor((__x) + .5) : -floor(.5 - (__x)))
224 #define d_nint(x) u_nint(*(x))
225 #define u_sign(__a,__b) ((__b) >= 0 ? ((__a) >= 0 ? (__a) : -(__a)) : -((__a) >= 0 ? (__a) : -(__a)))
226 #define d_sign(a,b) u_sign(*(a),*(b))
227 #define r_sign(a,b) u_sign(*(a),*(b))
228 #define d_sin(x) (sin(*(x)))
229 #define d_sinh(x) (sinh(*(x)))
230 #define d_sqrt(x) (sqrt(*(x)))
231 #define d_tan(x) (tan(*(x)))
232 #define d_tanh(x) (tanh(*(x)))
233 #define i_abs(x) abs(*(x))
234 #define i_dnnt(x) ((integer)u_nint(*(x)))
235 #define i_len(s, n) (n)
236 #define i_nint(x) ((integer)u_nint(*(x)))
237 #define i_sign(a,b) ((integer)u_sign((integer)*(a),(integer)*(b)))
238 #define pow_dd(ap, bp) ( pow(*(ap), *(bp)))
239 #define pow_si(B,E) spow_ui(*(B),*(E))
240 #define pow_ri(B,E) spow_ui(*(B),*(E))
241 #define pow_di(B,E) dpow_ui(*(B),*(E))
242 #define pow_zi(p, a, b) {pCd(p) = zpow_ui(Cd(a), *(b));}
243 #define pow_ci(p, a, b) {pCf(p) = cpow_ui(Cf(a), *(b));}
244 #define pow_zz(R,A,B) {pCd(R) = cpow(Cd(A),*(B));}
245 #define s_cat(lpp, rpp, rnp, np, llp) { ftnlen i, nc, ll; char *f__rp, *lp; ll = (llp); lp = (lpp); for(i=0; i < (int)*(np); ++i) { nc = ll; if((rnp)[i] < nc) nc = (rnp)[i]; ll -= nc; f__rp = (rpp)[i]; while(--nc >= 0) *lp++ = *(f__rp)++; } while(--ll >= 0) *lp++ = ' '; }
246 #define s_cmp(a,b,c,d) ((integer)strncmp((a),(b),f2cmin((c),(d))))
247 #define s_copy(A,B,C,D) { int __i,__m; for (__i=0, __m=f2cmin((C),(D)); __i<__m && (B)[__i] != 0; ++__i) (A)[__i] = (B)[__i]; }
248 #define sig_die(s, kill) { exit(1); }
249 #define s_stop(s, n) {exit(0);}
250 static char junk[] = "\n@(#)LIBF77 VERSION 19990503\n";
251 #define z_abs(z) (cabs(Cd(z)))
252 #define z_exp(R, Z) {pCd(R) = cexp(Cd(Z));}
253 #define z_sqrt(R, Z) {pCd(R) = csqrt(Cd(Z));}
254 #define myexit_() break;
255 #define mycycle() continue;
256 #define myceiling(w) {ceil(w)}
257 #define myhuge(w) {HUGE_VAL}
258 //#define mymaxloc_(w,s,e,n) {if (sizeof(*(w)) == sizeof(double)) dmaxloc_((w),*(s),*(e),n); else dmaxloc_((w),*(s),*(e),n);}
259 #define mymaxloc(w,s,e,n) {dmaxloc_(w,*(s),*(e),n)}
261 /* procedure parameter types for -A and -C++ */
263 #define F2C_proc_par_types 1
265 typedef logical (*L_fp)(...);
267 typedef logical (*L_fp)();
270 static float spow_ui(float x, integer n) {
271 float pow=1.0; unsigned long int u;
273 if(n < 0) n = -n, x = 1/x;
282 static double dpow_ui(double x, integer n) {
283 double pow=1.0; unsigned long int u;
285 if(n < 0) n = -n, x = 1/x;
295 static _Fcomplex cpow_ui(complex x, integer n) {
296 complex pow={1.0,0.0}; unsigned long int u;
298 if(n < 0) n = -n, x.r = 1/x.r, x.i=1/x.i;
300 if(u & 01) pow.r *= x.r, pow.i *= x.i;
301 if(u >>= 1) x.r *= x.r, x.i *= x.i;
305 _Fcomplex p={pow.r, pow.i};
309 static _Complex float cpow_ui(_Complex float x, integer n) {
310 _Complex float pow=1.0; unsigned long int u;
312 if(n < 0) n = -n, x = 1/x;
323 static _Dcomplex zpow_ui(_Dcomplex x, integer n) {
324 _Dcomplex pow={1.0,0.0}; unsigned long int u;
326 if(n < 0) n = -n, x._Val[0] = 1/x._Val[0], x._Val[1] =1/x._Val[1];
328 if(u & 01) pow._Val[0] *= x._Val[0], pow._Val[1] *= x._Val[1];
329 if(u >>= 1) x._Val[0] *= x._Val[0], x._Val[1] *= x._Val[1];
333 _Dcomplex p = {pow._Val[0], pow._Val[1]};
337 static _Complex double zpow_ui(_Complex double x, integer n) {
338 _Complex double pow=1.0; unsigned long int u;
340 if(n < 0) n = -n, x = 1/x;
350 static integer pow_ii(integer x, integer n) {
351 integer pow; unsigned long int u;
353 if (n == 0 || x == 1) pow = 1;
354 else if (x != -1) pow = x == 0 ? 1/x : 0;
357 if ((n > 0) || !(n == 0 || x == 1 || x != -1)) {
367 static integer dmaxloc_(double *w, integer s, integer e, integer *n)
369 double m; integer i, mi;
370 for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
371 if (w[i-1]>m) mi=i ,m=w[i-1];
374 static integer smaxloc_(float *w, integer s, integer e, integer *n)
376 float m; integer i, mi;
377 for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
378 if (w[i-1]>m) mi=i ,m=w[i-1];
381 static inline void cdotc_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
382 integer n = *n_, incx = *incx_, incy = *incy_, i;
384 _Fcomplex zdotc = {0.0, 0.0};
385 if (incx == 1 && incy == 1) {
386 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
387 zdotc._Val[0] += conjf(Cf(&x[i]))._Val[0] * Cf(&y[i])._Val[0];
388 zdotc._Val[1] += conjf(Cf(&x[i]))._Val[1] * Cf(&y[i])._Val[1];
391 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
392 zdotc._Val[0] += conjf(Cf(&x[i*incx]))._Val[0] * Cf(&y[i*incy])._Val[0];
393 zdotc._Val[1] += conjf(Cf(&x[i*incx]))._Val[1] * Cf(&y[i*incy])._Val[1];
399 _Complex float zdotc = 0.0;
400 if (incx == 1 && incy == 1) {
401 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
402 zdotc += conjf(Cf(&x[i])) * Cf(&y[i]);
405 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
406 zdotc += conjf(Cf(&x[i*incx])) * Cf(&y[i*incy]);
412 static inline void zdotc_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
413 integer n = *n_, incx = *incx_, incy = *incy_, i;
415 _Dcomplex zdotc = {0.0, 0.0};
416 if (incx == 1 && incy == 1) {
417 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
418 zdotc._Val[0] += conj(Cd(&x[i]))._Val[0] * Cd(&y[i])._Val[0];
419 zdotc._Val[1] += conj(Cd(&x[i]))._Val[1] * Cd(&y[i])._Val[1];
422 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
423 zdotc._Val[0] += conj(Cd(&x[i*incx]))._Val[0] * Cd(&y[i*incy])._Val[0];
424 zdotc._Val[1] += conj(Cd(&x[i*incx]))._Val[1] * Cd(&y[i*incy])._Val[1];
430 _Complex double zdotc = 0.0;
431 if (incx == 1 && incy == 1) {
432 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
433 zdotc += conj(Cd(&x[i])) * Cd(&y[i]);
436 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
437 zdotc += conj(Cd(&x[i*incx])) * Cd(&y[i*incy]);
443 static inline void cdotu_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
444 integer n = *n_, incx = *incx_, incy = *incy_, i;
446 _Fcomplex zdotc = {0.0, 0.0};
447 if (incx == 1 && incy == 1) {
448 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
449 zdotc._Val[0] += Cf(&x[i])._Val[0] * Cf(&y[i])._Val[0];
450 zdotc._Val[1] += Cf(&x[i])._Val[1] * Cf(&y[i])._Val[1];
453 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
454 zdotc._Val[0] += Cf(&x[i*incx])._Val[0] * Cf(&y[i*incy])._Val[0];
455 zdotc._Val[1] += Cf(&x[i*incx])._Val[1] * Cf(&y[i*incy])._Val[1];
461 _Complex float zdotc = 0.0;
462 if (incx == 1 && incy == 1) {
463 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
464 zdotc += Cf(&x[i]) * Cf(&y[i]);
467 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
468 zdotc += Cf(&x[i*incx]) * Cf(&y[i*incy]);
474 static inline void zdotu_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
475 integer n = *n_, incx = *incx_, incy = *incy_, i;
477 _Dcomplex zdotc = {0.0, 0.0};
478 if (incx == 1 && incy == 1) {
479 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
480 zdotc._Val[0] += Cd(&x[i])._Val[0] * Cd(&y[i])._Val[0];
481 zdotc._Val[1] += Cd(&x[i])._Val[1] * Cd(&y[i])._Val[1];
484 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
485 zdotc._Val[0] += Cd(&x[i*incx])._Val[0] * Cd(&y[i*incy])._Val[0];
486 zdotc._Val[1] += Cd(&x[i*incx])._Val[1] * Cd(&y[i*incy])._Val[1];
492 _Complex double zdotc = 0.0;
493 if (incx == 1 && incy == 1) {
494 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
495 zdotc += Cd(&x[i]) * Cd(&y[i]);
498 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
499 zdotc += Cd(&x[i*incx]) * Cd(&y[i*incy]);
505 /* -- translated by f2c (version 20000121).
506 You must link the resulting object file with the libraries:
507 -lf2c -lm (in that order)
513 /* Table of constant values */
515 static integer c_n1 = -1;
516 static logical c_false = FALSE_;
518 /* > \brief \b CUNCSD */
520 /* =========== DOCUMENTATION =========== */
522 /* Online html documentation available at */
523 /* http://www.netlib.org/lapack/explore-html/ */
526 /* > Download CUNCSD + dependencies */
527 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/cuncsd.
530 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/cuncsd.
533 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/cuncsd.
541 /* SUBROUTINE CUNCSD( JOBU1, JOBU2, JOBV1T, JOBV2T, TRANS, */
542 /* SIGNS, M, P, Q, X11, LDX11, X12, */
543 /* LDX12, X21, LDX21, X22, LDX22, THETA, */
544 /* U1, LDU1, U2, LDU2, V1T, LDV1T, V2T, */
545 /* LDV2T, WORK, LWORK, RWORK, LRWORK, */
548 /* CHARACTER JOBU1, JOBU2, JOBV1T, JOBV2T, SIGNS, TRANS */
549 /* INTEGER INFO, LDU1, LDU2, LDV1T, LDV2T, LDX11, LDX12, */
550 /* $ LDX21, LDX22, LRWORK, LWORK, M, P, Q */
551 /* INTEGER IWORK( * ) */
552 /* REAL THETA( * ) */
553 /* REAL RWORK( * ) */
554 /* COMPLEX U1( LDU1, * ), U2( LDU2, * ), V1T( LDV1T, * ), */
555 /* $ V2T( LDV2T, * ), WORK( * ), X11( LDX11, * ), */
556 /* $ X12( LDX12, * ), X21( LDX21, * ), X22( LDX22, */
560 /* > \par Purpose: */
565 /* > CUNCSD computes the CS decomposition of an M-by-M partitioned */
566 /* > unitary matrix X: */
568 /* > [ I 0 0 | 0 0 0 ] */
569 /* > [ 0 C 0 | 0 -S 0 ] */
570 /* > [ X11 | X12 ] [ U1 | ] [ 0 0 0 | 0 0 -I ] [ V1 | ]**H */
571 /* > X = [-----------] = [---------] [---------------------] [---------] . */
572 /* > [ X21 | X22 ] [ | U2 ] [ 0 0 0 | I 0 0 ] [ | V2 ] */
573 /* > [ 0 S 0 | 0 C 0 ] */
574 /* > [ 0 0 I | 0 0 0 ] */
576 /* > X11 is P-by-Q. The unitary matrices U1, U2, V1, and V2 are P-by-P, */
577 /* > (M-P)-by-(M-P), Q-by-Q, and (M-Q)-by-(M-Q), respectively. C and S are */
578 /* > R-by-R nonnegative diagonal matrices satisfying C^2 + S^2 = I, in */
579 /* > which R = MIN(P,M-P,Q,M-Q). */
585 /* > \param[in] JOBU1 */
587 /* > JOBU1 is CHARACTER */
588 /* > = 'Y': U1 is computed; */
589 /* > otherwise: U1 is not computed. */
592 /* > \param[in] JOBU2 */
594 /* > JOBU2 is CHARACTER */
595 /* > = 'Y': U2 is computed; */
596 /* > otherwise: U2 is not computed. */
599 /* > \param[in] JOBV1T */
601 /* > JOBV1T is CHARACTER */
602 /* > = 'Y': V1T is computed; */
603 /* > otherwise: V1T is not computed. */
606 /* > \param[in] JOBV2T */
608 /* > JOBV2T is CHARACTER */
609 /* > = 'Y': V2T is computed; */
610 /* > otherwise: V2T is not computed. */
613 /* > \param[in] TRANS */
615 /* > TRANS is CHARACTER */
616 /* > = 'T': X, U1, U2, V1T, and V2T are stored in row-major */
618 /* > otherwise: X, U1, U2, V1T, and V2T are stored in column- */
622 /* > \param[in] SIGNS */
624 /* > SIGNS is CHARACTER */
625 /* > = 'O': The lower-left block is made nonpositive (the */
626 /* > "other" convention); */
627 /* > otherwise: The upper-right block is made nonpositive (the */
628 /* > "default" convention). */
634 /* > The number of rows and columns in X. */
640 /* > The number of rows in X11 and X12. 0 <= P <= M. */
646 /* > The number of columns in X11 and X21. 0 <= Q <= M. */
649 /* > \param[in,out] X11 */
651 /* > X11 is COMPLEX array, dimension (LDX11,Q) */
652 /* > On entry, part of the unitary matrix whose CSD is desired. */
655 /* > \param[in] LDX11 */
657 /* > LDX11 is INTEGER */
658 /* > The leading dimension of X11. LDX11 >= MAX(1,P). */
661 /* > \param[in,out] X12 */
663 /* > X12 is COMPLEX array, dimension (LDX12,M-Q) */
664 /* > On entry, part of the unitary matrix whose CSD is desired. */
667 /* > \param[in] LDX12 */
669 /* > LDX12 is INTEGER */
670 /* > The leading dimension of X12. LDX12 >= MAX(1,P). */
673 /* > \param[in,out] X21 */
675 /* > X21 is COMPLEX array, dimension (LDX21,Q) */
676 /* > On entry, part of the unitary matrix whose CSD is desired. */
679 /* > \param[in] LDX21 */
681 /* > LDX21 is INTEGER */
682 /* > The leading dimension of X11. LDX21 >= MAX(1,M-P). */
685 /* > \param[in,out] X22 */
687 /* > X22 is COMPLEX array, dimension (LDX22,M-Q) */
688 /* > On entry, part of the unitary matrix whose CSD is desired. */
691 /* > \param[in] LDX22 */
693 /* > LDX22 is INTEGER */
694 /* > The leading dimension of X11. LDX22 >= MAX(1,M-P). */
697 /* > \param[out] THETA */
699 /* > THETA is REAL array, dimension (R), in which R = */
700 /* > MIN(P,M-P,Q,M-Q). */
701 /* > C = DIAG( COS(THETA(1)), ... , COS(THETA(R)) ) and */
702 /* > S = DIAG( SIN(THETA(1)), ... , SIN(THETA(R)) ). */
705 /* > \param[out] U1 */
707 /* > U1 is COMPLEX array, dimension (LDU1,P) */
708 /* > If JOBU1 = 'Y', U1 contains the P-by-P unitary matrix U1. */
711 /* > \param[in] LDU1 */
713 /* > LDU1 is INTEGER */
714 /* > The leading dimension of U1. If JOBU1 = 'Y', LDU1 >= */
718 /* > \param[out] U2 */
720 /* > U2 is COMPLEX array, dimension (LDU2,M-P) */
721 /* > If JOBU2 = 'Y', U2 contains the (M-P)-by-(M-P) unitary */
725 /* > \param[in] LDU2 */
727 /* > LDU2 is INTEGER */
728 /* > The leading dimension of U2. If JOBU2 = 'Y', LDU2 >= */
732 /* > \param[out] V1T */
734 /* > V1T is COMPLEX array, dimension (LDV1T,Q) */
735 /* > If JOBV1T = 'Y', V1T contains the Q-by-Q matrix unitary */
736 /* > matrix V1**H. */
739 /* > \param[in] LDV1T */
741 /* > LDV1T is INTEGER */
742 /* > The leading dimension of V1T. If JOBV1T = 'Y', LDV1T >= */
746 /* > \param[out] V2T */
748 /* > V2T is COMPLEX array, dimension (LDV2T,M-Q) */
749 /* > If JOBV2T = 'Y', V2T contains the (M-Q)-by-(M-Q) unitary */
750 /* > matrix V2**H. */
753 /* > \param[in] LDV2T */
755 /* > LDV2T is INTEGER */
756 /* > The leading dimension of V2T. If JOBV2T = 'Y', LDV2T >= */
760 /* > \param[out] WORK */
762 /* > WORK is COMPLEX array, dimension (MAX(1,LWORK)) */
763 /* > On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */
766 /* > \param[in] LWORK */
768 /* > LWORK is INTEGER */
769 /* > The dimension of the array WORK. */
771 /* > If LWORK = -1, then a workspace query is assumed; the routine */
772 /* > only calculates the optimal size of the WORK array, returns */
773 /* > this value as the first entry of the work array, and no error */
774 /* > message related to LWORK is issued by XERBLA. */
777 /* > \param[out] RWORK */
779 /* > RWORK is REAL array, dimension MAX(1,LRWORK) */
780 /* > On exit, if INFO = 0, RWORK(1) returns the optimal LRWORK. */
781 /* > If INFO > 0 on exit, RWORK(2:R) contains the values PHI(1), */
782 /* > ..., PHI(R-1) that, together with THETA(1), ..., THETA(R), */
783 /* > define the matrix in intermediate bidiagonal-block form */
784 /* > remaining after nonconvergence. INFO specifies the number */
785 /* > of nonzero PHI's. */
788 /* > \param[in] LRWORK */
790 /* > LRWORK is INTEGER */
791 /* > The dimension of the array RWORK. */
793 /* > If LRWORK = -1, then a workspace query is assumed; the routine */
794 /* > only calculates the optimal size of the RWORK array, returns */
795 /* > this value as the first entry of the work array, and no error */
796 /* > message related to LRWORK is issued by XERBLA. */
799 /* > \param[out] IWORK */
801 /* > IWORK is INTEGER array, dimension (M-MIN(P,M-P,Q,M-Q)) */
804 /* > \param[out] INFO */
806 /* > INFO is INTEGER */
807 /* > = 0: successful exit. */
808 /* > < 0: if INFO = -i, the i-th argument had an illegal value. */
809 /* > > 0: CBBCSD did not converge. See the description of RWORK */
810 /* > above for details. */
813 /* > \par References: */
814 /* ================ */
816 /* > [1] Brian D. Sutton. Computing the complete CS decomposition. Numer. */
817 /* > Algorithms, 50(1):33-65, 2009. */
822 /* > \author Univ. of Tennessee */
823 /* > \author Univ. of California Berkeley */
824 /* > \author Univ. of Colorado Denver */
825 /* > \author NAG Ltd. */
827 /* > \date June 2016 */
829 /* > \ingroup complexOTHERcomputational */
831 /* ===================================================================== */
832 /* Subroutine */ int cuncsd_(char *jobu1, char *jobu2, char *jobv1t, char *
833 jobv2t, char *trans, char *signs, integer *m, integer *p, integer *q,
834 complex *x11, integer *ldx11, complex *x12, integer *ldx12, complex *
835 x21, integer *ldx21, complex *x22, integer *ldx22, real *theta,
836 complex *u1, integer *ldu1, complex *u2, integer *ldu2, complex *v1t,
837 integer *ldv1t, complex *v2t, integer *ldv2t, complex *work, integer *
838 lwork, real *rwork, integer *lrwork, integer *iwork, integer *info)
840 /* System generated locals */
841 integer u1_dim1, u1_offset, u2_dim1, u2_offset, v1t_dim1, v1t_offset,
842 v2t_dim1, v2t_offset, x11_dim1, x11_offset, x12_dim1, x12_offset,
843 x21_dim1, x21_offset, x22_dim1, x22_offset, i__1, i__2, i__3,
846 /* Local variables */
847 integer ib11d, ib11e, ib12d, ib12e, ib21d, ib21e, ib22d, ib22e, iphi;
850 logical defaultsigns;
851 integer lworkopt, i__, j;
852 extern logical lsame_(char *, char *);
853 integer childinfo, p1, q1, lbbcsdworkmin, itaup1, itaup2, itauq1, itauq2,
854 lorbdbworkmin, lrworkmin, lbbcsdworkopt;
855 logical wantu1, wantu2;
856 extern /* Subroutine */ int cbbcsd_(char *, char *, char *, char *, char *
857 , integer *, integer *, integer *, real *, real *, complex *,
858 integer *, complex *, integer *, complex *, integer *, complex *,
859 integer *, real *, real *, real *, real *, real *, real *, real *,
860 real *, real *, integer *, integer *);
861 integer lrworkopt, ibbcsd, lorbdbworkopt;
862 extern /* Subroutine */ int cunbdb_(char *, char *, integer *, integer *,
863 integer *, complex *, integer *, complex *, integer *, complex *,
864 integer *, complex *, integer *, real *, real *, complex *,
865 complex *, complex *, complex *, complex *, integer *, integer *);
866 integer iorbdb, lorglqworkmin, lorgqrworkmin;
867 extern /* Subroutine */ int clacpy_(char *, integer *, integer *, complex
868 *, integer *, complex *, integer *), xerbla_(char *,
869 integer *, ftnlen), clapmr_(logical *, integer *, integer *,
870 complex *, integer *, integer *), clapmt_(logical *, integer *,
871 integer *, complex *, integer *, integer *);
872 integer lorglqworkopt;
873 extern /* Subroutine */ int cunglq_(integer *, integer *, integer *,
874 complex *, integer *, complex *, complex *, integer *, integer *);
875 integer lorgqrworkopt, iorglq;
876 extern /* Subroutine */ int cungqr_(integer *, integer *, integer *,
877 complex *, integer *, complex *, complex *, integer *, integer *);
879 char signst[1], transt[1];
882 integer lorbdbwork, lorglqwork, lorgqrwork;
883 logical wantv1t, wantv2t, lrquery;
886 /* -- LAPACK computational routine (version 3.7.1) -- */
887 /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
888 /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
892 /* =================================================================== */
895 /* Test input arguments */
897 /* Parameter adjustments */
899 x11_offset = 1 + x11_dim1 * 1;
902 x12_offset = 1 + x12_dim1 * 1;
905 x21_offset = 1 + x21_dim1 * 1;
908 x22_offset = 1 + x22_dim1 * 1;
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;
929 wantu1 = lsame_(jobu1, "Y");
930 wantu2 = lsame_(jobu2, "Y");
931 wantv1t = lsame_(jobv1t, "Y");
932 wantv2t = lsame_(jobv2t, "Y");
933 colmajor = ! lsame_(trans, "T");
934 defaultsigns = ! lsame_(signs, "O");
935 lquery = *lwork == -1;
936 lrquery = *lrwork == -1;
939 } else if (*p < 0 || *p > *m) {
941 } else if (*q < 0 || *q > *m) {
943 } else if (colmajor && *ldx11 < f2cmax(1,*p)) {
945 } else if (! colmajor && *ldx11 < f2cmax(1,*q)) {
947 } else if (colmajor && *ldx12 < f2cmax(1,*p)) {
949 } else /* if(complicated condition) */ {
951 i__1 = 1, i__2 = *m - *q;
952 if (! colmajor && *ldx12 < f2cmax(i__1,i__2)) {
954 } else /* if(complicated condition) */ {
956 i__1 = 1, i__2 = *m - *p;
957 if (colmajor && *ldx21 < f2cmax(i__1,i__2)) {
959 } else if (! colmajor && *ldx21 < f2cmax(1,*q)) {
961 } else /* if(complicated condition) */ {
963 i__1 = 1, i__2 = *m - *p;
964 if (colmajor && *ldx22 < f2cmax(i__1,i__2)) {
966 } else /* if(complicated condition) */ {
968 i__1 = 1, i__2 = *m - *q;
969 if (! colmajor && *ldx22 < f2cmax(i__1,i__2)) {
971 } else if (wantu1 && *ldu1 < *p) {
973 } else if (wantu2 && *ldu2 < *m - *p) {
975 } else if (wantv1t && *ldv1t < *q) {
977 } else if (wantv2t && *ldv2t < *m - *q) {
985 /* Work with transpose if convenient */
988 i__1 = *p, i__2 = *m - *p;
990 i__3 = *q, i__4 = *m - *q;
991 if (*info == 0 && f2cmin(i__1,i__2) < f2cmin(i__3,i__4)) {
993 *(unsigned char *)transt = 'T';
995 *(unsigned char *)transt = 'N';
998 *(unsigned char *)signst = 'O';
1000 *(unsigned char *)signst = 'D';
1002 cuncsd_(jobv1t, jobv2t, jobu1, jobu2, transt, signst, m, q, p, &x11[
1003 x11_offset], ldx11, &x21[x21_offset], ldx21, &x12[x12_offset],
1004 ldx12, &x22[x22_offset], ldx22, &theta[1], &v1t[v1t_offset],
1005 ldv1t, &v2t[v2t_offset], ldv2t, &u1[u1_offset], ldu1, &u2[
1006 u2_offset], ldu2, &work[1], lwork, &rwork[1], lrwork, &iwork[
1011 /* Work with permutation [ 0 I; I 0 ] * X * [ 0 I; I 0 ] if */
1014 if (*info == 0 && *m - *q < *q) {
1016 *(unsigned char *)signst = 'O';
1018 *(unsigned char *)signst = 'D';
1022 cuncsd_(jobu2, jobu1, jobv2t, jobv1t, trans, signst, m, &i__1, &i__2,
1023 &x22[x22_offset], ldx22, &x21[x21_offset], ldx21, &x12[
1024 x12_offset], ldx12, &x11[x11_offset], ldx11, &theta[1], &u2[
1025 u2_offset], ldu2, &u1[u1_offset], ldu1, &v2t[v2t_offset],
1026 ldv2t, &v1t[v1t_offset], ldv1t, &work[1], lwork, &rwork[1],
1027 lrwork, &iwork[1], info);
1031 /* Compute workspace */
1035 /* Real workspace */
1039 i__1 = 1, i__2 = *q - 1;
1040 ib11d = iphi + f2cmax(i__1,i__2);
1041 ib11e = ib11d + f2cmax(1,*q);
1043 i__1 = 1, i__2 = *q - 1;
1044 ib12d = ib11e + f2cmax(i__1,i__2);
1045 ib12e = ib12d + f2cmax(1,*q);
1047 i__1 = 1, i__2 = *q - 1;
1048 ib21d = ib12e + f2cmax(i__1,i__2);
1049 ib21e = ib21d + f2cmax(1,*q);
1051 i__1 = 1, i__2 = *q - 1;
1052 ib22d = ib21e + f2cmax(i__1,i__2);
1053 ib22e = ib22d + f2cmax(1,*q);
1055 i__1 = 1, i__2 = *q - 1;
1056 ibbcsd = ib22e + f2cmax(i__1,i__2);
1057 cbbcsd_(jobu1, jobu2, jobv1t, jobv2t, trans, m, p, q, &theta[1], &
1058 theta[1], &u1[u1_offset], ldu1, &u2[u2_offset], ldu2, &v1t[
1059 v1t_offset], ldv1t, &v2t[v2t_offset], ldv2t, &theta[1], &
1060 theta[1], &theta[1], &theta[1], &theta[1], &theta[1], &theta[
1061 1], &theta[1], &rwork[1], &c_n1, &childinfo);
1062 lbbcsdworkopt = (integer) rwork[1];
1063 lbbcsdworkmin = lbbcsdworkopt;
1064 lrworkopt = ibbcsd + lbbcsdworkopt - 1;
1065 lrworkmin = ibbcsd + lbbcsdworkmin - 1;
1066 rwork[1] = (real) lrworkopt;
1068 /* Complex workspace */
1071 itaup2 = itaup1 + f2cmax(1,*p);
1073 i__1 = 1, i__2 = *m - *p;
1074 itauq1 = itaup2 + f2cmax(i__1,i__2);
1075 itauq2 = itauq1 + f2cmax(1,*q);
1077 i__1 = 1, i__2 = *m - *q;
1078 iorgqr = itauq2 + f2cmax(i__1,i__2);
1083 i__5 = 1, i__6 = *m - *q;
1084 i__4 = f2cmax(i__5,i__6);
1085 cungqr_(&i__1, &i__2, &i__3, &u1[u1_offset], &i__4, &u1[u1_offset], &
1086 work[1], &c_n1, &childinfo);
1087 lorgqrworkopt = (integer) work[1].r;
1089 i__1 = 1, i__2 = *m - *q;
1090 lorgqrworkmin = f2cmax(i__1,i__2);
1092 i__1 = 1, i__2 = *m - *q;
1093 iorglq = itauq2 + f2cmax(i__1,i__2);
1098 i__5 = 1, i__6 = *m - *q;
1099 i__4 = f2cmax(i__5,i__6);
1100 cunglq_(&i__1, &i__2, &i__3, &u1[u1_offset], &i__4, &u1[u1_offset], &
1101 work[1], &c_n1, &childinfo);
1102 lorglqworkopt = (integer) work[1].r;
1104 i__1 = 1, i__2 = *m - *q;
1105 lorglqworkmin = f2cmax(i__1,i__2);
1107 i__1 = 1, i__2 = *m - *q;
1108 iorbdb = itauq2 + f2cmax(i__1,i__2);
1109 cunbdb_(trans, signs, m, p, q, &x11[x11_offset], ldx11, &x12[
1110 x12_offset], ldx12, &x21[x21_offset], ldx21, &x22[x22_offset],
1111 ldx22, &theta[1], &theta[1], &u1[u1_offset], &u2[u2_offset],
1112 &v1t[v1t_offset], &v2t[v2t_offset], &work[1], &c_n1, &
1114 lorbdbworkopt = (integer) work[1].r;
1115 lorbdbworkmin = lorbdbworkopt;
1117 i__1 = iorgqr + lorgqrworkopt, i__2 = iorglq + lorglqworkopt, i__1 =
1118 f2cmax(i__1,i__2), i__2 = iorbdb + lorbdbworkopt;
1119 lworkopt = f2cmax(i__1,i__2) - 1;
1121 i__1 = iorgqr + lorgqrworkmin, i__2 = iorglq + lorglqworkmin, i__1 =
1122 f2cmax(i__1,i__2), i__2 = iorbdb + lorbdbworkmin;
1123 lworkmin = f2cmax(i__1,i__2) - 1;
1124 i__1 = f2cmax(lworkopt,lworkmin);
1125 work[1].r = (real) i__1, work[1].i = 0.f;
1127 if (*lwork < lworkmin && ! (lquery || lrquery)) {
1129 } else if (*lrwork < lrworkmin && ! (lquery || lrquery)) {
1132 lorgqrwork = *lwork - iorgqr + 1;
1133 lorglqwork = *lwork - iorglq + 1;
1134 lorbdbwork = *lwork - iorbdb + 1;
1135 lbbcsdwork = *lrwork - ibbcsd + 1;
1139 /* Abort if any illegal arguments */
1143 xerbla_("CUNCSD", &i__1, (ftnlen)6);
1145 } else if (lquery || lrquery) {
1149 /* Transform to bidiagonal block form */
1151 cunbdb_(trans, signs, m, p, q, &x11[x11_offset], ldx11, &x12[x12_offset],
1152 ldx12, &x21[x21_offset], ldx21, &x22[x22_offset], ldx22, &theta[1]
1153 , &rwork[iphi], &work[itaup1], &work[itaup2], &work[itauq1], &
1154 work[itauq2], &work[iorbdb], &lorbdbwork, &childinfo);
1156 /* Accumulate Householder reflectors */
1159 if (wantu1 && *p > 0) {
1160 clacpy_("L", p, q, &x11[x11_offset], ldx11, &u1[u1_offset], ldu1);
1161 cungqr_(p, p, q, &u1[u1_offset], ldu1, &work[itaup1], &work[
1162 iorgqr], &lorgqrwork, info);
1164 if (wantu2 && *m - *p > 0) {
1166 clacpy_("L", &i__1, q, &x21[x21_offset], ldx21, &u2[u2_offset],
1170 cungqr_(&i__1, &i__2, q, &u2[u2_offset], ldu2, &work[itaup2], &
1171 work[iorgqr], &lorgqrwork, info);
1173 if (wantv1t && *q > 0) {
1176 clacpy_("U", &i__1, &i__2, &x11[(x11_dim1 << 1) + 1], ldx11, &v1t[
1177 (v1t_dim1 << 1) + 2], ldv1t);
1178 i__1 = v1t_dim1 + 1;
1179 v1t[i__1].r = 1.f, v1t[i__1].i = 0.f;
1181 for (j = 2; j <= i__1; ++j) {
1182 i__2 = j * v1t_dim1 + 1;
1183 v1t[i__2].r = 0.f, v1t[i__2].i = 0.f;
1184 i__2 = j + v1t_dim1;
1185 v1t[i__2].r = 0.f, v1t[i__2].i = 0.f;
1190 cunglq_(&i__1, &i__2, &i__3, &v1t[(v1t_dim1 << 1) + 2], ldv1t, &
1191 work[itauq1], &work[iorglq], &lorglqwork, info);
1193 if (wantv2t && *m - *q > 0) {
1195 clacpy_("U", p, &i__1, &x12[x12_offset], ldx12, &v2t[v2t_offset],
1198 i__1 = *m - *p - *q;
1199 i__2 = *m - *p - *q;
1200 clacpy_("U", &i__1, &i__2, &x22[*q + 1 + (*p + 1) * x22_dim1],
1201 ldx22, &v2t[*p + 1 + (*p + 1) * v2t_dim1], ldv2t);
1207 cunglq_(&i__1, &i__2, &i__3, &v2t[v2t_offset], ldv2t, &work[
1208 itauq2], &work[iorglq], &lorglqwork, info);
1212 if (wantu1 && *p > 0) {
1213 clacpy_("U", q, p, &x11[x11_offset], ldx11, &u1[u1_offset], ldu1);
1214 cunglq_(p, p, q, &u1[u1_offset], ldu1, &work[itaup1], &work[
1215 iorglq], &lorglqwork, info);
1217 if (wantu2 && *m - *p > 0) {
1219 clacpy_("U", q, &i__1, &x21[x21_offset], ldx21, &u2[u2_offset],
1223 cunglq_(&i__1, &i__2, q, &u2[u2_offset], ldu2, &work[itaup2], &
1224 work[iorglq], &lorglqwork, info);
1226 if (wantv1t && *q > 0) {
1229 clacpy_("L", &i__1, &i__2, &x11[x11_dim1 + 2], ldx11, &v1t[(
1230 v1t_dim1 << 1) + 2], ldv1t);
1231 i__1 = v1t_dim1 + 1;
1232 v1t[i__1].r = 1.f, v1t[i__1].i = 0.f;
1234 for (j = 2; j <= i__1; ++j) {
1235 i__2 = j * v1t_dim1 + 1;
1236 v1t[i__2].r = 0.f, v1t[i__2].i = 0.f;
1237 i__2 = j + v1t_dim1;
1238 v1t[i__2].r = 0.f, v1t[i__2].i = 0.f;
1243 cungqr_(&i__1, &i__2, &i__3, &v1t[(v1t_dim1 << 1) + 2], ldv1t, &
1244 work[itauq1], &work[iorgqr], &lorgqrwork, info);
1246 if (wantv2t && *m - *q > 0) {
1249 p1 = f2cmin(i__1,*m);
1252 q1 = f2cmin(i__1,*m);
1254 clacpy_("L", &i__1, p, &x12[x12_offset], ldx12, &v2t[v2t_offset],
1257 i__1 = *m - *p - *q;
1258 i__2 = *m - *p - *q;
1259 clacpy_("L", &i__1, &i__2, &x22[p1 + q1 * x22_dim1], ldx22, &
1260 v2t[*p + 1 + (*p + 1) * v2t_dim1], ldv2t);
1265 cungqr_(&i__1, &i__2, &i__3, &v2t[v2t_offset], ldv2t, &work[
1266 itauq2], &work[iorgqr], &lorgqrwork, info);
1270 /* Compute the CSD of the matrix in bidiagonal-block form */
1272 cbbcsd_(jobu1, jobu2, jobv1t, jobv2t, trans, m, p, q, &theta[1], &rwork[
1273 iphi], &u1[u1_offset], ldu1, &u2[u2_offset], ldu2, &v1t[
1274 v1t_offset], ldv1t, &v2t[v2t_offset], ldv2t, &rwork[ib11d], &
1275 rwork[ib11e], &rwork[ib12d], &rwork[ib12e], &rwork[ib21d], &rwork[
1276 ib21e], &rwork[ib22d], &rwork[ib22e], &rwork[ibbcsd], &lbbcsdwork,
1279 /* Permute rows and columns to place identity submatrices in top- */
1280 /* left corner of (1,1)-block and/or bottom-right corner of (1,2)- */
1281 /* block and/or bottom-right corner of (2,1)-block and/or top-left */
1282 /* corner of (2,2)-block */
1284 if (*q > 0 && wantu2) {
1286 for (i__ = 1; i__ <= i__1; ++i__) {
1287 iwork[i__] = *m - *p - *q + i__;
1290 for (i__ = *q + 1; i__ <= i__1; ++i__) {
1291 iwork[i__] = i__ - *q;
1296 clapmt_(&c_false, &i__1, &i__2, &u2[u2_offset], ldu2, &iwork[1]);
1300 clapmr_(&c_false, &i__1, &i__2, &u2[u2_offset], ldu2, &iwork[1]);
1303 if (*m > 0 && wantv2t) {
1305 for (i__ = 1; i__ <= i__1; ++i__) {
1306 iwork[i__] = *m - *p - *q + i__;
1309 for (i__ = *p + 1; i__ <= i__1; ++i__) {
1310 iwork[i__] = i__ - *p;
1315 clapmt_(&c_false, &i__1, &i__2, &v2t[v2t_offset], ldv2t, &iwork[1]
1320 clapmr_(&c_false, &i__1, &i__2, &v2t[v2t_offset], ldv2t, &iwork[1]