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


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