LAPACK 3.12.1
LAPACK: Linear Algebra PACKage
Loading...
Searching...
No Matches
zlarfgp.f
Go to the documentation of this file.
1*> \brief \b ZLARFGP generates an elementary reflector (Householder matrix) with non-negative beta.
2*
3* =========== DOCUMENTATION ===========
4*
5* Online html documentation available at
6* http://www.netlib.org/lapack/explore-html/
7*
8*> Download ZLARFGP + dependencies
9*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/zlarfgp.f">
10*> [TGZ]</a>
11*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/zlarfgp.f">
12*> [ZIP]</a>
13*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/zlarfgp.f">
14*> [TXT]</a>
15*
16* Definition:
17* ===========
18*
19* SUBROUTINE ZLARFGP( N, ALPHA, X, INCX, TAU )
20*
21* .. Scalar Arguments ..
22* INTEGER INCX, N
23* COMPLEX*16 ALPHA, TAU
24* ..
25* .. Array Arguments ..
26* COMPLEX*16 X( * )
27* ..
28*
29*
30*> \par Purpose:
31* =============
32*>
33*> \verbatim
34*>
35*> ZLARFGP generates a complex elementary reflector H of order n, such
36*> that
37*>
38*> H**H * ( alpha ) = ( beta ), H**H * H = I.
39*> ( x ) ( 0 )
40*>
41*> where alpha and beta are scalars, beta is real and non-negative, and
42*> x is an (n-1)-element complex vector. H is represented in the form
43*>
44*> H = I - tau * ( 1 ) * ( 1 v**H ) ,
45*> ( v )
46*>
47*> where tau is a complex scalar and v is a complex (n-1)-element
48*> vector. Note that H is not hermitian.
49*>
50*> If the elements of x are all zero and alpha is real, then tau = 0
51*> and H is taken to be the unit matrix.
52*> \endverbatim
53*
54* Arguments:
55* ==========
56*
57*> \param[in] N
58*> \verbatim
59*> N is INTEGER
60*> The order of the elementary reflector.
61*> \endverbatim
62*>
63*> \param[in,out] ALPHA
64*> \verbatim
65*> ALPHA is COMPLEX*16
66*> On entry, the value alpha.
67*> On exit, it is overwritten with the value beta.
68*> \endverbatim
69*>
70*> \param[in,out] X
71*> \verbatim
72*> X is COMPLEX*16 array, dimension
73*> (1+(N-2)*abs(INCX))
74*> On entry, the vector x.
75*> On exit, it is overwritten with the vector v.
76*> \endverbatim
77*>
78*> \param[in] INCX
79*> \verbatim
80*> INCX is INTEGER
81*> The increment between elements of X. INCX > 0.
82*> \endverbatim
83*>
84*> \param[out] TAU
85*> \verbatim
86*> TAU is COMPLEX*16
87*> The value tau.
88*> \endverbatim
89*
90* Authors:
91* ========
92*
93*> \author Univ. of Tennessee
94*> \author Univ. of California Berkeley
95*> \author Univ. of Colorado Denver
96*> \author NAG Ltd.
97*
98*> \ingroup larfgp
99*
100* =====================================================================
101 SUBROUTINE zlarfgp( N, ALPHA, X, INCX, TAU )
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 COMPLEX*16 ALPHA, TAU
110* ..
111* .. Array Arguments ..
112 COMPLEX*16 X( * )
113* ..
114*
115* =====================================================================
116*
117* .. Parameters ..
118 DOUBLE PRECISION TWO, ONE, ZERO
119 parameter( two = 2.0d+0, one = 1.0d+0, zero = 0.0d+0 )
120* ..
121* .. Local Scalars ..
122 INTEGER J, KNT
123 DOUBLE PRECISION ALPHI, ALPHR, BETA, BIGNUM, EPS, SMLNUM, XNORM
124 COMPLEX*16 SAVEALPHA
125* ..
126* .. External Functions ..
127 DOUBLE PRECISION DLAMCH, DLAPY3, DLAPY2, DZNRM2
128 COMPLEX*16 ZLADIV
129 EXTERNAL dlamch, dlapy3, dlapy2, dznrm2,
130 $ zladiv
131* ..
132* .. Intrinsic Functions ..
133 INTRINSIC abs, dble, dcmplx, dimag, sign
134* ..
135* .. External Subroutines ..
136 EXTERNAL zdscal, zscal
137* ..
138* .. Executable Statements ..
139*
140 IF( n.LE.0 ) THEN
141 tau = zero
142 RETURN
143 END IF
144*
145 eps = dlamch( 'Precision' )
146 xnorm = dznrm2( n-1, x, incx )
147 alphr = dble( alpha )
148 alphi = dimag( alpha )
149*
150 IF( xnorm.LE.eps*abs(alpha) .AND. alphi.EQ.zero ) THEN
151*
152* H = [1-alpha/abs(alpha) 0; 0 I], sign chosen so ALPHA >= 0.
153*
154 IF( alphr.GE.zero ) THEN
155* When TAU.eq.ZERO, the vector is special-cased to be
156* all zeros in the application routines. We do not need
157* to clear it.
158 tau = zero
159 ELSE
160* However, the application routines rely on explicit
161* zero checks when TAU.ne.ZERO, and we must clear X.
162 tau = two
163 DO j = 1, n-1
164 x( 1 + (j-1)*incx ) = zero
165 END DO
166 alpha = -alpha
167 END IF
168 ELSE
169*
170* general case
171*
172 beta = sign( dlapy3( alphr, alphi, xnorm ), alphr )
173 smlnum = dlamch( 'S' ) / dlamch( 'E' )
174 bignum = one / smlnum
175*
176 knt = 0
177 IF( abs( beta ).LT.smlnum ) THEN
178*
179* XNORM, BETA may be inaccurate; scale X and recompute them
180*
181 10 CONTINUE
182 knt = knt + 1
183 CALL zdscal( n-1, bignum, x, incx )
184 beta = beta*bignum
185 alphi = alphi*bignum
186 alphr = alphr*bignum
187 IF( (abs( beta ).LT.smlnum) .AND. (knt .LT. 20) )
188 $ GO TO 10
189*
190* New BETA is at most 1, at least SMLNUM
191*
192 xnorm = dznrm2( n-1, x, incx )
193 alpha = dcmplx( alphr, alphi )
194 beta = sign( dlapy3( alphr, alphi, xnorm ), alphr )
195 END IF
196 savealpha = alpha
197 alpha = alpha + beta
198 IF( beta.LT.zero ) THEN
199 beta = -beta
200 tau = -alpha / beta
201 ELSE
202 alphr = alphi * (alphi/dble( alpha ))
203 alphr = alphr + xnorm * (xnorm/dble( alpha ))
204 tau = dcmplx( alphr/beta, -alphi/beta )
205 alpha = dcmplx( -alphr, alphi )
206 END IF
207 alpha = zladiv( dcmplx( one ), alpha )
208*
209 IF ( abs(tau).LE.smlnum ) THEN
210*
211* In the case where the computed TAU ends up being a denormalized number,
212* it loses relative accuracy. This is a BIG problem. Solution: flush TAU
213* to ZERO (or TWO or whatever makes a nonnegative real number for BETA).
214*
215* (Bug report provided by Pat Quillen from MathWorks on Jul 29, 2009.)
216* (Thanks Pat. Thanks MathWorks.)
217*
218 alphr = dble( savealpha )
219 alphi = dimag( savealpha )
220 IF( alphi.EQ.zero ) THEN
221 IF( alphr.GE.zero ) THEN
222 tau = zero
223 ELSE
224 tau = two
225 DO j = 1, n-1
226 x( 1 + (j-1)*incx ) = zero
227 END DO
228 beta = dble( -savealpha )
229 END IF
230 ELSE
231 xnorm = dlapy2( alphr, alphi )
232 tau = dcmplx( one - alphr / xnorm, -alphi / xnorm )
233 DO j = 1, n-1
234 x( 1 + (j-1)*incx ) = zero
235 END DO
236 beta = xnorm
237 END IF
238*
239 ELSE
240*
241* This is the general case.
242*
243 CALL zscal( n-1, alpha, x, incx )
244*
245 END IF
246*
247* If BETA is subnormal, it may lose relative accuracy
248*
249 DO 20 j = 1, knt
250 beta = beta*smlnum
251 20 CONTINUE
252 alpha = beta
253 END IF
254*
255 RETURN
256*
257* End of ZLARFGP
258*
259 END
subroutine zlarfgp(n, alpha, x, incx, tau)
ZLARFGP generates an elementary reflector (Householder matrix) with non-negative beta.
Definition zlarfgp.f:102
subroutine zdscal(n, da, zx, incx)
ZDSCAL
Definition zdscal.f:78
subroutine zscal(n, za, zx, incx)
ZSCAL
Definition zscal.f:78