GNU Radio Manual and C++ API Reference  3.8.1.0
The Free & Open Software Radio Ecosystem
gf2mat.h
Go to the documentation of this file.
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2015 Free Software Foundation, Inc.
4  *
5  * This file is part of GNU Radio
6  *
7  * GNU Radio is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 3, or (at your option)
10  * any later version.
11  *
12  * GNU Radio is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with GNU Radio; see the file COPYING. If not, write to
19  * the Free Software Foundation, Inc., 51 Franklin Street,
20  * Boston, MA 02110-1301, USA.
21  */
22 
23 #ifndef GF2MAT_H
24 #define GF2MAT_H
25 #include "alist.h"
26 #include "gf2vec.h"
27 #include <vector>
28 
29 class GF2Mat
30 {
31  //! The matrix H
32  std::vector<std::vector<char>> H;
33 
34  //! Number of rows in H
35  int M;
36 
37  //! Number of columns in H
38  int N;
39 
40 public:
41  //! Default constructor
42  GF2Mat(){};
43 
44  //! Construct an M x N matrix with all 0 entries
45  GF2Mat(int m, int n);
46 
47  //! Loads the matrix from alist _list
48  GF2Mat(alist _list);
49 
50  //! Initializes the class from a 2-D vector X
51  GF2Mat(std::vector<std::vector<char>> X);
52 
53  //! Returns the variable M
54  int get_M();
55 
56  //! Returns the variable N
57  int get_N();
58 
59  //! Set the element at (i, j) coordinate to val
60  void set_element(int i, int j, char val);
61 
62  //! Returns the element at coordinate (i, j)
63  char get_element(int i, int j);
64 
65  //! Returns the ith row
66  GF2Vec get_row(int i);
67 
68  //! Returns the ith column
69  GF2Vec get_col(int i);
70 
71  //! Returns the ith row
72  GF2Vec operator[](int i);
73 
74  //! Prints the matrix H
75  void print_matrix();
76 
77  //! Sets the ith column with the given vector
78  void set_col(int i, GF2Vec vec);
79 
80  //! Sets the ith row with the given vector
81  void set_row(int i, GF2Vec vec);
82 
83  //! Swaps columns i and j
84  void swap_cols(int i, int j);
85 
86  //! Adds column j to i and replace i with the sum
87  void add_cols(int i, int j);
88 
89  //! Add row j to i and replace j with the sum
90  void add_rows(int i, int j);
91 
92  //! Returns the variable H
93  std::vector<std::vector<char>> get_H();
94 
95  /*!
96  * \brief Obtains an equivalent representation of H for encoding
97  *
98  * For encoding a G matrix in the form [I P] obtained from the
99  * parity matrix H, by (a) Column permutations, (b) Row additions
100  * and (c) Row permutations. Details of encoding is given in
101  * section A.1 of the reference:
102  *
103  * - "Modern Coding Theory", T Richardson and R Urbanke.
104  *
105  * \param p The column permutation during this operation.
106  * \param rank The rank of the matrix.
107  */
108  GF2Mat get_G(std::vector<int>& p, int& rank);
109 };
110 
111 #endif // #ifndef GF2MAT_H
GF2Vec get_row(int i)
Returns the ith row.
void swap_cols(int i, int j)
Swaps columns i and j.
char get_element(int i, int j)
Returns the element at coordinate (i, j)
std::vector< std::vector< char > > get_H()
Returns the variable H.
Definition: alist.h:44
GF2Vec operator[](int i)
Returns the ith row.
void set_col(int i, GF2Vec vec)
Sets the ith column with the given vector.
int get_M()
Returns the variable M.
GF2Mat()
Default constructor.
Definition: gf2mat.h:42
Definition: gf2mat.h:29
void set_row(int i, GF2Vec vec)
Sets the ith row with the given vector.
GF2Mat get_G(std::vector< int > &p, int &rank)
Obtains an equivalent representation of H for encoding.
void print_matrix()
Prints the matrix H.
int get_N()
Returns the variable N.
Definition: gf2vec.h:28
GF2Vec get_col(int i)
Returns the ith column.
void set_element(int i, int j, char val)
Set the element at (i, j) coordinate to val.
void add_rows(int i, int j)
Add row j to i and replace j with the sum.
void add_cols(int i, int j)
Adds column j to i and replace i with the sum.