zhptrd.c
Go to the documentation of this file.
00001 /* zhptrd.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 zhptrd_(char *uplo, integer *n, doublecomplex *ap, 
00022         doublereal *d__, doublereal *e, doublecomplex *tau, integer *info)
00023 {
00024     /* System generated locals */
00025     integer i__1, i__2, i__3;
00026     doublereal d__1;
00027     doublecomplex z__1, z__2, z__3, z__4;
00028 
00029     /* Local variables */
00030     integer i__, i1, ii, i1i1;
00031     doublecomplex taui;
00032     extern /* Subroutine */ int zhpr2_(char *, integer *, doublecomplex *, 
00033             doublecomplex *, integer *, doublecomplex *, integer *, 
00034             doublecomplex *);
00035     doublecomplex alpha;
00036     extern logical lsame_(char *, char *);
00037     extern /* Double Complex */ VOID zdotc_(doublecomplex *, integer *, 
00038             doublecomplex *, integer *, doublecomplex *, integer *);
00039     logical upper;
00040     extern /* Subroutine */ int zhpmv_(char *, integer *, doublecomplex *, 
00041             doublecomplex *, doublecomplex *, integer *, doublecomplex *, 
00042             doublecomplex *, integer *), zaxpy_(integer *, 
00043             doublecomplex *, doublecomplex *, integer *, doublecomplex *, 
00044             integer *), xerbla_(char *, integer *), zlarfg_(integer *, 
00045              doublecomplex *, doublecomplex *, integer *, doublecomplex *);
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 /*  ZHPTRD reduces a complex Hermitian matrix A stored in packed form to */
00061 /*  real symmetric tridiagonal form T by a unitary similarity */
00062 /*  transformation: Q**H * A * Q = T. */
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) COMPLEX*16 array, dimension (N*(N+1)/2) */
00075 /*          On entry, the upper or lower triangle of the Hermitian 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)*(2*n-j)/2) = A(i,j) for j<=i<=n. */
00080 /*          On exit, if UPLO = 'U', the diagonal and first superdiagonal */
00081 /*          of A are overwritten by the corresponding elements of the */
00082 /*          tridiagonal matrix T, and the elements above the first */
00083 /*          superdiagonal, with the array TAU, represent the unitary */
00084 /*          matrix Q as a product of elementary reflectors; if UPLO */
00085 /*          = 'L', the diagonal and first subdiagonal of A are over- */
00086 /*          written by the corresponding elements of the tridiagonal */
00087 /*          matrix T, and the elements below the first subdiagonal, with */
00088 /*          the array TAU, represent the unitary matrix Q as a product */
00089 /*          of elementary reflectors. See Further Details. */
00090 
00091 /*  D       (output) DOUBLE PRECISION array, dimension (N) */
00092 /*          The diagonal elements of the tridiagonal matrix T: */
00093 /*          D(i) = A(i,i). */
00094 
00095 /*  E       (output) DOUBLE PRECISION array, dimension (N-1) */
00096 /*          The off-diagonal elements of the tridiagonal matrix T: */
00097 /*          E(i) = A(i,i+1) if UPLO = 'U', E(i) = A(i+1,i) if UPLO = 'L'. */
00098 
00099 /*  TAU     (output) COMPLEX*16 array, dimension (N-1) */
00100 /*          The scalar factors of the elementary reflectors (see Further */
00101 /*          Details). */
00102 
00103 /*  INFO    (output) INTEGER */
00104 /*          = 0:  successful exit */
00105 /*          < 0:  if INFO = -i, the i-th argument had an illegal value */
00106 
00107 /*  Further Details */
00108 /*  =============== */
00109 
00110 /*  If UPLO = 'U', the matrix Q is represented as a product of elementary */
00111 /*  reflectors */
00112 
00113 /*     Q = H(n-1) . . . H(2) H(1). */
00114 
00115 /*  Each H(i) has the form */
00116 
00117 /*     H(i) = I - tau * v * v' */
00118 
00119 /*  where tau is a complex scalar, and v is a complex vector with */
00120 /*  v(i+1:n) = 0 and v(i) = 1; v(1:i-1) is stored on exit in AP, */
00121 /*  overwriting A(1:i-1,i+1), and tau is stored in TAU(i). */
00122 
00123 /*  If UPLO = 'L', the matrix Q is represented as a product of elementary */
00124 /*  reflectors */
00125 
00126 /*     Q = H(1) H(2) . . . H(n-1). */
00127 
00128 /*  Each H(i) has the form */
00129 
00130 /*     H(i) = I - tau * v * v' */
00131 
00132 /*  where tau is a complex scalar, and v is a complex vector with */
00133 /*  v(1:i) = 0 and v(i+1) = 1; v(i+2:n) is stored on exit in AP, */
00134 /*  overwriting A(i+2:n,i), and tau is stored in TAU(i). */
00135 
00136 /*  ===================================================================== */
00137 
00138 /*     .. Parameters .. */
00139 /*     .. */
00140 /*     .. Local Scalars .. */
00141 /*     .. */
00142 /*     .. External Subroutines .. */
00143 /*     .. */
00144 /*     .. External Functions .. */
00145 /*     .. */
00146 /*     .. Intrinsic Functions .. */
00147 /*     .. */
00148 /*     .. Executable Statements .. */
00149 
00150 /*     Test the input parameters */
00151 
00152     /* Parameter adjustments */
00153     --tau;
00154     --e;
00155     --d__;
00156     --ap;
00157 
00158     /* Function Body */
00159     *info = 0;
00160     upper = lsame_(uplo, "U");
00161     if (! upper && ! lsame_(uplo, "L")) {
00162         *info = -1;
00163     } else if (*n < 0) {
00164         *info = -2;
00165     }
00166     if (*info != 0) {
00167         i__1 = -(*info);
00168         xerbla_("ZHPTRD", &i__1);
00169         return 0;
00170     }
00171 
00172 /*     Quick return if possible */
00173 
00174     if (*n <= 0) {
00175         return 0;
00176     }
00177 
00178     if (upper) {
00179 
00180 /*        Reduce the upper triangle of A. */
00181 /*        I1 is the index in AP of A(1,I+1). */
00182 
00183         i1 = *n * (*n - 1) / 2 + 1;
00184         i__1 = i1 + *n - 1;
00185         i__2 = i1 + *n - 1;
00186         d__1 = ap[i__2].r;
00187         ap[i__1].r = d__1, ap[i__1].i = 0.;
00188         for (i__ = *n - 1; i__ >= 1; --i__) {
00189 
00190 /*           Generate elementary reflector H(i) = I - tau * v * v' */
00191 /*           to annihilate A(1:i-1,i+1) */
00192 
00193             i__1 = i1 + i__ - 1;
00194             alpha.r = ap[i__1].r, alpha.i = ap[i__1].i;
00195             zlarfg_(&i__, &alpha, &ap[i1], &c__1, &taui);
00196             i__1 = i__;
00197             e[i__1] = alpha.r;
00198 
00199             if (taui.r != 0. || taui.i != 0.) {
00200 
00201 /*              Apply H(i) from both sides to A(1:i,1:i) */
00202 
00203                 i__1 = i1 + i__ - 1;
00204                 ap[i__1].r = 1., ap[i__1].i = 0.;
00205 
00206 /*              Compute  y := tau * A * v  storing y in TAU(1:i) */
00207 
00208                 zhpmv_(uplo, &i__, &taui, &ap[1], &ap[i1], &c__1, &c_b2, &tau[
00209                         1], &c__1);
00210 
00211 /*              Compute  w := y - 1/2 * tau * (y'*v) * v */
00212 
00213                 z__3.r = -.5, z__3.i = -0.;
00214                 z__2.r = z__3.r * taui.r - z__3.i * taui.i, z__2.i = z__3.r * 
00215                         taui.i + z__3.i * taui.r;
00216                 zdotc_(&z__4, &i__, &tau[1], &c__1, &ap[i1], &c__1);
00217                 z__1.r = z__2.r * z__4.r - z__2.i * z__4.i, z__1.i = z__2.r * 
00218                         z__4.i + z__2.i * z__4.r;
00219                 alpha.r = z__1.r, alpha.i = z__1.i;
00220                 zaxpy_(&i__, &alpha, &ap[i1], &c__1, &tau[1], &c__1);
00221 
00222 /*              Apply the transformation as a rank-2 update: */
00223 /*                 A := A - v * w' - w * v' */
00224 
00225                 z__1.r = -1., z__1.i = -0.;
00226                 zhpr2_(uplo, &i__, &z__1, &ap[i1], &c__1, &tau[1], &c__1, &ap[
00227                         1]);
00228 
00229             }
00230             i__1 = i1 + i__ - 1;
00231             i__2 = i__;
00232             ap[i__1].r = e[i__2], ap[i__1].i = 0.;
00233             i__1 = i__ + 1;
00234             i__2 = i1 + i__;
00235             d__[i__1] = ap[i__2].r;
00236             i__1 = i__;
00237             tau[i__1].r = taui.r, tau[i__1].i = taui.i;
00238             i1 -= i__;
00239 /* L10: */
00240         }
00241         d__[1] = ap[1].r;
00242     } else {
00243 
00244 /*        Reduce the lower triangle of A. II is the index in AP of */
00245 /*        A(i,i) and I1I1 is the index of A(i+1,i+1). */
00246 
00247         ii = 1;
00248         d__1 = ap[1].r;
00249         ap[1].r = d__1, ap[1].i = 0.;
00250         i__1 = *n - 1;
00251         for (i__ = 1; i__ <= i__1; ++i__) {
00252             i1i1 = ii + *n - i__ + 1;
00253 
00254 /*           Generate elementary reflector H(i) = I - tau * v * v' */
00255 /*           to annihilate A(i+2:n,i) */
00256 
00257             i__2 = ii + 1;
00258             alpha.r = ap[i__2].r, alpha.i = ap[i__2].i;
00259             i__2 = *n - i__;
00260             zlarfg_(&i__2, &alpha, &ap[ii + 2], &c__1, &taui);
00261             i__2 = i__;
00262             e[i__2] = alpha.r;
00263 
00264             if (taui.r != 0. || taui.i != 0.) {
00265 
00266 /*              Apply H(i) from both sides to A(i+1:n,i+1:n) */
00267 
00268                 i__2 = ii + 1;
00269                 ap[i__2].r = 1., ap[i__2].i = 0.;
00270 
00271 /*              Compute  y := tau * A * v  storing y in TAU(i:n-1) */
00272 
00273                 i__2 = *n - i__;
00274                 zhpmv_(uplo, &i__2, &taui, &ap[i1i1], &ap[ii + 1], &c__1, &
00275                         c_b2, &tau[i__], &c__1);
00276 
00277 /*              Compute  w := y - 1/2 * tau * (y'*v) * v */
00278 
00279                 z__3.r = -.5, z__3.i = -0.;
00280                 z__2.r = z__3.r * taui.r - z__3.i * taui.i, z__2.i = z__3.r * 
00281                         taui.i + z__3.i * taui.r;
00282                 i__2 = *n - i__;
00283                 zdotc_(&z__4, &i__2, &tau[i__], &c__1, &ap[ii + 1], &c__1);
00284                 z__1.r = z__2.r * z__4.r - z__2.i * z__4.i, z__1.i = z__2.r * 
00285                         z__4.i + z__2.i * z__4.r;
00286                 alpha.r = z__1.r, alpha.i = z__1.i;
00287                 i__2 = *n - i__;
00288                 zaxpy_(&i__2, &alpha, &ap[ii + 1], &c__1, &tau[i__], &c__1);
00289 
00290 /*              Apply the transformation as a rank-2 update: */
00291 /*                 A := A - v * w' - w * v' */
00292 
00293                 i__2 = *n - i__;
00294                 z__1.r = -1., z__1.i = -0.;
00295                 zhpr2_(uplo, &i__2, &z__1, &ap[ii + 1], &c__1, &tau[i__], &
00296                         c__1, &ap[i1i1]);
00297 
00298             }
00299             i__2 = ii + 1;
00300             i__3 = i__;
00301             ap[i__2].r = e[i__3], ap[i__2].i = 0.;
00302             i__2 = i__;
00303             i__3 = ii;
00304             d__[i__2] = ap[i__3].r;
00305             i__2 = i__;
00306             tau[i__2].r = taui.r, tau[i__2].i = taui.i;
00307             ii = i1i1;
00308 /* L20: */
00309         }
00310         i__1 = *n;
00311         i__2 = ii;
00312         d__[i__1] = ap[i__2].r;
00313     }
00314 
00315     return 0;
00316 
00317 /*     End of ZHPTRD */
00318 
00319 } /* zhptrd_ */


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