本文整理汇总了C++中vec_long::length方法的典型用法代码示例。如果您正苦于以下问题:C++ vec_long::length方法的具体用法?C++ vec_long::length怎么用?C++ vec_long::length使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类vec_long
的用法示例。
在下文中一共展示了vec_long::length方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: recursiveInterpolateMod
static void recursiveInterpolateMod(ZZX& poly, const vec_long& x, vec_long& y,
const vec_zz_p& xmod, vec_zz_p& ymod,
long p, long p2e)
{
if (p2e<=1) { // recursion edge condition, mod-1 poly = 0
clear(poly);
return;
}
// convert y input to zz_p
for (long j=0; j<y.length(); j++) ymod[j] = to_zz_p(y[j] % p);
// a polynomial p_i s.t. p_i(x[j]) = i'th p-base digit of poly(x[j])
zz_pX polyMod;
interpolate(polyMod, xmod, ymod); // interpolation modulo p
ZZX polyTmp; conv(polyTmp, polyMod); // convert to ZZX
// update ytmp by subtracting the new digit, then dividing by p
for (long j=0; j<y.length(); j++) {
y[j] -= polyEvalMod(polyTmp,x[j],p2e); // mod p^e
if (y[j]<0) y[j] += p2e;
// if (y[j] % p != 0) {
// cerr << "@@error (p2^e="<<p2e<<"): y["<<j<<"] not divisible by "<<p<< endl;
// exit(0);
// }
y[j] /= p;
} // maybe it's worth optimizing above by using multi-point evaluation
// recursive call to get the solution of poly'(x)=y mod p^{e-1}
recursiveInterpolateMod(poly, x, y, xmod, ymod, p, p2e/p);
// return poly = p*poly' + polyTmp
poly *= p;
poly += polyTmp;
}
示例2: RandomBasisElt
static
void RandomBasisElt(ZZ_pX& g, const vec_long& D, const vec_ZZVec& M)
{
ZZ t1, t2;
long n = D.length();
long i, j, s;
g.rep.SetLength(n);
vec_ZZ_p& v = g.rep;
for (j = n-1; j >= 0; j--) {
if (D[j] == -1)
random(v[j]);
else {
i = D[j];
// v[j] = sum_{s=j+1}^{n-1} v[s]*M[i,s]
clear(t1);
for (s = j+1; s < n; s++) {
mul(t2, rep(v[s]), M[i][s]);
add(t1, t1, t2);
}
conv(v[j], t1);
}
}
g.normalize();
}
示例3: interpolateMod
// Interpolate the integer polynomial such that poly(x[i] mod p)=y[i] (mod p^e)
// It is assumed that the points x[i] are all distinct modulo p
void interpolateMod(ZZX& poly, const vec_long& x, const vec_long& y,
long p, long e)
{
poly = ZZX::zero(); // initialize to zero
long p2e = power_long(p,e); // p^e
vec_long ytmp(INIT_SIZE, y.length()); // A temporary writable copy
for (long j=0; j<y.length(); j++) {
ytmp[j] = y[j] % p2e;
if (ytmp[j] < 0) ytmp[j] += p2e;
}
zz_pBak bak; bak.save(); // Set the current modulus to p
zz_p::init(p);
vec_zz_p xmod(INIT_SIZE, x.length()); // convert to zz_p
for (long j=0; j<x.length(); j++) xmod[j] = to_zz_p(x[j] % p);
vec_zz_p ymod(INIT_SIZE, y.length()); // scratch space
recursiveInterpolateMod(poly, x, ytmp, xmod, ymod, p, p2e);
}
示例4: ResHalfGCD
void ResHalfGCD(zz_pX& U, zz_pX& V, vec_zz_p& cvec, vec_long& dvec)
{
long d_red = (deg(U)+1)/2;
if (IsZero(V) || deg(V) <= deg(U) - d_red) {
return;
}
long du = deg(U);
long d1 = (d_red + 1)/2;
if (d1 < 1) d1 = 1;
if (d1 >= d_red) d1 = d_red - 1;
zz_pXMatrix M1;
ResHalfGCD(M1, U, V, d1, cvec, dvec);
mul(U, V, M1);
long d2 = deg(V) - du + d_red;
if (IsZero(V) || d2 <= 0) {
return;
}
M1(0,0).kill();
M1(0,1).kill();
M1(1,0).kill();
M1(1,1).kill();
zz_pX Q;
append(cvec, LeadCoeff(V));
append(dvec, dvec[dvec.length()-1]-deg(U)+deg(V));
DivRem(Q, U, U, V);
swap(U, V);
ResHalfGCD(M1, U, V, d2, cvec, dvec);
mul(U, V, M1);
}
示例5: ResIterHalfGCD
void ResIterHalfGCD(ZZ_pXMatrix& M_out, ZZ_pX& U, ZZ_pX& V, long d_red,
vec_ZZ_p& cvec, vec_long& dvec)
{
M_out(0,0).SetMaxLength(d_red);
M_out(0,1).SetMaxLength(d_red);
M_out(1,0).SetMaxLength(d_red);
M_out(1,1).SetMaxLength(d_red);
set(M_out(0,0)); clear(M_out(0,1));
clear(M_out(1,0)); set(M_out(1,1));
long goal = deg(U) - d_red;
if (deg(V) <= goal)
return;
ZZVec tmp(deg(U)+1, ZZ_p::ExtendedModulusSize());
ZZ_pX Q, t(INIT_SIZE, d_red);
while (deg(V) > goal) {
append(cvec, LeadCoeff(V));
append(dvec, dvec[dvec.length()-1]-deg(U)+deg(V));
PlainDivRem(Q, U, U, V, tmp);
swap(U, V);
mul(t, Q, M_out(1,0));
sub(t, M_out(0,0), t);
M_out(0,0) = M_out(1,0);
M_out(1,0) = t;
mul(t, Q, M_out(1,1));
sub(t, M_out(0,1), t);
M_out(0,1) = M_out(1,1);
M_out(1,1) = t;
}
}
示例6: seekPastChar
// cerr << "FHEPubKey[";
seekPastChar(str, '['); // defined in NumbTh.cpp
// sanity check, verify that basic context parameters are correct
unsigned long m, p, r;
vector<long> gens, ords;
readContextBase(str, m, p, r, gens, ords);
assert(comparePAlgebra(pk.getContext().zMStar, m, p, r, gens, ords));
// Get the public encryption key itself
str >> pk.pubEncrKey;
// Get the vector of secret-key Hamming-weights
vec_long vl;
str >> vl;
pk.skHwts.resize(vl.length());
for (long i=0; i<(long)pk.skHwts.size(); i++) pk.skHwts[i] = vl[i];
// Get the key-switching matrices
long nMatrices;
str >> nMatrices;
pk.keySwitching.resize(nMatrices);
for (long i=0; i<nMatrices; i++) // read the matrix from input str
pk.keySwitching[i].readMatrix(str, pk.getContext());
// Get the key-switching map
Vec< Vec<long> > vvl;
str >> vvl;
pk.keySwitchMap.resize(vvl.length());
for (long i=0; i<(long)pk.keySwitchMap.size(); i++) {
pk.keySwitchMap[i].resize(vvl[i].length());
示例7: wasComputed
bool wasComputed(long i) { return (i>=0 && i<v.length() && v[i]>=0); }
示例8: size
long size() const { return v.length(); }
示例9: clear
inline void clear(vec_long& v) {
memset(v.elts(),0,sizeof(long)*v.length());
}