LAPACK 3.12.0
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 103 of file slarfgp.f.

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