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


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