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

## ◆ clarfgp()

 subroutine clarfgp ( integer n, complex alpha, complex, dimension( * ) x, integer incx, complex tau )

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

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

Purpose:
``` CLARFGP generates a complex elementary reflector H of order n, such
that

H**H * ( alpha ) = ( beta ),   H**H * H = I.
(   x   )   (   0  )

where alpha and beta are scalars, beta is real and non-negative, and
x is an (n-1)-element complex vector.  H is represented in the form

H = I - tau * ( 1 ) * ( 1 v**H ) ,
( v )

where tau is a complex scalar and v is a complex (n-1)-element
vector. Note that H is not hermitian.

If the elements of x are all zero and alpha is real, 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 COMPLEX On entry, the value alpha. On exit, it is overwritten with the value beta.``` [in,out] X ``` X is COMPLEX 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 COMPLEX The value tau.```

Definition at line 103 of file clarfgp.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 COMPLEX ALPHA, TAU
112* ..
113* .. Array Arguments ..
114 COMPLEX 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 ALPHI, ALPHR, BETA, BIGNUM, EPS, SMLNUM, XNORM
126 COMPLEX SAVEALPHA
127* ..
128* .. External Functions ..
129 REAL SCNRM2, SLAMCH, SLAPY3, SLAPY2
130 COMPLEX CLADIV
131 EXTERNAL scnrm2, slamch, slapy3, slapy2, cladiv
132* ..
133* .. Intrinsic Functions ..
134 INTRINSIC abs, aimag, cmplx, real, sign
135* ..
136* .. External Subroutines ..
137 EXTERNAL cscal, csscal
138* ..
139* .. Executable Statements ..
140*
141 IF( n.LE.0 ) THEN
142 tau = zero
143 RETURN
144 END IF
145*
146 eps = slamch( 'Precision' )
147 xnorm = scnrm2( n-1, x, incx )
148 alphr = real( alpha )
149 alphi = aimag( alpha )
150*
151 IF( xnorm.LE.eps*abs(alpha) ) THEN
152*
153* H = [1-alpha/abs(alpha) 0; 0 I], sign chosen so ALPHA >= 0.
154*
155 IF( alphi.EQ.zero ) THEN
156 IF( alphr.GE.zero ) THEN
157* When TAU.eq.ZERO, the vector is special-cased to be
158* all zeros in the application routines. We do not need
159* to clear it.
160 tau = zero
161 ELSE
162* However, the application routines rely on explicit
163* zero checks when TAU.ne.ZERO, and we must clear X.
164 tau = two
165 DO j = 1, n-1
166 x( 1 + (j-1)*incx ) = zero
167 END DO
168 alpha = -alpha
169 END IF
170 ELSE
171* Only "reflecting" the diagonal entry to be real and non-negative.
172 xnorm = slapy2( alphr, alphi )
173 tau = cmplx( one - alphr / xnorm, -alphi / xnorm )
174 DO j = 1, n-1
175 x( 1 + (j-1)*incx ) = zero
176 END DO
177 alpha = xnorm
178 END IF
179 ELSE
180*
181* general case
182*
183 beta = sign( slapy3( alphr, alphi, xnorm ), alphr )
184 smlnum = slamch( 'S' ) / slamch( 'E' )
185 bignum = one / smlnum
186*
187 knt = 0
188 IF( abs( beta ).LT.smlnum ) THEN
189*
190* XNORM, BETA may be inaccurate; scale X and recompute them
191*
192 10 CONTINUE
193 knt = knt + 1
194 CALL csscal( n-1, bignum, x, incx )
195 beta = beta*bignum
196 alphi = alphi*bignum
197 alphr = alphr*bignum
198 IF( (abs( beta ).LT.smlnum) .AND. (knt .LT. 20) )
199 \$ GO TO 10
200*
201* New BETA is at most 1, at least SMLNUM
202*
203 xnorm = scnrm2( n-1, x, incx )
204 alpha = cmplx( alphr, alphi )
205 beta = sign( slapy3( alphr, alphi, xnorm ), alphr )
206 END IF
207 savealpha = alpha
208 alpha = alpha + beta
209 IF( beta.LT.zero ) THEN
210 beta = -beta
211 tau = -alpha / beta
212 ELSE
213 alphr = alphi * (alphi/real( alpha ))
214 alphr = alphr + xnorm * (xnorm/real( alpha ))
215 tau = cmplx( alphr/beta, -alphi/beta )
216 alpha = cmplx( -alphr, alphi )
217 END IF
218 alpha = cladiv( cmplx( one ), alpha )
219*
220 IF ( abs(tau).LE.smlnum ) THEN
221*
222* In the case where the computed TAU ends up being a denormalized number,
223* it loses relative accuracy. This is a BIG problem. Solution: flush TAU
224* to ZERO (or TWO or whatever makes a nonnegative real number for BETA).
225*
226* (Bug report provided by Pat Quillen from MathWorks on Jul 29, 2009.)
227* (Thanks Pat. Thanks MathWorks.)
228*
229 alphr = real( savealpha )
230 alphi = aimag( savealpha )
231 IF( alphi.EQ.zero ) THEN
232 IF( alphr.GE.zero ) THEN
233 tau = zero
234 ELSE
235 tau = two
236 DO j = 1, n-1
237 x( 1 + (j-1)*incx ) = zero
238 END DO
239 beta = real( -savealpha )
240 END IF
241 ELSE
242 xnorm = slapy2( alphr, alphi )
243 tau = cmplx( one - alphr / xnorm, -alphi / xnorm )
244 DO j = 1, n-1
245 x( 1 + (j-1)*incx ) = zero
246 END DO
247 beta = xnorm
248 END IF
249*
250 ELSE
251*
252* This is the general case.
253*
254 CALL cscal( n-1, alpha, x, incx )
255*
256 END IF
257*
258* If BETA is subnormal, it may lose relative accuracy
259*
260 DO 20 j = 1, knt
261 beta = beta*smlnum
262 20 CONTINUE
263 alpha = beta
264 END IF
265*
266 RETURN
267*
268* End of CLARFGP
269*
complex function cladiv(x, y)
CLADIV performs complex division in real arithmetic, avoiding unnecessary overflow.
Definition cladiv.f:64
real function slamch(cmach)
SLAMCH
Definition slamch.f:68
real function slapy2(x, y)
SLAPY2 returns sqrt(x2+y2).
Definition slapy2.f:63
real function slapy3(x, y, z)
SLAPY3 returns sqrt(x2+y2+z2).
Definition slapy3.f:68
real(wp) function scnrm2(n, x, incx)
SCNRM2
Definition scnrm2.f90:90
subroutine csscal(n, sa, cx, incx)
CSSCAL
Definition csscal.f:78
subroutine cscal(n, ca, cx, incx)
CSCAL
Definition cscal.f:78
Here is the call graph for this function:
Here is the caller graph for this function: