Debian Codegraph @

external/gsl/gsl_linalg__choleskyc.c

raw symbols SCIP
1 /* linalg/choleskyc.c
2 *
3 * Copyright (C) 2007 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 "gsl_matrix.h"cxx . . $ `<file>/external/gsl/gsl_matrix.h`/
22 #include "gsl_vector.h"cxx . . $ `<file>/external/gsl/gsl_vector.h`/
23 #include "gsl_linalg.h"cxx . . $ `<file>/external/gsl/gsl_linalg.h`/
24 #include "gsl_math.h"cxx . . $ `<file>/external/gsl/gsl_math.h`/
25 #include "gsl_complex.h"cxx . . $ `<file>/external/gsl/gsl_complex.h`/
26 #include "gsl_complex_math.h"cxx . . $ `<file>/external/gsl/gsl_complex_math.h`/
27 #include "gsl_blas.h"cxx . . $ `<file>/external/gsl/gsl_blas.h`/
28 #include "gsl_errno.h"cxx . . $ `<file>/external/gsl/gsl_errno.h`/
29
30 /*
31 * This module contains routines related to the Cholesky decomposition
32 * of a complex Hermitian positive definite matrix.
33 */
34
35 static void cholesky_complex_conj_vectorcxx . . $ cholesky_complex_conj_vector(14d2b39c6913e90).(gsl_vector_complexcxx . . $ gsl_vector_complex# *v);
36
37 /*
38 gsl_linalg_complex_cholesky_decomp()
39 Perform the Cholesky decomposition on a Hermitian positive definite
40 matrix. See Golub & Van Loan, "Matrix Computations" (3rd ed),
41 algorithm 4.2.2.
42
43 Inputs: A - (input/output) complex postive definite matrix
44
45 Return: success or error
46
47 The lower triangle of A is overwritten with the Cholesky decomposition
48 */
49
50 int
51 gsl_linalg_complex_cholesky_decompcxx . . $ gsl_linalg_complex_cholesky_decomp(7df0ef78f3b78ea1).(gsl_matrix_complexcxx . . $ gsl_matrix_complex# *A)
52 {
53 const size_t N = A->size1cxx . . $ $anonymous_type_76f4ec40ad1923db_0#size1.;
54
55 if (N != A->size2cxx . . $ $anonymous_type_76f4ec40ad1923db_0#size2.)
56 {
57 GSL_ERRORcxx . . $ `external/gsl/gsl_errno.h:104:9`!("cholesky decomposition requires square matrix", GSL_ENOTSQR);
58 }
59 else
60 {
61 size_t j;
62 gsl_complexcxx . . $ gsl_complex# z;
63 double ajj;
64
65 for (j = 0; j < N; ++j)
66 {
67 z = gsl_matrix_complex_getcxx . . $ gsl_matrix_complex_get(30564a92bc25dfb2).(A, j, j);
68 ajj = GSL_REALcxx . . $ `external/gsl/gsl_complex.h:88:9`!(z);
69
70 if (j > 0)
71 {
72 gsl_vector_complex_const_viewcxx . . $ gsl_vector_complex_const_view# aj =
73 gsl_matrix_complex_const_subrowcxx . . $ gsl_matrix_complex_const_subrow(db75469b86b60574).(A, j, 0, j);
74
75 gsl_blas_zdotccxx . . $ gsl_blas_zdotc(8d43f868372e01dd).(&aj.vectorcxx . . $ $anonymous_type_8293e13329784d65_2#vector., &aj.vectorcxx . . $ $anonymous_type_8293e13329784d65_2#vector., &z);
76 ajj -= GSL_REALcxx . . $ `external/gsl/gsl_complex.h:88:9`!(z);
77 }
78
79 if (ajj <= 0.0)
80 {
81 GSL_ERRORcxx . . $ `external/gsl/gsl_errno.h:104:9`!("matrix is not positive definite", GSL_EDOM);
82 }
83
84 ajj = sqrtcxx . . $ sqrt(447c67c6676f75c3).(ajj);
85 GSL_SET_COMPLEXcxx . . $ `external/gsl/gsl_complex.h:95:9`!(&z, ajj, 0.0);
86 gsl_matrix_complex_setcxx . . $ gsl_matrix_complex_set(2f351991ff7604).(A, j, j, z);
87
88 if (j < N - 1)
89 {
90 gsl_vector_complex_viewcxx . . $ gsl_vector_complex_view# av =
91 gsl_matrix_complex_subcolumncxx . . $ gsl_matrix_complex_subcolumn(7af1c927b24e14b2).(A, j, j + 1, N - j - 1);
92
93 if (j > 0)
94 {
95 gsl_vector_complex_viewcxx . . $ gsl_vector_complex_view# aj =
96 gsl_matrix_complex_subrowcxx . . $ gsl_matrix_complex_subrow(7af1c927b24e14b2).(A, j, 0, j);
97 gsl_matrix_complex_viewcxx . . $ gsl_matrix_complex_view# am =
98 gsl_matrix_complex_submatrixcxx . . $ gsl_matrix_complex_submatrix(dc2a19db158e5229).(A, j + 1, 0, N - j - 1, j);
99
100 cholesky_complex_conj_vectorcxx . . $ cholesky_complex_conj_vector(14d2b39c6913e90).(&aj.vectorcxx . . $ $anonymous_type_8293e13329784d65_1#vector.);
101
102 gsl_blas_zgemvcxx . . $ gsl_blas_zgemv(478ea939ea106930).(CblasNoTranscxx . . $ CblasNoTrans.,
103 GSL_COMPLEX_NEGONEcxx . . $ `external/gsl/gsl_complex_math.h:53:9`!,
104 &am.matrixcxx . . $ $anonymous_type_76f4ec40ad1923db_1#matrix.,
105 &aj.vectorcxx . . $ $anonymous_type_8293e13329784d65_1#vector.,
106 GSL_COMPLEX_ONEcxx . . $ `external/gsl/gsl_complex_math.h:51:9`!,
107 &av.vectorcxx . . $ $anonymous_type_8293e13329784d65_1#vector.);
108
109 cholesky_complex_conj_vectorcxx . . $ cholesky_complex_conj_vector(14d2b39c6913e90).(&aj.vectorcxx . . $ $anonymous_type_8293e13329784d65_1#vector.);
110 }
111
112 gsl_blas_zdscalcxx . . $ gsl_blas_zdscal(c8d96af3c961907e).(1.0 / ajj, &av.vectorcxx . . $ $anonymous_type_8293e13329784d65_1#vector.);
113 }
114 }
115
116 return GSL_SUCCESScxx . . $ GSL_SUCCESS.;
117 }
118 } /* gsl_linalg_complex_cholesky_decomp() */
119
120 /*
121 gsl_linalg_complex_cholesky_solve()
122 Solve A x = b where A is in cholesky form
123 */
124
125 int
126 gsl_linalg_complex_cholesky_solvecxx . . $ gsl_linalg_complex_cholesky_solve(a6800f49a3eb6c26). (const gsl_matrix_complexcxx . . $ gsl_matrix_complex# * cholesky,
127 const gsl_vector_complexcxx . . $ gsl_vector_complex# * b,
128 gsl_vector_complexcxx . . $ gsl_vector_complex# * x)
129 {
130 if (cholesky->size1cxx . . $ $anonymous_type_76f4ec40ad1923db_0#size1. != cholesky->size2cxx . . $ $anonymous_type_76f4ec40ad1923db_0#size2.)
131 {
132 GSL_ERRORcxx . . $ `external/gsl/gsl_errno.h:104:9`! ("cholesky matrix must be square", GSL_ENOTSQR);
133 }
134 else if (cholesky->size1cxx . . $ $anonymous_type_76f4ec40ad1923db_0#size1. != b->sizecxx . . $ $anonymous_type_8293e13329784d65_0#size.)
135 {
136 GSL_ERRORcxx . . $ `external/gsl/gsl_errno.h:104:9`! ("matrix size must match b size", GSL_EBADLEN);
137 }
138 else if (cholesky->size2cxx . . $ $anonymous_type_76f4ec40ad1923db_0#size2. != x->sizecxx . . $ $anonymous_type_8293e13329784d65_0#size.)
139 {
140 GSL_ERRORcxx . . $ `external/gsl/gsl_errno.h:104:9`! ("matrix size must match solution size", GSL_EBADLEN);
141 }
142 else
143 {
144 gsl_vector_complex_memcpycxx . . $ gsl_vector_complex_memcpy(d25704378b556445). (x, b);
145
146 /* solve for y using forward-substitution, L y = b */
147
148 gsl_blas_ztrsvcxx . . $ gsl_blas_ztrsv(136538f36152c42). (CblasLowercxx . . $ CblasLower., CblasNoTranscxx . . $ CblasNoTrans., CblasNonUnitcxx . . $ CblasNonUnit., cholesky, x);
149
150 /* perform back-substitution, L^H x = y */
151
152 gsl_blas_ztrsvcxx . . $ gsl_blas_ztrsv(136538f36152c42). (CblasLowercxx . . $ CblasLower., CblasConjTranscxx . . $ CblasConjTrans., CblasNonUnitcxx . . $ CblasNonUnit., cholesky, x);
153
154 return GSL_SUCCESScxx . . $ GSL_SUCCESS.;
155 }
156 } /* gsl_linalg_complex_cholesky_solve() */
157
158 /*
159 gsl_linalg_complex_cholesky_svx()
160 Solve A x = b in place where A is in cholesky form
161 */
162
163 int
164 gsl_linalg_complex_cholesky_svxcxx . . $ gsl_linalg_complex_cholesky_svx(3a5732eb3b75b895). (const gsl_matrix_complexcxx . . $ gsl_matrix_complex# * cholesky,
165 gsl_vector_complexcxx . . $ gsl_vector_complex# * x)
166 {
167 if (cholesky->size1cxx . . $ $anonymous_type_76f4ec40ad1923db_0#size1. != cholesky->size2cxx . . $ $anonymous_type_76f4ec40ad1923db_0#size2.)
168 {
169 GSL_ERRORcxx . . $ `external/gsl/gsl_errno.h:104:9`! ("cholesky matrix must be square", GSL_ENOTSQR);
170 }
171 else if (cholesky->size2cxx . . $ $anonymous_type_76f4ec40ad1923db_0#size2. != x->sizecxx . . $ $anonymous_type_8293e13329784d65_0#size.)
172 {
173 GSL_ERRORcxx . . $ `external/gsl/gsl_errno.h:104:9`! ("matrix size must match solution size", GSL_EBADLEN);
174 }
175 else
176 {
177 /* solve for y using forward-substitution, L y = b */
178
179 gsl_blas_ztrsvcxx . . $ gsl_blas_ztrsv(136538f36152c42). (CblasLowercxx . . $ CblasLower., CblasNoTranscxx . . $ CblasNoTrans., CblasNonUnitcxx . . $ CblasNonUnit., cholesky, x);
180
181 /* perform back-substitution, L^H x = y */
182
183 gsl_blas_ztrsvcxx . . $ gsl_blas_ztrsv(136538f36152c42). (CblasLowercxx . . $ CblasLower., CblasConjTranscxx . . $ CblasConjTrans., CblasNonUnitcxx . . $ CblasNonUnit., cholesky, x);
184
185 return GSL_SUCCESScxx . . $ GSL_SUCCESS.;
186 }
187 } /* gsl_linalg_complex_cholesky_svx() */
188
189 /********************************************
190 * INTERNAL ROUTINES *
191 ********************************************/
192
193 static void
194 cholesky_complex_conj_vectorcxx . . $ cholesky_complex_conj_vector(14d2b39c6913e90).(gsl_vector_complexcxx . . $ gsl_vector_complex# *v)
195 {
196 size_t i;
197
198 for (i = 0; i < v->sizecxx . . $ $anonymous_type_8293e13329784d65_0#size.; ++i)
199 {
200 gsl_complexcxx . . $ gsl_complex# z = gsl_vector_complex_getcxx . . $ gsl_vector_complex_get(5d8bca1ac2095b4a).(v, i);
201 gsl_vector_complex_setcxx . . $ gsl_vector_complex_set(40980682899f0413).(v, i, gsl_complex_conjugatecxx . . $ gsl_complex_conjugate(8eb82f5a0e7f60d8).(z));
202 }
203 } /* cholesky_complex_conj_vector() */