LAPACK 3.12.1
LAPACK: Linear Algebra PACKage
Loading...
Searching...
No Matches
dlarfgp.f
Go to the documentation of this file.
1*> \brief \b DLARFGP 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 DLARFGP + dependencies
9*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dlarfgp.f">
10*> [TGZ]</a>
11*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dlarfgp.f">
12*> [ZIP]</a>
13*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dlarfgp.f">
14*> [TXT]</a>
15*
16* Definition:
17* ===========
18*
19* SUBROUTINE DLARFGP( N, ALPHA, X, INCX, TAU )
20*
21* .. Scalar Arguments ..
22* INTEGER INCX, N
23* DOUBLE PRECISION ALPHA, TAU
24* ..
25* .. Array Arguments ..
26* DOUBLE PRECISION X( * )
27* ..
28*
29*
30*> \par Purpose:
31* =============
32*>
33*> \verbatim
34*>
35*> DLARFGP generates a real elementary reflector H of order n, such
36*> that
37*>
38*> H * ( alpha ) = ( beta ), H**T * H = I.
39*> ( x ) ( 0 )
40*>
41*> where alpha and beta are scalars, beta is non-negative, and x is
42*> an (n-1)-element real vector. H is represented in the form
43*>
44*> H = I - tau * ( 1 ) * ( 1 v**T ) ,
45*> ( v )
46*>
47*> where tau is a real scalar and v is a real (n-1)-element
48*> vector.
49*>
50*> If the elements of x are all zero, then tau = 0 and H is taken to be
51*> 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 DOUBLE PRECISION
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 DOUBLE PRECISION 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 DOUBLE PRECISION
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 dlarfgp( 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 DOUBLE PRECISION ALPHA, TAU
110* ..
111* .. Array Arguments ..
112 DOUBLE PRECISION 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 BETA, BIGNUM, EPS, SAVEALPHA, SMLNUM, XNORM
124* ..
125* .. External Functions ..
126 DOUBLE PRECISION DLAMCH, DLAPY2, DNRM2
127 EXTERNAL dlamch, dlapy2, dnrm2
128* ..
129* .. Intrinsic Functions ..
130 INTRINSIC abs, sign
131* ..
132* .. External Subroutines ..
133 EXTERNAL dscal
134* ..
135* .. Executable Statements ..
136*
137 IF( n.LE.0 ) THEN
138 tau = zero
139 RETURN
140 END IF
141*
142 eps = dlamch( 'Precision' )
143 xnorm = dnrm2( n-1, x, incx )
144*
145 IF( xnorm.LE.eps*abs(alpha) ) THEN
146*
147* H = [+/-1, 0; I], sign chosen so ALPHA >= 0.
148*
149 IF( alpha.GE.zero ) THEN
150* When TAU.eq.ZERO, the vector is special-cased to be
151* all zeros in the application routines. We do not need
152* to clear it.
153 tau = zero
154 ELSE
155* However, the application routines rely on explicit
156* zero checks when TAU.ne.ZERO, and we must clear X.
157 tau = two
158 DO j = 1, n-1
159 x( 1 + (j-1)*incx ) = 0
160 END DO
161 alpha = -alpha
162 END IF
163 ELSE
164*
165* general case
166*
167 beta = sign( dlapy2( alpha, xnorm ), alpha )
168 smlnum = dlamch( 'S' ) / dlamch( 'E' )
169 knt = 0
170 IF( abs( beta ).LT.smlnum ) THEN
171*
172* XNORM, BETA may be inaccurate; scale X and recompute them
173*
174 bignum = one / smlnum
175 10 CONTINUE
176 knt = knt + 1
177 CALL dscal( n-1, bignum, x, incx )
178 beta = beta*bignum
179 alpha = alpha*bignum
180 IF( (abs( beta ).LT.smlnum) .AND. (knt .LT. 20) )
181 $ GO TO 10
182*
183* New BETA is at most 1, at least SMLNUM
184*
185 xnorm = dnrm2( n-1, x, incx )
186 beta = sign( dlapy2( alpha, xnorm ), alpha )
187 END IF
188 savealpha = alpha
189 alpha = alpha + beta
190 IF( beta.LT.zero ) THEN
191 beta = -beta
192 tau = -alpha / beta
193 ELSE
194 alpha = xnorm * (xnorm/alpha)
195 tau = alpha / beta
196 alpha = -alpha
197 END IF
198*
199 IF ( abs(tau).LE.smlnum ) THEN
200*
201* In the case where the computed TAU ends up being a denormalized number,
202* it loses relative accuracy. This is a BIG problem. Solution: flush TAU
203* to ZERO. This explains the next IF statement.
204*
205* (Bug report provided by Pat Quillen from MathWorks on Jul 29, 2009.)
206* (Thanks Pat. Thanks MathWorks.)
207*
208 IF( savealpha.GE.zero ) THEN
209 tau = zero
210 ELSE
211 tau = two
212 DO j = 1, n-1
213 x( 1 + (j-1)*incx ) = 0
214 END DO
215 beta = -savealpha
216 END IF
217*
218 ELSE
219*
220* This is the general case.
221*
222 CALL dscal( n-1, one / alpha, x, incx )
223*
224 END IF
225*
226* If BETA is subnormal, it may lose relative accuracy
227*
228 DO 20 j = 1, knt
229 beta = beta*smlnum
230 20 CONTINUE
231 alpha = beta
232 END IF
233*
234 RETURN
235*
236* End of DLARFGP
237*
238 END
subroutine dlarfgp(n, alpha, x, incx, tau)
DLARFGP generates an elementary reflector (Householder matrix) with non-negative beta.
Definition dlarfgp.f:102
subroutine dscal(n, da, dx, incx)
DSCAL
Definition dscal.f:79