LAPACK 3.12.1
LAPACK: Linear Algebra PACKage
Loading...
Searching...
No Matches

◆ slarfgp()

subroutine slarfgp ( integer n,
real alpha,
real, dimension( * ) x,
integer incx,
real tau )

SLARFGP generates an elementary reflector (Householder matrix) with non-negative beta.

Download SLARFGP + dependencies [TGZ] [ZIP] [TXT]

Purpose:
!>
!> SLARFGP generates a real elementary reflector H of order n, such
!> that
!>
!>       H * ( alpha ) = ( beta ),   H**T * H = I.
!>           (   x   )   (   0  )
!>
!> where alpha and beta are scalars, beta is non-negative, and x is
!> an (n-1)-element real vector.  H is represented in the form
!>
!>       H = I - tau * ( 1 ) * ( 1 v**T ) ,
!>                     ( v )
!>
!> where tau is a real scalar and v is a real (n-1)-element
!> vector.
!>
!> If the elements of x are all zero, then tau = 0 and H is taken to be
!> the unit matrix.
!> 
Parameters
[in]N
!>          N is INTEGER
!>          The order of the elementary reflector.
!> 
[in,out]ALPHA
!>          ALPHA is REAL
!>          On entry, the value alpha.
!>          On exit, it is overwritten with the value beta.
!> 
[in,out]X
!>          X is REAL array, dimension
!>                         (1+(N-2)*abs(INCX))
!>          On entry, the vector x.
!>          On exit, it is overwritten with the vector v.
!> 
[in]INCX
!>          INCX is INTEGER
!>          The increment between elements of X. INCX > 0.
!> 
[out]TAU
!>          TAU is REAL
!>          The value tau.
!> 
Author
Univ. of Tennessee
Univ. of California Berkeley
Univ. of Colorado Denver
NAG Ltd.

Definition at line 101 of file slarfgp.f.

102*
103* -- LAPACK auxiliary routine --
104* -- LAPACK is a software package provided by Univ. of Tennessee, --
105* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
106*
107* .. Scalar Arguments ..
108 INTEGER INCX, N
109 REAL ALPHA, TAU
110* ..
111* .. Array Arguments ..
112 REAL X( * )
113* ..
114*
115* =====================================================================
116*
117* .. Parameters ..
118 REAL TWO, ONE, ZERO
119 parameter( two = 2.0e+0, one = 1.0e+0, zero = 0.0e+0 )
120* ..
121* .. Local Scalars ..
122 INTEGER J, KNT
123 REAL BETA, BIGNUM, EPS, SAVEALPHA, SMLNUM, XNORM
124* ..
125* .. External Functions ..
126 REAL SLAMCH, SLAPY2, SNRM2
127 EXTERNAL slamch, slapy2, snrm2
128* ..
129* .. Intrinsic Functions ..
130 INTRINSIC abs, sign
131* ..
132* .. External Subroutines ..
133 EXTERNAL sscal
134* ..
135* .. Executable Statements ..
136*
137 IF( n.LE.0 ) THEN
138 tau = zero
139 RETURN
140 END IF
141*
142 eps = slamch( 'Precision' )
143 xnorm = snrm2( n-1, x, incx )
144*
145 IF( xnorm.LE.eps*abs(alpha) ) THEN
146*
147* H = [+/-1, 0; I], sign chosen so ALPHA >= 0.
148*
149 IF( alpha.GE.zero ) THEN
150* When TAU.eq.ZERO, the vector is special-cased to be
151* all zeros in the application routines. We do not need
152* to clear it.
153 tau = zero
154 ELSE
155* However, the application routines rely on explicit
156* zero checks when TAU.ne.ZERO, and we must clear X.
157 tau = two
158 DO j = 1, n-1
159 x( 1 + (j-1)*incx ) = 0
160 END DO
161 alpha = -alpha
162 END IF
163 ELSE
164*
165* general case
166*
167 beta = sign( slapy2( alpha, xnorm ), alpha )
168 smlnum = slamch( 'S' ) / slamch( 'E' )
169 knt = 0
170 IF( abs( beta ).LT.smlnum ) THEN
171*
172* XNORM, BETA may be inaccurate; scale X and recompute them
173*
174 bignum = one / smlnum
175 10 CONTINUE
176 knt = knt + 1
177 CALL sscal( n-1, bignum, x, incx )
178 beta = beta*bignum
179 alpha = alpha*bignum
180 IF( (abs( beta ).LT.smlnum) .AND. (knt .LT. 20) )
181 $ GO TO 10
182*
183* New BETA is at most 1, at least SMLNUM
184*
185 xnorm = snrm2( n-1, x, incx )
186 beta = sign( slapy2( alpha, xnorm ), alpha )
187 END IF
188 savealpha = alpha
189 alpha = alpha + beta
190 IF( beta.LT.zero ) THEN
191 beta = -beta
192 tau = -alpha / beta
193 ELSE
194 alpha = xnorm * (xnorm/alpha)
195 tau = alpha / beta
196 alpha = -alpha
197 END IF
198*
199 IF ( abs(tau).LE.smlnum ) THEN
200*
201* In the case where the computed TAU ends up being a denormalized number,
202* it loses relative accuracy. This is a BIG problem. Solution: flush TAU
203* to ZERO. This explains the next IF statement.
204*
205* (Bug report provided by Pat Quillen from MathWorks on Jul 29, 2009.)
206* (Thanks Pat. Thanks MathWorks.)
207*
208 IF( savealpha.GE.zero ) THEN
209 tau = zero
210 ELSE
211 tau = two
212 DO j = 1, n-1
213 x( 1 + (j-1)*incx ) = 0
214 END DO
215 beta = -savealpha
216 END IF
217*
218 ELSE
219*
220* This is the general case.
221*
222 CALL sscal( n-1, one / alpha, x, incx )
223*
224 END IF
225*
226* If BETA is subnormal, it may lose relative accuracy
227*
228 DO 20 j = 1, knt
229 beta = beta*smlnum
230 20 CONTINUE
231 alpha = beta
232 END IF
233*
234 RETURN
235*
236* End of SLARFGP
237*
real function slamch(cmach)
SLAMCH
Definition slamch.f:68
real function slapy2(x, y)
SLAPY2 returns sqrt(x2+y2).
Definition slapy2.f:61
real(wp) function snrm2(n, x, incx)
SNRM2
Definition snrm2.f90:89
subroutine sscal(n, sa, sx, incx)
SSCAL
Definition sscal.f:79
Here is the call graph for this function:
Here is the caller graph for this function: