GF2::Matrix — Extract a Sub-Matrix
Extracts a sub-matrix as a stand-alone, distinct copy of elements from this bit-matrix.
constexpr Matrix sub(std::size_t i0, std::size_t j0, std::size_t r, std::size_t c) const; (1)
constexpr Matrix sub(std::size_t r, std::size_t c) const; (2)
constexpr Matrix sub(std::size_t n) const const; (3)
| 1 | Returns an r x c bit-matrix that is a copy from this bit-matrix starting at (i0, j0) |
| 2 | Returns an r x c bit-matrix that is a copy from this bit-matrix starting at (0, 0) |
| 3 | Returns an n x n square bit-matrix that is a copy from this bit-matrix starting at (0, 0) |
(i0, j0) has to be a valid index pair and the requested dimensions have to fit as a valid sub-matrix.
As usual these requirements are only checked if the GF2_DEBUG flag is set at compile time—in which case violations will cause the program to abort with a helpful message.
|
Example
#include <GF2/GF2.h>
int main()
{
auto m = GF2::Matrix<>::random(8); (1)
std::cout << "m: \n" << m << "\n";
std::cout << "m.sub(4): \n" << m.sub(4) << "\n"; (2)
std::cout << "m.sub(2,4): \n" << m.sub(2,4) << "\n"; (3)
std::cout << "m.sub(5,5,3,3): \n" << m.sub(5,5,3,3) << "\n"; (4)
}
| 1 | Constructs an 8 x 8 bit-matrix a random fill. |
| 2 | Extract the 4 x 4 elements starting at index (0, 0). |
| 3 | Extract the 2 x 4 elements starting at index (0, 0). |
| 4 | Extract the 3 x 3 elements starting at index (5, 5). |
Output
m:
00001110
10100001
10100111
01101100
01000100
10001101
01011011
00000000
m.sub(4):
0000
1010
1010
0110
m.sub(2,4):
0000
1010
m.sub(5,5,3,3):
101
011
000
See Also