本文整理汇总了C++中mat_GF2类的典型用法代码示例。如果您正苦于以下问题:C++ mat_GF2类的具体用法?C++ mat_GF2怎么用?C++ mat_GF2使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了mat_GF2类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: mul_aux
static
void mul_aux(vec_GF2& x, const vec_GF2& a, const mat_GF2& B)
{
long n = B.NumRows();
long l = B.NumCols();
if (n != a.length())
Error("matrix mul: dimension mismatch");
x.SetLength(l);
clear(x);
const _ntl_ulong *ap = a.rep.elts();
_ntl_ulong a_mask = 1;
_ntl_ulong *xp = x.rep.elts();
long lw = (l + NTL_BITS_PER_LONG - 1)/NTL_BITS_PER_LONG;
long i;
for (i = 0; i < n; i++) {
if (*ap & a_mask) {
const _ntl_ulong *bp = B[i].rep.elts();
long j;
for (j = 0; j < lw; j++)
xp[j] ^= bp[j];
}
a_mask <<= 1;
if (!a_mask) {
a_mask = 1;
ap++;
}
}
}
开发者ID:Macaulay2,项目名称:Singular,代码行数:35,代码来源:mat_GF2.c
示例2: power
void power(mat_GF2& X, const mat_GF2& A, const ZZ& e)
{
if (A.NumRows() != A.NumCols()) Error("power: non-square matrix");
if (e == 0) {
ident(X, A.NumRows());
return;
}
mat_GF2 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:Macaulay2,项目名称:Singular,代码行数:28,代码来源:mat_GF2.c
示例3: AddToCol
void AddToCol(mat_GF2& x, long j, const vec_GF2& a)
// add a to column j of x
// ALIAS RESTRICTION: a should not alias any row of x
{
long n = x.NumRows();
long m = x.NumCols();
if (a.length() != n || j < 0 || j >= m)
Error("AddToCol: bad args");
long wj = j/NTL_BITS_PER_LONG;
long bj = j - wj*NTL_BITS_PER_LONG;
_ntl_ulong j_mask = 1UL << bj;
const _ntl_ulong *ap = a.rep.elts();
_ntl_ulong a_mask = 1;
long i;
for (i = 0; i < n; i++) {
if (*ap & a_mask)
x[i].rep.elts()[wj] ^= j_mask;
a_mask <<= 1;
if (!a_mask) {
a_mask = 1;
ap++;
}
}
}
开发者ID:Macaulay2,项目名称:Singular,代码行数:29,代码来源:mat_GF2.c
示例4: ident
void ident(mat_GF2& X, long n)
{
X.SetDims(n, n);
clear(X);
long i;
for (i = 0; i < n; i++)
X.put(i, i, to_GF2(1));
}
开发者ID:Macaulay2,项目名称:Singular,代码行数:9,代码来源:mat_GF2.c
示例5: SetDims
NTL_START_IMPL
mat_GF2::mat_GF2(const mat_GF2& a)
{
_mat_GF2__numcols = 0;
SetDims(a.NumRows(), a.NumCols());
_mat_GF2__rep = a._mat_GF2__rep;
}
开发者ID:JamesHirschorn,项目名称:QFCL,代码行数:9,代码来源:mat_GF2.cpp
示例6: initMatrix
/**
* Initializes matrix from specified array.
* Data must be at least dimension of given matrix.
*/
int initMatrix(mat_GF2& M, long *data){
long i,j,n,m;
for(i=0, n=M.NumRows(); i<n; i++){
for(j=0, m=M.NumCols(); j<m; j++){
M.put(i,j,data[n*i+j]);
}
}
return 0;
}
开发者ID:Lulongping,项目名称:Whitebox-crypto-AES,代码行数:14,代码来源:NTLUtils.cpp
示例7: IsDiag
long IsDiag(const mat_GF2& A, long n, GF2 d)
{
if (A.NumRows() != n || A.NumCols() != n)
return 0;
if (d == 1)
return IsIdent(A, n);
else
return IsZero(A);
}
开发者ID:Macaulay2,项目名称:Singular,代码行数:10,代码来源:mat_GF2.c
示例8: transpose_aux
void transpose_aux(mat_GF2& X, const mat_GF2& A)
{
long n = A.NumRows();
long m = A.NumCols();
X.SetDims(m, n);
clear(X);
long i;
for (i = 0; i < n; i++)
AddToCol(X, i, A[i]);
}
开发者ID:Macaulay2,项目名称:Singular,代码行数:12,代码来源:mat_GF2.c
示例9: gauss
long gauss(mat_GF2& M, long w)
{
long k, l;
long i, j;
long pos;
long n = M.NumRows();
long m = M.NumCols();
if (w < 0 || w > m)
Error("gauss: bad args");
long wm = (m + NTL_BITS_PER_LONG - 1)/NTL_BITS_PER_LONG;
l = 0;
for (k = 0; k < w && l < n; k++) {
long wk = k/NTL_BITS_PER_LONG;
long bk = k - wk*NTL_BITS_PER_LONG;
_ntl_ulong k_mask = 1UL << bk;
pos = -1;
for (i = l; i < n; i++) {
if (M[i].rep.elts()[wk] & k_mask) {
pos = i;
break;
}
}
if (pos != -1) {
if (l != pos)
swap(M[pos], M[l]);
_ntl_ulong *y = M[l].rep.elts();
for (i = l+1; i < n; i++) {
// M[i] = M[i] + M[l]*M[i,k]
if (M[i].rep.elts()[wk] & k_mask) {
_ntl_ulong *x = M[i].rep.elts();
for (j = wk; j < wm; j++)
x[j] ^= y[j];
}
}
l++;
}
}
return l;
}
开发者ID:Macaulay2,项目名称:Singular,代码行数:52,代码来源:mat_GF2.c
示例10: 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]));
}
开发者ID:tell,项目名称:ntl-unix,代码行数:13,代码来源:BitMatTest.cpp
示例11: swap
vec_GF2 GF2MatrixUtils::solve(mat_GF2 A, vec_GF2 b) {
uint32_t nextRow = 0;
for (uint32_t j =0; j < A.NumCols(); j++) {
uint32_t i;
for (i=nextRow; i < A.NumRows(); i++) {
if (A[i][j] == 1) {
break;
}
}
if (i==A.NumRows()) {
continue;
}
if (A[i][j] == 1) {
if (nextRow !=i) {
swap(A[nextRow],A[i]);
swap(b[nextRow],b[i]);
}
for (uint32_t k=nextRow+1; k < A.NumRows(); k++) {
if (A[k][j] == 1) {
A[k] = A[k] + A[nextRow];
b[k] = b[k] + b[nextRow];
}
}
nextRow++;
}
}
vec_GF2 sol;
sol.SetLength(A.NumCols(), GF2(0));
int32_t lastRow=A.NumRows()-1;
while (A[lastRow][A.NumCols()-1]==0) {
if ((A[lastRow]*sol) != b[lastRow]) {
throw(system_error());
}
lastRow--;
if (lastRow == -1) {
throw(system_error());
}
}
for (int32_t j=A.NumCols()-1; j >= 0; j--) {
if (lastRow == -1) {
throw(system_error());
}
if (A[lastRow][j]==0) {
continue;
}
if ((A[lastRow]*sol) != b[lastRow]) {
sol[j]=1;
}
lastRow--;
}
return sol;
}
开发者ID:cryptobiu,项目名称:MultiPartyPSI,代码行数:60,代码来源:GF2MatrixUtils.cpp
示例12: IsIdent
long IsIdent(const mat_GF2& A, long n)
{
if (A.NumRows() != n || A.NumCols() != n)
return 0;
if (n == 0) return 1;
long i;
for (i = 0; i < n; i++)
if (!IsUnitVector(A[i], i))
return 0;
return 1;
}
开发者ID:Macaulay2,项目名称:Singular,代码行数:15,代码来源:mat_GF2.c
示例13: clear
void clear(mat_GF2& x)
{
long n = x.NumRows();
long i;
for (i = 0; i < n; i++)
clear(x[i]);
}
开发者ID:Macaulay2,项目名称:Singular,代码行数:7,代码来源:mat_GF2.c
示例14: kernel
void kernel(mat_GF2& X, const mat_GF2& A)
{
long m = A.NumRows();
long n = A.NumCols();
mat_GF2 M;
long r;
transpose(M, A);
r = gauss(M);
X.SetDims(m-r, m);
clear(X);
long i, j, k;
vec_long D;
D.SetLength(m);
for (j = 0; j < m; j++) D[j] = -1;
j = -1;
for (i = 0; i < r; i++) {
do {
j++;
} while (M.get(i, j) == 0);
D[j] = i;
}
for (k = 0; k < m-r; k++) {
vec_GF2& v = X[k];
long pos = 0;
for (j = m-1; j >= 0; j--) {
if (D[j] == -1) {
if (pos == k) {
v[j] = 1;
// v.put(j, to_GF2(1));
}
pos++;
}
else {
v[j] = v*M[D[j]];
// v.put(j, v*M[D[j]]);
}
}
}
}
开发者ID:Macaulay2,项目名称:Singular,代码行数:47,代码来源:mat_GF2.c
示例15:
long operator==(const mat_GF2& a, const mat_GF2& b)
{
if (a.NumCols() != b.NumCols())
return 0;
if (a.NumRows() != b.NumRows())
return 0;
long n = a.NumRows();
long i;
for (i = 0; i < n; i++)
if (a[i] != b[i])
return 0;
return 1;
}
开发者ID:JamesHirschorn,项目名称:QFCL,代码行数:17,代码来源:mat_GF2.cpp
示例16: diag
void diag(mat_GF2& X, long n, GF2 d)
{
if (d == 1)
ident(X, n);
else {
X.SetDims(n, n);
clear(X);
}
}
开发者ID:Macaulay2,项目名称:Singular,代码行数:9,代码来源:mat_GF2.c
示例17: mul
void mul(vec_GF2& x, const mat_GF2& A, const vec_GF2& b)
{
if (&b == &x || A.position1(x) != -1) {
vec_GF2 tmp;
mul_aux(tmp, A, b);
x = tmp;
}
else
mul_aux(x, A, b);
}
开发者ID:Macaulay2,项目名称:Singular,代码行数:10,代码来源:mat_GF2.c
示例18: IsZero
long IsZero(const mat_GF2& a)
{
long n = a.NumRows();
long i;
for (i = 0; i < n; i++)
if (!IsZero(a[i]))
return 0;
return 1;
}
开发者ID:Macaulay2,项目名称:Singular,代码行数:11,代码来源:mat_GF2.c
示例19: conv
void conv(mat_GF2& x, const vec_vec_GF2& a)
{
long n = a.length();
if (n == 0) {
x.SetDims(0, 0);
return;
}
long m = a[0].length();
long i;
for (i = 1; i < n; i++)
if (a[i].length() != m)
Error("nonrectangular matrix");
x.SetDims(n, m);
for (i = 0; i < n; i++)
x[i] = a[i];
}
开发者ID:JamesHirschorn,项目名称:QFCL,代码行数:20,代码来源:mat_GF2.cpp
示例20: add
void add(mat_GF2& X, const mat_GF2& A, const mat_GF2& B)
{
long n = A.NumRows();
long m = A.NumCols();
if (B.NumRows() != n || B.NumCols() != m)
Error("matrix add: dimension mismatch");
X.SetDims(n, m);
long mw = (m + NTL_BITS_PER_LONG - 1)/NTL_BITS_PER_LONG;
long i;
for (i = 0; i < n; i++) {
_ntl_ulong *xp = X[i].rep.elts();
const _ntl_ulong *ap = A[i].rep.elts();
const _ntl_ulong *bp = B[i].rep.elts();
long j;
for (j = 0; j < mw; j++)
xp[j] = ap[j] ^ bp[j];
}
}
开发者ID:Macaulay2,项目名称:Singular,代码行数:22,代码来源:mat_GF2.c
注:本文中的mat_GF2类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论