Debian Codegraph @

easel/interface_gsl.c

raw symbols SCIP
1 /* Easel's interfaces to the GNU Scientific Library
2 */
3 #include <esl_config.h>
4 #ifdef HAVE_LIBGSL
5
6 #include <stdlib.h>
7 #include "easel/easel.h"
8 #include "easel/dmatrix.h"
9 #include <gsl/gsl_math.h>
10 #include <gsl/gsl_blas.h>
11 #include <gsl/gsl_permutation.h>
12 #include <gsl/gsl_eigen.h>
13
14 int
15 esl_GSL_MatrixInversion(ESL_DMATRIX *A, ESL_DMATRIX **ret_Ai)
16 {
17 ESL_DMATRIX *Ai; /* RETURN: A^{-1} */
18 gsl_matrix_view Av; /* gsl view of matrix A */
19 gsl_matrix *LU; /* LU decomposition of A */
20 gsl_matrix *Aiv; /* gsl version of A^{-1} */
21 gsl_permutation *permute;
22 int signum;
23 int i,j;
24
25 Ai = esl_dmx_Alloc(A->n, A->m);
26
27 /* Invert U to get Ui, using LU decomposition.
28 */
29 Av = gsl_matrix_view_array(A->mx[0], A->n, A->n);
30 LU = gsl_matrix_alloc(A->n, A->n);
31 Aiv = gsl_matrix_alloc(A->n, A->n); /* U^{-1}: inverse of U */
32 permute = gsl_permutation_alloc(A->n);
33 gsl_matrix_memcpy(LU, &Av.matrix);
34
35 if (gsl_linalg_LU_decomp(LU, permute, &signum) != 0) ESL_EXCEPTION(eslEUNKNOWN, "gsl failed");
36 if (gsl_linalg_LU_invert(LU, permute, Aiv) != 0) ESL_EXCEPTION(eslEUNKNOWN, "gsl failed");
37
38 gsl_matrix_free(LU);
39 gsl_permutation_free(permute);
40
41 /* recover the matrix from gsl.
42 */
43 for (i = 0; i < A->n; i++)
44 for (j = 0; j < A->n; j++)
45 Ai->mx[i][j] = gsl_matrix_get(Aiv, i, j);
46 gsl_matrix_free(Aiv);
47
48 ret->Ai = Ai;
49 return eslOK;
50 }
51
52 #endif /*HAVE_LIBGSL*/
53
54
55