/* Subroutine */ int zungbr_(char *vect, integer *m, integer *n, integer *k, doublecomplex *a, integer *lda, doublecomplex *tau, doublecomplex * work, integer *lwork, integer *info) { /* System generated locals */ integer a_dim1, a_offset, i__1, i__2, i__3; /* Local variables */ integer i__, j, nb, mn; extern logical lsame_(char *, char *); integer iinfo; logical wantq; extern /* Subroutine */ int xerbla_(char *, integer *); extern integer ilaenv_(integer *, char *, char *, integer *, integer *, integer *, integer *); integer lwkopt; logical lquery; extern /* Subroutine */ int zunglq_(integer *, integer *, integer *, doublecomplex *, integer *, doublecomplex *, doublecomplex *, integer *, integer *), zungqr_(integer *, integer *, integer *, doublecomplex *, integer *, doublecomplex *, doublecomplex *, integer *, integer *); /* -- LAPACK routine (version 3.2) -- */ /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */ /* November 2006 */ /* .. Scalar Arguments .. */ /* .. */ /* .. Array Arguments .. */ /* .. */ /* Purpose */ /* ======= */ /* ZUNGBR generates one of the complex unitary matrices Q or P**H */ /* determined by ZGEBRD when reducing a complex matrix A to bidiagonal */ /* form: A = Q * B * P**H. Q and P**H are defined as products of */ /* elementary reflectors H(i) or G(i) respectively. */ /* If VECT = 'Q', A is assumed to have been an M-by-K matrix, and Q */ /* is of order M: */ /* if m >= k, Q = H(1) H(2) . . . H(k) and ZUNGBR returns the first n */ /* columns of Q, where m >= n >= k; */ /* if m < k, Q = H(1) H(2) . . . H(m-1) and ZUNGBR returns Q as an */ /* M-by-M matrix. */ /* If VECT = 'P', A is assumed to have been a K-by-N matrix, and P**H */ /* is of order N: */ /* if k < n, P**H = G(k) . . . G(2) G(1) and ZUNGBR returns the first m */ /* rows of P**H, where n >= m >= k; */ /* if k >= n, P**H = G(n-1) . . . G(2) G(1) and ZUNGBR returns P**H as */ /* an N-by-N matrix. */ /* Arguments */ /* ========= */ /* VECT (input) CHARACTER*1 */ /* Specifies whether the matrix Q or the matrix P**H is */ /* required, as defined in the transformation applied by ZGEBRD: */ /* = 'Q': generate Q; */ /* = 'P': generate P**H. */ /* M (input) INTEGER */ /* The number of rows of the matrix Q or P**H to be returned. */ /* M >= 0. */ /* N (input) INTEGER */ /* The number of columns of the matrix Q or P**H to be returned. */ /* N >= 0. */ /* If VECT = 'Q', M >= N >= lmin(M,K); */ /* if VECT = 'P', N >= M >= lmin(N,K). */ /* K (input) INTEGER */ /* If VECT = 'Q', the number of columns in the original M-by-K */ /* matrix reduced by ZGEBRD. */ /* If VECT = 'P', the number of rows in the original K-by-N */ /* matrix reduced by ZGEBRD. */ /* K >= 0. */ /* A (input/output) COMPLEX*16 array, dimension (LDA,N) */ /* On entry, the vectors which define the elementary reflectors, */ /* as returned by ZGEBRD. */ /* On exit, the M-by-N matrix Q or P**H. */ /* LDA (input) INTEGER */ /* The leading dimension of the array A. LDA >= M. */ /* TAU (input) COMPLEX*16 array, dimension */ /* (min(M,K)) if VECT = 'Q' */ /* (min(N,K)) if VECT = 'P' */ /* TAU(i) must contain the scalar factor of the elementary */ /* reflector H(i) or G(i), which determines Q or P**H, as */ /* returned by ZGEBRD in its array argument TAUQ or TAUP. */ /* WORK (workspace/output) COMPLEX*16 array, dimension (MAX(1,LWORK)) */ /* On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */ /* LWORK (input) INTEGER */ /* The dimension of the array WORK. LWORK >= lmax(1,min(M,N)). */ /* For optimum performance LWORK >= lmin(M,N)*NB, where NB */ /* is the optimal blocksize. */ /* If LWORK = -1, then a workspace query is assumed; the routine */ /* only calculates the optimal size of the WORK array, returns */ /* this value as the first entry of the WORK array, and no error */ /* message related to LWORK is issued by XERBLA. */ /* INFO (output) INTEGER */ /* = 0: successful exit */ /* < 0: if INFO = -i, the i-th argument had an illegal value */ /* ===================================================================== */ /* .. Parameters .. */ /* .. */ /* .. Local Scalars .. */ /* .. */ /* .. External Functions .. */ /* .. */ /* .. External Subroutines .. */ /* .. */ /* .. Intrinsic Functions .. */ /* .. */ /* .. Executable Statements .. */ /* Test the input arguments */ /* Parameter adjustments */ a_dim1 = *lda; a_offset = 1 + a_dim1; a -= a_offset; --tau; --work; /* Function Body */ *info = 0; wantq = lsame_(vect, "Q"); mn = lmin(*m,*n); lquery = *lwork == -1; if (! wantq && ! lsame_(vect, "P")) { *info = -1; } else if (*m < 0) { *info = -2; } else if (*n < 0 || wantq && (*n > *m || *n < lmin(*m,*k)) || ! wantq && ( *m > *n || *m < lmin(*n,*k))) { *info = -3; } else if (*k < 0) { *info = -4; } else if (*lda < lmax(1,*m)) { *info = -6; } else if (*lwork < lmax(1,mn) && ! lquery) { *info = -9; } if (*info == 0) { if (wantq) { nb = ilaenv_(&c__1, "ZUNGQR", " ", m, n, k, &c_n1); } else { nb = ilaenv_(&c__1, "ZUNGLQ", " ", m, n, k, &c_n1); } lwkopt = lmax(1,mn) * nb; work[1].r = (doublereal) lwkopt, work[1].i = 0.; } if (*info != 0) { i__1 = -(*info); xerbla_("ZUNGBR", &i__1); return 0; } else if (lquery) { return 0; } /* Quick return if possible */ if (*m == 0 || *n == 0) { work[1].r = 1., work[1].i = 0.; return 0; } if (wantq) { /* Form Q, determined by a call to ZGEBRD to reduce an m-by-k */ /* matrix */ if (*m >= *k) { /* If m >= k, assume m >= n >= k */ zungqr_(m, n, k, &a[a_offset], lda, &tau[1], &work[1], lwork, & iinfo); } else { /* If m < k, assume m = n */ /* Shift the vectors which define the elementary reflectors one */ /* column to the right, and set the first row and column of Q */ /* to those of the unit matrix */ for (j = *m; j >= 2; --j) { i__1 = j * a_dim1 + 1; a[i__1].r = 0., a[i__1].i = 0.; i__1 = *m; for (i__ = j + 1; i__ <= i__1; ++i__) { i__2 = i__ + j * a_dim1; i__3 = i__ + (j - 1) * a_dim1; a[i__2].r = a[i__3].r, a[i__2].i = a[i__3].i; /* L10: */ } /* L20: */ } i__1 = a_dim1 + 1; a[i__1].r = 1., a[i__1].i = 0.; i__1 = *m; for (i__ = 2; i__ <= i__1; ++i__) { i__2 = i__ + a_dim1; a[i__2].r = 0., a[i__2].i = 0.; /* L30: */ } if (*m > 1) { /* Form Q(2:m,2:m) */ i__1 = *m - 1; i__2 = *m - 1; i__3 = *m - 1; zungqr_(&i__1, &i__2, &i__3, &a[(a_dim1 << 1) + 2], lda, &tau[ 1], &work[1], lwork, &iinfo); } } } else { /* Form P', determined by a call to ZGEBRD to reduce a k-by-n */ /* matrix */ if (*k < *n) { /* If k < n, assume k <= m <= n */ zunglq_(m, n, k, &a[a_offset], lda, &tau[1], &work[1], lwork, & iinfo); } else { /* If k >= n, assume m = n */ /* Shift the vectors which define the elementary reflectors one */ /* row downward, and set the first row and column of P' to */ /* those of the unit matrix */ i__1 = a_dim1 + 1; a[i__1].r = 1., a[i__1].i = 0.; i__1 = *n; for (i__ = 2; i__ <= i__1; ++i__) { i__2 = i__ + a_dim1; a[i__2].r = 0., a[i__2].i = 0.; /* L40: */ } i__1 = *n; for (j = 2; j <= i__1; ++j) { for (i__ = j - 1; i__ >= 2; --i__) { i__2 = i__ + j * a_dim1; i__3 = i__ - 1 + j * a_dim1; a[i__2].r = a[i__3].r, a[i__2].i = a[i__3].i; /* L50: */ } i__2 = j * a_dim1 + 1; a[i__2].r = 0., a[i__2].i = 0.; /* L60: */ } if (*n > 1) { /* Form P'(2:n,2:n) */ i__1 = *n - 1; i__2 = *n - 1; i__3 = *n - 1; zunglq_(&i__1, &i__2, &i__3, &a[(a_dim1 << 1) + 2], lda, &tau[ 1], &work[1], lwork, &iinfo); } } } work[1].r = (doublereal) lwkopt, work[1].i = 0.; return 0; /* End of ZUNGBR */ } /* zungbr_ */
int zgges_(char *jobvsl, char *jobvsr, char *sort, L_fp selctg, int *n, doublecomplex *a, int *lda, doublecomplex *b, int *ldb, int *sdim, doublecomplex *alpha, doublecomplex * beta, doublecomplex *vsl, int *ldvsl, doublecomplex *vsr, int *ldvsr, doublecomplex *work, int *lwork, double *rwork, int *bwork, int *info) { /* System generated locals */ int a_dim1, a_offset, b_dim1, b_offset, vsl_dim1, vsl_offset, vsr_dim1, vsr_offset, i__1, i__2; /* Builtin functions */ double sqrt(double); /* Local variables */ int i__; double dif[2]; int ihi, ilo; double eps, anrm, bnrm; int idum[1], ierr, itau, iwrk; double pvsl, pvsr; extern int lsame_(char *, char *); int ileft, icols; int cursl, ilvsl, ilvsr; int irwrk, irows; extern int dlabad_(double *, double *); extern double dlamch_(char *); extern int zggbak_(char *, char *, int *, int *, int *, double *, double *, int *, doublecomplex *, int *, int *), zggbal_(char *, int *, doublecomplex *, int *, doublecomplex *, int *, int * , int *, double *, double *, double *, int *); int ilascl, ilbscl; extern int xerbla_(char *, int *); extern int ilaenv_(int *, char *, char *, int *, int *, int *, int *); extern double zlange_(char *, int *, int *, doublecomplex *, int *, double *); double bignum; int ijobvl, iright; extern int zgghrd_(char *, char *, int *, int *, int *, doublecomplex *, int *, doublecomplex *, int *, doublecomplex *, int *, doublecomplex *, int *, int * ), zlascl_(char *, int *, int *, double *, double *, int *, int *, doublecomplex *, int *, int *); int ijobvr; extern int zgeqrf_(int *, int *, doublecomplex *, int *, doublecomplex *, doublecomplex *, int *, int * ); double anrmto; int lwkmin; int lastsl; double bnrmto; extern int zlacpy_(char *, int *, int *, doublecomplex *, int *, doublecomplex *, int *), zlaset_(char *, int *, int *, doublecomplex *, doublecomplex *, doublecomplex *, int *), zhgeqz_( char *, char *, char *, int *, int *, int *, doublecomplex *, int *, doublecomplex *, int *, doublecomplex *, doublecomplex *, doublecomplex *, int *, doublecomplex *, int *, doublecomplex *, int *, double *, int *), ztgsen_(int *, int *, int *, int *, int *, doublecomplex *, int *, doublecomplex *, int *, doublecomplex *, doublecomplex *, doublecomplex *, int *, doublecomplex *, int *, int *, double *, double *, double *, doublecomplex *, int *, int *, int *, int *); double smlnum; int wantst, lquery; int lwkopt; extern int zungqr_(int *, int *, int *, doublecomplex *, int *, doublecomplex *, doublecomplex *, int *, int *), zunmqr_(char *, char *, int *, int *, int *, doublecomplex *, int *, doublecomplex *, doublecomplex *, int *, doublecomplex *, int *, int *); /* -- LAPACK driver routine (version 3.2) -- */ /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */ /* November 2006 */ /* .. Scalar Arguments .. */ /* .. */ /* .. Array Arguments .. */ /* .. */ /* .. Function Arguments .. */ /* .. */ /* Purpose */ /* ======= */ /* ZGGES computes for a pair of N-by-N complex nonsymmetric matrices */ /* (A,B), the generalized eigenvalues, the generalized complex Schur */ /* form (S, T), and optionally left and/or right Schur vectors (VSL */ /* and VSR). This gives the generalized Schur factorization */ /* (A,B) = ( (VSL)*S*(VSR)**H, (VSL)*T*(VSR)**H ) */ /* where (VSR)**H is the conjugate-transpose of VSR. */ /* Optionally, it also orders the eigenvalues so that a selected cluster */ /* of eigenvalues appears in the leading diagonal blocks of the upper */ /* triangular matrix S and the upper triangular matrix T. The leading */ /* columns of VSL and VSR then form an unitary basis for the */ /* corresponding left and right eigenspaces (deflating subspaces). */ /* (If only the generalized eigenvalues are needed, use the driver */ /* ZGGEV instead, which is faster.) */ /* A generalized eigenvalue for a pair of matrices (A,B) is a scalar w */ /* or a ratio alpha/beta = w, such that A - w*B is singular. It is */ /* usually represented as the pair (alpha,beta), as there is a */ /* reasonable interpretation for beta=0, and even for both being zero. */ /* A pair of matrices (S,T) is in generalized complex Schur form if S */ /* and T are upper triangular and, in addition, the diagonal elements */ /* of T are non-negative float numbers. */ /* Arguments */ /* ========= */ /* JOBVSL (input) CHARACTER*1 */ /* = 'N': do not compute the left Schur vectors; */ /* = 'V': compute the left Schur vectors. */ /* JOBVSR (input) CHARACTER*1 */ /* = 'N': do not compute the right Schur vectors; */ /* = 'V': compute the right Schur vectors. */ /* SORT (input) CHARACTER*1 */ /* Specifies whether or not to order the eigenvalues on the */ /* diagonal of the generalized Schur form. */ /* = 'N': Eigenvalues are not ordered; */ /* = 'S': Eigenvalues are ordered (see SELCTG). */ /* SELCTG (external procedure) LOGICAL FUNCTION of two COMPLEX*16 arguments */ /* SELCTG must be declared EXTERNAL in the calling subroutine. */ /* If SORT = 'N', SELCTG is not referenced. */ /* If SORT = 'S', SELCTG is used to select eigenvalues to sort */ /* to the top left of the Schur form. */ /* An eigenvalue ALPHA(j)/BETA(j) is selected if */ /* SELCTG(ALPHA(j),BETA(j)) is true. */ /* Note that a selected complex eigenvalue may no longer satisfy */ /* SELCTG(ALPHA(j),BETA(j)) = .TRUE. after ordering, since */ /* ordering may change the value of complex eigenvalues */ /* (especially if the eigenvalue is ill-conditioned), in this */ /* case INFO is set to N+2 (See INFO below). */ /* N (input) INTEGER */ /* The order of the matrices A, B, VSL, and VSR. N >= 0. */ /* A (input/output) COMPLEX*16 array, dimension (LDA, N) */ /* On entry, the first of the pair of matrices. */ /* On exit, A has been overwritten by its generalized Schur */ /* form S. */ /* LDA (input) INTEGER */ /* The leading dimension of A. LDA >= MAX(1,N). */ /* B (input/output) COMPLEX*16 array, dimension (LDB, N) */ /* On entry, the second of the pair of matrices. */ /* On exit, B has been overwritten by its generalized Schur */ /* form T. */ /* LDB (input) INTEGER */ /* The leading dimension of B. LDB >= MAX(1,N). */ /* SDIM (output) INTEGER */ /* If SORT = 'N', SDIM = 0. */ /* If SORT = 'S', SDIM = number of eigenvalues (after sorting) */ /* for which SELCTG is true. */ /* ALPHA (output) COMPLEX*16 array, dimension (N) */ /* BETA (output) COMPLEX*16 array, dimension (N) */ /* On exit, ALPHA(j)/BETA(j), j=1,...,N, will be the */ /* generalized eigenvalues. ALPHA(j), j=1,...,N and BETA(j), */ /* j=1,...,N are the diagonals of the complex Schur form (A,B) */ /* output by ZGGES. The BETA(j) will be non-negative float. */ /* Note: the quotients ALPHA(j)/BETA(j) may easily over- or */ /* underflow, and BETA(j) may even be zero. Thus, the user */ /* should avoid naively computing the ratio alpha/beta. */ /* However, ALPHA will be always less than and usually */ /* comparable with norm(A) in magnitude, and BETA always less */ /* than and usually comparable with norm(B). */ /* VSL (output) COMPLEX*16 array, dimension (LDVSL,N) */ /* If JOBVSL = 'V', VSL will contain the left Schur vectors. */ /* Not referenced if JOBVSL = 'N'. */ /* LDVSL (input) INTEGER */ /* The leading dimension of the matrix VSL. LDVSL >= 1, and */ /* if JOBVSL = 'V', LDVSL >= N. */ /* VSR (output) COMPLEX*16 array, dimension (LDVSR,N) */ /* If JOBVSR = 'V', VSR will contain the right Schur vectors. */ /* Not referenced if JOBVSR = 'N'. */ /* LDVSR (input) INTEGER */ /* The leading dimension of the matrix VSR. LDVSR >= 1, and */ /* if JOBVSR = 'V', LDVSR >= N. */ /* WORK (workspace/output) COMPLEX*16 array, dimension (MAX(1,LWORK)) */ /* On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */ /* LWORK (input) INTEGER */ /* The dimension of the array WORK. LWORK >= MAX(1,2*N). */ /* For good performance, LWORK must generally be larger. */ /* If LWORK = -1, then a workspace query is assumed; the routine */ /* only calculates the optimal size of the WORK array, returns */ /* this value as the first entry of the WORK array, and no error */ /* message related to LWORK is issued by XERBLA. */ /* RWORK (workspace) DOUBLE PRECISION array, dimension (8*N) */ /* BWORK (workspace) LOGICAL array, dimension (N) */ /* Not referenced if SORT = 'N'. */ /* INFO (output) INTEGER */ /* = 0: successful exit */ /* < 0: if INFO = -i, the i-th argument had an illegal value. */ /* =1,...,N: */ /* The QZ iteration failed. (A,B) are not in Schur */ /* form, but ALPHA(j) and BETA(j) should be correct for */ /* j=INFO+1,...,N. */ /* > N: =N+1: other than QZ iteration failed in ZHGEQZ */ /* =N+2: after reordering, roundoff changed values of */ /* some complex eigenvalues so that leading */ /* eigenvalues in the Generalized Schur form no */ /* longer satisfy SELCTG=.TRUE. This could also */ /* be caused due to scaling. */ /* =N+3: reordering falied in ZTGSEN. */ /* ===================================================================== */ /* .. Parameters .. */ /* .. */ /* .. Local Scalars .. */ /* .. */ /* .. Local Arrays .. */ /* .. */ /* .. External Subroutines .. */ /* .. */ /* .. External Functions .. */ /* .. */ /* .. Intrinsic Functions .. */ /* .. */ /* .. Executable Statements .. */ /* Decode the input arguments */ /* Parameter adjustments */ a_dim1 = *lda; a_offset = 1 + a_dim1; a -= a_offset; b_dim1 = *ldb; b_offset = 1 + b_dim1; b -= b_offset; --alpha; --beta; vsl_dim1 = *ldvsl; vsl_offset = 1 + vsl_dim1; vsl -= vsl_offset; vsr_dim1 = *ldvsr; vsr_offset = 1 + vsr_dim1; vsr -= vsr_offset; --work; --rwork; --bwork; /* Function Body */ if (lsame_(jobvsl, "N")) { ijobvl = 1; ilvsl = FALSE; } else if (lsame_(jobvsl, "V")) { ijobvl = 2; ilvsl = TRUE; } else { ijobvl = -1; ilvsl = FALSE; } if (lsame_(jobvsr, "N")) { ijobvr = 1; ilvsr = FALSE; } else if (lsame_(jobvsr, "V")) { ijobvr = 2; ilvsr = TRUE; } else { ijobvr = -1; ilvsr = FALSE; } wantst = lsame_(sort, "S"); /* Test the input arguments */ *info = 0; lquery = *lwork == -1; if (ijobvl <= 0) { *info = -1; } else if (ijobvr <= 0) { *info = -2; } else if (! wantst && ! lsame_(sort, "N")) { *info = -3; } else if (*n < 0) { *info = -5; } else if (*lda < MAX(1,*n)) { *info = -7; } else if (*ldb < MAX(1,*n)) { *info = -9; } else if (*ldvsl < 1 || ilvsl && *ldvsl < *n) { *info = -14; } else if (*ldvsr < 1 || ilvsr && *ldvsr < *n) { *info = -16; } /* Compute workspace */ /* (Note: Comments in the code beginning "Workspace:" describe the */ /* minimal amount of workspace needed at that point in the code, */ /* as well as the preferred amount for good performance. */ /* NB refers to the optimal block size for the immediately */ /* following subroutine, as returned by ILAENV.) */ if (*info == 0) { /* Computing MAX */ i__1 = 1, i__2 = *n << 1; lwkmin = MAX(i__1,i__2); /* Computing MAX */ i__1 = 1, i__2 = *n + *n * ilaenv_(&c__1, "ZGEQRF", " ", n, &c__1, n, &c__0); lwkopt = MAX(i__1,i__2); /* Computing MAX */ i__1 = lwkopt, i__2 = *n + *n * ilaenv_(&c__1, "ZUNMQR", " ", n, & c__1, n, &c_n1); lwkopt = MAX(i__1,i__2); if (ilvsl) { /* Computing MAX */ i__1 = lwkopt, i__2 = *n + *n * ilaenv_(&c__1, "ZUNGQR", " ", n, & c__1, n, &c_n1); lwkopt = MAX(i__1,i__2); } work[1].r = (double) lwkopt, work[1].i = 0.; if (*lwork < lwkmin && ! lquery) { *info = -18; } } if (*info != 0) { i__1 = -(*info); xerbla_("ZGGES ", &i__1); return 0; } else if (lquery) { return 0; } /* Quick return if possible */ if (*n == 0) { *sdim = 0; return 0; } /* Get machine constants */ eps = dlamch_("P"); smlnum = dlamch_("S"); bignum = 1. / smlnum; dlabad_(&smlnum, &bignum); smlnum = sqrt(smlnum) / eps; bignum = 1. / smlnum; /* Scale A if max element outside range [SMLNUM,BIGNUM] */ anrm = zlange_("M", n, n, &a[a_offset], lda, &rwork[1]); ilascl = FALSE; if (anrm > 0. && anrm < smlnum) { anrmto = smlnum; ilascl = TRUE; } else if (anrm > bignum) { anrmto = bignum; ilascl = TRUE; } if (ilascl) { zlascl_("G", &c__0, &c__0, &anrm, &anrmto, n, n, &a[a_offset], lda, & ierr); } /* Scale B if max element outside range [SMLNUM,BIGNUM] */ bnrm = zlange_("M", n, n, &b[b_offset], ldb, &rwork[1]); ilbscl = FALSE; if (bnrm > 0. && bnrm < smlnum) { bnrmto = smlnum; ilbscl = TRUE; } else if (bnrm > bignum) { bnrmto = bignum; ilbscl = TRUE; } if (ilbscl) { zlascl_("G", &c__0, &c__0, &bnrm, &bnrmto, n, n, &b[b_offset], ldb, & ierr); } /* Permute the matrix to make it more nearly triangular */ /* (Real Workspace: need 6*N) */ ileft = 1; iright = *n + 1; irwrk = iright + *n; zggbal_("P", n, &a[a_offset], lda, &b[b_offset], ldb, &ilo, &ihi, &rwork[ ileft], &rwork[iright], &rwork[irwrk], &ierr); /* Reduce B to triangular form (QR decomposition of B) */ /* (Complex Workspace: need N, prefer N*NB) */ irows = ihi + 1 - ilo; icols = *n + 1 - ilo; itau = 1; iwrk = itau + irows; i__1 = *lwork + 1 - iwrk; zgeqrf_(&irows, &icols, &b[ilo + ilo * b_dim1], ldb, &work[itau], &work[ iwrk], &i__1, &ierr); /* Apply the orthogonal transformation to matrix A */ /* (Complex Workspace: need N, prefer N*NB) */ i__1 = *lwork + 1 - iwrk; zunmqr_("L", "C", &irows, &icols, &irows, &b[ilo + ilo * b_dim1], ldb, & work[itau], &a[ilo + ilo * a_dim1], lda, &work[iwrk], &i__1, & ierr); /* Initialize VSL */ /* (Complex Workspace: need N, prefer N*NB) */ if (ilvsl) { zlaset_("Full", n, n, &c_b1, &c_b2, &vsl[vsl_offset], ldvsl); if (irows > 1) { i__1 = irows - 1; i__2 = irows - 1; zlacpy_("L", &i__1, &i__2, &b[ilo + 1 + ilo * b_dim1], ldb, &vsl[ ilo + 1 + ilo * vsl_dim1], ldvsl); } i__1 = *lwork + 1 - iwrk; zungqr_(&irows, &irows, &irows, &vsl[ilo + ilo * vsl_dim1], ldvsl, & work[itau], &work[iwrk], &i__1, &ierr); } /* Initialize VSR */ if (ilvsr) { zlaset_("Full", n, n, &c_b1, &c_b2, &vsr[vsr_offset], ldvsr); } /* Reduce to generalized Hessenberg form */ /* (Workspace: none needed) */ zgghrd_(jobvsl, jobvsr, n, &ilo, &ihi, &a[a_offset], lda, &b[b_offset], ldb, &vsl[vsl_offset], ldvsl, &vsr[vsr_offset], ldvsr, &ierr); *sdim = 0; /* Perform QZ algorithm, computing Schur vectors if desired */ /* (Complex Workspace: need N) */ /* (Real Workspace: need N) */ iwrk = itau; i__1 = *lwork + 1 - iwrk; zhgeqz_("S", jobvsl, jobvsr, n, &ilo, &ihi, &a[a_offset], lda, &b[ b_offset], ldb, &alpha[1], &beta[1], &vsl[vsl_offset], ldvsl, & vsr[vsr_offset], ldvsr, &work[iwrk], &i__1, &rwork[irwrk], &ierr); if (ierr != 0) { if (ierr > 0 && ierr <= *n) { *info = ierr; } else if (ierr > *n && ierr <= *n << 1) { *info = ierr - *n; } else { *info = *n + 1; } goto L30; } /* Sort eigenvalues ALPHA/BETA if desired */ /* (Workspace: none needed) */ if (wantst) { /* Undo scaling on eigenvalues before selecting */ if (ilascl) { zlascl_("G", &c__0, &c__0, &anrm, &anrmto, n, &c__1, &alpha[1], n, &ierr); } if (ilbscl) { zlascl_("G", &c__0, &c__0, &bnrm, &bnrmto, n, &c__1, &beta[1], n, &ierr); } /* Select eigenvalues */ i__1 = *n; for (i__ = 1; i__ <= i__1; ++i__) { bwork[i__] = (*selctg)(&alpha[i__], &beta[i__]); /* L10: */ } i__1 = *lwork - iwrk + 1; ztgsen_(&c__0, &ilvsl, &ilvsr, &bwork[1], n, &a[a_offset], lda, &b[ b_offset], ldb, &alpha[1], &beta[1], &vsl[vsl_offset], ldvsl, &vsr[vsr_offset], ldvsr, sdim, &pvsl, &pvsr, dif, &work[iwrk], &i__1, idum, &c__1, &ierr); if (ierr == 1) { *info = *n + 3; } } /* Apply back-permutation to VSL and VSR */ /* (Workspace: none needed) */ if (ilvsl) { zggbak_("P", "L", n, &ilo, &ihi, &rwork[ileft], &rwork[iright], n, & vsl[vsl_offset], ldvsl, &ierr); } if (ilvsr) { zggbak_("P", "R", n, &ilo, &ihi, &rwork[ileft], &rwork[iright], n, & vsr[vsr_offset], ldvsr, &ierr); } /* Undo scaling */ if (ilascl) { zlascl_("U", &c__0, &c__0, &anrmto, &anrm, n, n, &a[a_offset], lda, & ierr); zlascl_("G", &c__0, &c__0, &anrmto, &anrm, n, &c__1, &alpha[1], n, & ierr); } if (ilbscl) { zlascl_("U", &c__0, &c__0, &bnrmto, &bnrm, n, n, &b[b_offset], ldb, & ierr); zlascl_("G", &c__0, &c__0, &bnrmto, &bnrm, n, &c__1, &beta[1], n, & ierr); } if (wantst) { /* Check if reordering is correct */ lastsl = TRUE; *sdim = 0; i__1 = *n; for (i__ = 1; i__ <= i__1; ++i__) { cursl = (*selctg)(&alpha[i__], &beta[i__]); if (cursl) { ++(*sdim); } if (cursl && ! lastsl) { *info = *n + 2; } lastsl = cursl; /* L20: */ } } L30: work[1].r = (double) lwkopt, work[1].i = 0.; return 0; /* End of ZGGES */ } /* zgges_ */
/* Subroutine */ int zggev_(char *jobvl, char *jobvr, integer *n, doublecomplex *a, integer *lda, doublecomplex *b, integer *ldb, doublecomplex *alpha, doublecomplex *beta, doublecomplex *vl, integer *ldvl, doublecomplex *vr, integer *ldvr, doublecomplex *work, integer *lwork, doublereal *rwork, integer *info) { /* System generated locals */ integer a_dim1, a_offset, b_dim1, b_offset, vl_dim1, vl_offset, vr_dim1, vr_offset, i__1, i__2, i__3, i__4; doublereal d__1, d__2, d__3, d__4; doublecomplex z__1; /* Builtin functions */ double sqrt(doublereal), d_imag(doublecomplex *); /* Local variables */ integer jc, in, jr, ihi, ilo; doublereal eps; logical ilv; doublereal anrm, bnrm; integer ierr, itau; doublereal temp; logical ilvl, ilvr; integer iwrk; extern logical lsame_(char *, char *); integer ileft, icols, irwrk, irows; extern /* Subroutine */ int dlabad_(doublereal *, doublereal *); extern doublereal dlamch_(char *); extern /* Subroutine */ int zggbak_(char *, char *, integer *, integer *, integer *, doublereal *, doublereal *, integer *, doublecomplex *, integer *, integer *), zggbal_(char *, integer *, doublecomplex *, integer *, doublecomplex *, integer *, integer * , integer *, doublereal *, doublereal *, doublereal *, integer *); logical ilascl, ilbscl; extern /* Subroutine */ int xerbla_(char *, integer *); extern integer ilaenv_(integer *, char *, char *, integer *, integer *, integer *, integer *); logical ldumma[1]; char chtemp[1]; doublereal bignum; extern doublereal zlange_(char *, integer *, integer *, doublecomplex *, integer *, doublereal *); integer ijobvl, iright; extern /* Subroutine */ int zgghrd_(char *, char *, integer *, integer *, integer *, doublecomplex *, integer *, doublecomplex *, integer *, doublecomplex *, integer *, doublecomplex *, integer *, integer * ), zlascl_(char *, integer *, integer *, doublereal *, doublereal *, integer *, integer *, doublecomplex *, integer *, integer *); integer ijobvr; extern /* Subroutine */ int zgeqrf_(integer *, integer *, doublecomplex *, integer *, doublecomplex *, doublecomplex *, integer *, integer * ); doublereal anrmto; integer lwkmin; doublereal bnrmto; extern /* Subroutine */ int zlacpy_(char *, integer *, integer *, doublecomplex *, integer *, doublecomplex *, integer *), zlaset_(char *, integer *, integer *, doublecomplex *, doublecomplex *, doublecomplex *, integer *), ztgevc_( char *, char *, logical *, integer *, doublecomplex *, integer *, doublecomplex *, integer *, doublecomplex *, integer *, doublecomplex *, integer *, integer *, integer *, doublecomplex *, doublereal *, integer *), zhgeqz_(char *, char *, char *, integer *, integer *, integer *, doublecomplex *, integer *, doublecomplex *, integer *, doublecomplex *, doublecomplex *, doublecomplex *, integer *, doublecomplex *, integer *, doublecomplex *, integer *, doublereal *, integer *); doublereal smlnum; integer lwkopt; logical lquery; extern /* Subroutine */ int zungqr_(integer *, integer *, integer *, doublecomplex *, integer *, doublecomplex *, doublecomplex *, integer *, integer *), zunmqr_(char *, char *, integer *, integer *, integer *, doublecomplex *, integer *, doublecomplex *, doublecomplex *, integer *, doublecomplex *, integer *, integer *); /* -- LAPACK driver routine (version 3.2) -- */ /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */ /* November 2006 */ /* .. Scalar Arguments .. */ /* .. */ /* .. Array Arguments .. */ /* .. */ /* Purpose */ /* ======= */ /* ZGGEV computes for a pair of N-by-N complex nonsymmetric matrices */ /* (A,B), the generalized eigenvalues, and optionally, the left and/or */ /* right generalized eigenvectors. */ /* A generalized eigenvalue for a pair of matrices (A,B) is a scalar */ /* lambda or a ratio alpha/beta = lambda, such that A - lambda*B is */ /* singular. It is usually represented as the pair (alpha,beta), as */ /* there is a reasonable interpretation for beta=0, and even for both */ /* being zero. */ /* The right generalized eigenvector v(j) corresponding to the */ /* generalized eigenvalue lambda(j) of (A,B) satisfies */ /* A * v(j) = lambda(j) * B * v(j). */ /* The left generalized eigenvector u(j) corresponding to the */ /* generalized eigenvalues lambda(j) of (A,B) satisfies */ /* u(j)**H * A = lambda(j) * u(j)**H * B */ /* where u(j)**H is the conjugate-transpose of u(j). */ /* Arguments */ /* ========= */ /* JOBVL (input) CHARACTER*1 */ /* = 'N': do not compute the left generalized eigenvectors; */ /* = 'V': compute the left generalized eigenvectors. */ /* JOBVR (input) CHARACTER*1 */ /* = 'N': do not compute the right generalized eigenvectors; */ /* = 'V': compute the right generalized eigenvectors. */ /* N (input) INTEGER */ /* The order of the matrices A, B, VL, and VR. N >= 0. */ /* A (input/output) COMPLEX*16 array, dimension (LDA, N) */ /* On entry, the matrix A in the pair (A,B). */ /* On exit, A has been overwritten. */ /* LDA (input) INTEGER */ /* The leading dimension of A. LDA >= max(1,N). */ /* B (input/output) COMPLEX*16 array, dimension (LDB, N) */ /* On entry, the matrix B in the pair (A,B). */ /* On exit, B has been overwritten. */ /* LDB (input) INTEGER */ /* The leading dimension of B. LDB >= max(1,N). */ /* ALPHA (output) COMPLEX*16 array, dimension (N) */ /* BETA (output) COMPLEX*16 array, dimension (N) */ /* On exit, ALPHA(j)/BETA(j), j=1,...,N, will be the */ /* generalized eigenvalues. */ /* Note: the quotients ALPHA(j)/BETA(j) may easily over- or */ /* underflow, and BETA(j) may even be zero. Thus, the user */ /* should avoid naively computing the ratio alpha/beta. */ /* However, ALPHA will be always less than and usually */ /* comparable with norm(A) in magnitude, and BETA always less */ /* than and usually comparable with norm(B). */ /* VL (output) COMPLEX*16 array, dimension (LDVL,N) */ /* If JOBVL = 'V', the left generalized eigenvectors u(j) are */ /* stored one after another in the columns of VL, in the same */ /* order as their eigenvalues. */ /* Each eigenvector is scaled so the largest component has */ /* abs(real part) + abs(imag. part) = 1. */ /* Not referenced if JOBVL = 'N'. */ /* LDVL (input) INTEGER */ /* The leading dimension of the matrix VL. LDVL >= 1, and */ /* if JOBVL = 'V', LDVL >= N. */ /* VR (output) COMPLEX*16 array, dimension (LDVR,N) */ /* If JOBVR = 'V', the right generalized eigenvectors v(j) are */ /* stored one after another in the columns of VR, in the same */ /* order as their eigenvalues. */ /* Each eigenvector is scaled so the largest component has */ /* abs(real part) + abs(imag. part) = 1. */ /* Not referenced if JOBVR = 'N'. */ /* LDVR (input) INTEGER */ /* The leading dimension of the matrix VR. LDVR >= 1, and */ /* if JOBVR = 'V', LDVR >= N. */ /* WORK (workspace/output) COMPLEX*16 array, dimension (MAX(1,LWORK)) */ /* On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */ /* LWORK (input) INTEGER */ /* The dimension of the array WORK. LWORK >= max(1,2*N). */ /* For good performance, LWORK must generally be larger. */ /* If LWORK = -1, then a workspace query is assumed; the routine */ /* only calculates the optimal size of the WORK array, returns */ /* this value as the first entry of the WORK array, and no error */ /* message related to LWORK is issued by XERBLA. */ /* RWORK (workspace/output) DOUBLE PRECISION array, dimension (8*N) */ /* INFO (output) INTEGER */ /* = 0: successful exit */ /* < 0: if INFO = -i, the i-th argument had an illegal value. */ /* =1,...,N: */ /* The QZ iteration failed. No eigenvectors have been */ /* calculated, but ALPHA(j) and BETA(j) should be */ /* correct for j=INFO+1,...,N. */ /* > N: =N+1: other then QZ iteration failed in DHGEQZ, */ /* =N+2: error return from DTGEVC. */ /* ===================================================================== */ /* .. Parameters .. */ /* .. */ /* .. Local Scalars .. */ /* .. */ /* .. Local Arrays .. */ /* .. */ /* .. External Subroutines .. */ /* .. */ /* .. External Functions .. */ /* .. */ /* .. Intrinsic Functions .. */ /* .. */ /* .. Statement Functions .. */ /* .. */ /* .. Statement Function definitions .. */ /* .. */ /* .. Executable Statements .. */ /* Decode the input arguments */ /* Parameter adjustments */ a_dim1 = *lda; a_offset = 1 + a_dim1; a -= a_offset; b_dim1 = *ldb; b_offset = 1 + b_dim1; b -= b_offset; --alpha; --beta; vl_dim1 = *ldvl; vl_offset = 1 + vl_dim1; vl -= vl_offset; vr_dim1 = *ldvr; vr_offset = 1 + vr_dim1; vr -= vr_offset; --work; --rwork; /* Function Body */ if (lsame_(jobvl, "N")) { ijobvl = 1; ilvl = FALSE_; } else if (lsame_(jobvl, "V")) { ijobvl = 2; ilvl = TRUE_; } else { ijobvl = -1; ilvl = FALSE_; } if (lsame_(jobvr, "N")) { ijobvr = 1; ilvr = FALSE_; } else if (lsame_(jobvr, "V")) { ijobvr = 2; ilvr = TRUE_; } else { ijobvr = -1; ilvr = FALSE_; } ilv = ilvl || ilvr; /* Test the input arguments */ *info = 0; lquery = *lwork == -1; if (ijobvl <= 0) { *info = -1; } else if (ijobvr <= 0) { *info = -2; } else if (*n < 0) { *info = -3; } else if (*lda < max(1,*n)) { *info = -5; } else if (*ldb < max(1,*n)) { *info = -7; } else if (*ldvl < 1 || ilvl && *ldvl < *n) { *info = -11; } else if (*ldvr < 1 || ilvr && *ldvr < *n) { *info = -13; } /* Compute workspace */ /* (Note: Comments in the code beginning "Workspace:" describe the */ /* minimal amount of workspace needed at that point in the code, */ /* as well as the preferred amount for good performance. */ /* NB refers to the optimal block size for the immediately */ /* following subroutine, as returned by ILAENV. The workspace is */ /* computed assuming ILO = 1 and IHI = N, the worst case.) */ if (*info == 0) { /* Computing MAX */ i__1 = 1, i__2 = *n << 1; lwkmin = max(i__1,i__2); /* Computing MAX */ i__1 = 1, i__2 = *n + *n * ilaenv_(&c__1, "ZGEQRF", " ", n, &c__1, n, &c__0); lwkopt = max(i__1,i__2); /* Computing MAX */ i__1 = lwkopt, i__2 = *n + *n * ilaenv_(&c__1, "ZUNMQR", " ", n, & c__1, n, &c__0); lwkopt = max(i__1,i__2); if (ilvl) { /* Computing MAX */ i__1 = lwkopt, i__2 = *n + *n * ilaenv_(&c__1, "ZUNGQR", " ", n, & c__1, n, &c_n1); lwkopt = max(i__1,i__2); } work[1].r = (doublereal) lwkopt, work[1].i = 0.; if (*lwork < lwkmin && ! lquery) { *info = -15; } } if (*info != 0) { i__1 = -(*info); xerbla_("ZGGEV ", &i__1); return 0; } else if (lquery) { return 0; } /* Quick return if possible */ if (*n == 0) { return 0; } /* Get machine constants */ eps = dlamch_("E") * dlamch_("B"); smlnum = dlamch_("S"); bignum = 1. / smlnum; dlabad_(&smlnum, &bignum); smlnum = sqrt(smlnum) / eps; bignum = 1. / smlnum; /* Scale A if max element outside range [SMLNUM,BIGNUM] */ anrm = zlange_("M", n, n, &a[a_offset], lda, &rwork[1]); ilascl = FALSE_; if (anrm > 0. && anrm < smlnum) { anrmto = smlnum; ilascl = TRUE_; } else if (anrm > bignum) { anrmto = bignum; ilascl = TRUE_; } if (ilascl) { zlascl_("G", &c__0, &c__0, &anrm, &anrmto, n, n, &a[a_offset], lda, & ierr); } /* Scale B if max element outside range [SMLNUM,BIGNUM] */ bnrm = zlange_("M", n, n, &b[b_offset], ldb, &rwork[1]); ilbscl = FALSE_; if (bnrm > 0. && bnrm < smlnum) { bnrmto = smlnum; ilbscl = TRUE_; } else if (bnrm > bignum) { bnrmto = bignum; ilbscl = TRUE_; } if (ilbscl) { zlascl_("G", &c__0, &c__0, &bnrm, &bnrmto, n, n, &b[b_offset], ldb, & ierr); } /* Permute the matrices A, B to isolate eigenvalues if possible */ /* (Real Workspace: need 6*N) */ ileft = 1; iright = *n + 1; irwrk = iright + *n; zggbal_("P", n, &a[a_offset], lda, &b[b_offset], ldb, &ilo, &ihi, &rwork[ ileft], &rwork[iright], &rwork[irwrk], &ierr); /* Reduce B to triangular form (QR decomposition of B) */ /* (Complex Workspace: need N, prefer N*NB) */ irows = ihi + 1 - ilo; if (ilv) { icols = *n + 1 - ilo; } else { icols = irows; } itau = 1; iwrk = itau + irows; i__1 = *lwork + 1 - iwrk; zgeqrf_(&irows, &icols, &b[ilo + ilo * b_dim1], ldb, &work[itau], &work[ iwrk], &i__1, &ierr); /* Apply the orthogonal transformation to matrix A */ /* (Complex Workspace: need N, prefer N*NB) */ i__1 = *lwork + 1 - iwrk; zunmqr_("L", "C", &irows, &icols, &irows, &b[ilo + ilo * b_dim1], ldb, & work[itau], &a[ilo + ilo * a_dim1], lda, &work[iwrk], &i__1, & ierr); /* Initialize VL */ /* (Complex Workspace: need N, prefer N*NB) */ if (ilvl) { zlaset_("Full", n, n, &c_b1, &c_b2, &vl[vl_offset], ldvl); if (irows > 1) { i__1 = irows - 1; i__2 = irows - 1; zlacpy_("L", &i__1, &i__2, &b[ilo + 1 + ilo * b_dim1], ldb, &vl[ ilo + 1 + ilo * vl_dim1], ldvl); } i__1 = *lwork + 1 - iwrk; zungqr_(&irows, &irows, &irows, &vl[ilo + ilo * vl_dim1], ldvl, &work[ itau], &work[iwrk], &i__1, &ierr); } /* Initialize VR */ if (ilvr) { zlaset_("Full", n, n, &c_b1, &c_b2, &vr[vr_offset], ldvr); } /* Reduce to generalized Hessenberg form */ if (ilv) { /* Eigenvectors requested -- work on whole matrix. */ zgghrd_(jobvl, jobvr, n, &ilo, &ihi, &a[a_offset], lda, &b[b_offset], ldb, &vl[vl_offset], ldvl, &vr[vr_offset], ldvr, &ierr); } else { zgghrd_("N", "N", &irows, &c__1, &irows, &a[ilo + ilo * a_dim1], lda, &b[ilo + ilo * b_dim1], ldb, &vl[vl_offset], ldvl, &vr[ vr_offset], ldvr, &ierr); } /* Perform QZ algorithm (Compute eigenvalues, and optionally, the */ /* Schur form and Schur vectors) */ /* (Complex Workspace: need N) */ /* (Real Workspace: need N) */ iwrk = itau; if (ilv) { *(unsigned char *)chtemp = 'S'; } else { *(unsigned char *)chtemp = 'E'; } i__1 = *lwork + 1 - iwrk; zhgeqz_(chtemp, jobvl, jobvr, n, &ilo, &ihi, &a[a_offset], lda, &b[ b_offset], ldb, &alpha[1], &beta[1], &vl[vl_offset], ldvl, &vr[ vr_offset], ldvr, &work[iwrk], &i__1, &rwork[irwrk], &ierr); if (ierr != 0) { if (ierr > 0 && ierr <= *n) { *info = ierr; } else if (ierr > *n && ierr <= *n << 1) { *info = ierr - *n; } else { *info = *n + 1; } goto L70; } /* Compute Eigenvectors */ /* (Real Workspace: need 2*N) */ /* (Complex Workspace: need 2*N) */ if (ilv) { if (ilvl) { if (ilvr) { *(unsigned char *)chtemp = 'B'; } else { *(unsigned char *)chtemp = 'L'; } } else { *(unsigned char *)chtemp = 'R'; } ztgevc_(chtemp, "B", ldumma, n, &a[a_offset], lda, &b[b_offset], ldb, &vl[vl_offset], ldvl, &vr[vr_offset], ldvr, n, &in, &work[ iwrk], &rwork[irwrk], &ierr); if (ierr != 0) { *info = *n + 2; goto L70; } /* Undo balancing on VL and VR and normalization */ /* (Workspace: none needed) */ if (ilvl) { zggbak_("P", "L", n, &ilo, &ihi, &rwork[ileft], &rwork[iright], n, &vl[vl_offset], ldvl, &ierr); i__1 = *n; for (jc = 1; jc <= i__1; ++jc) { temp = 0.; i__2 = *n; for (jr = 1; jr <= i__2; ++jr) { /* Computing MAX */ i__3 = jr + jc * vl_dim1; d__3 = temp, d__4 = (d__1 = vl[i__3].r, abs(d__1)) + ( d__2 = d_imag(&vl[jr + jc * vl_dim1]), abs(d__2)); temp = max(d__3,d__4); /* L10: */ } if (temp < smlnum) { goto L30; } temp = 1. / temp; i__2 = *n; for (jr = 1; jr <= i__2; ++jr) { i__3 = jr + jc * vl_dim1; i__4 = jr + jc * vl_dim1; z__1.r = temp * vl[i__4].r, z__1.i = temp * vl[i__4].i; vl[i__3].r = z__1.r, vl[i__3].i = z__1.i; /* L20: */ } L30: ; } } if (ilvr) { zggbak_("P", "R", n, &ilo, &ihi, &rwork[ileft], &rwork[iright], n, &vr[vr_offset], ldvr, &ierr); i__1 = *n; for (jc = 1; jc <= i__1; ++jc) { temp = 0.; i__2 = *n; for (jr = 1; jr <= i__2; ++jr) { /* Computing MAX */ i__3 = jr + jc * vr_dim1; d__3 = temp, d__4 = (d__1 = vr[i__3].r, abs(d__1)) + ( d__2 = d_imag(&vr[jr + jc * vr_dim1]), abs(d__2)); temp = max(d__3,d__4); /* L40: */ } if (temp < smlnum) { goto L60; } temp = 1. / temp; i__2 = *n; for (jr = 1; jr <= i__2; ++jr) { i__3 = jr + jc * vr_dim1; i__4 = jr + jc * vr_dim1; z__1.r = temp * vr[i__4].r, z__1.i = temp * vr[i__4].i; vr[i__3].r = z__1.r, vr[i__3].i = z__1.i; /* L50: */ } L60: ; } } } /* Undo scaling if necessary */ if (ilascl) { zlascl_("G", &c__0, &c__0, &anrmto, &anrm, n, &c__1, &alpha[1], n, & ierr); } if (ilbscl) { zlascl_("G", &c__0, &c__0, &bnrmto, &bnrm, n, &c__1, &beta[1], n, & ierr); } L70: work[1].r = (doublereal) lwkopt, work[1].i = 0.; return 0; /* End of ZGGEV */ } /* zggev_ */
/* Subroutine */ int zggesx_(char *jobvsl, char *jobvsr, char *sort, L_fp delctg, char *sense, integer *n, doublecomplex *a, integer *lda, doublecomplex *b, integer *ldb, integer *sdim, doublecomplex *alpha, doublecomplex *beta, doublecomplex *vsl, integer *ldvsl, doublecomplex *vsr, integer *ldvsr, doublereal *rconde, doublereal * rcondv, doublecomplex *work, integer *lwork, doublereal *rwork, integer *iwork, integer *liwork, logical *bwork, integer *info, ftnlen jobvsl_len, ftnlen jobvsr_len, ftnlen sort_len, ftnlen sense_len) { /* System generated locals */ integer a_dim1, a_offset, b_dim1, b_offset, vsl_dim1, vsl_offset, vsr_dim1, vsr_offset, i__1, i__2; /* Builtin functions */ double sqrt(doublereal); /* Local variables */ static integer i__; static doublereal pl, pr, dif[2]; static integer ihi, ilo; static doublereal eps; static integer ijob; static doublereal anrm, bnrm; static integer ierr, itau, iwrk; extern logical lsame_(char *, char *, ftnlen, ftnlen); static integer ileft, icols; static logical cursl, ilvsl, ilvsr; static integer irwrk, irows; extern /* Subroutine */ int dlabad_(doublereal *, doublereal *); extern doublereal dlamch_(char *, ftnlen); extern /* Subroutine */ int zggbak_(char *, char *, integer *, integer *, integer *, doublereal *, doublereal *, integer *, doublecomplex *, integer *, integer *, ftnlen, ftnlen), zggbal_(char *, integer *, doublecomplex *, integer *, doublecomplex *, integer *, integer * , integer *, doublereal *, doublereal *, doublereal *, integer *, ftnlen); static logical ilascl, ilbscl; extern /* Subroutine */ int xerbla_(char *, integer *, ftnlen); extern integer ilaenv_(integer *, char *, char *, integer *, integer *, integer *, integer *, ftnlen, ftnlen); extern doublereal zlange_(char *, integer *, integer *, doublecomplex *, integer *, doublereal *, ftnlen); static doublereal bignum; static integer ijobvl, iright; extern /* Subroutine */ int zgghrd_(char *, char *, integer *, integer *, integer *, doublecomplex *, integer *, doublecomplex *, integer *, doublecomplex *, integer *, doublecomplex *, integer *, integer * , ftnlen, ftnlen), zlascl_(char *, integer *, integer *, doublereal *, doublereal *, integer *, integer *, doublecomplex *, integer *, integer *, ftnlen); static integer ijobvr; static logical wantsb; static integer liwmin; static logical wantse, lastsl; static doublereal anrmto, bnrmto; extern /* Subroutine */ int zgeqrf_(integer *, integer *, doublecomplex *, integer *, doublecomplex *, doublecomplex *, integer *, integer * ); static integer maxwrk; static logical wantsn; static integer minwrk; static doublereal smlnum; extern /* Subroutine */ int zhgeqz_(char *, char *, char *, integer *, integer *, integer *, doublecomplex *, integer *, doublecomplex *, integer *, doublecomplex *, doublecomplex *, doublecomplex *, integer *, doublecomplex *, integer *, doublecomplex *, integer *, doublereal *, integer *, ftnlen, ftnlen, ftnlen), zlacpy_(char *, integer *, integer *, doublecomplex *, integer *, doublecomplex * , integer *, ftnlen), zlaset_(char *, integer *, integer *, doublecomplex *, doublecomplex *, doublecomplex *, integer *, ftnlen); static logical wantst; extern /* Subroutine */ int ztgsen_(integer *, logical *, logical *, logical *, integer *, doublecomplex *, integer *, doublecomplex *, integer *, doublecomplex *, doublecomplex *, doublecomplex *, integer *, doublecomplex *, integer *, integer *, doublereal *, doublereal *, doublereal *, doublecomplex *, integer *, integer *, integer *, integer *); static logical wantsv; extern /* Subroutine */ int zungqr_(integer *, integer *, integer *, doublecomplex *, integer *, doublecomplex *, doublecomplex *, integer *, integer *), zunmqr_(char *, char *, integer *, integer *, integer *, doublecomplex *, integer *, doublecomplex *, doublecomplex *, integer *, doublecomplex *, integer *, integer *, ftnlen, ftnlen); /* -- LAPACK driver routine (version 3.0) -- */ /* Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd., */ /* Courant Institute, Argonne National Lab, and Rice University */ /* June 30, 1999 */ /* .. Scalar Arguments .. */ /* .. */ /* .. Array Arguments .. */ /* .. */ /* .. Function Arguments .. */ /* .. */ /* Purpose */ /* ======= */ /* ZGGESX computes for a pair of N-by-N complex nonsymmetric matrices */ /* (A,B), the generalized eigenvalues, the complex Schur form (S,T), */ /* and, optionally, the left and/or right matrices of Schur vectors (VSL */ /* and VSR). This gives the generalized Schur factorization */ /* (A,B) = ( (VSL) S (VSR)**H, (VSL) T (VSR)**H ) */ /* where (VSR)**H is the conjugate-transpose of VSR. */ /* Optionally, it also orders the eigenvalues so that a selected cluster */ /* of eigenvalues appears in the leading diagonal blocks of the upper */ /* triangular matrix S and the upper triangular matrix T; computes */ /* a reciprocal condition number for the average of the selected */ /* eigenvalues (RCONDE); and computes a reciprocal condition number for */ /* the right and left deflating subspaces corresponding to the selected */ /* eigenvalues (RCONDV). The leading columns of VSL and VSR then form */ /* an orthonormal basis for the corresponding left and right eigenspaces */ /* (deflating subspaces). */ /* A generalized eigenvalue for a pair of matrices (A,B) is a scalar w */ /* or a ratio alpha/beta = w, such that A - w*B is singular. It is */ /* usually represented as the pair (alpha,beta), as there is a */ /* reasonable interpretation for beta=0 or for both being zero. */ /* A pair of matrices (S,T) is in generalized complex Schur form if T is */ /* upper triangular with non-negative diagonal and S is upper */ /* triangular. */ /* Arguments */ /* ========= */ /* JOBVSL (input) CHARACTER*1 */ /* = 'N': do not compute the left Schur vectors; */ /* = 'V': compute the left Schur vectors. */ /* JOBVSR (input) CHARACTER*1 */ /* = 'N': do not compute the right Schur vectors; */ /* = 'V': compute the right Schur vectors. */ /* SORT (input) CHARACTER*1 */ /* Specifies whether or not to order the eigenvalues on the */ /* diagonal of the generalized Schur form. */ /* = 'N': Eigenvalues are not ordered; */ /* = 'S': Eigenvalues are ordered (see DELZTG). */ /* DELZTG (input) LOGICAL FUNCTION of two COMPLEX*16 arguments */ /* DELZTG must be declared EXTERNAL in the calling subroutine. */ /* If SORT = 'N', DELZTG is not referenced. */ /* If SORT = 'S', DELZTG is used to select eigenvalues to sort */ /* to the top left of the Schur form. */ /* Note that a selected complex eigenvalue may no longer satisfy */ /* DELZTG(ALPHA(j),BETA(j)) = .TRUE. after ordering, since */ /* ordering may change the value of complex eigenvalues */ /* (especially if the eigenvalue is ill-conditioned), in this */ /* case INFO is set to N+3 see INFO below). */ /* SENSE (input) CHARACTER */ /* Determines which reciprocal condition numbers are computed. */ /* = 'N' : None are computed; */ /* = 'E' : Computed for average of selected eigenvalues only; */ /* = 'V' : Computed for selected deflating subspaces only; */ /* = 'B' : Computed for both. */ /* If SENSE = 'E', 'V', or 'B', SORT must equal 'S'. */ /* N (input) INTEGER */ /* The order of the matrices A, B, VSL, and VSR. N >= 0. */ /* A (input/output) COMPLEX*16 array, dimension (LDA, N) */ /* On entry, the first of the pair of matrices. */ /* On exit, A has been overwritten by its generalized Schur */ /* form S. */ /* LDA (input) INTEGER */ /* The leading dimension of A. LDA >= max(1,N). */ /* B (input/output) COMPLEX*16 array, dimension (LDB, N) */ /* On entry, the second of the pair of matrices. */ /* On exit, B has been overwritten by its generalized Schur */ /* form T. */ /* LDB (input) INTEGER */ /* The leading dimension of B. LDB >= max(1,N). */ /* SDIM (output) INTEGER */ /* If SORT = 'N', SDIM = 0. */ /* If SORT = 'S', SDIM = number of eigenvalues (after sorting) */ /* for which DELZTG is true. */ /* ALPHA (output) COMPLEX*16 array, dimension (N) */ /* BETA (output) COMPLEX*16 array, dimension (N) */ /* On exit, ALPHA(j)/BETA(j), j=1,...,N, will be the */ /* generalized eigenvalues. ALPHA(j) and BETA(j),j=1,...,N are */ /* the diagonals of the complex Schur form (S,T). BETA(j) will */ /* be non-negative real. */ /* Note: the quotients ALPHA(j)/BETA(j) may easily over- or */ /* underflow, and BETA(j) may even be zero. Thus, the user */ /* should avoid naively computing the ratio alpha/beta. */ /* However, ALPHA will be always less than and usually */ /* comparable with norm(A) in magnitude, and BETA always less */ /* than and usually comparable with norm(B). */ /* VSL (output) COMPLEX*16 array, dimension (LDVSL,N) */ /* If JOBVSL = 'V', VSL will contain the left Schur vectors. */ /* Not referenced if JOBVSL = 'N'. */ /* LDVSL (input) INTEGER */ /* The leading dimension of the matrix VSL. LDVSL >=1, and */ /* if JOBVSL = 'V', LDVSL >= N. */ /* VSR (output) COMPLEX*16 array, dimension (LDVSR,N) */ /* If JOBVSR = 'V', VSR will contain the right Schur vectors. */ /* Not referenced if JOBVSR = 'N'. */ /* LDVSR (input) INTEGER */ /* The leading dimension of the matrix VSR. LDVSR >= 1, and */ /* if JOBVSR = 'V', LDVSR >= N. */ /* RCONDE (output) DOUBLE PRECISION array, dimension ( 2 ) */ /* If SENSE = 'E' or 'B', RCONDE(1) and RCONDE(2) contain the */ /* reciprocal condition numbers for the average of the selected */ /* eigenvalues. */ /* Not referenced if SENSE = 'N' or 'V'. */ /* RCONDV (output) DOUBLE PRECISION array, dimension ( 2 ) */ /* If SENSE = 'V' or 'B', RCONDV(1) and RCONDV(2) contain the */ /* reciprocal condition number for the selected deflating */ /* subspaces. */ /* Not referenced if SENSE = 'N' or 'E'. */ /* WORK (workspace/output) COMPLEX*16 array, dimension (LWORK) */ /* On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */ /* LWORK (input) INTEGER */ /* The dimension of the array WORK. LWORK >= 2*N. */ /* If SENSE = 'E', 'V', or 'B', */ /* LWORK >= MAX(2*N, 2*SDIM*(N-SDIM)). */ /* RWORK (workspace) DOUBLE PRECISION array, dimension ( 8*N ) */ /* Real workspace. */ /* IWORK (workspace/output) INTEGER array, dimension (LIWORK) */ /* Not referenced if SENSE = 'N'. */ /* On exit, if INFO = 0, IWORK(1) returns the optimal LIWORK. */ /* LIWORK (input) INTEGER */ /* The dimension of the array WORK. LIWORK >= N+2. */ /* BWORK (workspace) LOGICAL array, dimension (N) */ /* Not referenced if SORT = 'N'. */ /* INFO (output) INTEGER */ /* = 0: successful exit */ /* < 0: if INFO = -i, the i-th argument had an illegal value. */ /* = 1,...,N: */ /* The QZ iteration failed. (A,B) are not in Schur */ /* form, but ALPHA(j) and BETA(j) should be correct for */ /* j=INFO+1,...,N. */ /* > N: =N+1: other than QZ iteration failed in ZHGEQZ */ /* =N+2: after reordering, roundoff changed values of */ /* some complex eigenvalues so that leading */ /* eigenvalues in the Generalized Schur form no */ /* longer satisfy DELZTG=.TRUE. This could also */ /* be caused due to scaling. */ /* =N+3: reordering failed in ZTGSEN. */ /* ===================================================================== */ /* .. Parameters .. */ /* .. */ /* .. Local Scalars .. */ /* .. */ /* .. Local Arrays .. */ /* .. */ /* .. External Subroutines .. */ /* .. */ /* .. External Functions .. */ /* .. */ /* .. Intrinsic Functions .. */ /* .. */ /* .. Executable Statements .. */ /* Decode the input arguments */ /* Parameter adjustments */ a_dim1 = *lda; a_offset = 1 + a_dim1; a -= a_offset; b_dim1 = *ldb; b_offset = 1 + b_dim1; b -= b_offset; --alpha; --beta; vsl_dim1 = *ldvsl; vsl_offset = 1 + vsl_dim1; vsl -= vsl_offset; vsr_dim1 = *ldvsr; vsr_offset = 1 + vsr_dim1; vsr -= vsr_offset; --rconde; --rcondv; --work; --rwork; --iwork; --bwork; /* Function Body */ if (lsame_(jobvsl, "N", (ftnlen)1, (ftnlen)1)) { ijobvl = 1; ilvsl = FALSE_; } else if (lsame_(jobvsl, "V", (ftnlen)1, (ftnlen)1)) { ijobvl = 2; ilvsl = TRUE_; } else { ijobvl = -1; ilvsl = FALSE_; } if (lsame_(jobvsr, "N", (ftnlen)1, (ftnlen)1)) { ijobvr = 1; ilvsr = FALSE_; } else if (lsame_(jobvsr, "V", (ftnlen)1, (ftnlen)1)) { ijobvr = 2; ilvsr = TRUE_; } else { ijobvr = -1; ilvsr = FALSE_; } wantst = lsame_(sort, "S", (ftnlen)1, (ftnlen)1); wantsn = lsame_(sense, "N", (ftnlen)1, (ftnlen)1); wantse = lsame_(sense, "E", (ftnlen)1, (ftnlen)1); wantsv = lsame_(sense, "V", (ftnlen)1, (ftnlen)1); wantsb = lsame_(sense, "B", (ftnlen)1, (ftnlen)1); if (wantsn) { ijob = 0; iwork[1] = 1; } else if (wantse) { ijob = 1; } else if (wantsv) { ijob = 2; } else if (wantsb) { ijob = 4; } /* Test the input arguments */ *info = 0; if (ijobvl <= 0) { *info = -1; } else if (ijobvr <= 0) { *info = -2; } else if (! wantst && ! lsame_(sort, "N", (ftnlen)1, (ftnlen)1)) { *info = -3; } else if (! (wantsn || wantse || wantsv || wantsb) || ! wantst && ! wantsn) { *info = -5; } else if (*n < 0) { *info = -6; } else if (*lda < max(1,*n)) { *info = -8; } else if (*ldb < max(1,*n)) { *info = -10; } else if (*ldvsl < 1 || ilvsl && *ldvsl < *n) { *info = -15; } else if (*ldvsr < 1 || ilvsr && *ldvsr < *n) { *info = -17; } /* Compute workspace */ /* (Note: Comments in the code beginning "Workspace:" describe the */ /* minimal amount of workspace needed at that point in the code, */ /* as well as the preferred amount for good performance. */ /* NB refers to the optimal block size for the immediately */ /* following subroutine, as returned by ILAENV.) */ minwrk = 1; if (*info == 0 && *lwork >= 1) { /* Computing MAX */ i__1 = 1, i__2 = *n << 1; minwrk = max(i__1,i__2); maxwrk = *n + *n * ilaenv_(&c__1, "ZGEQRF", " ", n, &c__1, n, &c__0, ( ftnlen)6, (ftnlen)1); if (ilvsl) { /* Computing MAX */ i__1 = maxwrk, i__2 = *n + *n * ilaenv_(&c__1, "ZUNGQR", " ", n, & c__1, n, &c_n1, (ftnlen)6, (ftnlen)1); maxwrk = max(i__1,i__2); } work[1].r = (doublereal) maxwrk, work[1].i = 0.; } if (! wantsn) { liwmin = *n + 2; } else { liwmin = 1; } iwork[1] = liwmin; if (*info == 0 && *lwork < minwrk) { *info = -21; } else if (*info == 0 && ijob >= 1) { if (*liwork < liwmin) { *info = -24; } } if (*info != 0) { i__1 = -(*info); xerbla_("ZGGESX", &i__1, (ftnlen)6); return 0; } /* Quick return if possible */ if (*n == 0) { *sdim = 0; return 0; } /* Get machine constants */ eps = dlamch_("P", (ftnlen)1); smlnum = dlamch_("S", (ftnlen)1); bignum = 1. / smlnum; dlabad_(&smlnum, &bignum); smlnum = sqrt(smlnum) / eps; bignum = 1. / smlnum; /* Scale A if max element outside range [SMLNUM,BIGNUM] */ anrm = zlange_("M", n, n, &a[a_offset], lda, &rwork[1], (ftnlen)1); ilascl = FALSE_; if (anrm > 0. && anrm < smlnum) { anrmto = smlnum; ilascl = TRUE_; } else if (anrm > bignum) { anrmto = bignum; ilascl = TRUE_; } if (ilascl) { zlascl_("G", &c__0, &c__0, &anrm, &anrmto, n, n, &a[a_offset], lda, & ierr, (ftnlen)1); } /* Scale B if max element outside range [SMLNUM,BIGNUM] */ bnrm = zlange_("M", n, n, &b[b_offset], ldb, &rwork[1], (ftnlen)1); ilbscl = FALSE_; if (bnrm > 0. && bnrm < smlnum) { bnrmto = smlnum; ilbscl = TRUE_; } else if (bnrm > bignum) { bnrmto = bignum; ilbscl = TRUE_; } if (ilbscl) { zlascl_("G", &c__0, &c__0, &bnrm, &bnrmto, n, n, &b[b_offset], ldb, & ierr, (ftnlen)1); } /* Permute the matrix to make it more nearly triangular */ /* (Real Workspace: need 6*N) */ ileft = 1; iright = *n + 1; irwrk = iright + *n; zggbal_("P", n, &a[a_offset], lda, &b[b_offset], ldb, &ilo, &ihi, &rwork[ ileft], &rwork[iright], &rwork[irwrk], &ierr, (ftnlen)1); /* Reduce B to triangular form (QR decomposition of B) */ /* (Complex Workspace: need N, prefer N*NB) */ irows = ihi + 1 - ilo; icols = *n + 1 - ilo; itau = 1; iwrk = itau + irows; i__1 = *lwork + 1 - iwrk; zgeqrf_(&irows, &icols, &b[ilo + ilo * b_dim1], ldb, &work[itau], &work[ iwrk], &i__1, &ierr); /* Apply the unitary transformation to matrix A */ /* (Complex Workspace: need N, prefer N*NB) */ i__1 = *lwork + 1 - iwrk; zunmqr_("L", "C", &irows, &icols, &irows, &b[ilo + ilo * b_dim1], ldb, & work[itau], &a[ilo + ilo * a_dim1], lda, &work[iwrk], &i__1, & ierr, (ftnlen)1, (ftnlen)1); /* Initialize VSL */ /* (Complex Workspace: need N, prefer N*NB) */ if (ilvsl) { zlaset_("Full", n, n, &c_b1, &c_b2, &vsl[vsl_offset], ldvsl, (ftnlen) 4); i__1 = irows - 1; i__2 = irows - 1; zlacpy_("L", &i__1, &i__2, &b[ilo + 1 + ilo * b_dim1], ldb, &vsl[ilo + 1 + ilo * vsl_dim1], ldvsl, (ftnlen)1); i__1 = *lwork + 1 - iwrk; zungqr_(&irows, &irows, &irows, &vsl[ilo + ilo * vsl_dim1], ldvsl, & work[itau], &work[iwrk], &i__1, &ierr); } /* Initialize VSR */ if (ilvsr) { zlaset_("Full", n, n, &c_b1, &c_b2, &vsr[vsr_offset], ldvsr, (ftnlen) 4); } /* Reduce to generalized Hessenberg form */ /* (Workspace: none needed) */ zgghrd_(jobvsl, jobvsr, n, &ilo, &ihi, &a[a_offset], lda, &b[b_offset], ldb, &vsl[vsl_offset], ldvsl, &vsr[vsr_offset], ldvsr, &ierr, ( ftnlen)1, (ftnlen)1); *sdim = 0; /* Perform QZ algorithm, computing Schur vectors if desired */ /* (Complex Workspace: need N) */ /* (Real Workspace: need N) */ iwrk = itau; i__1 = *lwork + 1 - iwrk; zhgeqz_("S", jobvsl, jobvsr, n, &ilo, &ihi, &a[a_offset], lda, &b[ b_offset], ldb, &alpha[1], &beta[1], &vsl[vsl_offset], ldvsl, & vsr[vsr_offset], ldvsr, &work[iwrk], &i__1, &rwork[irwrk], &ierr, (ftnlen)1, (ftnlen)1, (ftnlen)1); if (ierr != 0) { if (ierr > 0 && ierr <= *n) { *info = ierr; } else if (ierr > *n && ierr <= *n << 1) { *info = ierr - *n; } else { *info = *n + 1; } goto L40; } /* Sort eigenvalues ALPHA/BETA and compute the reciprocal of */ /* condition number(s) */ if (wantst) { /* Undo scaling on eigenvalues before DELZTGing */ if (ilascl) { zlascl_("G", &c__0, &c__0, &anrmto, &anrm, n, &c__1, &alpha[1], n, &ierr, (ftnlen)1); } if (ilbscl) { zlascl_("G", &c__0, &c__0, &bnrmto, &bnrm, n, &c__1, &beta[1], n, &ierr, (ftnlen)1); } /* Select eigenvalues */ i__1 = *n; for (i__ = 1; i__ <= i__1; ++i__) { bwork[i__] = (*delctg)(&alpha[i__], &beta[i__]); /* L10: */ } /* Reorder eigenvalues, transform Generalized Schur vectors, and */ /* compute reciprocal condition numbers */ /* (Complex Workspace: If IJOB >= 1, need MAX(1, 2*SDIM*(N-SDIM)) */ /* otherwise, need 1 ) */ i__1 = *lwork - iwrk + 1; ztgsen_(&ijob, &ilvsl, &ilvsr, &bwork[1], n, &a[a_offset], lda, &b[ b_offset], ldb, &alpha[1], &beta[1], &vsl[vsl_offset], ldvsl, &vsr[vsr_offset], ldvsr, sdim, &pl, &pr, dif, &work[iwrk], & i__1, &iwork[1], liwork, &ierr); if (ijob >= 1) { /* Computing MAX */ i__1 = maxwrk, i__2 = (*sdim << 1) * (*n - *sdim); maxwrk = max(i__1,i__2); } if (ierr == -21) { /* not enough complex workspace */ *info = -21; } else { rconde[1] = pl; rconde[2] = pl; rcondv[1] = dif[0]; rcondv[2] = dif[1]; if (ierr == 1) { *info = *n + 3; } } } /* Apply permutation to VSL and VSR */ /* (Workspace: none needed) */ if (ilvsl) { zggbak_("P", "L", n, &ilo, &ihi, &rwork[ileft], &rwork[iright], n, & vsl[vsl_offset], ldvsl, &ierr, (ftnlen)1, (ftnlen)1); } if (ilvsr) { zggbak_("P", "R", n, &ilo, &ihi, &rwork[ileft], &rwork[iright], n, & vsr[vsr_offset], ldvsr, &ierr, (ftnlen)1, (ftnlen)1); } /* Undo scaling */ if (ilascl) { zlascl_("U", &c__0, &c__0, &anrmto, &anrm, n, n, &a[a_offset], lda, & ierr, (ftnlen)1); zlascl_("G", &c__0, &c__0, &anrmto, &anrm, n, &c__1, &alpha[1], n, & ierr, (ftnlen)1); } if (ilbscl) { zlascl_("U", &c__0, &c__0, &bnrmto, &bnrm, n, n, &b[b_offset], ldb, & ierr, (ftnlen)1); zlascl_("G", &c__0, &c__0, &bnrmto, &bnrm, n, &c__1, &beta[1], n, & ierr, (ftnlen)1); } /* L20: */ if (wantst) { /* Check if reordering is correct */ lastsl = TRUE_; *sdim = 0; i__1 = *n; for (i__ = 1; i__ <= i__1; ++i__) { cursl = (*delctg)(&alpha[i__], &beta[i__]); if (cursl) { ++(*sdim); } if (cursl && ! lastsl) { *info = *n + 2; } lastsl = cursl; /* L30: */ } } L40: work[1].r = (doublereal) maxwrk, work[1].i = 0.; iwork[1] = liwmin; return 0; /* End of ZGGESX */ } /* zggesx_ */
/* Subroutine */ int zgrqts_(integer *m, integer *p, integer *n, doublecomplex *a, doublecomplex *af, doublecomplex *q, doublecomplex * r__, integer *lda, doublecomplex *taua, doublecomplex *b, doublecomplex *bf, doublecomplex *z__, doublecomplex *t, doublecomplex *bwk, integer *ldb, doublecomplex *taub, doublecomplex * work, integer *lwork, doublereal *rwork, doublereal *result) { /* System generated locals */ integer a_dim1, a_offset, af_dim1, af_offset, b_dim1, b_offset, bf_dim1, bf_offset, bwk_dim1, bwk_offset, q_dim1, q_offset, r_dim1, r_offset, t_dim1, t_offset, z_dim1, z_offset, i__1, i__2; doublereal d__1; doublecomplex z__1; /* Local variables */ static integer info; static doublereal unfl, resid, anorm, bnorm; extern /* Subroutine */ int zgemm_(char *, char *, integer *, integer *, integer *, doublecomplex *, doublecomplex *, integer *, doublecomplex *, integer *, doublecomplex *, doublecomplex *, integer *), zherk_(char *, char *, integer *, integer *, doublereal *, doublecomplex *, integer *, doublereal *, doublecomplex *, integer *); extern doublereal dlamch_(char *), zlange_(char *, integer *, integer *, doublecomplex *, integer *, doublereal *), zlanhe_(char *, char *, integer *, doublecomplex *, integer *, doublereal *); extern /* Subroutine */ int zggrqf_(integer *, integer *, integer *, doublecomplex *, integer *, doublecomplex *, doublecomplex *, integer *, doublecomplex *, doublecomplex *, integer *, integer *) , zlacpy_(char *, integer *, integer *, doublecomplex *, integer * , doublecomplex *, integer *), zlaset_(char *, integer *, integer *, doublecomplex *, doublecomplex *, doublecomplex *, integer *), zungqr_(integer *, integer *, integer *, doublecomplex *, integer *, doublecomplex *, doublecomplex *, integer *, integer *), zungrq_(integer *, integer *, integer *, doublecomplex *, integer *, doublecomplex *, doublecomplex *, integer *, integer *); static doublereal ulp; #define q_subscr(a_1,a_2) (a_2)*q_dim1 + a_1 #define q_ref(a_1,a_2) q[q_subscr(a_1,a_2)] #define r___subscr(a_1,a_2) (a_2)*r_dim1 + a_1 #define r___ref(a_1,a_2) r__[r___subscr(a_1,a_2)] #define z___subscr(a_1,a_2) (a_2)*z_dim1 + a_1 #define z___ref(a_1,a_2) z__[z___subscr(a_1,a_2)] #define af_subscr(a_1,a_2) (a_2)*af_dim1 + a_1 #define af_ref(a_1,a_2) af[af_subscr(a_1,a_2)] #define bf_subscr(a_1,a_2) (a_2)*bf_dim1 + a_1 #define bf_ref(a_1,a_2) bf[bf_subscr(a_1,a_2)] /* -- LAPACK test routine (version 3.0) -- Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd., Courant Institute, Argonne National Lab, and Rice University September 30, 1994 Purpose ======= ZGRQTS tests ZGGRQF, which computes the GRQ factorization of an M-by-N matrix A and a P-by-N matrix B: A = R*Q and B = Z*T*Q. Arguments ========= M (input) INTEGER The number of rows of the matrix A. M >= 0. P (input) INTEGER The number of rows of the matrix B. P >= 0. N (input) INTEGER The number of columns of the matrices A and B. N >= 0. A (input) COMPLEX*16 array, dimension (LDA,N) The M-by-N matrix A. AF (output) COMPLEX*16 array, dimension (LDA,N) Details of the GRQ factorization of A and B, as returned by ZGGRQF, see CGGRQF for further details. Q (output) COMPLEX*16 array, dimension (LDA,N) The N-by-N unitary matrix Q. R (workspace) COMPLEX*16 array, dimension (LDA,MAX(M,N)) LDA (input) INTEGER The leading dimension of the arrays A, AF, R and Q. LDA >= max(M,N). TAUA (output) COMPLEX*16 array, dimension (min(M,N)) The scalar factors of the elementary reflectors, as returned by DGGQRC. B (input) COMPLEX*16 array, dimension (LDB,N) On entry, the P-by-N matrix A. BF (output) COMPLEX*16 array, dimension (LDB,N) Details of the GQR factorization of A and B, as returned by ZGGRQF, see CGGRQF for further details. Z (output) DOUBLE PRECISION array, dimension (LDB,P) The P-by-P unitary matrix Z. T (workspace) COMPLEX*16 array, dimension (LDB,max(P,N)) BWK (workspace) COMPLEX*16 array, dimension (LDB,N) LDB (input) INTEGER The leading dimension of the arrays B, BF, Z and T. LDB >= max(P,N). TAUB (output) COMPLEX*16 array, dimension (min(P,N)) The scalar factors of the elementary reflectors, as returned by DGGRQF. WORK (workspace) COMPLEX*16 array, dimension (LWORK) LWORK (input) INTEGER The dimension of the array WORK, LWORK >= max(M,P,N)**2. RWORK (workspace) DOUBLE PRECISION array, dimension (M) RESULT (output) DOUBLE PRECISION array, dimension (4) The test ratios: RESULT(1) = norm( R - A*Q' ) / ( MAX(M,N)*norm(A)*ULP) RESULT(2) = norm( T*Q - Z'*B ) / (MAX(P,N)*norm(B)*ULP) RESULT(3) = norm( I - Q'*Q ) / ( N*ULP ) RESULT(4) = norm( I - Z'*Z ) / ( P*ULP ) ===================================================================== Parameter adjustments */ r_dim1 = *lda; r_offset = 1 + r_dim1 * 1; r__ -= r_offset; q_dim1 = *lda; q_offset = 1 + q_dim1 * 1; q -= q_offset; af_dim1 = *lda; af_offset = 1 + af_dim1 * 1; af -= af_offset; a_dim1 = *lda; a_offset = 1 + a_dim1 * 1; a -= a_offset; --taua; bwk_dim1 = *ldb; bwk_offset = 1 + bwk_dim1 * 1; bwk -= bwk_offset; t_dim1 = *ldb; t_offset = 1 + t_dim1 * 1; t -= t_offset; z_dim1 = *ldb; z_offset = 1 + z_dim1 * 1; z__ -= z_offset; bf_dim1 = *ldb; bf_offset = 1 + bf_dim1 * 1; bf -= bf_offset; b_dim1 = *ldb; b_offset = 1 + b_dim1 * 1; b -= b_offset; --taub; --work; --rwork; --result; /* Function Body */ ulp = dlamch_("Precision"); unfl = dlamch_("Safe minimum"); /* Copy the matrix A to the array AF. */ zlacpy_("Full", m, n, &a[a_offset], lda, &af[af_offset], lda); zlacpy_("Full", p, n, &b[b_offset], ldb, &bf[bf_offset], ldb); /* Computing MAX */ d__1 = zlange_("1", m, n, &a[a_offset], lda, &rwork[1]); anorm = max(d__1,unfl); /* Computing MAX */ d__1 = zlange_("1", p, n, &b[b_offset], ldb, &rwork[1]); bnorm = max(d__1,unfl); /* Factorize the matrices A and B in the arrays AF and BF. */ zggrqf_(m, p, n, &af[af_offset], lda, &taua[1], &bf[bf_offset], ldb, & taub[1], &work[1], lwork, &info); /* Generate the N-by-N matrix Q */ zlaset_("Full", n, n, &c_b3, &c_b3, &q[q_offset], lda); if (*m <= *n) { if (*m > 0 && *m < *n) { i__1 = *n - *m; zlacpy_("Full", m, &i__1, &af[af_offset], lda, &q_ref(*n - *m + 1, 1), lda); } if (*m > 1) { i__1 = *m - 1; i__2 = *m - 1; zlacpy_("Lower", &i__1, &i__2, &af_ref(2, *n - *m + 1), lda, & q_ref(*n - *m + 2, *n - *m + 1), lda); } } else { if (*n > 1) { i__1 = *n - 1; i__2 = *n - 1; zlacpy_("Lower", &i__1, &i__2, &af_ref(*m - *n + 2, 1), lda, & q_ref(2, 1), lda); } } i__1 = min(*m,*n); zungrq_(n, n, &i__1, &q[q_offset], lda, &taua[1], &work[1], lwork, &info); /* Generate the P-by-P matrix Z */ zlaset_("Full", p, p, &c_b3, &c_b3, &z__[z_offset], ldb); if (*p > 1) { i__1 = *p - 1; zlacpy_("Lower", &i__1, n, &bf_ref(2, 1), ldb, &z___ref(2, 1), ldb); } i__1 = min(*p,*n); zungqr_(p, p, &i__1, &z__[z_offset], ldb, &taub[1], &work[1], lwork, & info); /* Copy R */ zlaset_("Full", m, n, &c_b1, &c_b1, &r__[r_offset], lda); if (*m <= *n) { zlacpy_("Upper", m, m, &af_ref(1, *n - *m + 1), lda, &r___ref(1, *n - *m + 1), lda); } else { i__1 = *m - *n; zlacpy_("Full", &i__1, n, &af[af_offset], lda, &r__[r_offset], lda); zlacpy_("Upper", n, n, &af_ref(*m - *n + 1, 1), lda, &r___ref(*m - *n + 1, 1), lda); } /* Copy T */ zlaset_("Full", p, n, &c_b1, &c_b1, &t[t_offset], ldb); zlacpy_("Upper", p, n, &bf[bf_offset], ldb, &t[t_offset], ldb); /* Compute R - A*Q' */ z__1.r = -1., z__1.i = 0.; zgemm_("No transpose", "Conjugate transpose", m, n, n, &z__1, &a[a_offset] , lda, &q[q_offset], lda, &c_b2, &r__[r_offset], lda); /* Compute norm( R - A*Q' ) / ( MAX(M,N)*norm(A)*ULP ) . */ resid = zlange_("1", m, n, &r__[r_offset], lda, &rwork[1]); if (anorm > 0.) { /* Computing MAX */ i__1 = max(1,*m); result[1] = resid / (doublereal) max(i__1,*n) / anorm / ulp; } else { result[1] = 0.; } /* Compute T*Q - Z'*B */ zgemm_("Conjugate transpose", "No transpose", p, n, p, &c_b2, &z__[ z_offset], ldb, &b[b_offset], ldb, &c_b1, &bwk[bwk_offset], ldb); z__1.r = -1., z__1.i = 0.; zgemm_("No transpose", "No transpose", p, n, n, &c_b2, &t[t_offset], ldb, &q[q_offset], lda, &z__1, &bwk[bwk_offset], ldb); /* Compute norm( T*Q - Z'*B ) / ( MAX(P,N)*norm(A)*ULP ) . */ resid = zlange_("1", p, n, &bwk[bwk_offset], ldb, &rwork[1]); if (bnorm > 0.) { /* Computing MAX */ i__1 = max(1,*p); result[2] = resid / (doublereal) max(i__1,*m) / bnorm / ulp; } else { result[2] = 0.; } /* Compute I - Q*Q' */ zlaset_("Full", n, n, &c_b1, &c_b2, &r__[r_offset], lda); zherk_("Upper", "No Transpose", n, n, &c_b34, &q[q_offset], lda, &c_b35, & r__[r_offset], lda); /* Compute norm( I - Q'*Q ) / ( N * ULP ) . */ resid = zlanhe_("1", "Upper", n, &r__[r_offset], lda, &rwork[1]); result[3] = resid / (doublereal) max(1,*n) / ulp; /* Compute I - Z'*Z */ zlaset_("Full", p, p, &c_b1, &c_b2, &t[t_offset], ldb); zherk_("Upper", "Conjugate transpose", p, p, &c_b34, &z__[z_offset], ldb, &c_b35, &t[t_offset], ldb); /* Compute norm( I - Z'*Z ) / ( P*ULP ) . */ resid = zlanhe_("1", "Upper", p, &t[t_offset], ldb, &rwork[1]); result[4] = resid / (doublereal) max(1,*p) / ulp; return 0; /* End of ZGRQTS */ } /* zgrqts_ */
/* Subroutine */ int zgges_(char *jobvsl, char *jobvsr, char *sort, L_fp delctg, integer *n, doublecomplex *a, integer *lda, doublecomplex *b, integer *ldb, integer *sdim, doublecomplex *alpha, doublecomplex * beta, doublecomplex *vsl, integer *ldvsl, doublecomplex *vsr, integer *ldvsr, doublecomplex *work, integer *lwork, doublereal *rwork, logical *bwork, integer *info) { /* -- LAPACK driver routine (version 3.0) -- Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd., Courant Institute, Argonne National Lab, and Rice University June 30, 1999 Purpose ======= ZGGES computes for a pair of N-by-N complex nonsymmetric matrices (A,B), the generalized eigenvalues, the generalized complex Schur form (S, T), and optionally left and/or right Schur vectors (VSL and VSR). This gives the generalized Schur factorization (A,B) = ( (VSL)*S*(VSR)**H, (VSL)*T*(VSR)**H ) where (VSR)**H is the conjugate-transpose of VSR. Optionally, it also orders the eigenvalues so that a selected cluster of eigenvalues appears in the leading diagonal blocks of the upper triangular matrix S and the upper triangular matrix T. The leading columns of VSL and VSR then form an unitary basis for the corresponding left and right eigenspaces (deflating subspaces). (If only the generalized eigenvalues are needed, use the driver ZGGEV instead, which is faster.) A generalized eigenvalue for a pair of matrices (A,B) is a scalar w or a ratio alpha/beta = w, such that A - w*B is singular. It is usually represented as the pair (alpha,beta), as there is a reasonable interpretation for beta=0, and even for both being zero. A pair of matrices (S,T) is in generalized complex Schur form if S and T are upper triangular and, in addition, the diagonal elements of T are non-negative real numbers. Arguments ========= JOBVSL (input) CHARACTER*1 = 'N': do not compute the left Schur vectors; = 'V': compute the left Schur vectors. JOBVSR (input) CHARACTER*1 = 'N': do not compute the right Schur vectors; = 'V': compute the right Schur vectors. SORT (input) CHARACTER*1 Specifies whether or not to order the eigenvalues on the diagonal of the generalized Schur form. = 'N': Eigenvalues are not ordered; = 'S': Eigenvalues are ordered (see DELZTG). DELZTG (input) LOGICAL FUNCTION of two COMPLEX*16 arguments DELZTG must be declared EXTERNAL in the calling subroutine. If SORT = 'N', DELZTG is not referenced. If SORT = 'S', DELZTG is used to select eigenvalues to sort to the top left of the Schur form. An eigenvalue ALPHA(j)/BETA(j) is selected if DELZTG(ALPHA(j),BETA(j)) is true. Note that a selected complex eigenvalue may no longer satisfy DELZTG(ALPHA(j),BETA(j)) = .TRUE. after ordering, since ordering may change the value of complex eigenvalues (especially if the eigenvalue is ill-conditioned), in this case INFO is set to N+2 (See INFO below). N (input) INTEGER The order of the matrices A, B, VSL, and VSR. N >= 0. A (input/output) COMPLEX*16 array, dimension (LDA, N) On entry, the first of the pair of matrices. On exit, A has been overwritten by its generalized Schur form S. LDA (input) INTEGER The leading dimension of A. LDA >= max(1,N). B (input/output) COMPLEX*16 array, dimension (LDB, N) On entry, the second of the pair of matrices. On exit, B has been overwritten by its generalized Schur form T. LDB (input) INTEGER The leading dimension of B. LDB >= max(1,N). SDIM (output) INTEGER If SORT = 'N', SDIM = 0. If SORT = 'S', SDIM = number of eigenvalues (after sorting) for which DELZTG is true. ALPHA (output) COMPLEX*16 array, dimension (N) BETA (output) COMPLEX*16 array, dimension (N) On exit, ALPHA(j)/BETA(j), j=1,...,N, will be the generalized eigenvalues. ALPHA(j), j=1,...,N and BETA(j), j=1,...,N are the diagonals of the complex Schur form (A,B) output by ZGGES. The BETA(j) will be non-negative real. Note: the quotients ALPHA(j)/BETA(j) may easily over- or underflow, and BETA(j) may even be zero. Thus, the user should avoid naively computing the ratio alpha/beta. However, ALPHA will be always less than and usually comparable with norm(A) in magnitude, and BETA always less than and usually comparable with norm(B). VSL (output) COMPLEX*16 array, dimension (LDVSL,N) If JOBVSL = 'V', VSL will contain the left Schur vectors. Not referenced if JOBVSL = 'N'. LDVSL (input) INTEGER The leading dimension of the matrix VSL. LDVSL >= 1, and if JOBVSL = 'V', LDVSL >= N. VSR (output) COMPLEX*16 array, dimension (LDVSR,N) If JOBVSR = 'V', VSR will contain the right Schur vectors. Not referenced if JOBVSR = 'N'. LDVSR (input) INTEGER The leading dimension of the matrix VSR. LDVSR >= 1, and if JOBVSR = 'V', LDVSR >= N. WORK (workspace/output) COMPLEX*16 array, dimension (LWORK) On exit, if INFO = 0, WORK(1) returns the optimal LWORK. LWORK (input) INTEGER The dimension of the array WORK. LWORK >= max(1,2*N). For good performance, LWORK must generally be larger. If LWORK = -1, then a workspace query is assumed; the routine only calculates the optimal size of the WORK array, returns this value as the first entry of the WORK array, and no error message related to LWORK is issued by XERBLA. RWORK (workspace) DOUBLE PRECISION array, dimension (8*N) BWORK (workspace) LOGICAL array, dimension (N) Not referenced if SORT = 'N'. INFO (output) INTEGER = 0: successful exit < 0: if INFO = -i, the i-th argument had an illegal value. =1,...,N: The QZ iteration failed. (A,B) are not in Schur form, but ALPHA(j) and BETA(j) should be correct for j=INFO+1,...,N. > N: =N+1: other than QZ iteration failed in ZHGEQZ =N+2: after reordering, roundoff changed values of some complex eigenvalues so that leading eigenvalues in the Generalized Schur form no longer satisfy DELZTG=.TRUE. This could also be caused due to scaling. =N+3: reordering falied in ZTGSEN. ===================================================================== Decode the input arguments Parameter adjustments */ /* Table of constant values */ static doublecomplex c_b1 = {0.,0.}; static doublecomplex c_b2 = {1.,0.}; static integer c__1 = 1; static integer c__0 = 0; static integer c_n1 = -1; /* System generated locals */ integer a_dim1, a_offset, b_dim1, b_offset, vsl_dim1, vsl_offset, vsr_dim1, vsr_offset, i__1, i__2; /* Builtin functions */ double sqrt(doublereal); /* Local variables */ static doublereal anrm, bnrm; static integer idum[1], ierr, itau, iwrk; static doublereal pvsl, pvsr; static integer i__; extern logical lsame_(char *, char *); static integer ileft, icols; static logical cursl, ilvsl, ilvsr; static integer irwrk, irows; extern /* Subroutine */ int dlabad_(doublereal *, doublereal *); extern doublereal dlamch_(char *); extern /* Subroutine */ int zggbak_(char *, char *, integer *, integer *, integer *, doublereal *, doublereal *, integer *, doublecomplex *, integer *, integer *), zggbal_(char *, integer *, doublecomplex *, integer *, doublecomplex *, integer *, integer * , integer *, doublereal *, doublereal *, doublereal *, integer *); static logical ilascl, ilbscl; extern /* Subroutine */ int xerbla_(char *, integer *); extern integer ilaenv_(integer *, char *, char *, integer *, integer *, integer *, integer *, ftnlen, ftnlen); extern doublereal zlange_(char *, integer *, integer *, doublecomplex *, integer *, doublereal *); static doublereal bignum; static integer ijobvl, iright; extern /* Subroutine */ int zgghrd_(char *, char *, integer *, integer *, integer *, doublecomplex *, integer *, doublecomplex *, integer *, doublecomplex *, integer *, doublecomplex *, integer *, integer * ), zlascl_(char *, integer *, integer *, doublereal *, doublereal *, integer *, integer *, doublecomplex *, integer *, integer *); static integer ijobvr; extern /* Subroutine */ int zgeqrf_(integer *, integer *, doublecomplex *, integer *, doublecomplex *, doublecomplex *, integer *, integer * ); static doublereal anrmto; static integer lwkmin; static logical lastsl; static doublereal bnrmto; extern /* Subroutine */ int zlacpy_(char *, integer *, integer *, doublecomplex *, integer *, doublecomplex *, integer *), zlaset_(char *, integer *, integer *, doublecomplex *, doublecomplex *, doublecomplex *, integer *), zhgeqz_( char *, char *, char *, integer *, integer *, integer *, doublecomplex *, integer *, doublecomplex *, integer *, doublecomplex *, doublecomplex *, doublecomplex *, integer *, doublecomplex *, integer *, doublecomplex *, integer *, doublereal *, integer *), ztgsen_(integer *, logical *, logical *, logical *, integer *, doublecomplex *, integer *, doublecomplex *, integer *, doublecomplex *, doublecomplex *, doublecomplex *, integer *, doublecomplex *, integer *, integer *, doublereal *, doublereal *, doublereal *, doublecomplex *, integer *, integer *, integer *, integer *); static doublereal smlnum; static logical wantst, lquery; static integer lwkopt; extern /* Subroutine */ int zungqr_(integer *, integer *, integer *, doublecomplex *, integer *, doublecomplex *, doublecomplex *, integer *, integer *), zunmqr_(char *, char *, integer *, integer *, integer *, doublecomplex *, integer *, doublecomplex *, doublecomplex *, integer *, doublecomplex *, integer *, integer *); static doublereal dif[2]; static integer ihi, ilo; static doublereal eps; #define a_subscr(a_1,a_2) (a_2)*a_dim1 + a_1 #define a_ref(a_1,a_2) a[a_subscr(a_1,a_2)] #define b_subscr(a_1,a_2) (a_2)*b_dim1 + a_1 #define b_ref(a_1,a_2) b[b_subscr(a_1,a_2)] #define vsl_subscr(a_1,a_2) (a_2)*vsl_dim1 + a_1 #define vsl_ref(a_1,a_2) vsl[vsl_subscr(a_1,a_2)] a_dim1 = *lda; a_offset = 1 + a_dim1 * 1; a -= a_offset; b_dim1 = *ldb; b_offset = 1 + b_dim1 * 1; b -= b_offset; --alpha; --beta; vsl_dim1 = *ldvsl; vsl_offset = 1 + vsl_dim1 * 1; vsl -= vsl_offset; vsr_dim1 = *ldvsr; vsr_offset = 1 + vsr_dim1 * 1; vsr -= vsr_offset; --work; --rwork; --bwork; /* Function Body */ if (lsame_(jobvsl, "N")) { ijobvl = 1; ilvsl = FALSE_; } else if (lsame_(jobvsl, "V")) { ijobvl = 2; ilvsl = TRUE_; } else { ijobvl = -1; ilvsl = FALSE_; } if (lsame_(jobvsr, "N")) { ijobvr = 1; ilvsr = FALSE_; } else if (lsame_(jobvsr, "V")) { ijobvr = 2; ilvsr = TRUE_; } else { ijobvr = -1; ilvsr = FALSE_; } wantst = lsame_(sort, "S"); /* Test the input arguments */ *info = 0; lquery = *lwork == -1; if (ijobvl <= 0) { *info = -1; } else if (ijobvr <= 0) { *info = -2; } else if (! wantst && ! lsame_(sort, "N")) { *info = -3; } else if (*n < 0) { *info = -5; } else if (*lda < max(1,*n)) { *info = -7; } else if (*ldb < max(1,*n)) { *info = -9; } else if (*ldvsl < 1 || ilvsl && *ldvsl < *n) { *info = -14; } else if (*ldvsr < 1 || ilvsr && *ldvsr < *n) { *info = -16; } /* Compute workspace (Note: Comments in the code beginning "Workspace:" describe the minimal amount of workspace needed at that point in the code, as well as the preferred amount for good performance. NB refers to the optimal block size for the immediately following subroutine, as returned by ILAENV.) */ lwkmin = 1; if (*info == 0 && (*lwork >= 1 || lquery)) { /* Computing MAX */ i__1 = 1, i__2 = *n << 1; lwkmin = max(i__1,i__2); lwkopt = *n + *n * ilaenv_(&c__1, "ZGEQRF", " ", n, &c__1, n, &c__0, ( ftnlen)6, (ftnlen)1); if (ilvsl) { /* Computing MAX */ i__1 = lwkopt, i__2 = *n + *n * ilaenv_(&c__1, "ZUNGQR", " ", n, & c__1, n, &c_n1, (ftnlen)6, (ftnlen)1); lwkopt = max(i__1,i__2); } work[1].r = (doublereal) lwkopt, work[1].i = 0.; } if (*lwork < lwkmin && ! lquery) { *info = -18; } if (*info != 0) { i__1 = -(*info); xerbla_("ZGGES ", &i__1); return 0; } else if (lquery) { return 0; } /* Quick return if possible */ work[1].r = (doublereal) lwkopt, work[1].i = 0.; if (*n == 0) { *sdim = 0; return 0; } /* Get machine constants */ eps = dlamch_("P"); smlnum = dlamch_("S"); bignum = 1. / smlnum; dlabad_(&smlnum, &bignum); smlnum = sqrt(smlnum) / eps; bignum = 1. / smlnum; /* Scale A if max element outside range [SMLNUM,BIGNUM] */ anrm = zlange_("M", n, n, &a[a_offset], lda, &rwork[1]); ilascl = FALSE_; if (anrm > 0. && anrm < smlnum) { anrmto = smlnum; ilascl = TRUE_; } else if (anrm > bignum) { anrmto = bignum; ilascl = TRUE_; } if (ilascl) { zlascl_("G", &c__0, &c__0, &anrm, &anrmto, n, n, &a[a_offset], lda, & ierr); } /* Scale B if max element outside range [SMLNUM,BIGNUM] */ bnrm = zlange_("M", n, n, &b[b_offset], ldb, &rwork[1]); ilbscl = FALSE_; if (bnrm > 0. && bnrm < smlnum) { bnrmto = smlnum; ilbscl = TRUE_; } else if (bnrm > bignum) { bnrmto = bignum; ilbscl = TRUE_; } if (ilbscl) { zlascl_("G", &c__0, &c__0, &bnrm, &bnrmto, n, n, &b[b_offset], ldb, & ierr); } /* Permute the matrix to make it more nearly triangular (Real Workspace: need 6*N) */ ileft = 1; iright = *n + 1; irwrk = iright + *n; zggbal_("P", n, &a[a_offset], lda, &b[b_offset], ldb, &ilo, &ihi, &rwork[ ileft], &rwork[iright], &rwork[irwrk], &ierr); /* Reduce B to triangular form (QR decomposition of B) (Complex Workspace: need N, prefer N*NB) */ irows = ihi + 1 - ilo; icols = *n + 1 - ilo; itau = 1; iwrk = itau + irows; i__1 = *lwork + 1 - iwrk; zgeqrf_(&irows, &icols, &b_ref(ilo, ilo), ldb, &work[itau], &work[iwrk], & i__1, &ierr); /* Apply the orthogonal transformation to matrix A (Complex Workspace: need N, prefer N*NB) */ i__1 = *lwork + 1 - iwrk; zunmqr_("L", "C", &irows, &icols, &irows, &b_ref(ilo, ilo), ldb, &work[ itau], &a_ref(ilo, ilo), lda, &work[iwrk], &i__1, &ierr); /* Initialize VSL (Complex Workspace: need N, prefer N*NB) */ if (ilvsl) { zlaset_("Full", n, n, &c_b1, &c_b2, &vsl[vsl_offset], ldvsl); i__1 = irows - 1; i__2 = irows - 1; zlacpy_("L", &i__1, &i__2, &b_ref(ilo + 1, ilo), ldb, &vsl_ref(ilo + 1, ilo), ldvsl); i__1 = *lwork + 1 - iwrk; zungqr_(&irows, &irows, &irows, &vsl_ref(ilo, ilo), ldvsl, &work[itau] , &work[iwrk], &i__1, &ierr); } /* Initialize VSR */ if (ilvsr) { zlaset_("Full", n, n, &c_b1, &c_b2, &vsr[vsr_offset], ldvsr); } /* Reduce to generalized Hessenberg form (Workspace: none needed) */ zgghrd_(jobvsl, jobvsr, n, &ilo, &ihi, &a[a_offset], lda, &b[b_offset], ldb, &vsl[vsl_offset], ldvsl, &vsr[vsr_offset], ldvsr, &ierr); *sdim = 0; /* Perform QZ algorithm, computing Schur vectors if desired (Complex Workspace: need N) (Real Workspace: need N) */ iwrk = itau; i__1 = *lwork + 1 - iwrk; zhgeqz_("S", jobvsl, jobvsr, n, &ilo, &ihi, &a[a_offset], lda, &b[ b_offset], ldb, &alpha[1], &beta[1], &vsl[vsl_offset], ldvsl, & vsr[vsr_offset], ldvsr, &work[iwrk], &i__1, &rwork[irwrk], &ierr); if (ierr != 0) { if (ierr > 0 && ierr <= *n) { *info = ierr; } else if (ierr > *n && ierr <= *n << 1) { *info = ierr - *n; } else { *info = *n + 1; } goto L30; } /* Sort eigenvalues ALPHA/BETA if desired (Workspace: none needed) */ if (wantst) { /* Undo scaling on eigenvalues before selecting */ if (ilascl) { zlascl_("G", &c__0, &c__0, &anrm, &anrmto, n, &c__1, &alpha[1], n, &ierr); } if (ilbscl) { zlascl_("G", &c__0, &c__0, &bnrm, &bnrmto, n, &c__1, &beta[1], n, &ierr); } /* Select eigenvalues */ i__1 = *n; for (i__ = 1; i__ <= i__1; ++i__) { bwork[i__] = (*delctg)(&alpha[i__], &beta[i__]); /* L10: */ } i__1 = *lwork - iwrk + 1; ztgsen_(&c__0, &ilvsl, &ilvsr, &bwork[1], n, &a[a_offset], lda, &b[ b_offset], ldb, &alpha[1], &beta[1], &vsl[vsl_offset], ldvsl, &vsr[vsr_offset], ldvsr, sdim, &pvsl, &pvsr, dif, &work[iwrk], &i__1, idum, &c__1, &ierr); if (ierr == 1) { *info = *n + 3; } } /* Apply back-permutation to VSL and VSR (Workspace: none needed) */ if (ilvsl) { zggbak_("P", "L", n, &ilo, &ihi, &rwork[ileft], &rwork[iright], n, & vsl[vsl_offset], ldvsl, &ierr); } if (ilvsr) { zggbak_("P", "R", n, &ilo, &ihi, &rwork[ileft], &rwork[iright], n, & vsr[vsr_offset], ldvsr, &ierr); } /* Undo scaling */ if (ilascl) { zlascl_("U", &c__0, &c__0, &anrmto, &anrm, n, n, &a[a_offset], lda, & ierr); zlascl_("G", &c__0, &c__0, &anrmto, &anrm, n, &c__1, &alpha[1], n, & ierr); } if (ilbscl) { zlascl_("U", &c__0, &c__0, &bnrmto, &bnrm, n, n, &b[b_offset], ldb, & ierr); zlascl_("G", &c__0, &c__0, &bnrmto, &bnrm, n, &c__1, &beta[1], n, & ierr); } if (wantst) { /* Check if reordering is correct */ lastsl = TRUE_; *sdim = 0; i__1 = *n; for (i__ = 1; i__ <= i__1; ++i__) { cursl = (*delctg)(&alpha[i__], &beta[i__]); if (cursl) { ++(*sdim); } if (cursl && ! lastsl) { *info = *n + 2; } lastsl = cursl; /* L20: */ } } L30: work[1].r = (doublereal) lwkopt, work[1].i = 0.; return 0; /* End of ZGGES */ } /* zgges_ */
/*< SUBROUTINE ZUNGHR( N, ILO, IHI, A, LDA, TAU, WORK, LWORK, INFO ) >*/ /* Subroutine */ int zunghr_(integer *n, integer *ilo, integer *ihi, doublecomplex *a, integer *lda, doublecomplex *tau, doublecomplex * work, integer *lwork, integer *info) { /* System generated locals */ integer a_dim1, a_offset, i__1, i__2, i__3, i__4; /* Local variables */ integer i__, j, nb, nh, iinfo; extern /* Subroutine */ int xerbla_(char *, integer *, ftnlen); extern integer ilaenv_(integer *, char *, char *, integer *, integer *, integer *, integer *, ftnlen, ftnlen); integer lwkopt=0; logical lquery; extern /* Subroutine */ int zungqr_(integer *, integer *, integer *, doublecomplex *, integer *, doublecomplex *, doublecomplex *, integer *, integer *); /* -- LAPACK routine (version 3.0) -- */ /* Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd., */ /* Courant Institute, Argonne National Lab, and Rice University */ /* June 30, 1999 */ /* .. Scalar Arguments .. */ /*< INTEGER IHI, ILO, INFO, LDA, LWORK, N >*/ /* .. */ /* .. Array Arguments .. */ /*< COMPLEX*16 A( LDA, * ), TAU( * ), WORK( * ) >*/ /* .. */ /* Purpose */ /* ======= */ /* ZUNGHR generates a complex unitary matrix Q which is defined as the */ /* product of IHI-ILO elementary reflectors of order N, as returned by */ /* ZGEHRD: */ /* Q = H(ilo) H(ilo+1) . . . H(ihi-1). */ /* Arguments */ /* ========= */ /* N (input) INTEGER */ /* The order of the matrix Q. N >= 0. */ /* ILO (input) INTEGER */ /* IHI (input) INTEGER */ /* ILO and IHI must have the same values as in the previous call */ /* of ZGEHRD. Q is equal to the unit matrix except in the */ /* submatrix Q(ilo+1:ihi,ilo+1:ihi). */ /* 1 <= ILO <= IHI <= N, if N > 0; ILO=1 and IHI=0, if N=0. */ /* A (input/output) COMPLEX*16 array, dimension (LDA,N) */ /* On entry, the vectors which define the elementary reflectors, */ /* as returned by ZGEHRD. */ /* On exit, the N-by-N unitary matrix Q. */ /* LDA (input) INTEGER */ /* The leading dimension of the array A. LDA >= max(1,N). */ /* TAU (input) COMPLEX*16 array, dimension (N-1) */ /* TAU(i) must contain the scalar factor of the elementary */ /* reflector H(i), as returned by ZGEHRD. */ /* WORK (workspace/output) COMPLEX*16 array, dimension (LWORK) */ /* On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */ /* LWORK (input) INTEGER */ /* The dimension of the array WORK. LWORK >= IHI-ILO. */ /* For optimum performance LWORK >= (IHI-ILO)*NB, where NB is */ /* the optimal blocksize. */ /* If LWORK = -1, then a workspace query is assumed; the routine */ /* only calculates the optimal size of the WORK array, returns */ /* this value as the first entry of the WORK array, and no error */ /* message related to LWORK is issued by XERBLA. */ /* INFO (output) INTEGER */ /* = 0: successful exit */ /* < 0: if INFO = -i, the i-th argument had an illegal value */ /* ===================================================================== */ /* .. Parameters .. */ /*< COMPLEX*16 ZERO, ONE >*/ /*< >*/ /* .. */ /* .. Local Scalars .. */ /*< LOGICAL LQUERY >*/ /*< INTEGER I, IINFO, J, LWKOPT, NB, NH >*/ /* .. */ /* .. External Subroutines .. */ /*< EXTERNAL XERBLA, ZUNGQR >*/ /* .. */ /* .. External Functions .. */ /*< INTEGER ILAENV >*/ /*< EXTERNAL ILAENV >*/ /* .. */ /* .. Intrinsic Functions .. */ /*< INTRINSIC MAX, MIN >*/ /* .. */ /* .. Executable Statements .. */ /* Test the input arguments */ /*< INFO = 0 >*/ /* Parameter adjustments */ a_dim1 = *lda; a_offset = 1 + a_dim1; a -= a_offset; --tau; --work; /* Function Body */ *info = 0; /*< NH = IHI - ILO >*/ nh = *ihi - *ilo; /*< LQUERY = ( LWORK.EQ.-1 ) >*/ lquery = *lwork == -1; /*< IF( N.LT.0 ) THEN >*/ if (*n < 0) { /*< INFO = -1 >*/ *info = -1; /*< ELSE IF( ILO.LT.1 .OR. ILO.GT.MAX( 1, N ) ) THEN >*/ } else if (*ilo < 1 || *ilo > max(1,*n)) { /*< INFO = -2 >*/ *info = -2; /*< ELSE IF( IHI.LT.MIN( ILO, N ) .OR. IHI.GT.N ) THEN >*/ } else if (*ihi < min(*ilo,*n) || *ihi > *n) { /*< INFO = -3 >*/ *info = -3; /*< ELSE IF( LDA.LT.MAX( 1, N ) ) THEN >*/ } else if (*lda < max(1,*n)) { /*< INFO = -5 >*/ *info = -5; /*< ELSE IF( LWORK.LT.MAX( 1, NH ) .AND. .NOT.LQUERY ) THEN >*/ } else if (*lwork < max(1,nh) && ! lquery) { /*< INFO = -8 >*/ *info = -8; /*< END IF >*/ } /*< IF( INFO.EQ.0 ) THEN >*/ if (*info == 0) { /*< NB = ILAENV( 1, 'ZUNGQR', ' ', NH, NH, NH, -1 ) >*/ nb = ilaenv_(&c__1, "ZUNGQR", " ", &nh, &nh, &nh, &c_n1, (ftnlen)6, ( ftnlen)1); /*< LWKOPT = MAX( 1, NH )*NB >*/ lwkopt = max(1,nh) * nb; /*< WORK( 1 ) = LWKOPT >*/ work[1].r = (doublereal) lwkopt, work[1].i = 0.; /*< END IF >*/ } /*< IF( INFO.NE.0 ) THEN >*/ if (*info != 0) { /*< CALL XERBLA( 'ZUNGHR', -INFO ) >*/ i__1 = -(*info); xerbla_("ZUNGHR", &i__1, (ftnlen)6); /*< RETURN >*/ return 0; /*< ELSE IF( LQUERY ) THEN >*/ } else if (lquery) { /*< RETURN >*/ return 0; /*< END IF >*/ } /* Quick return if possible */ /*< IF( N.EQ.0 ) THEN >*/ if (*n == 0) { /*< WORK( 1 ) = 1 >*/ work[1].r = 1., work[1].i = 0.; /*< RETURN >*/ return 0; /*< END IF >*/ } /* Shift the vectors which define the elementary reflectors one */ /* column to the right, and set the first ilo and the last n-ihi */ /* rows and columns to those of the unit matrix */ /*< DO 40 J = IHI, ILO + 1, -1 >*/ i__1 = *ilo + 1; for (j = *ihi; j >= i__1; --j) { /*< DO 10 I = 1, J - 1 >*/ i__2 = j - 1; for (i__ = 1; i__ <= i__2; ++i__) { /*< A( I, J ) = ZERO >*/ i__3 = i__ + j * a_dim1; a[i__3].r = 0., a[i__3].i = 0.; /*< 10 CONTINUE >*/ /* L10: */ } /*< DO 20 I = J + 1, IHI >*/ i__2 = *ihi; for (i__ = j + 1; i__ <= i__2; ++i__) { /*< A( I, J ) = A( I, J-1 ) >*/ i__3 = i__ + j * a_dim1; i__4 = i__ + (j - 1) * a_dim1; a[i__3].r = a[i__4].r, a[i__3].i = a[i__4].i; /*< 20 CONTINUE >*/ /* L20: */ } /*< DO 30 I = IHI + 1, N >*/ i__2 = *n; for (i__ = *ihi + 1; i__ <= i__2; ++i__) { /*< A( I, J ) = ZERO >*/ i__3 = i__ + j * a_dim1; a[i__3].r = 0., a[i__3].i = 0.; /*< 30 CONTINUE >*/ /* L30: */ } /*< 40 CONTINUE >*/ /* L40: */ } /*< DO 60 J = 1, ILO >*/ i__1 = *ilo; for (j = 1; j <= i__1; ++j) { /*< DO 50 I = 1, N >*/ i__2 = *n; for (i__ = 1; i__ <= i__2; ++i__) { /*< A( I, J ) = ZERO >*/ i__3 = i__ + j * a_dim1; a[i__3].r = 0., a[i__3].i = 0.; /*< 50 CONTINUE >*/ /* L50: */ } /*< A( J, J ) = ONE >*/ i__2 = j + j * a_dim1; a[i__2].r = 1., a[i__2].i = 0.; /*< 60 CONTINUE >*/ /* L60: */ } /*< DO 80 J = IHI + 1, N >*/ i__1 = *n; for (j = *ihi + 1; j <= i__1; ++j) { /*< DO 70 I = 1, N >*/ i__2 = *n; for (i__ = 1; i__ <= i__2; ++i__) { /*< A( I, J ) = ZERO >*/ i__3 = i__ + j * a_dim1; a[i__3].r = 0., a[i__3].i = 0.; /*< 70 CONTINUE >*/ /* L70: */ } /*< A( J, J ) = ONE >*/ i__2 = j + j * a_dim1; a[i__2].r = 1., a[i__2].i = 0.; /*< 80 CONTINUE >*/ /* L80: */ } /*< IF( NH.GT.0 ) THEN >*/ if (nh > 0) { /* Generate Q(ilo+1:ihi,ilo+1:ihi) */ /*< >*/ zungqr_(&nh, &nh, &nh, &a[*ilo + 1 + (*ilo + 1) * a_dim1], lda, &tau[* ilo], &work[1], lwork, &iinfo); /*< END IF >*/ } /*< WORK( 1 ) = LWKOPT >*/ work[1].r = (doublereal) lwkopt, work[1].i = 0.; /*< RETURN >*/ return 0; /* End of ZUNGHR */ /*< END >*/ } /* zunghr_ */
/* Subroutine */ int zqrt03_(integer *m, integer *n, integer *k, doublecomplex *af, doublecomplex *c__, doublecomplex *cc, doublecomplex *q, integer *lda, doublecomplex *tau, doublecomplex * work, integer *lwork, doublereal *rwork, doublereal *result) { /* Initialized data */ static integer iseed[4] = { 1988,1989,1990,1991 }; /* System generated locals */ integer af_dim1, af_offset, c_dim1, c_offset, cc_dim1, cc_offset, q_dim1, q_offset, i__1; /* Builtin functions */ /* Subroutine */ int s_copy(char *, char *, ftnlen, ftnlen); /* Local variables */ integer j, mc, nc; doublereal eps; char side[1]; integer info, iside; extern logical lsame_(char *, char *); doublereal resid, cnorm; extern /* Subroutine */ int zgemm_(char *, char *, integer *, integer *, integer *, doublecomplex *, doublecomplex *, integer *, doublecomplex *, integer *, doublecomplex *, doublecomplex *, integer *); char trans[1]; extern doublereal dlamch_(char *), zlange_(char *, integer *, integer *, doublecomplex *, integer *, doublereal *); integer itrans; extern /* Subroutine */ int zlacpy_(char *, integer *, integer *, doublecomplex *, integer *, doublecomplex *, integer *), zlaset_(char *, integer *, integer *, doublecomplex *, doublecomplex *, doublecomplex *, integer *), zlarnv_( integer *, integer *, integer *, doublecomplex *), zungqr_( integer *, integer *, integer *, doublecomplex *, integer *, doublecomplex *, doublecomplex *, integer *, integer *), zunmqr_( char *, char *, integer *, integer *, integer *, doublecomplex *, integer *, doublecomplex *, doublecomplex *, integer *, doublecomplex *, integer *, integer *); /* -- LAPACK test routine (version 3.1) -- */ /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */ /* November 2006 */ /* .. Scalar Arguments .. */ /* .. */ /* .. Array Arguments .. */ /* .. */ /* Purpose */ /* ======= */ /* ZQRT03 tests ZUNMQR, which computes Q*C, Q'*C, C*Q or C*Q'. */ /* ZQRT03 compares the results of a call to ZUNMQR with the results of */ /* forming Q explicitly by a call to ZUNGQR and then performing matrix */ /* multiplication by a call to ZGEMM. */ /* Arguments */ /* ========= */ /* M (input) INTEGER */ /* The order of the orthogonal matrix Q. M >= 0. */ /* N (input) INTEGER */ /* The number of rows or columns of the matrix C; C is m-by-n if */ /* Q is applied from the left, or n-by-m if Q is applied from */ /* the right. N >= 0. */ /* K (input) INTEGER */ /* The number of elementary reflectors whose product defines the */ /* orthogonal matrix Q. M >= K >= 0. */ /* AF (input) COMPLEX*16 array, dimension (LDA,N) */ /* Details of the QR factorization of an m-by-n matrix, as */ /* returnedby ZGEQRF. See CGEQRF for further details. */ /* C (workspace) COMPLEX*16 array, dimension (LDA,N) */ /* CC (workspace) COMPLEX*16 array, dimension (LDA,N) */ /* Q (workspace) COMPLEX*16 array, dimension (LDA,M) */ /* LDA (input) INTEGER */ /* The leading dimension of the arrays AF, C, CC, and Q. */ /* TAU (input) COMPLEX*16 array, dimension (min(M,N)) */ /* The scalar factors of the elementary reflectors corresponding */ /* to the QR factorization in AF. */ /* WORK (workspace) COMPLEX*16 array, dimension (LWORK) */ /* LWORK (input) INTEGER */ /* The length of WORK. LWORK must be at least M, and should be */ /* M*NB, where NB is the blocksize for this environment. */ /* RWORK (workspace) DOUBLE PRECISION array, dimension (M) */ /* RESULT (output) DOUBLE PRECISION array, dimension (4) */ /* The test ratios compare two techniques for multiplying a */ /* random matrix C by an m-by-m orthogonal matrix Q. */ /* RESULT(1) = norm( Q*C - Q*C ) / ( M * norm(C) * EPS ) */ /* RESULT(2) = norm( C*Q - C*Q ) / ( M * norm(C) * EPS ) */ /* RESULT(3) = norm( Q'*C - Q'*C )/ ( M * norm(C) * EPS ) */ /* RESULT(4) = norm( C*Q' - C*Q' )/ ( M * norm(C) * EPS ) */ /* ===================================================================== */ /* .. Parameters .. */ /* .. */ /* .. Local Scalars .. */ /* .. */ /* .. External Functions .. */ /* .. */ /* .. External Subroutines .. */ /* .. */ /* .. Local Arrays .. */ /* .. */ /* .. Intrinsic Functions .. */ /* .. */ /* .. Scalars in Common .. */ /* .. */ /* .. Common blocks .. */ /* .. */ /* .. Data statements .. */ /* Parameter adjustments */ q_dim1 = *lda; q_offset = 1 + q_dim1; q -= q_offset; cc_dim1 = *lda; cc_offset = 1 + cc_dim1; cc -= cc_offset; c_dim1 = *lda; c_offset = 1 + c_dim1; c__ -= c_offset; af_dim1 = *lda; af_offset = 1 + af_dim1; af -= af_offset; --tau; --work; --rwork; --result; /* Function Body */ /* .. */ /* .. Executable Statements .. */ eps = dlamch_("Epsilon"); /* Copy the first k columns of the factorization to the array Q */ zlaset_("Full", m, m, &c_b1, &c_b1, &q[q_offset], lda); i__1 = *m - 1; zlacpy_("Lower", &i__1, k, &af[af_dim1 + 2], lda, &q[q_dim1 + 2], lda); /* Generate the m-by-m matrix Q */ s_copy(srnamc_1.srnamt, "ZUNGQR", (ftnlen)32, (ftnlen)6); zungqr_(m, m, k, &q[q_offset], lda, &tau[1], &work[1], lwork, &info); for (iside = 1; iside <= 2; ++iside) { if (iside == 1) { *(unsigned char *)side = 'L'; mc = *m; nc = *n; } else { *(unsigned char *)side = 'R'; mc = *n; nc = *m; } /* Generate MC by NC matrix C */ i__1 = nc; for (j = 1; j <= i__1; ++j) { zlarnv_(&c__2, iseed, &mc, &c__[j * c_dim1 + 1]); /* L10: */ } cnorm = zlange_("1", &mc, &nc, &c__[c_offset], lda, &rwork[1]); if (cnorm == 0.) { cnorm = 1.; } for (itrans = 1; itrans <= 2; ++itrans) { if (itrans == 1) { *(unsigned char *)trans = 'N'; } else { *(unsigned char *)trans = 'C'; } /* Copy C */ zlacpy_("Full", &mc, &nc, &c__[c_offset], lda, &cc[cc_offset], lda); /* Apply Q or Q' to C */ s_copy(srnamc_1.srnamt, "ZUNMQR", (ftnlen)32, (ftnlen)6); zunmqr_(side, trans, &mc, &nc, k, &af[af_offset], lda, &tau[1], & cc[cc_offset], lda, &work[1], lwork, &info); /* Form explicit product and subtract */ if (lsame_(side, "L")) { zgemm_(trans, "No transpose", &mc, &nc, &mc, &c_b20, &q[ q_offset], lda, &c__[c_offset], lda, &c_b21, &cc[ cc_offset], lda); } else { zgemm_("No transpose", trans, &mc, &nc, &nc, &c_b20, &c__[ c_offset], lda, &q[q_offset], lda, &c_b21, &cc[ cc_offset], lda); } /* Compute error in the difference */ resid = zlange_("1", &mc, &nc, &cc[cc_offset], lda, &rwork[1]); result[(iside - 1 << 1) + itrans] = resid / ((doublereal) max(1,* m) * cnorm * eps); /* L20: */ } /* L30: */ } return 0; /* End of ZQRT03 */ } /* zqrt03_ */
/* Subroutine */ int zqrt01_(integer *m, integer *n, doublecomplex *a, doublecomplex *af, doublecomplex *q, doublecomplex *r__, integer *lda, doublecomplex *tau, doublecomplex *work, integer *lwork, doublereal * rwork, doublereal *result) { /* System generated locals */ integer a_dim1, a_offset, af_dim1, af_offset, q_dim1, q_offset, r_dim1, r_offset, i__1; /* Builtin functions */ /* Subroutine */ int s_copy(char *, char *, ftnlen, ftnlen); /* Local variables */ doublereal eps; integer info; doublereal resid, anorm; integer minmn; extern /* Subroutine */ int zgemm_(char *, char *, integer *, integer *, integer *, doublecomplex *, doublecomplex *, integer *, doublecomplex *, integer *, doublecomplex *, doublecomplex *, integer *), zherk_(char *, char *, integer *, integer *, doublereal *, doublecomplex *, integer *, doublereal *, doublecomplex *, integer *); extern doublereal dlamch_(char *), zlange_(char *, integer *, integer *, doublecomplex *, integer *, doublereal *); extern /* Subroutine */ int zgeqrf_(integer *, integer *, doublecomplex *, integer *, doublecomplex *, doublecomplex *, integer *, integer * ), zlacpy_(char *, integer *, integer *, doublecomplex *, integer *, doublecomplex *, integer *), zlaset_(char *, integer *, integer *, doublecomplex *, doublecomplex *, doublecomplex *, integer *); extern doublereal zlansy_(char *, char *, integer *, doublecomplex *, integer *, doublereal *); extern /* Subroutine */ int zungqr_(integer *, integer *, integer *, doublecomplex *, integer *, doublecomplex *, doublecomplex *, integer *, integer *); /* -- LAPACK test routine (version 3.1) -- */ /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */ /* November 2006 */ /* .. Scalar Arguments .. */ /* .. */ /* .. Array Arguments .. */ /* .. */ /* Purpose */ /* ======= */ /* ZQRT01 tests ZGEQRF, which computes the QR factorization of an m-by-n */ /* matrix A, and partially tests ZUNGQR which forms the m-by-m */ /* orthogonal matrix Q. */ /* ZQRT01 compares R with Q'*A, and checks that Q is orthogonal. */ /* Arguments */ /* ========= */ /* M (input) INTEGER */ /* The number of rows of the matrix A. M >= 0. */ /* N (input) INTEGER */ /* The number of columns of the matrix A. N >= 0. */ /* A (input) COMPLEX*16 array, dimension (LDA,N) */ /* The m-by-n matrix A. */ /* AF (output) COMPLEX*16 array, dimension (LDA,N) */ /* Details of the QR factorization of A, as returned by ZGEQRF. */ /* See ZGEQRF for further details. */ /* Q (output) COMPLEX*16 array, dimension (LDA,M) */ /* The m-by-m orthogonal matrix Q. */ /* R (workspace) COMPLEX*16 array, dimension (LDA,max(M,N)) */ /* LDA (input) INTEGER */ /* The leading dimension of the arrays A, AF, Q and R. */ /* LDA >= max(M,N). */ /* TAU (output) COMPLEX*16 array, dimension (min(M,N)) */ /* The scalar factors of the elementary reflectors, as returned */ /* by ZGEQRF. */ /* WORK (workspace) COMPLEX*16 array, dimension (LWORK) */ /* LWORK (input) INTEGER */ /* The dimension of the array WORK. */ /* RWORK (workspace) DOUBLE PRECISION array, dimension (M) */ /* RESULT (output) DOUBLE PRECISION array, dimension (2) */ /* The test ratios: */ /* RESULT(1) = norm( R - Q'*A ) / ( M * norm(A) * EPS ) */ /* RESULT(2) = norm( I - Q'*Q ) / ( M * EPS ) */ /* ===================================================================== */ /* .. Parameters .. */ /* .. */ /* .. Local Scalars .. */ /* .. */ /* .. External Functions .. */ /* .. */ /* .. External Subroutines .. */ /* .. */ /* .. Intrinsic Functions .. */ /* .. */ /* .. Scalars in Common .. */ /* .. */ /* .. Common blocks .. */ /* .. */ /* .. Executable Statements .. */ /* Parameter adjustments */ r_dim1 = *lda; r_offset = 1 + r_dim1; r__ -= r_offset; q_dim1 = *lda; q_offset = 1 + q_dim1; q -= q_offset; af_dim1 = *lda; af_offset = 1 + af_dim1; af -= af_offset; a_dim1 = *lda; a_offset = 1 + a_dim1; a -= a_offset; --tau; --work; --rwork; --result; /* Function Body */ minmn = min(*m,*n); eps = dlamch_("Epsilon"); /* Copy the matrix A to the array AF. */ zlacpy_("Full", m, n, &a[a_offset], lda, &af[af_offset], lda); /* Factorize the matrix A in the array AF. */ s_copy(srnamc_1.srnamt, "ZGEQRF", (ftnlen)6, (ftnlen)6); zgeqrf_(m, n, &af[af_offset], lda, &tau[1], &work[1], lwork, &info); /* Copy details of Q */ zlaset_("Full", m, m, &c_b1, &c_b1, &q[q_offset], lda); i__1 = *m - 1; zlacpy_("Lower", &i__1, n, &af[af_dim1 + 2], lda, &q[q_dim1 + 2], lda); /* Generate the m-by-m matrix Q */ s_copy(srnamc_1.srnamt, "ZUNGQR", (ftnlen)6, (ftnlen)6); zungqr_(m, m, &minmn, &q[q_offset], lda, &tau[1], &work[1], lwork, &info); /* Copy R */ zlaset_("Full", m, n, &c_b10, &c_b10, &r__[r_offset], lda); zlacpy_("Upper", m, n, &af[af_offset], lda, &r__[r_offset], lda); /* Compute R - Q'*A */ zgemm_("Conjugate transpose", "No transpose", m, n, m, &c_b15, &q[ q_offset], lda, &a[a_offset], lda, &c_b16, &r__[r_offset], lda); /* Compute norm( R - Q'*A ) / ( M * norm(A) * EPS ) . */ anorm = zlange_("1", m, n, &a[a_offset], lda, &rwork[1]); resid = zlange_("1", m, n, &r__[r_offset], lda, &rwork[1]); if (anorm > 0.) { result[1] = resid / (doublereal) max(1,*m) / anorm / eps; } else { result[1] = 0.; } /* Compute I - Q'*Q */ zlaset_("Full", m, m, &c_b10, &c_b16, &r__[r_offset], lda); zherk_("Upper", "Conjugate transpose", m, m, &c_b24, &q[q_offset], lda, & c_b25, &r__[r_offset], lda); /* Compute norm( I - Q'*Q ) / ( M * EPS ) . */ resid = zlansy_("1", "Upper", m, &r__[r_offset], lda, &rwork[1]); result[2] = resid / (doublereal) max(1,*m) / eps; return 0; /* End of ZQRT01 */ } /* zqrt01_ */
/* Subroutine */ int zgegs_(char *jobvsl, char *jobvsr, integer *n, doublecomplex *a, integer *lda, doublecomplex *b, integer *ldb, doublecomplex *alpha, doublecomplex *beta, doublecomplex *vsl, integer *ldvsl, doublecomplex *vsr, integer *ldvsr, doublecomplex * work, integer *lwork, doublereal *rwork, integer *info) { /* -- LAPACK driver routine (version 2.0) -- Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd., Courant Institute, Argonne National Lab, and Rice University September 30, 1994 Purpose ======= DGEGS computes for a pair of N-by-N complex nonsymmetric matrices A, B: the generalized eigenvalues (alpha, beta), the complex Schur form (A, B), and optionally left and/or right Schur vectors (VSL and VSR). (If only the generalized eigenvalues are needed, use the driver ZGEGV instead.) A generalized eigenvalue for a pair of matrices (A,B) is, roughly speaking, a scalar w or a ratio alpha/beta = w, such that A - w*B is singular. It is usually represented as the pair (alpha,beta), as there is a reasonable interpretation for beta=0, and even for both being zero. A good beginning reference is the book, "VISMatrix Computations", by G. Golub & C. van Loan (Johns Hopkins U. Press) The (generalized) Schur form of a pair of matrices is the result of multiplying both matrices on the left by one unitary matrix and both on the right by another unitary matrix, these two unitary matrices being chosen so as to bring the pair of matrices into upper triangular form with the diagonal elements of B being non-negative real numbers (this is also called complex Schur form.) The left and right Schur vectors are the columns of VSL and VSR, respectively, where VSL and VSR are the unitary matrices which reduce A and B to Schur form: Schur form of (A,B) = ( (VSL)**H A (VSR), (VSL)**H B (VSR) ) Arguments ========= JOBVSL (input) CHARACTER*1 = 'N': do not compute the left Schur vectors; = 'V': compute the left Schur vectors. JOBVSR (input) CHARACTER*1 = 'N': do not compute the right Schur vectors; = 'V': compute the right Schur vectors. N (input) INTEGER The order of the matrices A, B, VSL, and VSR. N >= 0. A (input/output) COMPLEX*16 array, dimension (LDA, N) On entry, the first of the pair of matrices whose generalized eigenvalues and (optionally) Schur vectors are to be computed. On exit, the generalized Schur form of A. LDA (input) INTEGER The leading dimension of A. LDA >= max(1,N). B (input/output) COMPLEX*16 array, dimension (LDB, N) On entry, the second of the pair of matrices whose generalized eigenvalues and (optionally) Schur vectors are to be computed. On exit, the generalized Schur form of B. LDB (input) INTEGER The leading dimension of B. LDB >= max(1,N). ALPHA (output) COMPLEX*16 array, dimension (N) BETA (output) COMPLEX*16 array, dimension (N) On exit, ALPHA(j)/BETA(j), j=1,...,N, will be the generalized eigenvalues. ALPHA(j), j=1,...,N and BETA(j), j=1,...,N are the diagonals of the complex Schur form (A,B) output by ZGEGS. The BETA(j) will be non-negative real. Note: the quotients ALPHA(j)/BETA(j) may easily over- or underflow, and BETA(j) may even be zero. Thus, the user should avoid naively computing the ratio alpha/beta. However, ALPHA will be always less than and usually comparable with norm(A) in magnitude, and BETA always less than and usually comparable with norm(B). VSL (output) COMPLEX*16 array, dimension (LDVSL,N) If JOBVSL = 'V', VSL will contain the left Schur vectors. (See "Purpose", above.) Not referenced if JOBVSL = 'N'. LDVSL (input) INTEGER The leading dimension of the matrix VSL. LDVSL >= 1, and if JOBVSL = 'V', LDVSL >= N. VSR (output) COMPLEX*16 array, dimension (LDVSR,N) If JOBVSR = 'V', VSR will contain the right Schur vectors. (See "Purpose", above.) Not referenced if JOBVSR = 'N'. LDVSR (input) INTEGER The leading dimension of the matrix VSR. LDVSR >= 1, and if JOBVSR = 'V', LDVSR >= N. WORK (workspace/output) COMPLEX*16 array, dimension (LWORK) On exit, if INFO = 0, WORK(1) returns the optimal LWORK. LWORK (input) INTEGER The dimension of the array WORK. LWORK >= max(1,2*N). For good performance, LWORK must generally be larger. To compute the optimal value of LWORK, call ILAENV to get blocksizes (for ZGEQRF, ZUNMQR, and CUNGQR.) Then compute: NB -- MAX of the blocksizes for ZGEQRF, ZUNMQR, and CUNGQR; the optimal LWORK is N*(NB+1). RWORK (workspace) DOUBLE PRECISION array, dimension (3*N) INFO (output) INTEGER = 0: successful exit < 0: if INFO = -i, the i-th argument had an illegal value. =1,...,N: The QZ iteration failed. (A,B) are not in Schur form, but ALPHA(j) and BETA(j) should be correct for j=INFO+1,...,N. > N: errors that usually indicate LAPACK problems: =N+1: error return from ZGGBAL =N+2: error return from ZGEQRF =N+3: error return from ZUNMQR =N+4: error return from ZUNGQR =N+5: error return from ZGGHRD =N+6: error return from ZHGEQZ (other than failed iteration) =N+7: error return from ZGGBAK (computing VSL) =N+8: error return from ZGGBAK (computing VSR) =N+9: error return from ZLASCL (various places) ===================================================================== Decode the input arguments Parameter adjustments Function Body */ /* Table of constant values */ static doublecomplex c_b1 = {0.,0.}; static doublecomplex c_b2 = {1.,0.}; static integer c_n1 = -1; static integer c__1 = 1; /* System generated locals */ integer a_dim1, a_offset, b_dim1, b_offset, vsl_dim1, vsl_offset, vsr_dim1, vsr_offset, i__1, i__2, i__3; /* Local variables */ static doublereal anrm, bnrm; static integer itau; extern logical lsame_(char *, char *); static integer ileft, iinfo, icols; static logical ilvsl; static integer iwork; static logical ilvsr; static integer irows; extern doublereal dlamch_(char *); extern /* Subroutine */ int zggbak_(char *, char *, integer *, integer *, integer *, doublereal *, doublereal *, integer *, doublecomplex *, integer *, integer *), zggbal_(char *, integer *, doublecomplex *, integer *, doublecomplex *, integer *, integer * , integer *, doublereal *, doublereal *, doublereal *, integer *); static logical ilascl, ilbscl; static doublereal safmin; extern /* Subroutine */ int xerbla_(char *, integer *); extern doublereal zlange_(char *, integer *, integer *, doublecomplex *, integer *, doublereal *); static doublereal bignum; static integer ijobvl, iright; extern /* Subroutine */ int zgghrd_(char *, char *, integer *, integer *, integer *, doublecomplex *, integer *, doublecomplex *, integer *, doublecomplex *, integer *, doublecomplex *, integer *, integer * ), zlascl_(char *, integer *, integer *, doublereal *, doublereal *, integer *, integer *, doublecomplex *, integer *, integer *); static integer ijobvr; extern /* Subroutine */ int zgeqrf_(integer *, integer *, doublecomplex *, integer *, doublecomplex *, doublecomplex *, integer *, integer * ); static doublereal anrmto; static integer lwkmin; static doublereal bnrmto; extern /* Subroutine */ int zlacpy_(char *, integer *, integer *, doublecomplex *, integer *, doublecomplex *, integer *), zlaset_(char *, integer *, integer *, doublecomplex *, doublecomplex *, doublecomplex *, integer *), zhgeqz_( char *, char *, char *, integer *, integer *, integer *, doublecomplex *, integer *, doublecomplex *, integer *, doublecomplex *, doublecomplex *, doublecomplex *, integer *, doublecomplex *, integer *, doublecomplex *, integer *, doublereal *, integer *); static doublereal smlnum; static integer irwork, lwkopt; extern /* Subroutine */ int zungqr_(integer *, integer *, integer *, doublecomplex *, integer *, doublecomplex *, doublecomplex *, integer *, integer *), zunmqr_(char *, char *, integer *, integer *, integer *, doublecomplex *, integer *, doublecomplex *, doublecomplex *, integer *, doublecomplex *, integer *, integer *); static integer ihi, ilo; static doublereal eps; #define ALPHA(I) alpha[(I)-1] #define BETA(I) beta[(I)-1] #define WORK(I) work[(I)-1] #define RWORK(I) rwork[(I)-1] #define A(I,J) a[(I)-1 + ((J)-1)* ( *lda)] #define B(I,J) b[(I)-1 + ((J)-1)* ( *ldb)] #define VSL(I,J) vsl[(I)-1 + ((J)-1)* ( *ldvsl)] #define VSR(I,J) vsr[(I)-1 + ((J)-1)* ( *ldvsr)] if (lsame_(jobvsl, "N")) { ijobvl = 1; ilvsl = FALSE_; } else if (lsame_(jobvsl, "V")) { ijobvl = 2; ilvsl = TRUE_; } else { ijobvl = -1; ilvsl = FALSE_; } if (lsame_(jobvsr, "N")) { ijobvr = 1; ilvsr = FALSE_; } else if (lsame_(jobvsr, "V")) { ijobvr = 2; ilvsr = TRUE_; } else { ijobvr = -1; ilvsr = FALSE_; } /* Test the input arguments Computing MAX */ i__1 = *n << 1; lwkmin = max(i__1,1); lwkopt = lwkmin; *info = 0; if (ijobvl <= 0) { *info = -1; } else if (ijobvr <= 0) { *info = -2; } else if (*n < 0) { *info = -3; } else if (*lda < max(1,*n)) { *info = -5; } else if (*ldb < max(1,*n)) { *info = -7; } else if (*ldvsl < 1 || ilvsl && *ldvsl < *n) { *info = -11; } else if (*ldvsr < 1 || ilvsr && *ldvsr < *n) { *info = -13; } else if (*lwork < lwkmin) { *info = -15; } if (*info != 0) { i__1 = -(*info); xerbla_("ZGEGS ", &i__1); return 0; } /* Quick return if possible */ WORK(1).r = (doublereal) lwkopt, WORK(1).i = 0.; if (*n == 0) { return 0; } /* Get machine constants */ eps = dlamch_("E") * dlamch_("B"); safmin = dlamch_("S"); smlnum = *n * safmin / eps; bignum = 1. / smlnum; /* Scale A if max element outside range [SMLNUM,BIGNUM] */ anrm = zlange_("M", n, n, &A(1,1), lda, &RWORK(1)); ilascl = FALSE_; if (anrm > 0. && anrm < smlnum) { anrmto = smlnum; ilascl = TRUE_; } else if (anrm > bignum) { anrmto = bignum; ilascl = TRUE_; } if (ilascl) { zlascl_("G", &c_n1, &c_n1, &anrm, &anrmto, n, n, &A(1,1), lda, & iinfo); if (iinfo != 0) { *info = *n + 9; return 0; } } /* Scale B if max element outside range [SMLNUM,BIGNUM] */ bnrm = zlange_("M", n, n, &B(1,1), ldb, &RWORK(1)); ilbscl = FALSE_; if (bnrm > 0. && bnrm < smlnum) { bnrmto = smlnum; ilbscl = TRUE_; } else if (bnrm > bignum) { bnrmto = bignum; ilbscl = TRUE_; } if (ilbscl) { zlascl_("G", &c_n1, &c_n1, &bnrm, &bnrmto, n, n, &B(1,1), ldb, & iinfo); if (iinfo != 0) { *info = *n + 9; return 0; } } /* Permute the matrix to make it more nearly triangular */ ileft = 1; iright = *n + 1; irwork = iright + *n; iwork = 1; zggbal_("P", n, &A(1,1), lda, &B(1,1), ldb, &ilo, &ihi, &RWORK( ileft), &RWORK(iright), &RWORK(irwork), &iinfo); if (iinfo != 0) { *info = *n + 1; goto L10; } /* Reduce B to triangular form, and initialize VSL and/or VSR */ irows = ihi + 1 - ilo; icols = *n + 1 - ilo; itau = iwork; iwork = itau + irows; i__1 = *lwork + 1 - iwork; zgeqrf_(&irows, &icols, &B(ilo,ilo), ldb, &WORK(itau), &WORK( iwork), &i__1, &iinfo); if (iinfo >= 0) { /* Computing MAX */ i__3 = iwork; i__1 = lwkopt, i__2 = (integer) WORK(iwork).r + iwork - 1; lwkopt = max(i__1,i__2); } if (iinfo != 0) { *info = *n + 2; goto L10; } i__1 = *lwork + 1 - iwork; zunmqr_("L", "C", &irows, &icols, &irows, &B(ilo,ilo), ldb, & WORK(itau), &A(ilo,ilo), lda, &WORK(iwork), &i__1, & iinfo); if (iinfo >= 0) { /* Computing MAX */ i__3 = iwork; i__1 = lwkopt, i__2 = (integer) WORK(iwork).r + iwork - 1; lwkopt = max(i__1,i__2); } if (iinfo != 0) { *info = *n + 3; goto L10; } if (ilvsl) { zlaset_("Full", n, n, &c_b1, &c_b2, &VSL(1,1), ldvsl); i__1 = irows - 1; i__2 = irows - 1; zlacpy_("L", &i__1, &i__2, &B(ilo+1,ilo), ldb, &VSL(ilo+1,ilo), ldvsl); i__1 = *lwork + 1 - iwork; zungqr_(&irows, &irows, &irows, &VSL(ilo,ilo), ldvsl, & WORK(itau), &WORK(iwork), &i__1, &iinfo); if (iinfo >= 0) { /* Computing MAX */ i__3 = iwork; i__1 = lwkopt, i__2 = (integer) WORK(iwork).r + iwork - 1; lwkopt = max(i__1,i__2); } if (iinfo != 0) { *info = *n + 4; goto L10; } } if (ilvsr) { zlaset_("Full", n, n, &c_b1, &c_b2, &VSR(1,1), ldvsr); } /* Reduce to generalized Hessenberg form */ zgghrd_(jobvsl, jobvsr, n, &ilo, &ihi, &A(1,1), lda, &B(1,1), ldb, &VSL(1,1), ldvsl, &VSR(1,1), ldvsr, &iinfo); if (iinfo != 0) { *info = *n + 5; goto L10; } /* Perform QZ algorithm, computing Schur vectors if desired */ iwork = itau; i__1 = *lwork + 1 - iwork; zhgeqz_("S", jobvsl, jobvsr, n, &ilo, &ihi, &A(1,1), lda, &B(1,1), ldb, &ALPHA(1), &BETA(1), &VSL(1,1), ldvsl, & VSR(1,1), ldvsr, &WORK(iwork), &i__1, &RWORK(irwork), & iinfo); if (iinfo >= 0) { /* Computing MAX */ i__3 = iwork; i__1 = lwkopt, i__2 = (integer) WORK(iwork).r + iwork - 1; lwkopt = max(i__1,i__2); } if (iinfo != 0) { if (iinfo > 0 && iinfo <= *n) { *info = iinfo; } else if (iinfo > *n && iinfo <= *n << 1) { *info = iinfo - *n; } else { *info = *n + 6; } goto L10; } /* Apply permutation to VSL and VSR */ if (ilvsl) { zggbak_("P", "L", n, &ilo, &ihi, &RWORK(ileft), &RWORK(iright), n, & VSL(1,1), ldvsl, &iinfo); if (iinfo != 0) { *info = *n + 7; goto L10; } } if (ilvsr) { zggbak_("P", "R", n, &ilo, &ihi, &RWORK(ileft), &RWORK(iright), n, & VSR(1,1), ldvsr, &iinfo); if (iinfo != 0) { *info = *n + 8; goto L10; } } /* Undo scaling */ if (ilascl) { zlascl_("U", &c_n1, &c_n1, &anrmto, &anrm, n, n, &A(1,1), lda, & iinfo); if (iinfo != 0) { *info = *n + 9; return 0; } zlascl_("G", &c_n1, &c_n1, &anrmto, &anrm, n, &c__1, &ALPHA(1), n, & iinfo); if (iinfo != 0) { *info = *n + 9; return 0; } } if (ilbscl) { zlascl_("U", &c_n1, &c_n1, &bnrmto, &bnrm, n, n, &B(1,1), ldb, & iinfo); if (iinfo != 0) { *info = *n + 9; return 0; } zlascl_("G", &c_n1, &c_n1, &bnrmto, &bnrm, n, &c__1, &BETA(1), n, & iinfo); if (iinfo != 0) { *info = *n + 9; return 0; } } L10: WORK(1).r = (doublereal) lwkopt, WORK(1).i = 0.; return 0; /* End of ZGEGS */ } /* zgegs_ */
/* Subroutine */ int zgqrts_(integer *n, integer *m, integer *p, doublecomplex *a, doublecomplex *af, doublecomplex *q, doublecomplex * r__, integer *lda, doublecomplex *taua, doublecomplex *b, doublecomplex *bf, doublecomplex *z__, doublecomplex *t, doublecomplex *bwk, integer *ldb, doublecomplex *taub, doublecomplex * work, integer *lwork, doublereal *rwork, doublereal *result) { /* System generated locals */ integer a_dim1, a_offset, af_dim1, af_offset, b_dim1, b_offset, bf_dim1, bf_offset, bwk_dim1, bwk_offset, q_dim1, q_offset, r_dim1, r_offset, t_dim1, t_offset, z_dim1, z_offset, i__1, i__2; doublereal d__1; doublecomplex z__1; /* Local variables */ doublereal ulp; integer info; doublereal unfl, resid, anorm, bnorm; extern /* Subroutine */ int zgemm_(char *, char *, integer *, integer *, integer *, doublecomplex *, doublecomplex *, integer *, doublecomplex *, integer *, doublecomplex *, doublecomplex *, integer *), zherk_(char *, char *, integer *, integer *, doublereal *, doublecomplex *, integer *, doublereal *, doublecomplex *, integer *); extern doublereal dlamch_(char *), zlange_(char *, integer *, integer *, doublecomplex *, integer *, doublereal *), zlanhe_(char *, char *, integer *, doublecomplex *, integer *, doublereal *); extern /* Subroutine */ int zggqrf_(integer *, integer *, integer *, doublecomplex *, integer *, doublecomplex *, doublecomplex *, integer *, doublecomplex *, doublecomplex *, integer *, integer *) , zlacpy_(char *, integer *, integer *, doublecomplex *, integer * , doublecomplex *, integer *), zlaset_(char *, integer *, integer *, doublecomplex *, doublecomplex *, doublecomplex *, integer *), zungqr_(integer *, integer *, integer *, doublecomplex *, integer *, doublecomplex *, doublecomplex *, integer *, integer *), zungrq_(integer *, integer *, integer *, doublecomplex *, integer *, doublecomplex *, doublecomplex *, integer *, integer *); /* -- LAPACK test routine (version 3.1) -- */ /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */ /* November 2006 */ /* .. Scalar Arguments .. */ /* .. */ /* .. Array Arguments .. */ /* .. */ /* Purpose */ /* ======= */ /* ZGQRTS tests ZGGQRF, which computes the GQR factorization of an */ /* N-by-M matrix A and a N-by-P matrix B: A = Q*R and B = Q*T*Z. */ /* Arguments */ /* ========= */ /* N (input) INTEGER */ /* The number of rows of the matrices A and B. N >= 0. */ /* M (input) INTEGER */ /* The number of columns of the matrix A. M >= 0. */ /* P (input) INTEGER */ /* The number of columns of the matrix B. P >= 0. */ /* A (input) COMPLEX*16 array, dimension (LDA,M) */ /* The N-by-M matrix A. */ /* AF (output) COMPLEX*16 array, dimension (LDA,N) */ /* Details of the GQR factorization of A and B, as returned */ /* by ZGGQRF, see CGGQRF for further details. */ /* Q (output) COMPLEX*16 array, dimension (LDA,N) */ /* The M-by-M unitary matrix Q. */ /* R (workspace) COMPLEX*16 array, dimension (LDA,MAX(M,N)) */ /* LDA (input) INTEGER */ /* The leading dimension of the arrays A, AF, R and Q. */ /* LDA >= max(M,N). */ /* TAUA (output) COMPLEX*16 array, dimension (min(M,N)) */ /* The scalar factors of the elementary reflectors, as returned */ /* by ZGGQRF. */ /* B (input) COMPLEX*16 array, dimension (LDB,P) */ /* On entry, the N-by-P matrix A. */ /* BF (output) COMPLEX*16 array, dimension (LDB,N) */ /* Details of the GQR factorization of A and B, as returned */ /* by ZGGQRF, see CGGQRF for further details. */ /* Z (output) COMPLEX*16 array, dimension (LDB,P) */ /* The P-by-P unitary matrix Z. */ /* T (workspace) COMPLEX*16 array, dimension (LDB,max(P,N)) */ /* BWK (workspace) COMPLEX*16 array, dimension (LDB,N) */ /* LDB (input) INTEGER */ /* The leading dimension of the arrays B, BF, Z and T. */ /* LDB >= max(P,N). */ /* TAUB (output) COMPLEX*16 array, dimension (min(P,N)) */ /* The scalar factors of the elementary reflectors, as returned */ /* by DGGRQF. */ /* WORK (workspace) COMPLEX*16 array, dimension (LWORK) */ /* LWORK (input) INTEGER */ /* The dimension of the array WORK, LWORK >= max(N,M,P)**2. */ /* RWORK (workspace) DOUBLE PRECISION array, dimension (max(N,M,P)) */ /* RESULT (output) DOUBLE PRECISION array, dimension (4) */ /* The test ratios: */ /* RESULT(1) = norm( R - Q'*A ) / ( MAX(M,N)*norm(A)*ULP) */ /* RESULT(2) = norm( T*Z - Q'*B ) / (MAX(P,N)*norm(B)*ULP) */ /* RESULT(3) = norm( I - Q'*Q ) / ( M*ULP ) */ /* RESULT(4) = norm( I - Z'*Z ) / ( P*ULP ) */ /* ===================================================================== */ /* .. Parameters .. */ /* .. */ /* .. Local Scalars .. */ /* .. */ /* .. External Functions .. */ /* .. */ /* .. External Subroutines .. */ /* .. */ /* .. Intrinsic Functions .. */ /* .. */ /* .. Executable Statements .. */ /* Parameter adjustments */ r_dim1 = *lda; r_offset = 1 + r_dim1; r__ -= r_offset; q_dim1 = *lda; q_offset = 1 + q_dim1; q -= q_offset; af_dim1 = *lda; af_offset = 1 + af_dim1; af -= af_offset; a_dim1 = *lda; a_offset = 1 + a_dim1; a -= a_offset; --taua; bwk_dim1 = *ldb; bwk_offset = 1 + bwk_dim1; bwk -= bwk_offset; t_dim1 = *ldb; t_offset = 1 + t_dim1; t -= t_offset; z_dim1 = *ldb; z_offset = 1 + z_dim1; z__ -= z_offset; bf_dim1 = *ldb; bf_offset = 1 + bf_dim1; bf -= bf_offset; b_dim1 = *ldb; b_offset = 1 + b_dim1; b -= b_offset; --taub; --work; --rwork; --result; /* Function Body */ ulp = dlamch_("Precision"); unfl = dlamch_("Safe minimum"); /* Copy the matrix A to the array AF. */ zlacpy_("Full", n, m, &a[a_offset], lda, &af[af_offset], lda); zlacpy_("Full", n, p, &b[b_offset], ldb, &bf[bf_offset], ldb); /* Computing MAX */ d__1 = zlange_("1", n, m, &a[a_offset], lda, &rwork[1]); anorm = max(d__1,unfl); /* Computing MAX */ d__1 = zlange_("1", n, p, &b[b_offset], ldb, &rwork[1]); bnorm = max(d__1,unfl); /* Factorize the matrices A and B in the arrays AF and BF. */ zggqrf_(n, m, p, &af[af_offset], lda, &taua[1], &bf[bf_offset], ldb, & taub[1], &work[1], lwork, &info); /* Generate the N-by-N matrix Q */ zlaset_("Full", n, n, &c_b3, &c_b3, &q[q_offset], lda); i__1 = *n - 1; zlacpy_("Lower", &i__1, m, &af[af_dim1 + 2], lda, &q[q_dim1 + 2], lda); i__1 = min(*n,*m); zungqr_(n, n, &i__1, &q[q_offset], lda, &taua[1], &work[1], lwork, &info); /* Generate the P-by-P matrix Z */ zlaset_("Full", p, p, &c_b3, &c_b3, &z__[z_offset], ldb); if (*n <= *p) { if (*n > 0 && *n < *p) { i__1 = *p - *n; zlacpy_("Full", n, &i__1, &bf[bf_offset], ldb, &z__[*p - *n + 1 + z_dim1], ldb); } if (*n > 1) { i__1 = *n - 1; i__2 = *n - 1; zlacpy_("Lower", &i__1, &i__2, &bf[(*p - *n + 1) * bf_dim1 + 2], ldb, &z__[*p - *n + 2 + (*p - *n + 1) * z_dim1], ldb); } } else { if (*p > 1) { i__1 = *p - 1; i__2 = *p - 1; zlacpy_("Lower", &i__1, &i__2, &bf[*n - *p + 2 + bf_dim1], ldb, & z__[z_dim1 + 2], ldb); } } i__1 = min(*n,*p); zungrq_(p, p, &i__1, &z__[z_offset], ldb, &taub[1], &work[1], lwork, & info); /* Copy R */ zlaset_("Full", n, m, &c_b1, &c_b1, &r__[r_offset], lda); zlacpy_("Upper", n, m, &af[af_offset], lda, &r__[r_offset], lda); /* Copy T */ zlaset_("Full", n, p, &c_b1, &c_b1, &t[t_offset], ldb); if (*n <= *p) { zlacpy_("Upper", n, n, &bf[(*p - *n + 1) * bf_dim1 + 1], ldb, &t[(*p - *n + 1) * t_dim1 + 1], ldb); } else { i__1 = *n - *p; zlacpy_("Full", &i__1, p, &bf[bf_offset], ldb, &t[t_offset], ldb); zlacpy_("Upper", p, p, &bf[*n - *p + 1 + bf_dim1], ldb, &t[*n - *p + 1 + t_dim1], ldb); } /* Compute R - Q'*A */ z__1.r = -1., z__1.i = -0.; zgemm_("Conjugate transpose", "No transpose", n, m, n, &z__1, &q[q_offset] , lda, &a[a_offset], lda, &c_b2, &r__[r_offset], lda); /* Compute norm( R - Q'*A ) / ( MAX(M,N)*norm(A)*ULP ) . */ resid = zlange_("1", n, m, &r__[r_offset], lda, &rwork[1]); if (anorm > 0.) { /* Computing MAX */ i__1 = max(1,*m); result[1] = resid / (doublereal) max(i__1,*n) / anorm / ulp; } else { result[1] = 0.; } /* Compute T*Z - Q'*B */ zgemm_("No Transpose", "No transpose", n, p, p, &c_b2, &t[t_offset], ldb, &z__[z_offset], ldb, &c_b1, &bwk[bwk_offset], ldb); z__1.r = -1., z__1.i = -0.; zgemm_("Conjugate transpose", "No transpose", n, p, n, &z__1, &q[q_offset] , lda, &b[b_offset], ldb, &c_b2, &bwk[bwk_offset], ldb); /* Compute norm( T*Z - Q'*B ) / ( MAX(P,N)*norm(A)*ULP ) . */ resid = zlange_("1", n, p, &bwk[bwk_offset], ldb, &rwork[1]); if (bnorm > 0.) { /* Computing MAX */ i__1 = max(1,*p); result[2] = resid / (doublereal) max(i__1,*n) / bnorm / ulp; } else { result[2] = 0.; } /* Compute I - Q'*Q */ zlaset_("Full", n, n, &c_b1, &c_b2, &r__[r_offset], lda); zherk_("Upper", "Conjugate transpose", n, n, &c_b34, &q[q_offset], lda, & c_b35, &r__[r_offset], lda); /* Compute norm( I - Q'*Q ) / ( N * ULP ) . */ resid = zlanhe_("1", "Upper", n, &r__[r_offset], lda, &rwork[1]); result[3] = resid / (doublereal) max(1,*n) / ulp; /* Compute I - Z'*Z */ zlaset_("Full", p, p, &c_b1, &c_b2, &t[t_offset], ldb); zherk_("Upper", "Conjugate transpose", p, p, &c_b34, &z__[z_offset], ldb, &c_b35, &t[t_offset], ldb); /* Compute norm( I - Z'*Z ) / ( P*ULP ) . */ resid = zlanhe_("1", "Upper", p, &t[t_offset], ldb, &rwork[1]); result[4] = resid / (doublereal) max(1,*p) / ulp; return 0; /* End of ZGQRTS */ } /* zgqrts_ */
/* Subroutine */ int zerrqr_(char *path, integer *nunit) { /* System generated locals */ integer i__1; doublereal d__1, d__2; doublecomplex z__1; /* Builtin functions */ integer s_wsle(cilist *), e_wsle(void); /* Subroutine */ int s_copy(char *, char *, ftnlen, ftnlen); /* Local variables */ static integer info; static doublecomplex a[4] /* was [2][2] */, b[2]; static integer i__, j; static doublecomplex w[2], x[2], af[4] /* was [2][2] */; extern /* Subroutine */ int zgeqr2_(integer *, integer *, doublecomplex *, integer *, doublecomplex *, doublecomplex *, integer *), zung2r_( integer *, integer *, integer *, doublecomplex *, integer *, doublecomplex *, doublecomplex *, integer *), zunm2r_(char *, char *, integer *, integer *, integer *, doublecomplex *, integer *, doublecomplex *, doublecomplex *, integer *, doublecomplex *, integer *), alaesm_(char *, logical *, integer *), chkxer_(char *, integer *, integer *, logical *, logical *), zgeqrf_(integer *, integer *, doublecomplex *, integer *, doublecomplex *, doublecomplex *, integer *, integer *) , zgeqrs_(integer *, integer *, integer *, doublecomplex *, integer *, doublecomplex *, doublecomplex *, integer *, doublecomplex *, integer *, integer *), zungqr_(integer *, integer *, integer *, doublecomplex *, integer *, doublecomplex *, doublecomplex *, integer *, integer *), zunmqr_(char *, char *, integer *, integer *, integer *, doublecomplex *, integer *, doublecomplex *, doublecomplex *, integer *, doublecomplex *, integer *, integer *); /* Fortran I/O blocks */ static cilist io___1 = { 0, 0, 0, 0, 0 }; #define a_subscr(a_1,a_2) (a_2)*2 + a_1 - 3 #define a_ref(a_1,a_2) a[a_subscr(a_1,a_2)] #define af_subscr(a_1,a_2) (a_2)*2 + a_1 - 3 #define af_ref(a_1,a_2) af[af_subscr(a_1,a_2)] /* -- LAPACK test routine (version 3.0) -- Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd., Courant Institute, Argonne National Lab, and Rice University February 29, 1992 Purpose ======= ZERRQR tests the error exits for the COMPLEX*16 routines that use the QR decomposition of a general matrix. Arguments ========= PATH (input) CHARACTER*3 The LAPACK path name for the routines to be tested. NUNIT (input) INTEGER The unit number for output. ===================================================================== */ infoc_1.nout = *nunit; io___1.ciunit = infoc_1.nout; s_wsle(&io___1); e_wsle(); /* Set the variables to innocuous values. */ for (j = 1; j <= 2; ++j) { for (i__ = 1; i__ <= 2; ++i__) { i__1 = a_subscr(i__, j); d__1 = 1. / (doublereal) (i__ + j); d__2 = -1. / (doublereal) (i__ + j); z__1.r = d__1, z__1.i = d__2; a[i__1].r = z__1.r, a[i__1].i = z__1.i; i__1 = af_subscr(i__, j); d__1 = 1. / (doublereal) (i__ + j); d__2 = -1. / (doublereal) (i__ + j); z__1.r = d__1, z__1.i = d__2; af[i__1].r = z__1.r, af[i__1].i = z__1.i; /* L10: */ } i__1 = j - 1; b[i__1].r = 0., b[i__1].i = 0.; i__1 = j - 1; w[i__1].r = 0., w[i__1].i = 0.; i__1 = j - 1; x[i__1].r = 0., x[i__1].i = 0.; /* L20: */ } infoc_1.ok = TRUE_; /* Error exits for QR factorization ZGEQRF */ s_copy(srnamc_1.srnamt, "ZGEQRF", (ftnlen)6, (ftnlen)6); infoc_1.infot = 1; zgeqrf_(&c_n1, &c__0, a, &c__1, b, w, &c__1, &info); chkxer_("ZGEQRF", &infoc_1.infot, &infoc_1.nout, &infoc_1.lerr, & infoc_1.ok); infoc_1.infot = 2; zgeqrf_(&c__0, &c_n1, a, &c__1, b, w, &c__1, &info); chkxer_("ZGEQRF", &infoc_1.infot, &infoc_1.nout, &infoc_1.lerr, & infoc_1.ok); infoc_1.infot = 4; zgeqrf_(&c__2, &c__1, a, &c__1, b, w, &c__1, &info); chkxer_("ZGEQRF", &infoc_1.infot, &infoc_1.nout, &infoc_1.lerr, & infoc_1.ok); infoc_1.infot = 7; zgeqrf_(&c__1, &c__2, a, &c__1, b, w, &c__1, &info); chkxer_("ZGEQRF", &infoc_1.infot, &infoc_1.nout, &infoc_1.lerr, & infoc_1.ok); /* ZGEQR2 */ s_copy(srnamc_1.srnamt, "ZGEQR2", (ftnlen)6, (ftnlen)6); infoc_1.infot = 1; zgeqr2_(&c_n1, &c__0, a, &c__1, b, w, &info); chkxer_("ZGEQR2", &infoc_1.infot, &infoc_1.nout, &infoc_1.lerr, & infoc_1.ok); infoc_1.infot = 2; zgeqr2_(&c__0, &c_n1, a, &c__1, b, w, &info); chkxer_("ZGEQR2", &infoc_1.infot, &infoc_1.nout, &infoc_1.lerr, & infoc_1.ok); infoc_1.infot = 4; zgeqr2_(&c__2, &c__1, a, &c__1, b, w, &info); chkxer_("ZGEQR2", &infoc_1.infot, &infoc_1.nout, &infoc_1.lerr, & infoc_1.ok); /* ZGEQRS */ s_copy(srnamc_1.srnamt, "ZGEQRS", (ftnlen)6, (ftnlen)6); infoc_1.infot = 1; zgeqrs_(&c_n1, &c__0, &c__0, a, &c__1, x, b, &c__1, w, &c__1, &info); chkxer_("ZGEQRS", &infoc_1.infot, &infoc_1.nout, &infoc_1.lerr, & infoc_1.ok); infoc_1.infot = 2; zgeqrs_(&c__0, &c_n1, &c__0, a, &c__1, x, b, &c__1, w, &c__1, &info); chkxer_("ZGEQRS", &infoc_1.infot, &infoc_1.nout, &infoc_1.lerr, & infoc_1.ok); infoc_1.infot = 2; zgeqrs_(&c__1, &c__2, &c__0, a, &c__2, x, b, &c__2, w, &c__1, &info); chkxer_("ZGEQRS", &infoc_1.infot, &infoc_1.nout, &infoc_1.lerr, & infoc_1.ok); infoc_1.infot = 3; zgeqrs_(&c__0, &c__0, &c_n1, a, &c__1, x, b, &c__1, w, &c__1, &info); chkxer_("ZGEQRS", &infoc_1.infot, &infoc_1.nout, &infoc_1.lerr, & infoc_1.ok); infoc_1.infot = 5; zgeqrs_(&c__2, &c__1, &c__0, a, &c__1, x, b, &c__2, w, &c__1, &info); chkxer_("ZGEQRS", &infoc_1.infot, &infoc_1.nout, &infoc_1.lerr, & infoc_1.ok); infoc_1.infot = 8; zgeqrs_(&c__2, &c__1, &c__0, a, &c__2, x, b, &c__1, w, &c__1, &info); chkxer_("ZGEQRS", &infoc_1.infot, &infoc_1.nout, &infoc_1.lerr, & infoc_1.ok); infoc_1.infot = 10; zgeqrs_(&c__1, &c__1, &c__2, a, &c__1, x, b, &c__1, w, &c__1, &info); chkxer_("ZGEQRS", &infoc_1.infot, &infoc_1.nout, &infoc_1.lerr, & infoc_1.ok); /* ZUNGQR */ s_copy(srnamc_1.srnamt, "ZUNGQR", (ftnlen)6, (ftnlen)6); infoc_1.infot = 1; zungqr_(&c_n1, &c__0, &c__0, a, &c__1, x, w, &c__1, &info); chkxer_("ZUNGQR", &infoc_1.infot, &infoc_1.nout, &infoc_1.lerr, & infoc_1.ok); infoc_1.infot = 2; zungqr_(&c__0, &c_n1, &c__0, a, &c__1, x, w, &c__1, &info); chkxer_("ZUNGQR", &infoc_1.infot, &infoc_1.nout, &infoc_1.lerr, & infoc_1.ok); infoc_1.infot = 2; zungqr_(&c__1, &c__2, &c__0, a, &c__1, x, w, &c__2, &info); chkxer_("ZUNGQR", &infoc_1.infot, &infoc_1.nout, &infoc_1.lerr, & infoc_1.ok); infoc_1.infot = 3; zungqr_(&c__0, &c__0, &c_n1, a, &c__1, x, w, &c__1, &info); chkxer_("ZUNGQR", &infoc_1.infot, &infoc_1.nout, &infoc_1.lerr, & infoc_1.ok); infoc_1.infot = 3; zungqr_(&c__1, &c__1, &c__2, a, &c__1, x, w, &c__1, &info); chkxer_("ZUNGQR", &infoc_1.infot, &infoc_1.nout, &infoc_1.lerr, & infoc_1.ok); infoc_1.infot = 5; zungqr_(&c__2, &c__2, &c__0, a, &c__1, x, w, &c__2, &info); chkxer_("ZUNGQR", &infoc_1.infot, &infoc_1.nout, &infoc_1.lerr, & infoc_1.ok); infoc_1.infot = 8; zungqr_(&c__2, &c__2, &c__0, a, &c__2, x, w, &c__1, &info); chkxer_("ZUNGQR", &infoc_1.infot, &infoc_1.nout, &infoc_1.lerr, & infoc_1.ok); /* ZUNG2R */ s_copy(srnamc_1.srnamt, "ZUNG2R", (ftnlen)6, (ftnlen)6); infoc_1.infot = 1; zung2r_(&c_n1, &c__0, &c__0, a, &c__1, x, w, &info); chkxer_("ZUNG2R", &infoc_1.infot, &infoc_1.nout, &infoc_1.lerr, & infoc_1.ok); infoc_1.infot = 2; zung2r_(&c__0, &c_n1, &c__0, a, &c__1, x, w, &info); chkxer_("ZUNG2R", &infoc_1.infot, &infoc_1.nout, &infoc_1.lerr, & infoc_1.ok); infoc_1.infot = 2; zung2r_(&c__1, &c__2, &c__0, a, &c__1, x, w, &info); chkxer_("ZUNG2R", &infoc_1.infot, &infoc_1.nout, &infoc_1.lerr, & infoc_1.ok); infoc_1.infot = 3; zung2r_(&c__0, &c__0, &c_n1, a, &c__1, x, w, &info); chkxer_("ZUNG2R", &infoc_1.infot, &infoc_1.nout, &infoc_1.lerr, & infoc_1.ok); infoc_1.infot = 3; zung2r_(&c__2, &c__1, &c__2, a, &c__2, x, w, &info); chkxer_("ZUNG2R", &infoc_1.infot, &infoc_1.nout, &infoc_1.lerr, & infoc_1.ok); infoc_1.infot = 5; zung2r_(&c__2, &c__1, &c__0, a, &c__1, x, w, &info); chkxer_("ZUNG2R", &infoc_1.infot, &infoc_1.nout, &infoc_1.lerr, & infoc_1.ok); /* ZUNMQR */ s_copy(srnamc_1.srnamt, "ZUNMQR", (ftnlen)6, (ftnlen)6); infoc_1.infot = 1; zunmqr_("/", "N", &c__0, &c__0, &c__0, a, &c__1, x, af, &c__1, w, &c__1, & info); chkxer_("ZUNMQR", &infoc_1.infot, &infoc_1.nout, &infoc_1.lerr, & infoc_1.ok); infoc_1.infot = 2; zunmqr_("L", "/", &c__0, &c__0, &c__0, a, &c__1, x, af, &c__1, w, &c__1, & info); chkxer_("ZUNMQR", &infoc_1.infot, &infoc_1.nout, &infoc_1.lerr, & infoc_1.ok); infoc_1.infot = 3; zunmqr_("L", "N", &c_n1, &c__0, &c__0, a, &c__1, x, af, &c__1, w, &c__1, & info); chkxer_("ZUNMQR", &infoc_1.infot, &infoc_1.nout, &infoc_1.lerr, & infoc_1.ok); infoc_1.infot = 4; zunmqr_("L", "N", &c__0, &c_n1, &c__0, a, &c__1, x, af, &c__1, w, &c__1, & info); chkxer_("ZUNMQR", &infoc_1.infot, &infoc_1.nout, &infoc_1.lerr, & infoc_1.ok); infoc_1.infot = 5; zunmqr_("L", "N", &c__0, &c__0, &c_n1, a, &c__1, x, af, &c__1, w, &c__1, & info); chkxer_("ZUNMQR", &infoc_1.infot, &infoc_1.nout, &infoc_1.lerr, & infoc_1.ok); infoc_1.infot = 5; zunmqr_("L", "N", &c__0, &c__1, &c__1, a, &c__1, x, af, &c__1, w, &c__1, & info); chkxer_("ZUNMQR", &infoc_1.infot, &infoc_1.nout, &infoc_1.lerr, & infoc_1.ok); infoc_1.infot = 5; zunmqr_("R", "N", &c__1, &c__0, &c__1, a, &c__1, x, af, &c__1, w, &c__1, & info); chkxer_("ZUNMQR", &infoc_1.infot, &infoc_1.nout, &infoc_1.lerr, & infoc_1.ok); infoc_1.infot = 7; zunmqr_("L", "N", &c__2, &c__1, &c__0, a, &c__1, x, af, &c__2, w, &c__1, & info); chkxer_("ZUNMQR", &infoc_1.infot, &infoc_1.nout, &infoc_1.lerr, & infoc_1.ok); infoc_1.infot = 7; zunmqr_("R", "N", &c__1, &c__2, &c__0, a, &c__1, x, af, &c__1, w, &c__1, & info); chkxer_("ZUNMQR", &infoc_1.infot, &infoc_1.nout, &infoc_1.lerr, & infoc_1.ok); infoc_1.infot = 10; zunmqr_("L", "N", &c__2, &c__1, &c__0, a, &c__2, x, af, &c__1, w, &c__1, & info); chkxer_("ZUNMQR", &infoc_1.infot, &infoc_1.nout, &infoc_1.lerr, & infoc_1.ok); infoc_1.infot = 12; zunmqr_("L", "N", &c__1, &c__2, &c__0, a, &c__1, x, af, &c__1, w, &c__1, & info); chkxer_("ZUNMQR", &infoc_1.infot, &infoc_1.nout, &infoc_1.lerr, & infoc_1.ok); infoc_1.infot = 12; zunmqr_("R", "N", &c__2, &c__1, &c__0, a, &c__1, x, af, &c__2, w, &c__1, & info); chkxer_("ZUNMQR", &infoc_1.infot, &infoc_1.nout, &infoc_1.lerr, & infoc_1.ok); /* ZUNM2R */ s_copy(srnamc_1.srnamt, "ZUNM2R", (ftnlen)6, (ftnlen)6); infoc_1.infot = 1; zunm2r_("/", "N", &c__0, &c__0, &c__0, a, &c__1, x, af, &c__1, w, &info); chkxer_("ZUNM2R", &infoc_1.infot, &infoc_1.nout, &infoc_1.lerr, & infoc_1.ok); infoc_1.infot = 2; zunm2r_("L", "/", &c__0, &c__0, &c__0, a, &c__1, x, af, &c__1, w, &info); chkxer_("ZUNM2R", &infoc_1.infot, &infoc_1.nout, &infoc_1.lerr, & infoc_1.ok); infoc_1.infot = 3; zunm2r_("L", "N", &c_n1, &c__0, &c__0, a, &c__1, x, af, &c__1, w, &info); chkxer_("ZUNM2R", &infoc_1.infot, &infoc_1.nout, &infoc_1.lerr, & infoc_1.ok); infoc_1.infot = 4; zunm2r_("L", "N", &c__0, &c_n1, &c__0, a, &c__1, x, af, &c__1, w, &info); chkxer_("ZUNM2R", &infoc_1.infot, &infoc_1.nout, &infoc_1.lerr, & infoc_1.ok); infoc_1.infot = 5; zunm2r_("L", "N", &c__0, &c__0, &c_n1, a, &c__1, x, af, &c__1, w, &info); chkxer_("ZUNM2R", &infoc_1.infot, &infoc_1.nout, &infoc_1.lerr, & infoc_1.ok); infoc_1.infot = 5; zunm2r_("L", "N", &c__0, &c__1, &c__1, a, &c__1, x, af, &c__1, w, &info); chkxer_("ZUNM2R", &infoc_1.infot, &infoc_1.nout, &infoc_1.lerr, & infoc_1.ok); infoc_1.infot = 5; zunm2r_("R", "N", &c__1, &c__0, &c__1, a, &c__1, x, af, &c__1, w, &info); chkxer_("ZUNM2R", &infoc_1.infot, &infoc_1.nout, &infoc_1.lerr, & infoc_1.ok); infoc_1.infot = 7; zunm2r_("L", "N", &c__2, &c__1, &c__0, a, &c__1, x, af, &c__2, w, &info); chkxer_("ZUNM2R", &infoc_1.infot, &infoc_1.nout, &infoc_1.lerr, & infoc_1.ok); infoc_1.infot = 7; zunm2r_("R", "N", &c__1, &c__2, &c__0, a, &c__1, x, af, &c__1, w, &info); chkxer_("ZUNM2R", &infoc_1.infot, &infoc_1.nout, &infoc_1.lerr, & infoc_1.ok); infoc_1.infot = 10; zunm2r_("L", "N", &c__2, &c__1, &c__0, a, &c__2, x, af, &c__1, w, &info); chkxer_("ZUNM2R", &infoc_1.infot, &infoc_1.nout, &infoc_1.lerr, & infoc_1.ok); /* Print a summary line. */ alaesm_(path, &infoc_1.ok, &infoc_1.nout); return 0; /* End of ZERRQR */ } /* zerrqr_ */
/* Subroutine */ int zgegv_(char *jobvl, char *jobvr, integer *n, doublecomplex *a, integer *lda, doublecomplex *b, integer *ldb, doublecomplex *alpha, doublecomplex *beta, doublecomplex *vl, integer *ldvl, doublecomplex *vr, integer *ldvr, doublecomplex *work, integer *lwork, doublereal *rwork, integer *info) { /* System generated locals */ integer a_dim1, a_offset, b_dim1, b_offset, vl_dim1, vl_offset, vr_dim1, vr_offset, i__1, i__2, i__3, i__4; doublereal d__1, d__2, d__3, d__4; doublecomplex z__1, z__2; /* Builtin functions */ double d_imag(doublecomplex *); /* Local variables */ integer jc, nb, in, jr, nb1, nb2, nb3, ihi, ilo; doublereal eps; logical ilv; doublereal absb, anrm, bnrm; integer itau; doublereal temp; logical ilvl, ilvr; integer lopt; doublereal anrm1, anrm2, bnrm1, bnrm2, absai, scale, absar, sbeta; extern logical lsame_(char *, char *); integer ileft, iinfo, icols, iwork, irows; extern doublereal dlamch_(char *); doublereal salfai; extern /* Subroutine */ int zggbak_(char *, char *, integer *, integer *, integer *, doublereal *, doublereal *, integer *, doublecomplex *, integer *, integer *), zggbal_(char *, integer *, doublecomplex *, integer *, doublecomplex *, integer *, integer * , integer *, doublereal *, doublereal *, doublereal *, integer *); doublereal salfar, safmin; extern /* Subroutine */ int xerbla_(char *, integer *); doublereal safmax; char chtemp[1]; logical ldumma[1]; extern integer ilaenv_(integer *, char *, char *, integer *, integer *, integer *, integer *); extern doublereal zlange_(char *, integer *, integer *, doublecomplex *, integer *, doublereal *); integer ijobvl, iright; logical ilimit; extern /* Subroutine */ int zgghrd_(char *, char *, integer *, integer *, integer *, doublecomplex *, integer *, doublecomplex *, integer *, doublecomplex *, integer *, doublecomplex *, integer *, integer * ), zlascl_(char *, integer *, integer *, doublereal *, doublereal *, integer *, integer *, doublecomplex *, integer *, integer *); integer ijobvr; extern /* Subroutine */ int zgeqrf_(integer *, integer *, doublecomplex *, integer *, doublecomplex *, doublecomplex *, integer *, integer * ); integer lwkmin; extern /* Subroutine */ int zlacpy_(char *, integer *, integer *, doublecomplex *, integer *, doublecomplex *, integer *), zlaset_(char *, integer *, integer *, doublecomplex *, doublecomplex *, doublecomplex *, integer *), ztgevc_( char *, char *, logical *, integer *, doublecomplex *, integer *, doublecomplex *, integer *, doublecomplex *, integer *, doublecomplex *, integer *, integer *, integer *, doublecomplex *, doublereal *, integer *), zhgeqz_(char *, char *, char *, integer *, integer *, integer *, doublecomplex *, integer *, doublecomplex *, integer *, doublecomplex *, doublecomplex *, doublecomplex *, integer *, doublecomplex *, integer *, doublecomplex *, integer *, doublereal *, integer *); integer irwork, lwkopt; logical lquery; extern /* Subroutine */ int zungqr_(integer *, integer *, integer *, doublecomplex *, integer *, doublecomplex *, doublecomplex *, integer *, integer *), zunmqr_(char *, char *, integer *, integer *, integer *, doublecomplex *, integer *, doublecomplex *, doublecomplex *, integer *, doublecomplex *, integer *, integer *); /* -- LAPACK driver routine (version 3.2) -- */ /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */ /* November 2006 */ /* .. Scalar Arguments .. */ /* .. */ /* .. Array Arguments .. */ /* .. */ /* Purpose */ /* ======= */ /* This routine is deprecated and has been replaced by routine ZGGEV. */ /* ZGEGV computes the eigenvalues and, optionally, the left and/or right */ /* eigenvectors of a complex matrix pair (A,B). */ /* Given two square matrices A and B, */ /* the generalized nonsymmetric eigenvalue problem (GNEP) is to find the */ /* eigenvalues lambda and corresponding (non-zero) eigenvectors x such */ /* that */ /* A*x = lambda*B*x. */ /* An alternate form is to find the eigenvalues mu and corresponding */ /* eigenvectors y such that */ /* mu*A*y = B*y. */ /* These two forms are equivalent with mu = 1/lambda and x = y if */ /* neither lambda nor mu is zero. In order to deal with the case that */ /* lambda or mu is zero or small, two values alpha and beta are returned */ /* for each eigenvalue, such that lambda = alpha/beta and */ /* mu = beta/alpha. */ /* The vectors x and y in the above equations are right eigenvectors of */ /* the matrix pair (A,B). Vectors u and v satisfying */ /* u**H*A = lambda*u**H*B or mu*v**H*A = v**H*B */ /* are left eigenvectors of (A,B). */ /* Note: this routine performs "full balancing" on A and B -- see */ /* "Further Details", below. */ /* Arguments */ /* ========= */ /* JOBVL (input) CHARACTER*1 */ /* = 'N': do not compute the left generalized eigenvectors; */ /* = 'V': compute the left generalized eigenvectors (returned */ /* in VL). */ /* JOBVR (input) CHARACTER*1 */ /* = 'N': do not compute the right generalized eigenvectors; */ /* = 'V': compute the right generalized eigenvectors (returned */ /* in VR). */ /* N (input) INTEGER */ /* The order of the matrices A, B, VL, and VR. N >= 0. */ /* A (input/output) COMPLEX*16 array, dimension (LDA, N) */ /* On entry, the matrix A. */ /* If JOBVL = 'V' or JOBVR = 'V', then on exit A */ /* contains the Schur form of A from the generalized Schur */ /* factorization of the pair (A,B) after balancing. If no */ /* eigenvectors were computed, then only the diagonal elements */ /* of the Schur form will be correct. See ZGGHRD and ZHGEQZ */ /* for details. */ /* LDA (input) INTEGER */ /* The leading dimension of A. LDA >= max(1,N). */ /* B (input/output) COMPLEX*16 array, dimension (LDB, N) */ /* On entry, the matrix B. */ /* If JOBVL = 'V' or JOBVR = 'V', then on exit B contains the */ /* upper triangular matrix obtained from B in the generalized */ /* Schur factorization of the pair (A,B) after balancing. */ /* If no eigenvectors were computed, then only the diagonal */ /* elements of B will be correct. See ZGGHRD and ZHGEQZ for */ /* details. */ /* LDB (input) INTEGER */ /* The leading dimension of B. LDB >= max(1,N). */ /* ALPHA (output) COMPLEX*16 array, dimension (N) */ /* The complex scalars alpha that define the eigenvalues of */ /* GNEP. */ /* BETA (output) COMPLEX*16 array, dimension (N) */ /* The complex scalars beta that define the eigenvalues of GNEP. */ /* Together, the quantities alpha = ALPHA(j) and beta = BETA(j) */ /* represent the j-th eigenvalue of the matrix pair (A,B), in */ /* one of the forms lambda = alpha/beta or mu = beta/alpha. */ /* Since either lambda or mu may overflow, they should not, */ /* in general, be computed. */ /* VL (output) COMPLEX*16 array, dimension (LDVL,N) */ /* If JOBVL = 'V', the left eigenvectors u(j) are stored */ /* in the columns of VL, in the same order as their eigenvalues. */ /* Each eigenvector is scaled so that its largest component has */ /* abs(real part) + abs(imag. part) = 1, except for eigenvectors */ /* corresponding to an eigenvalue with alpha = beta = 0, which */ /* are set to zero. */ /* Not referenced if JOBVL = 'N'. */ /* LDVL (input) INTEGER */ /* The leading dimension of the matrix VL. LDVL >= 1, and */ /* if JOBVL = 'V', LDVL >= N. */ /* VR (output) COMPLEX*16 array, dimension (LDVR,N) */ /* If JOBVR = 'V', the right eigenvectors x(j) are stored */ /* in the columns of VR, in the same order as their eigenvalues. */ /* Each eigenvector is scaled so that its largest component has */ /* abs(real part) + abs(imag. part) = 1, except for eigenvectors */ /* corresponding to an eigenvalue with alpha = beta = 0, which */ /* are set to zero. */ /* Not referenced if JOBVR = 'N'. */ /* LDVR (input) INTEGER */ /* The leading dimension of the matrix VR. LDVR >= 1, and */ /* if JOBVR = 'V', LDVR >= N. */ /* WORK (workspace/output) COMPLEX*16 array, dimension (MAX(1,LWORK)) */ /* On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */ /* LWORK (input) INTEGER */ /* The dimension of the array WORK. LWORK >= max(1,2*N). */ /* For good performance, LWORK must generally be larger. */ /* To compute the optimal value of LWORK, call ILAENV to get */ /* blocksizes (for ZGEQRF, ZUNMQR, and ZUNGQR.) Then compute: */ /* NB -- MAX of the blocksizes for ZGEQRF, ZUNMQR, and ZUNGQR; */ /* The optimal LWORK is MAX( 2*N, N*(NB+1) ). */ /* If LWORK = -1, then a workspace query is assumed; the routine */ /* only calculates the optimal size of the WORK array, returns */ /* this value as the first entry of the WORK array, and no error */ /* message related to LWORK is issued by XERBLA. */ /* RWORK (workspace/output) DOUBLE PRECISION array, dimension (8*N) */ /* INFO (output) INTEGER */ /* = 0: successful exit */ /* < 0: if INFO = -i, the i-th argument had an illegal value. */ /* =1,...,N: */ /* The QZ iteration failed. No eigenvectors have been */ /* calculated, but ALPHA(j) and BETA(j) should be */ /* correct for j=INFO+1,...,N. */ /* > N: errors that usually indicate LAPACK problems: */ /* =N+1: error return from ZGGBAL */ /* =N+2: error return from ZGEQRF */ /* =N+3: error return from ZUNMQR */ /* =N+4: error return from ZUNGQR */ /* =N+5: error return from ZGGHRD */ /* =N+6: error return from ZHGEQZ (other than failed */ /* iteration) */ /* =N+7: error return from ZTGEVC */ /* =N+8: error return from ZGGBAK (computing VL) */ /* =N+9: error return from ZGGBAK (computing VR) */ /* =N+10: error return from ZLASCL (various calls) */ /* Further Details */ /* =============== */ /* Balancing */ /* --------- */ /* This driver calls ZGGBAL to both permute and scale rows and columns */ /* of A and B. The permutations PL and PR are chosen so that PL*A*PR */ /* and PL*B*R will be upper triangular except for the diagonal blocks */ /* A(i:j,i:j) and B(i:j,i:j), with i and j as close together as */ /* possible. The diagonal scaling matrices DL and DR are chosen so */ /* that the pair DL*PL*A*PR*DR, DL*PL*B*PR*DR have elements close to */ /* one (except for the elements that start out zero.) */ /* After the eigenvalues and eigenvectors of the balanced matrices */ /* have been computed, ZGGBAK transforms the eigenvectors back to what */ /* they would have been (in perfect arithmetic) if they had not been */ /* balanced. */ /* Contents of A and B on Exit */ /* -------- -- - --- - -- ---- */ /* If any eigenvectors are computed (either JOBVL='V' or JOBVR='V' or */ /* both), then on exit the arrays A and B will contain the complex Schur */ /* form[*] of the "balanced" versions of A and B. If no eigenvectors */ /* are computed, then only the diagonal blocks will be correct. */ /* [*] In other words, upper triangular form. */ /* ===================================================================== */ /* .. Parameters .. */ /* .. */ /* .. Local Scalars .. */ /* .. */ /* .. Local Arrays .. */ /* .. */ /* .. External Subroutines .. */ /* .. */ /* .. External Functions .. */ /* .. */ /* .. Intrinsic Functions .. */ /* .. */ /* .. Statement Functions .. */ /* .. */ /* .. Statement Function definitions .. */ /* .. */ /* .. Executable Statements .. */ /* Decode the input arguments */ /* Parameter adjustments */ a_dim1 = *lda; a_offset = 1 + a_dim1; a -= a_offset; b_dim1 = *ldb; b_offset = 1 + b_dim1; b -= b_offset; --alpha; --beta; vl_dim1 = *ldvl; vl_offset = 1 + vl_dim1; vl -= vl_offset; vr_dim1 = *ldvr; vr_offset = 1 + vr_dim1; vr -= vr_offset; --work; --rwork; /* Function Body */ if (lsame_(jobvl, "N")) { ijobvl = 1; ilvl = FALSE_; } else if (lsame_(jobvl, "V")) { ijobvl = 2; ilvl = TRUE_; } else { ijobvl = -1; ilvl = FALSE_; } if (lsame_(jobvr, "N")) { ijobvr = 1; ilvr = FALSE_; } else if (lsame_(jobvr, "V")) { ijobvr = 2; ilvr = TRUE_; } else { ijobvr = -1; ilvr = FALSE_; } ilv = ilvl || ilvr; /* Test the input arguments */ /* Computing MAX */ i__1 = *n << 1; lwkmin = max(i__1,1); lwkopt = lwkmin; work[1].r = (doublereal) lwkopt, work[1].i = 0.; lquery = *lwork == -1; *info = 0; if (ijobvl <= 0) { *info = -1; } else if (ijobvr <= 0) { *info = -2; } else if (*n < 0) { *info = -3; } else if (*lda < max(1,*n)) { *info = -5; } else if (*ldb < max(1,*n)) { *info = -7; } else if (*ldvl < 1 || ilvl && *ldvl < *n) { *info = -11; } else if (*ldvr < 1 || ilvr && *ldvr < *n) { *info = -13; } else if (*lwork < lwkmin && ! lquery) { *info = -15; } if (*info == 0) { nb1 = ilaenv_(&c__1, "ZGEQRF", " ", n, n, &c_n1, &c_n1); nb2 = ilaenv_(&c__1, "ZUNMQR", " ", n, n, n, &c_n1); nb3 = ilaenv_(&c__1, "ZUNGQR", " ", n, n, n, &c_n1); /* Computing MAX */ i__1 = max(nb1,nb2); nb = max(i__1,nb3); /* Computing MAX */ i__1 = *n << 1, i__2 = *n * (nb + 1); lopt = max(i__1,i__2); work[1].r = (doublereal) lopt, work[1].i = 0.; } if (*info != 0) { i__1 = -(*info); xerbla_("ZGEGV ", &i__1); return 0; } else if (lquery) { return 0; } /* Quick return if possible */ if (*n == 0) { return 0; } /* Get machine constants */ eps = dlamch_("E") * dlamch_("B"); safmin = dlamch_("S"); safmin += safmin; safmax = 1. / safmin; /* Scale A */ anrm = zlange_("M", n, n, &a[a_offset], lda, &rwork[1]); anrm1 = anrm; anrm2 = 1.; if (anrm < 1.) { if (safmax * anrm < 1.) { anrm1 = safmin; anrm2 = safmax * anrm; } } if (anrm > 0.) { zlascl_("G", &c_n1, &c_n1, &anrm, &c_b29, n, n, &a[a_offset], lda, & iinfo); if (iinfo != 0) { *info = *n + 10; return 0; } } /* Scale B */ bnrm = zlange_("M", n, n, &b[b_offset], ldb, &rwork[1]); bnrm1 = bnrm; bnrm2 = 1.; if (bnrm < 1.) { if (safmax * bnrm < 1.) { bnrm1 = safmin; bnrm2 = safmax * bnrm; } } if (bnrm > 0.) { zlascl_("G", &c_n1, &c_n1, &bnrm, &c_b29, n, n, &b[b_offset], ldb, & iinfo); if (iinfo != 0) { *info = *n + 10; return 0; } } /* Permute the matrix to make it more nearly triangular */ /* Also "balance" the matrix. */ ileft = 1; iright = *n + 1; irwork = iright + *n; zggbal_("P", n, &a[a_offset], lda, &b[b_offset], ldb, &ilo, &ihi, &rwork[ ileft], &rwork[iright], &rwork[irwork], &iinfo); if (iinfo != 0) { *info = *n + 1; goto L80; } /* Reduce B to triangular form, and initialize VL and/or VR */ irows = ihi + 1 - ilo; if (ilv) { icols = *n + 1 - ilo; } else { icols = irows; } itau = 1; iwork = itau + irows; i__1 = *lwork + 1 - iwork; zgeqrf_(&irows, &icols, &b[ilo + ilo * b_dim1], ldb, &work[itau], &work[ iwork], &i__1, &iinfo); if (iinfo >= 0) { /* Computing MAX */ i__3 = iwork; i__1 = lwkopt, i__2 = (integer) work[i__3].r + iwork - 1; lwkopt = max(i__1,i__2); } if (iinfo != 0) { *info = *n + 2; goto L80; } i__1 = *lwork + 1 - iwork; zunmqr_("L", "C", &irows, &icols, &irows, &b[ilo + ilo * b_dim1], ldb, & work[itau], &a[ilo + ilo * a_dim1], lda, &work[iwork], &i__1, & iinfo); if (iinfo >= 0) { /* Computing MAX */ i__3 = iwork; i__1 = lwkopt, i__2 = (integer) work[i__3].r + iwork - 1; lwkopt = max(i__1,i__2); } if (iinfo != 0) { *info = *n + 3; goto L80; } if (ilvl) { zlaset_("Full", n, n, &c_b1, &c_b2, &vl[vl_offset], ldvl); i__1 = irows - 1; i__2 = irows - 1; zlacpy_("L", &i__1, &i__2, &b[ilo + 1 + ilo * b_dim1], ldb, &vl[ilo + 1 + ilo * vl_dim1], ldvl); i__1 = *lwork + 1 - iwork; zungqr_(&irows, &irows, &irows, &vl[ilo + ilo * vl_dim1], ldvl, &work[ itau], &work[iwork], &i__1, &iinfo); if (iinfo >= 0) { /* Computing MAX */ i__3 = iwork; i__1 = lwkopt, i__2 = (integer) work[i__3].r + iwork - 1; lwkopt = max(i__1,i__2); } if (iinfo != 0) { *info = *n + 4; goto L80; } } if (ilvr) { zlaset_("Full", n, n, &c_b1, &c_b2, &vr[vr_offset], ldvr); } /* Reduce to generalized Hessenberg form */ if (ilv) { /* Eigenvectors requested -- work on whole matrix. */ zgghrd_(jobvl, jobvr, n, &ilo, &ihi, &a[a_offset], lda, &b[b_offset], ldb, &vl[vl_offset], ldvl, &vr[vr_offset], ldvr, &iinfo); } else { zgghrd_("N", "N", &irows, &c__1, &irows, &a[ilo + ilo * a_dim1], lda, &b[ilo + ilo * b_dim1], ldb, &vl[vl_offset], ldvl, &vr[ vr_offset], ldvr, &iinfo); } if (iinfo != 0) { *info = *n + 5; goto L80; } /* Perform QZ algorithm */ iwork = itau; if (ilv) { *(unsigned char *)chtemp = 'S'; } else { *(unsigned char *)chtemp = 'E'; } i__1 = *lwork + 1 - iwork; zhgeqz_(chtemp, jobvl, jobvr, n, &ilo, &ihi, &a[a_offset], lda, &b[ b_offset], ldb, &alpha[1], &beta[1], &vl[vl_offset], ldvl, &vr[ vr_offset], ldvr, &work[iwork], &i__1, &rwork[irwork], &iinfo); if (iinfo >= 0) { /* Computing MAX */ i__3 = iwork; i__1 = lwkopt, i__2 = (integer) work[i__3].r + iwork - 1; lwkopt = max(i__1,i__2); } if (iinfo != 0) { if (iinfo > 0 && iinfo <= *n) { *info = iinfo; } else if (iinfo > *n && iinfo <= *n << 1) { *info = iinfo - *n; } else { *info = *n + 6; } goto L80; } if (ilv) { /* Compute Eigenvectors */ if (ilvl) { if (ilvr) { *(unsigned char *)chtemp = 'B'; } else { *(unsigned char *)chtemp = 'L'; } } else { *(unsigned char *)chtemp = 'R'; } ztgevc_(chtemp, "B", ldumma, n, &a[a_offset], lda, &b[b_offset], ldb, &vl[vl_offset], ldvl, &vr[vr_offset], ldvr, n, &in, &work[ iwork], &rwork[irwork], &iinfo); if (iinfo != 0) { *info = *n + 7; goto L80; } /* Undo balancing on VL and VR, rescale */ if (ilvl) { zggbak_("P", "L", n, &ilo, &ihi, &rwork[ileft], &rwork[iright], n, &vl[vl_offset], ldvl, &iinfo); if (iinfo != 0) { *info = *n + 8; goto L80; } i__1 = *n; for (jc = 1; jc <= i__1; ++jc) { temp = 0.; i__2 = *n; for (jr = 1; jr <= i__2; ++jr) { /* Computing MAX */ i__3 = jr + jc * vl_dim1; d__3 = temp, d__4 = (d__1 = vl[i__3].r, abs(d__1)) + ( d__2 = d_imag(&vl[jr + jc * vl_dim1]), abs(d__2)); temp = max(d__3,d__4); /* L10: */ } if (temp < safmin) { goto L30; } temp = 1. / temp; i__2 = *n; for (jr = 1; jr <= i__2; ++jr) { i__3 = jr + jc * vl_dim1; i__4 = jr + jc * vl_dim1; z__1.r = temp * vl[i__4].r, z__1.i = temp * vl[i__4].i; vl[i__3].r = z__1.r, vl[i__3].i = z__1.i; /* L20: */ } L30: ; } } if (ilvr) { zggbak_("P", "R", n, &ilo, &ihi, &rwork[ileft], &rwork[iright], n, &vr[vr_offset], ldvr, &iinfo); if (iinfo != 0) { *info = *n + 9; goto L80; } i__1 = *n; for (jc = 1; jc <= i__1; ++jc) { temp = 0.; i__2 = *n; for (jr = 1; jr <= i__2; ++jr) { /* Computing MAX */ i__3 = jr + jc * vr_dim1; d__3 = temp, d__4 = (d__1 = vr[i__3].r, abs(d__1)) + ( d__2 = d_imag(&vr[jr + jc * vr_dim1]), abs(d__2)); temp = max(d__3,d__4); /* L40: */ } if (temp < safmin) { goto L60; } temp = 1. / temp; i__2 = *n; for (jr = 1; jr <= i__2; ++jr) { i__3 = jr + jc * vr_dim1; i__4 = jr + jc * vr_dim1; z__1.r = temp * vr[i__4].r, z__1.i = temp * vr[i__4].i; vr[i__3].r = z__1.r, vr[i__3].i = z__1.i; /* L50: */ } L60: ; } } /* End of eigenvector calculation */ } /* Undo scaling in alpha, beta */ /* Note: this does not give the alpha and beta for the unscaled */ /* problem. */ /* Un-scaling is limited to avoid underflow in alpha and beta */ /* if they are significant. */ i__1 = *n; for (jc = 1; jc <= i__1; ++jc) { i__2 = jc; absar = (d__1 = alpha[i__2].r, abs(d__1)); absai = (d__1 = d_imag(&alpha[jc]), abs(d__1)); i__2 = jc; absb = (d__1 = beta[i__2].r, abs(d__1)); i__2 = jc; salfar = anrm * alpha[i__2].r; salfai = anrm * d_imag(&alpha[jc]); i__2 = jc; sbeta = bnrm * beta[i__2].r; ilimit = FALSE_; scale = 1.; /* Check for significant underflow in imaginary part of ALPHA */ /* Computing MAX */ d__1 = safmin, d__2 = eps * absar, d__1 = max(d__1,d__2), d__2 = eps * absb; if (abs(salfai) < safmin && absai >= max(d__1,d__2)) { ilimit = TRUE_; /* Computing MAX */ d__1 = safmin, d__2 = anrm2 * absai; scale = safmin / anrm1 / max(d__1,d__2); } /* Check for significant underflow in real part of ALPHA */ /* Computing MAX */ d__1 = safmin, d__2 = eps * absai, d__1 = max(d__1,d__2), d__2 = eps * absb; if (abs(salfar) < safmin && absar >= max(d__1,d__2)) { ilimit = TRUE_; /* Computing MAX */ /* Computing MAX */ d__3 = safmin, d__4 = anrm2 * absar; d__1 = scale, d__2 = safmin / anrm1 / max(d__3,d__4); scale = max(d__1,d__2); } /* Check for significant underflow in BETA */ /* Computing MAX */ d__1 = safmin, d__2 = eps * absar, d__1 = max(d__1,d__2), d__2 = eps * absai; if (abs(sbeta) < safmin && absb >= max(d__1,d__2)) { ilimit = TRUE_; /* Computing MAX */ /* Computing MAX */ d__3 = safmin, d__4 = bnrm2 * absb; d__1 = scale, d__2 = safmin / bnrm1 / max(d__3,d__4); scale = max(d__1,d__2); } /* Check for possible overflow when limiting scaling */ if (ilimit) { /* Computing MAX */ d__1 = abs(salfar), d__2 = abs(salfai), d__1 = max(d__1,d__2), d__2 = abs(sbeta); temp = scale * safmin * max(d__1,d__2); if (temp > 1.) { scale /= temp; } if (scale < 1.) { ilimit = FALSE_; } } /* Recompute un-scaled ALPHA, BETA if necessary. */ if (ilimit) { i__2 = jc; salfar = scale * alpha[i__2].r * anrm; salfai = scale * d_imag(&alpha[jc]) * anrm; i__2 = jc; z__2.r = scale * beta[i__2].r, z__2.i = scale * beta[i__2].i; z__1.r = bnrm * z__2.r, z__1.i = bnrm * z__2.i; sbeta = z__1.r; } i__2 = jc; z__1.r = salfar, z__1.i = salfai; alpha[i__2].r = z__1.r, alpha[i__2].i = z__1.i; i__2 = jc; beta[i__2].r = sbeta, beta[i__2].i = 0.; /* L70: */ } L80: work[1].r = (doublereal) lwkopt, work[1].i = 0.; return 0; /* End of ZGEGV */ } /* zgegv_ */
/* Subroutine */ int zggesx_(char *jobvsl, char *jobvsr, char *sort, L_fp selctg, char *sense, integer *n, doublecomplex *a, integer *lda, doublecomplex *b, integer *ldb, integer *sdim, doublecomplex *alpha, doublecomplex *beta, doublecomplex *vsl, integer *ldvsl, doublecomplex *vsr, integer *ldvsr, doublereal *rconde, doublereal * rcondv, doublecomplex *work, integer *lwork, doublereal *rwork, integer *iwork, integer *liwork, logical *bwork, integer *info) { /* System generated locals */ integer a_dim1, a_offset, b_dim1, b_offset, vsl_dim1, vsl_offset, vsr_dim1, vsr_offset, i__1, i__2; /* Builtin functions */ double sqrt(doublereal); /* Local variables */ integer i__; doublereal pl, pr, dif[2]; integer ihi, ilo; doublereal eps; integer ijob; doublereal anrm, bnrm; integer ierr, itau, iwrk, lwrk; extern logical lsame_(char *, char *); integer ileft, icols; logical cursl, ilvsl, ilvsr; integer irwrk, irows; extern /* Subroutine */ int dlabad_(doublereal *, doublereal *); extern doublereal dlamch_(char *); extern /* Subroutine */ int zggbak_(char *, char *, integer *, integer *, integer *, doublereal *, doublereal *, integer *, doublecomplex *, integer *, integer *), zggbal_(char *, integer *, doublecomplex *, integer *, doublecomplex *, integer *, integer * , integer *, doublereal *, doublereal *, doublereal *, integer *); logical ilascl, ilbscl; extern /* Subroutine */ int xerbla_(char *, integer *); extern integer ilaenv_(integer *, char *, char *, integer *, integer *, integer *, integer *); extern doublereal zlange_(char *, integer *, integer *, doublecomplex *, integer *, doublereal *); doublereal bignum; integer ijobvl, iright; extern /* Subroutine */ int zgghrd_(char *, char *, integer *, integer *, integer *, doublecomplex *, integer *, doublecomplex *, integer *, doublecomplex *, integer *, doublecomplex *, integer *, integer * ), zlascl_(char *, integer *, integer *, doublereal *, doublereal *, integer *, integer *, doublecomplex *, integer *, integer *); integer ijobvr; logical wantsb; integer liwmin; logical wantse, lastsl; doublereal anrmto, bnrmto; extern /* Subroutine */ int zgeqrf_(integer *, integer *, doublecomplex *, integer *, doublecomplex *, doublecomplex *, integer *, integer * ); integer maxwrk; logical wantsn; integer minwrk; doublereal smlnum; extern /* Subroutine */ int zhgeqz_(char *, char *, char *, integer *, integer *, integer *, doublecomplex *, integer *, doublecomplex *, integer *, doublecomplex *, doublecomplex *, doublecomplex *, integer *, doublecomplex *, integer *, doublecomplex *, integer *, doublereal *, integer *), zlacpy_(char *, integer *, integer *, doublecomplex *, integer *, doublecomplex * , integer *), zlaset_(char *, integer *, integer *, doublecomplex *, doublecomplex *, doublecomplex *, integer *); logical wantst, lquery, wantsv; extern /* Subroutine */ int ztgsen_(integer *, logical *, logical *, logical *, integer *, doublecomplex *, integer *, doublecomplex *, integer *, doublecomplex *, doublecomplex *, doublecomplex *, integer *, doublecomplex *, integer *, integer *, doublereal *, doublereal *, doublereal *, doublecomplex *, integer *, integer *, integer *, integer *), zungqr_(integer *, integer *, integer *, doublecomplex *, integer *, doublecomplex *, doublecomplex *, integer *, integer *), zunmqr_(char *, char *, integer *, integer *, integer *, doublecomplex *, integer *, doublecomplex *, doublecomplex *, integer *, doublecomplex *, integer *, integer *); /* -- LAPACK driver routine (version 3.4.0) -- */ /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */ /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */ /* November 2011 */ /* .. Scalar Arguments .. */ /* .. */ /* .. Array Arguments .. */ /* .. */ /* .. Function Arguments .. */ /* .. */ /* ===================================================================== */ /* .. Parameters .. */ /* .. */ /* .. Local Scalars .. */ /* .. */ /* .. Local Arrays .. */ /* .. */ /* .. External Subroutines .. */ /* .. */ /* .. External Functions .. */ /* .. */ /* .. Intrinsic Functions .. */ /* .. */ /* .. Executable Statements .. */ /* Decode the input arguments */ /* Parameter adjustments */ a_dim1 = *lda; a_offset = 1 + a_dim1; a -= a_offset; b_dim1 = *ldb; b_offset = 1 + b_dim1; b -= b_offset; --alpha; --beta; vsl_dim1 = *ldvsl; vsl_offset = 1 + vsl_dim1; vsl -= vsl_offset; vsr_dim1 = *ldvsr; vsr_offset = 1 + vsr_dim1; vsr -= vsr_offset; --rconde; --rcondv; --work; --rwork; --iwork; --bwork; /* Function Body */ if (lsame_(jobvsl, "N")) { ijobvl = 1; ilvsl = FALSE_; } else if (lsame_(jobvsl, "V")) { ijobvl = 2; ilvsl = TRUE_; } else { ijobvl = -1; ilvsl = FALSE_; } if (lsame_(jobvsr, "N")) { ijobvr = 1; ilvsr = FALSE_; } else if (lsame_(jobvsr, "V")) { ijobvr = 2; ilvsr = TRUE_; } else { ijobvr = -1; ilvsr = FALSE_; } wantst = lsame_(sort, "S"); wantsn = lsame_(sense, "N"); wantse = lsame_(sense, "E"); wantsv = lsame_(sense, "V"); wantsb = lsame_(sense, "B"); lquery = *lwork == -1 || *liwork == -1; if (wantsn) { ijob = 0; } else if (wantse) { ijob = 1; } else if (wantsv) { ijob = 2; } else if (wantsb) { ijob = 4; } /* Test the input arguments */ *info = 0; if (ijobvl <= 0) { *info = -1; } else if (ijobvr <= 0) { *info = -2; } else if (! wantst && ! lsame_(sort, "N")) { *info = -3; } else if (! (wantsn || wantse || wantsv || wantsb) || ! wantst && ! wantsn) { *info = -5; } else if (*n < 0) { *info = -6; } else if (*lda < max(1,*n)) { *info = -8; } else if (*ldb < max(1,*n)) { *info = -10; } else if (*ldvsl < 1 || ilvsl && *ldvsl < *n) { *info = -15; } else if (*ldvsr < 1 || ilvsr && *ldvsr < *n) { *info = -17; } /* Compute workspace */ /* (Note: Comments in the code beginning "Workspace:" describe the */ /* minimal amount of workspace needed at that point in the code, */ /* as well as the preferred amount for good performance. */ /* NB refers to the optimal block size for the immediately */ /* following subroutine, as returned by ILAENV.) */ if (*info == 0) { if (*n > 0) { minwrk = *n << 1; maxwrk = *n * (ilaenv_(&c__1, "ZGEQRF", " ", n, &c__1, n, &c__0) + 1); /* Computing MAX */ i__1 = maxwrk; i__2 = *n * (ilaenv_(&c__1, "ZUNMQR", " ", n, & c__1, n, &c_n1) + 1); // , expr subst maxwrk = max(i__1,i__2); if (ilvsl) { /* Computing MAX */ i__1 = maxwrk; i__2 = *n * (ilaenv_(&c__1, "ZUNGQR", " ", n, & c__1, n, &c_n1) + 1); // , expr subst maxwrk = max(i__1,i__2); } lwrk = maxwrk; if (ijob >= 1) { /* Computing MAX */ i__1 = lwrk; i__2 = *n * *n / 2; // , expr subst lwrk = max(i__1,i__2); } } else { minwrk = 1; maxwrk = 1; lwrk = 1; } work[1].r = (doublereal) lwrk; work[1].i = 0.; // , expr subst if (wantsn || *n == 0) { liwmin = 1; } else { liwmin = *n + 2; } iwork[1] = liwmin; if (*lwork < minwrk && ! lquery) { *info = -21; } else if (*liwork < liwmin && ! lquery) { *info = -24; } } if (*info != 0) { i__1 = -(*info); xerbla_("ZGGESX", &i__1); return 0; } else if (lquery) { return 0; } /* Quick return if possible */ if (*n == 0) { *sdim = 0; return 0; } /* Get machine constants */ eps = dlamch_("P"); smlnum = dlamch_("S"); bignum = 1. / smlnum; dlabad_(&smlnum, &bignum); smlnum = sqrt(smlnum) / eps; bignum = 1. / smlnum; /* Scale A if max element outside range [SMLNUM,BIGNUM] */ anrm = zlange_("M", n, n, &a[a_offset], lda, &rwork[1]); ilascl = FALSE_; if (anrm > 0. && anrm < smlnum) { anrmto = smlnum; ilascl = TRUE_; } else if (anrm > bignum) { anrmto = bignum; ilascl = TRUE_; } if (ilascl) { zlascl_("G", &c__0, &c__0, &anrm, &anrmto, n, n, &a[a_offset], lda, & ierr); } /* Scale B if max element outside range [SMLNUM,BIGNUM] */ bnrm = zlange_("M", n, n, &b[b_offset], ldb, &rwork[1]); ilbscl = FALSE_; if (bnrm > 0. && bnrm < smlnum) { bnrmto = smlnum; ilbscl = TRUE_; } else if (bnrm > bignum) { bnrmto = bignum; ilbscl = TRUE_; } if (ilbscl) { zlascl_("G", &c__0, &c__0, &bnrm, &bnrmto, n, n, &b[b_offset], ldb, & ierr); } /* Permute the matrix to make it more nearly triangular */ /* (Real Workspace: need 6*N) */ ileft = 1; iright = *n + 1; irwrk = iright + *n; zggbal_("P", n, &a[a_offset], lda, &b[b_offset], ldb, &ilo, &ihi, &rwork[ ileft], &rwork[iright], &rwork[irwrk], &ierr); /* Reduce B to triangular form (QR decomposition of B) */ /* (Complex Workspace: need N, prefer N*NB) */ irows = ihi + 1 - ilo; icols = *n + 1 - ilo; itau = 1; iwrk = itau + irows; i__1 = *lwork + 1 - iwrk; zgeqrf_(&irows, &icols, &b[ilo + ilo * b_dim1], ldb, &work[itau], &work[ iwrk], &i__1, &ierr); /* Apply the unitary transformation to matrix A */ /* (Complex Workspace: need N, prefer N*NB) */ i__1 = *lwork + 1 - iwrk; zunmqr_("L", "C", &irows, &icols, &irows, &b[ilo + ilo * b_dim1], ldb, & work[itau], &a[ilo + ilo * a_dim1], lda, &work[iwrk], &i__1, & ierr); /* Initialize VSL */ /* (Complex Workspace: need N, prefer N*NB) */ if (ilvsl) { zlaset_("Full", n, n, &c_b1, &c_b2, &vsl[vsl_offset], ldvsl); if (irows > 1) { i__1 = irows - 1; i__2 = irows - 1; zlacpy_("L", &i__1, &i__2, &b[ilo + 1 + ilo * b_dim1], ldb, &vsl[ ilo + 1 + ilo * vsl_dim1], ldvsl); } i__1 = *lwork + 1 - iwrk; zungqr_(&irows, &irows, &irows, &vsl[ilo + ilo * vsl_dim1], ldvsl, & work[itau], &work[iwrk], &i__1, &ierr); } /* Initialize VSR */ if (ilvsr) { zlaset_("Full", n, n, &c_b1, &c_b2, &vsr[vsr_offset], ldvsr); } /* Reduce to generalized Hessenberg form */ /* (Workspace: none needed) */ zgghrd_(jobvsl, jobvsr, n, &ilo, &ihi, &a[a_offset], lda, &b[b_offset], ldb, &vsl[vsl_offset], ldvsl, &vsr[vsr_offset], ldvsr, &ierr); *sdim = 0; /* Perform QZ algorithm, computing Schur vectors if desired */ /* (Complex Workspace: need N) */ /* (Real Workspace: need N) */ iwrk = itau; i__1 = *lwork + 1 - iwrk; zhgeqz_("S", jobvsl, jobvsr, n, &ilo, &ihi, &a[a_offset], lda, &b[ b_offset], ldb, &alpha[1], &beta[1], &vsl[vsl_offset], ldvsl, & vsr[vsr_offset], ldvsr, &work[iwrk], &i__1, &rwork[irwrk], &ierr); if (ierr != 0) { if (ierr > 0 && ierr <= *n) { *info = ierr; } else if (ierr > *n && ierr <= *n << 1) { *info = ierr - *n; } else { *info = *n + 1; } goto L40; } /* Sort eigenvalues ALPHA/BETA and compute the reciprocal of */ /* condition number(s) */ if (wantst) { /* Undo scaling on eigenvalues before SELCTGing */ if (ilascl) { zlascl_("G", &c__0, &c__0, &anrmto, &anrm, n, &c__1, &alpha[1], n, &ierr); } if (ilbscl) { zlascl_("G", &c__0, &c__0, &bnrmto, &bnrm, n, &c__1, &beta[1], n, &ierr); } /* Select eigenvalues */ i__1 = *n; for (i__ = 1; i__ <= i__1; ++i__) { bwork[i__] = (*selctg)(&alpha[i__], &beta[i__]); /* L10: */ } /* Reorder eigenvalues, transform Generalized Schur vectors, and */ /* compute reciprocal condition numbers */ /* (Complex Workspace: If IJOB >= 1, need MAX(1, 2*SDIM*(N-SDIM)) */ /* otherwise, need 1 ) */ i__1 = *lwork - iwrk + 1; ztgsen_(&ijob, &ilvsl, &ilvsr, &bwork[1], n, &a[a_offset], lda, &b[ b_offset], ldb, &alpha[1], &beta[1], &vsl[vsl_offset], ldvsl, &vsr[vsr_offset], ldvsr, sdim, &pl, &pr, dif, &work[iwrk], & i__1, &iwork[1], liwork, &ierr); if (ijob >= 1) { /* Computing MAX */ i__1 = maxwrk; i__2 = (*sdim << 1) * (*n - *sdim); // , expr subst maxwrk = max(i__1,i__2); } if (ierr == -21) { /* not enough complex workspace */ *info = -21; } else { if (ijob == 1 || ijob == 4) { rconde[1] = pl; rconde[2] = pr; } if (ijob == 2 || ijob == 4) { rcondv[1] = dif[0]; rcondv[2] = dif[1]; } if (ierr == 1) { *info = *n + 3; } } } /* Apply permutation to VSL and VSR */ /* (Workspace: none needed) */ if (ilvsl) { zggbak_("P", "L", n, &ilo, &ihi, &rwork[ileft], &rwork[iright], n, & vsl[vsl_offset], ldvsl, &ierr); } if (ilvsr) { zggbak_("P", "R", n, &ilo, &ihi, &rwork[ileft], &rwork[iright], n, & vsr[vsr_offset], ldvsr, &ierr); } /* Undo scaling */ if (ilascl) { zlascl_("U", &c__0, &c__0, &anrmto, &anrm, n, n, &a[a_offset], lda, & ierr); zlascl_("G", &c__0, &c__0, &anrmto, &anrm, n, &c__1, &alpha[1], n, & ierr); } if (ilbscl) { zlascl_("U", &c__0, &c__0, &bnrmto, &bnrm, n, n, &b[b_offset], ldb, & ierr); zlascl_("G", &c__0, &c__0, &bnrmto, &bnrm, n, &c__1, &beta[1], n, & ierr); } if (wantst) { /* Check if reordering is correct */ lastsl = TRUE_; *sdim = 0; i__1 = *n; for (i__ = 1; i__ <= i__1; ++i__) { cursl = (*selctg)(&alpha[i__], &beta[i__]); if (cursl) { ++(*sdim); } if (cursl && ! lastsl) { *info = *n + 2; } lastsl = cursl; /* L30: */ } } L40: work[1].r = (doublereal) maxwrk; work[1].i = 0.; // , expr subst iwork[1] = liwmin; return 0; /* End of ZGGESX */ }
/* Subroutine */ int zlaqzh_(logical *ilq, logical *ilz, integer *n, integer * ilo, integer *ihi, doublecomplex *a, integer *lda, doublecomplex *b, integer *ldb, doublecomplex *q, integer *ldq, doublecomplex *z__, integer *ldz, doublecomplex *work, integer *info) { /* System generated locals */ integer a_dim1, a_offset, b_dim1, b_offset, q_dim1, q_offset, z_dim1, z_offset, i__1, i__2; /* Local variables */ static integer iinfo, icols; static char compq[1], compz[1]; static integer irows; extern /* Subroutine */ int zgghrd_(char *, char *, integer *, integer *, integer *, doublecomplex *, integer *, doublecomplex *, integer *, doublecomplex *, integer *, doublecomplex *, integer *, integer * ), zgeqrf_(integer *, integer *, doublecomplex *, integer *, doublecomplex *, doublecomplex *, integer *, integer *) , zlacpy_(char *, integer *, integer *, doublecomplex *, integer * , doublecomplex *, integer *), zlaset_(char *, integer *, integer *, doublecomplex *, doublecomplex *, doublecomplex *, integer *), zungqr_(integer *, integer *, integer *, doublecomplex *, integer *, doublecomplex *, doublecomplex *, integer *, integer *), zunmqr_(char *, char *, integer *, integer *, integer *, doublecomplex *, integer *, doublecomplex *, doublecomplex *, integer *, doublecomplex *, integer *, integer *); #define a_subscr(a_1,a_2) (a_2)*a_dim1 + a_1 #define a_ref(a_1,a_2) a[a_subscr(a_1,a_2)] #define b_subscr(a_1,a_2) (a_2)*b_dim1 + a_1 #define b_ref(a_1,a_2) b[b_subscr(a_1,a_2)] #define q_subscr(a_1,a_2) (a_2)*q_dim1 + a_1 #define q_ref(a_1,a_2) q[q_subscr(a_1,a_2)] /* -- LAPACK timing routine (version 3.0) -- Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd., Courant Institute, Argonne National Lab, and Rice University September 30, 1994 Purpose ======= This calls the LAPACK routines to perform the function of QZHES. It is similar in function to ZGGHRD, except that B is not assumed to be upper-triangular. It reduces a pair of matrices (A,B) to a Hessenberg-triangular pair (H,T). More specifically, it computes unitary matrices Q and Z, an (upper) Hessenberg matrix H, and an upper triangular matrix T such that: A = Q H Z* and B = Q T Z* where * means conjugate transpose. Arguments ========= ILQ (input) LOGICAL = .FALSE. do not compute Q. = .TRUE. compute Q. ILZ (input) LOGICAL = .FALSE. do not compute Z. = .TRUE. compute Z. N (input) INTEGER The number of rows and columns in the matrices A, B, Q, and Z. N must be at least 0. ILO (input) INTEGER Columns 1 through ILO-1 of A and B are assumed to be in upper triangular form already, and will not be modified. ILO must be at least 1. IHI (input) INTEGER Rows IHI+1 through N of A and B are assumed to be in upper triangular form already, and will not be touched. IHI may not be greater than N. A (input/output) COMPLEX*16 array, dimension (LDA, N) On entry, the first of the pair of N x N general matrices to be reduced. On exit, the upper triangle and the first subdiagonal of A are overwritten with the Hessenberg matrix H, and the rest is set to zero. LDA (input) INTEGER The leading dimension of A as declared in the calling program. LDA must be at least max ( 1, N ) . B (input/output) COMPLEX*16 array, dimension (LDB, N) On entry, the second of the pair of N x N general matrices to be reduced. On exit, the transformed matrix T = Q* B Z, which is upper triangular. LDB (input) INTEGER The leading dimension of B as declared in the calling program. LDB must be at least max ( 1, N ) . Q (output) COMPLEX*16 array, dimension (LDQ,N) If ILQ = .TRUE., Q will contain the unitary matrix Q. (See "Purpose", above.) Will not be referenced if ILQ = .FALSE. LDQ (input) INTEGER The leading dimension of the matrix Q. LDQ must be at least 1 and at least N. Z (output) COMPLEX*16 array, dimension (LDZ,N) If ILZ = .TRUE., Z will contain the unitary matrix Z. (See "Purpose", above.) May be referenced even if ILZ = .FALSE. LDZ (input) INTEGER The leading dimension of the matrix Z. LDZ must be at least 1 and at least N. WORK (workspace) COMPLEX*16 array, dimension (N) Workspace. INFO (output) INTEGER = 0: successful exit. < 0: if INFO = -i, the i-th argument had an illegal value. > 0: errors that usually indicate LAPACK problems: = 2: error return from ZGEQRF; = 3: error return from ZUNMQR; = 4: error return from ZUNGQR; = 5: error return from ZGGHRD. ===================================================================== Quick return if possible Parameter adjustments */ --work; a_dim1 = *lda; a_offset = 1 + a_dim1 * 1; a -= a_offset; b_dim1 = *ldb; b_offset = 1 + b_dim1 * 1; b -= b_offset; q_dim1 = *ldq; q_offset = 1 + q_dim1 * 1; q -= q_offset; z_dim1 = *ldz; z_offset = 1 + z_dim1 * 1; z__ -= z_offset; /* Function Body */ if (*n == 0) { return 0; } /* Reduce B to triangular form, and initialize Q and/or Z */ irows = *ihi + 1 - *ilo; icols = *n + 1 - *ilo; i__1 = *n * *ldz; zgeqrf_(&irows, &icols, &b_ref(*ilo, *ilo), ldb, &work[1], &z__[z_offset], &i__1, &iinfo); if (iinfo != 0) { *info = 2; goto L10; } i__1 = *n * *ldz; zunmqr_("L", "C", &irows, &icols, &irows, &b_ref(*ilo, *ilo), ldb, &work[ 1], &a_ref(*ilo, *ilo), lda, &z__[z_offset], &i__1, &iinfo); if (iinfo != 0) { *info = 3; goto L10; } if (*ilq) { zlaset_("Full", n, n, &c_b1, &c_b2, &q[q_offset], ldq); i__1 = irows - 1; i__2 = irows - 1; zlacpy_("L", &i__1, &i__2, &b_ref(*ilo + 1, *ilo), ldb, &q_ref(*ilo + 1, *ilo), ldq); i__1 = *n * *ldz; zungqr_(&irows, &irows, &irows, &q_ref(*ilo, *ilo), ldq, &work[1], & z__[z_offset], &i__1, &iinfo); if (iinfo != 0) { *info = 4; goto L10; } } /* Reduce to generalized Hessenberg form */ if (*ilq) { *(unsigned char *)compq = 'V'; } else { *(unsigned char *)compq = 'N'; } if (*ilz) { *(unsigned char *)compz = 'I'; } else { *(unsigned char *)compz = 'N'; } zgghrd_(compq, compz, n, ilo, ihi, &a[a_offset], lda, &b[b_offset], ldb, & q[q_offset], ldq, &z__[z_offset], ldz, &iinfo); if (iinfo != 0) { *info = 5; goto L10; } /* End */ L10: return 0; /* End of ZLAQZH */ } /* zlaqzh_ */
/* Subroutine */ int zggev_(char *jobvl, char *jobvr, integer *n, doublecomplex *a, integer *lda, doublecomplex *b, integer *ldb, doublecomplex *alpha, doublecomplex *beta, doublecomplex *vl, integer *ldvl, doublecomplex *vr, integer *ldvr, doublecomplex *work, integer *lwork, doublereal *rwork, integer *info) { /* System generated locals */ integer a_dim1, a_offset, b_dim1, b_offset, vl_dim1, vl_offset, vr_dim1, vr_offset, i__1, i__2, i__3, i__4; doublereal d__1, d__2, d__3, d__4; doublecomplex z__1; /* Builtin functions */ double sqrt(doublereal), d_imag(doublecomplex *); /* Local variables */ integer jc, in, jr, ihi, ilo; doublereal eps; logical ilv; doublereal anrm, bnrm; integer ierr, itau; doublereal temp; logical ilvl, ilvr; integer iwrk; extern logical lsame_(char *, char *); integer ileft, icols, irwrk, irows; extern /* Subroutine */ int dlabad_(doublereal *, doublereal *); extern doublereal dlamch_(char *); extern /* Subroutine */ int zggbak_(char *, char *, integer *, integer *, integer *, doublereal *, doublereal *, integer *, doublecomplex *, integer *, integer *), zggbal_(char *, integer *, doublecomplex *, integer *, doublecomplex *, integer *, integer * , integer *, doublereal *, doublereal *, doublereal *, integer *); logical ilascl, ilbscl; extern /* Subroutine */ int xerbla_(char *, integer *); extern integer ilaenv_(integer *, char *, char *, integer *, integer *, integer *, integer *); logical ldumma[1]; char chtemp[1]; doublereal bignum; extern doublereal zlange_(char *, integer *, integer *, doublecomplex *, integer *, doublereal *); integer ijobvl, iright; extern /* Subroutine */ int zgghrd_(char *, char *, integer *, integer *, integer *, doublecomplex *, integer *, doublecomplex *, integer *, doublecomplex *, integer *, doublecomplex *, integer *, integer * ), zlascl_(char *, integer *, integer *, doublereal *, doublereal *, integer *, integer *, doublecomplex *, integer *, integer *); integer ijobvr; extern /* Subroutine */ int zgeqrf_(integer *, integer *, doublecomplex *, integer *, doublecomplex *, doublecomplex *, integer *, integer * ); doublereal anrmto; integer lwkmin; doublereal bnrmto; extern /* Subroutine */ int zlacpy_(char *, integer *, integer *, doublecomplex *, integer *, doublecomplex *, integer *), zlaset_(char *, integer *, integer *, doublecomplex *, doublecomplex *, doublecomplex *, integer *), ztgevc_( char *, char *, logical *, integer *, doublecomplex *, integer *, doublecomplex *, integer *, doublecomplex *, integer *, doublecomplex *, integer *, integer *, integer *, doublecomplex *, doublereal *, integer *), zhgeqz_(char *, char *, char *, integer *, integer *, integer *, doublecomplex *, integer *, doublecomplex *, integer *, doublecomplex *, doublecomplex *, doublecomplex *, integer *, doublecomplex *, integer *, doublecomplex *, integer *, doublereal *, integer *); doublereal smlnum; integer lwkopt; logical lquery; extern /* Subroutine */ int zungqr_(integer *, integer *, integer *, doublecomplex *, integer *, doublecomplex *, doublecomplex *, integer *, integer *), zunmqr_(char *, char *, integer *, integer *, integer *, doublecomplex *, integer *, doublecomplex *, doublecomplex *, integer *, doublecomplex *, integer *, integer *); /* -- LAPACK driver routine (version 3.4.1) -- */ /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */ /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */ /* April 2012 */ /* .. Scalar Arguments .. */ /* .. */ /* .. Array Arguments .. */ /* .. */ /* ===================================================================== */ /* .. Parameters .. */ /* .. */ /* .. Local Scalars .. */ /* .. */ /* .. Local Arrays .. */ /* .. */ /* .. External Subroutines .. */ /* .. */ /* .. External Functions .. */ /* .. */ /* .. Intrinsic Functions .. */ /* .. */ /* .. Statement Functions .. */ /* .. */ /* .. Statement Function definitions .. */ /* .. */ /* .. Executable Statements .. */ /* Decode the input arguments */ /* Parameter adjustments */ a_dim1 = *lda; a_offset = 1 + a_dim1; a -= a_offset; b_dim1 = *ldb; b_offset = 1 + b_dim1; b -= b_offset; --alpha; --beta; vl_dim1 = *ldvl; vl_offset = 1 + vl_dim1; vl -= vl_offset; vr_dim1 = *ldvr; vr_offset = 1 + vr_dim1; vr -= vr_offset; --work; --rwork; /* Function Body */ if (lsame_(jobvl, "N")) { ijobvl = 1; ilvl = FALSE_; } else if (lsame_(jobvl, "V")) { ijobvl = 2; ilvl = TRUE_; } else { ijobvl = -1; ilvl = FALSE_; } if (lsame_(jobvr, "N")) { ijobvr = 1; ilvr = FALSE_; } else if (lsame_(jobvr, "V")) { ijobvr = 2; ilvr = TRUE_; } else { ijobvr = -1; ilvr = FALSE_; } ilv = ilvl || ilvr; /* Test the input arguments */ *info = 0; lquery = *lwork == -1; if (ijobvl <= 0) { *info = -1; } else if (ijobvr <= 0) { *info = -2; } else if (*n < 0) { *info = -3; } else if (*lda < max(1,*n)) { *info = -5; } else if (*ldb < max(1,*n)) { *info = -7; } else if (*ldvl < 1 || ilvl && *ldvl < *n) { *info = -11; } else if (*ldvr < 1 || ilvr && *ldvr < *n) { *info = -13; } /* Compute workspace */ /* (Note: Comments in the code beginning "Workspace:" describe the */ /* minimal amount of workspace needed at that point in the code, */ /* as well as the preferred amount for good performance. */ /* NB refers to the optimal block size for the immediately */ /* following subroutine, as returned by ILAENV. The workspace is */ /* computed assuming ILO = 1 and IHI = N, the worst case.) */ if (*info == 0) { /* Computing MAX */ i__1 = 1; i__2 = *n << 1; // , expr subst lwkmin = max(i__1,i__2); /* Computing MAX */ i__1 = 1; i__2 = *n + *n * ilaenv_(&c__1, "ZGEQRF", " ", n, &c__1, n, &c__0); // , expr subst lwkopt = max(i__1,i__2); /* Computing MAX */ i__1 = lwkopt; i__2 = *n + *n * ilaenv_(&c__1, "ZUNMQR", " ", n, & c__1, n, &c__0); // , expr subst lwkopt = max(i__1,i__2); if (ilvl) { /* Computing MAX */ i__1 = lwkopt; i__2 = *n + *n * ilaenv_(&c__1, "ZUNGQR", " ", n, & c__1, n, &c_n1); // , expr subst lwkopt = max(i__1,i__2); } work[1].r = (doublereal) lwkopt; work[1].i = 0.; // , expr subst if (*lwork < lwkmin && ! lquery) { *info = -15; } } if (*info != 0) { i__1 = -(*info); xerbla_("ZGGEV ", &i__1); return 0; } else if (lquery) { return 0; } /* Quick return if possible */ if (*n == 0) { return 0; } /* Get machine constants */ eps = dlamch_("E") * dlamch_("B"); smlnum = dlamch_("S"); bignum = 1. / smlnum; dlabad_(&smlnum, &bignum); smlnum = sqrt(smlnum) / eps; bignum = 1. / smlnum; /* Scale A if max element outside range [SMLNUM,BIGNUM] */ anrm = zlange_("M", n, n, &a[a_offset], lda, &rwork[1]); ilascl = FALSE_; if (anrm > 0. && anrm < smlnum) { anrmto = smlnum; ilascl = TRUE_; } else if (anrm > bignum) { anrmto = bignum; ilascl = TRUE_; } if (ilascl) { zlascl_("G", &c__0, &c__0, &anrm, &anrmto, n, n, &a[a_offset], lda, & ierr); } /* Scale B if max element outside range [SMLNUM,BIGNUM] */ bnrm = zlange_("M", n, n, &b[b_offset], ldb, &rwork[1]); ilbscl = FALSE_; if (bnrm > 0. && bnrm < smlnum) { bnrmto = smlnum; ilbscl = TRUE_; } else if (bnrm > bignum) { bnrmto = bignum; ilbscl = TRUE_; } if (ilbscl) { zlascl_("G", &c__0, &c__0, &bnrm, &bnrmto, n, n, &b[b_offset], ldb, & ierr); } /* Permute the matrices A, B to isolate eigenvalues if possible */ /* (Real Workspace: need 6*N) */ ileft = 1; iright = *n + 1; irwrk = iright + *n; zggbal_("P", n, &a[a_offset], lda, &b[b_offset], ldb, &ilo, &ihi, &rwork[ ileft], &rwork[iright], &rwork[irwrk], &ierr); /* Reduce B to triangular form (QR decomposition of B) */ /* (Complex Workspace: need N, prefer N*NB) */ irows = ihi + 1 - ilo; if (ilv) { icols = *n + 1 - ilo; } else { icols = irows; } itau = 1; iwrk = itau + irows; i__1 = *lwork + 1 - iwrk; zgeqrf_(&irows, &icols, &b[ilo + ilo * b_dim1], ldb, &work[itau], &work[ iwrk], &i__1, &ierr); /* Apply the orthogonal transformation to matrix A */ /* (Complex Workspace: need N, prefer N*NB) */ i__1 = *lwork + 1 - iwrk; zunmqr_("L", "C", &irows, &icols, &irows, &b[ilo + ilo * b_dim1], ldb, & work[itau], &a[ilo + ilo * a_dim1], lda, &work[iwrk], &i__1, & ierr); /* Initialize VL */ /* (Complex Workspace: need N, prefer N*NB) */ if (ilvl) { zlaset_("Full", n, n, &c_b1, &c_b2, &vl[vl_offset], ldvl); if (irows > 1) { i__1 = irows - 1; i__2 = irows - 1; zlacpy_("L", &i__1, &i__2, &b[ilo + 1 + ilo * b_dim1], ldb, &vl[ ilo + 1 + ilo * vl_dim1], ldvl); } i__1 = *lwork + 1 - iwrk; zungqr_(&irows, &irows, &irows, &vl[ilo + ilo * vl_dim1], ldvl, &work[ itau], &work[iwrk], &i__1, &ierr); } /* Initialize VR */ if (ilvr) { zlaset_("Full", n, n, &c_b1, &c_b2, &vr[vr_offset], ldvr); } /* Reduce to generalized Hessenberg form */ if (ilv) { /* Eigenvectors requested -- work on whole matrix. */ zgghrd_(jobvl, jobvr, n, &ilo, &ihi, &a[a_offset], lda, &b[b_offset], ldb, &vl[vl_offset], ldvl, &vr[vr_offset], ldvr, &ierr); } else { zgghrd_("N", "N", &irows, &c__1, &irows, &a[ilo + ilo * a_dim1], lda, &b[ilo + ilo * b_dim1], ldb, &vl[vl_offset], ldvl, &vr[ vr_offset], ldvr, &ierr); } /* Perform QZ algorithm (Compute eigenvalues, and optionally, the */ /* Schur form and Schur vectors) */ /* (Complex Workspace: need N) */ /* (Real Workspace: need N) */ iwrk = itau; if (ilv) { *(unsigned char *)chtemp = 'S'; } else { *(unsigned char *)chtemp = 'E'; } i__1 = *lwork + 1 - iwrk; zhgeqz_(chtemp, jobvl, jobvr, n, &ilo, &ihi, &a[a_offset], lda, &b[ b_offset], ldb, &alpha[1], &beta[1], &vl[vl_offset], ldvl, &vr[ vr_offset], ldvr, &work[iwrk], &i__1, &rwork[irwrk], &ierr); if (ierr != 0) { if (ierr > 0 && ierr <= *n) { *info = ierr; } else if (ierr > *n && ierr <= *n << 1) { *info = ierr - *n; } else { *info = *n + 1; } goto L70; } /* Compute Eigenvectors */ /* (Real Workspace: need 2*N) */ /* (Complex Workspace: need 2*N) */ if (ilv) { if (ilvl) { if (ilvr) { *(unsigned char *)chtemp = 'B'; } else { *(unsigned char *)chtemp = 'L'; } } else { *(unsigned char *)chtemp = 'R'; } ztgevc_(chtemp, "B", ldumma, n, &a[a_offset], lda, &b[b_offset], ldb, &vl[vl_offset], ldvl, &vr[vr_offset], ldvr, n, &in, &work[ iwrk], &rwork[irwrk], &ierr); if (ierr != 0) { *info = *n + 2; goto L70; } /* Undo balancing on VL and VR and normalization */ /* (Workspace: none needed) */ if (ilvl) { zggbak_("P", "L", n, &ilo, &ihi, &rwork[ileft], &rwork[iright], n, &vl[vl_offset], ldvl, &ierr); i__1 = *n; for (jc = 1; jc <= i__1; ++jc) { temp = 0.; i__2 = *n; for (jr = 1; jr <= i__2; ++jr) { /* Computing MAX */ i__3 = jr + jc * vl_dim1; d__3 = temp; d__4 = (d__1 = vl[i__3].r, f2c_abs(d__1)) + ( d__2 = d_imag(&vl[jr + jc * vl_dim1]), f2c_abs(d__2)); // , expr subst temp = max(d__3,d__4); /* L10: */ } if (temp < smlnum) { goto L30; } temp = 1. / temp; i__2 = *n; for (jr = 1; jr <= i__2; ++jr) { i__3 = jr + jc * vl_dim1; i__4 = jr + jc * vl_dim1; z__1.r = temp * vl[i__4].r; z__1.i = temp * vl[i__4].i; // , expr subst vl[i__3].r = z__1.r; vl[i__3].i = z__1.i; // , expr subst /* L20: */ } L30: ; } } if (ilvr) { zggbak_("P", "R", n, &ilo, &ihi, &rwork[ileft], &rwork[iright], n, &vr[vr_offset], ldvr, &ierr); i__1 = *n; for (jc = 1; jc <= i__1; ++jc) { temp = 0.; i__2 = *n; for (jr = 1; jr <= i__2; ++jr) { /* Computing MAX */ i__3 = jr + jc * vr_dim1; d__3 = temp; d__4 = (d__1 = vr[i__3].r, f2c_abs(d__1)) + ( d__2 = d_imag(&vr[jr + jc * vr_dim1]), f2c_abs(d__2)); // , expr subst temp = max(d__3,d__4); /* L40: */ } if (temp < smlnum) { goto L60; } temp = 1. / temp; i__2 = *n; for (jr = 1; jr <= i__2; ++jr) { i__3 = jr + jc * vr_dim1; i__4 = jr + jc * vr_dim1; z__1.r = temp * vr[i__4].r; z__1.i = temp * vr[i__4].i; // , expr subst vr[i__3].r = z__1.r; vr[i__3].i = z__1.i; // , expr subst /* L50: */ } L60: ; } } } /* Undo scaling if necessary */ L70: if (ilascl) { zlascl_("G", &c__0, &c__0, &anrmto, &anrm, n, &c__1, &alpha[1], n, & ierr); } if (ilbscl) { zlascl_("G", &c__0, &c__0, &bnrmto, &bnrm, n, &c__1, &beta[1], n, & ierr); } work[1].r = (doublereal) lwkopt; work[1].i = 0.; // , expr subst return 0; /* End of ZGGEV */ }