dpstrf.c
Go to the documentation of this file.
00001 /* dpstrf.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 static integer c_n1 = -1;
00020 static doublereal c_b22 = -1.;
00021 static doublereal c_b24 = 1.;
00022 
00023 /* Subroutine */ int dpstrf_(char *uplo, integer *n, doublereal *a, integer *
00024         lda, integer *piv, integer *rank, doublereal *tol, doublereal *work, 
00025         integer *info)
00026 {
00027     /* System generated locals */
00028     integer a_dim1, a_offset, i__1, i__2, i__3, i__4, i__5;
00029     doublereal d__1;
00030 
00031     /* Builtin functions */
00032     double sqrt(doublereal);
00033 
00034     /* Local variables */
00035     integer i__, j, k, maxlocvar, jb, nb;
00036     doublereal ajj;
00037     integer pvt;
00038     extern /* Subroutine */ int dscal_(integer *, doublereal *, doublereal *, 
00039             integer *);
00040     extern logical lsame_(char *, char *);
00041     extern /* Subroutine */ int dgemv_(char *, integer *, integer *, 
00042             doublereal *, doublereal *, integer *, doublereal *, integer *, 
00043             doublereal *, doublereal *, integer *);
00044     doublereal dtemp;
00045     integer itemp;
00046     extern /* Subroutine */ int dswap_(integer *, doublereal *, integer *, 
00047             doublereal *, integer *);
00048     doublereal dstop;
00049     logical upper;
00050     extern /* Subroutine */ int dsyrk_(char *, char *, integer *, integer *, 
00051             doublereal *, doublereal *, integer *, doublereal *, doublereal *, 
00052              integer *), dpstf2_(char *, integer *, 
00053             doublereal *, integer *, integer *, integer *, doublereal *, 
00054             doublereal *, integer *);
00055     extern doublereal dlamch_(char *);
00056     extern logical disnan_(doublereal *);
00057     extern /* Subroutine */ int xerbla_(char *, integer *);
00058     extern integer ilaenv_(integer *, char *, char *, integer *, integer *, 
00059             integer *, integer *);
00060     extern integer dmaxloc_(doublereal *, integer *);
00061 
00062 
00063 /*  -- LAPACK routine (version 3.2) -- */
00064 /*     Craig Lucas, University of Manchester / NAG Ltd. */
00065 /*     October, 2008 */
00066 
00067 /*     .. Scalar Arguments .. */
00068 /*     .. */
00069 /*     .. Array Arguments .. */
00070 /*     .. */
00071 
00072 /*  Purpose */
00073 /*  ======= */
00074 
00075 /*  DPSTRF computes the Cholesky factorization with complete */
00076 /*  pivoting of a real symmetric positive semidefinite matrix A. */
00077 
00078 /*  The factorization has the form */
00079 /*     P' * A * P = U' * U ,  if UPLO = 'U', */
00080 /*     P' * A * P = L  * L',  if UPLO = 'L', */
00081 /*  where U is an upper triangular matrix and L is lower triangular, and */
00082 /*  P is stored as vector PIV. */
00083 
00084 /*  This algorithm does not attempt to check that A is positive */
00085 /*  semidefinite. This version of the algorithm calls level 3 BLAS. */
00086 
00087 /*  Arguments */
00088 /*  ========= */
00089 
00090 /*  UPLO    (input) CHARACTER*1 */
00091 /*          Specifies whether the upper or lower triangular part of the */
00092 /*          symmetric matrix A is stored. */
00093 /*          = 'U':  Upper triangular */
00094 /*          = 'L':  Lower triangular */
00095 
00096 /*  N       (input) INTEGER */
00097 /*          The order of the matrix A.  N >= 0. */
00098 
00099 /*  A       (input/output) DOUBLE PRECISION array, dimension (LDA,N) */
00100 /*          On entry, the symmetric matrix A.  If UPLO = 'U', the leading */
00101 /*          n by n upper triangular part of A contains the upper */
00102 /*          triangular part of the matrix A, and the strictly lower */
00103 /*          triangular part of A is not referenced.  If UPLO = 'L', the */
00104 /*          leading n by n lower triangular part of A contains the lower */
00105 /*          triangular part of the matrix A, and the strictly upper */
00106 /*          triangular part of A is not referenced. */
00107 
00108 /*          On exit, if INFO = 0, the factor U or L from the Cholesky */
00109 /*          factorization as above. */
00110 
00111 /*  LDA     (input) INTEGER */
00112 /*          The leading dimension of the array A.  LDA >= max(1,N). */
00113 
00114 /*  PIV     (output) INTEGER array, dimension (N) */
00115 /*          PIV is such that the nonzero entries are P( PIV(K), K ) = 1. */
00116 
00117 /*  RANK    (output) INTEGER */
00118 /*          The rank of A given by the number of steps the algorithm */
00119 /*          completed. */
00120 
00121 /*  TOL     (input) DOUBLE PRECISION */
00122 /*          User defined tolerance. If TOL < 0, then N*U*MAX( A(K,K) ) */
00123 /*          will be used. The algorithm terminates at the (K-1)st step */
00124 /*          if the pivot <= TOL. */
00125 
00126 /*  WORK    DOUBLE PRECISION array, dimension (2*N) */
00127 /*          Work space. */
00128 
00129 /*  INFO    (output) INTEGER */
00130 /*          < 0: If INFO = -K, the K-th argument had an illegal value, */
00131 /*          = 0: algorithm completed successfully, and */
00132 /*          > 0: the matrix A is either rank deficient with computed rank */
00133 /*               as returned in RANK, or is indefinite.  See Section 7 of */
00134 /*               LAPACK Working Note #161 for further information. */
00135 
00136 /*  ===================================================================== */
00137 
00138 /*     .. Parameters .. */
00139 /*     .. */
00140 /*     .. Local Scalars .. */
00141 /*     .. */
00142 /*     .. External Functions .. */
00143 /*     .. */
00144 /*     .. External Subroutines .. */
00145 /*     .. */
00146 /*     .. Intrinsic Functions .. */
00147 /*     .. */
00148 /*     .. Executable Statements .. */
00149 
00150 /*     Test the input parameters. */
00151 
00152     /* Parameter adjustments */
00153     --work;
00154     --piv;
00155     a_dim1 = *lda;
00156     a_offset = 1 + a_dim1;
00157     a -= a_offset;
00158 
00159     /* Function Body */
00160     *info = 0;
00161     upper = lsame_(uplo, "U");
00162     if (! upper && ! lsame_(uplo, "L")) {
00163         *info = -1;
00164     } else if (*n < 0) {
00165         *info = -2;
00166     } else if (*lda < max(1,*n)) {
00167         *info = -4;
00168     }
00169     if (*info != 0) {
00170         i__1 = -(*info);
00171         xerbla_("DPSTRF", &i__1);
00172         return 0;
00173     }
00174 
00175 /*     Quick return if possible */
00176 
00177     if (*n == 0) {
00178         return 0;
00179     }
00180 
00181 /*     Get block size */
00182 
00183     nb = ilaenv_(&c__1, "DPOTRF", uplo, n, &c_n1, &c_n1, &c_n1);
00184     if (nb <= 1 || nb >= *n) {
00185 
00186 /*        Use unblocked code */
00187 
00188         dpstf2_(uplo, n, &a[a_dim1 + 1], lda, &piv[1], rank, tol, &work[1], 
00189                 info);
00190         goto L200;
00191 
00192     } else {
00193 
00194 /*     Initialize PIV */
00195 
00196         i__1 = *n;
00197         for (i__ = 1; i__ <= i__1; ++i__) {
00198             piv[i__] = i__;
00199 /* L100: */
00200         }
00201 
00202 /*     Compute stopping value */
00203 
00204         pvt = 1;
00205         ajj = a[pvt + pvt * a_dim1];
00206         i__1 = *n;
00207         for (i__ = 2; i__ <= i__1; ++i__) {
00208             if (a[i__ + i__ * a_dim1] > ajj) {
00209                 pvt = i__;
00210                 ajj = a[pvt + pvt * a_dim1];
00211             }
00212         }
00213         if (ajj == 0. || disnan_(&ajj)) {
00214             *rank = 0;
00215             *info = 1;
00216             goto L200;
00217         }
00218 
00219 /*     Compute stopping value if not supplied */
00220 
00221         if (*tol < 0.) {
00222             dstop = *n * dlamch_("Epsilon") * ajj;
00223         } else {
00224             dstop = *tol;
00225         }
00226 
00227 
00228         if (upper) {
00229 
00230 /*           Compute the Cholesky factorization P' * A * P = U' * U */
00231 
00232             i__1 = *n;
00233             i__2 = nb;
00234             for (k = 1; i__2 < 0 ? k >= i__1 : k <= i__1; k += i__2) {
00235 
00236 /*              Account for last block not being NB wide */
00237 
00238 /* Computing MIN */
00239                 i__3 = nb, i__4 = *n - k + 1;
00240                 jb = min(i__3,i__4);
00241 
00242 /*              Set relevant part of first half of WORK to zero, */
00243 /*              holds dot products */
00244 
00245                 i__3 = *n;
00246                 for (i__ = k; i__ <= i__3; ++i__) {
00247                     work[i__] = 0.;
00248 /* L110: */
00249                 }
00250 
00251                 i__3 = k + jb - 1;
00252                 for (j = k; j <= i__3; ++j) {
00253 
00254 /*              Find pivot, test for exit, else swap rows and columns */
00255 /*              Update dot products, compute possible pivots which are */
00256 /*              stored in the second half of WORK */
00257 
00258                     i__4 = *n;
00259                     for (i__ = j; i__ <= i__4; ++i__) {
00260 
00261                         if (j > k) {
00262 /* Computing 2nd power */
00263                             d__1 = a[j - 1 + i__ * a_dim1];
00264                             work[i__] += d__1 * d__1;
00265                         }
00266                         work[*n + i__] = a[i__ + i__ * a_dim1] - work[i__];
00267 
00268 /* L120: */
00269                     }
00270 
00271                     if (j > 1) {
00272                         maxlocvar = (*n << 1) - (*n + j) + 1;
00273                         itemp = dmaxloc_(&work[*n + j], &maxlocvar);
00274                         pvt = itemp + j - 1;
00275                         ajj = work[*n + pvt];
00276                         if (ajj <= dstop || disnan_(&ajj)) {
00277                             a[j + j * a_dim1] = ajj;
00278                             goto L190;
00279                         }
00280                     }
00281 
00282                     if (j != pvt) {
00283 
00284 /*                    Pivot OK, so can now swap pivot rows and columns */
00285 
00286                         a[pvt + pvt * a_dim1] = a[j + j * a_dim1];
00287                         i__4 = j - 1;
00288                         dswap_(&i__4, &a[j * a_dim1 + 1], &c__1, &a[pvt * 
00289                                 a_dim1 + 1], &c__1);
00290                         if (pvt < *n) {
00291                             i__4 = *n - pvt;
00292                             dswap_(&i__4, &a[j + (pvt + 1) * a_dim1], lda, &a[
00293                                     pvt + (pvt + 1) * a_dim1], lda);
00294                         }
00295                         i__4 = pvt - j - 1;
00296                         dswap_(&i__4, &a[j + (j + 1) * a_dim1], lda, &a[j + 1 
00297                                 + pvt * a_dim1], &c__1);
00298 
00299 /*                    Swap dot products and PIV */
00300 
00301                         dtemp = work[j];
00302                         work[j] = work[pvt];
00303                         work[pvt] = dtemp;
00304                         itemp = piv[pvt];
00305                         piv[pvt] = piv[j];
00306                         piv[j] = itemp;
00307                     }
00308 
00309                     ajj = sqrt(ajj);
00310                     a[j + j * a_dim1] = ajj;
00311 
00312 /*                 Compute elements J+1:N of row J. */
00313 
00314                     if (j < *n) {
00315                         i__4 = j - k;
00316                         i__5 = *n - j;
00317                         dgemv_("Trans", &i__4, &i__5, &c_b22, &a[k + (j + 1) *
00318                                  a_dim1], lda, &a[k + j * a_dim1], &c__1, &
00319                                 c_b24, &a[j + (j + 1) * a_dim1], lda);
00320                         i__4 = *n - j;
00321                         d__1 = 1. / ajj;
00322                         dscal_(&i__4, &d__1, &a[j + (j + 1) * a_dim1], lda);
00323                     }
00324 
00325 /* L130: */
00326                 }
00327 
00328 /*              Update trailing matrix, J already incremented */
00329 
00330                 if (k + jb <= *n) {
00331                     i__3 = *n - j + 1;
00332                     dsyrk_("Upper", "Trans", &i__3, &jb, &c_b22, &a[k + j * 
00333                             a_dim1], lda, &c_b24, &a[j + j * a_dim1], lda);
00334                 }
00335 
00336 /* L140: */
00337             }
00338 
00339         } else {
00340 
00341 /*        Compute the Cholesky factorization P' * A * P = L * L' */
00342 
00343             i__2 = *n;
00344             i__1 = nb;
00345             for (k = 1; i__1 < 0 ? k >= i__2 : k <= i__2; k += i__1) {
00346 
00347 /*              Account for last block not being NB wide */
00348 
00349 /* Computing MIN */
00350                 i__3 = nb, i__4 = *n - k + 1;
00351                 jb = min(i__3,i__4);
00352 
00353 /*              Set relevant part of first half of WORK to zero, */
00354 /*              holds dot products */
00355 
00356                 i__3 = *n;
00357                 for (i__ = k; i__ <= i__3; ++i__) {
00358                     work[i__] = 0.;
00359 /* L150: */
00360                 }
00361 
00362                 i__3 = k + jb - 1;
00363                 for (j = k; j <= i__3; ++j) {
00364 
00365 /*              Find pivot, test for exit, else swap rows and columns */
00366 /*              Update dot products, compute possible pivots which are */
00367 /*              stored in the second half of WORK */
00368 
00369                     i__4 = *n;
00370                     for (i__ = j; i__ <= i__4; ++i__) {
00371 
00372                         if (j > k) {
00373 /* Computing 2nd power */
00374                             d__1 = a[i__ + (j - 1) * a_dim1];
00375                             work[i__] += d__1 * d__1;
00376                         }
00377                         work[*n + i__] = a[i__ + i__ * a_dim1] - work[i__];
00378 
00379 /* L160: */
00380                     }
00381 
00382                     if (j > 1) {
00383                         maxlocvar = (*n << 1) - (*n + j) + 1;
00384                         itemp = dmaxloc_(&work[*n + j], &maxlocvar);
00385                         pvt = itemp + j - 1;
00386                         ajj = work[*n + pvt];
00387                         if (ajj <= dstop || disnan_(&ajj)) {
00388                             a[j + j * a_dim1] = ajj;
00389                             goto L190;
00390                         }
00391                     }
00392 
00393                     if (j != pvt) {
00394 
00395 /*                    Pivot OK, so can now swap pivot rows and columns */
00396 
00397                         a[pvt + pvt * a_dim1] = a[j + j * a_dim1];
00398                         i__4 = j - 1;
00399                         dswap_(&i__4, &a[j + a_dim1], lda, &a[pvt + a_dim1], 
00400                                 lda);
00401                         if (pvt < *n) {
00402                             i__4 = *n - pvt;
00403                             dswap_(&i__4, &a[pvt + 1 + j * a_dim1], &c__1, &a[
00404                                     pvt + 1 + pvt * a_dim1], &c__1);
00405                         }
00406                         i__4 = pvt - j - 1;
00407                         dswap_(&i__4, &a[j + 1 + j * a_dim1], &c__1, &a[pvt + 
00408                                 (j + 1) * a_dim1], lda);
00409 
00410 /*                    Swap dot products and PIV */
00411 
00412                         dtemp = work[j];
00413                         work[j] = work[pvt];
00414                         work[pvt] = dtemp;
00415                         itemp = piv[pvt];
00416                         piv[pvt] = piv[j];
00417                         piv[j] = itemp;
00418                     }
00419 
00420                     ajj = sqrt(ajj);
00421                     a[j + j * a_dim1] = ajj;
00422 
00423 /*                 Compute elements J+1:N of column J. */
00424 
00425                     if (j < *n) {
00426                         i__4 = *n - j;
00427                         i__5 = j - k;
00428                         dgemv_("No Trans", &i__4, &i__5, &c_b22, &a[j + 1 + k 
00429                                 * a_dim1], lda, &a[j + k * a_dim1], lda, &
00430                                 c_b24, &a[j + 1 + j * a_dim1], &c__1);
00431                         i__4 = *n - j;
00432                         d__1 = 1. / ajj;
00433                         dscal_(&i__4, &d__1, &a[j + 1 + j * a_dim1], &c__1);
00434                     }
00435 
00436 /* L170: */
00437                 }
00438 
00439 /*              Update trailing matrix, J already incremented */
00440 
00441                 if (k + jb <= *n) {
00442                     i__3 = *n - j + 1;
00443                     dsyrk_("Lower", "No Trans", &i__3, &jb, &c_b22, &a[j + k *
00444                              a_dim1], lda, &c_b24, &a[j + j * a_dim1], lda);
00445                 }
00446 
00447 /* L180: */
00448             }
00449 
00450         }
00451     }
00452 
00453 /*     Ran to completion, A has full rank */
00454 
00455     *rank = *n;
00456 
00457     goto L200;
00458 L190:
00459 
00460 /*     Rank is the number of steps completed.  Set INFO = 1 to signal */
00461 /*     that the factorization cannot be used to solve a system. */
00462 
00463     *rank = j - 1;
00464     *info = 1;
00465 
00466 L200:
00467     return 0;
00468 
00469 /*     End of DPSTRF */
00470 
00471 } /* dpstrf_ */


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