Skip to content

Commit

Permalink
Use linear storage for dense matrices, for speed
Browse files Browse the repository at this point in the history
  • Loading branch information
infradig committed Jul 2, 2024
1 parent 48923f0 commit a8176ab
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 18 deletions.
18 changes: 0 additions & 18 deletions library/gsl.pl
Original file line number Diff line number Diff line change
Expand Up @@ -116,24 +116,6 @@
gsl_linalg_LU_det([ptr,sint], double)
]).

mat_lup_det(M,Size,Det) :-
gsl_permutation_alloc(Size,P),
gsl_linalg_LU_decomp(M,P,Signum,_),
gsl_vector_alloc(Size,B),
(
between(1,Size,I),
I2 is I - 1,
V is float(I),
gsl_vector_set(B,I2,V),
fail; true
),
gsl_vector_alloc(Size,X),
gsl_linalg_LU_solve(M,P,B,X,_),
gsl_permutation_free(P),
gsl_vector_free(B),
gsl_vector_free(X),
gsl_linalg_LU_det(M,Signum,Det).

vec_write(V,S) :- '$gsl_vector_write'(V,S).

vec_read(V,S,Size1) :-
Expand Down
27 changes: 27 additions & 0 deletions samples/test_matrix_det.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
:- use_module(library(gsl)).

mat_lup_det(M,Size,Det) :-
gsl_permutation_alloc(Size,P),
gsl_linalg_LU_decomp(M,P,Signum,_),
gsl_vector_alloc(Size,B),
(
between(1,Size,I),
I2 is I - 1,
V is float(I),
gsl_vector_set(B,I2,V),
fail; true
),
gsl_vector_alloc(Size,X),
gsl_linalg_LU_solve(M,P,B,X,_),
gsl_permutation_free(P),
gsl_vector_free(B),
gsl_vector_free(X),
gsl_linalg_LU_det(M,Signum,Det).

main :-
open('samples/test_matrix_det.mat',read,S),
mat_read(M,S,Rows,Cols),
mat_lup_det(M,Rows,Det),
gsl_matrix_free(M),
close(S),
write(Det), nl.

0 comments on commit a8176ab

Please sign in to comment.