00001 /* spptrf.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_b16 = -1.f; 00020 00021 /* Subroutine */ int spptrf_(char *uplo, integer *n, real *ap, integer *info) 00022 { 00023 /* System generated locals */ 00024 integer i__1, i__2; 00025 real r__1; 00026 00027 /* Builtin functions */ 00028 double sqrt(doublereal); 00029 00030 /* Local variables */ 00031 integer j, jc, jj; 00032 real ajj; 00033 extern doublereal sdot_(integer *, real *, integer *, real *, integer *); 00034 extern /* Subroutine */ int sspr_(char *, integer *, real *, real *, 00035 integer *, real *); 00036 extern logical lsame_(char *, char *); 00037 extern /* Subroutine */ int sscal_(integer *, real *, real *, integer *); 00038 logical upper; 00039 extern /* Subroutine */ int stpsv_(char *, char *, char *, integer *, 00040 real *, real *, integer *), xerbla_(char * 00041 , integer *); 00042 00043 00044 /* -- LAPACK routine (version 3.2) -- */ 00045 /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */ 00046 /* November 2006 */ 00047 00048 /* .. Scalar Arguments .. */ 00049 /* .. */ 00050 /* .. Array Arguments .. */ 00051 /* .. */ 00052 00053 /* Purpose */ 00054 /* ======= */ 00055 00056 /* SPPTRF computes the Cholesky factorization of a real symmetric */ 00057 /* positive definite matrix A stored in packed format. */ 00058 00059 /* The factorization has the form */ 00060 /* A = U**T * U, if UPLO = 'U', or */ 00061 /* A = L * L**T, if UPLO = 'L', */ 00062 /* where U is an upper triangular matrix and L is lower triangular. */ 00063 00064 /* Arguments */ 00065 /* ========= */ 00066 00067 /* UPLO (input) CHARACTER*1 */ 00068 /* = 'U': Upper triangle of A is stored; */ 00069 /* = 'L': Lower triangle of A is stored. */ 00070 00071 /* N (input) INTEGER */ 00072 /* The order of the matrix A. N >= 0. */ 00073 00074 /* AP (input/output) REAL array, dimension (N*(N+1)/2) */ 00075 /* On entry, the upper or lower triangle of the symmetric matrix */ 00076 /* A, packed columnwise in a linear array. The j-th column of A */ 00077 /* is stored in the array AP as follows: */ 00078 /* if UPLO = 'U', AP(i + (j-1)*j/2) = A(i,j) for 1<=i<=j; */ 00079 /* if UPLO = 'L', AP(i + (j-1)*(2n-j)/2) = A(i,j) for j<=i<=n. */ 00080 /* See below for further details. */ 00081 00082 /* On exit, if INFO = 0, the triangular factor U or L from the */ 00083 /* Cholesky factorization A = U**T*U or A = L*L**T, in the same */ 00084 /* storage format as A. */ 00085 00086 /* INFO (output) INTEGER */ 00087 /* = 0: successful exit */ 00088 /* < 0: if INFO = -i, the i-th argument had an illegal value */ 00089 /* > 0: if INFO = i, the leading minor of order i is not */ 00090 /* positive definite, and the factorization could not be */ 00091 /* completed. */ 00092 00093 /* Further Details */ 00094 /* ======= ======= */ 00095 00096 /* The packed storage scheme is illustrated by the following example */ 00097 /* when N = 4, UPLO = 'U': */ 00098 00099 /* Two-dimensional storage of the symmetric matrix A: */ 00100 00101 /* a11 a12 a13 a14 */ 00102 /* a22 a23 a24 */ 00103 /* a33 a34 (aij = aji) */ 00104 /* a44 */ 00105 00106 /* Packed storage of the upper triangle of A: */ 00107 00108 /* AP = [ a11, a12, a22, a13, a23, a33, a14, a24, a34, a44 ] */ 00109 00110 /* ===================================================================== */ 00111 00112 /* .. Parameters .. */ 00113 /* .. */ 00114 /* .. Local Scalars .. */ 00115 /* .. */ 00116 /* .. External Functions .. */ 00117 /* .. */ 00118 /* .. External Subroutines .. */ 00119 /* .. */ 00120 /* .. Intrinsic Functions .. */ 00121 /* .. */ 00122 /* .. Executable Statements .. */ 00123 00124 /* Test the input parameters. */ 00125 00126 /* Parameter adjustments */ 00127 --ap; 00128 00129 /* Function Body */ 00130 *info = 0; 00131 upper = lsame_(uplo, "U"); 00132 if (! upper && ! lsame_(uplo, "L")) { 00133 *info = -1; 00134 } else if (*n < 0) { 00135 *info = -2; 00136 } 00137 if (*info != 0) { 00138 i__1 = -(*info); 00139 xerbla_("SPPTRF", &i__1); 00140 return 0; 00141 } 00142 00143 /* Quick return if possible */ 00144 00145 if (*n == 0) { 00146 return 0; 00147 } 00148 00149 if (upper) { 00150 00151 /* Compute the Cholesky factorization A = U'*U. */ 00152 00153 jj = 0; 00154 i__1 = *n; 00155 for (j = 1; j <= i__1; ++j) { 00156 jc = jj + 1; 00157 jj += j; 00158 00159 /* Compute elements 1:J-1 of column J. */ 00160 00161 if (j > 1) { 00162 i__2 = j - 1; 00163 stpsv_("Upper", "Transpose", "Non-unit", &i__2, &ap[1], &ap[ 00164 jc], &c__1); 00165 } 00166 00167 /* Compute U(J,J) and test for non-positive-definiteness. */ 00168 00169 i__2 = j - 1; 00170 ajj = ap[jj] - sdot_(&i__2, &ap[jc], &c__1, &ap[jc], &c__1); 00171 if (ajj <= 0.f) { 00172 ap[jj] = ajj; 00173 goto L30; 00174 } 00175 ap[jj] = sqrt(ajj); 00176 /* L10: */ 00177 } 00178 } else { 00179 00180 /* Compute the Cholesky factorization A = L*L'. */ 00181 00182 jj = 1; 00183 i__1 = *n; 00184 for (j = 1; j <= i__1; ++j) { 00185 00186 /* Compute L(J,J) and test for non-positive-definiteness. */ 00187 00188 ajj = ap[jj]; 00189 if (ajj <= 0.f) { 00190 ap[jj] = ajj; 00191 goto L30; 00192 } 00193 ajj = sqrt(ajj); 00194 ap[jj] = ajj; 00195 00196 /* Compute elements J+1:N of column J and update the trailing */ 00197 /* submatrix. */ 00198 00199 if (j < *n) { 00200 i__2 = *n - j; 00201 r__1 = 1.f / ajj; 00202 sscal_(&i__2, &r__1, &ap[jj + 1], &c__1); 00203 i__2 = *n - j; 00204 sspr_("Lower", &i__2, &c_b16, &ap[jj + 1], &c__1, &ap[jj + *n 00205 - j + 1]); 00206 jj = jj + *n - j + 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 SPPTRF */ 00220 00221 } /* spptrf_ */