clagsy.c
Go to the documentation of this file.
00001 /* clagsy.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 clagsy_(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, i__4, i__5, i__6, i__7, i__8, 
00028             i__9;
00029     real r__1;
00030     complex q__1, q__2, q__3, q__4;
00031 
00032     /* Builtin functions */
00033     double c_abs(complex *);
00034     void c_div(complex *, complex *, complex *);
00035 
00036     /* Local variables */
00037     integer i__, j, ii, jj;
00038     complex wa, wb;
00039     real wn;
00040     complex tau;
00041     extern /* Subroutine */ int cgerc_(integer *, integer *, complex *, 
00042             complex *, integer *, complex *, integer *, complex *, integer *);
00043     complex alpha;
00044     extern /* Subroutine */ int cscal_(integer *, complex *, complex *, 
00045             integer *);
00046     extern /* Complex */ VOID cdotc_(complex *, integer *, complex *, integer 
00047             *, complex *, integer *);
00048     extern /* Subroutine */ int cgemv_(char *, integer *, integer *, complex *
00049 , complex *, integer *, complex *, integer *, complex *, complex *
00050 , integer *), caxpy_(integer *, complex *, complex *, 
00051             integer *, complex *, integer *), csymv_(char *, integer *, 
00052             complex *, complex *, integer *, complex *, integer *, complex *, 
00053             complex *, integer *);
00054     extern doublereal scnrm2_(integer *, complex *, integer *);
00055     extern /* Subroutine */ int clacgv_(integer *, complex *, integer *), 
00056             xerbla_(char *, integer *), clarnv_(integer *, integer *, 
00057             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 /*  CLAGSY generates a complex symmetric matrix A, by pre- and post- */
00073 /*  multiplying a real diagonal matrix D with a random unitary matrix: */
00074 /*  A = U*D*U**T. The semi-bandwidth may then be reduced to k by */
00075 /*  additional 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 symmetric 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_("CLAGSY", &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 symmetric 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 * conjg(u) */
00199 
00200         i__1 = *n - i__ + 1;
00201         clacgv_(&i__1, &work[1], &c__1);
00202         i__1 = *n - i__ + 1;
00203         csymv_("Lower", &i__1, &tau, &a[i__ + i__ * a_dim1], lda, &work[1], &
00204                 c__1, &c_b1, &work[*n + 1], &c__1);
00205         i__1 = *n - i__ + 1;
00206         clacgv_(&i__1, &work[1], &c__1);
00207 
00208 /*        compute  v := y - 1/2 * tau * ( u, y ) * u */
00209 
00210         q__3.r = -.5f, q__3.i = -0.f;
00211         q__2.r = q__3.r * tau.r - q__3.i * tau.i, q__2.i = q__3.r * tau.i + 
00212                 q__3.i * tau.r;
00213         i__1 = *n - i__ + 1;
00214         cdotc_(&q__4, &i__1, &work[1], &c__1, &work[*n + 1], &c__1);
00215         q__1.r = q__2.r * q__4.r - q__2.i * q__4.i, q__1.i = q__2.r * q__4.i 
00216                 + q__2.i * q__4.r;
00217         alpha.r = q__1.r, alpha.i = q__1.i;
00218         i__1 = *n - i__ + 1;
00219         caxpy_(&i__1, &alpha, &work[1], &c__1, &work[*n + 1], &c__1);
00220 
00221 /*        apply the transformation as a rank-2 update to A(i:n,i:n) */
00222 
00223 /*        CALL CSYR2( 'Lower', N-I+1, -ONE, WORK, 1, WORK( N+1 ), 1, */
00224 /*        $               A( I, I ), LDA ) */
00225 
00226         i__1 = *n;
00227         for (jj = i__; jj <= i__1; ++jj) {
00228             i__2 = *n;
00229             for (ii = jj; ii <= i__2; ++ii) {
00230                 i__3 = ii + jj * a_dim1;
00231                 i__4 = ii + jj * a_dim1;
00232                 i__5 = ii - i__ + 1;
00233                 i__6 = *n + jj - i__ + 1;
00234                 q__3.r = work[i__5].r * work[i__6].r - work[i__5].i * work[
00235                         i__6].i, q__3.i = work[i__5].r * work[i__6].i + work[
00236                         i__5].i * work[i__6].r;
00237                 q__2.r = a[i__4].r - q__3.r, q__2.i = a[i__4].i - q__3.i;
00238                 i__7 = *n + ii - i__ + 1;
00239                 i__8 = jj - i__ + 1;
00240                 q__4.r = work[i__7].r * work[i__8].r - work[i__7].i * work[
00241                         i__8].i, q__4.i = work[i__7].r * work[i__8].i + work[
00242                         i__7].i * work[i__8].r;
00243                 q__1.r = q__2.r - q__4.r, q__1.i = q__2.i - q__4.i;
00244                 a[i__3].r = q__1.r, a[i__3].i = q__1.i;
00245 /* L40: */
00246             }
00247 /* L50: */
00248         }
00249 /* L60: */
00250     }
00251 
00252 /*     Reduce number of subdiagonals to K */
00253 
00254     i__1 = *n - 1 - *k;
00255     for (i__ = 1; i__ <= i__1; ++i__) {
00256 
00257 /*        generate reflection to annihilate A(k+i+1:n,i) */
00258 
00259         i__2 = *n - *k - i__ + 1;
00260         wn = scnrm2_(&i__2, &a[*k + i__ + i__ * a_dim1], &c__1);
00261         r__1 = wn / c_abs(&a[*k + i__ + i__ * a_dim1]);
00262         i__2 = *k + i__ + i__ * a_dim1;
00263         q__1.r = r__1 * a[i__2].r, q__1.i = r__1 * a[i__2].i;
00264         wa.r = q__1.r, wa.i = q__1.i;
00265         if (wn == 0.f) {
00266             tau.r = 0.f, tau.i = 0.f;
00267         } else {
00268             i__2 = *k + i__ + i__ * a_dim1;
00269             q__1.r = a[i__2].r + wa.r, q__1.i = a[i__2].i + wa.i;
00270             wb.r = q__1.r, wb.i = q__1.i;
00271             i__2 = *n - *k - i__;
00272             c_div(&q__1, &c_b2, &wb);
00273             cscal_(&i__2, &q__1, &a[*k + i__ + 1 + i__ * a_dim1], &c__1);
00274             i__2 = *k + i__ + i__ * a_dim1;
00275             a[i__2].r = 1.f, a[i__2].i = 0.f;
00276             c_div(&q__1, &wb, &wa);
00277             r__1 = q__1.r;
00278             tau.r = r__1, tau.i = 0.f;
00279         }
00280 
00281 /*        apply reflection to A(k+i:n,i+1:k+i-1) from the left */
00282 
00283         i__2 = *n - *k - i__ + 1;
00284         i__3 = *k - 1;
00285         cgemv_("Conjugate transpose", &i__2, &i__3, &c_b2, &a[*k + i__ + (i__ 
00286                 + 1) * a_dim1], lda, &a[*k + i__ + i__ * a_dim1], &c__1, &
00287                 c_b1, &work[1], &c__1);
00288         i__2 = *n - *k - i__ + 1;
00289         i__3 = *k - 1;
00290         q__1.r = -tau.r, q__1.i = -tau.i;
00291         cgerc_(&i__2, &i__3, &q__1, &a[*k + i__ + i__ * a_dim1], &c__1, &work[
00292                 1], &c__1, &a[*k + i__ + (i__ + 1) * a_dim1], lda);
00293 
00294 /*        apply reflection to A(k+i:n,k+i:n) from the left and the right */
00295 
00296 /*        compute  y := tau * A * conjg(u) */
00297 
00298         i__2 = *n - *k - i__ + 1;
00299         clacgv_(&i__2, &a[*k + i__ + i__ * a_dim1], &c__1);
00300         i__2 = *n - *k - i__ + 1;
00301         csymv_("Lower", &i__2, &tau, &a[*k + i__ + (*k + i__) * a_dim1], lda, 
00302                 &a[*k + i__ + i__ * a_dim1], &c__1, &c_b1, &work[1], &c__1);
00303         i__2 = *n - *k - i__ + 1;
00304         clacgv_(&i__2, &a[*k + i__ + i__ * a_dim1], &c__1);
00305 
00306 /*        compute  v := y - 1/2 * tau * ( u, y ) * u */
00307 
00308         q__3.r = -.5f, q__3.i = -0.f;
00309         q__2.r = q__3.r * tau.r - q__3.i * tau.i, q__2.i = q__3.r * tau.i + 
00310                 q__3.i * tau.r;
00311         i__2 = *n - *k - i__ + 1;
00312         cdotc_(&q__4, &i__2, &a[*k + i__ + i__ * a_dim1], &c__1, &work[1], &
00313                 c__1);
00314         q__1.r = q__2.r * q__4.r - q__2.i * q__4.i, q__1.i = q__2.r * q__4.i 
00315                 + q__2.i * q__4.r;
00316         alpha.r = q__1.r, alpha.i = q__1.i;
00317         i__2 = *n - *k - i__ + 1;
00318         caxpy_(&i__2, &alpha, &a[*k + i__ + i__ * a_dim1], &c__1, &work[1], &
00319                 c__1);
00320 
00321 /*        apply symmetric rank-2 update to A(k+i:n,k+i:n) */
00322 
00323 /*        CALL CSYR2( 'Lower', N-K-I+1, -ONE, A( K+I, I ), 1, WORK, 1, */
00324 /*        $               A( K+I, K+I ), LDA ) */
00325 
00326         i__2 = *n;
00327         for (jj = *k + i__; jj <= i__2; ++jj) {
00328             i__3 = *n;
00329             for (ii = jj; ii <= i__3; ++ii) {
00330                 i__4 = ii + jj * a_dim1;
00331                 i__5 = ii + jj * a_dim1;
00332                 i__6 = ii + i__ * a_dim1;
00333                 i__7 = jj - *k - i__ + 1;
00334                 q__3.r = a[i__6].r * work[i__7].r - a[i__6].i * work[i__7].i, 
00335                         q__3.i = a[i__6].r * work[i__7].i + a[i__6].i * work[
00336                         i__7].r;
00337                 q__2.r = a[i__5].r - q__3.r, q__2.i = a[i__5].i - q__3.i;
00338                 i__8 = ii - *k - i__ + 1;
00339                 i__9 = jj + i__ * a_dim1;
00340                 q__4.r = work[i__8].r * a[i__9].r - work[i__8].i * a[i__9].i, 
00341                         q__4.i = work[i__8].r * a[i__9].i + work[i__8].i * a[
00342                         i__9].r;
00343                 q__1.r = q__2.r - q__4.r, q__1.i = q__2.i - q__4.i;
00344                 a[i__4].r = q__1.r, a[i__4].i = q__1.i;
00345 /* L70: */
00346             }
00347 /* L80: */
00348         }
00349 
00350         i__2 = *k + i__ + i__ * a_dim1;
00351         q__1.r = -wa.r, q__1.i = -wa.i;
00352         a[i__2].r = q__1.r, a[i__2].i = q__1.i;
00353         i__2 = *n;
00354         for (j = *k + i__ + 1; j <= i__2; ++j) {
00355             i__3 = j + i__ * a_dim1;
00356             a[i__3].r = 0.f, a[i__3].i = 0.f;
00357 /* L90: */
00358         }
00359 /* L100: */
00360     }
00361 
00362 /*     Store full symmetric matrix */
00363 
00364     i__1 = *n;
00365     for (j = 1; j <= i__1; ++j) {
00366         i__2 = *n;
00367         for (i__ = j + 1; i__ <= i__2; ++i__) {
00368             i__3 = j + i__ * a_dim1;
00369             i__4 = i__ + j * a_dim1;
00370             a[i__3].r = a[i__4].r, a[i__3].i = a[i__4].i;
00371 /* L110: */
00372         }
00373 /* L120: */
00374     }
00375     return 0;
00376 
00377 /*     End of CLAGSY */
00378 
00379 } /* clagsy_ */


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