Debian Codegraph @

external/gsl/gsl_linalg__householdercomplex.c

raw symbols SCIP
1 /* linalg/householdercomplex.c
2 *
3 * Copyright (C) 2001, 2007 Brian Gough
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or (at
8 * your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 */
19
20 /* Computes a householder transformation matrix H such that
21 *
22 * H' v = -/+ |v| e_1
23 *
24 * where e_1 is the first unit vector. On exit the matrix H can be
25 * computed from the return values (tau, v)
26 *
27 * H = I - tau * w * w'
28 *
29 * where w = (1, v(2), ..., v(N)). The nonzero element of the result
30 * vector -/+|v| e_1 is stored in v(1).
31 *
32 * Note that the matrix H' in the householder transformation is the
33 * hermitian conjugate of H. To compute H'v, pass the conjugate of
34 * tau as the first argument to gsl_linalg_householder_hm() rather
35 * than tau itself. See the LAPACK function CLARFG for details of this
36 * convention. */
37
38 #include "gsl__config.h"cxx . . $ `<file>/external/gsl/gsl__config.h`/
39 #include <stdlib.h>
40 #include "gsl_math.h"cxx . . $ `<file>/external/gsl/gsl_math.h`/
41 #include "gsl_vector.h"cxx . . $ `<file>/external/gsl/gsl_vector.h`/
42 #include "gsl_matrix.h"cxx . . $ `<file>/external/gsl/gsl_matrix.h`/
43 #include "gsl_blas.h"cxx . . $ `<file>/external/gsl/gsl_blas.h`/
44 #include "gsl_complex_math.h"cxx . . $ `<file>/external/gsl/gsl_complex_math.h`/
45
46 #include "gsl_linalg.h"cxx . . $ `<file>/external/gsl/gsl_linalg.h`/
47
48 gsl_complexcxx . . $ gsl_complex#
49 gsl_linalg_complex_householder_transformcxx . . $ gsl_linalg_complex_householder_transform(e968322202838fc8). (gsl_vector_complexcxx . . $ gsl_vector_complex# * v)
50 {
51 /* replace v[0:n-1] with a householder vector (v[0:n-1]) and
52 coefficient tau that annihilate v[1:n-1] */
53
54 const size_t n = v->sizecxx . . $ $anonymous_type_8293e13329784d65_0#size. ;
55
56 if (n == 1)
57 {
58 gsl_complexcxx . . $ gsl_complex# alpha = gsl_vector_complex_getcxx . . $ gsl_vector_complex_get(5d8bca1ac2095b4a). (v, 0) ;
59 double absa = gsl_complex_abscxx . . $ gsl_complex_abs(99532ffcb3ef1144). (alpha);
60 double beta_r = - (GSL_REALcxx . . $ `external/gsl/gsl_complex.h:88:9`!(alpha) >= 0 ? +1 : -1) * absa ;
61
62 gsl_complexcxx . . $ gsl_complex# tau;
63
64 if (beta_r == 0.0)
65 {
66 GSL_REALcxx . . $ `external/gsl/gsl_complex.h:88:9`!(tau) = 0.0;
67 GSL_IMAGcxx . . $ `external/gsl/gsl_complex.h:89:9`!(tau) = 0.0;
68 }
69 else
70 {
71 GSL_REALcxx . . $ `external/gsl/gsl_complex.h:88:9`!(tau) = (beta_r - GSL_REALcxx . . $ `external/gsl/gsl_complex.h:88:9`!(alpha)) / beta_r ;
72 GSL_IMAGcxx . . $ `external/gsl/gsl_complex.h:89:9`!(tau) = - GSL_IMAGcxx . . $ `external/gsl/gsl_complex.h:89:9`!(alpha) / beta_r ;
73
74 {
75 gsl_complexcxx . . $ gsl_complex# beta = gsl_complex_rectcxx . . $ gsl_complex_rect(ce072676009bb5ad). (beta_r, 0.0);
76 gsl_vector_complex_setcxx . . $ gsl_vector_complex_set(40980682899f0413). (v, 0, beta) ;
77 }
78 }
79
80 return tau;
81 }
82 else
83 {
84 gsl_complexcxx . . $ gsl_complex# tau ;
85 double beta_r;
86
87 gsl_vector_complex_viewcxx . . $ gsl_vector_complex_view# x = gsl_vector_complex_subvectorcxx . . $ gsl_vector_complex_subvector(6cbc2efe0426a8d3). (v, 1, n - 1) ;
88 gsl_complexcxx . . $ gsl_complex# alpha = gsl_vector_complex_getcxx . . $ gsl_vector_complex_get(5d8bca1ac2095b4a). (v, 0) ;
89 double absa = gsl_complex_abscxx . . $ gsl_complex_abs(99532ffcb3ef1144). (alpha);
90 double xnorm = gsl_blas_dznrm2cxx . . $ gsl_blas_dznrm2(91b78807f015d6c1). (&x.vectorcxx . . $ $anonymous_type_8293e13329784d65_1#vector.);
91
92 if (xnorm == 0 && GSL_IMAGcxx . . $ `external/gsl/gsl_complex.h:89:9`!(alpha) == 0)
93 {
94 gsl_complexcxx . . $ gsl_complex# zero = gsl_complex_rectcxx . . $ gsl_complex_rect(ce072676009bb5ad).(0.0, 0.0);
95 return zero; /* tau = 0 */
96 }
97
98 beta_r = - (GSL_REALcxx . . $ `external/gsl/gsl_complex.h:88:9`!(alpha) >= 0 ? +1 : -1) * hypot(absa, xnorm) ;
99
100 GSL_REALcxx . . $ `external/gsl/gsl_complex.h:88:9`!(tau) = (beta_r - GSL_REALcxx . . $ `external/gsl/gsl_complex.h:88:9`!(alpha)) / beta_r ;
101 GSL_IMAGcxx . . $ `external/gsl/gsl_complex.h:89:9`!(tau) = - GSL_IMAGcxx . . $ `external/gsl/gsl_complex.h:89:9`!(alpha) / beta_r ;
102
103 {
104 gsl_complexcxx . . $ gsl_complex# amb = gsl_complex_sub_realcxx . . $ gsl_complex_sub_real(c6889a7dee95c079).(alpha, beta_r);
105 gsl_complexcxx . . $ gsl_complex# s = gsl_complex_inversecxx . . $ gsl_complex_inverse(8eb82f5a0e7f60d8).(amb);
106 gsl_blas_zscalcxx . . $ gsl_blas_zscal(8a1e5c0acb837d83). (s, &x.vectorcxx . . $ $anonymous_type_8293e13329784d65_1#vector.);
107 }
108
109 {
110 gsl_complexcxx . . $ gsl_complex# beta = gsl_complex_rectcxx . . $ gsl_complex_rect(ce072676009bb5ad). (beta_r, 0.0);
111 gsl_vector_complex_setcxx . . $ gsl_vector_complex_set(40980682899f0413). (v, 0, beta) ;
112 }
113
114 return tau;
115 }
116 }
117
118 int
119 gsl_linalg_complex_householder_hmcxx . . $ gsl_linalg_complex_householder_hm(b299bf2b85f0f022). (gsl_complexcxx . . $ gsl_complex# tau, const gsl_vector_complexcxx . . $ gsl_vector_complex# * v, gsl_matrix_complexcxx . . $ gsl_matrix_complex# * A)
120 {
121 /* applies a householder transformation v,tau to matrix m */
122
123 size_t i, j;
124
125 if (GSL_REALcxx . . $ `external/gsl/gsl_complex.h:88:9`!(tau) == 0.0 && GSL_IMAGcxx . . $ `external/gsl/gsl_complex.h:89:9`!(tau) == 0.0)
126 {
127 return GSL_SUCCESScxx . . $ GSL_SUCCESS.;
128 }
129
130 /* w = (v' A)^T */
131
132 for (j = 0; j < A->size2cxx . . $ $anonymous_type_76f4ec40ad1923db_0#size2.; j++)
133 {
134 gsl_complexcxx . . $ gsl_complex# tauwj;
135 gsl_complexcxx . . $ gsl_complex# wj = gsl_matrix_complex_getcxx . . $ gsl_matrix_complex_get(30564a92bc25dfb2).(A,0,j);
136
137 for (i = 1; i < A->size1cxx . . $ $anonymous_type_76f4ec40ad1923db_0#size1.; i++) /* note, computed for v(0) = 1 above */
138 {
139 gsl_complexcxx . . $ gsl_complex# Aij = gsl_matrix_complex_getcxx . . $ gsl_matrix_complex_get(30564a92bc25dfb2).(A,i,j);
140 gsl_complexcxx . . $ gsl_complex# vi = gsl_vector_complex_getcxx . . $ gsl_vector_complex_get(5d8bca1ac2095b4a).(v,i);
141 gsl_complexcxx . . $ gsl_complex# Av = gsl_complex_mulcxx . . $ gsl_complex_mul(97d196ab28e6deec). (Aij, gsl_complex_conjugatecxx . . $ gsl_complex_conjugate(8eb82f5a0e7f60d8).(vi));
142 wj = gsl_complex_addcxx . . $ gsl_complex_add(97d196ab28e6deec). (wj, Av);
143 }
144
145 tauwj = gsl_complex_mulcxx . . $ gsl_complex_mul(97d196ab28e6deec). (tau, wj);
146
147 /* A = A - v w^T */
148
149 {
150 gsl_complexcxx . . $ gsl_complex# A0j = gsl_matrix_complex_getcxx . . $ gsl_matrix_complex_get(30564a92bc25dfb2). (A, 0, j);
151 gsl_complexcxx . . $ gsl_complex# Atw = gsl_complex_subcxx . . $ gsl_complex_sub(97d196ab28e6deec). (A0j, tauwj);
152 /* store A0j - tau * wj */
153 gsl_matrix_complex_setcxx . . $ gsl_matrix_complex_set(2f351991ff7604). (A, 0, j, Atw);
154 }
155
156 for (i = 1; i < A->size1cxx . . $ $anonymous_type_76f4ec40ad1923db_0#size1.; i++)
157 {
158 gsl_complexcxx . . $ gsl_complex# vi = gsl_vector_complex_getcxx . . $ gsl_vector_complex_get(5d8bca1ac2095b4a). (v, i);
159 gsl_complexcxx . . $ gsl_complex# tauvw = gsl_complex_mulcxx . . $ gsl_complex_mul(97d196ab28e6deec).(vi, tauwj);
160 gsl_complexcxx . . $ gsl_complex# Aij = gsl_matrix_complex_getcxx . . $ gsl_matrix_complex_get(30564a92bc25dfb2). (A, i, j);
161 gsl_complexcxx . . $ gsl_complex# Atwv = gsl_complex_subcxx . . $ gsl_complex_sub(97d196ab28e6deec). (Aij, tauvw);
162 /* store Aij - tau * vi * wj */
163 gsl_matrix_complex_setcxx . . $ gsl_matrix_complex_set(2f351991ff7604). (A, i, j, Atwv);
164 }
165 }
166
167 return GSL_SUCCESScxx . . $ GSL_SUCCESS.;
168 }
169
170 int
171 gsl_linalg_complex_householder_mhcxx . . $ gsl_linalg_complex_householder_mh(b299bf2b85f0f022). (gsl_complexcxx . . $ gsl_complex# tau, const gsl_vector_complexcxx . . $ gsl_vector_complex# * v, gsl_matrix_complexcxx . . $ gsl_matrix_complex# * A)
172 {
173 /* applies a householder transformation v,tau to matrix m on the right */
174
175 size_t i, j;
176
177 if (GSL_REALcxx . . $ `external/gsl/gsl_complex.h:88:9`!(tau) == 0.0 && GSL_IMAGcxx . . $ `external/gsl/gsl_complex.h:89:9`!(tau) == 0.0)
178 {
179 return GSL_SUCCESScxx . . $ GSL_SUCCESS.;
180 }
181
182 /* A -> A - A*tau*v*v^h */
183
184 for (i = 0; i < A->size1cxx . . $ $anonymous_type_76f4ec40ad1923db_0#size1.; i++)
185 {
186 gsl_complexcxx . . $ gsl_complex# tauwi;
187 gsl_complexcxx . . $ gsl_complex# Ai0 = gsl_matrix_complex_getcxx . . $ gsl_matrix_complex_get(30564a92bc25dfb2). (A, i, 0);
188 gsl_complexcxx . . $ gsl_complex# wi = Ai0;
189
190 /* compute w = A v */
191 for (j = 1; j < A->size2cxx . . $ $anonymous_type_76f4ec40ad1923db_0#size2.; j++) /* note, computed for v(0) = 1 above */
192 {
193 gsl_complexcxx . . $ gsl_complex# Aij = gsl_matrix_complex_getcxx . . $ gsl_matrix_complex_get(30564a92bc25dfb2).(A, i, j);
194 gsl_complexcxx . . $ gsl_complex# vj = gsl_vector_complex_getcxx . . $ gsl_vector_complex_get(5d8bca1ac2095b4a).(v, j);
195 gsl_complexcxx . . $ gsl_complex# Av = gsl_complex_mulcxx . . $ gsl_complex_mul(97d196ab28e6deec). (Aij, vj);
196 wi = gsl_complex_addcxx . . $ gsl_complex_add(97d196ab28e6deec). (wi, Av);
197 }
198
199 tauwi = gsl_complex_mulcxx . . $ gsl_complex_mul(97d196ab28e6deec). (tau, wi);
200
201 /* A = A - w v^H */
202
203 {
204 gsl_complexcxx . . $ gsl_complex# Atw = gsl_complex_subcxx . . $ gsl_complex_sub(97d196ab28e6deec). (Ai0, tauwi);
205 /* store Ai0 - tau * wi */
206 gsl_matrix_complex_setcxx . . $ gsl_matrix_complex_set(2f351991ff7604). (A, i, 0, Atw);
207 }
208
209 for (j = 1; j < A->size2cxx . . $ $anonymous_type_76f4ec40ad1923db_0#size2.; j++)
210 {
211 gsl_complexcxx . . $ gsl_complex# vj = gsl_vector_complex_getcxx . . $ gsl_vector_complex_get(5d8bca1ac2095b4a). (v, j);
212 gsl_complexcxx . . $ gsl_complex# tauwv = gsl_complex_mulcxx . . $ gsl_complex_mul(97d196ab28e6deec).(gsl_complex_conjugatecxx . . $ gsl_complex_conjugate(8eb82f5a0e7f60d8).(vj), tauwi);
213 gsl_complexcxx . . $ gsl_complex# Aij = gsl_matrix_complex_getcxx . . $ gsl_matrix_complex_get(30564a92bc25dfb2). (A, i, j);
214 gsl_complexcxx . . $ gsl_complex# Atwv = gsl_complex_subcxx . . $ gsl_complex_sub(97d196ab28e6deec). (Aij, tauwv);
215 /* store Aij - tau * wi * conj(vj) */
216 gsl_matrix_complex_setcxx . . $ gsl_matrix_complex_set(2f351991ff7604). (A, i, j, Atwv);
217 }
218 }
219
220 return GSL_SUCCESScxx . . $ GSL_SUCCESS.;
221 }
222
223 int
224 gsl_linalg_complex_householder_hvcxx . . $ gsl_linalg_complex_householder_hv(ebd6bc4bc7f4fcc7). (gsl_complexcxx . . $ gsl_complex# tau, const gsl_vector_complexcxx . . $ gsl_vector_complex# * v, gsl_vector_complexcxx . . $ gsl_vector_complex# * w)
225 {
226 const size_t N = v->sizecxx . . $ $anonymous_type_8293e13329784d65_0#size.;
227
228 if (GSL_REALcxx . . $ `external/gsl/gsl_complex.h:88:9`!(tau) == 0.0 && GSL_IMAGcxx . . $ `external/gsl/gsl_complex.h:89:9`!(tau) == 0.0)
229 return GSL_SUCCESScxx . . $ GSL_SUCCESS.;
230
231 {
232 /* compute z = v'w */
233
234 gsl_complexcxx . . $ gsl_complex# z0 = gsl_vector_complex_getcxx . . $ gsl_vector_complex_get(5d8bca1ac2095b4a).(w,0);
235 gsl_complexcxx . . $ gsl_complex# z1, z;
236 gsl_complexcxx . . $ gsl_complex# tz, ntz;
237
238 gsl_vector_complex_const_viewcxx . . $ gsl_vector_complex_const_view# v1 = gsl_vector_complex_const_subvectorcxx . . $ gsl_vector_complex_const_subvector(98e3843abfaf3807).(v, 1, N-1);
239 gsl_vector_complex_viewcxx . . $ gsl_vector_complex_view# w1 = gsl_vector_complex_subvectorcxx . . $ gsl_vector_complex_subvector(6cbc2efe0426a8d3).(w, 1, N-1);
240
241 gsl_blas_zdotccxx . . $ gsl_blas_zdotc(8d43f868372e01dd).(&v1.vectorcxx . . $ $anonymous_type_8293e13329784d65_2#vector., &w1.vectorcxx . . $ $anonymous_type_8293e13329784d65_1#vector., &z1);
242
243 z = gsl_complex_addcxx . . $ gsl_complex_add(97d196ab28e6deec). (z0, z1);
244
245 tz = gsl_complex_mulcxx . . $ gsl_complex_mul(97d196ab28e6deec).(tau, z);
246 ntz = gsl_complex_negativecxx . . $ gsl_complex_negative(8eb82f5a0e7f60d8). (tz);
247
248 /* compute w = w - tau * (v'w) * v */
249
250 {
251 gsl_complexcxx . . $ gsl_complex# w0 = gsl_vector_complex_getcxx . . $ gsl_vector_complex_get(5d8bca1ac2095b4a).(w, 0);
252 gsl_complexcxx . . $ gsl_complex# w0ntz = gsl_complex_addcxx . . $ gsl_complex_add(97d196ab28e6deec). (w0, ntz);
253 gsl_vector_complex_setcxx . . $ gsl_vector_complex_set(40980682899f0413). (w, 0, w0ntz);
254 }
255
256 gsl_blas_zaxpycxx . . $ gsl_blas_zaxpy(ebd6bc4bc7f4fcc7).(ntz, &v1.vectorcxx . . $ $anonymous_type_8293e13329784d65_2#vector., &w1.vectorcxx . . $ $anonymous_type_8293e13329784d65_1#vector.);
257 }
258
259 return GSL_SUCCESScxx . . $ GSL_SUCCESS.;
260 }