Debian Codegraph @

external/gsl/gsl_eigen__hermv.c

raw symbols SCIP
1 /* eigen/hermv.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 #include "gsl__config.h"cxx . . $ `<file>/external/gsl/gsl__config.h`/
21 #include <stdlib.h>
22 #include "gsl_math.h"cxx . . $ `<file>/external/gsl/gsl_math.h`/
23 #include "gsl_vector.h"cxx . . $ `<file>/external/gsl/gsl_vector.h`/
24 #include "gsl_matrix.h"cxx . . $ `<file>/external/gsl/gsl_matrix.h`/
25 #include "gsl_complex_math.h"cxx . . $ `<file>/external/gsl/gsl_complex_math.h`/
26 #include "gsl_linalg.h"cxx . . $ `<file>/external/gsl/gsl_linalg.h`/
27 #include "gsl_eigen.h"cxx . . $ `<file>/external/gsl/gsl_eigen.h`/
28
29 /* Compute eigenvalues/eigenvectors of complex hermitian matrix using
30 reduction to real symmetric tridiagonal form, followed by QR
31 iteration with implicit shifts.
32
33 See Golub & Van Loan, "Matrix Computations" (3rd ed), Section 8.3 */
34
35 #include "gsl_eigen__qrstep.c"cxx . . $ `<file>/external/gsl/gsl_eigen__qrstep.c`/
36
37 gsl_eigen_hermv_workspacecxx . . $ gsl_eigen_hermv_workspace# *
38 gsl_eigen_hermv_alloccxx . . $ gsl_eigen_hermv_alloc(bf90a9fbb7ed288d). (const size_t n)
39 {
40 gsl_eigen_hermv_workspacecxx . . $ gsl_eigen_hermv_workspace# * w ;
41
42 if (n == 0)
43 {
44 GSL_ERROR_NULLcxx . . $ `external/gsl/gsl_errno.h:129:9`! ("matrix dimension must be positive integer", GSL_EINVAL);
45 }
46
47 w = (gsl_eigen_hermv_workspacecxx . . $ gsl_eigen_hermv_workspace# *) malloccxx . . $ malloc(bfcfa4d6b7f7ef64). (sizeof(gsl_eigen_hermv_workspacecxx . . $ gsl_eigen_hermv_workspace#));
48
49 if (w == 0)
50 {
51 GSL_ERROR_NULLcxx . . $ `external/gsl/gsl_errno.h:129:9`! ("failed to allocate space for workspace", GSL_ENOMEM);
52 }
53
54 w->dcxx . . $ $anonymous_type_e201739ce63d4a42_3#d. = (double *) malloccxx . . $ malloc(bfcfa4d6b7f7ef64). (n * sizeof (double));
55
56 if (w->dcxx . . $ $anonymous_type_e201739ce63d4a42_3#d. == 0)
57 {
58 freecxx . . $ free(5d22bdacc48458e8). (w);
59 GSL_ERROR_NULLcxx . . $ `external/gsl/gsl_errno.h:129:9`! ("failed to allocate space for diagonal", GSL_ENOMEM);
60 }
61
62 w->sdcxx . . $ $anonymous_type_e201739ce63d4a42_3#sd. = (double *) malloccxx . . $ malloc(bfcfa4d6b7f7ef64). (n * sizeof (double));
63
64 if (w->sdcxx . . $ $anonymous_type_e201739ce63d4a42_3#sd. == 0)
65 {
66 freecxx . . $ free(5d22bdacc48458e8). (w->dcxx . . $ $anonymous_type_e201739ce63d4a42_3#d.);
67 freecxx . . $ free(5d22bdacc48458e8). (w);
68 GSL_ERROR_NULLcxx . . $ `external/gsl/gsl_errno.h:129:9`! ("failed to allocate space for subdiagonal", GSL_ENOMEM);
69 }
70
71 w->taucxx . . $ $anonymous_type_e201739ce63d4a42_3#tau. = (double *) malloccxx . . $ malloc(bfcfa4d6b7f7ef64). (2 * n * sizeof (double));
72
73 if (w->taucxx . . $ $anonymous_type_e201739ce63d4a42_3#tau. == 0)
74 {
75 freecxx . . $ free(5d22bdacc48458e8). (w->sdcxx . . $ $anonymous_type_e201739ce63d4a42_3#sd.);
76 freecxx . . $ free(5d22bdacc48458e8). (w->dcxx . . $ $anonymous_type_e201739ce63d4a42_3#d.);
77 freecxx . . $ free(5d22bdacc48458e8). (w);
78 GSL_ERROR_NULLcxx . . $ `external/gsl/gsl_errno.h:129:9`! ("failed to allocate space for tau", GSL_ENOMEM);
79 }
80
81 w->gccxx . . $ $anonymous_type_e201739ce63d4a42_3#gc. = (double *) malloccxx . . $ malloc(bfcfa4d6b7f7ef64). (n * sizeof (double));
82
83 if (w->gccxx . . $ $anonymous_type_e201739ce63d4a42_3#gc. == 0)
84 {
85 freecxx . . $ free(5d22bdacc48458e8). (w->taucxx . . $ $anonymous_type_e201739ce63d4a42_3#tau.);
86 freecxx . . $ free(5d22bdacc48458e8). (w->sdcxx . . $ $anonymous_type_e201739ce63d4a42_3#sd.);
87 freecxx . . $ free(5d22bdacc48458e8). (w->dcxx . . $ $anonymous_type_e201739ce63d4a42_3#d.);
88 freecxx . . $ free(5d22bdacc48458e8). (w);
89 GSL_ERROR_NULLcxx . . $ `external/gsl/gsl_errno.h:129:9`! ("failed to allocate space for cosines", GSL_ENOMEM);
90 }
91
92 w->gscxx . . $ $anonymous_type_e201739ce63d4a42_3#gs. = (double *) malloccxx . . $ malloc(bfcfa4d6b7f7ef64). (n * sizeof (double));
93
94 if (w->gscxx . . $ $anonymous_type_e201739ce63d4a42_3#gs. == 0)
95 {
96 freecxx . . $ free(5d22bdacc48458e8). (w->gccxx . . $ $anonymous_type_e201739ce63d4a42_3#gc.);
97 freecxx . . $ free(5d22bdacc48458e8). (w->taucxx . . $ $anonymous_type_e201739ce63d4a42_3#tau.);
98 freecxx . . $ free(5d22bdacc48458e8). (w->sdcxx . . $ $anonymous_type_e201739ce63d4a42_3#sd.);
99 freecxx . . $ free(5d22bdacc48458e8). (w->dcxx . . $ $anonymous_type_e201739ce63d4a42_3#d.);
100 freecxx . . $ free(5d22bdacc48458e8). (w);
101 GSL_ERROR_NULLcxx . . $ `external/gsl/gsl_errno.h:129:9`! ("failed to allocate space for sines", GSL_ENOMEM);
102 }
103
104 w->sizecxx . . $ $anonymous_type_e201739ce63d4a42_3#size. = n;
105
106 return w;
107 }
108
109 void
110 gsl_eigen_hermv_freecxx . . $ gsl_eigen_hermv_free(b127c5de3c4c8875). (gsl_eigen_hermv_workspacecxx . . $ gsl_eigen_hermv_workspace# * w)
111 {
112 freecxx . . $ free(5d22bdacc48458e8). (w->gscxx . . $ $anonymous_type_e201739ce63d4a42_3#gs.);
113 freecxx . . $ free(5d22bdacc48458e8). (w->gccxx . . $ $anonymous_type_e201739ce63d4a42_3#gc.);
114 freecxx . . $ free(5d22bdacc48458e8). (w->taucxx . . $ $anonymous_type_e201739ce63d4a42_3#tau.);
115 freecxx . . $ free(5d22bdacc48458e8). (w->sdcxx . . $ $anonymous_type_e201739ce63d4a42_3#sd.);
116 freecxx . . $ free(5d22bdacc48458e8). (w->dcxx . . $ $anonymous_type_e201739ce63d4a42_3#d.);
117 freecxx . . $ free(5d22bdacc48458e8). (w);
118 }
119
120 int
121 gsl_eigen_hermvcxx . . $ gsl_eigen_hermv(8ec11bd32837ef28). (gsl_matrix_complexcxx . . $ gsl_matrix_complex# * A, gsl_vectorcxx . . $ gsl_vector# * eval,
122 gsl_matrix_complexcxx . . $ gsl_matrix_complex# * evec,
123 gsl_eigen_hermv_workspacecxx . . $ gsl_eigen_hermv_workspace# * w)
124 {
125 if (A->size1cxx . . $ $anonymous_type_76f4ec40ad1923db_0#size1. != A->size2cxx . . $ $anonymous_type_76f4ec40ad1923db_0#size2.)
126 {
127 GSL_ERRORcxx . . $ `external/gsl/gsl_errno.h:104:9`! ("matrix must be square to compute eigenvalues", GSL_ENOTSQR);
128 }
129 else if (eval->sizecxx . . $ $anonymous_type_a8c2e3e00d6867c2_0#size. != A->size1cxx . . $ $anonymous_type_76f4ec40ad1923db_0#size1.)
130 {
131 GSL_ERRORcxx . . $ `external/gsl/gsl_errno.h:104:9`! ("eigenvalue vector must match matrix size", GSL_EBADLEN);
132 }
133 else if (evec->size1cxx . . $ $anonymous_type_76f4ec40ad1923db_0#size1. != A->size1cxx . . $ $anonymous_type_76f4ec40ad1923db_0#size1. || evec->size2cxx . . $ $anonymous_type_76f4ec40ad1923db_0#size2. != A->size1cxx . . $ $anonymous_type_76f4ec40ad1923db_0#size1.)
134 {
135 GSL_ERRORcxx . . $ `external/gsl/gsl_errno.h:104:9`! ("eigenvector matrix must match matrix size", GSL_EBADLEN);
136 }
137 else
138 {
139 const size_t N = A->size1cxx . . $ $anonymous_type_76f4ec40ad1923db_0#size1.;
140 double *const d = w->dcxx . . $ $anonymous_type_e201739ce63d4a42_3#d.;
141 double *const sd = w->sdcxx . . $ $anonymous_type_e201739ce63d4a42_3#sd.;
142
143 size_t a, b;
144
145 /* handle special case */
146
147 if (N == 1)
148 {
149 gsl_complexcxx . . $ gsl_complex# A00 = gsl_matrix_complex_getcxx . . $ gsl_matrix_complex_get(30564a92bc25dfb2). (A, 0, 0);
150 gsl_vector_setcxx . . $ gsl_vector_set(c35f863a529e8fae). (eval, 0, GSL_REALcxx . . $ `external/gsl/gsl_complex.h:88:9`!(A00));
151 gsl_matrix_complex_setcxx . . $ gsl_matrix_complex_set(2f351991ff7604). (evec, 0, 0, GSL_COMPLEX_ONEcxx . . $ `external/gsl/gsl_complex_math.h:51:9`!);
152 return GSL_SUCCESScxx . . $ GSL_SUCCESS.;
153 }
154
155 /* Transform the matrix into a symmetric tridiagonal form */
156
157 {
158 gsl_vector_viewcxx . . $ gsl_vector_view# d_vec = gsl_vector_view_arraycxx . . $ gsl_vector_view_array(8bd5fb11e568e882). (d, N);
159 gsl_vector_viewcxx . . $ gsl_vector_view# sd_vec = gsl_vector_view_arraycxx . . $ gsl_vector_view_array(8bd5fb11e568e882). (sd, N - 1);
160 gsl_vector_complex_viewcxx . . $ gsl_vector_complex_view# tau_vec = gsl_vector_complex_view_arraycxx . . $ gsl_vector_complex_view_array(bba33b6b9faaeb25). (w->taucxx . . $ $anonymous_type_e201739ce63d4a42_3#tau., N-1);
161 gsl_linalg_hermtd_decompcxx . . $ gsl_linalg_hermtd_decomp(bc47534ab4b69ea2). (A, &tau_vec.vectorcxx . . $ $anonymous_type_8293e13329784d65_1#vector.);
162 gsl_linalg_hermtd_unpackcxx . . $ gsl_linalg_hermtd_unpack(20fa6af30e0074bf). (A, &tau_vec.vectorcxx . . $ $anonymous_type_8293e13329784d65_1#vector., evec, &d_vec.vectorcxx . . $ $anonymous_type_a8c2e3e00d6867c2_1#vector., &sd_vec.vectorcxx . . $ $anonymous_type_a8c2e3e00d6867c2_1#vector.);
163 }
164
165 /* Make an initial pass through the tridiagonal decomposition
166 to remove off-diagonal elements which are effectively zero */
167
168 chop_small_elementscxx . . $ chop_small_elements(dd13095031ccc7a7). (N, d, sd);
169
170 /* Progressively reduce the matrix until it is diagonal */
171
172 b = N - 1;
173
174 while (b > 0)
175 {
176 if (sd[b - 1] == 0.0 || isnancxx . . $ `<external>/11263917310783833665/math.h:980:11`!(sd[b - 1]))
177 {
178 b--;
179 continue;
180 }
181
182 /* Find the largest unreduced block (a,b) starting from b
183 and working backwards */
184
185 a = b - 1;
186
187 while (a > 0)
188 {
189 if (sd[a - 1] == 0.0)
190 {
191 break;
192 }
193 a--;
194 }
195
196 {
197 size_t i;
198 const size_t n_block = b - a + 1;
199 double *d_block = d + a;
200 double *sd_block = sd + a;
201 double * const gc = w->gccxx . . $ $anonymous_type_e201739ce63d4a42_3#gc.;
202 double * const gs = w->gscxx . . $ $anonymous_type_e201739ce63d4a42_3#gs.;
203
204 /* apply QR reduction with implicit deflation to the
205 unreduced block */
206
207 qrstepcxx . . $ qrstep(580e95a87e9be734). (n_block, d_block, sd_block, gc, gs);
208
209 /* Apply Givens rotation Gij(c,s) to matrix Q, Q <- Q G */
210
211 for (i = 0; i < n_block - 1; i++)
212 {
213 const double c = gc[i], s = gs[i];
214 size_t k;
215
216 for (k = 0; k < N; k++)
217 {
218 gsl_complexcxx . . $ gsl_complex# qki = gsl_matrix_complex_getcxx . . $ gsl_matrix_complex_get(30564a92bc25dfb2). (evec, k, a + i);
219 gsl_complexcxx . . $ gsl_complex# qkj = gsl_matrix_complex_getcxx . . $ gsl_matrix_complex_get(30564a92bc25dfb2). (evec, k, a + i + 1);
220 /* qki <= qki * c - qkj * s */
221 /* qkj <= qki * s + qkj * c */
222 gsl_complexcxx . . $ gsl_complex# x1 = gsl_complex_mul_realcxx . . $ gsl_complex_mul_real(c6889a7dee95c079).(qki, c);
223 gsl_complexcxx . . $ gsl_complex# y1 = gsl_complex_mul_realcxx . . $ gsl_complex_mul_real(c6889a7dee95c079).(qkj, -s);
224
225 gsl_complexcxx . . $ gsl_complex# x2 = gsl_complex_mul_realcxx . . $ gsl_complex_mul_real(c6889a7dee95c079).(qki, s);
226 gsl_complexcxx . . $ gsl_complex# y2 = gsl_complex_mul_realcxx . . $ gsl_complex_mul_real(c6889a7dee95c079).(qkj, c);
227
228 gsl_complexcxx . . $ gsl_complex# qqki = gsl_complex_addcxx . . $ gsl_complex_add(97d196ab28e6deec).(x1, y1);
229 gsl_complexcxx . . $ gsl_complex# qqkj = gsl_complex_addcxx . . $ gsl_complex_add(97d196ab28e6deec).(x2, y2);
230
231 gsl_matrix_complex_setcxx . . $ gsl_matrix_complex_set(2f351991ff7604). (evec, k, a + i, qqki);
232 gsl_matrix_complex_setcxx . . $ gsl_matrix_complex_set(2f351991ff7604). (evec, k, a + i + 1, qqkj);
233 }
234 }
235
236 /* remove any small off-diagonal elements */
237
238 chop_small_elementscxx . . $ chop_small_elements(dd13095031ccc7a7). (n_block, d_block, sd_block);
239 }
240 }
241
242 {
243 gsl_vector_viewcxx . . $ gsl_vector_view# d_vec = gsl_vector_view_arraycxx . . $ gsl_vector_view_array(8bd5fb11e568e882). (d, N);
244 gsl_vector_memcpycxx . . $ gsl_vector_memcpy(950c164c4e50c555). (eval, &d_vec.vectorcxx . . $ $anonymous_type_a8c2e3e00d6867c2_1#vector.);
245 }
246
247 return GSL_SUCCESScxx . . $ GSL_SUCCESS.;
248 }
249 }