1 *> \brief \b SLARFGP generates an elementary reflector (Householder matrix) with non-negative beta.
3 * =========== DOCUMENTATION ===========
5 * Online html documentation available at
6 * http://www.netlib.org/lapack/explore-html/
9 *> Download SLARFGP + dependencies
10 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/slarfgp.f">
12 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/slarfgp.f">
14 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/slarfgp.f">
21 * SUBROUTINE SLARFGP( N, ALPHA, X, INCX, TAU )
23 * .. Scalar Arguments ..
27 * .. Array Arguments ..
37 *> SLARFGP generates a real elementary reflector H of order n, such
40 *> H * ( alpha ) = ( beta ), H**T * H = I.
43 *> where alpha and beta are scalars, beta is non-negative, and x is
44 *> an (n-1)-element real vector. H is represented in the form
46 *> H = I - tau * ( 1 ) * ( 1 v**T ) ,
49 *> where tau is a real scalar and v is a real (n-1)-element
52 *> If the elements of x are all zero, then tau = 0 and H is taken to be
62 *> The order of the elementary reflector.
65 *> \param[in,out] ALPHA
68 *> On entry, the value alpha.
69 *> On exit, it is overwritten with the value beta.
74 *> X is REAL array, dimension
75 *> (1+(N-2)*abs(INCX))
76 *> On entry, the vector x.
77 *> On exit, it is overwritten with the vector v.
83 *> The increment between elements of X. INCX > 0.
95 *> \author Univ. of Tennessee
96 *> \author Univ. of California Berkeley
97 *> \author Univ. of Colorado Denver
100 *> \date November 2015
102 *> \ingroup realOTHERauxiliary
104 * =====================================================================
105 SUBROUTINE SLARFGP( N, ALPHA, X, INCX, TAU )
107 * -- LAPACK auxiliary routine (version 3.6.0) --
108 * -- LAPACK is a software package provided by Univ. of Tennessee, --
109 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
112 * .. Scalar Arguments ..
116 * .. Array Arguments ..
120 * =====================================================================
124 PARAMETER ( TWO = 2.0E+0, ONE = 1.0E+0, ZERO = 0.0E+0 )
126 * .. Local Scalars ..
128 REAL BETA, BIGNUM, SAVEALPHA, SMLNUM, XNORM
130 * .. External Functions ..
131 REAL SLAMCH, SLAPY2, SNRM2
132 EXTERNAL SLAMCH, SLAPY2, SNRM2
134 * .. Intrinsic Functions ..
137 * .. External Subroutines ..
140 * .. Executable Statements ..
147 XNORM = SNRM2( N-1, X, INCX )
149 IF( XNORM.EQ.ZERO ) THEN
151 * H = [+/-1, 0; I], sign chosen so ALPHA >= 0.
153 IF( ALPHA.GE.ZERO ) THEN
154 * When TAU.eq.ZERO, the vector is special-cased to be
155 * all zeros in the application routines. We do not need
159 * However, the application routines rely on explicit
160 * zero checks when TAU.ne.ZERO, and we must clear X.
163 X( 1 + (J-1)*INCX ) = 0
171 BETA = SIGN( SLAPY2( ALPHA, XNORM ), ALPHA )
172 SMLNUM = SLAMCH( 'S' ) / SLAMCH( 'E' )
174 IF( ABS( BETA ).LT.SMLNUM ) THEN
176 * XNORM, BETA may be inaccurate; scale X and recompute them
178 BIGNUM = ONE / SMLNUM
181 CALL SSCAL( N-1, BIGNUM, X, INCX )
184 IF( ABS( BETA ).LT.SMLNUM )
187 * New BETA is at most 1, at least SMLNUM
189 XNORM = SNRM2( N-1, X, INCX )
190 BETA = SIGN( SLAPY2( ALPHA, XNORM ), ALPHA )
194 IF( BETA.LT.ZERO ) THEN
198 ALPHA = XNORM * (XNORM/ALPHA)
203 IF ( ABS(TAU).LE.SMLNUM ) THEN
205 * In the case where the computed TAU ends up being a denormalized number,
206 * it loses relative accuracy. This is a BIG problem. Solution: flush TAU
207 * to ZERO. This explains the next IF statement.
209 * (Bug report provided by Pat Quillen from MathWorks on Jul 29, 2009.)
210 * (Thanks Pat. Thanks MathWorks.)
212 IF( SAVEALPHA.GE.ZERO ) THEN
217 X( 1 + (J-1)*INCX ) = 0
224 * This is the general case.
226 CALL SSCAL( N-1, ONE / ALPHA, X, INCX )
230 * If BETA is subnormal, it may lose relative accuracy