 LAPACK  3.6.1 LAPACK: Linear Algebra PACKage
 subroutine zlarfgp ( integer N, complex*16 ALPHA, complex*16, dimension( * ) X, integer INCX, complex*16 TAU )

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

Purpose:
``` ZLARFGP 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*16 On entry, the value alpha. On exit, it is overwritten with the value beta.``` [in,out] X ``` X is COMPLEX*16 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*16 The value tau.```
Date
November 2015

Definition at line 106 of file zlarfgp.f.

106 *
107 * -- LAPACK auxiliary routine (version 3.6.0) --
108 * -- LAPACK is a software package provided by Univ. of Tennessee, --
109 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
110 * November 2015
111 *
112 * .. Scalar Arguments ..
113  INTEGER incx, n
114  COMPLEX*16 alpha, tau
115 * ..
116 * .. Array Arguments ..
117  COMPLEX*16 x( * )
118 * ..
119 *
120 * =====================================================================
121 *
122 * .. Parameters ..
123  DOUBLE PRECISION two, one, zero
124  parameter ( two = 2.0d+0, one = 1.0d+0, zero = 0.0d+0 )
125 * ..
126 * .. Local Scalars ..
127  INTEGER j, knt
128  DOUBLE PRECISION alphi, alphr, beta, bignum, smlnum, xnorm
129  COMPLEX*16 savealpha
130 * ..
131 * .. External Functions ..
132  DOUBLE PRECISION dlamch, dlapy3, dlapy2, dznrm2
134  EXTERNAL dlamch, dlapy3, dlapy2, dznrm2, zladiv
135 * ..
136 * .. Intrinsic Functions ..
137  INTRINSIC abs, dble, dcmplx, dimag, sign
138 * ..
139 * .. External Subroutines ..
140  EXTERNAL zdscal, zscal
141 * ..
142 * .. Executable Statements ..
143 *
144  IF( n.LE.0 ) THEN
145  tau = zero
146  RETURN
147  END IF
148 *
149  xnorm = dznrm2( n-1, x, incx )
150  alphr = dble( alpha )
151  alphi = dimag( alpha )
152 *
153  IF( xnorm.EQ.zero ) THEN
154 *
155 * H = [1-alpha/abs(alpha) 0; 0 I], sign chosen so ALPHA >= 0.
156 *
157  IF( alphi.EQ.zero ) THEN
158  IF( alphr.GE.zero ) THEN
159 * When TAU.eq.ZERO, the vector is special-cased to be
160 * all zeros in the application routines. We do not need
161 * to clear it.
162  tau = zero
163  ELSE
164 * However, the application routines rely on explicit
165 * zero checks when TAU.ne.ZERO, and we must clear X.
166  tau = two
167  DO j = 1, n-1
168  x( 1 + (j-1)*incx ) = zero
169  END DO
170  alpha = -alpha
171  END IF
172  ELSE
173 * Only "reflecting" the diagonal entry to be real and non-negative.
174  xnorm = dlapy2( alphr, alphi )
175  tau = dcmplx( one - alphr / xnorm, -alphi / xnorm )
176  DO j = 1, n-1
177  x( 1 + (j-1)*incx ) = zero
178  END DO
179  alpha = xnorm
180  END IF
181  ELSE
182 *
183 * general case
184 *
185  beta = sign( dlapy3( alphr, alphi, xnorm ), alphr )
186  smlnum = dlamch( 'S' ) / dlamch( 'E' )
187  bignum = one / smlnum
188 *
189  knt = 0
190  IF( abs( beta ).LT.smlnum ) THEN
191 *
192 * XNORM, BETA may be inaccurate; scale X and recompute them
193 *
194  10 CONTINUE
195  knt = knt + 1
196  CALL zdscal( n-1, bignum, x, incx )
197  beta = beta*bignum
198  alphi = alphi*bignum
199  alphr = alphr*bignum
200  IF( abs( beta ).LT.smlnum )
201  \$ GO TO 10
202 *
203 * New BETA is at most 1, at least SMLNUM
204 *
205  xnorm = dznrm2( n-1, x, incx )
206  alpha = dcmplx( alphr, alphi )
207  beta = sign( dlapy3( alphr, alphi, xnorm ), alphr )
208  END IF
209  savealpha = alpha
210  alpha = alpha + beta
211  IF( beta.LT.zero ) THEN
212  beta = -beta
213  tau = -alpha / beta
214  ELSE
215  alphr = alphi * (alphi/dble( alpha ))
216  alphr = alphr + xnorm * (xnorm/dble( alpha ))
217  tau = dcmplx( alphr/beta, -alphi/beta )
218  alpha = dcmplx( -alphr, alphi )
219  END IF
220  alpha = zladiv( dcmplx( one ), alpha )
221 *
222  IF ( abs(tau).LE.smlnum ) THEN
223 *
224 * In the case where the computed TAU ends up being a denormalized number,
225 * it loses relative accuracy. This is a BIG problem. Solution: flush TAU
226 * to ZERO (or TWO or whatever makes a nonnegative real number for BETA).
227 *
228 * (Bug report provided by Pat Quillen from MathWorks on Jul 29, 2009.)
229 * (Thanks Pat. Thanks MathWorks.)
230 *
231  alphr = dble( savealpha )
232  alphi = dimag( savealpha )
233  IF( alphi.EQ.zero ) THEN
234  IF( alphr.GE.zero ) THEN
235  tau = zero
236  ELSE
237  tau = two
238  DO j = 1, n-1
239  x( 1 + (j-1)*incx ) = zero
240  END DO
241  beta = -savealpha
242  END IF
243  ELSE
244  xnorm = dlapy2( alphr, alphi )
245  tau = dcmplx( one - alphr / xnorm, -alphi / xnorm )
246  DO j = 1, n-1
247  x( 1 + (j-1)*incx ) = zero
248  END DO
249  beta = xnorm
250  END IF
251 *
252  ELSE
253 *
254 * This is the general case.
255 *
256  CALL zscal( n-1, alpha, x, incx )
257 *
258  END IF
259 *
260 * If BETA is subnormal, it may lose relative accuracy
261 *
262  DO 20 j = 1, knt
263  beta = beta*smlnum
264  20 CONTINUE
265  alpha = beta
266  END IF
267 *
268  RETURN
269 *
270 * End of ZLARFGP
271 *
double precision function dlamch(CMACH)
DLAMCH
Definition: dlamch.f:65
double precision function dznrm2(N, X, INCX)
DZNRM2
Definition: dznrm2.f:56
double precision function dlapy3(X, Y, Z)
DLAPY3 returns sqrt(x2+y2+z2).
Definition: dlapy3.f:70
subroutine zdscal(N, DA, ZX, INCX)
ZDSCAL
Definition: zdscal.f:54
double precision function dlapy2(X, Y)
DLAPY2 returns sqrt(x2+y2).
Definition: dlapy2.f:65