GF2::Matrix — Pack Bit-Matrix into a Bit-Vector
Packs the bit-matrix into a bit-vector.
constexpr Vector<Block, Allocator> to_vector(bool by_rows = true) const;
By default this returns a bit-vector with all the elements of the bit-matrix stored row by row.
If the argument by_rows is set to false the return bit-vector will have the elements of the bit-matrix stored column by column.
Example
#include <GF2/GF2.h>
int main()
{
GF2::Matrix<> m(4, [](std::size_t i, std::size_t) { return (i)%2; }); (1)
auto vrow = m.to_vector(); (2)
auto vcol = m.to_vector(false); (3)
std::cout << "Original:\n" << m << '\n';
std::cout << "By row: " << vrow << '\n';
std::cout << "By col: " << vcol << '\n';
std::cout << "From row:\n" << GF2::Matrix(vrow, 4) << '\n'; (4)
std::cout << "From col:\n" << GF2::Matrix(vcol, 4, false) << '\n'; (5)
}
| 1 | Construct a bit-matrix that has rows which alternate between all zeros and all ones. |
| 2 | Pack the bit-matrix in a bit-vector row by row. |
| 3 | Pack the bit-matrix in a bit-vector column by column. |
| 4 | Reconstitute a bit-matrix from the row by row bit-vector. |
| 5 | Reconstitute a bit-matrix from the column by column bit-vector. |
Output
Original:
0000
1111
0000
1111
By row: 0000111100001111
By col: 0101010101010101
From row:
0000
1111
0000
1111
From col:
0000
1111
0000
1111
See Also
constructors for a constructor that reshapes a bit-vector in to a bit-matrix.