From faef2451e5aaeb4841a7b8a42a0e8386e591d257 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Wed, 15 Dec 2021 19:22:46 -0800 Subject: [PATCH] matrix: Avoid gsl_linalg_LU_invx() because it was new in GSL 2.6. Debian only added GSL 2.6 in the current stable (bullseye) but one of the CI systems is using oldstable (buster), thus failures. Thanks to Friedrich Beckmann for reporting the problem. --- src/language/stats/matrix.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/language/stats/matrix.c b/src/language/stats/matrix.c index 64d8dd92f8..8a08740183 100644 --- a/src/language/stats/matrix.c +++ b/src/language/stats/matrix.c @@ -1851,21 +1851,24 @@ matrix_eval_IDENT (double s1, double s2) return m; } +/* Inverts X, storing the inverse into INVERSE. As a side effect, replaces X + by its LU decomposition. */ static void -invert_matrix (gsl_matrix *x) +invert_matrix (gsl_matrix *x, gsl_matrix *inverse) { gsl_permutation *p = gsl_permutation_alloc (x->size1); int signum; gsl_linalg_LU_decomp (x, p, &signum); - gsl_linalg_LU_invx (x, p); + gsl_linalg_LU_invert (x, p, inverse); gsl_permutation_free (p); } static gsl_matrix * -matrix_eval_INV (gsl_matrix *m) +matrix_eval_INV (gsl_matrix *src) { - invert_matrix (m); - return m; + gsl_matrix *dst = gsl_matrix_alloc (src->size1, src->size2); + invert_matrix (src, dst); + return dst; } static gsl_matrix * @@ -3405,7 +3408,10 @@ matrix_expr_evaluate_exp_mat (const struct matrix_expr *e, mul_matrix (&y, x, y, &t); if (bf < 0) - invert_matrix (y); + { + invert_matrix (y, x); + swap_matrix (&x, &y); + } /* Garbage collection. -- 2.30.2