X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Flanguage%2Fstats%2Fmatrix.c;h=8a08740183a54f72dba21798abae29d9fa42d6c1;hb=faef2451e5aaeb4841a7b8a42a0e8386e591d257;hp=64d8dd92f83873465a0727415c1604c3843a452c;hpb=8a7698655f6f01e83c99a0eab7597dc5ce7a64ca;p=pspp 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.