本文整理汇总了C++中mat_zz_p::SetDims方法的典型用法代码示例。如果您正苦于以下问题:C++ mat_zz_p::SetDims方法的具体用法?C++ mat_zz_p::SetDims怎么用?C++ mat_zz_p::SetDims使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mat_zz_p
的用法示例。
在下文中一共展示了mat_zz_p::SetDims方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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);
}
}
示例2: 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);
}
}
}
}
示例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: 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]);
}
示例5: 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]);
}
示例6: 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));
}
示例7: 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));
}
示例8: 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));
}
示例9: 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));
}
示例10: inv
void inv(zz_p& d, mat_zz_p& X, const mat_zz_p& 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_p t1, t2, t3;
zz_p *x, *y;
mat_zz_p M;
M.SetDims(n, 2*n);
for (i = 0; i < n; i++) {
for (j = 0; j < n; j++) {
M[i][j] = A[i][j];
clear(M[i][n+j]);
}
set(M[i][n+i]);
}
zz_p det;
set(det);
long p = zz_p::modulus();
mulmod_t pinv = zz_p::ModulusInverse();
for (k = 0; k < n; k++) {
pos = -1;
for (i = k; i < n; i++) {
if (!IsZero(M[i][k])) {
pos = i;
break;
}
}
if (pos != -1) {
if (k != pos) {
swap(M[pos], M[k]);
negate(det, det);
}
mul(det, det, M[k][k]);
inv(t3, M[k][k]);
M[k][k] = t3;
for (i = k+1; i < n; i++) {
// M[i] = M[i] - M[k]*M[i,k]*t3
mul(t1, M[i][k], t3);
negate(t1, t1);
x = M[i].elts() + (k+1);
y = M[k].elts() + (k+1);
long T1 = rep(t1);
mulmod_precon_t t1pinv = PrepMulModPrecon(T1, p, pinv); // T1*pinv;
long T2;
for (j = k+1; j < 2*n; j++, x++, y++) {
// *x = *x + (*y)*t1
T2 = MulModPrecon(rep(*y), T1, p, t1pinv);
x->LoopHole() = AddMod(rep(*x), T2, p);
}
}
}
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, X[j][k], M[i][j]);
add(t1, t1, t2);
}
sub(t1, M[i][n+k], t1);
mul(X[i][k], t1, M[i][i]);
}
}
d = det;
}
示例11: mul_aux
static
void mul_aux(mat_zz_p& X, const mat_zz_p& A, const mat_zz_p& B)
{
long n = A.NumRows();
long l = A.NumCols();
long m = B.NumCols();
if (l != B.NumRows())
LogicError("matrix mul: dimension mismatch");
X.SetDims(n, m);
if (m > 1) { // new preconditioning code
long p = zz_p::modulus();
mulmod_t pinv = zz_p::ModulusInverse();
vec_long::Watcher watch_mul_aux_vec(mul_aux_vec);
mul_aux_vec.SetLength(m);
long *acc = mul_aux_vec.elts();
long i, j, k;
for (i = 0; i < n; i++) {
const zz_p* ap = A[i].elts();
for (j = 0; j < m; j++) acc[j] = 0;
for (k = 0; k < l; k++) {
long aa = rep(ap[k]);
if (aa != 0) {
const zz_p* bp = B[k].elts();
long T1;
mulmod_precon_t aapinv = PrepMulModPrecon(aa, p, pinv);
for (j = 0; j < m; j++) {
T1 = MulModPrecon(rep(bp[j]), aa, p, aapinv);
acc[j] = AddMod(acc[j], T1, p);
}
}
}
zz_p *xp = X[i].elts();
for (j = 0; j < m; j++)
xp[j].LoopHole() = acc[j];
}
}
else { // just use the old code, w/o preconditioning
long p = zz_p::modulus();
mulmod_t pinv = zz_p::ModulusInverse();
long i, j, k;
long acc, tmp;
for (i = 1; i <= n; i++) {
for (j = 1; j <= m; j++) {
acc = 0;
for(k = 1; k <= l; k++) {
tmp = MulMod(rep(A(i,k)), rep(B(k,j)), p, pinv);
acc = AddMod(acc, tmp, p);
}
X(i,j).LoopHole() = acc;
}
}
}
}