GAP 4.8.9 installation with standard packages -- copy to your CoCalc project to get it
#include "typedef.h"1#include "gmp.h"2/* #include "gmp-impl.h" */3/**************************************************************************\4@---------------------------------------------------------------------------5@---------------------------------------------------------------------------6@ FILE: MP_conv_mat.c7@---------------------------------------------------------------------------8@---------------------------------------------------------------------------9@10\**************************************************************************/11121314/**************************************************************************\15@---------------------------------------------------------------------------16@ MP_INT **matrix_to_MP_mat(M)17@ matrix_TYP *M;18@19@ allocated an 2-dimensional array of MP_INT of the size20@ Mat->rows x Mat->cols,21@ converts the entries of Mat->array.SZ to MP_INt and writes22@ them into the array.23@---------------------------------------------------------------------------24@25\**************************************************************************/26MP_INT **matrix_to_MP_mat(M)27matrix_TYP *M;28{29int i,j,m,n;30MP_INT **erg;3132m = M->cols;33n = M->rows;3435if((erg = (MP_INT **) malloc(n *sizeof(MP_INT *))) == NULL)36{37printf("malloc of 'erg' in mat_to_MP_mat failed\n");38exit(2);39}40for(i=0;i<n;i++)41{42if((erg[i] = (MP_INT *) malloc(m *sizeof(MP_INT))) == NULL)43{44printf("malloc of 'erg[%d]' in mat_to_MP_mat failed\n", i);45exit(2);46}47}48for(i=0;i<n;i++)49for(j=0;j<m;j++)50mpz_init_set_si(&erg[i][j], M->array.SZ[i][j]);51return(erg);52}535455/**************************************************************************\56@---------------------------------------------------------------------------57@ matrix_TYP *MP_mat_to_matrix(M, rows, cols)58@ MP_INT **M;59@ int rows, cols;60@61@ converts the 2-dimensional array M of MP_INT to a matrix_TYP.62@ if the entries in M are to big, the function exits with an error message.63@---------------------------------------------------------------------------64@65\**************************************************************************/66matrix_TYP *MP_mat_to_matrix(M, rows, cols)67MP_INT **M;68int rows, cols;69{70int i,j;71matrix_TYP *erg;7273extern matrix_TYP *init_mat();7475erg = init_mat(rows, cols, "");7677for(i=0;i<rows;i++){78for(j=0;j<cols;j++)79{80if(abs(M[i][j]._mp_size) > 1)81{82printf("Error: Integer overflow in 'MP_mat_to_matrix'\n");83exit(2);84}85erg->array.SZ[i][j] = mpz_get_si(&M[i][j]);86}87}8889return(erg);90}91929394/**************************************************************************\95@---------------------------------------------------------------------------96@ void write_MP_mat_to_matrix(Mat, mp)97@ matrix_TYP *Mat;98@ MP_INT **mp;99@100@ converts the entries of 'mp' and write them to mat->array.SZ101@ If the entries are to big, the programm exits102@---------------------------------------------------------------------------103@104\**************************************************************************/105void write_MP_mat_to_matrix(Mat, mp)106matrix_TYP *Mat;107MP_INT **mp;108{109int i,j;110matrix_TYP *erg;111112extern matrix_TYP *init_mat();113114for(i=0;i<Mat->rows;i++)115for(j=0;j<Mat->cols;j++)116{117if(abs(mp[i][j]._mp_size) > 1)118{119printf("Error: Integer overflow in 'write_MP_mat_to_matrix'\n");120exit(3);121}122Mat->array.SZ[i][j] = mpz_get_si(&mp[i][j]);123}124}125126127/**************************************************************************\128@---------------------------------------------------------------------------129@ MP_INT **init_MP_mat(rows, cols)130@ int rows, cols;131@132@ intitializes a 2-dimensional array of MP_INT of size rows x cols133@ and sets all entries 0.134@---------------------------------------------------------------------------135@136\**************************************************************************/137MP_INT **init_MP_mat(rows, cols)138int rows, cols;139{140MP_INT **E;141int i,j;142143if( (E = (MP_INT **)malloc(rows *sizeof(MP_INT *))) == NULL)144{145printf("malloc of 'E' in 'init_MP_mat' failed\n");146exit(2);147}148for(i=0;i<rows;i++)149{150if( (E[i] = (MP_INT *)malloc(cols *sizeof(MP_INT))) == NULL)151{152printf("malloc of 'E[%d]' in 'init_MP_mat' failed\n", i);153exit(2);154}155for(j=0;j<cols;j++)156mpz_init(&E[i][j]);157}158return(E);159}160161162163/**************************************************************************\164@---------------------------------------------------------------------------165@ void free_MP_mat(M, rows, cols)166@ MP_INT **M;167@ int rows, cols;168@169@ Clears the entries in the 2-dimensional array 'M' and frees170@ M[i] for 0 <= i < rows171@---------------------------------------------------------------------------172@173\**************************************************************************/174void free_MP_mat(M, rows, cols)175MP_INT **M;176int rows, cols;177{178int i,j;179for(i=0;i<rows;i++)180{181for(j=0;j<cols;j++)182mpz_clear(&M[i][j]);183free(M[i]);184}185}186187188