slahr2.c
Go to the documentation of this file.
00001 /* slahr2.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 real c_b4 = -1.f;
00019 static real c_b5 = 1.f;
00020 static integer c__1 = 1;
00021 static real c_b38 = 0.f;
00022 
00023 /* Subroutine */ int slahr2_(integer *n, integer *k, integer *nb, real *a, 
00024         integer *lda, real *tau, real *t, integer *ldt, real *y, integer *ldy)
00025 {
00026     /* System generated locals */
00027     integer a_dim1, a_offset, t_dim1, t_offset, y_dim1, y_offset, i__1, i__2, 
00028             i__3;
00029     real r__1;
00030 
00031     /* Local variables */
00032     integer i__;
00033     real ei;
00034     extern /* Subroutine */ int sscal_(integer *, real *, real *, integer *), 
00035             sgemm_(char *, char *, integer *, integer *, integer *, real *, 
00036             real *, integer *, real *, integer *, real *, real *, integer *), sgemv_(char *, integer *, integer *, real *, 
00037             real *, integer *, real *, integer *, real *, real *, integer *), scopy_(integer *, real *, integer *, real *, integer *), 
00038             strmm_(char *, char *, char *, char *, integer *, integer *, real 
00039             *, real *, integer *, real *, integer *), saxpy_(integer *, real *, real *, integer *, real *, 
00040             integer *), strmv_(char *, char *, char *, integer *, real *, 
00041             integer *, real *, integer *), slarfg_(
00042             integer *, real *, real *, integer *, real *), slacpy_(char *, 
00043             integer *, integer *, real *, integer *, real *, integer *);
00044 
00045 
00046 /*  -- LAPACK auxiliary routine (version 3.2) -- */
00047 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
00048 /*     November 2006 */
00049 
00050 /*     .. Scalar Arguments .. */
00051 /*     .. */
00052 /*     .. Array Arguments .. */
00053 /*     .. */
00054 
00055 /*  Purpose */
00056 /*  ======= */
00057 
00058 /*  SLAHR2 reduces the first NB columns of A real general n-BY-(n-k+1) */
00059 /*  matrix A so that elements below the k-th subdiagonal are zero. The */
00060 /*  reduction is performed by an orthogonal similarity transformation */
00061 /*  Q' * A * Q. The routine returns the matrices V and T which determine */
00062 /*  Q as a block reflector I - V*T*V', and also the matrix Y = A * V * T. */
00063 
00064 /*  This is an auxiliary routine called by SGEHRD. */
00065 
00066 /*  Arguments */
00067 /*  ========= */
00068 
00069 /*  N       (input) INTEGER */
00070 /*          The order of the matrix A. */
00071 
00072 /*  K       (input) INTEGER */
00073 /*          The offset for the reduction. Elements below the k-th */
00074 /*          subdiagonal in the first NB columns are reduced to zero. */
00075 /*          K < N. */
00076 
00077 /*  NB      (input) INTEGER */
00078 /*          The number of columns to be reduced. */
00079 
00080 /*  A       (input/output) REAL array, dimension (LDA,N-K+1) */
00081 /*          On entry, the n-by-(n-k+1) general matrix A. */
00082 /*          On exit, the elements on and above the k-th subdiagonal in */
00083 /*          the first NB columns are overwritten with the corresponding */
00084 /*          elements of the reduced matrix; the elements below the k-th */
00085 /*          subdiagonal, with the array TAU, represent the matrix Q as a */
00086 /*          product of elementary reflectors. The other columns of A are */
00087 /*          unchanged. See Further Details. */
00088 
00089 /*  LDA     (input) INTEGER */
00090 /*          The leading dimension of the array A.  LDA >= max(1,N). */
00091 
00092 /*  TAU     (output) REAL array, dimension (NB) */
00093 /*          The scalar factors of the elementary reflectors. See Further */
00094 /*          Details. */
00095 
00096 /*  T       (output) REAL array, dimension (LDT,NB) */
00097 /*          The upper triangular matrix T. */
00098 
00099 /*  LDT     (input) INTEGER */
00100 /*          The leading dimension of the array T.  LDT >= NB. */
00101 
00102 /*  Y       (output) REAL array, dimension (LDY,NB) */
00103 /*          The n-by-nb matrix Y. */
00104 
00105 /*  LDY     (input) INTEGER */
00106 /*          The leading dimension of the array Y. LDY >= N. */
00107 
00108 /*  Further Details */
00109 /*  =============== */
00110 
00111 /*  The matrix Q is represented as a product of nb elementary reflectors */
00112 
00113 /*     Q = H(1) H(2) . . . H(nb). */
00114 
00115 /*  Each H(i) has the form */
00116 
00117 /*     H(i) = I - tau * v * v' */
00118 
00119 /*  where tau is a real scalar, and v is a real vector with */
00120 /*  v(1:i+k-1) = 0, v(i+k) = 1; v(i+k+1:n) is stored on exit in */
00121 /*  A(i+k+1:n,i), and tau in TAU(i). */
00122 
00123 /*  The elements of the vectors v together form the (n-k+1)-by-nb matrix */
00124 /*  V which is needed, with T and Y, to apply the transformation to the */
00125 /*  unreduced part of the matrix, using an update of the form: */
00126 /*  A := (I - V*T*V') * (A - Y*V'). */
00127 
00128 /*  The contents of A on exit are illustrated by the following example */
00129 /*  with n = 7, k = 3 and nb = 2: */
00130 
00131 /*     ( a   a   a   a   a ) */
00132 /*     ( a   a   a   a   a ) */
00133 /*     ( a   a   a   a   a ) */
00134 /*     ( h   h   a   a   a ) */
00135 /*     ( v1  h   a   a   a ) */
00136 /*     ( v1  v2  a   a   a ) */
00137 /*     ( v1  v2  a   a   a ) */
00138 
00139 /*  where a denotes an element of the original matrix A, h denotes a */
00140 /*  modified element of the upper Hessenberg matrix H, and vi denotes an */
00141 /*  element of the vector defining H(i). */
00142 
00143 /*  This file is a slight modification of LAPACK-3.0's SLAHRD */
00144 /*  incorporating improvements proposed by Quintana-Orti and Van de */
00145 /*  Gejin. Note that the entries of A(1:K,2:NB) differ from those */
00146 /*  returned by the original LAPACK routine. This function is */
00147 /*  not backward compatible with LAPACK3.0. */
00148 
00149 /*  ===================================================================== */
00150 
00151 /*     .. Parameters .. */
00152 /*     .. */
00153 /*     .. Local Scalars .. */
00154 /*     .. */
00155 /*     .. External Subroutines .. */
00156 /*     .. */
00157 /*     .. Intrinsic Functions .. */
00158 /*     .. */
00159 /*     .. Executable Statements .. */
00160 
00161 /*     Quick return if possible */
00162 
00163     /* Parameter adjustments */
00164     --tau;
00165     a_dim1 = *lda;
00166     a_offset = 1 + a_dim1;
00167     a -= a_offset;
00168     t_dim1 = *ldt;
00169     t_offset = 1 + t_dim1;
00170     t -= t_offset;
00171     y_dim1 = *ldy;
00172     y_offset = 1 + y_dim1;
00173     y -= y_offset;
00174 
00175     /* Function Body */
00176     if (*n <= 1) {
00177         return 0;
00178     }
00179 
00180     i__1 = *nb;
00181     for (i__ = 1; i__ <= i__1; ++i__) {
00182         if (i__ > 1) {
00183 
00184 /*           Update A(K+1:N,I) */
00185 
00186 /*           Update I-th column of A - Y * V' */
00187 
00188             i__2 = *n - *k;
00189             i__3 = i__ - 1;
00190             sgemv_("NO TRANSPOSE", &i__2, &i__3, &c_b4, &y[*k + 1 + y_dim1], 
00191                     ldy, &a[*k + i__ - 1 + a_dim1], lda, &c_b5, &a[*k + 1 + 
00192                     i__ * a_dim1], &c__1);
00193 
00194 /*           Apply I - V * T' * V' to this column (call it b) from the */
00195 /*           left, using the last column of T as workspace */
00196 
00197 /*           Let  V = ( V1 )   and   b = ( b1 )   (first I-1 rows) */
00198 /*                    ( V2 )             ( b2 ) */
00199 
00200 /*           where V1 is unit lower triangular */
00201 
00202 /*           w := V1' * b1 */
00203 
00204             i__2 = i__ - 1;
00205             scopy_(&i__2, &a[*k + 1 + i__ * a_dim1], &c__1, &t[*nb * t_dim1 + 
00206                     1], &c__1);
00207             i__2 = i__ - 1;
00208             strmv_("Lower", "Transpose", "UNIT", &i__2, &a[*k + 1 + a_dim1], 
00209                     lda, &t[*nb * t_dim1 + 1], &c__1);
00210 
00211 /*           w := w + V2'*b2 */
00212 
00213             i__2 = *n - *k - i__ + 1;
00214             i__3 = i__ - 1;
00215             sgemv_("Transpose", &i__2, &i__3, &c_b5, &a[*k + i__ + a_dim1], 
00216                     lda, &a[*k + i__ + i__ * a_dim1], &c__1, &c_b5, &t[*nb * 
00217                     t_dim1 + 1], &c__1);
00218 
00219 /*           w := T'*w */
00220 
00221             i__2 = i__ - 1;
00222             strmv_("Upper", "Transpose", "NON-UNIT", &i__2, &t[t_offset], ldt, 
00223                      &t[*nb * t_dim1 + 1], &c__1);
00224 
00225 /*           b2 := b2 - V2*w */
00226 
00227             i__2 = *n - *k - i__ + 1;
00228             i__3 = i__ - 1;
00229             sgemv_("NO TRANSPOSE", &i__2, &i__3, &c_b4, &a[*k + i__ + a_dim1], 
00230                      lda, &t[*nb * t_dim1 + 1], &c__1, &c_b5, &a[*k + i__ + 
00231                     i__ * a_dim1], &c__1);
00232 
00233 /*           b1 := b1 - V1*w */
00234 
00235             i__2 = i__ - 1;
00236             strmv_("Lower", "NO TRANSPOSE", "UNIT", &i__2, &a[*k + 1 + a_dim1]
00237 , lda, &t[*nb * t_dim1 + 1], &c__1);
00238             i__2 = i__ - 1;
00239             saxpy_(&i__2, &c_b4, &t[*nb * t_dim1 + 1], &c__1, &a[*k + 1 + i__ 
00240                     * a_dim1], &c__1);
00241 
00242             a[*k + i__ - 1 + (i__ - 1) * a_dim1] = ei;
00243         }
00244 
00245 /*        Generate the elementary reflector H(I) to annihilate */
00246 /*        A(K+I+1:N,I) */
00247 
00248         i__2 = *n - *k - i__ + 1;
00249 /* Computing MIN */
00250         i__3 = *k + i__ + 1;
00251         slarfg_(&i__2, &a[*k + i__ + i__ * a_dim1], &a[min(i__3, *n)+ i__ * 
00252                 a_dim1], &c__1, &tau[i__]);
00253         ei = a[*k + i__ + i__ * a_dim1];
00254         a[*k + i__ + i__ * a_dim1] = 1.f;
00255 
00256 /*        Compute  Y(K+1:N,I) */
00257 
00258         i__2 = *n - *k;
00259         i__3 = *n - *k - i__ + 1;
00260         sgemv_("NO TRANSPOSE", &i__2, &i__3, &c_b5, &a[*k + 1 + (i__ + 1) * 
00261                 a_dim1], lda, &a[*k + i__ + i__ * a_dim1], &c__1, &c_b38, &y[*
00262                 k + 1 + i__ * y_dim1], &c__1);
00263         i__2 = *n - *k - i__ + 1;
00264         i__3 = i__ - 1;
00265         sgemv_("Transpose", &i__2, &i__3, &c_b5, &a[*k + i__ + a_dim1], lda, &
00266                 a[*k + i__ + i__ * a_dim1], &c__1, &c_b38, &t[i__ * t_dim1 + 
00267                 1], &c__1);
00268         i__2 = *n - *k;
00269         i__3 = i__ - 1;
00270         sgemv_("NO TRANSPOSE", &i__2, &i__3, &c_b4, &y[*k + 1 + y_dim1], ldy, 
00271                 &t[i__ * t_dim1 + 1], &c__1, &c_b5, &y[*k + 1 + i__ * y_dim1], 
00272                  &c__1);
00273         i__2 = *n - *k;
00274         sscal_(&i__2, &tau[i__], &y[*k + 1 + i__ * y_dim1], &c__1);
00275 
00276 /*        Compute T(1:I,I) */
00277 
00278         i__2 = i__ - 1;
00279         r__1 = -tau[i__];
00280         sscal_(&i__2, &r__1, &t[i__ * t_dim1 + 1], &c__1);
00281         i__2 = i__ - 1;
00282         strmv_("Upper", "No Transpose", "NON-UNIT", &i__2, &t[t_offset], ldt, 
00283                 &t[i__ * t_dim1 + 1], &c__1)
00284                 ;
00285         t[i__ + i__ * t_dim1] = tau[i__];
00286 
00287 /* L10: */
00288     }
00289     a[*k + *nb + *nb * a_dim1] = ei;
00290 
00291 /*     Compute Y(1:K,1:NB) */
00292 
00293     slacpy_("ALL", k, nb, &a[(a_dim1 << 1) + 1], lda, &y[y_offset], ldy);
00294     strmm_("RIGHT", "Lower", "NO TRANSPOSE", "UNIT", k, nb, &c_b5, &a[*k + 1 
00295             + a_dim1], lda, &y[y_offset], ldy);
00296     if (*n > *k + *nb) {
00297         i__1 = *n - *k - *nb;
00298         sgemm_("NO TRANSPOSE", "NO TRANSPOSE", k, nb, &i__1, &c_b5, &a[(*nb + 
00299                 2) * a_dim1 + 1], lda, &a[*k + 1 + *nb + a_dim1], lda, &c_b5, 
00300                 &y[y_offset], ldy);
00301     }
00302     strmm_("RIGHT", "Upper", "NO TRANSPOSE", "NON-UNIT", k, nb, &c_b5, &t[
00303             t_offset], ldt, &y[y_offset], ldy);
00304 
00305     return 0;
00306 
00307 /*     End of SLAHR2 */
00308 
00309 } /* slahr2_ */


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