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


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