cppsvx.c
Go to the documentation of this file.
00001 /* cppsvx.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 cppsvx_(char *fact, char *uplo, integer *n, integer *
00021         nrhs, complex *ap, complex *afp, char *equed, real *s, complex *b, 
00022         integer *ldb, complex *x, integer *ldx, real *rcond, real *ferr, real 
00023         *berr, complex *work, real *rwork, integer *info)
00024 {
00025     /* System generated locals */
00026     integer b_dim1, b_offset, x_dim1, x_offset, i__1, i__2, i__3, i__4, i__5;
00027     real r__1, r__2;
00028     complex q__1;
00029 
00030     /* Local variables */
00031     integer i__, j;
00032     real amax, smin, smax;
00033     extern logical lsame_(char *, char *);
00034     real scond, anorm;
00035     extern /* Subroutine */ int ccopy_(integer *, complex *, integer *, 
00036             complex *, integer *);
00037     logical equil, rcequ;
00038     extern doublereal clanhp_(char *, char *, integer *, complex *, real *), slamch_(char *);
00039     extern /* Subroutine */ int claqhp_(char *, integer *, complex *, real *, 
00040             real *, real *, char *);
00041     logical nofact;
00042     extern /* Subroutine */ int clacpy_(char *, integer *, integer *, complex 
00043             *, integer *, complex *, integer *), xerbla_(char *, 
00044             integer *);
00045     real bignum;
00046     extern /* Subroutine */ int cppcon_(char *, integer *, complex *, real *, 
00047             real *, complex *, real *, integer *);
00048     integer infequ;
00049     extern /* Subroutine */ int cppequ_(char *, integer *, complex *, real *, 
00050             real *, real *, integer *), cpprfs_(char *, integer *, 
00051             integer *, complex *, complex *, complex *, integer *, complex *, 
00052             integer *, real *, real *, complex *, real *, integer *), 
00053             cpptrf_(char *, integer *, complex *, integer *);
00054     real smlnum;
00055     extern /* Subroutine */ int cpptrs_(char *, integer *, integer *, complex 
00056             *, complex *, integer *, integer *);
00057 
00058 
00059 /*  -- LAPACK driver routine (version 3.2) -- */
00060 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
00061 /*     November 2006 */
00062 
00063 /*     .. Scalar Arguments .. */
00064 /*     .. */
00065 /*     .. Array Arguments .. */
00066 /*     .. */
00067 
00068 /*  Purpose */
00069 /*  ======= */
00070 
00071 /*  CPPSVX uses the Cholesky factorization A = U**H*U or A = L*L**H to */
00072 /*  compute the solution to a complex system of linear equations */
00073 /*     A * X = B, */
00074 /*  where A is an N-by-N Hermitian positive definite matrix stored in */
00075 /*  packed format and X and B are N-by-NRHS matrices. */
00076 
00077 /*  Error bounds on the solution and a condition estimate are also */
00078 /*  provided. */
00079 
00080 /*  Description */
00081 /*  =========== */
00082 
00083 /*  The following steps are performed: */
00084 
00085 /*  1. If FACT = 'E', real scaling factors are computed to equilibrate */
00086 /*     the system: */
00087 /*        diag(S) * A * diag(S) * inv(diag(S)) * X = diag(S) * B */
00088 /*     Whether or not the system will be equilibrated depends on the */
00089 /*     scaling of the matrix A, but if equilibration is used, A is */
00090 /*     overwritten by diag(S)*A*diag(S) and B by diag(S)*B. */
00091 
00092 /*  2. If FACT = 'N' or 'E', the Cholesky decomposition is used to */
00093 /*     factor the matrix A (after equilibration if FACT = 'E') as */
00094 /*        A = U'* U ,  if UPLO = 'U', or */
00095 /*        A = L * L',  if UPLO = 'L', */
00096 /*     where U is an upper triangular matrix, L is a lower triangular */
00097 /*     matrix, and ' indicates conjugate transpose. */
00098 
00099 /*  3. If the leading i-by-i principal minor is not positive definite, */
00100 /*     then the routine returns with INFO = i. Otherwise, the factored */
00101 /*     form of A is used to estimate the condition number of the matrix */
00102 /*     A.  If the reciprocal of the condition number is less than machine */
00103 /*     precision, INFO = N+1 is returned as a warning, but the routine */
00104 /*     still goes on to solve for X and compute error bounds as */
00105 /*     described below. */
00106 
00107 /*  4. The system of equations is solved for X using the factored form */
00108 /*     of A. */
00109 
00110 /*  5. Iterative refinement is applied to improve the computed solution */
00111 /*     matrix and calculate error bounds and backward error estimates */
00112 /*     for it. */
00113 
00114 /*  6. If equilibration was used, the matrix X is premultiplied by */
00115 /*     diag(S) so that it solves the original system before */
00116 /*     equilibration. */
00117 
00118 /*  Arguments */
00119 /*  ========= */
00120 
00121 /*  FACT    (input) CHARACTER*1 */
00122 /*          Specifies whether or not the factored form of the matrix A is */
00123 /*          supplied on entry, and if not, whether the matrix A should be */
00124 /*          equilibrated before it is factored. */
00125 /*          = 'F':  On entry, AFP contains the factored form of A. */
00126 /*                  If EQUED = 'Y', the matrix A has been equilibrated */
00127 /*                  with scaling factors given by S.  AP and AFP will not */
00128 /*                  be modified. */
00129 /*          = 'N':  The matrix A will be copied to AFP and factored. */
00130 /*          = 'E':  The matrix A will be equilibrated if necessary, then */
00131 /*                  copied to AFP and factored. */
00132 
00133 /*  UPLO    (input) CHARACTER*1 */
00134 /*          = 'U':  Upper triangle of A is stored; */
00135 /*          = 'L':  Lower triangle of A is stored. */
00136 
00137 /*  N       (input) INTEGER */
00138 /*          The number of linear equations, i.e., the order of the */
00139 /*          matrix A.  N >= 0. */
00140 
00141 /*  NRHS    (input) INTEGER */
00142 /*          The number of right hand sides, i.e., the number of columns */
00143 /*          of the matrices B and X.  NRHS >= 0. */
00144 
00145 /*  AP      (input/output) COMPLEX array, dimension (N*(N+1)/2) */
00146 /*          On entry, the upper or lower triangle of the Hermitian matrix */
00147 /*          A, packed columnwise in a linear array, except if FACT = 'F' */
00148 /*          and EQUED = 'Y', then A must contain the equilibrated matrix */
00149 /*          diag(S)*A*diag(S).  The j-th column of A is stored in the */
00150 /*          array AP as follows: */
00151 /*          if UPLO = 'U', AP(i + (j-1)*j/2) = A(i,j) for 1<=i<=j; */
00152 /*          if UPLO = 'L', AP(i + (j-1)*(2n-j)/2) = A(i,j) for j<=i<=n. */
00153 /*          See below for further details.  A is not modified if */
00154 /*          FACT = 'F' or 'N', or if FACT = 'E' and EQUED = 'N' on exit. */
00155 
00156 /*          On exit, if FACT = 'E' and EQUED = 'Y', A is overwritten by */
00157 /*          diag(S)*A*diag(S). */
00158 
00159 /*  AFP     (input or output) COMPLEX array, dimension (N*(N+1)/2) */
00160 /*          If FACT = 'F', then AFP is an input argument and on entry */
00161 /*          contains the triangular factor U or L from the Cholesky */
00162 /*          factorization A = U**H*U or A = L*L**H, in the same storage */
00163 /*          format as A.  If EQUED .ne. 'N', then AFP is the factored */
00164 /*          form of the equilibrated matrix A. */
00165 
00166 /*          If FACT = 'N', then AFP is an output argument and on exit */
00167 /*          returns the triangular factor U or L from the Cholesky */
00168 /*          factorization A = U**H*U or A = L*L**H of the original */
00169 /*          matrix A. */
00170 
00171 /*          If FACT = 'E', then AFP is an output argument and on exit */
00172 /*          returns the triangular factor U or L from the Cholesky */
00173 /*          factorization A = U**H*U or A = L*L**H of the equilibrated */
00174 /*          matrix A (see the description of AP for the form of the */
00175 /*          equilibrated matrix). */
00176 
00177 /*  EQUED   (input or output) CHARACTER*1 */
00178 /*          Specifies the form of equilibration that was done. */
00179 /*          = 'N':  No equilibration (always true if FACT = 'N'). */
00180 /*          = 'Y':  Equilibration was done, i.e., A has been replaced by */
00181 /*                  diag(S) * A * diag(S). */
00182 /*          EQUED is an input argument if FACT = 'F'; otherwise, it is an */
00183 /*          output argument. */
00184 
00185 /*  S       (input or output) REAL array, dimension (N) */
00186 /*          The scale factors for A; not accessed if EQUED = 'N'.  S is */
00187 /*          an input argument if FACT = 'F'; otherwise, S is an output */
00188 /*          argument.  If FACT = 'F' and EQUED = 'Y', each element of S */
00189 /*          must be positive. */
00190 
00191 /*  B       (input/output) COMPLEX array, dimension (LDB,NRHS) */
00192 /*          On entry, the N-by-NRHS right hand side matrix B. */
00193 /*          On exit, if EQUED = 'N', B is not modified; if EQUED = 'Y', */
00194 /*          B is overwritten by diag(S) * B. */
00195 
00196 /*  LDB     (input) INTEGER */
00197 /*          The leading dimension of the array B.  LDB >= max(1,N). */
00198 
00199 /*  X       (output) COMPLEX array, dimension (LDX,NRHS) */
00200 /*          If INFO = 0 or INFO = N+1, the N-by-NRHS solution matrix X to */
00201 /*          the original system of equations.  Note that if EQUED = 'Y', */
00202 /*          A and B are modified on exit, and the solution to the */
00203 /*          equilibrated system is inv(diag(S))*X. */
00204 
00205 /*  LDX     (input) INTEGER */
00206 /*          The leading dimension of the array X.  LDX >= max(1,N). */
00207 
00208 /*  RCOND   (output) REAL */
00209 /*          The estimate of the reciprocal condition number of the matrix */
00210 /*          A after equilibration (if done).  If RCOND is less than the */
00211 /*          machine precision (in particular, if RCOND = 0), the matrix */
00212 /*          is singular to working precision.  This condition is */
00213 /*          indicated by a return code of INFO > 0. */
00214 
00215 /*  FERR    (output) REAL array, dimension (NRHS) */
00216 /*          The estimated forward error bound for each solution vector */
00217 /*          X(j) (the j-th column of the solution matrix X). */
00218 /*          If XTRUE is the true solution corresponding to X(j), FERR(j) */
00219 /*          is an estimated upper bound for the magnitude of the largest */
00220 /*          element in (X(j) - XTRUE) divided by the magnitude of the */
00221 /*          largest element in X(j).  The estimate is as reliable as */
00222 /*          the estimate for RCOND, and is almost always a slight */
00223 /*          overestimate of the true error. */
00224 
00225 /*  BERR    (output) REAL array, dimension (NRHS) */
00226 /*          The componentwise relative backward error of each solution */
00227 /*          vector X(j) (i.e., the smallest relative change in */
00228 /*          any element of A or B that makes X(j) an exact solution). */
00229 
00230 /*  WORK    (workspace) COMPLEX array, dimension (2*N) */
00231 
00232 /*  RWORK   (workspace) REAL array, dimension (N) */
00233 
00234 /*  INFO    (output) INTEGER */
00235 /*          = 0:  successful exit */
00236 /*          < 0:  if INFO = -i, the i-th argument had an illegal value */
00237 /*          > 0:  if INFO = i, and i is */
00238 /*                <= N:  the leading minor of order i of A is */
00239 /*                       not positive definite, so the factorization */
00240 /*                       could not be completed, and the solution has not */
00241 /*                       been computed. RCOND = 0 is returned. */
00242 /*                = N+1: U is nonsingular, but RCOND is less than machine */
00243 /*                       precision, meaning that the matrix is singular */
00244 /*                       to working precision.  Nevertheless, the */
00245 /*                       solution and error bounds are computed because */
00246 /*                       there are a number of situations where the */
00247 /*                       computed solution can be more accurate than the */
00248 /*                       value of RCOND would suggest. */
00249 
00250 /*  Further Details */
00251 /*  =============== */
00252 
00253 /*  The packed storage scheme is illustrated by the following example */
00254 /*  when N = 4, UPLO = 'U': */
00255 
00256 /*  Two-dimensional storage of the Hermitian matrix A: */
00257 
00258 /*     a11 a12 a13 a14 */
00259 /*         a22 a23 a24 */
00260 /*             a33 a34     (aij = conjg(aji)) */
00261 /*                 a44 */
00262 
00263 /*  Packed storage of the upper triangle of A: */
00264 
00265 /*  AP = [ a11, a12, a22, a13, a23, a33, a14, a24, a34, a44 ] */
00266 
00267 /*  ===================================================================== */
00268 
00269 /*     .. Parameters .. */
00270 /*     .. */
00271 /*     .. Local Scalars .. */
00272 /*     .. */
00273 /*     .. External Functions .. */
00274 /*     .. */
00275 /*     .. External Subroutines .. */
00276 /*     .. */
00277 /*     .. Intrinsic Functions .. */
00278 /*     .. */
00279 /*     .. Executable Statements .. */
00280 
00281     /* Parameter adjustments */
00282     --ap;
00283     --afp;
00284     --s;
00285     b_dim1 = *ldb;
00286     b_offset = 1 + b_dim1;
00287     b -= b_offset;
00288     x_dim1 = *ldx;
00289     x_offset = 1 + x_dim1;
00290     x -= x_offset;
00291     --ferr;
00292     --berr;
00293     --work;
00294     --rwork;
00295 
00296     /* Function Body */
00297     *info = 0;
00298     nofact = lsame_(fact, "N");
00299     equil = lsame_(fact, "E");
00300     if (nofact || equil) {
00301         *(unsigned char *)equed = 'N';
00302         rcequ = FALSE_;
00303     } else {
00304         rcequ = lsame_(equed, "Y");
00305         smlnum = slamch_("Safe minimum");
00306         bignum = 1.f / smlnum;
00307     }
00308 
00309 /*     Test the input parameters. */
00310 
00311     if (! nofact && ! equil && ! lsame_(fact, "F")) {
00312         *info = -1;
00313     } else if (! lsame_(uplo, "U") && ! lsame_(uplo, 
00314             "L")) {
00315         *info = -2;
00316     } else if (*n < 0) {
00317         *info = -3;
00318     } else if (*nrhs < 0) {
00319         *info = -4;
00320     } else if (lsame_(fact, "F") && ! (rcequ || lsame_(
00321             equed, "N"))) {
00322         *info = -7;
00323     } else {
00324         if (rcequ) {
00325             smin = bignum;
00326             smax = 0.f;
00327             i__1 = *n;
00328             for (j = 1; j <= i__1; ++j) {
00329 /* Computing MIN */
00330                 r__1 = smin, r__2 = s[j];
00331                 smin = dmin(r__1,r__2);
00332 /* Computing MAX */
00333                 r__1 = smax, r__2 = s[j];
00334                 smax = dmax(r__1,r__2);
00335 /* L10: */
00336             }
00337             if (smin <= 0.f) {
00338                 *info = -8;
00339             } else if (*n > 0) {
00340                 scond = dmax(smin,smlnum) / dmin(smax,bignum);
00341             } else {
00342                 scond = 1.f;
00343             }
00344         }
00345         if (*info == 0) {
00346             if (*ldb < max(1,*n)) {
00347                 *info = -10;
00348             } else if (*ldx < max(1,*n)) {
00349                 *info = -12;
00350             }
00351         }
00352     }
00353 
00354     if (*info != 0) {
00355         i__1 = -(*info);
00356         xerbla_("CPPSVX", &i__1);
00357         return 0;
00358     }
00359 
00360     if (equil) {
00361 
00362 /*        Compute row and column scalings to equilibrate the matrix A. */
00363 
00364         cppequ_(uplo, n, &ap[1], &s[1], &scond, &amax, &infequ);
00365         if (infequ == 0) {
00366 
00367 /*           Equilibrate the matrix. */
00368 
00369             claqhp_(uplo, n, &ap[1], &s[1], &scond, &amax, equed);
00370             rcequ = lsame_(equed, "Y");
00371         }
00372     }
00373 
00374 /*     Scale the right-hand side. */
00375 
00376     if (rcequ) {
00377         i__1 = *nrhs;
00378         for (j = 1; j <= i__1; ++j) {
00379             i__2 = *n;
00380             for (i__ = 1; i__ <= i__2; ++i__) {
00381                 i__3 = i__ + j * b_dim1;
00382                 i__4 = i__;
00383                 i__5 = i__ + j * b_dim1;
00384                 q__1.r = s[i__4] * b[i__5].r, q__1.i = s[i__4] * b[i__5].i;
00385                 b[i__3].r = q__1.r, b[i__3].i = q__1.i;
00386 /* L20: */
00387             }
00388 /* L30: */
00389         }
00390     }
00391 
00392     if (nofact || equil) {
00393 
00394 /*        Compute the Cholesky factorization A = U'*U or A = L*L'. */
00395 
00396         i__1 = *n * (*n + 1) / 2;
00397         ccopy_(&i__1, &ap[1], &c__1, &afp[1], &c__1);
00398         cpptrf_(uplo, n, &afp[1], info);
00399 
00400 /*        Return if INFO is non-zero. */
00401 
00402         if (*info > 0) {
00403             *rcond = 0.f;
00404             return 0;
00405         }
00406     }
00407 
00408 /*     Compute the norm of the matrix A. */
00409 
00410     anorm = clanhp_("I", uplo, n, &ap[1], &rwork[1]);
00411 
00412 /*     Compute the reciprocal of the condition number of A. */
00413 
00414     cppcon_(uplo, n, &afp[1], &anorm, rcond, &work[1], &rwork[1], info);
00415 
00416 /*     Compute the solution matrix X. */
00417 
00418     clacpy_("Full", n, nrhs, &b[b_offset], ldb, &x[x_offset], ldx);
00419     cpptrs_(uplo, n, nrhs, &afp[1], &x[x_offset], ldx, info);
00420 
00421 /*     Use iterative refinement to improve the computed solution and */
00422 /*     compute error bounds and backward error estimates for it. */
00423 
00424     cpprfs_(uplo, n, nrhs, &ap[1], &afp[1], &b[b_offset], ldb, &x[x_offset], 
00425             ldx, &ferr[1], &berr[1], &work[1], &rwork[1], info);
00426 
00427 /*     Transform the solution matrix X to a solution of the original */
00428 /*     system. */
00429 
00430     if (rcequ) {
00431         i__1 = *nrhs;
00432         for (j = 1; j <= i__1; ++j) {
00433             i__2 = *n;
00434             for (i__ = 1; i__ <= i__2; ++i__) {
00435                 i__3 = i__ + j * x_dim1;
00436                 i__4 = i__;
00437                 i__5 = i__ + j * x_dim1;
00438                 q__1.r = s[i__4] * x[i__5].r, q__1.i = s[i__4] * x[i__5].i;
00439                 x[i__3].r = q__1.r, x[i__3].i = q__1.i;
00440 /* L40: */
00441             }
00442 /* L50: */
00443         }
00444         i__1 = *nrhs;
00445         for (j = 1; j <= i__1; ++j) {
00446             ferr[j] /= scond;
00447 /* L60: */
00448         }
00449     }
00450 
00451 /*     Set INFO = N+1 if the matrix is singular to working precision. */
00452 
00453     if (*rcond < slamch_("Epsilon")) {
00454         *info = *n + 1;
00455     }
00456 
00457     return 0;
00458 
00459 /*     End of CPPSVX */
00460 
00461 } /* cppsvx_ */


swiftnav
Author(s):
autogenerated on Sat Jun 8 2019 18:55:33