bit::matrix
— Side-by-Side Printing
We have functions that print a bit-matrix and some bit-vectors or two or three bit-matrices side by side to a stream.
Versions that print to an arbitrary stream
(std::ostream &s,
printconst bit::matrix &A,
const bit::vector &b,
1std::string_view delim = "\t");
(std::ostream &s,
printconst bit::matrix &A,
const bit::vector &b, const bit::vector &c,
2std::string_view delim = "\t");
(std::ostream &s,
printconst bit::matrix &A,
const bit::vector &b, const bit::vector &c, const bit::vector &d,
3std::string_view delim = "\t");
(std::ostream &s,
printconst bit::matrix &A,
const bit::matrix &B,
4std::string_view delim = "\t");
(std::ostream &s,
printconst bit::matrix &A,
const bit::matrix &B, const bit::matrix &C,
5std::string_view delim = "\t");
- 1
- Prints a bit-matrix and a bit-vector side by side to an arbitrary stream.
- 2
- Prints a bit-matrix and two bit-vectors side by side to an arbitrary stream.
- 3
- Prints a bit-matrix and three bit-vectors side by side to an arbitrary stream.
- 4
- Prints two bit-matrices side by side to an arbitrary stream.
- 5
- Prints three bit-matrices side by side to an arbitrary stream.
Versions that print to std::cout
(const bit::matrix &A,
printconst bit::vector &b,
1std::string_view delim = "\t");
(const bit::matrix &A,
printconst bit::vector &b, const bit::vector &c,
2std::string_view delim = "\t");
(const bit::matrix &A,
printconst bit::vector &b, const bit::vector &c, const bit::vector &d,
3std::string_view delim = "\t");
(const bit::matrix &A,
printconst bit::matrix &B,
4std::string_view delim = "\t");
(const bit::matrix &A,
printconst bit::matrix &B, const bit::matrix &C,
5std::string_view delim = "\t");
- 1
-
Prints a bit-matrix and a bit-vector side by side to
std::cout
. - 2
-
Prints a bit-matrix and two bit-vectors side by side to
std::cout
. - 3
-
Prints a bit-matrix and three bit-vectors side by side to
std::cout
. - 4
-
Prints two bit-matrices side by side to
std::cout
. - 5
-
Prints three bit-matrices side by side to
std::cout
.
Each non-member function is void (i.e., returns nothing). In practice, each has all the appropriate template parameters (not shown here for brevity).
The delimiter string delim
separates the various bit-matrices and bit-vectors in the output stream.
The need for this sort of printing turns up often enough to make it sensible to include the code in the library directly. In particular, these functions gracefully handle cases where the number of rows in the arguments does not match. |
Example
#include <bit/bit.h>
int main()
{
auto M1 = bit::matrix<>::random(8, 6);
auto M2 = bit::matrix<>::random(10);
auto M3 = bit::matrix<>::random(6, 8);
std::cout << "M1 M2 M3\n";
(M1, M2, M3, " | ");
print}
Output where the specific numbers vary from run to run
M1 M2 M3
001011 | 0111010001 | 00111010
111101 | 0100100010 | 11100100
011101 | 0010110111 | 00100011
100111 | 0100111110 | 00100011
011001 | 1010110010 | 11001001
011001 | 1101010100 | 01000001
010010 | 1011000001 |
011011 | 1101001010 |
| 0100111101 |
| 1101111001 |