Class for dense GF(2) matrices. More...
#include <itpp/base/gf2mat.h>
Public Member Functions | |
GF2mat () | |
Default constructor (gives an empty 1 x 1 matrix) | |
GF2mat (int m, int n) | |
Construct an empty (all-zero) m x n matrix. | |
GF2mat (const GF2mat_sparse &X) | |
Construct a dense GF(2) matrix from a sparse GF(2) matrix. | |
GF2mat (const GF2mat_sparse &X, int m1, int n1, int m2, int n2) | |
Constructor, from subset of sparse GF(2) matrix. | |
GF2mat (const GF2mat_sparse &X, const ivec &columns) | |
Constructor, from subset of sparse GF(2) matrix. | |
GF2mat (const bvec &x, bool is_column=true) | |
Create a dense GF(2) matrix from a single vector. | |
GF2mat (const bmat &X) | |
Create a dense GF(2) matrix from a bmat. | |
void | set_size (int m, int n, bool copy=false) |
Set size of GF(2) matrix. If copy = true, keep data before resizing. | |
GF2mat_sparse | sparsify () const |
Create a sparse GF(2) matrix from a dense GF(2) matrix. | |
bvec | bvecify () const |
Create a bvec from a GF(2) matrix (must have one column or one row) | |
bin | get (int i, int j) const |
Getting element. | |
bin | operator() (int i, int j) const |
Getting element. | |
void | set (int i, int j, bin s) |
Set element i,j to s (0 or 1) | |
void | addto_element (int i, int j, bin s) |
Add s (0 or 1) to element (i,j) | |
void | set_col (int j, bvec x) |
Set column j to a binary vector x. | |
void | set_row (int i, bvec x) |
Set row i to a binary vector x. | |
bool | is_zero () const |
Check whether the matrix is identical to zero. | |
void | swap_rows (int i, int j) |
Swap rows i and j. | |
void | swap_cols (int i, int j) |
Swap columns i and j. | |
void | permute_rows (ivec &perm, bool I) |
Multiply from left with permutation matrix (permute rows). | |
void | permute_cols (ivec &perm, bool I) |
Multiply a matrix from right with a permutation matrix (i.e., permute the columns). | |
GF2mat | transpose () const |
Transpose. | |
GF2mat | get_submatrix (int m1, int n1, int m2, int n2) const |
Submatrix from (m1,n1) to (m2,n2) | |
GF2mat | concatenate_horizontal (const GF2mat &X) const |
Concatenate horizontally (append X on the right side of matrix) | |
GF2mat | concatenate_vertical (const GF2mat &X) const |
Concatenate vertically (append X underneath) | |
bvec | get_row (int i) const |
Get row. | |
bvec | get_col (int j) const |
Get column. | |
double | density () const |
Compute the matrix density (fraction of elements equal to "1") | |
int | rows () const |
Get number of rows. | |
int | cols () const |
Get number of columns. | |
void | add_rows (int i, int j) |
Add (or equivalently, subtract) rows. | |
GF2mat | inverse () const |
Inversion. | |
int | row_rank () const |
Returns the number of linearly independent rows. | |
int | T_fact (GF2mat &T, GF2mat &U, ivec &P) const |
TXP factorization. | |
int | T_fact_update_bitflip (GF2mat &T, GF2mat &U, ivec &P, int rank, int r, int c) const |
TXP factorization update, when bit is flipped. | |
bool | T_fact_update_addcol (GF2mat &T, GF2mat &U, ivec &P, bvec newcol) const |
TXP factorization update, when column is added. | |
void | operator= (const GF2mat &X) |
Assignment operator. | |
bool | operator== (const GF2mat &X) const |
Check if equal. | |
Friends | |
ITPP_EXPORT GF2mat | operator* (const GF2mat &X, const GF2mat &Y) |
Multiplication operator. | |
ITPP_EXPORT bvec | operator* (const GF2mat &X, const bvec &y) |
Multiplication operator with binary vector. | |
ITPP_EXPORT GF2mat | operator+ (const GF2mat &X, const GF2mat &Y) |
Addition operator. | |
ITPP_EXPORT std::ostream & | operator<< (std::ostream &os, const GF2mat &X) |
Output stream operator (plain text) | |
ITPP_EXPORT it_file & | operator<< (it_file &f, const GF2mat &X) |
Write the matrix to file. | |
ITPP_EXPORT it_ifile & | operator>> (it_ifile &f, GF2mat &X) |
Read the matrix from file. | |
ITPP_EXPORT GF2mat | mult_trans (const GF2mat &X, const GF2mat &Y) |
Multiplication X*Y' where X and Y are GF(2) matrices. | |
Related Functions | |
(Note that these are not member functions.) | |
ITPP_EXPORT GF2mat | operator* (const GF2mat &X, const GF2mat &Y) |
GF(2) matrix multiplication. | |
ITPP_EXPORT bvec | operator* (const GF2mat &X, const bvec &y) |
GF(2) matrix multiplication with "regular" binary vector. | |
ITPP_EXPORT GF2mat | operator+ (const GF2mat &X, const GF2mat &Y) |
GF(2) matrix addition. | |
ITPP_EXPORT std::ostream & | operator<< (std::ostream &os, const GF2mat &X) |
Output stream (plain text) operator for dense GF(2) matrices. | |
ITPP_EXPORT GF2mat | gf2dense_eye (int m) |
GF(2) Identity matrix. | |
ITPP_EXPORT GF2mat | mult_trans (const GF2mat &X, const GF2mat &Y) |
Multiplication X*Y' where X and Y are GF(2) matrices. | |
Class for dense GF(2) matrices.
This class can be used as an alternative to bmat
to represent GF(2) matrices. It extends the functionality of bmat
in two ways:
GF2mat
makes more efficient use of computer memory than bmat
(one bit in the matrix requires one bit of memory)GF2mat
provides several functions for linear algebra and matrix factorizationsSee also GF2mat_sparse
which offers an efficient representation of sparse GF(2) matrices, and GF2mat_sparse_alist
for a parameterized representation of sparse GF(2) matrices.
itpp::GF2mat::GF2mat | ( | const GF2mat_sparse & | X, |
int | m1, | ||
int | n1, | ||
int | m2, | ||
int | n2 | ||
) |
Constructor, from subset of sparse GF(2) matrix.
This constructor forms a dense GF(2) matrix from a subset (m1,n1) to (m2,n2) of a sparse GF(2) matrix
Definition at line 352 of file gf2mat.cpp.
References itpp::Sparse_Mat< T >::cols(), it_assert, itpp::Sparse_Mat< T >::rows(), and itpp::Mat< Num_T >::set_size().
itpp::GF2mat::GF2mat | ( | const GF2mat_sparse & | X, |
const ivec & | columns | ||
) |
Constructor, from subset of sparse GF(2) matrix.
This constructor forms a dense GF(2) matrix from a subset of columns in sparse GF(2) matrix
X | matrix to copy from |
columns | subset of columns to copy |
Definition at line 379 of file gf2mat.cpp.
References itpp::Sparse_Mat< T >::cols(), itpp::Sparse_Mat< T >::get_col(), it_assert, itpp::length(), itpp::max(), itpp::min(), itpp::Sparse_Mat< T >::rows(), and itpp::Mat< Num_T >::set_size().
itpp::GF2mat::GF2mat | ( | const bvec & | x, |
bool | is_column = true |
||
) |
Create a dense GF(2) matrix from a single vector.
x | The input vector |
is_column | A parameter that indicates whether the result should be a row vector (false), or a column vector (true - default) |
Definition at line 294 of file gf2mat.cpp.
References itpp::Mat< Num_T >::clear(), itpp::length(), and itpp::Mat< Num_T >::set_size().
void itpp::GF2mat::permute_rows | ( | ivec & | perm, |
bool | I | ||
) |
Multiply from left with permutation matrix (permute rows).
perm | Permutation vector |
I | Parameter that determines permutation. I=0: apply permutation, I=1: apply inverse permutation |
Definition at line 980 of file gf2mat.cpp.
References it_assert, and itpp::length().
Referenced by inverse().
void itpp::GF2mat::permute_cols | ( | ivec & | perm, |
bool | I | ||
) |
Multiply a matrix from right with a permutation matrix (i.e., permute the columns).
perm | Permutation vector |
I | Parameter that determines permutation. I=0: apply permutation, I=1: apply inverse permutation |
Definition at line 964 of file gf2mat.cpp.
References get_col(), it_assert, itpp::length(), and set_col().
void itpp::GF2mat::add_rows | ( | int | i, |
int | j | ||
) |
Add (or equivalently, subtract) rows.
This function updates row i according to row_i = row_i+row_j
i | Row to add to. This row will be modified |
j | Row to add. This row will not be modified. |
Definition at line 809 of file gf2mat.cpp.
References it_assert.
Referenced by itpp::BLDPC_Generator::construct(), inverse(), T_fact(), T_fact_update_addcol(), and T_fact_update_bitflip().
GF2mat itpp::GF2mat::inverse | ( | ) | const |
Inversion.
The matrix must be invertible, otherwise the function will terminate with an error.
Definition at line 748 of file gf2mat.cpp.
References add_rows(), get(), it_assert, permute_rows(), itpp::rank(), and T_fact().
Referenced by itpp::LDPC_Generator_Systematic::construct().
TXP factorization.
Given X, compute a factorization of the form U=TXP, where U is upper triangular, T is square and invertible, and P is a permutation matrix. This is basically an "LU"-factorization, but not called so here because T is not necessarily lower triangular. The matrix X may have any dimension. The permutation matrix P is represented as a permutation vector.
The function returns the row rank of X. (If X is full row rank, then the number of rows is returned.)
The function uses Gaussian elimination combined with permutations. The computational complexity is O(m*m*n) for an m*n matrix.
Definition at line 561 of file gf2mat.cpp.
References add_rows(), itpp::floor_i(), get(), gf2dense_eye(), it_info_debug, swap_cols(), swap_rows(), and itpp::zeros_i().
Referenced by itpp::LDPC_Generator_Systematic::construct(), inverse(), and row_rank().
int itpp::GF2mat::T_fact_update_bitflip | ( | GF2mat & | T, |
GF2mat & | U, | ||
ivec & | P, | ||
int | rank, | ||
int | r, | ||
int | c | ||
) | const |
TXP factorization update, when bit is flipped.
Update upper triangular factor U in the TXP-factorization (U=TXP) when the bit at position (r,c) is changed (0->1 or 1->0). The purpose of this function is to avoid re-running a complete T-factorization when a single bit is changed. The function assumes that T, U, and P already exist and that U=TXP before the function is called. The function also assumes that the rank provided is correct. The function updates T, U and P these matrices. The function returns the new rank of the matrix after the bitflip.
The function works by performing permutations to bring the matrix to a form where the Gaussian eliminated can be restarted from the point (rank-1,rank-1). The function is very fast for matrices with close to full rank but it is generally slower for non-full rank matrices.
Definition at line 614 of file gf2mat.cpp.
References add_rows(), addto_element(), get(), get_col(), get_row(), it_error, set_col(), set_row(), swap_cols(), and swap_rows().
TXP factorization update, when column is added.
Update upper triangular factor U in the T-factorization (U=TXP) when a column (newcol) is appended at the right side of the matrix. The purpose of this function is to avoid re-running a complete T-factorization when a column is added. The function ONLY adds the column if it improves the rank of the matrix (nothing is done otherwise). The function returns "true" if the column was added, and "false" otherwise.
The complexity is O(m^2) for an m*n matrix.
Definition at line 697 of file gf2mat.cpp.
References add_rows(), cols(), concatenate_horizontal(), get(), GF2mat(), it_assert, it_assert_debug, itpp::length(), row_rank(), rows(), and swap_rows().
Referenced by itpp::LDPC_Generator_Systematic::construct().
Addition operator.
Subtraction is not implemented because it is equivalent to addition.
Definition at line 948 of file gf2mat.cpp.
Write the matrix to file.
/relatesalso GF2mat /brief Write GF(2) matrix to file.
Definition at line 1032 of file gf2mat.cpp.
Read the matrix from file.
/relatesalso GF2mat /brief Read GF(2) matrix from file.
Definition at line 1050 of file gf2mat.cpp.
Generated on Sat May 25 2013 16:32:29 for IT++ by Doxygen 1.8.2