Skip to content

Commit 20063e6

Browse files
authored
Issue757 (#758)
* fix for issue757 (remove m_originalModulus) * fix for issue734
1 parent dd3035b commit 20063e6

File tree

4 files changed

+16
-65
lines changed

4 files changed

+16
-65
lines changed

Diff for: OpenFHEConfig.cmake.in

+2-7
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,12 @@ set(OpenFHE_STATIC_LIBRARIES @OpenFHE_STATIC_LIBS@ @THIRDPARTYLIBS@ @OpenMP_CXX_
1818
set(OpenFHE_SHARED_LIBRARIES @OpenFHE_SHARED_LIBS@ @THIRDPARTYLIBS@ @OpenMP_CXX_FLAGS@)
1919
set(BASE_OPENFHE_VERSION @OPENFHE_VERSION@)
2020

21-
set(OPENMP_INCLUDES "@OPENMP_INCLUDES@" )
22-
set(OPENMP_LIBRARIES "@OPENMP_LIBRARIES@" )
21+
set(OPENMP_INCLUDES "@OPENMP_INCLUDES@")
22+
set(OPENMP_LIBRARIES "@OPENMP_LIBRARIES@")
2323

2424
set(OpenFHE_CXX_FLAGS "@CMAKE_CXX_FLAGS@")
2525
set(OpenFHE_C_FLAGS "@CMAKE_C_FLAGS@")
2626

27-
if( "@WITH_NTL@" STREQUAL "Y" )
28-
set(OpenFHE_CXX_FLAGS "${OpenFHE_CXX_FLAGS} -DWITH_NTL" )
29-
set(OpenFHE_C_FLAGS "${OpenFHE_C_FLAGS} -DWITH_NTL")
30-
endif()
31-
3227
set (OpenFHE_EXE_LINKER_FLAGS "@CMAKE_EXE_LINKER_FLAGS@")
3328

3429
# CXX info

Diff for: src/core/include/lattice/hal/dcrtpoly-interface.h

-8
Original file line numberDiff line numberDiff line change
@@ -233,14 +233,6 @@ class DCRTPolyInterface : public ILElement<DerivedType, BigVecType> {
233233
return this->GetDerived().GetParams()->GetModulus();
234234
}
235235

236-
/**
237-
* @brief returns the element's original modulus, derived from Poly
238-
* @return returns the modulus of the element.
239-
*/
240-
const BigIntType& GetOriginalModulus() const {
241-
return this->GetDerived().GetParams()->GetOriginalModulus();
242-
}
243-
244236
/**
245237
* @brief returns the element's root of unity.
246238
* @return the element's root of unity.

Diff for: src/core/include/lattice/hal/default/dcrtpoly-impl.h

-3
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ template <typename VecType>
6060
DCRTPolyImpl<VecType>::DCRTPolyImpl(const PolyLargeType& rhs,
6161
const std::shared_ptr<DCRTPolyImpl::Params>& params) noexcept
6262
: DCRTPolyImpl<VecType>::DCRTPolyImpl(params, rhs.GetFormat(), true) {
63-
m_params->SetOriginalModulus(rhs.GetModulus());
6463
size_t size{m_vectors.size()};
6564
uint32_t rdim{rhs.GetLength()};
6665
for (size_t i{0}; i < size; ++i) {
@@ -73,7 +72,6 @@ DCRTPolyImpl<VecType>::DCRTPolyImpl(const PolyLargeType& rhs,
7372

7473
template <typename VecType>
7574
DCRTPolyImpl<VecType>& DCRTPolyImpl<VecType>::operator=(const PolyLargeType& rhs) noexcept {
76-
m_params->SetOriginalModulus(rhs.GetModulus());
7775
m_vectors.clear();
7876
m_vectors.reserve(m_params->GetParams().size());
7977
uint32_t rdim{rhs.GetLength()};
@@ -668,7 +666,6 @@ void DCRTPolyImpl<VecType>::SetValuesModSwitch(const DCRTPolyImpl& element, cons
668666
.Mod(modulus);
669667
}
670668
m_vectors[0].SetValues(std::move(tmp), Format::COEFFICIENT);
671-
m_params->SetOriginalModulus(modulus);
672669
}
673670

674671
template <typename VecType>

Diff for: src/core/include/lattice/hal/default/ildcrtparams.h

+14-47
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class ILDCRTParams final : public ElemParams<IntType> {
7373
using ILNativeParams = ILParamsImpl<NativeInteger>;
7474

7575
ILDCRTParams(uint32_t corder, const IntType& modulus, const IntType& rootOfUnity = IntType(0))
76-
: ElemParams<IntType>(corder, modulus), m_originalModulus(modulus) {
76+
: ElemParams<IntType>(corder, modulus) {
7777
// NOTE params generation uses this constructor to make an empty params that
7878
// it will later populate during the gen process. For that special case...
7979
// we don't populate, and we just return
@@ -146,8 +146,8 @@ class ILDCRTParams final : public ElemParams<IntType> {
146146

147147
ILDCRTParams(uint32_t corder, const std::vector<NativeInteger>& moduli,
148148
const std::vector<NativeInteger>& rootsOfUnity, const std::vector<NativeInteger>& moduliBig,
149-
const std::vector<NativeInteger>& rootsOfUnityBig, const IntType& inputOriginalModulus = IntType(0))
150-
: ElemParams<IntType>(corder, 0), m_originalModulus(inputOriginalModulus) {
149+
const std::vector<NativeInteger>& rootsOfUnityBig)
150+
: ElemParams<IntType>(corder, 0) {
151151
size_t limbs{moduli.size()};
152152
if (limbs != rootsOfUnity.size() || limbs != moduliBig.size() || limbs != rootsOfUnityBig.size())
153153
OPENFHE_THROW("sizes of moduli and roots of unity do not match 2");
@@ -170,9 +170,7 @@ class ILDCRTParams final : public ElemParams<IntType> {
170170
* @param corder the order of the ciphertext
171171
* @param &moduli is the tower of moduli
172172
*/
173-
ILDCRTParams(uint32_t corder, const std::vector<NativeInteger>& moduli,
174-
const IntType& inputOriginalModulus = IntType(0))
175-
: ElemParams<IntType>(corder, 0), m_originalModulus(inputOriginalModulus) {
173+
ILDCRTParams(uint32_t corder, const std::vector<NativeInteger>& moduli) : ElemParams<IntType>(corder, 0) {
176174
size_t limbs{moduli.size()};
177175
m_params.reserve(limbs);
178176
IntType compositeModulus(1);
@@ -191,19 +189,15 @@ class ILDCRTParams final : public ElemParams<IntType> {
191189
* @param params the componet parameters.
192190
* @return
193191
*/
194-
ILDCRTParams(uint32_t corder, const std::vector<std::shared_ptr<ILNativeParams>>& params,
195-
const IntType& inputOriginalModulus = IntType(0))
196-
: ElemParams<IntType>(corder, 0), m_params(params), m_originalModulus(inputOriginalModulus) {
192+
ILDCRTParams(uint32_t corder, const std::vector<std::shared_ptr<ILNativeParams>>& params)
193+
: ElemParams<IntType>(corder, 0), m_params(params) {
197194
RecalculateModulus();
198195
}
199196

200-
ILDCRTParams(const ILDCRTParams& rhs)
201-
: ElemParams<IntType>(rhs), m_params(rhs.m_params), m_originalModulus(rhs.m_originalModulus) {}
197+
ILDCRTParams(const ILDCRTParams& rhs) : ElemParams<IntType>(rhs), m_params(rhs.m_params) {}
202198

203199
ILDCRTParams(ILDCRTParams&& rhs) noexcept
204-
: ElemParams<IntType>(rhs),
205-
m_params(std::move(rhs.m_params)),
206-
m_originalModulus(std::move(rhs.m_originalModulus)) {}
200+
: ElemParams<IntType>(std::move(rhs)), m_params(std::move(rhs.m_params)) {}
207201

208202
/**
209203
* Assignment Operator.
@@ -213,15 +207,13 @@ class ILDCRTParams final : public ElemParams<IntType> {
213207
*/
214208
ILDCRTParams& operator=(const ILDCRTParams& rhs) {
215209
ElemParams<IntType>::operator=(rhs);
216-
m_params = rhs.m_params;
217-
m_originalModulus = rhs.m_originalModulus;
210+
m_params = rhs.m_params;
218211
return *this;
219212
}
220213

221214
ILDCRTParams& operator=(ILDCRTParams&& rhs) noexcept {
222-
ElemParams<IntType>::operator=(rhs);
223-
m_params = std::move(rhs.m_params);
224-
m_originalModulus = std::move(rhs.m_originalModulus);
215+
ElemParams<IntType>::operator=(std::move(rhs));
216+
m_params = std::move(rhs.m_params);
225217
return *this;
226218
}
227219

@@ -242,28 +234,12 @@ class ILDCRTParams final : public ElemParams<IntType> {
242234
* @return A vector of the component polynomial parameters.
243235
*/
244236
std::vector<std::shared_ptr<ILNativeParams>> GetParamPartition(uint32_t start, uint32_t end) const {
245-
if (end < start || end > m_params.size())
237+
if (end < start || end >= m_params.size())
246238
OPENFHE_THROW("Incorrect parameters for GetParamPartition - (start: " + std::to_string(start) +
247239
", end:" + std::to_string(end) + ")");
248240
return std::vector<std::shared_ptr<ILNativeParams>>(m_params.begin() + start, m_params.begin() + end + 1);
249241
}
250242

251-
/**
252-
* @brief Simple getter method for the original modulus, not the ciphertex
253-
* modulus.
254-
* @return The original modulus, not the big ciphertext modulus.
255-
*/
256-
const IntType& GetOriginalModulus() const {
257-
return m_originalModulus;
258-
}
259-
/**
260-
* @brief Simple setter method for the original modulus, not the ciphertex
261-
* modulus.
262-
* @return void
263-
*/
264-
void SetOriginalModulus(const IntType& inputOriginalModulus) {
265-
m_originalModulus = inputOriginalModulus;
266-
}
267243
/**
268244
* @brief Getter method for the component parameters of a specific index.
269245
* @param i the index of the parameters to return. Note this this call is
@@ -321,7 +297,7 @@ class ILDCRTParams final : public ElemParams<IntType> {
321297
if (*m_params[i] != *dcrtParams->m_params[i])
322298
return false;
323299
}
324-
return (m_originalModulus == dcrtParams->GetOriginalModulus());
300+
return true;
325301
}
326302

327303
/**
@@ -350,7 +326,6 @@ class ILDCRTParams final : public ElemParams<IntType> {
350326
void save(Archive& ar, std::uint32_t const version) const {
351327
ar(::cereal::base_class<ElemParams<IntType>>(this));
352328
ar(::cereal::make_nvp("p", m_params));
353-
ar(::cereal::make_nvp("m", m_originalModulus));
354329
}
355330

356331
template <class Archive>
@@ -361,7 +336,6 @@ class ILDCRTParams final : public ElemParams<IntType> {
361336
}
362337
ar(::cereal::base_class<ElemParams<IntType>>(this));
363338
ar(::cereal::make_nvp("p", m_params));
364-
ar(::cereal::make_nvp("m", m_originalModulus));
365339
}
366340

367341
std::string SerializedObjectName() const override {
@@ -378,18 +352,11 @@ class ILDCRTParams final : public ElemParams<IntType> {
378352
out << std::endl << " m_params:" << std::endl;
379353
for (size_t i = 0; i < m_params.size(); ++i)
380354
out << " " << i << ": " << *m_params[i];
381-
return out << " m_originalModulus: " << m_originalModulus << std::endl;
355+
return out << std::endl;
382356
}
383357

384358
// array of smaller ILParams
385359
std::vector<std::shared_ptr<ILNativeParams>> m_params;
386-
387-
// original modulus when being constructed from a Poly or when
388-
// ctor is passed that parameter
389-
// note orignalModulus will be <= composite modules
390-
// i.e. \Prod_i=0^k-1 m_params[i]->GetModulus()
391-
// note not using ElemParams::ciphertextModulus due to object stripping
392-
IntType m_originalModulus;
393360
};
394361

395362
} // namespace lbcrypto

0 commit comments

Comments
 (0)