Skip to content

Commit 099331e

Browse files
author
Shai Halevi
committed
added EncryptedArray to constructor of GeneralAutomorphPrecon types
1 parent 0cd6d72 commit 099331e

File tree

1 file changed

+26
-22
lines changed

1 file changed

+26
-22
lines changed

src/matmul.cpp

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,9 @@ class GeneralAutomorphPrecon_UNKNOWN : public GeneralAutomorphPrecon {
160160
const PAlgebra& zMStar;
161161

162162
public:
163-
GeneralAutomorphPrecon_UNKNOWN(const Ctxt& _ctxt, long _dim) :
164-
ctxt(_ctxt), dim(_dim), zMStar(_ctxt.getContext().zMStar)
163+
GeneralAutomorphPrecon_UNKNOWN(const Ctxt& _ctxt, long _dim,
164+
const EncryptedArray& ea) :
165+
ctxt(_ctxt), dim(_dim), zMStar(ea.getPAlgebra())
165166
{
166167
ctxt.cleanUp();
167168
}
@@ -184,8 +185,9 @@ class GeneralAutomorphPrecon_FULL : public GeneralAutomorphPrecon {
184185
const PAlgebra& zMStar;
185186

186187
public:
187-
GeneralAutomorphPrecon_FULL(const Ctxt& _ctxt, long _dim) :
188-
precon(_ctxt), dim(_dim), zMStar(_ctxt.getContext().zMStar)
188+
GeneralAutomorphPrecon_FULL(const Ctxt& _ctxt, long _dim,
189+
const EncryptedArray& ea) :
190+
precon(_ctxt), dim(_dim), zMStar(ea.getPAlgebra())
189191
{ }
190192

191193
shared_ptr<Ctxt> automorph(long i) const override
@@ -206,8 +208,9 @@ class GeneralAutomorphPrecon_BSGS : public GeneralAutomorphPrecon {
206208
vector<shared_ptr<BasicAutomorphPrecon>> precon;
207209

208210
public:
209-
GeneralAutomorphPrecon_BSGS(const Ctxt& _ctxt, long _dim) :
210-
dim(_dim), zMStar(_ctxt.getContext().zMStar)
211+
GeneralAutomorphPrecon_BSGS(const Ctxt& _ctxt, long _dim,
212+
const EncryptedArray& ea) :
213+
dim(_dim), zMStar(ea.getPAlgebra())
211214
{
212215
D = (dim == -1) ? zMStar.getOrdP() : zMStar.OrderOf(dim);
213216
g = KSGiantStepSize(D);
@@ -237,26 +240,27 @@ class GeneralAutomorphPrecon_BSGS : public GeneralAutomorphPrecon {
237240
};
238241

239242
shared_ptr<GeneralAutomorphPrecon>
240-
buildGeneralAutomorphPrecon(const Ctxt& ctxt, long dim)
243+
buildGeneralAutomorphPrecon(const Ctxt& ctxt, long dim,
244+
const EncryptedArray& ea)
241245
{
242246
// allow dim == -1 (Frobenius)
243247
// allow dim == #gens (the dummy generator of order 1)
244-
assert(dim >= -1 && dim <= long(ctxt.getContext().zMStar.numOfGens()));
248+
assert(dim >= -1 && dim <= ea.dimension());
245249

246250
if (fhe_test_force_hoist >= 0) {
247251
switch (ctxt.getPubKey().getKSStrategy(dim)) {
248252
case FHE_KSS_BSGS:
249-
return make_shared<GeneralAutomorphPrecon_BSGS>(ctxt, dim);
253+
return make_shared<GeneralAutomorphPrecon_BSGS>(ctxt, dim, ea);
250254

251255
case FHE_KSS_FULL:
252-
return make_shared<GeneralAutomorphPrecon_FULL>(ctxt, dim);
256+
return make_shared<GeneralAutomorphPrecon_FULL>(ctxt, dim, ea);
253257

254258
default:
255-
return make_shared<GeneralAutomorphPrecon_UNKNOWN>(ctxt, dim);
259+
return make_shared<GeneralAutomorphPrecon_UNKNOWN>(ctxt, dim, ea);
256260
}
257261
}
258262
else {
259-
return make_shared<GeneralAutomorphPrecon_UNKNOWN>(ctxt, dim);
263+
return make_shared<GeneralAutomorphPrecon_UNKNOWN>(ctxt, dim, ea);
260264
}
261265
}
262266

@@ -1025,7 +1029,7 @@ MatMul1DExec::mul(Ctxt& ctxt) const
10251029
else if (!iterative) {
10261030
if (native) {
10271031
shared_ptr<GeneralAutomorphPrecon> precon =
1028-
buildGeneralAutomorphPrecon(ctxt, dim);
1032+
buildGeneralAutomorphPrecon(ctxt, dim, ea);
10291033

10301034
PartitionInfo pinfo(D);
10311035
long cnt = pinfo.NumIntervals();
@@ -1051,7 +1055,7 @@ MatMul1DExec::mul(Ctxt& ctxt) const
10511055
}
10521056
else {
10531057
shared_ptr<GeneralAutomorphPrecon> precon =
1054-
buildGeneralAutomorphPrecon(ctxt, dim);
1058+
buildGeneralAutomorphPrecon(ctxt, dim, ea);
10551059

10561060
PartitionInfo pinfo(D);
10571061
long cnt = pinfo.NumIntervals();
@@ -1573,7 +1577,7 @@ BlockMatMul1DExec::mul(Ctxt& ctxt) const
15731577
else {
15741578

15751579
shared_ptr<GeneralAutomorphPrecon> precon =
1576-
buildGeneralAutomorphPrecon(ctxt, dim0);
1580+
buildGeneralAutomorphPrecon(ctxt, dim0, ea);
15771581

15781582
#if 0
15791583
// This is the original code
@@ -1683,7 +1687,7 @@ BlockMatMul1DExec::mul(Ctxt& ctxt) const
16831687
else {
16841688

16851689
shared_ptr<GeneralAutomorphPrecon> precon =
1686-
buildGeneralAutomorphPrecon(ctxt, dim0);
1690+
buildGeneralAutomorphPrecon(ctxt, dim0, ea);
16871691

16881692
#if 0
16891693
// original code
@@ -1993,7 +1997,7 @@ MatMulFullExec::rec_mul(Ctxt& acc, const Ctxt& ctxt, long dim_idx, long idx) con
19931997

19941998
if (native) {
19951999
shared_ptr<GeneralAutomorphPrecon> precon =
1996-
buildGeneralAutomorphPrecon(ctxt, dim);
2000+
buildGeneralAutomorphPrecon(ctxt, dim, ea);
19972001

19982002
for (long i: range(sdim)) {
19992003
shared_ptr<Ctxt> tmp = precon->automorph(i);
@@ -2004,9 +2008,9 @@ MatMulFullExec::rec_mul(Ctxt& acc, const Ctxt& ctxt, long dim_idx, long idx) con
20042008
Ctxt ctxt1 = ctxt;
20052009
ctxt1.smartAutomorph(zMStar.genToPow(dim, -sdim));
20062010
shared_ptr<GeneralAutomorphPrecon> precon =
2007-
buildGeneralAutomorphPrecon(ctxt, dim);
2011+
buildGeneralAutomorphPrecon(ctxt, dim, ea);
20082012
shared_ptr<GeneralAutomorphPrecon> precon1 =
2009-
buildGeneralAutomorphPrecon(ctxt1, dim);
2013+
buildGeneralAutomorphPrecon(ctxt1, dim, ea);
20102014

20112015
for (long i: range(sdim)) {
20122016
if (i == 0)
@@ -2336,7 +2340,7 @@ BlockMatMulFullExec::rec_mul(Ctxt& acc, const Ctxt& ctxt, long dim_idx, long idx
23362340

23372341
if (native) {
23382342
shared_ptr<GeneralAutomorphPrecon> precon =
2339-
buildGeneralAutomorphPrecon(ctxt, dim);
2343+
buildGeneralAutomorphPrecon(ctxt, dim, ea);
23402344

23412345
for (long i: range(sdim)) {
23422346
shared_ptr<Ctxt> tmp = precon->automorph(i);
@@ -2347,9 +2351,9 @@ BlockMatMulFullExec::rec_mul(Ctxt& acc, const Ctxt& ctxt, long dim_idx, long idx
23472351
Ctxt ctxt1 = ctxt;
23482352
ctxt1.smartAutomorph(zMStar.genToPow(dim, -sdim));
23492353
shared_ptr<GeneralAutomorphPrecon> precon =
2350-
buildGeneralAutomorphPrecon(ctxt, dim);
2354+
buildGeneralAutomorphPrecon(ctxt, dim, ea);
23512355
shared_ptr<GeneralAutomorphPrecon> precon1 =
2352-
buildGeneralAutomorphPrecon(ctxt1, dim);
2356+
buildGeneralAutomorphPrecon(ctxt1, dim, ea);
23532357

23542358
for (long i: range(sdim)) {
23552359
if (i == 0)

0 commit comments

Comments
 (0)