dpotf2.c
Go to the documentation of this file.
00001 /* dpotf2.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 doublereal c_b10 = -1.;
00020 static doublereal c_b12 = 1.;
00021 
00022 /* Subroutine */ int dpotf2_(char *uplo, integer *n, doublereal *a, integer *
00023         lda, integer *info)
00024 {
00025     /* System generated locals */
00026     integer a_dim1, a_offset, i__1, i__2, i__3;
00027     doublereal d__1;
00028 
00029     /* Builtin functions */
00030     double sqrt(doublereal);
00031 
00032     /* Local variables */
00033     integer j;
00034     doublereal ajj;
00035     extern doublereal ddot_(integer *, doublereal *, integer *, doublereal *, 
00036             integer *);
00037     extern /* Subroutine */ int dscal_(integer *, doublereal *, doublereal *, 
00038             integer *);
00039     extern logical lsame_(char *, char *);
00040     extern /* Subroutine */ int dgemv_(char *, integer *, integer *, 
00041             doublereal *, doublereal *, integer *, doublereal *, integer *, 
00042             doublereal *, doublereal *, integer *);
00043     logical upper;
00044     extern logical disnan_(doublereal *);
00045     extern /* Subroutine */ int xerbla_(char *, integer *);
00046 
00047 
00048 /*  -- LAPACK routine (version 3.2) -- */
00049 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
00050 /*     November 2006 */
00051 
00052 /*     .. Scalar Arguments .. */
00053 /*     .. */
00054 /*     .. Array Arguments .. */
00055 /*     .. */
00056 
00057 /*  Purpose */
00058 /*  ======= */
00059 
00060 /*  DPOTF2 computes the Cholesky factorization of a real symmetric */
00061 /*  positive definite matrix A. */
00062 
00063 /*  The factorization has the form */
00064 /*     A = U' * U ,  if UPLO = 'U', or */
00065 /*     A = L  * L',  if UPLO = 'L', */
00066 /*  where U is an upper triangular matrix and L is lower triangular. */
00067 
00068 /*  This is the unblocked version of the algorithm, calling Level 2 BLAS. */
00069 
00070 /*  Arguments */
00071 /*  ========= */
00072 
00073 /*  UPLO    (input) CHARACTER*1 */
00074 /*          Specifies whether the upper or lower triangular part of the */
00075 /*          symmetric matrix A is stored. */
00076 /*          = 'U':  Upper triangular */
00077 /*          = 'L':  Lower triangular */
00078 
00079 /*  N       (input) INTEGER */
00080 /*          The order of the matrix A.  N >= 0. */
00081 
00082 /*  A       (input/output) DOUBLE PRECISION array, dimension (LDA,N) */
00083 /*          On entry, the symmetric matrix A.  If UPLO = 'U', the leading */
00084 /*          n by n upper triangular part of A contains the upper */
00085 /*          triangular part of the matrix A, and the strictly lower */
00086 /*          triangular part of A is not referenced.  If UPLO = 'L', the */
00087 /*          leading n by n lower triangular part of A contains the lower */
00088 /*          triangular part of the matrix A, and the strictly upper */
00089 /*          triangular part of A is not referenced. */
00090 
00091 /*          On exit, if INFO = 0, the factor U or L from the Cholesky */
00092 /*          factorization A = U'*U  or A = L*L'. */
00093 
00094 /*  LDA     (input) INTEGER */
00095 /*          The leading dimension of the array A.  LDA >= max(1,N). */
00096 
00097 /*  INFO    (output) INTEGER */
00098 /*          = 0: successful exit */
00099 /*          < 0: if INFO = -k, the k-th argument had an illegal value */
00100 /*          > 0: if INFO = k, the leading minor of order k is not */
00101 /*               positive definite, and the factorization could not be */
00102 /*               completed. */
00103 
00104 /*  ===================================================================== */
00105 
00106 /*     .. Parameters .. */
00107 /*     .. */
00108 /*     .. Local Scalars .. */
00109 /*     .. */
00110 /*     .. External Functions .. */
00111 /*     .. */
00112 /*     .. External Subroutines .. */
00113 /*     .. */
00114 /*     .. Intrinsic Functions .. */
00115 /*     .. */
00116 /*     .. Executable Statements .. */
00117 
00118 /*     Test the input parameters. */
00119 
00120     /* Parameter adjustments */
00121     a_dim1 = *lda;
00122     a_offset = 1 + a_dim1;
00123     a -= a_offset;
00124 
00125     /* Function Body */
00126     *info = 0;
00127     upper = lsame_(uplo, "U");
00128     if (! upper && ! lsame_(uplo, "L")) {
00129         *info = -1;
00130     } else if (*n < 0) {
00131         *info = -2;
00132     } else if (*lda < max(1,*n)) {
00133         *info = -4;
00134     }
00135     if (*info != 0) {
00136         i__1 = -(*info);
00137         xerbla_("DPOTF2", &i__1);
00138         return 0;
00139     }
00140 
00141 /*     Quick return if possible */
00142 
00143     if (*n == 0) {
00144         return 0;
00145     }
00146 
00147     if (upper) {
00148 
00149 /*        Compute the Cholesky factorization A = U'*U. */
00150 
00151         i__1 = *n;
00152         for (j = 1; j <= i__1; ++j) {
00153 
00154 /*           Compute U(J,J) and test for non-positive-definiteness. */
00155 
00156             i__2 = j - 1;
00157             ajj = a[j + j * a_dim1] - ddot_(&i__2, &a[j * a_dim1 + 1], &c__1, 
00158                     &a[j * a_dim1 + 1], &c__1);
00159             if (ajj <= 0. || disnan_(&ajj)) {
00160                 a[j + j * a_dim1] = ajj;
00161                 goto L30;
00162             }
00163             ajj = sqrt(ajj);
00164             a[j + j * a_dim1] = ajj;
00165 
00166 /*           Compute elements J+1:N of row J. */
00167 
00168             if (j < *n) {
00169                 i__2 = j - 1;
00170                 i__3 = *n - j;
00171                 dgemv_("Transpose", &i__2, &i__3, &c_b10, &a[(j + 1) * a_dim1 
00172                         + 1], lda, &a[j * a_dim1 + 1], &c__1, &c_b12, &a[j + (
00173                         j + 1) * a_dim1], lda);
00174                 i__2 = *n - j;
00175                 d__1 = 1. / ajj;
00176                 dscal_(&i__2, &d__1, &a[j + (j + 1) * a_dim1], lda);
00177             }
00178 /* L10: */
00179         }
00180     } else {
00181 
00182 /*        Compute the Cholesky factorization A = L*L'. */
00183 
00184         i__1 = *n;
00185         for (j = 1; j <= i__1; ++j) {
00186 
00187 /*           Compute L(J,J) and test for non-positive-definiteness. */
00188 
00189             i__2 = j - 1;
00190             ajj = a[j + j * a_dim1] - ddot_(&i__2, &a[j + a_dim1], lda, &a[j 
00191                     + a_dim1], lda);
00192             if (ajj <= 0. || disnan_(&ajj)) {
00193                 a[j + j * a_dim1] = ajj;
00194                 goto L30;
00195             }
00196             ajj = sqrt(ajj);
00197             a[j + j * a_dim1] = ajj;
00198 
00199 /*           Compute elements J+1:N of column J. */
00200 
00201             if (j < *n) {
00202                 i__2 = *n - j;
00203                 i__3 = j - 1;
00204                 dgemv_("No transpose", &i__2, &i__3, &c_b10, &a[j + 1 + 
00205                         a_dim1], lda, &a[j + a_dim1], lda, &c_b12, &a[j + 1 + 
00206                         j * a_dim1], &c__1);
00207                 i__2 = *n - j;
00208                 d__1 = 1. / ajj;
00209                 dscal_(&i__2, &d__1, &a[j + 1 + j * a_dim1], &c__1);
00210             }
00211 /* L20: */
00212         }
00213     }
00214     goto L40;
00215 
00216 L30:
00217     *info = j;
00218 
00219 L40:
00220     return 0;
00221 
00222 /*     End of DPOTF2 */
00223 
00224 } /* dpotf2_ */


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