本文整理汇总了C++中vec_long::elts方法的典型用法代码示例。如果您正苦于以下问题:C++ vec_long::elts方法的具体用法?C++ vec_long::elts怎么用?C++ vec_long::elts使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类vec_long
的用法示例。
在下文中一共展示了vec_long::elts方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: FFT
void Cmodulus::FFT(vec_long &y, const ZZX& x) const
{
FHE_TIMER_START;
zz_pBak bak; bak.save();
context.restore();
zz_pX& tmp = Cmodulus::getScratch_zz_pX();
{ FHE_NTIMER_START(FFT_remainder);
conv(tmp,x); // convert input to zpx format
}
if (!ALT_CRT && zMStar->getPow2()) {
// special case when m is a power of 2
long k = zMStar->getPow2();
long phim = (1L << (k-1));
long dx = deg(tmp);
long p = zz_p::modulus();
const zz_p *powers_p = (*powers).rep.elts();
const mulmod_precon_t *powers_aux_p = powers_aux.elts();
y.SetLength(phim);
long *yp = y.elts();
zz_p *tmp_p = tmp.rep.elts();
for (long i = 0; i <= dx; i++)
yp[i] = MulModPrecon(rep(tmp_p[i]), rep(powers_p[i]), p, powers_aux_p[i]);
for (long i = dx+1; i < phim; i++)
yp[i] = 0;
FFTFwd(yp, yp, k-1, *zz_pInfo->p_info);
return;
}
zz_p rt;
conv(rt, root); // convert root to zp format
BluesteinFFT(tmp, getM(), rt, *powers, powers_aux, *Rb); // call the FFT routine
// copy the result to the output vector y, keeping only the
// entries corresponding to primitive roots of unity
y.SetLength(zMStar->getPhiM());
long i,j;
long m = getM();
for (i=j=0; i<m; i++)
if (zMStar->inZmStar(i)) y[j++] = rep(coeff(tmp,i));
}
示例2: FFT_aux
void Cmodulus::FFT_aux(vec_long &y, zz_pX& tmp) const
{
if (zMStar->getPow2()) {
// special case when m is a power of 2
long k = zMStar->getPow2();
long phim = (1L << (k-1));
long dx = deg(tmp);
long p = zz_p::modulus();
const zz_p *powers_p = (*powers).rep.elts();
const mulmod_precon_t *powers_aux_p = powers_aux.elts();
y.SetLength(phim);
long *yp = y.elts();
zz_p *tmp_p = tmp.rep.elts();
for (long i = 0; i <= dx; i++)
yp[i] = MulModPrecon(rep(tmp_p[i]), rep(powers_p[i]), p, powers_aux_p[i]);
for (long i = dx+1; i < phim; i++)
yp[i] = 0;
#ifdef FHE_OPENCL
AltFFTFwd(yp, yp, k-1, *altFFTInfo);
#else
FFTFwd(yp, yp, k-1, *zz_pInfo->p_info);
#endif
return;
}
zz_p rt;
conv(rt, root); // convert root to zp format
BluesteinFFT(tmp, getM(), rt, *powers, powers_aux, *Rb); // call the FFT routine
// copy the result to the output vector y, keeping only the
// entries corresponding to primitive roots of unity
y.SetLength(zMStar->getPhiM());
long i,j;
long m = getM();
for (i=j=0; i<m; i++)
if (zMStar->inZmStar(i)) y[j++] = rep(coeff(tmp,i));
}
示例3: iFFT
void Cmodulus::iFFT(zz_pX &x, const vec_long& y)const
{
FHE_TIMER_START;
zz_pBak bak; bak.save();
context.restore();
if (zMStar->getPow2()) {
// special case when m is a power of 2
long k = zMStar->getPow2();
long phim = (1L << (k-1));
long p = zz_p::modulus();
const zz_p *ipowers_p = (*ipowers).rep.elts();
const mulmod_precon_t *ipowers_aux_p = ipowers_aux.elts();
const long *yp = y.elts();
vec_long& tmp = Cmodulus::getScratch_vec_long();
tmp.SetLength(phim);
long *tmp_p = tmp.elts();
#ifdef FHE_OPENCL
AltFFTRev1(tmp_p, yp, k-1, *altFFTInfo);
#else
FFTRev1(tmp_p, yp, k-1, *zz_pInfo->p_info);
#endif
x.rep.SetLength(phim);
zz_p *xp = x.rep.elts();
for (long i = 0; i < phim; i++)
xp[i].LoopHole() = MulModPrecon(tmp_p[i], rep(ipowers_p[i]), p, ipowers_aux_p[i]);
x.normalize();
return;
}
zz_p rt;
long m = getM();
// convert input to zpx format, initializing only the coeffs i s.t. (i,m)=1
x.rep.SetLength(m);
long i,j;
for (i=j=0; i<m; i++)
if (zMStar->inZmStar(i)) x.rep[i].LoopHole() = y[j++]; // DIRT: y[j] already reduced
x.normalize();
conv(rt, rInv); // convert rInv to zp format
BluesteinFFT(x, m, rt, *ipowers, ipowers_aux, *iRb); // call the FFT routine
// reduce the result mod (Phi_m(X),q) and copy to the output polynomial x
{ FHE_NTIMER_START(iFFT_division);
rem(x, x, *phimx); // out %= (Phi_m(X),q)
}
// normalize
zz_p mm_inv;
conv(mm_inv, m_inv);
x *= mm_inv;
}
示例4: clear
inline void clear(vec_long& v) {
memset(v.elts(),0,sizeof(long)*v.length());
}
示例5: mul_aux
static
void mul_aux(mat_zz_p& X, const mat_zz_p& A, const mat_zz_p& B)
{
long n = A.NumRows();
long l = A.NumCols();
long m = B.NumCols();
if (l != B.NumRows())
Error("matrix mul: dimension mismatch");
X.SetDims(n, m);
if (m > 1) { // new preconditioning code
long p = zz_p::modulus();
double pinv = zz_p::ModulusInverse();
mul_aux_vec.SetLength(m);
long *acc = mul_aux_vec.elts();
long i, j, k;
for (i = 0; i < n; i++) {
const zz_p* ap = A[i].elts();
for (j = 0; j < m; j++) acc[j] = 0;
for (k = 0; k < l; k++) {
long aa = rep(ap[k]);
if (aa != 0) {
const zz_p* bp = B[k].elts();
long T1;
mulmod_precon_t aapinv = PrepMulModPrecon(aa, p, pinv);
for (j = 0; j < m; j++) {
T1 = MulModPrecon(rep(bp[j]), aa, p, aapinv);
acc[j] = AddMod(acc[j], T1, p);
}
}
}
zz_p *xp = X[i].elts();
for (j = 0; j < m; j++)
xp[j].LoopHole() = acc[j];
}
}
else { // just use the old code, w/o preconditioning
long p = zz_p::modulus();
double pinv = zz_p::ModulusInverse();
long i, j, k;
long acc, tmp;
for (i = 1; i <= n; i++) {
for (j = 1; j <= m; j++) {
acc = 0;
for(k = 1; k <= l; k++) {
tmp = MulMod(rep(A(i,k)), rep(B(k,j)), p, pinv);
acc = AddMod(acc, tmp, p);
}
X(i,j).LoopHole() = acc;
}
}
}
}
示例6: mul
void mul(vec_zz_p& x, const vec_zz_p& a, const mat_zz_p& B)
{
long l = a.length();
long m = B.NumCols();
if (l != B.NumRows())
Error("matrix mul: dimension mismatch");
if (m == 0) {
x.SetLength(0);
}
else if (m == 1) {
long p = zz_p::modulus();
double pinv = zz_p::ModulusInverse();
long acc, tmp;
long k;
acc = 0;
for(k = 1; k <= l; k++) {
tmp = MulMod(rep(a(k)), rep(B(k,1)), p, pinv);
acc = AddMod(acc, tmp, p);
}
x.SetLength(1);
x(1).LoopHole() = acc;
}
else { // m > 1. precondition
long p = zz_p::modulus();
double pinv = zz_p::ModulusInverse();
mul_aux_vec.SetLength(m);
long *acc = mul_aux_vec.elts();
long j, k;
const zz_p* ap = a.elts();
for (j = 0; j < m; j++) acc[j] = 0;
for (k = 0; k < l; k++) {
long aa = rep(ap[k]);
if (aa != 0) {
const zz_p* bp = B[k].elts();
long T1;
mulmod_precon_t aapinv = PrepMulModPrecon(aa, p, pinv);
for (j = 0; j < m; j++) {
T1 = MulModPrecon(rep(bp[j]), aa, p, aapinv);
acc[j] = AddMod(acc[j], T1, p);
}
}
}
x.SetLength(m);
zz_p *xp = x.elts();
for (j = 0; j < m; j++)
xp[j].LoopHole() = acc[j];
}
}