cpotf2.c
Go to the documentation of this file.
00001 /* cpotf2.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 complex c_b1 = {1.f,0.f};
00019 static integer c__1 = 1;
00020 
00021 /* Subroutine */ int cpotf2_(char *uplo, integer *n, complex *a, integer *lda, 
00022          integer *info)
00023 {
00024     /* System generated locals */
00025     integer a_dim1, a_offset, 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;
00034     real ajj;
00035     extern /* Complex */ VOID cdotc_(complex *, integer *, complex *, integer 
00036             *, complex *, integer *);
00037     extern logical lsame_(char *, char *);
00038     extern /* Subroutine */ int cgemv_(char *, integer *, integer *, complex *
00039 , complex *, integer *, complex *, integer *, complex *, complex *
00040 , integer *);
00041     logical upper;
00042     extern /* Subroutine */ int clacgv_(integer *, complex *, integer *), 
00043             csscal_(integer *, real *, complex *, integer *), xerbla_(char *, 
00044             integer *);
00045     extern logical sisnan_(real *);
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 /*  CPOTF2 computes the Cholesky factorization of a complex Hermitian */
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 /*          Hermitian 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) COMPLEX array, dimension (LDA,N) */
00083 /*          On entry, the Hermitian 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_("CPOTF2", &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 + j * a_dim1;
00157             r__1 = a[i__2].r;
00158             i__3 = j - 1;
00159             cdotc_(&q__2, &i__3, &a[j * a_dim1 + 1], &c__1, &a[j * a_dim1 + 1]
00160 , &c__1);
00161             q__1.r = r__1 - q__2.r, q__1.i = -q__2.i;
00162             ajj = q__1.r;
00163             if (ajj <= 0.f || sisnan_(&ajj)) {
00164                 i__2 = j + j * a_dim1;
00165                 a[i__2].r = ajj, a[i__2].i = 0.f;
00166                 goto L30;
00167             }
00168             ajj = sqrt(ajj);
00169             i__2 = j + j * a_dim1;
00170             a[i__2].r = ajj, a[i__2].i = 0.f;
00171 
00172 /*           Compute elements J+1:N of row J. */
00173 
00174             if (j < *n) {
00175                 i__2 = j - 1;
00176                 clacgv_(&i__2, &a[j * a_dim1 + 1], &c__1);
00177                 i__2 = j - 1;
00178                 i__3 = *n - j;
00179                 q__1.r = -1.f, q__1.i = -0.f;
00180                 cgemv_("Transpose", &i__2, &i__3, &q__1, &a[(j + 1) * a_dim1 
00181                         + 1], lda, &a[j * a_dim1 + 1], &c__1, &c_b1, &a[j + (
00182                         j + 1) * a_dim1], lda);
00183                 i__2 = j - 1;
00184                 clacgv_(&i__2, &a[j * a_dim1 + 1], &c__1);
00185                 i__2 = *n - j;
00186                 r__1 = 1.f / ajj;
00187                 csscal_(&i__2, &r__1, &a[j + (j + 1) * a_dim1], lda);
00188             }
00189 /* L10: */
00190         }
00191     } else {
00192 
00193 /*        Compute the Cholesky factorization A = L*L'. */
00194 
00195         i__1 = *n;
00196         for (j = 1; j <= i__1; ++j) {
00197 
00198 /*           Compute L(J,J) and test for non-positive-definiteness. */
00199 
00200             i__2 = j + j * a_dim1;
00201             r__1 = a[i__2].r;
00202             i__3 = j - 1;
00203             cdotc_(&q__2, &i__3, &a[j + a_dim1], lda, &a[j + a_dim1], lda);
00204             q__1.r = r__1 - q__2.r, q__1.i = -q__2.i;
00205             ajj = q__1.r;
00206             if (ajj <= 0.f || sisnan_(&ajj)) {
00207                 i__2 = j + j * a_dim1;
00208                 a[i__2].r = ajj, a[i__2].i = 0.f;
00209                 goto L30;
00210             }
00211             ajj = sqrt(ajj);
00212             i__2 = j + j * a_dim1;
00213             a[i__2].r = ajj, a[i__2].i = 0.f;
00214 
00215 /*           Compute elements J+1:N of column J. */
00216 
00217             if (j < *n) {
00218                 i__2 = j - 1;
00219                 clacgv_(&i__2, &a[j + a_dim1], lda);
00220                 i__2 = *n - j;
00221                 i__3 = j - 1;
00222                 q__1.r = -1.f, q__1.i = -0.f;
00223                 cgemv_("No transpose", &i__2, &i__3, &q__1, &a[j + 1 + a_dim1]
00224 , lda, &a[j + a_dim1], lda, &c_b1, &a[j + 1 + j * 
00225                         a_dim1], &c__1);
00226                 i__2 = j - 1;
00227                 clacgv_(&i__2, &a[j + a_dim1], lda);
00228                 i__2 = *n - j;
00229                 r__1 = 1.f / ajj;
00230                 csscal_(&i__2, &r__1, &a[j + 1 + j * a_dim1], &c__1);
00231             }
00232 /* L20: */
00233         }
00234     }
00235     goto L40;
00236 
00237 L30:
00238     *info = j;
00239 
00240 L40:
00241     return 0;
00242 
00243 /*     End of CPOTF2 */
00244 
00245 } /* cpotf2_ */


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