Hello,
I’m struggling to understand OpenFHE Packed Encoding.
When I coefficient encode 2 vectors and use the Evaluation format to multiply them, everything worked as expected (code below), but when I pack the vector into a PackedEncoding, and then multiply them in Evaluation format, the result is wrong.
Below I reproduce two snips of the code I’m using (with and without packing).
It is strange because I would expect that both the packing and the format switch would use NTT transformations, but it seems that they are different!!
What am I missing?
It seems pretty simple, but I’ve not been able to understand it. Can you help me?
Regards
--------------------------------------------
[CODE WITH PACKING]
usint m = 22;
PlaintextModulus p = 89;
BigInteger modulusQ("955263939794561");
BigInteger squareRootOfRoot("941018665059848");
BigInteger bigmodulus("80899135611688102162227204937217");
BigInteger bigroot("77936753846653065954043047918387");
auto lp = std::make_shared<ILParams>(m, modulusQ, squareRootOfRoot, bigmodulus, bigroot);
EncodingParams ep(std::make_shared<EncodingParamsImpl>(p, 8));
PackedEncoding::SetParams(m, ep);
std::vector<int64_t> v1 = {1, 2, 3, 4, 0, 0, 0, 0, 0, 0};
PackedEncoding a(lp, ep, v1);
a.Encode();
Poly &p = a.GetElement<Poly>();
p.SetFormat(Format::EVALUATION);
p = p.Times(p);
p.SetFormat(Format::COEFFICIENT);
a.Decode();
std::cout << a << std::endl;
-------------------------------------------------
[Output]
[ 29 40 43 0 21 22 5 32 35 10 ]
-------------------------------------------------
[CODE WITHOUT PACKING]
usint m = 8;
typename VecType::Integer primeModulus("73");
typename VecType::Integer primitiveRootOfUnity("22");
...
Poly A(ilparams, Format::COEFFICIENT);
A = {"2", "1", "1", "1"};
Poly A(ilparams, Format::COEFFICIENT);
A = {"1", "0", "1", "1"};
A.SwitchFormat();
B.SwitchFormat();
std::cout << "A: " << A << std::endl;
std::cout << "B: " << B << std::endl;
Poly C = A.Times(B);
std::cout << "C: " << C << std::endl;
C.SwitchFormat();
std::cout << "C: " << C << std::endl;
---------------------------------------------------
[Output Of Code Without Packaging]
A: EVAL: [60 36 41 17] modulus: 73
B: EVAL: [37 57 50 6] modulus: 73
C: EVAL: [30 8 6 29] modulus: 73
C: COEF: [0 72 2 4] modulus 73