GF2::Matrix — Create Special Bit-Matrices

Class methods to construct some special well known bit-matrices.

static constexpr Matrix ones(std::size_t r, std::size_t c);                          //  (1)
static constexpr Matrix ones(std::size_t n);                                         //  (2)
static constexpr Matrix zeros(std::size_t r, std::size_t c);                         //  (3)
static constexpr Matrix zeros(std::size_t n);                                        //  (4)
static constexpr Matrix checker_board(std::size_t r, std::size_t c, int first = 1);  //  (5)
static constexpr Matrix checker_board(std::size_t n, int first = 1);                 //  (6)
static constexpr Matrix identity(std::size_t n);                                     //  (7)
static constexpr Matrix shift(std::size_t n, int p = -1);                            //  (8)
static constexpr Matrix rotate(std::size_t n, int p = -1);                           //  (9)
1 Returns an r x c bit-matrix where all the elements are set to 1.
2 Returns an n x n square bit-matrix where all the elements are set to 1.
3 Returns an r x c bit-matrix where all the elements are set to 0.
4 Returns an n x n square bit-matrix where all the elements are set to 0.
5 Returns an r x c bit-matrix where the elements form a checker-board pattern.
6 Returns an n x n square bit-matrix where the elements form a checker-board pattern.
7 Returns the n x n identity bit-matrix (ones on the diagonal, other elements all zero).
8 Returns the n x n bit-matrix that shifts a bit-vector by p slots to the right if p > 0 and the left if p < 0.
9 Returns the n x n bit-matrix that rotates a bit-vector by p slots to the right if p > 0 and the left if p < 0.
Example
#include <GF2/GF2.h>
int main()
{
    auto ones = GF2::Matrix<>::ones(4);
    std::cout << "The all set matrix:\n" << ones << "\n\n";

    auto ident = GF2::Matrix<>::identity(8);
    std::cout << "The identity matrix:\n" << ident << "\n\n";

    auto shiftr = GF2::Matrix<>::shift(8, 1);
    std::cout << "The shift right one place matrix:\n" << shiftr << "\n\n";

    auto shiftl = GF2::Matrix<>::shift(8, -1);
    std::cout << "The shift left one place matrix:\n" << shiftl << "\n\n";

    auto rotr= GF2::Matrix<>::rotate(8, 1);
    std::cout << "The rotate right one place matrix:\n" << rotr << "\n\n";

    auto rotl = GF2::Matrix<>::rotate(8, -1);
    std::cout << "The rotate left one place matrix:\n" << rotl << "\n\n";

    auto u = GF2::Vector<>::ones(8);
    std::cout << "Product identity matrix with " << u << " yields " << dot(ident,  u) << '\n';
    std::cout << "Product shiftr matrix with   " << u << " yields " << dot(shiftr, u) << '\n';
    std::cout << "Product shiftl matrix with   " << u << " yields " << dot(shiftl, u) << '\n';

    u[0] = 0;
    std::cout << "Product rotr matrix with     " << u << " yields " << dot(rotr,   u) << '\n';
    std::cout << "Product rotl matrix with     " << u << " yields " << dot(rotl,   u) << '\n\n';

    auto C1 = GF2::Matrix<>::checker_board(4,1);
    auto C0 = GF2::Matrix<>::checker_board(4,0);
    std::cout << "Two checker-board matrices:\n";
    GF2::print(C0, C1);
}
Output
The all set matrix:
1111
1111
1111
1111

The identity matrix:
10000000
01000000
00100000
00010000
00001000
00000100
00000010
00000001

The shift right one place matrix:
01000000
00100000
00010000
00001000
00000100
00000010
00000001
00000000

The shift left one place matrix:
00000000
10000000
01000000
00100000
00010000
00001000
00000100
00000010

The rotate right one place matrix:
01000000
00100000
00010000
00001000
00000100
00000010
00000001
10000000

The rotate left one place matrix:
00000001
10000000
01000000
00100000
00010000
00001000
00000100
00000010

Product identity matrix with 11111111 yields 11111111
Product shiftr matrix with   11111111 yields 11111110
Product shiftl matrix with   11111111 yields 01111111
Product rotr matrix with     01111111 yields 11111110
Product rotl matrix with     01111111 yields 10111111

Two checker-board matrices:
0101    1010
1010    0101
0101    1010
1010    0101