24 #ifndef SRC_CORE_LIB_LATTICE_ELEMPARAMFACTORY_H_ 25 #define SRC_CORE_LIB_LATTICE_ELEMPARAMFACTORY_H_ 28 using std::shared_ptr;
33 #include "lattice/ildcrtparams.h" 35 #include "math/backend.h" 36 #include "utils/parmfactory.h" 43 enum ElementOrder { M16 = 0, M1024, M2048, M4096, M8192, M16384, M32768 };
47 static struct ElemParmSet {
54 static size_t GetNearestIndex(usint m) {
56 if (DefaultSet[0].m < m) {
57 for (sIdx = 1; DefaultSet[sIdx].m != 0; sIdx++) {
58 if (m <= DefaultSet[sIdx].m)
break;
61 if (DefaultSet[sIdx].m == 0) sIdx--;
75 DEBUG(
"in GenElemParams(ElementOrder o)");
76 return std::make_shared<P>(
77 DefaultSet[
static_cast<int>(o)].m,
78 typename P::Integer(DefaultSet[static_cast<int>(o)].q),
79 typename P::Integer(DefaultSet[static_cast<int>(o)].ru));
92 DEBUG(
"in GenElemParams(usint m)");
93 size_t sIdx = GetNearestIndex(m);
95 return std::make_shared<P>(DefaultSet[sIdx].m,
96 typename P::Integer(DefaultSet[sIdx].q),
97 typename P::Integer(DefaultSet[sIdx].ru));
109 template <
typename P>
110 static shared_ptr<P>
GenElemParams(usint m, usint bits, usint towersize = 1) {
112 DEBUG(
"in GenElemParams(usint m, usint bits, usint towers)");
113 typename P::Integer q = FirstPrime<typename P::Integer>(bits, m);
114 typename P::Integer ru = RootOfUnity<typename P::Integer>(m, q);
115 return std::make_shared<P>(m, q, ru);
126 template <
typename P>
128 const typename P::Integer& ctModulus,
129 const typename P::Integer& rootUnity) {
131 DEBUG(
"in GenElemParams(usint m, const typename P::Integer etc)");
132 return std::make_shared<P>(m, ctModulus, rootUnity);
137 inline shared_ptr<ILDCRTParams<M2Integer>>
138 ElemParamFactory::GenElemParams<ILDCRTParams<M2Integer>>(usint m, usint bits,
142 "in GenElemParams<ILDCRTParams<M2Integer>>(usint m, usint bits, usint " 147 return GenerateDCRTParams<M2Integer>(m, towersize, bits);
151 inline shared_ptr<ILDCRTParams<M4Integer>>
152 ElemParamFactory::GenElemParams<ILDCRTParams<M4Integer>>(usint m, usint bits,
156 "in GenElemParams<ILDCRTParams<M4Integer>>(usint m, usint bits, usint " 161 return GenerateDCRTParams<M4Integer>(m, towersize, bits);
165 inline shared_ptr<ILDCRTParams<M6Integer>>
166 ElemParamFactory::GenElemParams<ILDCRTParams<M6Integer>>(usint m, usint bits,
170 "in GenElemParams<ILDCRTParams<M6Integer>>(usint m, usint bits, usint " 175 return GenerateDCRTParams<M6Integer>(m, towersize, bits);
static shared_ptr< P > GenElemParams(usint m, usint bits, usint towersize=1)
Definition: elemparamfactory.h:110
static shared_ptr< P > GenElemParams(usint m)
Definition: elemparamfactory.h:90
static shared_ptr< P > GenElemParams(ElementOrder o)
Definition: elemparamfactory.h:73
Definition: binfhecontext.h:36
Wrapper class to hold the parameters for integer lattice operations and their inheritors.
Definition: elemparamfactory.h:45
static shared_ptr< P > GenElemParams(usint m, const typename P::Integer &ctModulus, const typename P::Integer &rootUnity)
Definition: elemparamfactory.h:127