Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/pke/lib/scheme/ckksrns/ckksrns-advancedshe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -361,12 +361,12 @@ std::shared_ptr<seriesPowers<DCRTPoly>> AdvancedSHECKKSRNS::EvalPowers(
}

template <typename VectorDataType>
Ciphertext<DCRTPoly> internalEvalPolyLinearWithPrecomp(std::vector<Ciphertext<DCRTPoly>>& powers,
const std::vector<VectorDataType>& coefficients) {
const uint32_t k = coefficients.size() - 1;
if (k <= 1)
static inline Ciphertext<DCRTPoly> internalEvalPolyLinearWithPrecomp(std::vector<Ciphertext<DCRTPoly>>& powers,
const std::vector<VectorDataType>& coefficients) {
if (coefficients.size() < 2)
OPENFHE_THROW("The coefficients vector should contain at least 2 elements");

uint32_t k = coefficients.size() - 1;
if (!IsNotEqualZero(coefficients[k]))
OPENFHE_THROW("EvalPolyLinear: The highest-order coefficient cannot be set to 0.");

Expand Down
16 changes: 16 additions & 0 deletions src/pke/unittest/utckksrns/UnitTestCKKSrns.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1801,6 +1801,9 @@ class UTCKKSRNS : public ::testing::TestWithParam<TEST_CASE_UTCKKSRNS> {
// x + x^2 - x^3
// low-degree function to check linear implementation
std::vector<double> coefficients5{0, 1, 1, -1};
// 1 + 2x
// linear function to check linear implementation
std::vector<double> coefficients6{1.0, 2.0};

Plaintext plaintext1 = cc->MakeCKKSPackedPlaintext(input);

Expand All @@ -1819,6 +1822,9 @@ class UTCKKSRNS : public ::testing::TestWithParam<TEST_CASE_UTCKKSRNS> {
std::vector<std::complex<double>> output5{0.625, 0.847, 0.9809999999, 0.995125, 0.990543};
Plaintext plaintextResult5 = cc->MakeCKKSPackedPlaintext(output5);

std::vector<std::complex<double>> output6{2.0, 2.4, 2.8, 2.9, 2.86};
Plaintext plaintextResult6 = cc->MakeCKKSPackedPlaintext(output6);

// Generate encryption keys
KeyPair<Element> kp = cc->KeyGen();
// Generate multiplication keys
Expand Down Expand Up @@ -1878,6 +1884,16 @@ class UTCKKSRNS : public ::testing::TestWithParam<TEST_CASE_UTCKKSRNS> {
<< " - we get: " << results5->GetCKKSPackedValue();
checkEquality(plaintextResult5->GetCKKSPackedValue(), results5->GetCKKSPackedValue(), epsHigh,
failmsg + " EvalPoly for low-degree polynomial failed: " + buffer5.str());

Ciphertext<Element> cResult6 = cc->EvalPolyLinear(ciphertext1, coefficients6);
Plaintext results6;
cc->Decrypt(kp.secretKey, cResult6, &results6);
results6->SetLength(encodedLength);
std::stringstream buffer6;
buffer6 << "should be: " << plaintextResult6->GetCKKSPackedValue()
<< " - we get: " << results6->GetCKKSPackedValue();
checkEquality(plaintextResult6->GetCKKSPackedValue(), results6->GetCKKSPackedValue(), epsHigh,
failmsg + " EvalPoly for linear polynomial failed: " + buffer6.str());
}
catch (std::exception& e) {
std::cerr << "Exception thrown from " << __func__ << "(): " << e.what() << std::endl;
Expand Down