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


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