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


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