?? vec_lzz_pe.cpp
字號:
#include <NTL/vec_lzz_pE.h>
#include <NTL/new.h>
NTL_START_IMPL
NTL_vector_impl(zz_pE,vec_zz_pE)
NTL_io_vector_impl(zz_pE,vec_zz_pE)
NTL_eq_vector_impl(zz_pE,vec_zz_pE)
void InnerProduct(zz_pE& x, const vec_zz_pE& a, const vec_zz_pE& b)
{
long n = min(a.length(), b.length());
long i;
zz_pX accum, t;
clear(accum);
for (i = 0; i < n; i++) {
mul(t, rep(a[i]), rep(b[i]));
add(accum, accum, t);
}
conv(x, accum);
}
void InnerProduct(zz_pE& x, const vec_zz_pE& a, const vec_zz_pE& b,
long offset)
{
if (offset < 0) Error("InnerProduct: negative offset");
if (NTL_OVERFLOW(offset, 1, 0)) Error("InnerProduct: offset too big");
long n = min(a.length(), b.length()+offset);
long i;
zz_pX accum, t;
clear(accum);
for (i = offset; i < n; i++) {
mul(t, rep(a[i]), rep(b[i-offset]));
add(accum, accum, t);
}
conv(x, accum);
}
void mul(vec_zz_pE& x, const vec_zz_pE& a, const zz_pE& b_in)
{
zz_pE b = b_in;
long n = a.length();
x.SetLength(n);
long i;
for (i = 0; i < n; i++)
mul(x[i], a[i], b);
}
void mul(vec_zz_pE& x, const vec_zz_pE& a, const zz_p& b_in)
{
NTL_zz_pRegister(b);
b = b_in;
long n = a.length();
x.SetLength(n);
long i;
for (i = 0; i < n; i++)
mul(x[i], a[i], b);
}
void mul(vec_zz_pE& x, const vec_zz_pE& a, long b_in)
{
NTL_zz_pRegister(b);
b = b_in;
long n = a.length();
x.SetLength(n);
long i;
for (i = 0; i < n; i++)
mul(x[i], a[i], b);
}
void add(vec_zz_pE& x, const vec_zz_pE& a, const vec_zz_pE& b)
{
long n = a.length();
if (b.length() != n) Error("vector add: dimension mismatch");
x.SetLength(n);
long i;
for (i = 0; i < n; i++)
add(x[i], a[i], b[i]);
}
void sub(vec_zz_pE& x, const vec_zz_pE& a, const vec_zz_pE& 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]);
}
void negate(vec_zz_pE& x, const vec_zz_pE& a)
{
long n = a.length();
x.SetLength(n);
long i;
for (i = 0; i < n; i++)
negate(x[i], a[i]);
}
void clear(vec_zz_pE& x)
{
long n = x.length();
long i;
for (i = 0; i < n; i++)
clear(x[i]);
}
long IsZero(const vec_zz_pE& a)
{
long n = a.length();
long i;
for (i = 0; i < n; i++)
if (!IsZero(a[i]))
return 0;
return 1;
}
vec_zz_pE operator+(const vec_zz_pE& a, const vec_zz_pE& b)
{
vec_zz_pE res;
add(res, a, b);
NTL_OPT_RETURN(vec_zz_pE, res);
}
vec_zz_pE operator-(const vec_zz_pE& a, const vec_zz_pE& b)
{
vec_zz_pE res;
sub(res, a, b);
NTL_OPT_RETURN(vec_zz_pE, res);
}
vec_zz_pE operator-(const vec_zz_pE& a)
{
vec_zz_pE res;
negate(res, a);
NTL_OPT_RETURN(vec_zz_pE, res);
}
zz_pE operator*(const vec_zz_pE& a, const vec_zz_pE& b)
{
zz_pE res;
InnerProduct(res, a, b);
return res;
}
void VectorCopy(vec_zz_pE& x, const vec_zz_pE& 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]);
}
NTL_END_IMPL
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -