@@ -20,24 +20,58 @@ typedef long *GEN;
20
20
%extend pari_GEN{
21
21
pari_GEN (PyObject *int_list){
22
22
pari_GEN* result = new pari_GEN ();
23
- int *array = NULL ;
24
- int nInts;
25
- if (PyList_Check ( int_list ))
26
- {
27
- nInts = PyList_Size ( int_list );
28
- array = (int *) malloc ( nInts * sizeof (int ) );
29
- for ( int ii = 0 ; ii < nInts; ii++ ){
30
- PyObject *oo = PyList_GetItem ( int_list, ii);
31
- if ( PyInt_Check ( oo ) )
32
- array[ ii ] = ( int ) PyInt_AsLong ( oo );
23
+ if (PyList_Size (PyList_GetItem ( int_list, 0 )) == -1 ){
24
+ int *array = NULL ;
25
+ int nInts;
26
+ if (PyList_Check ( int_list ))
27
+ {
28
+ nInts = PyList_Size ( int_list );
29
+ array = (int *) malloc ( nInts * sizeof (int ) );
30
+ for ( int ii = 0 ; ii < nInts; ii++ ){
31
+ PyObject *oo = PyList_GetItem ( int_list, ii);
32
+ if ( PyInt_Check ( oo ) )
33
+ array[ ii ] = ( int ) PyInt_AsLong ( oo );
34
+ }
33
35
}
36
+ GEN x;
37
+ x = cgetg (nInts + 1 , t_VEC);
38
+ for (int i = 0 ; i < nInts; i++)
39
+ gel (x, i + 1 ) = stoi (array[i]);
40
+ result->initialize (x);
41
+ return result;
34
42
}
35
- GEN x;
36
- x = cgetg (nInts + 1 , t_VEC);
37
- for (int i = 0 ; i < nInts; i++)
38
- gel (x, i + 1 ) = stoi (array[i]);
39
- result->initialize (x);
40
- return result;
43
+ else {
44
+ int *array = NULL ;
45
+ int **arrofarray = NULL ;
46
+ int nInts;
47
+ int nOutInts;
48
+ if (PyList_Check ( int_list ))
49
+ {
50
+ nOutInts = PyList_Size ( int_list );
51
+ arrofarray = (int **) malloc ( nOutInts * sizeof (int *) );
52
+ for ( int jj = 0 ; jj < nOutInts; jj++ ){
53
+ nInts = PyList_Size (PyList_GetItem ( int_list, jj) );
54
+ array = (int *) malloc ( nInts * sizeof (int ) );
55
+ for ( int ii = 0 ; ii < nInts; ii++ ){
56
+ PyObject *oo = PyList_GetItem (PyList_GetItem ( int_list, jj), ii);
57
+ if ( PyInt_Check ( oo ) ){
58
+ array[ ii ] = ( int ) PyInt_AsLong ( oo );
59
+ }
60
+
61
+ }
62
+ arrofarray[jj] = array;
63
+ }
64
+ }
65
+ GEN x;
66
+ x = zeromatcopy (nOutInts, nInts);
67
+ for (int j = 0 ; j < nOutInts; j++){
68
+ for (int i = 0 ; i < nInts; i++)
69
+ gel (gel (x, i + 1 ), j + 1 ) = stoi (arrofarray[j][i]);
70
+ }
71
+ result->initialize (x);
72
+ return result;
73
+ }
74
+
41
75
}
42
76
43
77
char * __str__ (){
@@ -53,8 +87,20 @@ typedef long *GEN;
53
87
pari_GEN sub_mat_array (int key_1, int key_2){
54
88
pari_GEN result;
55
89
result.value = cgetg (key_2 - key_1 + 1 , t_VEC);
90
+ int cnt = 0 ;
56
91
for (int i = key_1; i < key_2; i++)
57
- gel (result.value , i + 1 ) = gel (gel (self->value , i + 1 ), 1 );
92
+ gel (result.value , 1 +cnt++) = gel (gel (self->value , i + 1 ), 1 );
93
+ return result;
94
+ }
95
+
96
+ pari_GEN sub_mat_array (int row_1, int row_2, int col_1, int col_2){
97
+ pari_GEN result;
98
+ result.value = zeromatcopy (row_2 - row_1, col_2 - col_1);
99
+ for (int j = col_1; j < col_2; j++){
100
+ for (int i = row_1; i < row_2; i++){
101
+ gel (gel (result.value , 1 +(j-col_1)), 1 +(i-row_1)) = gel (gel (self->value , j + 1 ), i + 1 );
102
+ }
103
+ }
58
104
return result;
59
105
}
60
106
@@ -68,7 +114,7 @@ typedef long *GEN;
68
114
};
69
115
70
116
%extend ciphertext{
71
- ciphertext (PyObject *int_list, public_key* pk, parameters* params ){
117
+ ciphertext (PyObject *int_list, public_key* pk){
72
118
ciphertext* result = new ciphertext ();
73
119
int *array = NULL ;
74
120
int nInts;
@@ -86,21 +132,26 @@ typedef long *GEN;
86
132
pt.value = cgetg (nInts + 1 , t_VEC);
87
133
for (int i = 0 ; i < nInts; i++)
88
134
gel (pt.value , i + 1 ) = stoi (array[i]);
89
- result->packing_method (pt, pk, params );
135
+ result->packing_method (pt, pk);
90
136
return result;
91
137
}
138
+
92
139
93
140
ciphertext __mul__ (const int pt){
94
141
ciphertext result;
95
142
pari_GEN pt_GEN (pt);
96
143
result.value = plaintext_multiplication (self->value , pt_GEN);
144
+ result.params = self->params ;
145
+ result.pk = self->pk ;
97
146
return result;
98
147
}
99
148
100
149
ciphertext __rmul__ (const int pt){
101
150
ciphertext result;
102
151
pari_GEN pt_GEN (pt);
103
152
result.value = plaintext_multiplication (self->value , pt_GEN);
153
+ result.params = self->params ;
154
+ result.pk = self->pk ;
104
155
return result;
105
156
}
106
157
};
0 commit comments