本文整理汇总了C++中mat_zz_p类的典型用法代码示例。如果您正苦于以下问题:C++ mat_zz_p类的具体用法?C++ mat_zz_p怎么用?C++ mat_zz_p使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了mat_zz_p类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: power
void power(mat_zz_p& X, const mat_zz_p& A, const ZZ& e)
{
if (A.NumRows() != A.NumCols()) LogicError("power: non-square matrix");
if (e == 0) {
ident(X, A.NumRows());
return;
}
mat_zz_p T1, T2;
long i, k;
k = NumBits(e);
T1 = A;
for (i = k-2; i >= 0; i--) {
sqr(T2, T1);
if (bit(e, i))
mul(T1, T2, A);
else
T1 = T2;
}
if (e < 0)
inv(X, T1);
else
X = T1;
}
示例2: transpose
void transpose(mat_zz_p& X, const mat_zz_p& A)
{
long n = A.NumRows();
long m = A.NumCols();
long i, j;
if (&X == & A) {
if (n == m)
for (i = 1; i <= n; i++)
for (j = i+1; j <= n; j++)
swap(X(i, j), X(j, i));
else {
mat_zz_p tmp;
tmp.SetDims(m, n);
for (i = 1; i <= n; i++)
for (j = 1; j <= m; j++)
tmp(j, i) = A(i, j);
X.kill();
X = tmp;
}
}
else {
X.SetDims(m, n);
for (i = 1; i <= n; i++)
for (j = 1; j <= m; j++)
X(j, i) = A(i, j);
}
}
示例3: mul
void mul(mat_zz_p& X, const mat_zz_p& A, zz_p b)
{
long n = A.NumRows();
long m = A.NumCols();
X.SetDims(n, m);
long i, j;
if (n == 0 || m == 0 || (n == 1 && m == 1)) {
for (i = 0; i < n; i++)
for (j = 0; j < m; j++)
mul(X[i][j], A[i][j], b);
}
else {
long p = zz_p::modulus();
mulmod_t pinv = zz_p::ModulusInverse();
long bb = rep(b);
mulmod_precon_t bpinv = PrepMulModPrecon(bb, p, pinv);
for (i = 0; i < n; i++) {
const zz_p *ap = A[i].elts();
zz_p *xp = X[i].elts();
for (j = 0; j < m; j++)
xp[j].LoopHole() = MulModPrecon(rep(ap[j]), bb, p, bpinv);
}
}
}
示例4: kernel
void kernel(mat_zz_p& X, const mat_zz_p& A)
{
long m = A.NumRows();
long n = A.NumCols();
mat_zz_p M;
long r;
transpose(M, A);
r = gauss(M);
X.SetDims(m-r, m);
long i, j, k, s;
zz_p t1, t2;
vec_long D;
D.SetLength(m);
for (j = 0; j < m; j++) D[j] = -1;
vec_zz_p inverses;
inverses.SetLength(m);
j = -1;
for (i = 0; i < r; i++) {
do {
j++;
} while (IsZero(M[i][j]));
D[j] = i;
inv(inverses[j], M[i][j]);
}
for (k = 0; k < m-r; k++) {
vec_zz_p& v = X[k];
long pos = 0;
for (j = m-1; j >= 0; j--) {
if (D[j] == -1) {
if (pos == k)
set(v[j]);
else
clear(v[j]);
pos++;
}
else {
i = D[j];
clear(t1);
for (s = j+1; s < m; s++) {
mul(t2, v[s], M[i][s]);
add(t1, t1, t2);
}
mul(t1, t1, inverses[j]);
negate(v[j], t1);
}
}
}
}
示例5: 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;
}
}
}
示例6: negate
void negate(mat_zz_p& X, const mat_zz_p& A)
{
long n = A.NumRows();
long m = A.NumCols();
X.SetDims(n, m);
long i, j;
for (i = 1; i <= n; i++)
for (j = 1; j <= m; j++)
negate(X(i,j), A(i,j));
}
示例7: cvt
void cvt(mat_GF2& x, const mat_zz_p& a)
{
long n = a.NumRows();
long m = a.NumCols();
x.SetDims(n, m);
long i, j;
for (i = 0; i < n; i++)
for (j = 0; j < m; j++)
x.put(i, j, rep(a[i][j]));
}
示例8: sub
void sub(mat_zz_p& X, const mat_zz_p& A, const mat_zz_p& B)
{
long n = A.NumRows();
long m = A.NumCols();
if (B.NumRows() != n || B.NumCols() != m)
LogicError("matrix sub: dimension mismatch");
X.SetDims(n, m);
long i, j;
for (i = 1; i <= n; i++)
for (j = 1; j <= m; j++)
sub(X(i,j), A(i,j), B(i,j));
}
示例9: clear
void clear(mat_zz_p& x)
{
long n = x.NumRows();
long i;
for (i = 0; i < n; i++)
clear(x[i]);
}
示例10: IsDiag
long IsDiag(const mat_zz_p& A, long n, zz_p d)
{
if (A.NumRows() != n || A.NumCols() != n)
return 0;
long i, j;
for (i = 1; i <= n; i++)
for (j = 1; j <= n; j++)
if (i != j) {
if (!IsZero(A(i, j))) return 0;
}
else {
if (A(i, j) != d) return 0;
}
return 1;
}
示例11: conv
void conv(mat_zz_p& x, const mat_ZZ& a)
{
long n = a.NumRows();
long m = a.NumCols();
long i;
x.SetDims(n, m);
for (i = 0; i < n; i++)
conv(x[i], a[i]);
}
示例12: IsZero
long IsZero(const mat_zz_p& a)
{
long n = a.NumRows();
long i;
for (i = 0; i < n; i++)
if (!IsZero(a[i]))
return 0;
return 1;
}
示例13: diag
void diag(mat_zz_p& X, long n, zz_p d)
{
X.SetDims(n, n);
long i, j;
for (i = 1; i <= n; i++)
for (j = 1; j <= n; j++)
if (i == j)
X(i, j) = d;
else
clear(X(i, j));
}
示例14: random
NTL_CLIENT
void random(mat_zz_p& X, long n, long m)
{
X.SetDims(n, m);
long i, j;
for (i = 0; i < n; i++)
for (j = 0; j < m; j++)
random(X[i][j]);
}
示例15: ident
void ident(mat_zz_p& X, long n)
{
X.SetDims(n, n);
long i, j;
for (i = 1; i <= n; i++)
for (j = 1; j <= n; j++)
if (i == j)
set(X(i, j));
else
clear(X(i, j));
}