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


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