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


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