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


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