GNU Radio's CCSDS Package
lib/fec/ldpc/alist.h
Go to the documentation of this file.
1 /*!
2  * \file
3  * \brief Definition of a class to hold sparse matrices in alist-format
4  * \author Manu T S
5  *
6  * -----------------------------------------------------------------
7  *
8  * Copyright 2013 IIT Bombay.
9  *
10  * This is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 3, or (at your option)
13  * any later version.
14  *
15  * This software is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this software; see the file COPYING. If not, write to
22  * the Free Software Foundation, Inc., 51 Franklin Street,
23  * Boston, MA 02110-1301, USA.
24  *
25  * -----------------------------------------------------------------
26  *
27  * This class handles sparse matrices specified in alist-format.
28  * For details about alist format please visit the link below.
29  * - http://www.inference.phy.cam.ac.uk/mackay/codes/alist.html
30  *
31  * Alist class is an efficient way of representing a sparse matrix
32  * the parity check matrix H of an LDPC code for instance.
33  *
34  */
35 
36 #ifndef ALIST_H
37 #define ALIST_H
38 
39 #include <iostream>
40 #include <fstream>
41 #include <sstream>
42 #include <vector>
43 #include <stdlib.h>
44 
45 class alist
46 {
47  public:
48 
49  //! Default Constructor
50  alist() : data_ok(false) {}
51 
52  //! Constructor which loads alist class from an alist-file
53  alist(const char * fname);
54 
55  //! Read alist data from a file
56  void read(const char * fname);
57 
58  //! Write alist data to a file
59  void write(const char * fname) const;
60 
61  //! Retuns N, the number of variable nodes
62  int get_N();
63 
64  //! Return M, the number of check nodes
65  int get_M();
66 
67  //! Return the m_list variable
68  std::vector< std::vector<int> > get_mlist();
69 
70  //! Returns the n_list variable
71  std::vector< std::vector<int> > get_nlist();
72 
73  //! Returns the num_mlist variable
74  std::vector<int> get_num_mlist();
75 
76  //! Returns the num_nlist variable
77  std::vector<int> get_num_nlist();
78 
79  //! Returns the max_num_nlist variable
80  int get_max_num_nlist();
81 
82  //! Returns the max_num_mlist variable
83  int get_max_num_mlist();
84 
85  //! Prints the nlist[i] variable
86  void print_nlist_i(int i);
87 
88  //! Prints the mlist[i] variable
89  void print_mlist_i(int i);
90 
91  //! Returns the corresponding H matrix
92  std::vector<std::vector<char> > get_matrix();
93 
94  protected:
95  //! A variable indicating if data has been read from alist-file
96  bool data_ok;
97 
98  //! Number of variable nodes
99  int N;
100 
101  //! Number of check nodes
102  int M;
103 
104  //! Maximum weight of rows
105  int max_num_mlist;
106 
107  //! Maximum weight of columns
108  int max_num_nlist;
109 
110  //! Weight of each column n
111  std::vector<int> num_nlist;
112 
113  //! Weight of each row m
114  std::vector<int> num_mlist;
115 
116  //! List of integer coordinates along each rows with non-zero entries
117  std::vector< std::vector<int> > mlist;
118 
119  //! List of integer coordinates along each column with non-zero entries
120  std::vector< std::vector<int> > nlist;
121 };
122 #endif // ifndef ALIST_H
int N
Number of variable nodes.
Definition: examples/LDPC/ldpc_2/ldpc_decoder/alist.h:99
void print_mlist_i(int i)
Prints the mlist[i] variable.
Definition: examples/LDPC/ldpc_2/ldpc_decoder/alist.h:45
int get_max_num_nlist()
Returns the max_num_nlist variable.
std::vector< int > num_mlist
Weight of each row m.
Definition: examples/LDPC/ldpc_2/ldpc_decoder/alist.h:114
std::vector< int > get_num_mlist()
Returns the num_mlist variable.
std::vector< std::vector< char > > get_matrix()
Returns the corresponding H matrix.
int get_M()
Return M, the number of check nodes.
int max_num_mlist
Maximum weight of rows.
Definition: examples/LDPC/ldpc_2/ldpc_decoder/alist.h:105
int get_N()
Retuns N, the number of variable nodes.
std::vector< int > get_num_nlist()
Returns the num_nlist variable.
alist()
Default Constructor.
Definition: lib/fec/ldpc/alist.h:50
std::vector< std::vector< int > > get_nlist()
Returns the n_list variable.
std::vector< std::vector< int > > nlist
List of integer coordinates along each column with non-zero entries.
Definition: examples/LDPC/ldpc_2/ldpc_decoder/alist.h:120
int max_num_nlist
Maximum weight of columns.
Definition: examples/LDPC/ldpc_2/ldpc_decoder/alist.h:108
int M
Number of check nodes.
Definition: examples/LDPC/ldpc_2/ldpc_decoder/alist.h:102
void write(const char *fname) const
Write alist data to a file.
int get_max_num_mlist()
Returns the max_num_mlist variable.
bool data_ok
A variable indicating if data has been read from alist-file.
Definition: examples/LDPC/ldpc_2/ldpc_decoder/alist.h:96
std::vector< int > num_nlist
Weight of each column n.
Definition: examples/LDPC/ldpc_2/ldpc_decoder/alist.h:111
std::vector< std::vector< int > > mlist
List of integer coordinates along each rows with non-zero entries.
Definition: examples/LDPC/ldpc_2/ldpc_decoder/alist.h:117
void read(const char *fname)
Read alist data from a file.
void print_nlist_i(int i)
Prints the nlist[i] variable.
std::vector< std::vector< int > > get_mlist()
Return the m_list variable.