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


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