Debian Codegraph @

external/gsl/gsl_linalg__hh.c

raw symbols SCIP
1 /* linalg/hh.c
2 *
3 * Copyright (C) 1996, 1997, 1998, 1999, 2000, 2007 Gerard Jungman, 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 /* Author: G. Jungman */
21
22 #include "gsl__config.h"cxx . . $ `<file>/external/gsl/gsl__config.h`/
23 #include <stdlib.h>
24 #include "gsl_math.h"cxx . . $ `<file>/external/gsl/gsl_math.h`/
25 #include "gsl_vector.h"cxx . . $ `<file>/external/gsl/gsl_vector.h`/
26 #include "gsl_matrix.h"cxx . . $ `<file>/external/gsl/gsl_matrix.h`/
27 #include "gsl_linalg.h"cxx . . $ `<file>/external/gsl/gsl_linalg.h`/
28
29 #define REALcxx . . $ `external/gsl/gsl_linalg__hh.c:29:9`! double
30
31 /* [Engeln-Mullges + Uhlig, Alg. 4.42]
32 */
33
34 int
35 gsl_linalg_HH_solvecxx . . $ gsl_linalg_HH_solve(8d73dd403187907c). (gsl_matrixcxx . . $ gsl_matrix# * A, const gsl_vectorcxx . . $ gsl_vector# * b, gsl_vectorcxx . . $ gsl_vector# * x)
36 {
37 if (A->size1cxx . . $ $anonymous_type_2f547ace9ee68af9_0#size1. > A->size2cxx . . $ $anonymous_type_2f547ace9ee68af9_0#size2.)
38 {
39 /* System is underdetermined. */
40
41 GSL_ERRORcxx . . $ `external/gsl/gsl_errno.h:104:9`! ("System is underdetermined", GSL_EINVAL);
42 }
43 else if (A->size2cxx . . $ $anonymous_type_2f547ace9ee68af9_0#size2. != x->sizecxx . . $ $anonymous_type_a8c2e3e00d6867c2_0#size.)
44 {
45 GSL_ERRORcxx . . $ `external/gsl/gsl_errno.h:104:9`! ("matrix and vector sizes must be equal", GSL_EBADLEN);
46 }
47 else
48 {
49 int status ;
50
51 gsl_vector_memcpycxx . . $ gsl_vector_memcpy(950c164c4e50c555). (x, b);
52
53 status = gsl_linalg_HH_svxcxx . . $ gsl_linalg_HH_svx(2b074ddc1e11e0af). (A, x);
54
55 return status ;
56 }
57 }
58
59 int
60 gsl_linalg_HH_svxcxx . . $ gsl_linalg_HH_svx(2b074ddc1e11e0af). (gsl_matrixcxx . . $ gsl_matrix# * A, gsl_vectorcxx . . $ gsl_vector# * x)
61 {
62 if (A->size1cxx . . $ $anonymous_type_2f547ace9ee68af9_0#size1. > A->size2cxx . . $ $anonymous_type_2f547ace9ee68af9_0#size2.)
63 {
64 /* System is underdetermined. */
65
66 GSL_ERRORcxx . . $ `external/gsl/gsl_errno.h:104:9`! ("System is underdetermined", GSL_EINVAL);
67 }
68 else if (A->size2cxx . . $ $anonymous_type_2f547ace9ee68af9_0#size2. != x->sizecxx . . $ $anonymous_type_a8c2e3e00d6867c2_0#size.)
69 {
70 GSL_ERRORcxx . . $ `external/gsl/gsl_errno.h:104:9`! ("matrix and vector sizes must be equal", GSL_EBADLEN);
71 }
72 else
73 {
74 const size_t N = A->size1cxx . . $ $anonymous_type_2f547ace9ee68af9_0#size1.;
75 const size_t M = A->size2cxx . . $ $anonymous_type_2f547ace9ee68af9_0#size2.;
76 size_t i, j, k;
77 REALcxx . . $ `external/gsl/gsl_linalg__hh.c:29:9`! *d = (REALcxx . . $ `external/gsl/gsl_linalg__hh.c:29:9`! *) malloccxx . . $ malloc(bfcfa4d6b7f7ef64). (N * sizeof (REALcxx . . $ `external/gsl/gsl_linalg__hh.c:29:9`!));
78
79 if (d == 0)
80 {
81 GSL_ERRORcxx . . $ `external/gsl/gsl_errno.h:104:9`! ("could not allocate memory for workspace", GSL_ENOMEM);
82 }
83
84 /* Perform Householder transformation. */
85
86 for (i = 0; i < N; i++)
87 {
88 const REALcxx . . $ `external/gsl/gsl_linalg__hh.c:29:9`! aii = gsl_matrix_getcxx . . $ gsl_matrix_get(dfa4c0641bd665a5). (A, i, i);
89 REALcxx . . $ `external/gsl/gsl_linalg__hh.c:29:9`! alpha;
90 REALcxx . . $ `external/gsl/gsl_linalg__hh.c:29:9`! f;
91 REALcxx . . $ `external/gsl/gsl_linalg__hh.c:29:9`! ak;
92 REALcxx . . $ `external/gsl/gsl_linalg__hh.c:29:9`! max_norm = 0.0;
93 REALcxx . . $ `external/gsl/gsl_linalg__hh.c:29:9`! r = 0.0;
94
95 for (k = i; k < M; k++)
96 {
97 REALcxx . . $ `external/gsl/gsl_linalg__hh.c:29:9`! aki = gsl_matrix_getcxx . . $ gsl_matrix_get(dfa4c0641bd665a5). (A, k, i);
98 r += aki * aki;
99 }
100
101 if (r == 0.0)
102 {
103 /* Rank of matrix is less than size1. */
104 freecxx . . $ free(5d22bdacc48458e8). (d);
105 GSL_ERRORcxx . . $ `external/gsl/gsl_errno.h:104:9`! ("matrix is rank deficient", GSL_ESING);
106 }
107
108 alpha = sqrt (r) * GSL_SIGNcxx . . $ `external/gsl/gsl_math.h:114:9`! (aii);
109
110 ak = 1.0 / (r + alpha * aii);
111 gsl_matrix_setcxx . . $ gsl_matrix_set(b56d954874bd7b13). (A, i, i, aii + alpha);
112
113 d[i] = -alpha;
114
115 for (k = i + 1; k < N; k++)
116 {
117 REALcxx . . $ `external/gsl/gsl_linalg__hh.c:29:9`! norm = 0.0;
118 f = 0.0;
119 for (j = i; j < M; j++)
120 {
121 REALcxx . . $ `external/gsl/gsl_linalg__hh.c:29:9`! ajk = gsl_matrix_getcxx . . $ gsl_matrix_get(dfa4c0641bd665a5). (A, j, k);
122 REALcxx . . $ `external/gsl/gsl_linalg__hh.c:29:9`! aji = gsl_matrix_getcxx . . $ gsl_matrix_get(dfa4c0641bd665a5). (A, j, i);
123 norm += ajk * ajk;
124 f += ajk * aji;
125 }
126 max_norm = GSL_MAXcxx . . $ `external/gsl/gsl_math.h:122:9`! (max_norm, norm);
127
128 f *= ak;
129
130 for (j = i; j < M; j++)
131 {
132 REALcxx . . $ `external/gsl/gsl_linalg__hh.c:29:9`! ajk = gsl_matrix_getcxx . . $ gsl_matrix_get(dfa4c0641bd665a5). (A, j, k);
133 REALcxx . . $ `external/gsl/gsl_linalg__hh.c:29:9`! aji = gsl_matrix_getcxx . . $ gsl_matrix_get(dfa4c0641bd665a5). (A, j, i);
134 gsl_matrix_setcxx . . $ gsl_matrix_set(b56d954874bd7b13). (A, j, k, ajk - f * aji);
135 }
136 }
137
138 if (fabs (alpha) < 2.0 * GSL_DBL_EPSILONcxx . . $ `external/gsl/gsl_machine.h:17:9`! * sqrt (max_norm))
139 {
140 /* Apparent singularity. */
141 freecxx . . $ free(5d22bdacc48458e8). (d);
142 GSL_ERRORcxx . . $ `external/gsl/gsl_errno.h:104:9`!("apparent singularity detected", GSL_ESING);
143 }
144
145 /* Perform update of RHS. */
146
147 f = 0.0;
148 for (j = i; j < M; j++)
149 {
150 f += gsl_vector_getcxx . . $ gsl_vector_get(bd1f20df78adc7a). (x, j) * gsl_matrix_getcxx . . $ gsl_matrix_get(dfa4c0641bd665a5). (A, j, i);
151 }
152 f *= ak;
153 for (j = i; j < M; j++)
154 {
155 REALcxx . . $ `external/gsl/gsl_linalg__hh.c:29:9`! xj = gsl_vector_getcxx . . $ gsl_vector_get(bd1f20df78adc7a). (x, j);
156 REALcxx . . $ `external/gsl/gsl_linalg__hh.c:29:9`! aji = gsl_matrix_getcxx . . $ gsl_matrix_get(dfa4c0641bd665a5). (A, j, i);
157 gsl_vector_setcxx . . $ gsl_vector_set(c35f863a529e8fae). (x, j, xj - f * aji);
158 }
159 }
160
161 /* Perform back-substitution. */
162
163 for (i = N; i > 0 && i--;)
164 {
165 REALcxx . . $ `external/gsl/gsl_linalg__hh.c:29:9`! xi = gsl_vector_getcxx . . $ gsl_vector_get(bd1f20df78adc7a). (x, i);
166 REALcxx . . $ `external/gsl/gsl_linalg__hh.c:29:9`! sum = 0.0;
167 for (k = i + 1; k < N; k++)
168 {
169 sum += gsl_matrix_getcxx . . $ gsl_matrix_get(dfa4c0641bd665a5). (A, i, k) * gsl_vector_getcxx . . $ gsl_vector_get(bd1f20df78adc7a). (x, k);
170 }
171
172 gsl_vector_setcxx . . $ gsl_vector_set(c35f863a529e8fae). (x, i, (xi - sum) / d[i]);
173 }
174
175 freecxx . . $ free(5d22bdacc48458e8). (d);
176 return GSL_SUCCESScxx . . $ GSL_SUCCESS.;
177 }
178 }
179