本文整理汇总了C++中vec_zz_p::SetLength方法的典型用法代码示例。如果您正苦于以下问题:C++ vec_zz_p::SetLength方法的具体用法?C++ vec_zz_p::SetLength怎么用?C++ vec_zz_p::SetLength使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类vec_zz_p
的用法示例。
在下文中一共展示了vec_zz_p::SetLength方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: mul
void mul(vec_zz_p& x, const vec_zz_p& a, zz_p b)
{
long n = a.length();
x.SetLength(n);
long i;
if (n <= 1) {
for (i = 0; i < n; i++)
mul(x[i], a[i], b);
}
else {
long p = zz_p::modulus();
double pinv = zz_p::ModulusInverse();
long bb = rep(b);
mulmod_precon_t bpinv = PrepMulModPrecon(bb, p, pinv);
const zz_p *ap = a.elts();
zz_p *xp = x.elts();
for (i = 0; i < n; i++)
xp[i].LoopHole() = MulModPrecon(rep(ap[i]), bb, p, bpinv);
}
}
示例2: StripZeroes
static void StripZeroes(vec_zz_p& x)
{
long n = x.length();
while (n > 0 && IsZero(x[n-1]))
n--;
x.SetLength(n);
}
示例3: ProjectPowers
void ProjectPowers(vec_zz_p& x, const vec_zz_p& a, long k,
const zz_pXArgument& H, const zz_pXModulus& F)
{
long n = F.n;
if (a.length() > n || k < 0 || NTL_OVERFLOW(k, 1, 0))
Error("ProjectPowers: bad args");
long m = H.H.length()-1;
long l = (k+m-1)/m - 1;
zz_pXMultiplier M;
build(M, H.H[m], F);
vec_zz_p s(INIT_SIZE, n);
s = a;
StripZeroes(s);
x.SetLength(k);
for (long i = 0; i <= l; i++) {
long m1 = min(m, k-i*m);
zz_p* w = &x[i*m];
for (long j = 0; j < m1; j++)
InnerProduct(w[j], H.H[j].rep, s);
if (i < l)
UpdateMap(s, s, M, F);
}
}
示例4: PlainUpdateMap
void PlainUpdateMap(vec_zz_p& xx, const vec_zz_p& a,
const zz_pX& b, const zz_pX& f)
{
long n = deg(f);
long i, m;
if (IsZero(b)) {
xx.SetLength(0);
return;
}
m = n-1 - deg(b);
vec_zz_p x(INIT_SIZE, n);
for (i = 0; i <= m; i++)
InnerProduct(x[i], a, b.rep, i);
if (deg(b) != 0) {
zz_pX c(INIT_SIZE, n);
LeftShift(c, b, m);
for (i = m+1; i < n; i++) {
MulByXMod(c, c, f);
InnerProduct(x[i], a, c.rep);
}
}
xx = x;
}
示例5: negate
void negate(vec_zz_p& x, const vec_zz_p& a)
{
long n = a.length();
x.SetLength(n);
long i;
for (i = 0; i < n; i++)
negate(x[i], a[i]);
}
示例6: random
void random(vec_zz_p& X, long n)
{
X.SetLength(n);
long i;
for (i = 0; i < n; i++)
random(X[i]);
}
示例7: conv
// NOTE: the signature for this is in lzz_p.h
void conv(vec_zz_p& x, const Vec<long>& a)
{
long i, n;
n = a.length();
x.SetLength(n);
VectorConv(n, x.elts(), a.elts());
}
示例8: sub
void sub(vec_zz_p& x, const vec_zz_p& a, const vec_zz_p& b)
{
long n = a.length();
if (b.length() != n) Error("vector sub: dimension mismatch");
x.SetLength(n);
long i;
for (i = 0; i < n; i++)
sub(x[i], a[i], b[i]);
}
示例9: mul_aux
void mul_aux(vec_zz_p& x, const mat_zz_p& A, const vec_zz_p& b)
{
long n = A.NumRows();
long l = A.NumCols();
if (l != b.length())
LogicError("matrix mul: dimension mismatch");
x.SetLength(n);
zz_p* xp = x.elts();
long p = zz_p::modulus();
mulmod_t pinv = zz_p::ModulusInverse();
long i, k;
long acc, tmp;
const zz_p* bp = b.elts();
if (n <= 1) {
for (i = 0; i < n; i++) {
acc = 0;
const zz_p* ap = A[i].elts();
for (k = 0; k < l; k++) {
tmp = MulMod(rep(ap[k]), rep(bp[k]), p, pinv);
acc = AddMod(acc, tmp, p);
}
xp[i].LoopHole() = acc;
}
}
else {
Vec<mulmod_precon_t>::Watcher watch_precon_vec(precon_vec);
precon_vec.SetLength(l);
mulmod_precon_t *bpinv = precon_vec.elts();
for (k = 0; k < l; k++)
bpinv[k] = PrepMulModPrecon(rep(bp[k]), p, pinv);
for (i = 0; i < n; i++) {
acc = 0;
const zz_p* ap = A[i].elts();
for (k = 0; k < l; k++) {
tmp = MulModPrecon(rep(ap[k]), rep(bp[k]), p, bpinv[k]);
acc = AddMod(acc, tmp, p);
}
xp[i].LoopHole() = acc;
}
}
}
示例10: FastTraceVec
void FastTraceVec(vec_zz_p& S, const zz_pX& f)
{
long n = deg(f);
if (n <= 0)
Error("FastTraceVec: bad args");
if (n == 0) {
S.SetLength(0);
return;
}
if (n == 1) {
S.SetLength(1);
set(S[0]);
return;
}
long i;
zz_pX f1;
f1.rep.SetLength(n-1);
for (i = 0; i <= n-2; i++)
f1.rep[i] = f.rep[n-i];
f1.normalize();
zz_pX f2;
f2.rep.SetLength(n-1);
for (i = 0; i <= n-2; i++)
mul(f2.rep[i], f.rep[n-1-i], i+1);
f2.normalize();
zz_pX f3;
InvTrunc(f3, f1, n-1);
MulTrunc(f3, f3, f2, n-1);
S.SetLength(n);
S[0] = n;
for (i = 1; i < n; i++)
negate(S[i], coeff(f3, i-1));
}
示例11: conv
void conv(vec_zz_p& x, const vec_ZZ& a)
{
long i, n;
n = a.length();
x.SetLength(n);
zz_p* xp = x.elts();
const ZZ* ap = a.elts();
for (i = 0; i < n; i++)
conv(xp[i], ap[i]);
}
示例12: negate
void negate(vec_zz_p& x, const vec_zz_p& a)
{
long n = a.length();
long p = zz_p::modulus();
x.SetLength(n);
const zz_p *ap = a.elts();
zz_p *xp = x.elts();
long i;
for (i = 0; i < n; i++)
xp[i].LoopHole() = NegateMod(rep(ap[i]), p);
}
示例13: eval
void eval(vec_zz_p& b, const zz_pX& f, const vec_zz_p& a)
// naive algorithm: repeats Horner
{
if (&b == &f.rep) {
vec_zz_p bb;
eval(bb, f, a);
b = bb;
return;
}
long m = a.length();
b.SetLength(m);
long i;
for (i = 0; i < m; i++)
eval(b[i], f, a[i]);
}
示例14: add
void add(vec_zz_p& x, const vec_zz_p& a, const vec_zz_p& b)
{
long n = a.length();
if (b.length() != n) LogicError("vector add: dimension mismatch");
long p = zz_p::modulus();
x.SetLength(n);
const zz_p *ap = a.elts();
const zz_p *bp = b.elts();
zz_p *xp = x.elts();
long i;
for (i = 0; i < n; i++)
xp[i].LoopHole() = AddMod(rep(ap[i]), rep(bp[i]), p);
}
示例15: VectorCopy
void VectorCopy(vec_zz_p& x, const vec_zz_p& a, long n)
{
if (n < 0) Error("VectorCopy: negative length");
if (NTL_OVERFLOW(n, 1, 0)) Error("overflow in VectorCopy");
long m = min(n, a.length());
x.SetLength(n);
long i;
for (i = 0; i < m; i++)
x[i] = a[i];
for (i = m; i < n; i++)
clear(x[i]);
}