Skip to content

Commit a7c2033

Browse files
Small bug fix and formatting
1 parent d460eaf commit a7c2033

File tree

1 file changed

+85
-96
lines changed

1 file changed

+85
-96
lines changed

src/lib/bindings.cpp

Lines changed: 85 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -868,101 +868,91 @@ void bind_crypto_context(py::module &m)
868868
cc_InsertEvalAutomorphismKey_docs,
869869
py::arg("evalKeyMap"),
870870
py::arg("keyTag") = "")
871-
.def_static(
872-
"ClearEvalAutomorphismKeys", []()
873-
{ CryptoContextImpl<DCRTPoly>::ClearEvalAutomorphismKeys(); },
871+
.def_static("ClearEvalAutomorphismKeys", []() {
872+
CryptoContextImpl<DCRTPoly>::ClearEvalAutomorphismKeys();
873+
},
874874
cc_ClearEvalAutomorphismKeys_docs)
875875
// it is safer to return by value instead of by reference (GetEvalMultKeyVector returns a const reference to std::vector)
876-
.def_static("GetEvalMultKeyVector",
877-
[](const std::string& keyTag) {
878-
return CryptoContextImpl<DCRTPoly>::GetEvalMultKeyVector(keyTag);
876+
.def_static("GetEvalMultKeyVector", [](const std::string& keyTag) {
877+
return CryptoContextImpl<DCRTPoly>::GetEvalMultKeyVector(keyTag);
879878
},
880879
cc_GetEvalMultKeyVector_docs,
881880
py::arg("keyTag") = "")
882881
.def_static("GetEvalAutomorphismKeyMap", &CryptoContextImpl<DCRTPoly>::GetEvalAutomorphismKeyMapPtr,
883882
cc_GetEvalAutomorphismKeyMap_docs,
884883
py::arg("keyTag") = "")
885-
.def_static(
886-
"SerializeEvalMultKey", [](const std::string &filename, const SerType::SERBINARY &sertype, std::string keyTag = "")
887-
{
888-
std::ofstream outfile(filename, std::ios::out | std::ios::binary);
889-
bool res = CryptoContextImpl<DCRTPoly>::SerializeEvalMultKey<SerType::SERBINARY>(outfile, sertype, keyTag);
890-
outfile.close();
891-
return res; },
884+
.def_static("SerializeEvalMultKey", [](const std::string &filename, const SerType::SERBINARY &sertype, std::string keyTag = "") {
885+
std::ofstream outfile(filename, std::ios::out | std::ios::binary);
886+
bool res = CryptoContextImpl<DCRTPoly>::SerializeEvalMultKey<SerType::SERBINARY>(outfile, sertype, keyTag);
887+
outfile.close();
888+
return res;
889+
},
892890
cc_SerializeEvalMultKey_docs,
893891
py::arg("filename"), py::arg("sertype"), py::arg("keyTag") = "")
894-
.def_static( // SerializeEvalMultKey - JSON
895-
"SerializeEvalMultKey", [](const std::string &filename, const SerType::SERJSON &sertype, std::string keyTag = "")
896-
{
897-
std::ofstream outfile(filename, std::ios::out | std::ios::binary);
898-
bool res = CryptoContextImpl<DCRTPoly>::SerializeEvalMultKey<SerType::SERJSON>(outfile, sertype, keyTag);
899-
outfile.close();
900-
return res; },
892+
.def_static("SerializeEvalMultKey", [](const std::string &filename, const SerType::SERJSON &sertype, std::string keyTag = "") {
893+
std::ofstream outfile(filename, std::ios::out | std::ios::binary);
894+
bool res = CryptoContextImpl<DCRTPoly>::SerializeEvalMultKey<SerType::SERJSON>(outfile, sertype, keyTag);
895+
outfile.close();
896+
return res;
897+
},
901898
cc_SerializeEvalMultKey_docs,
902899
py::arg("filename"), py::arg("sertype"), py::arg("keyTag") = "")
903-
.def_static( // SerializeEvalAutomorphismKey - Binary
904-
"SerializeEvalAutomorphismKey", [](const std::string &filename, const SerType::SERBINARY &sertype, std::string keyTag = "")
905-
{
906-
std::ofstream outfile(filename, std::ios::out | std::ios::binary);
907-
bool res = CryptoContextImpl<DCRTPoly>::SerializeEvalAutomorphismKey<SerType::SERBINARY>(outfile, sertype, keyTag);
908-
outfile.close();
909-
return res; },
900+
.def_static("SerializeEvalAutomorphismKey", [](const std::string &filename, const SerType::SERBINARY &sertype, std::string keyTag = "") {
901+
std::ofstream outfile(filename, std::ios::out | std::ios::binary);
902+
bool res = CryptoContextImpl<DCRTPoly>::SerializeEvalAutomorphismKey<SerType::SERBINARY>(outfile, sertype, keyTag);
903+
outfile.close();
904+
return res;
905+
},
910906
cc_SerializeEvalAutomorphismKey_docs,
911907
py::arg("filename"), py::arg("sertype"), py::arg("keyTag") = "")
912-
.def_static( // SerializeEvalAutomorphismKey - JSON
913-
"SerializeEvalAutomorphismKey", [](const std::string &filename, const SerType::SERJSON &sertype, std::string keyTag = "")
914-
{
915-
std::ofstream outfile(filename, std::ios::out | std::ios::binary);
916-
bool res = CryptoContextImpl<DCRTPoly>::SerializeEvalAutomorphismKey<SerType::SERJSON>(outfile, sertype, keyTag);
917-
outfile.close();
918-
return res; },
908+
.def_static("SerializeEvalAutomorphismKey", [](const std::string &filename, const SerType::SERJSON &sertype, std::string keyTag = "") {
909+
std::ofstream outfile(filename, std::ios::out | std::ios::binary);
910+
bool res = CryptoContextImpl<DCRTPoly>::SerializeEvalAutomorphismKey<SerType::SERJSON>(outfile, sertype, keyTag);
911+
outfile.close();
912+
return res;
913+
},
919914
cc_SerializeEvalAutomorphismKey_docs,
920915
py::arg("filename"), py::arg("sertype"), py::arg("keyTag") = "")
921-
.def_static("DeserializeEvalMultKey", // DeserializeEvalMultKey - Binary
922-
[](const std::string &filename, const SerType::SERBINARY &sertype)
923-
{
924-
std::ifstream emkeys(filename, std::ios::in | std::ios::binary);
925-
if (!emkeys.is_open()) {
926-
std::cerr << "I cannot read serialization from " << filename << std::endl;
927-
}
928-
bool res = CryptoContextImpl<DCRTPoly>::DeserializeEvalMultKey<SerType::SERBINARY>(emkeys, sertype);
929-
return res;
930-
},
931-
cc_DeserializeEvalMultKey_docs,
932-
py::arg("filename"), py::arg("sertype"))
933-
.def_static("DeserializeEvalMultKey", // DeserializeEvalMultKey - JSON
934-
[](const std::string &filename, const SerType::SERJSON &sertype)
935-
{
936-
std::ifstream emkeys(filename, std::ios::in | std::ios::binary);
937-
if (!emkeys.is_open()) {
938-
std::cerr << "I cannot read serialization from " << filename << std::endl;
939-
}
940-
bool res = CryptoContextImpl<DCRTPoly>::DeserializeEvalMultKey<SerType::SERJSON>(emkeys, sertype);
941-
return res; },
942-
cc_DeserializeEvalMultKey_docs,
943-
py::arg("filename"), py::arg("sertype"))
944-
.def_static("DeserializeEvalAutomorphismKey", // DeserializeEvalAutomorphismKey - Binary
945-
[](const std::string &filename, const SerType::SERBINARY &sertype)
946-
{
947-
std::ifstream erkeys(filename, std::ios::in | std::ios::binary);
948-
if (!erkeys.is_open()) {
949-
std::cerr << "I cannot read serialization from " << filename << std::endl;
950-
}
951-
bool res = CryptoContextImpl<DCRTPoly>::DeserializeEvalAutomorphismKey<SerType::SERBINARY>(erkeys, sertype);
952-
return res; },
953-
cc_DeserializeEvalAutomorphismKey_docs,
954-
py::arg("filename"), py::arg("sertype"))
955-
.def_static("DeserializeEvalAutomorphismKey", // DeserializeEvalAutomorphismKey - JSON
956-
[](const std::string &filename, const SerType::SERJSON &sertype)
957-
{
958-
std::ifstream erkeys(filename, std::ios::in | std::ios::binary);
959-
if (!erkeys.is_open()) {
960-
std::cerr << "I cannot read serialization from " << filename << std::endl;
961-
}
962-
bool res = CryptoContextImpl<DCRTPoly>::DeserializeEvalAutomorphismKey<SerType::SERJSON>(erkeys, sertype);
963-
return res; },
964-
cc_DeserializeEvalAutomorphismKey_docs,
965-
py::arg("filename"), py::arg("sertype"));
916+
.def_static("DeserializeEvalMultKey", [](const std::string &filename, const SerType::SERBINARY &sertype) {
917+
std::ifstream emkeys(filename, std::ios::in | std::ios::binary);
918+
if (!emkeys.is_open()) {
919+
std::cerr << "I cannot read serialization from " << filename << std::endl;
920+
}
921+
bool res = CryptoContextImpl<DCRTPoly>::DeserializeEvalMultKey<SerType::SERBINARY>(emkeys, sertype);
922+
return res;
923+
},
924+
cc_DeserializeEvalMultKey_docs,
925+
py::arg("filename"), py::arg("sertype"))
926+
.def_static("DeserializeEvalMultKey", [](const std::string &filename, const SerType::SERJSON &sertype) {
927+
std::ifstream emkeys(filename, std::ios::in | std::ios::binary);
928+
if (!emkeys.is_open()) {
929+
std::cerr << "I cannot read serialization from " << filename << std::endl;
930+
}
931+
bool res = CryptoContextImpl<DCRTPoly>::DeserializeEvalMultKey<SerType::SERJSON>(emkeys, sertype);
932+
return res;
933+
},
934+
cc_DeserializeEvalMultKey_docs,
935+
py::arg("filename"), py::arg("sertype"))
936+
.def_static("DeserializeEvalAutomorphismKey", [](const std::string &filename, const SerType::SERBINARY &sertype) {
937+
std::ifstream erkeys(filename, std::ios::in | std::ios::binary);
938+
if (!erkeys.is_open()) {
939+
std::cerr << "I cannot read serialization from " << filename << std::endl;
940+
}
941+
bool res = CryptoContextImpl<DCRTPoly>::DeserializeEvalAutomorphismKey<SerType::SERBINARY>(erkeys, sertype);
942+
return res;
943+
},
944+
cc_DeserializeEvalAutomorphismKey_docs,
945+
py::arg("filename"), py::arg("sertype"))
946+
.def_static("DeserializeEvalAutomorphismKey", [](const std::string &filename, const SerType::SERJSON &sertype) {
947+
std::ifstream erkeys(filename, std::ios::in | std::ios::binary);
948+
if (!erkeys.is_open()) {
949+
std::cerr << "I cannot read serialization from " << filename << std::endl;
950+
}
951+
bool res = CryptoContextImpl<DCRTPoly>::DeserializeEvalAutomorphismKey<SerType::SERJSON>(erkeys, sertype);
952+
return res;
953+
},
954+
cc_DeserializeEvalAutomorphismKey_docs,
955+
py::arg("filename"), py::arg("sertype"));
966956

967957
// Generator Functions
968958
m.def("GenCryptoContext", &GenCryptoContext<CryptoContextBFVRNS>,
@@ -1303,16 +1293,16 @@ void bind_encodings(py::module &m)
13031293
.def("SetStringValue", &PlaintextImpl::SetStringValue)
13041294
.def("SetIntVectorValue", &PlaintextImpl::SetIntVectorValue)
13051295
.def("GetFormattedValues", &PlaintextImpl::GetFormattedValues)
1306-
.def("__repr__", [](const PlaintextImpl &p)
1307-
{
1308-
std::stringstream ss;
1309-
ss << "<Plaintext Object: " << p << ">";
1310-
return ss.str(); })
1311-
.def("__str__", [](const PlaintextImpl &p)
1312-
{
1313-
std::stringstream ss;
1314-
ss << p;
1315-
return ss.str(); });
1296+
.def("__repr__", [](const PlaintextImpl &p) {
1297+
std::stringstream ss;
1298+
ss << "<Plaintext Object: " << p << ">";
1299+
return ss.str();
1300+
})
1301+
.def("__str__", [](const PlaintextImpl &p) {
1302+
std::stringstream ss;
1303+
ss << p;
1304+
return ss.str();
1305+
});
13161306
}
13171307

13181308
void bind_ciphertext(py::module &m) {
@@ -1339,7 +1329,7 @@ void bind_ciphertext(py::module &m) {
13391329
.def("GetNoiseScaleDeg", &CiphertextImpl<DCRTPoly>::GetNoiseScaleDeg)
13401330
.def("SetNoiseScaleDeg", &CiphertextImpl<DCRTPoly>::SetNoiseScaleDeg)
13411331
.def("GetCryptoContext", &CiphertextImpl<DCRTPoly>::GetCryptoContext)
1342-
.def("GetEncodingType", &CiphertextImpl<DCRTPoly>::GetEncodingType);
1332+
.def("GetEncodingType", &CiphertextImpl<DCRTPoly>::GetEncodingType)
13431333
.def("GetElements", [](const CiphertextImpl<DCRTPoly>& self) -> const std::vector<DCRTPoly>& {
13441334
return self.GetElements();
13451335
},
@@ -1408,14 +1398,13 @@ void bind_sch_swch_params(py::module &m)
14081398
.def("SetRingDimension", &SchSwchParams::SetRingDimension)
14091399
.def("SetScalingModSize", &SchSwchParams::SetScalingModSize)
14101400
.def("SetBatchSize", &SchSwchParams::SetBatchSize)
1411-
.def("__str__",[](const SchSwchParams &params) {
1412-
std::stringstream stream;
1413-
stream << params;
1414-
return stream.str();
1415-
});
1401+
.def("__str__", [](const SchSwchParams &params) {
1402+
std::stringstream stream;
1403+
stream << params;
1404+
return stream.str();
1405+
});
14161406
}
14171407

1418-
14191408
PYBIND11_MODULE(openfhe, m)
14201409
{
14211410
m.doc() = "Open-Source Fully Homomorphic Encryption Library";

0 commit comments

Comments
 (0)