本文整理汇总了C++中mat_GF2::SetDims方法的典型用法代码示例。如果您正苦于以下问题:C++ mat_GF2::SetDims方法的具体用法?C++ mat_GF2::SetDims怎么用?C++ mat_GF2::SetDims使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mat_GF2
的用法示例。
在下文中一共展示了mat_GF2::SetDims方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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));
}
示例2: diag
void diag(mat_GF2& X, long n, GF2 d)
{
if (d == 1)
ident(X, n);
else {
X.SetDims(n, n);
clear(X);
}
}
示例3: 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];
}
示例4: 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]);
}
示例5: 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]));
}
示例6: 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]]);
}
}
}
}
示例7: mul_aux
void mul_aux(mat_GF2& X, const mat_GF2& A, const mat_GF2& 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;
for (i = 1; i <= n; i++) {
mul_aux(X(i), A(i), B);
}
}
示例8: 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];
}
}
示例9: checkInvertibleLinear
int LinearAffineEq::checkInvertibleLinear(const bset & Ua, const bset & Ub,
smap & mapA, smap & mapB,
bsetElem * S1, bsetElem * S1inv,
bsetElem * S2, bsetElem * S2inv,
mat_GF2 & Ta, mat_GF2 & Tb,
mat_GF2 & Tbinv, smap & mapBinv,
bool AisA){
// Extract linearly independent vectors, to determine mapping.
// We need matrix consisting of Avect to be invertible in order to determine
// matrix representation of transformation.
bset Avect = extractLinearlyIndependent(mapA);
if (verbosity) {
cout << "Size of linearly independent vectors: " << Avect.size() << endl;
LinearAffineEq::dumpSet(Avect);
}
// Derive matrix representation of transformation, if possible
//
// Ta * Ainp = Aout => Ta = Aout * Ainp^{-1}
mat_GF2 Ainp = LinearAffineEq::vectorSet2GF2matrix(Avect, 8), AinpInv;
mat_GF2 Aout = LinearAffineEq::values2GF2matrix(Avect, mapA, 8);
mat_GF2 TAinv;
GF2 det;
// Dimension check, each matrix has to have exactly 8 rows (dimension) and at least 8 columns
// (number of equations, sample points)
if ( Ainp.NumCols() < dim || Ainp.NumRows() != dim
|| Aout.NumCols() < dim || Aout.NumRows() != dim){
if (verbosity) cout << "Dimension mismatch for Ainp || Aout matrices " << endl;
return -1;
}
if (verbosity){
cout << "Input matrix: " << endl;
dumpMatrix(Ainp);
cout << "Output matrix: " << endl;
dumpMatrix(Aout);
}
// invertible?
inv(det, AinpInv, Ainp);
if (det == 0) {
if (verbosity) cout << "A Matrix is not invertible! " << endl;
return -2;
}
if (verbosity){
cout << "Inverse matrix: " << endl;
dumpMatrix(AinpInv);
}
// obtain linear transformation
Ta = Aout * AinpInv;
if (verbosity) {
cout << "Ta matrix: " << endl;
dumpMatrix(Ta);
}
// invertible?
inv(det, TAinv, Ta);
if (det==0){
if (verbosity) cout << "Transformation is not linear & invertible!" << endl;
return -3;
}
if (verbosity){
cout << "Transformation matrix repr. obtained!!!" << endl;
dumpMatrix(Ta);
}
//
// A is known (matrix representation), build lookup table
//
if (buildLookupTableAndCheck(Ta, 0, mapA)<0){
return -4;
}
//
// Deriving mapping B from mapping A that is complete now and in matrix form.
//
// B * S2 = S1 * A
// B(x) = S1 * A * S2^{-1} (x)
// From this we derive mapping for B for basis vectors directly.
//
// Or B and A are swapped here and we want to compute values for A(x)
// knowing mapping for B(x) (AisA==false)
//
// A(x) = S1inv * B * S2 (x)
//
Tb.SetDims(dim,dim);
for(unsigned int i=0; i<dim; i++){
bsetElem base = 1 << i;
bsetElem res = AisA ? S1[mapA[S2inv[base]]] : S1inv[mapA[S2[base]]];
for(unsigned int j=0; j<dim; j++){
Tb.put(j, i, (res & (1<<j)) > 0 ? 1 : 0);
}
}
if (verbosity){
cout << "Mapping B derived" << endl;
//.........这里部分代码省略.........
示例10: inv
void inv(GF2& d, mat_GF2& X, const mat_GF2& A)
{
long n = A.NumRows();
if (A.NumCols() != n)
Error("solve: nonsquare matrix");
if (n == 0) {
X.SetDims(0, 0);
set(d);
}
long i, j, k, pos;
mat_GF2 M;
M.SetDims(n, 2*n);
vec_GF2 aa;
aa.SetLength(2*n);
for (i = 0; i < n; i++) {
aa = A[i];
aa.SetLength(2*n);
aa.put(n+i, 1);
M[i] = aa;
}
long wn = ((2*n) + NTL_BITS_PER_LONG - 1)/NTL_BITS_PER_LONG;
for (k = 0; k < 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 = k; i < n; i++) {
if (M[i].rep.elts()[wk] & k_mask) {
pos = i;
break;
}
}
if (pos != -1) {
if (k != pos) {
swap(M[pos], M[k]);
}
_ntl_ulong *y = M[k].rep.elts();
for (i = k+1; i < n; i++) {
// M[i] = M[i] + M[k]*M[i,k]
if (M[i].rep.elts()[wk] & k_mask) {
_ntl_ulong *x = M[i].rep.elts();
for (j = wk; j < wn; j++)
x[j] ^= y[j];
}
}
}
else {
clear(d);
return;
}
}
vec_GF2 XX;
XX.SetLength(2*n);
X.SetDims(n, n);
clear(X);
for (j = 0; j < n; j++) {
XX.SetLength(n+j+1);
clear(XX);
XX.put(n+j, to_GF2(1));
for (i = n-1; i >= 0; i--) {
XX.put(i, XX*M[i]);
}
XX.SetLength(n);
AddToCol(X, j, XX);
}
set(d);
return;
}