Debian Codegraph @

external/gsl/gsl_eigen__herm.c

raw symbols SCIP
1 /* eigen/herm.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_linalg.h"cxx . . $ `<file>/external/gsl/gsl_linalg.h`/
26 #include "gsl_eigen.h"cxx . . $ `<file>/external/gsl/gsl_eigen.h`/
27
28 /* Compute eigenvalues of complex hermitian matrix using reduction to
29 real symmetric tridiagonal form, followed by QR iteration with
30 implicit shifts.
31
32 See Golub & Van Loan, "Matrix Computations" (3rd ed), Section 8.3 */
33
34 #include "gsl_eigen__qrstep.c"cxx . . $ `<file>/external/gsl/gsl_eigen__qrstep.c`/
35
36 gsl_eigen_herm_workspacecxx . . $ gsl_eigen_herm_workspace# *
37 gsl_eigen_herm_alloccxx . . $ gsl_eigen_herm_alloc(9f6dbaacba7a3d8a). (const size_tcxx . . $ size_t# n)
38 {
39 gsl_eigen_herm_workspacecxx . . $ gsl_eigen_herm_workspace# * w ;
40
41 if (n == 0)
42 {
43 GSL_ERROR_NULLcxx . . $ `external/gsl/gsl_errno.h:129:9`! ("matrix dimension must be positive integer", GSL_EINVAL);
44 }
45
46 w = (gsl_eigen_herm_workspacecxx . . $ gsl_eigen_herm_workspace# *) malloccxx . . $ malloc(bfcfa4d6b7f7ef64). (sizeof(gsl_eigen_herm_workspacecxx . . $ gsl_eigen_herm_workspace#));
47
48 if (w == 0)
49 {
50 GSL_ERROR_NULLcxx . . $ `external/gsl/gsl_errno.h:129:9`! ("failed to allocate space for workspace", GSL_ENOMEM);
51 }
52
53 w->dcxx . . $ $anonymous_type_e201739ce63d4a42_2#d. = (double *) malloccxx . . $ malloc(bfcfa4d6b7f7ef64). (n * sizeof (double));
54
55 if (w->dcxx . . $ $anonymous_type_e201739ce63d4a42_2#d. == 0)
56 {
57 GSL_ERROR_NULLcxx . . $ `external/gsl/gsl_errno.h:129:9`! ("failed to allocate space for diagonal", GSL_ENOMEM);
58 }
59
60 w->sdcxx . . $ $anonymous_type_e201739ce63d4a42_2#sd. = (double *) malloccxx . . $ malloc(bfcfa4d6b7f7ef64). (n * sizeof (double));
61
62 if (w->sdcxx . . $ $anonymous_type_e201739ce63d4a42_2#sd. == 0)
63 {
64 GSL_ERROR_NULLcxx . . $ `external/gsl/gsl_errno.h:129:9`! ("failed to allocate space for subdiagonal", GSL_ENOMEM);
65 }
66
67 w->taucxx . . $ $anonymous_type_e201739ce63d4a42_2#tau. = (double *) malloccxx . . $ malloc(bfcfa4d6b7f7ef64). (2 * n * sizeof (double));
68
69 if (w->taucxx . . $ $anonymous_type_e201739ce63d4a42_2#tau. == 0)
70 {
71 GSL_ERROR_NULLcxx . . $ `external/gsl/gsl_errno.h:129:9`! ("failed to allocate space for tau", GSL_ENOMEM);
72 }
73
74 w->sizecxx . . $ $anonymous_type_e201739ce63d4a42_2#size. = n;
75
76 return w;
77 }
78
79 void
80 gsl_eigen_herm_freecxx . . $ gsl_eigen_herm_free(532e1c404cbb9092). (gsl_eigen_herm_workspacecxx . . $ gsl_eigen_herm_workspace# * w)
81 {
82 freecxx . . $ free(5d22bdacc48458e8). (w->taucxx . . $ $anonymous_type_e201739ce63d4a42_2#tau.);
83 freecxx . . $ free(5d22bdacc48458e8). (w->sdcxx . . $ $anonymous_type_e201739ce63d4a42_2#sd.);
84 freecxx . . $ free(5d22bdacc48458e8). (w->dcxx . . $ $anonymous_type_e201739ce63d4a42_2#d.);
85 freecxx . . $ free(5d22bdacc48458e8).(w);
86 }
87
88 int
89 gsl_eigen_hermcxx . . $ gsl_eigen_herm(82c1210742bdc18b). (gsl_matrix_complexcxx . . $ gsl_matrix_complex# * A, gsl_vectorcxx . . $ gsl_vector# * eval,
90 gsl_eigen_herm_workspacecxx . . $ gsl_eigen_herm_workspace# * w)
91 {
92 if (A->size1cxx . . $ $anonymous_type_76f4ec40ad1923db_0#size1. != A->size2cxx . . $ $anonymous_type_76f4ec40ad1923db_0#size2.)
93 {
94 GSL_ERRORcxx . . $ `external/gsl/gsl_errno.h:104:9`! ("matrix must be square to compute eigenvalues", GSL_ENOTSQR);
95 }
96 else if (eval->sizecxx . . $ $anonymous_type_a8c2e3e00d6867c2_0#size. != A->size1cxx . . $ $anonymous_type_76f4ec40ad1923db_0#size1.)
97 {
98 GSL_ERRORcxx . . $ `external/gsl/gsl_errno.h:104:9`! ("eigenvalue vector must match matrix size", GSL_EBADLEN);
99 }
100 else
101 {
102 const size_tcxx . . $ size_t# N = A->size1cxx . . $ $anonymous_type_76f4ec40ad1923db_0#size1.;
103 double *const d = w->dcxx . . $ $anonymous_type_e201739ce63d4a42_2#d.;
104 double *const sd = w->sdcxx . . $ $anonymous_type_e201739ce63d4a42_2#sd.;
105
106 size_tcxx . . $ size_t# a, b;
107
108 /* handle special case */
109
110 if (N == 1)
111 {
112 gsl_complexcxx . . $ gsl_complex# A00 = gsl_matrix_complex_getcxx . . $ gsl_matrix_complex_get(30564a92bc25dfb2). (A, 0, 0);
113 gsl_vector_setcxx . . $ gsl_vector_set(c35f863a529e8fae). (eval, 0, GSL_REALcxx . . $ `external/gsl/gsl_complex.h:88:9`!(A00));
114 return GSL_SUCCESScxx . . $ GSL_SUCCESS.;
115 }
116
117 {
118 gsl_vector_viewcxx . . $ gsl_vector_view# d_vec = gsl_vector_view_arraycxx . . $ gsl_vector_view_array(8bd5fb11e568e882). (d, N);
119 gsl_vector_viewcxx . . $ gsl_vector_view# sd_vec = gsl_vector_view_arraycxx . . $ gsl_vector_view_array(8bd5fb11e568e882). (sd, N - 1);
120 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_2#tau., N-1);
121 gsl_linalg_hermtd_decompcxx . . $ gsl_linalg_hermtd_decomp(bc47534ab4b69ea2). (A, &tau_vec.vectorcxx . . $ $anonymous_type_8293e13329784d65_1#vector.);
122 gsl_linalg_hermtd_unpack_Tcxx . . $ gsl_linalg_hermtd_unpack_T(3c56d4b2856e13). (A, &d_vec.vectorcxx . . $ $anonymous_type_a8c2e3e00d6867c2_1#vector., &sd_vec.vectorcxx . . $ $anonymous_type_a8c2e3e00d6867c2_1#vector.);
123 }
124
125 /* Make an initial pass through the tridiagonal decomposition
126 to remove off-diagonal elements which are effectively zero */
127
128 chop_small_elementscxx . . $ chop_small_elements(dd13095031ccc7a7). (N, d, sd);
129
130 /* Progressively reduce the matrix until it is diagonal */
131
132 b = N - 1;
133
134 while (b > 0)
135 {
136 if (sd[b - 1] == 0.0 || isnancxx . . $ `<external>/11263917310783833665/math.h:980:11`!(sd[b - 1]))
137 {
138 b--;
139 continue;
140 }
141
142 /* Find the largest unreduced block (a,b) starting from b
143 and working backwards */
144
145 a = b - 1;
146
147 while (a > 0)
148 {
149 if (sd[a - 1] == 0.0)
150 {
151 break;
152 }
153 a--;
154 }
155
156 {
157 const size_tcxx . . $ size_t# n_block = b - a + 1;
158 double *d_block = d + a;
159 double *sd_block = sd + a;
160
161 /* apply QR reduction with implicit deflation to the
162 unreduced block */
163
164 qrstepcxx . . $ qrstep(580e95a87e9be734). (n_block, d_block, sd_block, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!);
165
166 /* remove any small off-diagonal elements */
167
168 chop_small_elementscxx . . $ chop_small_elements(dd13095031ccc7a7). (n_block, d_block, sd_block);
169 }
170 }
171
172 {
173 gsl_vector_viewcxx . . $ gsl_vector_view# d_vec = gsl_vector_view_arraycxx . . $ gsl_vector_view_array(8bd5fb11e568e882). (d, N);
174 gsl_vector_memcpycxx . . $ gsl_vector_memcpy(950c164c4e50c555). (eval, &d_vec.vectorcxx . . $ $anonymous_type_a8c2e3e00d6867c2_1#vector.);
175 }
176
177 return GSL_SUCCESScxx . . $ GSL_SUCCESS.;
178 }
179 }
180
181