trealla
trealla copied to clipboard
GSL: Bugs
This bundle is mathematically error free:
matrix_calloc
permutation_alloc
LU_decomp
LU_det
Exercisers:
$ cat x.c
#include <stdio.h>
#include <gsl/gsl_version.h>
#include <gsl/gsl_linalg.h>
int main (int argc, char *argv[]) {
int sig, stat;
double det;
int rows = atoi(argv[1]);
int cols = atoi(argv[2]);
printf("v%s %dx%d\n",GSL_VERSION,rows,cols);
gsl_matrix *mat = gsl_matrix_calloc(rows, cols);
gsl_permutation *perm = gsl_permutation_alloc(rows);
stat = gsl_linalg_LU_decomp(mat, perm, &sig);
det = gsl_linalg_LU_det(mat, sig);
printf("%lf\n",det);
gsl_permutation_free(perm);
gsl_matrix_free(mat);
return 0;
}
$ cat x.pl
:- use_module(library(gsl)).
tst(Rows,Cols) :-
gsl_matrix_calloc(Rows, Cols, M),
gsl_permutation_alloc(Rows, P),
gsl_linalg_LU_decomp(M, P, Sig, Stat),
gsl_linalg_LU_det(M, Sig, Det),
write(Det),nl,
gsl_permutation_free(P),
gsl_matrix_free(M).
RESULTS:
GSL 2.7.1
$ ./a.out 127 127
v2.7.1 127x127
-nan # Libgsl: known bug in v2.7
$
$ tpl x.pl
?- tst(127,127).
-.0nan % Trealla morphs -nan into -.0nan
true.
?- halt.
$
GSL 2.8
$ ./a.out 127 127
v2.8 127x127
:
# printf in function gsl_linalg_LU_decomp() of gsl-git/linalg/lu.c
# convert ipiv array to permutation
# unsigned int pivi = gsl_vector_uint_get(ipiv, i);
:
FF pivi 13 i 13
FF pivi 14 i 14
FF pivi 15 i 15
FF pivi 0 i 16 # Trealla Crash here
FF pivi 0 i 17
FF pivi 0 i 18
:
FF pivi 0 i 124
FF pivi 0 i 125
FF pivi 0 i 126
-0.000000 # expected, v2.7 bug '-nan' has been fixed
$
$ tpl x.pl
?- tst(127,127). % First Call
:
FF pivi 13 i 13
FF pivi 14 i 14
FF pivi 15 i 15
FF pivi 210299952 i 16 % looks like Trealla puts an address somewhere in an array
Segmentation fault (core dumped)
$