本文整理汇总了C++中mat_ZZ_p::NumRows方法的典型用法代码示例。如果您正苦于以下问题:C++ mat_ZZ_p::NumRows方法的具体用法?C++ mat_ZZ_p::NumRows怎么用?C++ mat_ZZ_p::NumRows使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mat_ZZ_p
的用法示例。
在下文中一共展示了mat_ZZ_p::NumRows方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: mul_aux
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())
Error("matrix mul: dimension mismatch");
X.SetDims(n, m);
long i, j, k;
ZZ 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);
}
}
}
示例2: power
void power(mat_ZZ_p& X, const mat_ZZ_p& A, const ZZ& e)
{
if (A.NumRows() != A.NumCols()) Error("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;
}
示例3: mul
void mul(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");
if (NTL_USE_MM_MATMUL && n >= 24 && l >= 24 && m >= 24)
multi_modular_mul(X, A, B);
else
plain_mul(X, A, B);
}
示例4: 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)
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));
}
示例5: 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);
}
}
示例6: clear
void clear(mat_ZZ_p& x)
{
long n = x.NumRows();
long i;
for (i = 0; i < n; i++)
clear(x[i]);
}
示例7: to_mat_ZZ_p_crt_rep
void to_mat_ZZ_p_crt_rep(mat_ZZ_p_crt_rep& X, const mat_ZZ_p& A)
{
long n = A.NumRows();
long m = A.NumCols();
const MatPrime_crt_helper& H = get_MatPrime_crt_helper_info();
long nprimes = H.GetNumPrimes();
if (NTL_OVERFLOW(nprimes, CRT_BLK, 0))
ResourceError("overflow"); // this is pretty academic
X.rep.SetLength(nprimes);
for (long k = 0; k < nprimes; k++) X.rep[k].SetDims(n, m);
ZZ_pContext context;
context.save();
bool seq = (double(n)*double(m)*H.GetCost() < PAR_THRESH);
// FIXME: right now, we just partition the rows, but if
// #cols > #rows, we should perhaps partition the cols
NTL_GEXEC_RANGE(seq, n, first, last)
NTL_IMPORT(n)
NTL_IMPORT(m)
NTL_IMPORT(nprimes)
context.restore();
MatPrime_crt_helper_scratch scratch;
Vec<MatPrime_residue_t> remainders_store;
remainders_store.SetLength(nprimes*CRT_BLK);
MatPrime_residue_t *remainders = remainders_store.elts();
for (long i = first; i < last; i++) {
const ZZ_p *a = A[i].elts();
long jj = 0;
for (; jj <= m-CRT_BLK; jj += CRT_BLK) {
for (long j = 0; j < CRT_BLK; j++)
reduce(H, rep(a[jj+j]), remainders + j*nprimes, scratch);
for (long k = 0; k < nprimes; k++) {
MatPrime_residue_t *x = X.rep[k][i].elts();
for (long j = 0; j < CRT_BLK; j++)
x[jj+j] = remainders[j*nprimes+k];
}
}
if (jj < m) {
for (long j = 0; j < m-jj; j++)
reduce(H, rep(a[jj+j]), remainders + j*nprimes, scratch);
for (long k = 0; k < nprimes; k++) {
MatPrime_residue_t *x = X.rep[k][i].elts();
for (long j = 0; j < m-jj; j++)
x[jj+j] = remainders[j*nprimes+k];
}
}
}
NTL_GEXEC_RANGE_END
}
示例8: add
NTL_START_IMPL
void add(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 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));
}
示例9: plain_mul_transpose_aux
void plain_mul_transpose_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.NumRows();
if (l != B.NumCols())
LogicError("matrix mul: dimension mismatch");
X.SetDims(n, m);
ZZ_pContext context;
context.save();
long sz = ZZ_p::ModulusSize();
bool seq = (double(n)*double(l)*double(m)*double(sz)*double(sz) < PAR_THRESH);
NTL_GEXEC_RANGE(seq, m, first, last)
NTL_IMPORT(n)
NTL_IMPORT(l)
NTL_IMPORT(m)
context.restore();
long i, j, k;
ZZ acc, tmp;
for (j = first; j < last; j++) {
const ZZ_p *B_col = B[j].elts();
for (i = 0; i < n; i++) {
clear(acc);
for (k = 0; k < l; k++) {
mul(tmp, rep(A[i][k]), rep(B_col[k]));
add(acc, acc, tmp);
}
conv(X[i][j], acc);
}
}
NTL_GEXEC_RANGE_END
}
示例10: 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;
}
示例11: 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));
}
示例12: mul
void mul(mat_ZZ_p& X, const mat_ZZ_p& A, long b_in)
{
NTL_ZZ_pRegister(b);
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);
}
示例13: multi_modular_mul
void multi_modular_mul(mat_ZZ_p& X, const mat_ZZ_p& A, const mat_ZZ_p& B)
{
long l = A.NumCols();
if (l != B.NumRows())
LogicError("matrix mul: dimension mismatch");
if (l > NTL_MatPrimeLimit)
ResourceError("matrix mul: dimension too large");
mat_ZZ_p_crt_rep x, a, b;
to_mat_ZZ_p_crt_rep(a, A);
to_mat_ZZ_p_crt_rep(b, B);
mul(x, a, b);
from_mat_ZZ_p_crt_rep(x, X);
}
示例14: IsDiag
long IsDiag(const mat_ZZ_p& A, long n, const 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;
}
示例15: IsIdent
long IsIdent(const mat_ZZ_p& A, long n)
{
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 (!IsOne(A(i, j))) return 0;
}
return 1;
}