Debian Codegraph @

external/gsl/gsl_eigen__nonsymm.c

raw symbols SCIP
1 /* eigen/nonsymm.c
2 *
3 * Copyright (C) 2006 Patrick Alken
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 <math.h>
23 #include "gsl_eigen.h"cxx . . $ `<file>/external/gsl/gsl_eigen.h`/
24 #include "gsl_linalg.h"cxx . . $ `<file>/external/gsl/gsl_linalg.h`/
25 #include "gsl_math.h"cxx . . $ `<file>/external/gsl/gsl_math.h`/
26 #include "gsl_blas.h"cxx . . $ `<file>/external/gsl/gsl_blas.h`/
27 #include "gsl_vector.h"cxx . . $ `<file>/external/gsl/gsl_vector.h`/
28 #include "gsl_vector_complex.h"cxx . . $ `<file>/external/gsl/gsl_vector_complex.h`/
29 #include "gsl_matrix.h"cxx . . $ `<file>/external/gsl/gsl_matrix.h`/
30
31 /*
32 * This module computes the eigenvalues of a real nonsymmetric
33 * matrix, using the double shift Francis method.
34 *
35 * See the references in francis.c.
36 *
37 * This module gets the matrix ready by balancing it and
38 * reducing it to Hessenberg form before passing it to the
39 * francis module.
40 */
41
42 /*
43 gsl_eigen_nonsymm_alloc()
44
45 Allocate a workspace for solving the nonsymmetric eigenvalue problem.
46 The size of this workspace is O(2n)
47
48 Inputs: n - size of matrix
49
50 Return: pointer to workspace
51 */
52
53 gsl_eigen_nonsymm_workspacecxx . . $ gsl_eigen_nonsymm_workspace# *
54 gsl_eigen_nonsymm_alloccxx . . $ gsl_eigen_nonsymm_alloc(e27e4782bceda4).(const size_tcxx . . $ size_t# n)
55 {
56 gsl_eigen_nonsymm_workspacecxx . . $ gsl_eigen_nonsymm_workspace# *w;
57
58 if (n == 0)
59 {
60 GSL_ERROR_NULLcxx . . $ `external/gsl/gsl_errno.h:129:9`! ("matrix dimension must be positive integer",
61 GSL_EINVAL);
62 }
63
64 w = (gsl_eigen_nonsymm_workspacecxx . . $ gsl_eigen_nonsymm_workspace# *)
65 calloccxx . . $ calloc(63a7bf2941bfcd7a). (1, sizeof (gsl_eigen_nonsymm_workspacecxx . . $ gsl_eigen_nonsymm_workspace#));
66
67 if (w == 0)
68 {
69 GSL_ERROR_NULLcxx . . $ `external/gsl/gsl_errno.h:129:9`! ("failed to allocate space for workspace", GSL_ENOMEM);
70 }
71
72 w->sizecxx . . $ $anonymous_type_e201739ce63d4a42_5#size. = n;
73 w->Zcxx . . $ $anonymous_type_e201739ce63d4a42_5#Z. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
74 w->do_balancecxx . . $ $anonymous_type_e201739ce63d4a42_5#do_balance. = 0;
75
76 w->diagcxx . . $ $anonymous_type_e201739ce63d4a42_5#diag. = gsl_vector_alloccxx . . $ gsl_vector_alloc(71d9e095f27e8ea9).(n);
77
78 if (w->diagcxx . . $ $anonymous_type_e201739ce63d4a42_5#diag. == 0)
79 {
80 gsl_eigen_nonsymm_freecxx . . $ gsl_eigen_nonsymm_free(9d70855858afc512).(w);
81 GSL_ERROR_NULLcxx . . $ `external/gsl/gsl_errno.h:129:9`! ("failed to allocate space for balancing vector", GSL_ENOMEM);
82 }
83
84 w->taucxx . . $ $anonymous_type_e201739ce63d4a42_5#tau. = gsl_vector_alloccxx . . $ gsl_vector_alloc(71d9e095f27e8ea9).(n);
85
86 if (w->taucxx . . $ $anonymous_type_e201739ce63d4a42_5#tau. == 0)
87 {
88 gsl_eigen_nonsymm_freecxx . . $ gsl_eigen_nonsymm_free(9d70855858afc512).(w);
89 GSL_ERROR_NULLcxx . . $ `external/gsl/gsl_errno.h:129:9`! ("failed to allocate space for hessenberg coefficients", GSL_ENOMEM);
90 }
91
92 w->francis_workspace_pcxx . . $ $anonymous_type_e201739ce63d4a42_5#francis_workspace_p. = gsl_eigen_francis_alloccxx . . $ gsl_eigen_francis_alloc(b4350ea11ad12641).();
93
94 if (w->francis_workspace_pcxx . . $ $anonymous_type_e201739ce63d4a42_5#francis_workspace_p. == 0)
95 {
96 gsl_eigen_nonsymm_freecxx . . $ gsl_eigen_nonsymm_free(9d70855858afc512).(w);
97 GSL_ERROR_NULLcxx . . $ `external/gsl/gsl_errno.h:129:9`! ("failed to allocate space for francis workspace", GSL_ENOMEM);
98 }
99
100 return (w);
101 } /* gsl_eigen_nonsymm_alloc() */
102
103 /*
104 gsl_eigen_nonsymm_free()
105 Free workspace w
106 */
107
108 void
109 gsl_eigen_nonsymm_freecxx . . $ gsl_eigen_nonsymm_free(9d70855858afc512). (gsl_eigen_nonsymm_workspacecxx . . $ gsl_eigen_nonsymm_workspace# * w)
110 {
111 if (w->taucxx . . $ $anonymous_type_e201739ce63d4a42_5#tau.)
112 gsl_vector_freecxx . . $ gsl_vector_free(5d65852ca0326259).(w->taucxx . . $ $anonymous_type_e201739ce63d4a42_5#tau.);
113
114 if (w->diagcxx . . $ $anonymous_type_e201739ce63d4a42_5#diag.)
115 gsl_vector_freecxx . . $ gsl_vector_free(5d65852ca0326259).(w->diagcxx . . $ $anonymous_type_e201739ce63d4a42_5#diag.);
116
117 if (w->francis_workspace_pcxx . . $ $anonymous_type_e201739ce63d4a42_5#francis_workspace_p.)
118 gsl_eigen_francis_freecxx . . $ gsl_eigen_francis_free(6cacf312a1c1f5c5).(w->francis_workspace_pcxx . . $ $anonymous_type_e201739ce63d4a42_5#francis_workspace_p.);
119
120 freecxx . . $ free(5d22bdacc48458e8).(w);
121 } /* gsl_eigen_nonsymm_free() */
122
123 /*
124 gsl_eigen_nonsymm_params()
125 Set some parameters which define how we solve the eigenvalue
126 problem.
127
128 Inputs: compute_t - 1 if we want to compute T, 0 if not
129 balance - 1 if we want to balance the matrix, 0 if not
130 w - nonsymm workspace
131 */
132
133 void
134 gsl_eigen_nonsymm_paramscxx . . $ gsl_eigen_nonsymm_params(a30e7d4d35efff57). (const int compute_t, const int balance,
135 gsl_eigen_nonsymm_workspacecxx . . $ gsl_eigen_nonsymm_workspace# *w)
136 {
137 gsl_eigen_francis_Tcxx . . $ gsl_eigen_francis_T(8371d60ac8157c82).(compute_t, w->francis_workspace_pcxx . . $ $anonymous_type_e201739ce63d4a42_5#francis_workspace_p.);
138 w->do_balancecxx . . $ $anonymous_type_e201739ce63d4a42_5#do_balance. = balance;
139 } /* gsl_eigen_nonsymm_params() */
140
141 /*
142 gsl_eigen_nonsymm()
143
144 Solve the nonsymmetric eigenvalue problem
145
146 A x = \lambda x
147
148 for the eigenvalues \lambda using the Francis method.
149
150 Here we compute the real Schur form
151
152 T = Z^t A Z
153
154 with the diagonal blocks of T giving us the eigenvalues.
155 Z is a matrix of Schur vectors which is not computed by
156 this algorithm. See gsl_eigen_nonsymm_Z().
157
158 Inputs: A - general real matrix
159 eval - where to store eigenvalues
160 w - workspace
161
162 Return: success or error
163
164 Notes: If T is computed, it is stored in A on output. Otherwise
165 the diagonal of A contains the 1-by-1 and 2-by-2 eigenvalue
166 blocks.
167 */
168
169 int
170 gsl_eigen_nonsymmcxx . . $ gsl_eigen_nonsymm(dba7368a7f99deb5). (gsl_matrixcxx . . $ gsl_matrix# * A, gsl_vector_complexcxx . . $ gsl_vector_complex# * eval,
171 gsl_eigen_nonsymm_workspacecxx . . $ gsl_eigen_nonsymm_workspace# * w)
172 {
173 const size_tcxx . . $ size_t# N = A->size1cxx . . $ $anonymous_type_2f547ace9ee68af9_0#size1.;
174
175 /* check matrix and vector sizes */
176
177 if (N != A->size2cxx . . $ $anonymous_type_2f547ace9ee68af9_0#size2.)
178 {
179 GSL_ERRORcxx . . $ `external/gsl/gsl_errno.h:104:9`! ("matrix must be square to compute eigenvalues", GSL_ENOTSQR);
180 }
181 else if (eval->sizecxx . . $ $anonymous_type_8293e13329784d65_0#size. != N)
182 {
183 GSL_ERRORcxx . . $ `external/gsl/gsl_errno.h:104:9`! ("eigenvalue vector must match matrix size", GSL_EBADLEN);
184 }
185 else
186 {
187 int s;
188
189 if (w->do_balancecxx . . $ $anonymous_type_e201739ce63d4a42_5#do_balance.)
190 {
191 /* balance the matrix */
192 gsl_linalg_balance_matrixcxx . . $ gsl_linalg_balance_matrix(2b074ddc1e11e0af).(A, w->diagcxx . . $ $anonymous_type_e201739ce63d4a42_5#diag.);
193 }
194
195 /* compute the Hessenberg reduction of A */
196 gsl_linalg_hessenberg_decompcxx . . $ gsl_linalg_hessenberg_decomp(2b074ddc1e11e0af).(A, w->taucxx . . $ $anonymous_type_e201739ce63d4a42_5#tau.);
197
198 if (w->Zcxx . . $ $anonymous_type_e201739ce63d4a42_5#Z.)
199 {
200 /*
201 * initialize the matrix Z to U, which is the matrix used
202 * to construct the Hessenberg reduction.
203 */
204
205 /* compute U and store it in Z */
206 gsl_linalg_hessenberg_unpackcxx . . $ gsl_linalg_hessenberg_unpack(1cd6cd0fafcc7a5f).(A, w->taucxx . . $ $anonymous_type_e201739ce63d4a42_5#tau., w->Zcxx . . $ $anonymous_type_e201739ce63d4a42_5#Z.);
207
208 /* find the eigenvalues and Schur vectors */
209 s = gsl_eigen_francis_Zcxx . . $ gsl_eigen_francis_Z(c3e73f5536459245).(A, eval, w->Zcxx . . $ $anonymous_type_e201739ce63d4a42_5#Z., w->francis_workspace_pcxx . . $ $anonymous_type_e201739ce63d4a42_5#francis_workspace_p.);
210
211 if (w->do_balancecxx . . $ $anonymous_type_e201739ce63d4a42_5#do_balance.)
212 {
213 /*
214 * The Schur vectors in Z are the vectors for the balanced
215 * matrix. We now must undo the balancing to get the
216 * vectors for the original matrix A.
217 */
218 gsl_linalg_balance_accumcxx . . $ gsl_linalg_balance_accum(2b074ddc1e11e0af).(w->Zcxx . . $ $anonymous_type_e201739ce63d4a42_5#Z., w->diagcxx . . $ $anonymous_type_e201739ce63d4a42_5#diag.);
219 }
220 }
221 else
222 {
223 /* find the eigenvalues only */
224 s = gsl_eigen_franciscxx . . $ gsl_eigen_francis(8700f6223711b7fa).(A, eval, w->francis_workspace_pcxx . . $ $anonymous_type_e201739ce63d4a42_5#francis_workspace_p.);
225 }
226
227 w->n_evalscxx . . $ $anonymous_type_e201739ce63d4a42_5#n_evals. = w->francis_workspace_pcxx . . $ $anonymous_type_e201739ce63d4a42_5#francis_workspace_p.->n_evalscxx . . $ $anonymous_type_e201739ce63d4a42_4#n_evals.;
228
229 return s;
230 }
231 } /* gsl_eigen_nonsymm() */
232
233 /*
234 gsl_eigen_nonsymm_Z()
235
236 Solve the nonsymmetric eigenvalue problem
237
238 A x = \lambda x
239
240 for the eigenvalues \lambda.
241
242 Here we compute the real Schur form
243
244 T = Z^t A Z
245
246 with the diagonal blocks of T giving us the eigenvalues.
247 Z is the matrix of Schur vectors.
248
249 Inputs: A - general real matrix
250 eval - where to store eigenvalues
251 Z - where to store Schur vectors
252 w - workspace
253
254 Return: success or error
255
256 Notes: If T is computed, it is stored in A on output. Otherwise
257 the diagonal of A contains the 1-by-1 and 2-by-2 eigenvalue
258 blocks.
259 */
260
261 int
262 gsl_eigen_nonsymm_Zcxx . . $ gsl_eigen_nonsymm_Z(ea83bb8898cb0ffc). (gsl_matrixcxx . . $ gsl_matrix# * A, gsl_vector_complexcxx . . $ gsl_vector_complex# * eval,
263 gsl_matrixcxx . . $ gsl_matrix# * Z, gsl_eigen_nonsymm_workspacecxx . . $ gsl_eigen_nonsymm_workspace# * w)
264 {
265 /* check matrix and vector sizes */
266
267 if (A->size1cxx . . $ $anonymous_type_2f547ace9ee68af9_0#size1. != A->size2cxx . . $ $anonymous_type_2f547ace9ee68af9_0#size2.)
268 {
269 GSL_ERRORcxx . . $ `external/gsl/gsl_errno.h:104:9`! ("matrix must be square to compute eigenvalues", GSL_ENOTSQR);
270 }
271 else if (eval->sizecxx . . $ $anonymous_type_8293e13329784d65_0#size. != A->size1cxx . . $ $anonymous_type_2f547ace9ee68af9_0#size1.)
272 {
273 GSL_ERRORcxx . . $ `external/gsl/gsl_errno.h:104:9`! ("eigenvalue vector must match matrix size", GSL_EBADLEN);
274 }
275 else if ((Z->size1cxx . . $ $anonymous_type_2f547ace9ee68af9_0#size1. != Z->size2cxx . . $ $anonymous_type_2f547ace9ee68af9_0#size2.) || (Z->size1cxx . . $ $anonymous_type_2f547ace9ee68af9_0#size1. != A->size1cxx . . $ $anonymous_type_2f547ace9ee68af9_0#size1.))
276 {
277 GSL_ERRORcxx . . $ `external/gsl/gsl_errno.h:104:9`! ("Z matrix has wrong dimensions", GSL_EBADLEN);
278 }
279 else
280 {
281 int s;
282
283 w->Zcxx . . $ $anonymous_type_e201739ce63d4a42_5#Z. = Z;
284
285 s = gsl_eigen_nonsymmcxx . . $ gsl_eigen_nonsymm(dba7368a7f99deb5).(A, eval, w);
286
287 w->Zcxx . . $ $anonymous_type_e201739ce63d4a42_5#Z. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
288
289 return s;
290 }
291 } /* gsl_eigen_nonsymm_Z() */