ztrsna.c
Go to the documentation of this file.
00001 /* ztrsna.f -- translated by f2c (version 20061008).
00002    You must link the resulting object file with libf2c:
00003         on Microsoft Windows system, link with libf2c.lib;
00004         on Linux or Unix systems, link with .../path/to/libf2c.a -lm
00005         or, if you install libf2c.a in a standard place, with -lf2c -lm
00006         -- in that order, at the end of the command line, as in
00007                 cc *.o -lf2c -lm
00008         Source for libf2c is in /netlib/f2c/libf2c.zip, e.g.,
00009 
00010                 http://www.netlib.org/f2c/libf2c.zip
00011 */
00012 
00013 #include "f2c.h"
00014 #include "blaswrap.h"
00015 
00016 /* Table of constant values */
00017 
00018 static integer c__1 = 1;
00019 
00020 /* Subroutine */ int ztrsna_(char *job, char *howmny, logical *select, 
00021         integer *n, doublecomplex *t, integer *ldt, doublecomplex *vl, 
00022         integer *ldvl, doublecomplex *vr, integer *ldvr, doublereal *s, 
00023         doublereal *sep, integer *mm, integer *m, doublecomplex *work, 
00024         integer *ldwork, doublereal *rwork, integer *info)
00025 {
00026     /* System generated locals */
00027     integer t_dim1, t_offset, vl_dim1, vl_offset, vr_dim1, vr_offset, 
00028             work_dim1, work_offset, i__1, i__2, i__3, i__4, i__5;
00029     doublereal d__1, d__2;
00030     doublecomplex z__1;
00031 
00032     /* Builtin functions */
00033     double z_abs(doublecomplex *), d_imag(doublecomplex *);
00034 
00035     /* Local variables */
00036     integer i__, j, k, ks, ix;
00037     doublereal eps, est;
00038     integer kase, ierr;
00039     doublecomplex prod;
00040     doublereal lnrm, rnrm, scale;
00041     extern logical lsame_(char *, char *);
00042     integer isave[3];
00043     extern /* Double Complex */ VOID zdotc_(doublecomplex *, integer *, 
00044             doublecomplex *, integer *, doublecomplex *, integer *);
00045     doublecomplex dummy[1];
00046     logical wants;
00047     doublereal xnorm;
00048     extern /* Subroutine */ int zlacn2_(integer *, doublecomplex *, 
00049             doublecomplex *, doublereal *, integer *, integer *), dlabad_(
00050             doublereal *, doublereal *);
00051     extern doublereal dznrm2_(integer *, doublecomplex *, integer *), dlamch_(
00052             char *);
00053     extern /* Subroutine */ int xerbla_(char *, integer *);
00054     doublereal bignum;
00055     logical wantbh;
00056     extern integer izamax_(integer *, doublecomplex *, integer *);
00057     logical somcon;
00058     extern /* Subroutine */ int zdrscl_(integer *, doublereal *, 
00059             doublecomplex *, integer *);
00060     char normin[1];
00061     extern /* Subroutine */ int zlacpy_(char *, integer *, integer *, 
00062             doublecomplex *, integer *, doublecomplex *, integer *);
00063     doublereal smlnum;
00064     logical wantsp;
00065     extern /* Subroutine */ int zlatrs_(char *, char *, char *, char *, 
00066             integer *, doublecomplex *, integer *, doublecomplex *, 
00067             doublereal *, doublereal *, integer *), ztrexc_(char *, integer *, doublecomplex *, integer *, 
00068             doublecomplex *, integer *, integer *, integer *, integer *);
00069 
00070 
00071 /*  -- LAPACK routine (version 3.2) -- */
00072 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
00073 /*     November 2006 */
00074 
00075 /*     Modified to call ZLACN2 in place of ZLACON, 10 Feb 03, SJH. */
00076 
00077 /*     .. Scalar Arguments .. */
00078 /*     .. */
00079 /*     .. Array Arguments .. */
00080 /*     .. */
00081 
00082 /*  Purpose */
00083 /*  ======= */
00084 
00085 /*  ZTRSNA estimates reciprocal condition numbers for specified */
00086 /*  eigenvalues and/or right eigenvectors of a complex upper triangular */
00087 /*  matrix T (or of any matrix Q*T*Q**H with Q unitary). */
00088 
00089 /*  Arguments */
00090 /*  ========= */
00091 
00092 /*  JOB     (input) CHARACTER*1 */
00093 /*          Specifies whether condition numbers are required for */
00094 /*          eigenvalues (S) or eigenvectors (SEP): */
00095 /*          = 'E': for eigenvalues only (S); */
00096 /*          = 'V': for eigenvectors only (SEP); */
00097 /*          = 'B': for both eigenvalues and eigenvectors (S and SEP). */
00098 
00099 /*  HOWMNY  (input) CHARACTER*1 */
00100 /*          = 'A': compute condition numbers for all eigenpairs; */
00101 /*          = 'S': compute condition numbers for selected eigenpairs */
00102 /*                 specified by the array SELECT. */
00103 
00104 /*  SELECT  (input) LOGICAL array, dimension (N) */
00105 /*          If HOWMNY = 'S', SELECT specifies the eigenpairs for which */
00106 /*          condition numbers are required. To select condition numbers */
00107 /*          for the j-th eigenpair, SELECT(j) must be set to .TRUE.. */
00108 /*          If HOWMNY = 'A', SELECT is not referenced. */
00109 
00110 /*  N       (input) INTEGER */
00111 /*          The order of the matrix T. N >= 0. */
00112 
00113 /*  T       (input) COMPLEX*16 array, dimension (LDT,N) */
00114 /*          The upper triangular matrix T. */
00115 
00116 /*  LDT     (input) INTEGER */
00117 /*          The leading dimension of the array T. LDT >= max(1,N). */
00118 
00119 /*  VL      (input) COMPLEX*16 array, dimension (LDVL,M) */
00120 /*          If JOB = 'E' or 'B', VL must contain left eigenvectors of T */
00121 /*          (or of any Q*T*Q**H with Q unitary), corresponding to the */
00122 /*          eigenpairs specified by HOWMNY and SELECT. The eigenvectors */
00123 /*          must be stored in consecutive columns of VL, as returned by */
00124 /*          ZHSEIN or ZTREVC. */
00125 /*          If JOB = 'V', VL is not referenced. */
00126 
00127 /*  LDVL    (input) INTEGER */
00128 /*          The leading dimension of the array VL. */
00129 /*          LDVL >= 1; and if JOB = 'E' or 'B', LDVL >= N. */
00130 
00131 /*  VR      (input) COMPLEX*16 array, dimension (LDVR,M) */
00132 /*          If JOB = 'E' or 'B', VR must contain right eigenvectors of T */
00133 /*          (or of any Q*T*Q**H with Q unitary), corresponding to the */
00134 /*          eigenpairs specified by HOWMNY and SELECT. The eigenvectors */
00135 /*          must be stored in consecutive columns of VR, as returned by */
00136 /*          ZHSEIN or ZTREVC. */
00137 /*          If JOB = 'V', VR is not referenced. */
00138 
00139 /*  LDVR    (input) INTEGER */
00140 /*          The leading dimension of the array VR. */
00141 /*          LDVR >= 1; and if JOB = 'E' or 'B', LDVR >= N. */
00142 
00143 /*  S       (output) DOUBLE PRECISION array, dimension (MM) */
00144 /*          If JOB = 'E' or 'B', the reciprocal condition numbers of the */
00145 /*          selected eigenvalues, stored in consecutive elements of the */
00146 /*          array. Thus S(j), SEP(j), and the j-th columns of VL and VR */
00147 /*          all correspond to the same eigenpair (but not in general the */
00148 /*          j-th eigenpair, unless all eigenpairs are selected). */
00149 /*          If JOB = 'V', S is not referenced. */
00150 
00151 /*  SEP     (output) DOUBLE PRECISION array, dimension (MM) */
00152 /*          If JOB = 'V' or 'B', the estimated reciprocal condition */
00153 /*          numbers of the selected eigenvectors, stored in consecutive */
00154 /*          elements of the array. */
00155 /*          If JOB = 'E', SEP is not referenced. */
00156 
00157 /*  MM      (input) INTEGER */
00158 /*          The number of elements in the arrays S (if JOB = 'E' or 'B') */
00159 /*           and/or SEP (if JOB = 'V' or 'B'). MM >= M. */
00160 
00161 /*  M       (output) INTEGER */
00162 /*          The number of elements of the arrays S and/or SEP actually */
00163 /*          used to store the estimated condition numbers. */
00164 /*          If HOWMNY = 'A', M is set to N. */
00165 
00166 /*  WORK    (workspace) COMPLEX*16 array, dimension (LDWORK,N+6) */
00167 /*          If JOB = 'E', WORK is not referenced. */
00168 
00169 /*  LDWORK  (input) INTEGER */
00170 /*          The leading dimension of the array WORK. */
00171 /*          LDWORK >= 1; and if JOB = 'V' or 'B', LDWORK >= N. */
00172 
00173 /*  RWORK   (workspace) DOUBLE PRECISION array, dimension (N) */
00174 /*          If JOB = 'E', RWORK is not referenced. */
00175 
00176 /*  INFO    (output) INTEGER */
00177 /*          = 0: successful exit */
00178 /*          < 0: if INFO = -i, the i-th argument had an illegal value */
00179 
00180 /*  Further Details */
00181 /*  =============== */
00182 
00183 /*  The reciprocal of the condition number of an eigenvalue lambda is */
00184 /*  defined as */
00185 
00186 /*          S(lambda) = |v'*u| / (norm(u)*norm(v)) */
00187 
00188 /*  where u and v are the right and left eigenvectors of T corresponding */
00189 /*  to lambda; v' denotes the conjugate transpose of v, and norm(u) */
00190 /*  denotes the Euclidean norm. These reciprocal condition numbers always */
00191 /*  lie between zero (very badly conditioned) and one (very well */
00192 /*  conditioned). If n = 1, S(lambda) is defined to be 1. */
00193 
00194 /*  An approximate error bound for a computed eigenvalue W(i) is given by */
00195 
00196 /*                      EPS * norm(T) / S(i) */
00197 
00198 /*  where EPS is the machine precision. */
00199 
00200 /*  The reciprocal of the condition number of the right eigenvector u */
00201 /*  corresponding to lambda is defined as follows. Suppose */
00202 
00203 /*              T = ( lambda  c  ) */
00204 /*                  (   0    T22 ) */
00205 
00206 /*  Then the reciprocal condition number is */
00207 
00208 /*          SEP( lambda, T22 ) = sigma-min( T22 - lambda*I ) */
00209 
00210 /*  where sigma-min denotes the smallest singular value. We approximate */
00211 /*  the smallest singular value by the reciprocal of an estimate of the */
00212 /*  one-norm of the inverse of T22 - lambda*I. If n = 1, SEP(1) is */
00213 /*  defined to be abs(T(1,1)). */
00214 
00215 /*  An approximate error bound for a computed right eigenvector VR(i) */
00216 /*  is given by */
00217 
00218 /*                      EPS * norm(T) / SEP(i) */
00219 
00220 /*  ===================================================================== */
00221 
00222 /*     .. Parameters .. */
00223 /*     .. */
00224 /*     .. Local Scalars .. */
00225 /*     .. */
00226 /*     .. Local Arrays .. */
00227 /*     .. */
00228 /*     .. External Functions .. */
00229 /*     .. */
00230 /*     .. External Subroutines .. */
00231 /*     .. */
00232 /*     .. Intrinsic Functions .. */
00233 /*     .. */
00234 /*     .. Statement Functions .. */
00235 /*     .. */
00236 /*     .. Statement Function definitions .. */
00237 /*     .. */
00238 /*     .. Executable Statements .. */
00239 
00240 /*     Decode and test the input parameters */
00241 
00242     /* Parameter adjustments */
00243     --select;
00244     t_dim1 = *ldt;
00245     t_offset = 1 + t_dim1;
00246     t -= t_offset;
00247     vl_dim1 = *ldvl;
00248     vl_offset = 1 + vl_dim1;
00249     vl -= vl_offset;
00250     vr_dim1 = *ldvr;
00251     vr_offset = 1 + vr_dim1;
00252     vr -= vr_offset;
00253     --s;
00254     --sep;
00255     work_dim1 = *ldwork;
00256     work_offset = 1 + work_dim1;
00257     work -= work_offset;
00258     --rwork;
00259 
00260     /* Function Body */
00261     wantbh = lsame_(job, "B");
00262     wants = lsame_(job, "E") || wantbh;
00263     wantsp = lsame_(job, "V") || wantbh;
00264 
00265     somcon = lsame_(howmny, "S");
00266 
00267 /*     Set M to the number of eigenpairs for which condition numbers are */
00268 /*     to be computed. */
00269 
00270     if (somcon) {
00271         *m = 0;
00272         i__1 = *n;
00273         for (j = 1; j <= i__1; ++j) {
00274             if (select[j]) {
00275                 ++(*m);
00276             }
00277 /* L10: */
00278         }
00279     } else {
00280         *m = *n;
00281     }
00282 
00283     *info = 0;
00284     if (! wants && ! wantsp) {
00285         *info = -1;
00286     } else if (! lsame_(howmny, "A") && ! somcon) {
00287         *info = -2;
00288     } else if (*n < 0) {
00289         *info = -4;
00290     } else if (*ldt < max(1,*n)) {
00291         *info = -6;
00292     } else if (*ldvl < 1 || wants && *ldvl < *n) {
00293         *info = -8;
00294     } else if (*ldvr < 1 || wants && *ldvr < *n) {
00295         *info = -10;
00296     } else if (*mm < *m) {
00297         *info = -13;
00298     } else if (*ldwork < 1 || wantsp && *ldwork < *n) {
00299         *info = -16;
00300     }
00301     if (*info != 0) {
00302         i__1 = -(*info);
00303         xerbla_("ZTRSNA", &i__1);
00304         return 0;
00305     }
00306 
00307 /*     Quick return if possible */
00308 
00309     if (*n == 0) {
00310         return 0;
00311     }
00312 
00313     if (*n == 1) {
00314         if (somcon) {
00315             if (! select[1]) {
00316                 return 0;
00317             }
00318         }
00319         if (wants) {
00320             s[1] = 1.;
00321         }
00322         if (wantsp) {
00323             sep[1] = z_abs(&t[t_dim1 + 1]);
00324         }
00325         return 0;
00326     }
00327 
00328 /*     Get machine constants */
00329 
00330     eps = dlamch_("P");
00331     smlnum = dlamch_("S") / eps;
00332     bignum = 1. / smlnum;
00333     dlabad_(&smlnum, &bignum);
00334 
00335     ks = 1;
00336     i__1 = *n;
00337     for (k = 1; k <= i__1; ++k) {
00338 
00339         if (somcon) {
00340             if (! select[k]) {
00341                 goto L50;
00342             }
00343         }
00344 
00345         if (wants) {
00346 
00347 /*           Compute the reciprocal condition number of the k-th */
00348 /*           eigenvalue. */
00349 
00350             zdotc_(&z__1, n, &vr[ks * vr_dim1 + 1], &c__1, &vl[ks * vl_dim1 + 
00351                     1], &c__1);
00352             prod.r = z__1.r, prod.i = z__1.i;
00353             rnrm = dznrm2_(n, &vr[ks * vr_dim1 + 1], &c__1);
00354             lnrm = dznrm2_(n, &vl[ks * vl_dim1 + 1], &c__1);
00355             s[ks] = z_abs(&prod) / (rnrm * lnrm);
00356 
00357         }
00358 
00359         if (wantsp) {
00360 
00361 /*           Estimate the reciprocal condition number of the k-th */
00362 /*           eigenvector. */
00363 
00364 /*           Copy the matrix T to the array WORK and swap the k-th */
00365 /*           diagonal element to the (1,1) position. */
00366 
00367             zlacpy_("Full", n, n, &t[t_offset], ldt, &work[work_offset], 
00368                     ldwork);
00369             ztrexc_("No Q", n, &work[work_offset], ldwork, dummy, &c__1, &k, &
00370                     c__1, &ierr);
00371 
00372 /*           Form  C = T22 - lambda*I in WORK(2:N,2:N). */
00373 
00374             i__2 = *n;
00375             for (i__ = 2; i__ <= i__2; ++i__) {
00376                 i__3 = i__ + i__ * work_dim1;
00377                 i__4 = i__ + i__ * work_dim1;
00378                 i__5 = work_dim1 + 1;
00379                 z__1.r = work[i__4].r - work[i__5].r, z__1.i = work[i__4].i - 
00380                         work[i__5].i;
00381                 work[i__3].r = z__1.r, work[i__3].i = z__1.i;
00382 /* L20: */
00383             }
00384 
00385 /*           Estimate a lower bound for the 1-norm of inv(C'). The 1st */
00386 /*           and (N+1)th columns of WORK are used to store work vectors. */
00387 
00388             sep[ks] = 0.;
00389             est = 0.;
00390             kase = 0;
00391             *(unsigned char *)normin = 'N';
00392 L30:
00393             i__2 = *n - 1;
00394             zlacn2_(&i__2, &work[(*n + 1) * work_dim1 + 1], &work[work_offset]
00395 , &est, &kase, isave);
00396 
00397             if (kase != 0) {
00398                 if (kase == 1) {
00399 
00400 /*                 Solve C'*x = scale*b */
00401 
00402                     i__2 = *n - 1;
00403                     zlatrs_("Upper", "Conjugate transpose", "Nonunit", normin, 
00404                              &i__2, &work[(work_dim1 << 1) + 2], ldwork, &
00405                             work[work_offset], &scale, &rwork[1], &ierr);
00406                 } else {
00407 
00408 /*                 Solve C*x = scale*b */
00409 
00410                     i__2 = *n - 1;
00411                     zlatrs_("Upper", "No transpose", "Nonunit", normin, &i__2, 
00412                              &work[(work_dim1 << 1) + 2], ldwork, &work[
00413                             work_offset], &scale, &rwork[1], &ierr);
00414                 }
00415                 *(unsigned char *)normin = 'Y';
00416                 if (scale != 1.) {
00417 
00418 /*                 Multiply by 1/SCALE if doing so will not cause */
00419 /*                 overflow. */
00420 
00421                     i__2 = *n - 1;
00422                     ix = izamax_(&i__2, &work[work_offset], &c__1);
00423                     i__2 = ix + work_dim1;
00424                     xnorm = (d__1 = work[i__2].r, abs(d__1)) + (d__2 = d_imag(
00425                             &work[ix + work_dim1]), abs(d__2));
00426                     if (scale < xnorm * smlnum || scale == 0.) {
00427                         goto L40;
00428                     }
00429                     zdrscl_(n, &scale, &work[work_offset], &c__1);
00430                 }
00431                 goto L30;
00432             }
00433 
00434             sep[ks] = 1. / max(est,smlnum);
00435         }
00436 
00437 L40:
00438         ++ks;
00439 L50:
00440         ;
00441     }
00442     return 0;
00443 
00444 /*     End of ZTRSNA */
00445 
00446 } /* ztrsna_ */


swiftnav
Author(s):
autogenerated on Sat Jun 8 2019 18:56:44