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


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