本文整理汇总了C++中mat_ZZ_pE类的典型用法代码示例。如果您正苦于以下问题:C++ mat_ZZ_pE类的具体用法?C++ mat_ZZ_pE怎么用?C++ mat_ZZ_pE使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了mat_ZZ_pE类的17个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: mul_aux
void mul_aux(mat_ZZ_pE& X, const mat_ZZ_pE& A, const mat_ZZ_pE& 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);
long i, j, k;
ZZ_pX acc, tmp;
for (i = 1; i <= n; i++) {
for (j = 1; j <= m; j++) {
clear(acc);
for(k = 1; k <= l; k++) {
mul(tmp, rep(A(i,k)), rep(B(k,j)));
add(acc, acc, tmp);
}
conv(X(i,j), acc);
}
}
}
开发者ID:av-elier,项目名称:fast-exponentiation-algs,代码行数:25,代码来源:mat_ZZ_pE.c
示例2: power
void power(mat_ZZ_pE& X, const mat_ZZ_pE& A, const ZZ& e)
{
if (A.NumRows() != A.NumCols()) Error("power: non-square matrix");
if (e == 0) {
ident(X, A.NumRows());
return;
}
mat_ZZ_pE 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;
}
开发者ID:av-elier,项目名称:fast-exponentiation-algs,代码行数:28,代码来源:mat_ZZ_pE.c
示例3: transpose
void transpose(mat_ZZ_pE& X, const mat_ZZ_pE& 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_pE 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);
}
}
开发者ID:av-elier,项目名称:fast-exponentiation-algs,代码行数:29,代码来源:mat_ZZ_pE.c
示例4: negate
void negate(mat_ZZ_pE& X, const mat_ZZ_pE& 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));
}
开发者ID:av-elier,项目名称:fast-exponentiation-algs,代码行数:13,代码来源:mat_ZZ_pE.c
示例5: mul
void mul(mat_ZZ_pE& X, const mat_ZZ_pE& A, const ZZ_pE& b_in)
{
ZZ_pE b = b_in;
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++)
mul(X[i][j], A[i][j], b);
}
开发者ID:av-elier,项目名称:fast-exponentiation-algs,代码行数:13,代码来源:mat_ZZ_pE.c
示例6: sub
void sub(mat_ZZ_pE& X, const mat_ZZ_pE& A, const mat_ZZ_pE& B)
{
long n = A.NumRows();
long m = A.NumCols();
if (B.NumRows() != n || B.NumCols() != m)
Error("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));
}
开发者ID:av-elier,项目名称:fast-exponentiation-algs,代码行数:15,代码来源:mat_ZZ_pE.c
示例7: clear
void clear(mat_ZZ_pE& x)
{
long n = x.NumRows();
long i;
for (i = 0; i < n; i++)
clear(x[i]);
}
开发者ID:av-elier,项目名称:fast-exponentiation-algs,代码行数:7,代码来源:mat_ZZ_pE.c
示例8: IsDiag
long IsDiag(const mat_ZZ_pE& A, long n, const ZZ_pE& 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;
}
开发者ID:av-elier,项目名称:fast-exponentiation-algs,代码行数:18,代码来源:mat_ZZ_pE.c
示例9: add
NTL_START_IMPL
void add(mat_ZZ_pE& X, const mat_ZZ_pE& A, const mat_ZZ_pE& B)
{
long n = A.NumRows();
long m = A.NumCols();
if (B.NumRows() != n || B.NumCols() != m)
LogicError("matrix add: dimension mismatch");
X.SetDims(n, m);
long i, j;
for (i = 1; i <= n; i++)
for (j = 1; j <= m; j++)
add(X(i,j), A(i,j), B(i,j));
}
开发者ID:kenjinote,项目名称:NTLSample,代码行数:18,代码来源:mat_ZZ_pE.cpp
示例10: IsZero
long IsZero(const mat_ZZ_pE& a)
{
long n = a.NumRows();
long i;
for (i = 0; i < n; i++)
if (!IsZero(a[i]))
return 0;
return 1;
}
开发者ID:av-elier,项目名称:fast-exponentiation-algs,代码行数:11,代码来源:mat_ZZ_pE.c
示例11: ident
void ident(mat_ZZ_pE& 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));
}
开发者ID:av-elier,项目名称:fast-exponentiation-algs,代码行数:12,代码来源:mat_ZZ_pE.c
示例12: diag
void diag(mat_ZZ_pE& X, long n, const ZZ_pE& d_in)
{
ZZ_pE d = d_in;
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));
}
开发者ID:av-elier,项目名称:fast-exponentiation-algs,代码行数:13,代码来源:mat_ZZ_pE.c
示例13: inv
void inv(ZZ_pE& d, mat_ZZ_pE& X, const mat_ZZ_pE& A)
{
long n = A.NumRows();
if (A.NumCols() != n)
Error("inv: nonsquare matrix");
if (n == 0) {
set(d);
X.SetDims(0, 0);
return;
}
long i, j, k, pos;
ZZ_pX t1, t2;
ZZ_pX *x, *y;
const ZZ_pXModulus& p = ZZ_pE::modulus();
vec_ZZ_pX *M = NTL_NEW_OP vec_ZZ_pX[n];
for (i = 0; i < n; i++) {
M[i].SetLength(2*n);
for (j = 0; j < n; j++) {
M[i][j].rep.SetMaxLength(2*deg(p)-1);
M[i][j] = rep(A[i][j]);
M[i][n+j].rep.SetMaxLength(2*deg(p)-1);
clear(M[i][n+j]);
}
set(M[i][n+i]);
}
ZZ_pX det;
set(det);
for (k = 0; k < n; k++) {
pos = -1;
for (i = k; i < n; i++) {
rem(t1, M[i][k], p);
M[i][k] = t1;
if (pos == -1 && !IsZero(t1)) {
pos = i;
}
}
if (pos != -1) {
if (k != pos) {
swap(M[pos], M[k]);
negate(det, det);
}
MulMod(det, det, M[k][k], p);
// make M[k, k] == -1 mod p, and make row k reduced
InvMod(t1, M[k][k], p);
negate(t1, t1);
for (j = k+1; j < 2*n; j++) {
rem(t2, M[k][j], p);
MulMod(M[k][j], t2, t1, p);
}
for (i = k+1; i < n; i++) {
// M[i] = M[i] + M[k]*M[i,k]
t1 = M[i][k]; // this is already reduced
x = M[i].elts() + (k+1);
y = M[k].elts() + (k+1);
for (j = k+1; j < 2*n; j++, x++, y++) {
// *x = *x + (*y)*t1
mul(t2, *y, t1);
add(*x, *x, t2);
}
}
}
else {
clear(d);
goto done;
}
}
X.SetDims(n, n);
for (k = 0; k < n; k++) {
for (i = n-1; i >= 0; i--) {
clear(t1);
for (j = i+1; j < n; j++) {
mul(t2, rep(X[j][k]), M[i][j]);
add(t1, t1, t2);
}
sub(t1, t1, M[i][n+k]);
conv(X[i][k], t1);
}
}
conv(d, det);
done:
//.........这里部分代码省略.........
开发者ID:av-elier,项目名称:fast-exponentiation-algs,代码行数:101,代码来源:mat_ZZ_pE.c
示例14: gauss
long gauss(mat_ZZ_pE& M)
{
return gauss(M, M.NumCols());
}
开发者ID:av-elier,项目名称:fast-exponentiation-algs,代码行数:4,代码来源:mat_ZZ_pE.c
示例15: determinant
void determinant(ZZ_pE& d, const mat_ZZ_pE& M_in)
{
long k, n;
long i, j;
long pos;
ZZ_pX t1, t2;
ZZ_pX *x, *y;
const ZZ_pXModulus& p = ZZ_pE::modulus();
n = M_in.NumRows();
if (M_in.NumCols() != n)
Error("determinant: nonsquare matrix");
if (n == 0) {
set(d);
return;
}
vec_ZZ_pX *M = NTL_NEW_OP vec_ZZ_pX[n];
for (i = 0; i < n; i++) {
M[i].SetLength(n);
for (j = 0; j < n; j++) {
M[i][j].rep.SetMaxLength(2*deg(p)-1);
M[i][j] = rep(M_in[i][j]);
}
}
ZZ_pX det;
set(det);
for (k = 0; k < n; k++) {
pos = -1;
for (i = k; i < n; i++) {
rem(t1, M[i][k], p);
M[i][k] = t1;
if (pos == -1 && !IsZero(t1))
pos = i;
}
if (pos != -1) {
if (k != pos) {
swap(M[pos], M[k]);
negate(det, det);
}
MulMod(det, det, M[k][k], p);
// make M[k, k] == -1 mod p, and make row k reduced
InvMod(t1, M[k][k], p);
negate(t1, t1);
for (j = k+1; j < n; j++) {
rem(t2, M[k][j], p);
MulMod(M[k][j], t2, t1, p);
}
for (i = k+1; i < n; i++) {
// M[i] = M[i] + M[k]*M[i,k]
t1 = M[i][k]; // this is already reduced
x = M[i].elts() + (k+1);
y = M[k].elts() + (k+1);
for (j = k+1; j < n; j++, x++, y++) {
// *x = *x + (*y)*t1
mul(t2, *y, t1);
add(*x, *x, t2);
}
}
}
else {
clear(d);
goto done;
}
}
conv(d, det);
done:
delete[] M;
}
开发者ID:av-elier,项目名称:fast-exponentiation-algs,代码行数:86,代码来源:mat_ZZ_pE.c
示例16: kernel
void kernel(mat_ZZ_pE& X, const mat_ZZ_pE& A)
{
long m = A.NumRows();
long n = A.NumCols();
mat_ZZ_pE M;
long r;
transpose(M, A);
r = gauss(M);
X.SetDims(m-r, m);
long i, j, k, s;
ZZ_pX t1, t2;
ZZ_pE T3;
vec_long D;
D.SetLength(m);
for (j = 0; j < m; j++) D[j] = -1;
vec_ZZ_pE 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_pE& 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, rep(v[s]), rep(M[i][s]));
add(t1, t1, t2);
}
conv(T3, t1);
mul(T3, T3, inverses[j]);
negate(v[j], T3);
}
}
}
}
开发者ID:av-elier,项目名称:fast-exponentiation-algs,代码行数:63,代码来源:mat_ZZ_pE.c
示例17: solve_impl
static
void solve_impl(ZZ_pE& d, vec_ZZ_pE& X, const mat_ZZ_pE& A, const vec_ZZ_pE& b, bool trans)
{
long n = A.NumRows();
if (A.NumCols() != n)
LogicError("solve: nonsquare matrix");
if (b.length() != n)
LogicError("solve: dimension mismatch");
if (n == 0) {
set(d);
X.SetLength(0);
return;
}
long i, j, k, pos;
ZZ_pX t1, t2;
ZZ_pX *x, *y;
const ZZ_pXModulus& p = ZZ_pE::modulus();
UniqueArray<vec_ZZ_pX> M_store;
M_store.SetLength(n);
vec_ZZ_pX *M = M_store.get();
for (i = 0; i < n; i++) {
M[i].SetLength(n+1);
if (trans) {
for (j = 0; j < n; j++) {
M[i][j].rep.SetMaxLength(2*deg(p)-1);
M[i][j] = rep(A[j][i]);
}
}
else {
for (j = 0; j < n; j++) {
M[i][j].rep.SetMaxLength(2*deg(p)-1);
M[i][j] = rep(A[i][j]);
}
}
M[i][n].rep.SetMaxLength(2*deg(p)-1);
M[i][n] = rep(b[i]);
}
ZZ_pX det;
set(det);
for (k = 0; k < n; k++) {
pos = -1;
for (i = k; i < n; i++) {
rem(t1, M[i][k], p);
M[i][k] = t1;
if (pos == -1 && !IsZero(t1)) {
pos = i;
}
}
if (pos != -1) {
if (k != pos) {
swap(M[pos], M[k]);
negate(det, det);
}
MulMod(det, det, M[k][k], p);
// make M[k, k] == -1 mod p, and make row k reduced
InvMod(t1, M[k][k], p);
negate(t1, t1);
for (j = k+1; j <= n; j++) {
rem(t2, M[k][j], p);
MulMod(M[k][j], t2, t1, p);
}
for (i = k+1; i < n; i++) {
// M[i] = M[i] + M[k]*M[i,k]
t1 = M[i][k]; // this is already reduced
x = M[i].elts() + (k+1);
y = M[k].elts() + (k+1);
for (j = k+1; j <= n; j++, x++, y++) {
// *x = *x + (*y)*t1
mul(t2, *y, t1);
add(*x, *x, t2);
}
}
}
else {
clear(d);
return;
}
}
X.SetLength(n);
for (i = n-1; i >= 0; i--) {
clear(t1);
//.........这里部分代码省略.........
开发者ID:kenjinote,项目名称:NTLSample,代码行数:101,代码来源:mat_ZZ_pE.cpp
注:本文中的mat_ZZ_pE类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论