Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download

GAP 4.8.9 installation with standard packages -- copy to your CoCalc project to get it

563641 views
1
#include "typedef.h"
2
#include "gmp.h"
3
/* #include "gmp-impl.h" */
4
/**************************************************************************\
5
@---------------------------------------------------------------------------
6
@---------------------------------------------------------------------------
7
@ FILE: MP_conv_mat.c
8
@---------------------------------------------------------------------------
9
@---------------------------------------------------------------------------
10
@
11
\**************************************************************************/
12
13
14
15
/**************************************************************************\
16
@---------------------------------------------------------------------------
17
@ MP_INT **matrix_to_MP_mat(M)
18
@ matrix_TYP *M;
19
@
20
@ allocated an 2-dimensional array of MP_INT of the size
21
@ Mat->rows x Mat->cols,
22
@ converts the entries of Mat->array.SZ to MP_INt and writes
23
@ them into the array.
24
@---------------------------------------------------------------------------
25
@
26
\**************************************************************************/
27
MP_INT **matrix_to_MP_mat(M)
28
matrix_TYP *M;
29
{
30
int i,j,m,n;
31
MP_INT **erg;
32
33
m = M->cols;
34
n = M->rows;
35
36
if((erg = (MP_INT **) malloc(n *sizeof(MP_INT *))) == NULL)
37
{
38
printf("malloc of 'erg' in mat_to_MP_mat failed\n");
39
exit(2);
40
}
41
for(i=0;i<n;i++)
42
{
43
if((erg[i] = (MP_INT *) malloc(m *sizeof(MP_INT))) == NULL)
44
{
45
printf("malloc of 'erg[%d]' in mat_to_MP_mat failed\n", i);
46
exit(2);
47
}
48
}
49
for(i=0;i<n;i++)
50
for(j=0;j<m;j++)
51
mpz_init_set_si(&erg[i][j], M->array.SZ[i][j]);
52
return(erg);
53
}
54
55
56
/**************************************************************************\
57
@---------------------------------------------------------------------------
58
@ matrix_TYP *MP_mat_to_matrix(M, rows, cols)
59
@ MP_INT **M;
60
@ int rows, cols;
61
@
62
@ converts the 2-dimensional array M of MP_INT to a matrix_TYP.
63
@ if the entries in M are to big, the function exits with an error message.
64
@---------------------------------------------------------------------------
65
@
66
\**************************************************************************/
67
matrix_TYP *MP_mat_to_matrix(M, rows, cols)
68
MP_INT **M;
69
int rows, cols;
70
{
71
int i,j;
72
matrix_TYP *erg;
73
74
extern matrix_TYP *init_mat();
75
76
erg = init_mat(rows, cols, "");
77
78
for(i=0;i<rows;i++){
79
for(j=0;j<cols;j++)
80
{
81
if(abs(M[i][j]._mp_size) > 1)
82
{
83
printf("Error: Integer overflow in 'MP_mat_to_matrix'\n");
84
exit(2);
85
}
86
erg->array.SZ[i][j] = mpz_get_si(&M[i][j]);
87
}
88
}
89
90
return(erg);
91
}
92
93
94
95
/**************************************************************************\
96
@---------------------------------------------------------------------------
97
@ void write_MP_mat_to_matrix(Mat, mp)
98
@ matrix_TYP *Mat;
99
@ MP_INT **mp;
100
@
101
@ converts the entries of 'mp' and write them to mat->array.SZ
102
@ If the entries are to big, the programm exits
103
@---------------------------------------------------------------------------
104
@
105
\**************************************************************************/
106
void write_MP_mat_to_matrix(Mat, mp)
107
matrix_TYP *Mat;
108
MP_INT **mp;
109
{
110
int i,j;
111
matrix_TYP *erg;
112
113
extern matrix_TYP *init_mat();
114
115
for(i=0;i<Mat->rows;i++)
116
for(j=0;j<Mat->cols;j++)
117
{
118
if(abs(mp[i][j]._mp_size) > 1)
119
{
120
printf("Error: Integer overflow in 'write_MP_mat_to_matrix'\n");
121
exit(3);
122
}
123
Mat->array.SZ[i][j] = mpz_get_si(&mp[i][j]);
124
}
125
}
126
127
128
/**************************************************************************\
129
@---------------------------------------------------------------------------
130
@ MP_INT **init_MP_mat(rows, cols)
131
@ int rows, cols;
132
@
133
@ intitializes a 2-dimensional array of MP_INT of size rows x cols
134
@ and sets all entries 0.
135
@---------------------------------------------------------------------------
136
@
137
\**************************************************************************/
138
MP_INT **init_MP_mat(rows, cols)
139
int rows, cols;
140
{
141
MP_INT **E;
142
int i,j;
143
144
if( (E = (MP_INT **)malloc(rows *sizeof(MP_INT *))) == NULL)
145
{
146
printf("malloc of 'E' in 'init_MP_mat' failed\n");
147
exit(2);
148
}
149
for(i=0;i<rows;i++)
150
{
151
if( (E[i] = (MP_INT *)malloc(cols *sizeof(MP_INT))) == NULL)
152
{
153
printf("malloc of 'E[%d]' in 'init_MP_mat' failed\n", i);
154
exit(2);
155
}
156
for(j=0;j<cols;j++)
157
mpz_init(&E[i][j]);
158
}
159
return(E);
160
}
161
162
163
164
/**************************************************************************\
165
@---------------------------------------------------------------------------
166
@ void free_MP_mat(M, rows, cols)
167
@ MP_INT **M;
168
@ int rows, cols;
169
@
170
@ Clears the entries in the 2-dimensional array 'M' and frees
171
@ M[i] for 0 <= i < rows
172
@---------------------------------------------------------------------------
173
@
174
\**************************************************************************/
175
void free_MP_mat(M, rows, cols)
176
MP_INT **M;
177
int rows, cols;
178
{
179
int i,j;
180
for(i=0;i<rows;i++)
181
{
182
for(j=0;j<cols;j++)
183
mpz_clear(&M[i][j]);
184
free(M[i]);
185
}
186
}
187
188