zlaghe.c
Go to the documentation of this file.
00001 /* zlaghe.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_b1 = {0.,0.};
00019 static doublecomplex c_b2 = {1.,0.};
00020 static integer c__3 = 3;
00021 static integer c__1 = 1;
00022 
00023 /* Subroutine */ int zlaghe_(integer *n, integer *k, doublereal *d__, 
00024         doublecomplex *a, integer *lda, integer *iseed, doublecomplex *work, 
00025         integer *info)
00026 {
00027     /* System generated locals */
00028     integer a_dim1, a_offset, i__1, i__2, i__3;
00029     doublereal d__1;
00030     doublecomplex z__1, z__2, z__3, z__4;
00031 
00032     /* Builtin functions */
00033     double z_abs(doublecomplex *);
00034     void z_div(doublecomplex *, doublecomplex *, doublecomplex *), d_cnjg(
00035             doublecomplex *, doublecomplex *);
00036 
00037     /* Local variables */
00038     integer i__, j;
00039     doublecomplex wa, wb;
00040     doublereal wn;
00041     doublecomplex tau;
00042     extern /* Subroutine */ int zher2_(char *, integer *, doublecomplex *, 
00043             doublecomplex *, integer *, doublecomplex *, integer *, 
00044             doublecomplex *, integer *);
00045     doublecomplex alpha;
00046     extern /* Subroutine */ int zgerc_(integer *, integer *, doublecomplex *, 
00047             doublecomplex *, integer *, doublecomplex *, integer *, 
00048             doublecomplex *, integer *), zscal_(integer *, doublecomplex *, 
00049             doublecomplex *, integer *);
00050     extern /* Double Complex */ VOID zdotc_(doublecomplex *, integer *, 
00051             doublecomplex *, integer *, doublecomplex *, integer *);
00052     extern /* Subroutine */ int zgemv_(char *, integer *, integer *, 
00053             doublecomplex *, doublecomplex *, integer *, doublecomplex *, 
00054             integer *, doublecomplex *, doublecomplex *, integer *), 
00055             zhemv_(char *, integer *, doublecomplex *, doublecomplex *, 
00056             integer *, doublecomplex *, integer *, doublecomplex *, 
00057             doublecomplex *, integer *), zaxpy_(integer *, 
00058             doublecomplex *, doublecomplex *, integer *, doublecomplex *, 
00059             integer *);
00060     extern doublereal dznrm2_(integer *, doublecomplex *, integer *);
00061     extern /* Subroutine */ int xerbla_(char *, integer *), zlarnv_(
00062             integer *, integer *, integer *, doublecomplex *);
00063 
00064 
00065 /*  -- LAPACK auxiliary test routine (version 3.1) -- */
00066 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
00067 /*     November 2006 */
00068 
00069 /*     .. Scalar Arguments .. */
00070 /*     .. */
00071 /*     .. Array Arguments .. */
00072 /*     .. */
00073 
00074 /*  Purpose */
00075 /*  ======= */
00076 
00077 /*  ZLAGHE generates a complex hermitian matrix A, by pre- and post- */
00078 /*  multiplying a real diagonal matrix D with a random unitary matrix: */
00079 /*  A = U*D*U'. The semi-bandwidth may then be reduced to k by additional */
00080 /*  unitary transformations. */
00081 
00082 /*  Arguments */
00083 /*  ========= */
00084 
00085 /*  N       (input) INTEGER */
00086 /*          The order of the matrix A.  N >= 0. */
00087 
00088 /*  K       (input) INTEGER */
00089 /*          The number of nonzero subdiagonals within the band of A. */
00090 /*          0 <= K <= N-1. */
00091 
00092 /*  D       (input) DOUBLE PRECISION array, dimension (N) */
00093 /*          The diagonal elements of the diagonal matrix D. */
00094 
00095 /*  A       (output) COMPLEX*16 array, dimension (LDA,N) */
00096 /*          The generated n by n hermitian matrix A (the full matrix is */
00097 /*          stored). */
00098 
00099 /*  LDA     (input) INTEGER */
00100 /*          The leading dimension of the array A.  LDA >= N. */
00101 
00102 /*  ISEED   (input/output) INTEGER array, dimension (4) */
00103 /*          On entry, the seed of the random number generator; the array */
00104 /*          elements must be between 0 and 4095, and ISEED(4) must be */
00105 /*          odd. */
00106 /*          On exit, the seed is updated. */
00107 
00108 /*  WORK    (workspace) COMPLEX*16 array, dimension (2*N) */
00109 
00110 /*  INFO    (output) INTEGER */
00111 /*          = 0: successful exit */
00112 /*          < 0: if INFO = -i, the i-th argument had an illegal value */
00113 
00114 /*  ===================================================================== */
00115 
00116 /*     .. Parameters .. */
00117 /*     .. */
00118 /*     .. Local Scalars .. */
00119 /*     .. */
00120 /*     .. External Subroutines .. */
00121 /*     .. */
00122 /*     .. External Functions .. */
00123 /*     .. */
00124 /*     .. Intrinsic Functions .. */
00125 /*     .. */
00126 /*     .. Executable Statements .. */
00127 
00128 /*     Test the input arguments */
00129 
00130     /* Parameter adjustments */
00131     --d__;
00132     a_dim1 = *lda;
00133     a_offset = 1 + a_dim1;
00134     a -= a_offset;
00135     --iseed;
00136     --work;
00137 
00138     /* Function Body */
00139     *info = 0;
00140     if (*n < 0) {
00141         *info = -1;
00142     } else if (*k < 0 || *k > *n - 1) {
00143         *info = -2;
00144     } else if (*lda < max(1,*n)) {
00145         *info = -5;
00146     }
00147     if (*info < 0) {
00148         i__1 = -(*info);
00149         xerbla_("ZLAGHE", &i__1);
00150         return 0;
00151     }
00152 
00153 /*     initialize lower triangle of A to diagonal matrix */
00154 
00155     i__1 = *n;
00156     for (j = 1; j <= i__1; ++j) {
00157         i__2 = *n;
00158         for (i__ = j + 1; i__ <= i__2; ++i__) {
00159             i__3 = i__ + j * a_dim1;
00160             a[i__3].r = 0., a[i__3].i = 0.;
00161 /* L10: */
00162         }
00163 /* L20: */
00164     }
00165     i__1 = *n;
00166     for (i__ = 1; i__ <= i__1; ++i__) {
00167         i__2 = i__ + i__ * a_dim1;
00168         i__3 = i__;
00169         a[i__2].r = d__[i__3], a[i__2].i = 0.;
00170 /* L30: */
00171     }
00172 
00173 /*     Generate lower triangle of hermitian matrix */
00174 
00175     for (i__ = *n - 1; i__ >= 1; --i__) {
00176 
00177 /*        generate random reflection */
00178 
00179         i__1 = *n - i__ + 1;
00180         zlarnv_(&c__3, &iseed[1], &i__1, &work[1]);
00181         i__1 = *n - i__ + 1;
00182         wn = dznrm2_(&i__1, &work[1], &c__1);
00183         d__1 = wn / z_abs(&work[1]);
00184         z__1.r = d__1 * work[1].r, z__1.i = d__1 * work[1].i;
00185         wa.r = z__1.r, wa.i = z__1.i;
00186         if (wn == 0.) {
00187             tau.r = 0., tau.i = 0.;
00188         } else {
00189             z__1.r = work[1].r + wa.r, z__1.i = work[1].i + wa.i;
00190             wb.r = z__1.r, wb.i = z__1.i;
00191             i__1 = *n - i__;
00192             z_div(&z__1, &c_b2, &wb);
00193             zscal_(&i__1, &z__1, &work[2], &c__1);
00194             work[1].r = 1., work[1].i = 0.;
00195             z_div(&z__1, &wb, &wa);
00196             d__1 = z__1.r;
00197             tau.r = d__1, tau.i = 0.;
00198         }
00199 
00200 /*        apply random reflection to A(i:n,i:n) from the left */
00201 /*        and the right */
00202 
00203 /*        compute  y := tau * A * u */
00204 
00205         i__1 = *n - i__ + 1;
00206         zhemv_("Lower", &i__1, &tau, &a[i__ + i__ * a_dim1], lda, &work[1], &
00207                 c__1, &c_b1, &work[*n + 1], &c__1);
00208 
00209 /*        compute  v := y - 1/2 * tau * ( y, u ) * u */
00210 
00211         z__3.r = -.5, z__3.i = -0.;
00212         z__2.r = z__3.r * tau.r - z__3.i * tau.i, z__2.i = z__3.r * tau.i + 
00213                 z__3.i * tau.r;
00214         i__1 = *n - i__ + 1;
00215         zdotc_(&z__4, &i__1, &work[*n + 1], &c__1, &work[1], &c__1);
00216         z__1.r = z__2.r * z__4.r - z__2.i * z__4.i, z__1.i = z__2.r * z__4.i 
00217                 + z__2.i * z__4.r;
00218         alpha.r = z__1.r, alpha.i = z__1.i;
00219         i__1 = *n - i__ + 1;
00220         zaxpy_(&i__1, &alpha, &work[1], &c__1, &work[*n + 1], &c__1);
00221 
00222 /*        apply the transformation as a rank-2 update to A(i:n,i:n) */
00223 
00224         i__1 = *n - i__ + 1;
00225         z__1.r = -1., z__1.i = -0.;
00226         zher2_("Lower", &i__1, &z__1, &work[1], &c__1, &work[*n + 1], &c__1, &
00227                 a[i__ + i__ * a_dim1], lda);
00228 /* L40: */
00229     }
00230 
00231 /*     Reduce number of subdiagonals to K */
00232 
00233     i__1 = *n - 1 - *k;
00234     for (i__ = 1; i__ <= i__1; ++i__) {
00235 
00236 /*        generate reflection to annihilate A(k+i+1:n,i) */
00237 
00238         i__2 = *n - *k - i__ + 1;
00239         wn = dznrm2_(&i__2, &a[*k + i__ + i__ * a_dim1], &c__1);
00240         d__1 = wn / z_abs(&a[*k + i__ + i__ * a_dim1]);
00241         i__2 = *k + i__ + i__ * a_dim1;
00242         z__1.r = d__1 * a[i__2].r, z__1.i = d__1 * a[i__2].i;
00243         wa.r = z__1.r, wa.i = z__1.i;
00244         if (wn == 0.) {
00245             tau.r = 0., tau.i = 0.;
00246         } else {
00247             i__2 = *k + i__ + i__ * a_dim1;
00248             z__1.r = a[i__2].r + wa.r, z__1.i = a[i__2].i + wa.i;
00249             wb.r = z__1.r, wb.i = z__1.i;
00250             i__2 = *n - *k - i__;
00251             z_div(&z__1, &c_b2, &wb);
00252             zscal_(&i__2, &z__1, &a[*k + i__ + 1 + i__ * a_dim1], &c__1);
00253             i__2 = *k + i__ + i__ * a_dim1;
00254             a[i__2].r = 1., a[i__2].i = 0.;
00255             z_div(&z__1, &wb, &wa);
00256             d__1 = z__1.r;
00257             tau.r = d__1, tau.i = 0.;
00258         }
00259 
00260 /*        apply reflection to A(k+i:n,i+1:k+i-1) from the left */
00261 
00262         i__2 = *n - *k - i__ + 1;
00263         i__3 = *k - 1;
00264         zgemv_("Conjugate transpose", &i__2, &i__3, &c_b2, &a[*k + i__ + (i__ 
00265                 + 1) * a_dim1], lda, &a[*k + i__ + i__ * a_dim1], &c__1, &
00266                 c_b1, &work[1], &c__1);
00267         i__2 = *n - *k - i__ + 1;
00268         i__3 = *k - 1;
00269         z__1.r = -tau.r, z__1.i = -tau.i;
00270         zgerc_(&i__2, &i__3, &z__1, &a[*k + i__ + i__ * a_dim1], &c__1, &work[
00271                 1], &c__1, &a[*k + i__ + (i__ + 1) * a_dim1], lda);
00272 
00273 /*        apply reflection to A(k+i:n,k+i:n) from the left and the right */
00274 
00275 /*        compute  y := tau * A * u */
00276 
00277         i__2 = *n - *k - i__ + 1;
00278         zhemv_("Lower", &i__2, &tau, &a[*k + i__ + (*k + i__) * a_dim1], lda, 
00279                 &a[*k + i__ + i__ * a_dim1], &c__1, &c_b1, &work[1], &c__1);
00280 
00281 /*        compute  v := y - 1/2 * tau * ( y, u ) * u */
00282 
00283         z__3.r = -.5, z__3.i = -0.;
00284         z__2.r = z__3.r * tau.r - z__3.i * tau.i, z__2.i = z__3.r * tau.i + 
00285                 z__3.i * tau.r;
00286         i__2 = *n - *k - i__ + 1;
00287         zdotc_(&z__4, &i__2, &work[1], &c__1, &a[*k + i__ + i__ * a_dim1], &
00288                 c__1);
00289         z__1.r = z__2.r * z__4.r - z__2.i * z__4.i, z__1.i = z__2.r * z__4.i 
00290                 + z__2.i * z__4.r;
00291         alpha.r = z__1.r, alpha.i = z__1.i;
00292         i__2 = *n - *k - i__ + 1;
00293         zaxpy_(&i__2, &alpha, &a[*k + i__ + i__ * a_dim1], &c__1, &work[1], &
00294                 c__1);
00295 
00296 /*        apply hermitian rank-2 update to A(k+i:n,k+i:n) */
00297 
00298         i__2 = *n - *k - i__ + 1;
00299         z__1.r = -1., z__1.i = -0.;
00300         zher2_("Lower", &i__2, &z__1, &a[*k + i__ + i__ * a_dim1], &c__1, &
00301                 work[1], &c__1, &a[*k + i__ + (*k + i__) * a_dim1], lda);
00302 
00303         i__2 = *k + i__ + i__ * a_dim1;
00304         z__1.r = -wa.r, z__1.i = -wa.i;
00305         a[i__2].r = z__1.r, a[i__2].i = z__1.i;
00306         i__2 = *n;
00307         for (j = *k + i__ + 1; j <= i__2; ++j) {
00308             i__3 = j + i__ * a_dim1;
00309             a[i__3].r = 0., a[i__3].i = 0.;
00310 /* L50: */
00311         }
00312 /* L60: */
00313     }
00314 
00315 /*     Store full hermitian matrix */
00316 
00317     i__1 = *n;
00318     for (j = 1; j <= i__1; ++j) {
00319         i__2 = *n;
00320         for (i__ = j + 1; i__ <= i__2; ++i__) {
00321             i__3 = j + i__ * a_dim1;
00322             d_cnjg(&z__1, &a[i__ + j * a_dim1]);
00323             a[i__3].r = z__1.r, a[i__3].i = z__1.i;
00324 /* L70: */
00325         }
00326 /* L80: */
00327     }
00328     return 0;
00329 
00330 /*     End of ZLAGHE */
00331 
00332 } /* zlaghe_ */


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