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