ssytd2.c
Go to the documentation of this file.
00001 /* ssytd2.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__1 = 1;
00019 static real c_b8 = 0.f;
00020 static real c_b14 = -1.f;
00021 
00022 /* Subroutine */ int ssytd2_(char *uplo, integer *n, real *a, integer *lda, 
00023         real *d__, real *e, real *tau, integer *info)
00024 {
00025     /* System generated locals */
00026     integer a_dim1, a_offset, i__1, i__2, i__3;
00027 
00028     /* Local variables */
00029     integer i__;
00030     real taui;
00031     extern doublereal sdot_(integer *, real *, integer *, real *, integer *);
00032     extern /* Subroutine */ int ssyr2_(char *, integer *, real *, real *, 
00033             integer *, real *, integer *, real *, integer *);
00034     real alpha;
00035     extern logical lsame_(char *, char *);
00036     logical upper;
00037     extern /* Subroutine */ int saxpy_(integer *, real *, real *, integer *, 
00038             real *, integer *), ssymv_(char *, integer *, real *, real *, 
00039             integer *, real *, integer *, real *, real *, integer *), 
00040             xerbla_(char *, integer *), slarfg_(integer *, real *, 
00041             real *, integer *, real *);
00042 
00043 
00044 /*  -- LAPACK routine (version 3.2) -- */
00045 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
00046 /*     November 2006 */
00047 
00048 /*     .. Scalar Arguments .. */
00049 /*     .. */
00050 /*     .. Array Arguments .. */
00051 /*     .. */
00052 
00053 /*  Purpose */
00054 /*  ======= */
00055 
00056 /*  SSYTD2 reduces a real symmetric matrix A to symmetric tridiagonal */
00057 /*  form T by an orthogonal similarity transformation: Q' * A * Q = T. */
00058 
00059 /*  Arguments */
00060 /*  ========= */
00061 
00062 /*  UPLO    (input) CHARACTER*1 */
00063 /*          Specifies whether the upper or lower triangular part of the */
00064 /*          symmetric matrix A is stored: */
00065 /*          = 'U':  Upper triangular */
00066 /*          = 'L':  Lower triangular */
00067 
00068 /*  N       (input) INTEGER */
00069 /*          The order of the matrix A.  N >= 0. */
00070 
00071 /*  A       (input/output) REAL array, dimension (LDA,N) */
00072 /*          On entry, the symmetric matrix A.  If UPLO = 'U', the leading */
00073 /*          n-by-n upper triangular part of A contains the upper */
00074 /*          triangular part of the matrix A, and the strictly lower */
00075 /*          triangular part of A is not referenced.  If UPLO = 'L', the */
00076 /*          leading n-by-n lower triangular part of A contains the lower */
00077 /*          triangular part of the matrix A, and the strictly upper */
00078 /*          triangular part of A is not referenced. */
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 orthogonal */
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 orthogonal matrix Q as a product */
00088 /*          of elementary reflectors. See Further Details. */
00089 
00090 /*  LDA     (input) INTEGER */
00091 /*          The leading dimension of the array A.  LDA >= max(1,N). */
00092 
00093 /*  D       (output) REAL array, dimension (N) */
00094 /*          The diagonal elements of the tridiagonal matrix T: */
00095 /*          D(i) = A(i,i). */
00096 
00097 /*  E       (output) REAL array, dimension (N-1) */
00098 /*          The off-diagonal elements of the tridiagonal matrix T: */
00099 /*          E(i) = A(i,i+1) if UPLO = 'U', E(i) = A(i+1,i) if UPLO = 'L'. */
00100 
00101 /*  TAU     (output) REAL array, dimension (N-1) */
00102 /*          The scalar factors of the elementary reflectors (see Further */
00103 /*          Details). */
00104 
00105 /*  INFO    (output) INTEGER */
00106 /*          = 0:  successful exit */
00107 /*          < 0:  if INFO = -i, the i-th argument had an illegal value. */
00108 
00109 /*  Further Details */
00110 /*  =============== */
00111 
00112 /*  If UPLO = 'U', the matrix Q is represented as a product of elementary */
00113 /*  reflectors */
00114 
00115 /*     Q = H(n-1) . . . H(2) H(1). */
00116 
00117 /*  Each H(i) has the form */
00118 
00119 /*     H(i) = I - tau * v * v' */
00120 
00121 /*  where tau is a real scalar, and v is a real vector with */
00122 /*  v(i+1:n) = 0 and v(i) = 1; v(1:i-1) is stored on exit in */
00123 /*  A(1:i-1,i+1), and tau in TAU(i). */
00124 
00125 /*  If UPLO = 'L', the matrix Q is represented as a product of elementary */
00126 /*  reflectors */
00127 
00128 /*     Q = H(1) H(2) . . . H(n-1). */
00129 
00130 /*  Each H(i) has the form */
00131 
00132 /*     H(i) = I - tau * v * v' */
00133 
00134 /*  where tau is a real scalar, and v is a real vector with */
00135 /*  v(1:i) = 0 and v(i+1) = 1; v(i+2:n) is stored on exit in A(i+2:n,i), */
00136 /*  and tau in TAU(i). */
00137 
00138 /*  The contents of A on exit are illustrated by the following examples */
00139 /*  with n = 5: */
00140 
00141 /*  if UPLO = 'U':                       if UPLO = 'L': */
00142 
00143 /*    (  d   e   v2  v3  v4 )              (  d                  ) */
00144 /*    (      d   e   v3  v4 )              (  e   d              ) */
00145 /*    (          d   e   v4 )              (  v1  e   d          ) */
00146 /*    (              d   e  )              (  v1  v2  e   d      ) */
00147 /*    (                  d  )              (  v1  v2  v3  e   d  ) */
00148 
00149 /*  where d and e denote diagonal and off-diagonal elements of T, and vi */
00150 /*  denotes an element of the vector defining H(i). */
00151 
00152 /*  ===================================================================== */
00153 
00154 /*     .. Parameters .. */
00155 /*     .. */
00156 /*     .. Local Scalars .. */
00157 /*     .. */
00158 /*     .. External Subroutines .. */
00159 /*     .. */
00160 /*     .. External Functions .. */
00161 /*     .. */
00162 /*     .. Intrinsic Functions .. */
00163 /*     .. */
00164 /*     .. Executable Statements .. */
00165 
00166 /*     Test the input parameters */
00167 
00168     /* Parameter adjustments */
00169     a_dim1 = *lda;
00170     a_offset = 1 + a_dim1;
00171     a -= a_offset;
00172     --d__;
00173     --e;
00174     --tau;
00175 
00176     /* Function Body */
00177     *info = 0;
00178     upper = lsame_(uplo, "U");
00179     if (! upper && ! lsame_(uplo, "L")) {
00180         *info = -1;
00181     } else if (*n < 0) {
00182         *info = -2;
00183     } else if (*lda < max(1,*n)) {
00184         *info = -4;
00185     }
00186     if (*info != 0) {
00187         i__1 = -(*info);
00188         xerbla_("SSYTD2", &i__1);
00189         return 0;
00190     }
00191 
00192 /*     Quick return if possible */
00193 
00194     if (*n <= 0) {
00195         return 0;
00196     }
00197 
00198     if (upper) {
00199 
00200 /*        Reduce the upper triangle of A */
00201 
00202         for (i__ = *n - 1; i__ >= 1; --i__) {
00203 
00204 /*           Generate elementary reflector H(i) = I - tau * v * v' */
00205 /*           to annihilate A(1:i-1,i+1) */
00206 
00207             slarfg_(&i__, &a[i__ + (i__ + 1) * a_dim1], &a[(i__ + 1) * a_dim1 
00208                     + 1], &c__1, &taui);
00209             e[i__] = a[i__ + (i__ + 1) * a_dim1];
00210 
00211             if (taui != 0.f) {
00212 
00213 /*              Apply H(i) from both sides to A(1:i,1:i) */
00214 
00215                 a[i__ + (i__ + 1) * a_dim1] = 1.f;
00216 
00217 /*              Compute  x := tau * A * v  storing x in TAU(1:i) */
00218 
00219                 ssymv_(uplo, &i__, &taui, &a[a_offset], lda, &a[(i__ + 1) * 
00220                         a_dim1 + 1], &c__1, &c_b8, &tau[1], &c__1);
00221 
00222 /*              Compute  w := x - 1/2 * tau * (x'*v) * v */
00223 
00224                 alpha = taui * -.5f * sdot_(&i__, &tau[1], &c__1, &a[(i__ + 1)
00225                          * a_dim1 + 1], &c__1);
00226                 saxpy_(&i__, &alpha, &a[(i__ + 1) * a_dim1 + 1], &c__1, &tau[
00227                         1], &c__1);
00228 
00229 /*              Apply the transformation as a rank-2 update: */
00230 /*                 A := A - v * w' - w * v' */
00231 
00232                 ssyr2_(uplo, &i__, &c_b14, &a[(i__ + 1) * a_dim1 + 1], &c__1, 
00233                         &tau[1], &c__1, &a[a_offset], lda);
00234 
00235                 a[i__ + (i__ + 1) * a_dim1] = e[i__];
00236             }
00237             d__[i__ + 1] = a[i__ + 1 + (i__ + 1) * a_dim1];
00238             tau[i__] = taui;
00239 /* L10: */
00240         }
00241         d__[1] = a[a_dim1 + 1];
00242     } else {
00243 
00244 /*        Reduce the lower triangle of A */
00245 
00246         i__1 = *n - 1;
00247         for (i__ = 1; i__ <= i__1; ++i__) {
00248 
00249 /*           Generate elementary reflector H(i) = I - tau * v * v' */
00250 /*           to annihilate A(i+2:n,i) */
00251 
00252             i__2 = *n - i__;
00253 /* Computing MIN */
00254             i__3 = i__ + 2;
00255             slarfg_(&i__2, &a[i__ + 1 + i__ * a_dim1], &a[min(i__3, *n)+ i__ *
00256                      a_dim1], &c__1, &taui);
00257             e[i__] = a[i__ + 1 + i__ * a_dim1];
00258 
00259             if (taui != 0.f) {
00260 
00261 /*              Apply H(i) from both sides to A(i+1:n,i+1:n) */
00262 
00263                 a[i__ + 1 + i__ * a_dim1] = 1.f;
00264 
00265 /*              Compute  x := tau * A * v  storing y in TAU(i:n-1) */
00266 
00267                 i__2 = *n - i__;
00268                 ssymv_(uplo, &i__2, &taui, &a[i__ + 1 + (i__ + 1) * a_dim1], 
00269                         lda, &a[i__ + 1 + i__ * a_dim1], &c__1, &c_b8, &tau[
00270                         i__], &c__1);
00271 
00272 /*              Compute  w := x - 1/2 * tau * (x'*v) * v */
00273 
00274                 i__2 = *n - i__;
00275                 alpha = taui * -.5f * sdot_(&i__2, &tau[i__], &c__1, &a[i__ + 
00276                         1 + i__ * a_dim1], &c__1);
00277                 i__2 = *n - i__;
00278                 saxpy_(&i__2, &alpha, &a[i__ + 1 + i__ * a_dim1], &c__1, &tau[
00279                         i__], &c__1);
00280 
00281 /*              Apply the transformation as a rank-2 update: */
00282 /*                 A := A - v * w' - w * v' */
00283 
00284                 i__2 = *n - i__;
00285                 ssyr2_(uplo, &i__2, &c_b14, &a[i__ + 1 + i__ * a_dim1], &c__1, 
00286                          &tau[i__], &c__1, &a[i__ + 1 + (i__ + 1) * a_dim1], 
00287                         lda);
00288 
00289                 a[i__ + 1 + i__ * a_dim1] = e[i__];
00290             }
00291             d__[i__] = a[i__ + i__ * a_dim1];
00292             tau[i__] = taui;
00293 /* L20: */
00294         }
00295         d__[*n] = a[*n + *n * a_dim1];
00296     }
00297 
00298     return 0;
00299 
00300 /*     End of SSYTD2 */
00301 
00302 } /* ssytd2_ */


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