Skip to content
This repository was archived by the owner on Dec 10, 2017. It is now read-only.

Commit 5a61b46

Browse files
authored
Version 1 Rollout
1 parent 7efb2f1 commit 5a61b46

7 files changed

+418
-215
lines changed

Aono.i

Lines changed: 70 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,58 @@ typedef long *GEN;
2020
%extend pari_GEN{
2121
pari_GEN(PyObject *int_list){
2222
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+
}
3335
}
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;
3442
}
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+
4175
}
4276

4377
char* __str__(){
@@ -53,8 +87,20 @@ typedef long *GEN;
5387
pari_GEN sub_mat_array(int key_1, int key_2){
5488
pari_GEN result;
5589
result.value = cgetg(key_2 - key_1 + 1, t_VEC);
90+
int cnt = 0;
5691
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+
}
58104
return result;
59105
}
60106

@@ -68,7 +114,7 @@ typedef long *GEN;
68114
};
69115

70116
%extend ciphertext{
71-
ciphertext(PyObject *int_list, public_key* pk, parameters* params){
117+
ciphertext(PyObject *int_list, public_key* pk){
72118
ciphertext* result = new ciphertext();
73119
int *array = NULL;
74120
int nInts;
@@ -86,21 +132,26 @@ typedef long *GEN;
86132
pt.value = cgetg(nInts + 1, t_VEC);
87133
for(int i = 0; i < nInts; i++)
88134
gel(pt.value, i + 1) = stoi(array[i]);
89-
result->packing_method(pt, pk, params);
135+
result->packing_method(pt, pk);
90136
return result;
91137
}
138+
92139

93140
ciphertext __mul__(const int pt){
94141
ciphertext result;
95142
pari_GEN pt_GEN(pt);
96143
result.value = plaintext_multiplication(self->value, pt_GEN);
144+
result.params = self->params;
145+
result.pk = self->pk;
97146
return result;
98147
}
99148

100149
ciphertext __rmul__(const int pt){
101150
ciphertext result;
102151
pari_GEN pt_GEN(pt);
103152
result.value = plaintext_multiplication(self->value, pt_GEN);
153+
result.params = self->params;
154+
result.pk = self->pk;
104155
return result;
105156
}
106157
};

Aono.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,8 @@ class ciphertext(_object):
128128
__swig_destroy__ = _Aono.delete_ciphertext
129129
__del__ = lambda self: None
130130

131-
def packing_method(self, m, pk, params):
132-
return _Aono.ciphertext_packing_method(self, m, pk, params)
131+
def packing_method(self, m, pk):
132+
return _Aono.ciphertext_packing_method(self, m, pk)
133133

134134
def initialize(self, *args):
135135
return _Aono.ciphertext_initialize(self, *args)
@@ -381,8 +381,8 @@ def __str__(self):
381381
def __getitem__(self, key):
382382
return _Aono.pari_GEN___getitem__(self, key)
383383

384-
def sub_mat_array(self, key_1, key_2):
385-
return _Aono.pari_GEN_sub_mat_array(self, key_1, key_2)
384+
def sub_mat_array(self, *args):
385+
return _Aono.pari_GEN_sub_mat_array(self, *args)
386386

387387
def sub_array(self, key_1, key_2):
388388
return _Aono.pari_GEN_sub_array(self, key_1, key_2)

Aono.pyc

-16 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)