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

◆ slarfg()

subroutine slarfg ( integer  N,
real  ALPHA,
real, dimension( * )  X,
integer  INCX,
real  TAU 
)

SLARFG generates an elementary reflector (Householder matrix).

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

Purpose:
 SLARFG 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, 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.

 Otherwise  1 <= tau <= 2.
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 105 of file slarfg.f.

106*
107* -- LAPACK auxiliary routine --
108* -- LAPACK is a software package provided by Univ. of Tennessee, --
109* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
110*
111* .. Scalar Arguments ..
112 INTEGER INCX, N
113 REAL ALPHA, TAU
114* ..
115* .. Array Arguments ..
116 REAL X( * )
117* ..
118*
119* =====================================================================
120*
121* .. Parameters ..
122 REAL ONE, ZERO
123 parameter( one = 1.0e+0, zero = 0.0e+0 )
124* ..
125* .. Local Scalars ..
126 INTEGER J, KNT
127 REAL BETA, RSAFMN, SAFMIN, XNORM
128* ..
129* .. External Functions ..
130 REAL SLAMCH, SLAPY2, SNRM2
131 EXTERNAL slamch, slapy2, snrm2
132* ..
133* .. Intrinsic Functions ..
134 INTRINSIC abs, sign
135* ..
136* .. External Subroutines ..
137 EXTERNAL sscal
138* ..
139* .. Executable Statements ..
140*
141 IF( n.LE.1 ) THEN
142 tau = zero
143 RETURN
144 END IF
145*
146 xnorm = snrm2( n-1, x, incx )
147*
148 IF( xnorm.EQ.zero ) THEN
149*
150* H = I
151*
152 tau = zero
153 ELSE
154*
155* general case
156*
157 beta = -sign( slapy2( alpha, xnorm ), alpha )
158 safmin = slamch( 'S' ) / slamch( 'E' )
159 knt = 0
160 IF( abs( beta ).LT.safmin ) THEN
161*
162* XNORM, BETA may be inaccurate; scale X and recompute them
163*
164 rsafmn = one / safmin
165 10 CONTINUE
166 knt = knt + 1
167 CALL sscal( n-1, rsafmn, x, incx )
168 beta = beta*rsafmn
169 alpha = alpha*rsafmn
170 IF( (abs( beta ).LT.safmin) .AND. (knt .LT. 20) )
171 $ GO TO 10
172*
173* New BETA is at most 1, at least SAFMIN
174*
175 xnorm = snrm2( n-1, x, incx )
176 beta = -sign( slapy2( alpha, xnorm ), alpha )
177 END IF
178 tau = ( beta-alpha ) / beta
179 CALL sscal( n-1, one / ( alpha-beta ), x, incx )
180*
181* If ALPHA is subnormal, it may lose relative accuracy
182*
183 DO 20 j = 1, knt
184 beta = beta*safmin
185 20 CONTINUE
186 alpha = beta
187 END IF
188*
189 RETURN
190*
191* End of SLARFG
192*
real function slapy2(X, Y)
SLAPY2 returns sqrt(x2+y2).
Definition: slapy2.f:63
subroutine sscal(N, SA, SX, INCX)
SSCAL
Definition: sscal.f:79
real(wp) function snrm2(n, x, incx)
SNRM2
Definition: snrm2.f90:89
real function slamch(CMACH)
SLAMCH
Definition: slamch.f:68
Here is the call graph for this function:
Here is the caller graph for this function: