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]/Cd(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)
514 /* Table of constant values */
516 static complex c_b1 = {0.f,0.f};
517 static complex c_b2 = {1.f,0.f};
518 static real c_b3 = 0.f;
519 static integer c__1 = 1;
520 static real c_b40 = -1.f;
521 static real c_b43 = 1.f;
523 /* > \brief \b CTGSJA */
525 /* =========== DOCUMENTATION =========== */
527 /* Online html documentation available at */
528 /* http://www.netlib.org/lapack/explore-html/ */
531 /* > Download CTGSJA + dependencies */
532 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/ctgsja.
535 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/ctgsja.
538 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/ctgsja.
546 /* SUBROUTINE CTGSJA( JOBU, JOBV, JOBQ, M, P, N, K, L, A, LDA, B, */
547 /* LDB, TOLA, TOLB, ALPHA, BETA, U, LDU, V, LDV, */
548 /* Q, LDQ, WORK, NCALL MYCYCLE, INFO ) */
550 /* CHARACTER JOBQ, JOBU, JOBV */
551 /* INTEGER INFO, K, L, LDA, LDB, LDQ, LDU, LDV, M, N, */
552 /* $ NCALL MYCYCLE, P */
553 /* REAL TOLA, TOLB */
554 /* REAL ALPHA( * ), BETA( * ) */
555 /* COMPLEX A( LDA, * ), B( LDB, * ), Q( LDQ, * ), */
556 /* $ U( LDU, * ), V( LDV, * ), WORK( * ) */
559 /* > \par Purpose: */
564 /* > CTGSJA computes the generalized singular value decomposition (GSVD) */
565 /* > of two complex upper triangular (or trapezoidal) matrices A and B. */
567 /* > On entry, it is assumed that matrices A and B have the following */
568 /* > forms, which may be obtained by the preprocessing subroutine CGGSVP */
569 /* > from a general M-by-N matrix A and P-by-N matrix B: */
572 /* > A = K ( 0 A12 A13 ) if M-K-L >= 0; */
573 /* > L ( 0 0 A23 ) */
574 /* > M-K-L ( 0 0 0 ) */
577 /* > A = K ( 0 A12 A13 ) if M-K-L < 0; */
578 /* > M-K ( 0 0 A23 ) */
581 /* > B = L ( 0 0 B13 ) */
582 /* > P-L ( 0 0 0 ) */
584 /* > where the K-by-K matrix A12 and L-by-L matrix B13 are nonsingular */
585 /* > upper triangular; A23 is L-by-L upper triangular if M-K-L >= 0, */
586 /* > otherwise A23 is (M-K)-by-L upper trapezoidal. */
590 /* > U**H *A*Q = D1*( 0 R ), V**H *B*Q = D2*( 0 R ), */
592 /* > where U, V and Q are unitary matrices. */
593 /* > R is a nonsingular upper triangular matrix, and D1 */
594 /* > and D2 are ``diagonal'' matrices, which are of the following */
597 /* > If M-K-L >= 0, */
600 /* > D1 = K ( I 0 ) */
602 /* > M-K-L ( 0 0 ) */
605 /* > D2 = L ( 0 S ) */
609 /* > ( 0 R ) = K ( 0 R11 R12 ) K */
610 /* > L ( 0 0 R22 ) L */
614 /* > C = diag( ALPHA(K+1), ... , ALPHA(K+L) ), */
615 /* > S = diag( BETA(K+1), ... , BETA(K+L) ), */
616 /* > C**2 + S**2 = I. */
618 /* > R is stored in A(1:K+L,N-K-L+1:N) on exit. */
620 /* > If M-K-L < 0, */
623 /* > D1 = K ( I 0 0 ) */
624 /* > M-K ( 0 C 0 ) */
627 /* > D2 = M-K ( 0 S 0 ) */
628 /* > K+L-M ( 0 0 I ) */
629 /* > P-L ( 0 0 0 ) */
631 /* > N-K-L K M-K K+L-M */
632 /* > ( 0 R ) = K ( 0 R11 R12 R13 ) */
633 /* > M-K ( 0 0 R22 R23 ) */
634 /* > K+L-M ( 0 0 0 R33 ) */
637 /* > C = diag( ALPHA(K+1), ... , ALPHA(M) ), */
638 /* > S = diag( BETA(K+1), ... , BETA(M) ), */
639 /* > C**2 + S**2 = I. */
641 /* > R = ( R11 R12 R13 ) is stored in A(1:M, N-K-L+1:N) and R33 is stored */
642 /* > ( 0 R22 R23 ) */
643 /* > in B(M-K+1:L,N+M-K-L+1:N) on exit. */
645 /* > The computation of the unitary transformation matrices U, V or Q */
646 /* > is optional. These matrices may either be formed explicitly, or they */
647 /* > may be postmultiplied into input matrices U1, V1, or Q1. */
653 /* > \param[in] JOBU */
655 /* > JOBU is CHARACTER*1 */
656 /* > = 'U': U must contain a unitary matrix U1 on entry, and */
657 /* > the product U1*U is returned; */
658 /* > = 'I': U is initialized to the unit matrix, and the */
659 /* > unitary matrix U is returned; */
660 /* > = 'N': U is not computed. */
663 /* > \param[in] JOBV */
665 /* > JOBV is CHARACTER*1 */
666 /* > = 'V': V must contain a unitary matrix V1 on entry, and */
667 /* > the product V1*V is returned; */
668 /* > = 'I': V is initialized to the unit matrix, and the */
669 /* > unitary matrix V is returned; */
670 /* > = 'N': V is not computed. */
673 /* > \param[in] JOBQ */
675 /* > JOBQ is CHARACTER*1 */
676 /* > = 'Q': Q must contain a unitary matrix Q1 on entry, and */
677 /* > the product Q1*Q is returned; */
678 /* > = 'I': Q is initialized to the unit matrix, and the */
679 /* > unitary matrix Q is returned; */
680 /* > = 'N': Q is not computed. */
686 /* > The number of rows of the matrix A. M >= 0. */
692 /* > The number of rows of the matrix B. P >= 0. */
698 /* > The number of columns of the matrices A and B. N >= 0. */
710 /* > K and L specify the subblocks in the input matrices A and B: */
711 /* > A23 = A(K+1:MIN(K+L,M),N-L+1:N) and B13 = B(1:L,,N-L+1:N) */
712 /* > of A and B, whose GSVD is going to be computed by CTGSJA. */
713 /* > See Further Details. */
716 /* > \param[in,out] A */
718 /* > A is COMPLEX array, dimension (LDA,N) */
719 /* > On entry, the M-by-N matrix A. */
720 /* > On exit, A(N-K+1:N,1:MIN(K+L,M) ) contains the triangular */
721 /* > matrix R or part of R. See Purpose for details. */
724 /* > \param[in] LDA */
726 /* > LDA is INTEGER */
727 /* > The leading dimension of the array A. LDA >= f2cmax(1,M). */
730 /* > \param[in,out] B */
732 /* > B is COMPLEX array, dimension (LDB,N) */
733 /* > On entry, the P-by-N matrix B. */
734 /* > On exit, if necessary, B(M-K+1:L,N+M-K-L+1:N) contains */
735 /* > a part of R. See Purpose for details. */
738 /* > \param[in] LDB */
740 /* > LDB is INTEGER */
741 /* > The leading dimension of the array B. LDB >= f2cmax(1,P). */
744 /* > \param[in] TOLA */
749 /* > \param[in] TOLB */
753 /* > TOLA and TOLB are the convergence criteria for the Jacobi- */
754 /* > Kogbetliantz iteration procedure. Generally, they are the */
755 /* > same as used in the preprocessing step, say */
756 /* > TOLA = MAX(M,N)*norm(A)*MACHEPS, */
757 /* > TOLB = MAX(P,N)*norm(B)*MACHEPS. */
760 /* > \param[out] ALPHA */
762 /* > ALPHA is REAL array, dimension (N) */
765 /* > \param[out] BETA */
767 /* > BETA is REAL array, dimension (N) */
769 /* > On exit, ALPHA and BETA contain the generalized singular */
770 /* > value pairs of A and B; */
771 /* > ALPHA(1:K) = 1, */
772 /* > BETA(1:K) = 0, */
773 /* > and if M-K-L >= 0, */
774 /* > ALPHA(K+1:K+L) = diag(C), */
775 /* > BETA(K+1:K+L) = diag(S), */
776 /* > or if M-K-L < 0, */
777 /* > ALPHA(K+1:M)= C, ALPHA(M+1:K+L)= 0 */
778 /* > BETA(K+1:M) = S, BETA(M+1:K+L) = 1. */
779 /* > Furthermore, if K+L < N, */
780 /* > ALPHA(K+L+1:N) = 0 */
781 /* > BETA(K+L+1:N) = 0. */
784 /* > \param[in,out] U */
786 /* > U is COMPLEX array, dimension (LDU,M) */
787 /* > On entry, if JOBU = 'U', U must contain a matrix U1 (usually */
788 /* > the unitary matrix returned by CGGSVP). */
790 /* > if JOBU = 'I', U contains the unitary matrix U; */
791 /* > if JOBU = 'U', U contains the product U1*U. */
792 /* > If JOBU = 'N', U is not referenced. */
795 /* > \param[in] LDU */
797 /* > LDU is INTEGER */
798 /* > The leading dimension of the array U. LDU >= f2cmax(1,M) if */
799 /* > JOBU = 'U'; LDU >= 1 otherwise. */
802 /* > \param[in,out] V */
804 /* > V is COMPLEX array, dimension (LDV,P) */
805 /* > On entry, if JOBV = 'V', V must contain a matrix V1 (usually */
806 /* > the unitary matrix returned by CGGSVP). */
808 /* > if JOBV = 'I', V contains the unitary matrix V; */
809 /* > if JOBV = 'V', V contains the product V1*V. */
810 /* > If JOBV = 'N', V is not referenced. */
813 /* > \param[in] LDV */
815 /* > LDV is INTEGER */
816 /* > The leading dimension of the array V. LDV >= f2cmax(1,P) if */
817 /* > JOBV = 'V'; LDV >= 1 otherwise. */
820 /* > \param[in,out] Q */
822 /* > Q is COMPLEX array, dimension (LDQ,N) */
823 /* > On entry, if JOBQ = 'Q', Q must contain a matrix Q1 (usually */
824 /* > the unitary matrix returned by CGGSVP). */
826 /* > if JOBQ = 'I', Q contains the unitary matrix Q; */
827 /* > if JOBQ = 'Q', Q contains the product Q1*Q. */
828 /* > If JOBQ = 'N', Q is not referenced. */
831 /* > \param[in] LDQ */
833 /* > LDQ is INTEGER */
834 /* > The leading dimension of the array Q. LDQ >= f2cmax(1,N) if */
835 /* > JOBQ = 'Q'; LDQ >= 1 otherwise. */
838 /* > \param[out] WORK */
840 /* > WORK is COMPLEX array, dimension (2*N) */
843 /* > \param[out] NCALL MYCYCLE */
845 /* > NCALL MYCYCLE is INTEGER */
846 /* > The number of cycles required for convergence. */
849 /* > \param[out] INFO */
851 /* > INFO is INTEGER */
852 /* > = 0: successful exit */
853 /* > < 0: if INFO = -i, the i-th argument had an illegal value. */
854 /* > = 1: the procedure does not converge after MAXIT cycles. */
857 /* > \par Internal Parameters: */
858 /* ========================= */
861 /* > MAXIT INTEGER */
862 /* > MAXIT specifies the total loops that the iterative procedure */
863 /* > may take. If after MAXIT cycles, the routine fails to */
864 /* > converge, we return INFO = 1. */
870 /* > \author Univ. of Tennessee */
871 /* > \author Univ. of California Berkeley */
872 /* > \author Univ. of Colorado Denver */
873 /* > \author NAG Ltd. */
875 /* > \date December 2016 */
877 /* > \ingroup complexOTHERcomputational */
879 /* > \par Further Details: */
880 /* ===================== */
884 /* > CTGSJA essentially uses a variant of Kogbetliantz algorithm to reduce */
885 /* > f2cmin(L,M-K)-by-L triangular (or trapezoidal) matrix A23 and L-by-L */
886 /* > matrix B13 to the form: */
888 /* > U1**H *A13*Q1 = C1*R1; V1**H *B13*Q1 = S1*R1, */
890 /* > where U1, V1 and Q1 are unitary matrix. */
891 /* > C1 and S1 are diagonal matrices satisfying */
893 /* > C1**2 + S1**2 = I, */
895 /* > and R1 is an L-by-L nonsingular upper triangular matrix. */
898 /* ===================================================================== */
899 /* Subroutine */ int ctgsja_(char *jobu, char *jobv, char *jobq, integer *m,
900 integer *p, integer *n, integer *k, integer *l, complex *a, integer *
901 lda, complex *b, integer *ldb, real *tola, real *tolb, real *alpha,
902 real *beta, complex *u, integer *ldu, complex *v, integer *ldv,
903 complex *q, integer *ldq, complex *work, integer *ncallmycycle,
906 /* System generated locals */
907 integer a_dim1, a_offset, b_dim1, b_offset, q_dim1, q_offset, u_dim1,
908 u_offset, v_dim1, v_offset, i__1, i__2, i__3, i__4;
912 /* Local variables */
913 extern /* Subroutine */ int crot_(integer *, complex *, integer *,
914 complex *, integer *, real *, complex *);
915 integer kcallmycycle, i__, j;
917 extern logical lsame_(char *, char *);
918 extern /* Subroutine */ int ccopy_(integer *, complex *, integer *,
919 complex *, integer *);
922 logical initu, initv, wantq, upper;
924 logical wantu, wantv;
927 extern /* Subroutine */ int clags2_(logical *, real *, complex *, real *,
928 real *, complex *, real *, real *, complex *, real *, complex *,
929 real *, complex *), clapll_(integer *, complex *, integer *,
930 complex *, integer *, real *), csscal_(integer *, real *, complex
931 *, integer *), claset_(char *, integer *, integer *, complex *,
932 complex *, complex *, integer *), xerbla_(char *, integer
933 *, ftnlen), slartg_(real *, real *, real *, real *, real *);
934 // extern integer myhuge_(real *);
941 /* -- LAPACK computational routine (version 3.7.0) -- */
942 /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
943 /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
947 /* ===================================================================== */
951 /* Decode and test the input parameters */
953 /* Parameter adjustments */
955 a_offset = 1 + a_dim1 * 1;
958 b_offset = 1 + b_dim1 * 1;
963 u_offset = 1 + u_dim1 * 1;
966 v_offset = 1 + v_dim1 * 1;
969 q_offset = 1 + q_dim1 * 1;
974 initu = lsame_(jobu, "I");
975 wantu = initu || lsame_(jobu, "U");
977 initv = lsame_(jobv, "I");
978 wantv = initv || lsame_(jobv, "V");
980 initq = lsame_(jobq, "I");
981 wantq = initq || lsame_(jobq, "Q");
984 if (! (initu || wantu || lsame_(jobu, "N"))) {
986 } else if (! (initv || wantv || lsame_(jobv, "N")))
989 } else if (! (initq || wantq || lsame_(jobq, "N")))
998 } else if (*lda < f2cmax(1,*m)) {
1000 } else if (*ldb < f2cmax(1,*p)) {
1002 } else if (*ldu < 1 || wantu && *ldu < *m) {
1004 } else if (*ldv < 1 || wantv && *ldv < *p) {
1006 } else if (*ldq < 1 || wantq && *ldq < *n) {
1011 xerbla_("CTGSJA", &i__1, (ftnlen)6);
1015 /* Initialize U, V and Q, if necessary */
1018 claset_("Full", m, m, &c_b1, &c_b2, &u[u_offset], ldu);
1021 claset_("Full", p, p, &c_b1, &c_b2, &v[v_offset], ldv);
1024 claset_("Full", n, n, &c_b1, &c_b2, &q[q_offset], ldq);
1027 /* Loop until convergence */
1030 for (kcallmycycle = 1; kcallmycycle <= 40; ++kcallmycycle) {
1035 for (i__ = 1; i__ <= i__1; ++i__) {
1037 for (j = i__ + 1; j <= i__2; ++j) {
1040 a2.r = 0.f, a2.i = 0.f;
1042 if (*k + i__ <= *m) {
1043 i__3 = *k + i__ + (*n - *l + i__) * a_dim1;
1047 i__3 = *k + j + (*n - *l + j) * a_dim1;
1051 i__3 = i__ + (*n - *l + i__) * b_dim1;
1053 i__3 = j + (*n - *l + j) * b_dim1;
1057 if (*k + i__ <= *m) {
1058 i__3 = *k + i__ + (*n - *l + j) * a_dim1;
1059 a2.r = a[i__3].r, a2.i = a[i__3].i;
1061 i__3 = i__ + (*n - *l + j) * b_dim1;
1062 b2.r = b[i__3].r, b2.i = b[i__3].i;
1065 i__3 = *k + j + (*n - *l + i__) * a_dim1;
1066 a2.r = a[i__3].r, a2.i = a[i__3].i;
1068 i__3 = j + (*n - *l + i__) * b_dim1;
1069 b2.r = b[i__3].r, b2.i = b[i__3].i;
1072 clags2_(&upper, &a1, &a2, &a3, &b1, &b2, &b3, &csu, &snu, &
1073 csv, &snv, &csq, &snq);
1075 /* Update (K+I)-th and (K+J)-th rows of matrix A: U**H *A */
1078 r_cnjg(&q__1, &snu);
1079 crot_(l, &a[*k + j + (*n - *l + 1) * a_dim1], lda, &a[*k
1080 + i__ + (*n - *l + 1) * a_dim1], lda, &csu, &q__1)
1084 /* Update I-th and J-th rows of matrix B: V**H *B */
1086 r_cnjg(&q__1, &snv);
1087 crot_(l, &b[j + (*n - *l + 1) * b_dim1], ldb, &b[i__ + (*n - *
1088 l + 1) * b_dim1], ldb, &csv, &q__1);
1090 /* Update (N-L+I)-th and (N-L+J)-th columns of matrices */
1091 /* A and B: A*Q and B*Q */
1095 i__3 = f2cmin(i__4,*m);
1096 crot_(&i__3, &a[(*n - *l + j) * a_dim1 + 1], &c__1, &a[(*n - *
1097 l + i__) * a_dim1 + 1], &c__1, &csq, &snq);
1099 crot_(l, &b[(*n - *l + j) * b_dim1 + 1], &c__1, &b[(*n - *l +
1100 i__) * b_dim1 + 1], &c__1, &csq, &snq);
1103 if (*k + i__ <= *m) {
1104 i__3 = *k + i__ + (*n - *l + j) * a_dim1;
1105 a[i__3].r = 0.f, a[i__3].i = 0.f;
1107 i__3 = i__ + (*n - *l + j) * b_dim1;
1108 b[i__3].r = 0.f, b[i__3].i = 0.f;
1111 i__3 = *k + j + (*n - *l + i__) * a_dim1;
1112 a[i__3].r = 0.f, a[i__3].i = 0.f;
1114 i__3 = j + (*n - *l + i__) * b_dim1;
1115 b[i__3].r = 0.f, b[i__3].i = 0.f;
1118 /* Ensure that the diagonal elements of A and B are real. */
1120 if (*k + i__ <= *m) {
1121 i__3 = *k + i__ + (*n - *l + i__) * a_dim1;
1122 i__4 = *k + i__ + (*n - *l + i__) * a_dim1;
1124 a[i__3].r = r__1, a[i__3].i = 0.f;
1127 i__3 = *k + j + (*n - *l + j) * a_dim1;
1128 i__4 = *k + j + (*n - *l + j) * a_dim1;
1130 a[i__3].r = r__1, a[i__3].i = 0.f;
1132 i__3 = i__ + (*n - *l + i__) * b_dim1;
1133 i__4 = i__ + (*n - *l + i__) * b_dim1;
1135 b[i__3].r = r__1, b[i__3].i = 0.f;
1136 i__3 = j + (*n - *l + j) * b_dim1;
1137 i__4 = j + (*n - *l + j) * b_dim1;
1139 b[i__3].r = r__1, b[i__3].i = 0.f;
1141 /* Update unitary matrices U, V, Q, if desired. */
1143 if (wantu && *k + j <= *m) {
1144 crot_(m, &u[(*k + j) * u_dim1 + 1], &c__1, &u[(*k + i__) *
1145 u_dim1 + 1], &c__1, &csu, &snu);
1149 crot_(p, &v[j * v_dim1 + 1], &c__1, &v[i__ * v_dim1 + 1],
1154 crot_(n, &q[(*n - *l + j) * q_dim1 + 1], &c__1, &q[(*n - *
1155 l + i__) * q_dim1 + 1], &c__1, &csq, &snq);
1165 /* The matrices A13 and B13 were lower triangular at the start */
1166 /* of the cycle, and are now upper triangular. */
1168 /* Convergence test: test the parallelism of the corresponding */
1169 /* rows of A and B. */
1173 i__2 = *l, i__3 = *m - *k;
1174 i__1 = f2cmin(i__2,i__3);
1175 for (i__ = 1; i__ <= i__1; ++i__) {
1176 i__2 = *l - i__ + 1;
1177 ccopy_(&i__2, &a[*k + i__ + (*n - *l + i__) * a_dim1], lda, &
1179 i__2 = *l - i__ + 1;
1180 ccopy_(&i__2, &b[i__ + (*n - *l + i__) * b_dim1], ldb, &work[*
1182 i__2 = *l - i__ + 1;
1183 clapll_(&i__2, &work[1], &c__1, &work[*l + 1], &c__1, &ssmin);
1184 error = f2cmax(error,ssmin);
1188 if (abs(error) <= f2cmin(*tola,*tolb)) {
1193 /* End of cycle loop */
1198 /* The algorithm has not converged after MAXIT cycles. */
1205 /* If ERROR <= MIN(TOLA,TOLB), then the algorithm has converged. */
1206 /* Compute the generalized singular value pairs (ALPHA, BETA), and */
1207 /* set the triangular matrix R to array A. */
1210 for (i__ = 1; i__ <= i__1; ++i__) {
1217 i__2 = *l, i__3 = *m - *k;
1218 i__1 = f2cmin(i__2,i__3);
1219 for (i__ = 1; i__ <= i__1; ++i__) {
1221 i__2 = *k + i__ + (*n - *l + i__) * a_dim1;
1223 i__2 = i__ + (*n - *l + i__) * b_dim1;
1227 if (gamma <= (real) myhuge_(&c_b3) && gamma >= -((real) myhuge_(&c_b3)
1231 i__2 = *l - i__ + 1;
1232 csscal_(&i__2, &c_b40, &b[i__ + (*n - *l + i__) * b_dim1],
1235 csscal_(p, &c_b40, &v[i__ * v_dim1 + 1], &c__1);
1240 slartg_(&r__1, &c_b43, &beta[*k + i__], &alpha[*k + i__], &rwk);
1242 if (alpha[*k + i__] >= beta[*k + i__]) {
1243 i__2 = *l - i__ + 1;
1244 r__1 = 1.f / alpha[*k + i__];
1245 csscal_(&i__2, &r__1, &a[*k + i__ + (*n - *l + i__) * a_dim1],
1248 i__2 = *l - i__ + 1;
1249 r__1 = 1.f / beta[*k + i__];
1250 csscal_(&i__2, &r__1, &b[i__ + (*n - *l + i__) * b_dim1], ldb)
1252 i__2 = *l - i__ + 1;
1253 ccopy_(&i__2, &b[i__ + (*n - *l + i__) * b_dim1], ldb, &a[*k
1254 + i__ + (*n - *l + i__) * a_dim1], lda);
1258 alpha[*k + i__] = 0.f;
1259 beta[*k + i__] = 1.f;
1260 i__2 = *l - i__ + 1;
1261 ccopy_(&i__2, &b[i__ + (*n - *l + i__) * b_dim1], ldb, &a[*k +
1262 i__ + (*n - *l + i__) * a_dim1], lda);
1267 /* Post-assignment */
1270 for (i__ = *m + 1; i__ <= i__1; ++i__) {
1278 for (i__ = *k + *l + 1; i__ <= i__1; ++i__) {
1286 *ncallmycycle = kcallmycycle;