/src/igraph/vendor/lapack/dlarfg.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* -- translated by f2c (version 20191129). |
2 | | You must link the resulting object file with libf2c: |
3 | | on Microsoft Windows system, link with libf2c.lib; |
4 | | on Linux or Unix systems, link with .../path/to/libf2c.a -lm |
5 | | or, if you install libf2c.a in a standard place, with -lf2c -lm |
6 | | -- in that order, at the end of the command line, as in |
7 | | cc *.o -lf2c -lm |
8 | | Source for libf2c is in /netlib/f2c/libf2c.zip, e.g., |
9 | | |
10 | | http://www.netlib.org/f2c/libf2c.zip |
11 | | */ |
12 | | |
13 | | #include "f2c.h" |
14 | | |
15 | | /* > \brief \b DLARFG generates an elementary reflector (Householder matrix). |
16 | | |
17 | | =========== DOCUMENTATION =========== |
18 | | |
19 | | Online html documentation available at |
20 | | http://www.netlib.org/lapack/explore-html/ |
21 | | |
22 | | > \htmlonly |
23 | | > Download DLARFG + dependencies |
24 | | > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dlarfg. |
25 | | f"> |
26 | | > [TGZ]</a> |
27 | | > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dlarfg. |
28 | | f"> |
29 | | > [ZIP]</a> |
30 | | > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dlarfg. |
31 | | f"> |
32 | | > [TXT]</a> |
33 | | > \endhtmlonly |
34 | | |
35 | | Definition: |
36 | | =========== |
37 | | |
38 | | SUBROUTINE DLARFG( N, ALPHA, X, INCX, TAU ) |
39 | | |
40 | | INTEGER INCX, N |
41 | | DOUBLE PRECISION ALPHA, TAU |
42 | | DOUBLE PRECISION X( * ) |
43 | | |
44 | | |
45 | | > \par Purpose: |
46 | | ============= |
47 | | > |
48 | | > \verbatim |
49 | | > |
50 | | > DLARFG generates a real elementary reflector H of order n, such |
51 | | > that |
52 | | > |
53 | | > H * ( alpha ) = ( beta ), H**T * H = I. |
54 | | > ( x ) ( 0 ) |
55 | | > |
56 | | > where alpha and beta are scalars, and x is an (n-1)-element real |
57 | | > vector. H is represented in the form |
58 | | > |
59 | | > H = I - tau * ( 1 ) * ( 1 v**T ) , |
60 | | > ( v ) |
61 | | > |
62 | | > where tau is a real scalar and v is a real (n-1)-element |
63 | | > vector. |
64 | | > |
65 | | > If the elements of x are all zero, then tau = 0 and H is taken to be |
66 | | > the unit matrix. |
67 | | > |
68 | | > Otherwise 1 <= tau <= 2. |
69 | | > \endverbatim |
70 | | |
71 | | Arguments: |
72 | | ========== |
73 | | |
74 | | > \param[in] N |
75 | | > \verbatim |
76 | | > N is INTEGER |
77 | | > The order of the elementary reflector. |
78 | | > \endverbatim |
79 | | > |
80 | | > \param[in,out] ALPHA |
81 | | > \verbatim |
82 | | > ALPHA is DOUBLE PRECISION |
83 | | > On entry, the value alpha. |
84 | | > On exit, it is overwritten with the value beta. |
85 | | > \endverbatim |
86 | | > |
87 | | > \param[in,out] X |
88 | | > \verbatim |
89 | | > X is DOUBLE PRECISION array, dimension |
90 | | > (1+(N-2)*abs(INCX)) |
91 | | > On entry, the vector x. |
92 | | > On exit, it is overwritten with the vector v. |
93 | | > \endverbatim |
94 | | > |
95 | | > \param[in] INCX |
96 | | > \verbatim |
97 | | > INCX is INTEGER |
98 | | > The increment between elements of X. INCX > 0. |
99 | | > \endverbatim |
100 | | > |
101 | | > \param[out] TAU |
102 | | > \verbatim |
103 | | > TAU is DOUBLE PRECISION |
104 | | > The value tau. |
105 | | > \endverbatim |
106 | | |
107 | | Authors: |
108 | | ======== |
109 | | |
110 | | > \author Univ. of Tennessee |
111 | | > \author Univ. of California Berkeley |
112 | | > \author Univ. of Colorado Denver |
113 | | > \author NAG Ltd. |
114 | | |
115 | | > \date September 2012 |
116 | | |
117 | | > \ingroup doubleOTHERauxiliary |
118 | | |
119 | | ===================================================================== |
120 | | Subroutine */ int igraphdlarfg_(integer *n, doublereal *alpha, doublereal *x, |
121 | | integer *incx, doublereal *tau) |
122 | 0 | { |
123 | | /* System generated locals */ |
124 | 0 | integer i__1; |
125 | 0 | doublereal d__1; |
126 | | |
127 | | /* Builtin functions */ |
128 | 0 | double d_sign(doublereal *, doublereal *); |
129 | | |
130 | | /* Local variables */ |
131 | 0 | integer j, knt; |
132 | 0 | doublereal beta; |
133 | 0 | extern doublereal igraphdnrm2_(integer *, doublereal *, integer *); |
134 | 0 | extern /* Subroutine */ int igraphdscal_(integer *, doublereal *, doublereal *, |
135 | 0 | integer *); |
136 | 0 | doublereal xnorm; |
137 | 0 | extern doublereal igraphdlapy2_(doublereal *, doublereal *), igraphdlamch_(char *); |
138 | 0 | doublereal safmin, rsafmn; |
139 | | |
140 | | |
141 | | /* -- LAPACK auxiliary routine (version 3.4.2) -- |
142 | | -- LAPACK is a software package provided by Univ. of Tennessee, -- |
143 | | -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- |
144 | | September 2012 |
145 | | |
146 | | |
147 | | ===================================================================== |
148 | | |
149 | | |
150 | | Parameter adjustments */ |
151 | 0 | --x; |
152 | | |
153 | | /* Function Body */ |
154 | 0 | if (*n <= 1) { |
155 | 0 | *tau = 0.; |
156 | 0 | return 0; |
157 | 0 | } |
158 | | |
159 | 0 | i__1 = *n - 1; |
160 | 0 | xnorm = igraphdnrm2_(&i__1, &x[1], incx); |
161 | |
|
162 | 0 | if (xnorm == 0.) { |
163 | | |
164 | | /* H = I */ |
165 | |
|
166 | 0 | *tau = 0.; |
167 | 0 | } else { |
168 | | |
169 | | /* general case */ |
170 | |
|
171 | 0 | d__1 = igraphdlapy2_(alpha, &xnorm); |
172 | 0 | beta = -d_sign(&d__1, alpha); |
173 | 0 | safmin = igraphdlamch_("S") / igraphdlamch_("E"); |
174 | 0 | knt = 0; |
175 | 0 | if (abs(beta) < safmin) { |
176 | | |
177 | | /* XNORM, BETA may be inaccurate; scale X and recompute them */ |
178 | |
|
179 | 0 | rsafmn = 1. / safmin; |
180 | 0 | L10: |
181 | 0 | ++knt; |
182 | 0 | i__1 = *n - 1; |
183 | 0 | igraphdscal_(&i__1, &rsafmn, &x[1], incx); |
184 | 0 | beta *= rsafmn; |
185 | 0 | *alpha *= rsafmn; |
186 | 0 | if (abs(beta) < safmin) { |
187 | 0 | goto L10; |
188 | 0 | } |
189 | | |
190 | | /* New BETA is at most 1, at least SAFMIN */ |
191 | | |
192 | 0 | i__1 = *n - 1; |
193 | 0 | xnorm = igraphdnrm2_(&i__1, &x[1], incx); |
194 | 0 | d__1 = igraphdlapy2_(alpha, &xnorm); |
195 | 0 | beta = -d_sign(&d__1, alpha); |
196 | 0 | } |
197 | 0 | *tau = (beta - *alpha) / beta; |
198 | 0 | i__1 = *n - 1; |
199 | 0 | d__1 = 1. / (*alpha - beta); |
200 | 0 | igraphdscal_(&i__1, &d__1, &x[1], incx); |
201 | | |
202 | | /* If ALPHA is subnormal, it may lose relative accuracy */ |
203 | |
|
204 | 0 | i__1 = knt; |
205 | 0 | for (j = 1; j <= i__1; ++j) { |
206 | 0 | beta *= safmin; |
207 | | /* L20: */ |
208 | 0 | } |
209 | 0 | *alpha = beta; |
210 | 0 | } |
211 | | |
212 | 0 | return 0; |
213 | | |
214 | | /* End of DLARFG */ |
215 | |
|
216 | 0 | } /* igraphdlarfg_ */ |
217 | | |