chetd2.c
Go to the documentation of this file.
00001 /* chetd2.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_b2 = {0.f,0.f};
00019 static integer c__1 = 1;
00020 
00021 /* Subroutine */ int chetd2_(char *uplo, integer *n, complex *a, integer *lda, 
00022          real *d__, real *e, complex *tau, 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, q__3, q__4;
00028 
00029     /* Local variables */
00030     integer i__;
00031     complex taui;
00032     extern /* Subroutine */ int cher2_(char *, integer *, complex *, complex *
00033 , integer *, complex *, integer *, complex *, integer *);
00034     complex alpha;
00035     extern /* Complex */ VOID cdotc_(complex *, integer *, complex *, integer 
00036             *, complex *, integer *);
00037     extern logical lsame_(char *, char *);
00038     extern /* Subroutine */ int chemv_(char *, integer *, complex *, complex *
00039 , integer *, complex *, integer *, complex *, complex *, integer *
00040 ), caxpy_(integer *, complex *, complex *, integer *, 
00041             complex *, integer *);
00042     logical upper;
00043     extern /* Subroutine */ int clarfg_(integer *, complex *, complex *, 
00044             integer *, complex *), xerbla_(char *, integer *);
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 /*  CHETD2 reduces a complex Hermitian matrix A to real symmetric */
00060 /*  tridiagonal form T by a unitary similarity transformation: */
00061 /*  Q' * A * Q = T. */
00062 
00063 /*  Arguments */
00064 /*  ========= */
00065 
00066 /*  UPLO    (input) CHARACTER*1 */
00067 /*          Specifies whether the upper or lower triangular part of the */
00068 /*          Hermitian matrix A is stored: */
00069 /*          = 'U':  Upper triangular */
00070 /*          = 'L':  Lower triangular */
00071 
00072 /*  N       (input) INTEGER */
00073 /*          The order of the matrix A.  N >= 0. */
00074 
00075 /*  A       (input/output) COMPLEX array, dimension (LDA,N) */
00076 /*          On entry, the Hermitian matrix A.  If UPLO = 'U', the leading */
00077 /*          n-by-n upper triangular part of A contains the upper */
00078 /*          triangular part of the matrix A, and the strictly lower */
00079 /*          triangular part of A is not referenced.  If UPLO = 'L', the */
00080 /*          leading n-by-n lower triangular part of A contains the lower */
00081 /*          triangular part of the matrix A, and the strictly upper */
00082 /*          triangular part of A is not referenced. */
00083 /*          On exit, if UPLO = 'U', the diagonal and first superdiagonal */
00084 /*          of A are overwritten by the corresponding elements of the */
00085 /*          tridiagonal matrix T, and the elements above the first */
00086 /*          superdiagonal, with the array TAU, represent the unitary */
00087 /*          matrix Q as a product of elementary reflectors; if UPLO */
00088 /*          = 'L', the diagonal and first subdiagonal of A are over- */
00089 /*          written by the corresponding elements of the tridiagonal */
00090 /*          matrix T, and the elements below the first subdiagonal, with */
00091 /*          the array TAU, represent the unitary matrix Q as a product */
00092 /*          of elementary reflectors. See Further Details. */
00093 
00094 /*  LDA     (input) INTEGER */
00095 /*          The leading dimension of the array A.  LDA >= max(1,N). */
00096 
00097 /*  D       (output) REAL array, dimension (N) */
00098 /*          The diagonal elements of the tridiagonal matrix T: */
00099 /*          D(i) = A(i,i). */
00100 
00101 /*  E       (output) REAL array, dimension (N-1) */
00102 /*          The off-diagonal elements of the tridiagonal matrix T: */
00103 /*          E(i) = A(i,i+1) if UPLO = 'U', E(i) = A(i+1,i) if UPLO = 'L'. */
00104 
00105 /*  TAU     (output) COMPLEX array, dimension (N-1) */
00106 /*          The scalar factors of the elementary reflectors (see Further */
00107 /*          Details). */
00108 
00109 /*  INFO    (output) INTEGER */
00110 /*          = 0:  successful exit */
00111 /*          < 0:  if INFO = -i, the i-th argument had an illegal value. */
00112 
00113 /*  Further Details */
00114 /*  =============== */
00115 
00116 /*  If UPLO = 'U', the matrix Q is represented as a product of elementary */
00117 /*  reflectors */
00118 
00119 /*     Q = H(n-1) . . . H(2) H(1). */
00120 
00121 /*  Each H(i) has the form */
00122 
00123 /*     H(i) = I - tau * v * v' */
00124 
00125 /*  where tau is a complex scalar, and v is a complex vector with */
00126 /*  v(i+1:n) = 0 and v(i) = 1; v(1:i-1) is stored on exit in */
00127 /*  A(1:i-1,i+1), and tau in TAU(i). */
00128 
00129 /*  If UPLO = 'L', the matrix Q is represented as a product of elementary */
00130 /*  reflectors */
00131 
00132 /*     Q = H(1) H(2) . . . H(n-1). */
00133 
00134 /*  Each H(i) has the form */
00135 
00136 /*     H(i) = I - tau * v * v' */
00137 
00138 /*  where tau is a complex scalar, and v is a complex vector with */
00139 /*  v(1:i) = 0 and v(i+1) = 1; v(i+2:n) is stored on exit in A(i+2:n,i), */
00140 /*  and tau in TAU(i). */
00141 
00142 /*  The contents of A on exit are illustrated by the following examples */
00143 /*  with n = 5: */
00144 
00145 /*  if UPLO = 'U':                       if UPLO = 'L': */
00146 
00147 /*    (  d   e   v2  v3  v4 )              (  d                  ) */
00148 /*    (      d   e   v3  v4 )              (  e   d              ) */
00149 /*    (          d   e   v4 )              (  v1  e   d          ) */
00150 /*    (              d   e  )              (  v1  v2  e   d      ) */
00151 /*    (                  d  )              (  v1  v2  v3  e   d  ) */
00152 
00153 /*  where d and e denote diagonal and off-diagonal elements of T, and vi */
00154 /*  denotes an element of the vector defining H(i). */
00155 
00156 /*  ===================================================================== */
00157 
00158 /*     .. Parameters .. */
00159 /*     .. */
00160 /*     .. Local Scalars .. */
00161 /*     .. */
00162 /*     .. External Subroutines .. */
00163 /*     .. */
00164 /*     .. External Functions .. */
00165 /*     .. */
00166 /*     .. Intrinsic Functions .. */
00167 /*     .. */
00168 /*     .. Executable Statements .. */
00169 
00170 /*     Test the input parameters */
00171 
00172     /* Parameter adjustments */
00173     a_dim1 = *lda;
00174     a_offset = 1 + a_dim1;
00175     a -= a_offset;
00176     --d__;
00177     --e;
00178     --tau;
00179 
00180     /* Function Body */
00181     *info = 0;
00182     upper = lsame_(uplo, "U");
00183     if (! upper && ! lsame_(uplo, "L")) {
00184         *info = -1;
00185     } else if (*n < 0) {
00186         *info = -2;
00187     } else if (*lda < max(1,*n)) {
00188         *info = -4;
00189     }
00190     if (*info != 0) {
00191         i__1 = -(*info);
00192         xerbla_("CHETD2", &i__1);
00193         return 0;
00194     }
00195 
00196 /*     Quick return if possible */
00197 
00198     if (*n <= 0) {
00199         return 0;
00200     }
00201 
00202     if (upper) {
00203 
00204 /*        Reduce the upper triangle of A */
00205 
00206         i__1 = *n + *n * a_dim1;
00207         i__2 = *n + *n * a_dim1;
00208         r__1 = a[i__2].r;
00209         a[i__1].r = r__1, a[i__1].i = 0.f;
00210         for (i__ = *n - 1; i__ >= 1; --i__) {
00211 
00212 /*           Generate elementary reflector H(i) = I - tau * v * v' */
00213 /*           to annihilate A(1:i-1,i+1) */
00214 
00215             i__1 = i__ + (i__ + 1) * a_dim1;
00216             alpha.r = a[i__1].r, alpha.i = a[i__1].i;
00217             clarfg_(&i__, &alpha, &a[(i__ + 1) * a_dim1 + 1], &c__1, &taui);
00218             i__1 = i__;
00219             e[i__1] = alpha.r;
00220 
00221             if (taui.r != 0.f || taui.i != 0.f) {
00222 
00223 /*              Apply H(i) from both sides to A(1:i,1:i) */
00224 
00225                 i__1 = i__ + (i__ + 1) * a_dim1;
00226                 a[i__1].r = 1.f, a[i__1].i = 0.f;
00227 
00228 /*              Compute  x := tau * A * v  storing x in TAU(1:i) */
00229 
00230                 chemv_(uplo, &i__, &taui, &a[a_offset], lda, &a[(i__ + 1) * 
00231                         a_dim1 + 1], &c__1, &c_b2, &tau[1], &c__1);
00232 
00233 /*              Compute  w := x - 1/2 * tau * (x'*v) * v */
00234 
00235                 q__3.r = -.5f, q__3.i = -0.f;
00236                 q__2.r = q__3.r * taui.r - q__3.i * taui.i, q__2.i = q__3.r * 
00237                         taui.i + q__3.i * taui.r;
00238                 cdotc_(&q__4, &i__, &tau[1], &c__1, &a[(i__ + 1) * a_dim1 + 1]
00239 , &c__1);
00240                 q__1.r = q__2.r * q__4.r - q__2.i * q__4.i, q__1.i = q__2.r * 
00241                         q__4.i + q__2.i * q__4.r;
00242                 alpha.r = q__1.r, alpha.i = q__1.i;
00243                 caxpy_(&i__, &alpha, &a[(i__ + 1) * a_dim1 + 1], &c__1, &tau[
00244                         1], &c__1);
00245 
00246 /*              Apply the transformation as a rank-2 update: */
00247 /*                 A := A - v * w' - w * v' */
00248 
00249                 q__1.r = -1.f, q__1.i = -0.f;
00250                 cher2_(uplo, &i__, &q__1, &a[(i__ + 1) * a_dim1 + 1], &c__1, &
00251                         tau[1], &c__1, &a[a_offset], lda);
00252 
00253             } else {
00254                 i__1 = i__ + i__ * a_dim1;
00255                 i__2 = i__ + i__ * a_dim1;
00256                 r__1 = a[i__2].r;
00257                 a[i__1].r = r__1, a[i__1].i = 0.f;
00258             }
00259             i__1 = i__ + (i__ + 1) * a_dim1;
00260             i__2 = i__;
00261             a[i__1].r = e[i__2], a[i__1].i = 0.f;
00262             i__1 = i__ + 1;
00263             i__2 = i__ + 1 + (i__ + 1) * a_dim1;
00264             d__[i__1] = a[i__2].r;
00265             i__1 = i__;
00266             tau[i__1].r = taui.r, tau[i__1].i = taui.i;
00267 /* L10: */
00268         }
00269         i__1 = a_dim1 + 1;
00270         d__[1] = a[i__1].r;
00271     } else {
00272 
00273 /*        Reduce the lower triangle of A */
00274 
00275         i__1 = a_dim1 + 1;
00276         i__2 = a_dim1 + 1;
00277         r__1 = a[i__2].r;
00278         a[i__1].r = r__1, a[i__1].i = 0.f;
00279         i__1 = *n - 1;
00280         for (i__ = 1; i__ <= i__1; ++i__) {
00281 
00282 /*           Generate elementary reflector H(i) = I - tau * v * v' */
00283 /*           to annihilate A(i+2:n,i) */
00284 
00285             i__2 = i__ + 1 + i__ * a_dim1;
00286             alpha.r = a[i__2].r, alpha.i = a[i__2].i;
00287             i__2 = *n - i__;
00288 /* Computing MIN */
00289             i__3 = i__ + 2;
00290             clarfg_(&i__2, &alpha, &a[min(i__3, *n)+ i__ * a_dim1], &c__1, &
00291                     taui);
00292             i__2 = i__;
00293             e[i__2] = alpha.r;
00294 
00295             if (taui.r != 0.f || taui.i != 0.f) {
00296 
00297 /*              Apply H(i) from both sides to A(i+1:n,i+1:n) */
00298 
00299                 i__2 = i__ + 1 + i__ * a_dim1;
00300                 a[i__2].r = 1.f, a[i__2].i = 0.f;
00301 
00302 /*              Compute  x := tau * A * v  storing y in TAU(i:n-1) */
00303 
00304                 i__2 = *n - i__;
00305                 chemv_(uplo, &i__2, &taui, &a[i__ + 1 + (i__ + 1) * a_dim1], 
00306                         lda, &a[i__ + 1 + i__ * a_dim1], &c__1, &c_b2, &tau[
00307                         i__], &c__1);
00308 
00309 /*              Compute  w := x - 1/2 * tau * (x'*v) * v */
00310 
00311                 q__3.r = -.5f, q__3.i = -0.f;
00312                 q__2.r = q__3.r * taui.r - q__3.i * taui.i, q__2.i = q__3.r * 
00313                         taui.i + q__3.i * taui.r;
00314                 i__2 = *n - i__;
00315                 cdotc_(&q__4, &i__2, &tau[i__], &c__1, &a[i__ + 1 + i__ * 
00316                         a_dim1], &c__1);
00317                 q__1.r = q__2.r * q__4.r - q__2.i * q__4.i, q__1.i = q__2.r * 
00318                         q__4.i + q__2.i * q__4.r;
00319                 alpha.r = q__1.r, alpha.i = q__1.i;
00320                 i__2 = *n - i__;
00321                 caxpy_(&i__2, &alpha, &a[i__ + 1 + i__ * a_dim1], &c__1, &tau[
00322                         i__], &c__1);
00323 
00324 /*              Apply the transformation as a rank-2 update: */
00325 /*                 A := A - v * w' - w * v' */
00326 
00327                 i__2 = *n - i__;
00328                 q__1.r = -1.f, q__1.i = -0.f;
00329                 cher2_(uplo, &i__2, &q__1, &a[i__ + 1 + i__ * a_dim1], &c__1, 
00330                         &tau[i__], &c__1, &a[i__ + 1 + (i__ + 1) * a_dim1], 
00331                         lda);
00332 
00333             } else {
00334                 i__2 = i__ + 1 + (i__ + 1) * a_dim1;
00335                 i__3 = i__ + 1 + (i__ + 1) * a_dim1;
00336                 r__1 = a[i__3].r;
00337                 a[i__2].r = r__1, a[i__2].i = 0.f;
00338             }
00339             i__2 = i__ + 1 + i__ * a_dim1;
00340             i__3 = i__;
00341             a[i__2].r = e[i__3], a[i__2].i = 0.f;
00342             i__2 = i__;
00343             i__3 = i__ + i__ * a_dim1;
00344             d__[i__2] = a[i__3].r;
00345             i__2 = i__;
00346             tau[i__2].r = taui.r, tau[i__2].i = taui.i;
00347 /* L20: */
00348         }
00349         i__1 = *n;
00350         i__2 = *n + *n * a_dim1;
00351         d__[i__1] = a[i__2].r;
00352     }
00353 
00354     return 0;
00355 
00356 /*     End of CHETD2 */
00357 
00358 } /* chetd2_ */


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