本文整理汇总了C++中mat_zz_pE::NumRows方法的典型用法代码示例。如果您正苦于以下问题:C++ mat_zz_pE::NumRows方法的具体用法?C++ mat_zz_pE::NumRows怎么用?C++ mat_zz_pE::NumRows使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mat_zz_pE
的用法示例。
在下文中一共展示了mat_zz_pE::NumRows方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: gauss
long gauss(mat_zz_pE& M_in, long w)
{
long k, l;
long i, j;
long pos;
zz_pX t1, t2, t3;
zz_pX *x, *y;
long n = M_in.NumRows();
long m = M_in.NumCols();
if (w < 0 || w > m)
LogicError("gauss: bad args");
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(m);
for (j = 0; j < m; j++) {
M[i][j].rep.SetMaxLength(2*deg(p)-1);
M[i][j] = rep(M_in[i][j]);
}
}
l = 0;
for (k = 0; k < w && l < n; k++) {
pos = -1;
for (i = l; i < n; i++) {
rem(t1, M[i][k], p);
M[i][k] = t1;
if (pos == -1 && !IsZero(t1)) {
pos = i;
}
}
if (pos != -1) {
swap(M[pos], M[l]);
InvMod(t3, M[l][k], p);
negate(t3, t3);
for (j = k+1; j < m; j++) {
rem(M[l][j], M[l][j], p);
}
for (i = l+1; i < n; i++) {
// M[i] = M[i] + M[l]*M[i,k]*t3
MulMod(t1, M[i][k], t3, p);
clear(M[i][k]);
x = M[i].elts() + (k+1);
y = M[l].elts() + (k+1);
for (j = k+1; j < m; j++, x++, y++) {
// *x = *x + (*y)*t1
mul(t2, *y, t1);
add(t2, t2, *x);
*x = t2;
}
}
l++;
}
}
for (i = 0; i < n; i++)
for (j = 0; j < m; j++)
conv(M_in[i][j], M[i][j]);
return l;
}
示例2: 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)
LogicError("determinant: nonsquare matrix");
if (n == 0) {
set(d);
return;
}
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);
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);
return;
}
}
conv(d, det);
}
示例3: inv
void inv(zz_pE& d, mat_zz_pE& X, const mat_zz_pE& A)
{
long n = A.NumRows();
if (A.NumCols() != n)
LogicError("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();
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(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);
return;
}
}
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);
//.........这里部分代码省略.........
示例4: ppsolve
// prime power solver
// zz_p::modulus() is assumed to be p^r, for p prime, r >= 1
// A is an n x n matrix, b is a length n (row) vector,
// and a solution for the matrix-vector equation x A = b is found.
// If A is not inverible mod p, then error is raised.
void ppsolve(vec_zz_pE& x, const mat_zz_pE& A, const vec_zz_pE& b,
long p, long r)
{
if (r == 1) {
zz_pE det;
solve(det, x, A, b);
if (det == 0) Error("ppsolve: matrix not invertible");
return;
}
long n = A.NumRows();
if (n != A.NumCols())
Error("ppsolve: matrix not square");
if (n == 0)
Error("ppsolve: matrix of dimension 0");
zz_pContext pr_context;
pr_context.save();
zz_pEContext prE_context;
prE_context.save();
zz_pX G = zz_pE::modulus();
ZZX GG = to_ZZX(G);
vector< vector<ZZX> > AA;
convert(AA, A);
vector<ZZX> bb;
convert(bb, b);
zz_pContext p_context(p);
p_context.restore();
zz_pX G1 = to_zz_pX(GG);
zz_pEContext pE_context(G1);
pE_context.restore();
// we are now working mod p...
// invert A mod p
mat_zz_pE A1;
convert(A1, AA);
mat_zz_pE I1;
zz_pE det;
inv(det, I1, A1);
if (det == 0) {
Error("ppsolve: matrix not invertible");
}
vec_zz_pE b1;
convert(b1, bb);
vec_zz_pE y1;
y1 = b1 * I1;
vector<ZZX> yy;
convert(yy, y1);
// yy is a solution mod p
for (long k = 1; k < r; k++) {
// lift solution yy mod p^k to a solution mod p^{k+1}
pr_context.restore();
prE_context.restore();
// we are now working mod p^r
vec_zz_pE d, y;
convert(y, yy);
d = b - y * A;
vector<ZZX> dd;
convert(dd, d);
long pk = power_long(p, k);
vector<ZZX> ee;
div(ee, dd, pk);
p_context.restore();
pE_context.restore();
// we are now working mod p
vec_zz_pE e1;
convert(e1, ee);
vec_zz_pE z1;
z1 = e1 * I1;
//.........这里部分代码省略.........