summaryrefslogtreecommitdiff
path: root/gr-fec
diff options
context:
space:
mode:
authorTom Rondeau <tom@trondeau.com>2015-10-14 17:52:41 -0400
committerTom Rondeau <tom@trondeau.com>2015-10-15 10:40:25 -0400
commit3688105f23791c00349d4fa01c3a4f671af3b00b (patch)
tree484f6bdce2360ed54629fb7e4383f9caf9a0a6c9 /gr-fec
parent62fb423cc415f658e6a7e1b8cafd37d066573a70 (diff)
fec: LDPC: fixed issue with bit_flip_decoder.
We can't use a raw pointer, so using a shared_ptr to the base class, instead, from the H and G matrices.
Diffstat (limited to 'gr-fec')
-rw-r--r--gr-fec/include/gnuradio/fec/fec_mtrx.h3
-rw-r--r--gr-fec/include/gnuradio/fec/ldpc_G_matrix.h15
-rw-r--r--gr-fec/include/gnuradio/fec/ldpc_H_matrix.h11
-rw-r--r--gr-fec/include/gnuradio/fec/ldpc_bit_flip_decoder.h2
-rw-r--r--gr-fec/lib/fec_mtrx_impl.cc1
-rw-r--r--gr-fec/lib/ldpc_G_matrix_impl.cc9
-rw-r--r--gr-fec/lib/ldpc_G_matrix_impl.h5
-rw-r--r--gr-fec/lib/ldpc_H_matrix_impl.cc11
-rw-r--r--gr-fec/lib/ldpc_H_matrix_impl.h8
-rw-r--r--gr-fec/lib/ldpc_bit_flip_decoder_impl.cc4
-rw-r--r--gr-fec/lib/ldpc_bit_flip_decoder_impl.h5
-rw-r--r--gr-fec/python/fec/qa_fecapi_ldpc.py20
-rw-r--r--gr-fec/swig/ldpc.i1
13 files changed, 52 insertions, 43 deletions
diff --git a/gr-fec/include/gnuradio/fec/fec_mtrx.h b/gr-fec/include/gnuradio/fec/fec_mtrx.h
index 30b5ede4fd..1dcee6547a 100644
--- a/gr-fec/include/gnuradio/fec/fec_mtrx.h
+++ b/gr-fec/include/gnuradio/fec/fec_mtrx.h
@@ -49,6 +49,9 @@ namespace gr {
typedef boost::shared_ptr<matrix> matrix_sptr;
+ class fec_mtrx;
+ typedef boost::shared_ptr<fec_mtrx> fec_mtrx_sptr;
+
/*!
* \brief Read in an alist file and produce the matrix object.
*
diff --git a/gr-fec/include/gnuradio/fec/ldpc_G_matrix.h b/gr-fec/include/gnuradio/fec/ldpc_G_matrix.h
index 32c38a144b..36a598146d 100644
--- a/gr-fec/include/gnuradio/fec/ldpc_G_matrix.h
+++ b/gr-fec/include/gnuradio/fec/ldpc_G_matrix.h
@@ -24,6 +24,7 @@
#include <gnuradio/fec/api.h>
#include <gnuradio/fec/fec_mtrx.h>
#include <boost/shared_ptr.hpp>
+#include <boost/enable_shared_from_this.hpp>
namespace gr {
namespace fec {
@@ -50,7 +51,8 @@ namespace gr {
* This variable can used by the ldpc_gen_mtrx_encoder and
* ldpc_bit_flip_decoder classes.
*/
- class FEC_API ldpc_G_matrix : virtual public fec_mtrx
+ class FEC_API ldpc_G_matrix : virtual public fec_mtrx,
+ public boost::enable_shared_from_this<ldpc_G_matrix>
{
public:
typedef boost::shared_ptr<ldpc_G_matrix> sptr;
@@ -78,7 +80,16 @@ namespace gr {
unsigned int frame_size,
unsigned int max_iterations) const = 0;
- virtual gr::fec::code::fec_mtrx* get_base_ptr() = 0;
+ /*!
+ * \brief A pointer to make SWIG work
+ *
+ * \details
+ * SWIG doesn't understand the parent class pointer to this
+ * child class for the make function of the
+ * ldpc_bit_flip_decoder; it's expecting a pointer to the base
+ * class. This returns a shared_from_this instance.
+ */
+ virtual gr::fec::code::fec_mtrx_sptr get_base_sptr() = 0;
};
}
diff --git a/gr-fec/include/gnuradio/fec/ldpc_H_matrix.h b/gr-fec/include/gnuradio/fec/ldpc_H_matrix.h
index 37805a04e5..d770a658a3 100644
--- a/gr-fec/include/gnuradio/fec/ldpc_H_matrix.h
+++ b/gr-fec/include/gnuradio/fec/ldpc_H_matrix.h
@@ -24,6 +24,7 @@
#include <gnuradio/fec/api.h>
#include <gnuradio/fec/fec_mtrx.h>
#include <boost/shared_ptr.hpp>
+#include <boost/enable_shared_from_this.hpp>
namespace gr {
namespace fec {
@@ -45,7 +46,8 @@ namespace gr {
* python functions in:
* /lib/python2.7/dist-packages/gnuradio/fec/LDPC/Generate_LDPC_matrix.py.
*/
- class FEC_API ldpc_H_matrix : virtual public fec_mtrx
+ class FEC_API ldpc_H_matrix : virtual public fec_mtrx,
+ public boost::enable_shared_from_this<ldpc_H_matrix>
{
public:
typedef boost::shared_ptr<ldpc_H_matrix> sptr;
@@ -86,13 +88,14 @@ namespace gr {
* \brief A pointer to make SWIG work
*
* \details
- * For some reason, SWIG isn't accepting a pointer to this
+ * SWIG doesn't understand the parent class pointer to this
* child class for the make function of the
* ldpc_bit_flip_decoder; it's expecting a pointer to the base
- * class. So, this is just a workaround for SWIG and GRC.
+ * class. This returns a shared_from_this instance.
*/
- virtual gr::fec::code::fec_mtrx *get_base_ptr() = 0;
+ virtual gr::fec::code::fec_mtrx_sptr get_base_sptr() = 0;
};
+
}
}
}
diff --git a/gr-fec/include/gnuradio/fec/ldpc_bit_flip_decoder.h b/gr-fec/include/gnuradio/fec/ldpc_bit_flip_decoder.h
index 13f8693331..6ed0658e93 100644
--- a/gr-fec/include/gnuradio/fec/ldpc_bit_flip_decoder.h
+++ b/gr-fec/include/gnuradio/fec/ldpc_bit_flip_decoder.h
@@ -66,7 +66,7 @@ namespace gr {
* testing. May be increased for possibly better
* performance, but may slow things down.
*/
- static generic_decoder::sptr make(const fec_mtrx *mtrx_obj,
+ static generic_decoder::sptr make(const fec_mtrx_sptr mtrx_obj,
unsigned int max_iter=100);
/*!
diff --git a/gr-fec/lib/fec_mtrx_impl.cc b/gr-fec/lib/fec_mtrx_impl.cc
index 3ce68ec901..7c4dd34f2d 100644
--- a/gr-fec/lib/fec_mtrx_impl.cc
+++ b/gr-fec/lib/fec_mtrx_impl.cc
@@ -487,6 +487,7 @@ namespace gr {
return matrix_inverse;
}
+
bool
fec_mtrx_impl::parity_bits_come_last() const
{
diff --git a/gr-fec/lib/ldpc_G_matrix_impl.cc b/gr-fec/lib/ldpc_G_matrix_impl.cc
index 6474b166bc..d0a6df1dee 100644
--- a/gr-fec/lib/ldpc_G_matrix_impl.cc
+++ b/gr-fec/lib/ldpc_G_matrix_impl.cc
@@ -134,8 +134,6 @@ namespace gr {
// Free memory
gsl_matrix_free(P);
gsl_matrix_free(P_transpose);
-
- d_base_ptr = reinterpret_cast<fec_mtrx*>(this);
}
@@ -278,11 +276,10 @@ namespace gr {
gsl_matrix_free(x);
}
-
- gr::fec::code::fec_mtrx*
- ldpc_G_matrix_impl::get_base_ptr()
+ gr::fec::code::fec_mtrx_sptr
+ ldpc_G_matrix_impl::get_base_sptr()
{
- return d_base_ptr;
+ return shared_from_this();
}
ldpc_G_matrix_impl::~ldpc_G_matrix_impl()
diff --git a/gr-fec/lib/ldpc_G_matrix_impl.h b/gr-fec/lib/ldpc_G_matrix_impl.h
index f272d0aff8..b9b119dfd5 100644
--- a/gr-fec/lib/ldpc_G_matrix_impl.h
+++ b/gr-fec/lib/ldpc_G_matrix_impl.h
@@ -71,8 +71,6 @@ namespace gr {
gr::logger_ptr d_logger;
gr::logger_ptr d_debug_logger;
- gr::fec::code::fec_mtrx *d_base_ptr;
-
public:
ldpc_G_matrix_impl(const std::string filename);
@@ -90,7 +88,7 @@ namespace gr {
gsl_matrix* generate_H();
- gr::fec::code::fec_mtrx* get_base_ptr();
+ gr::fec::code::fec_mtrx_sptr get_base_sptr();
/*!
* \brief Destructor
@@ -99,6 +97,7 @@ namespace gr {
*/
virtual ~ldpc_G_matrix_impl();
};
+
}
}
}
diff --git a/gr-fec/lib/ldpc_H_matrix_impl.cc b/gr-fec/lib/ldpc_H_matrix_impl.cc
index 74801cfba9..ae6fb9a0e1 100644
--- a/gr-fec/lib/ldpc_H_matrix_impl.cc
+++ b/gr-fec/lib/ldpc_H_matrix_impl.cc
@@ -62,9 +62,6 @@ namespace gr {
set_parameters_for_encoding();
- // For info about this see get_base_ptr() function
- //d_base_ptr = this;
-
// The parity bits come first in this particular matrix
// format (specifically required for the Richardson Urbanke
// encoder)
@@ -80,8 +77,6 @@ namespace gr {
d_p2 = gsl_matrix_alloc(phi_inverse()->size1, d_temp5->size2);
d_temp6 = gsl_matrix_alloc(A()->size1, d_p2->size2);
d_temp7 = gsl_matrix_alloc(d_temp6->size1, d_temp1->size2);
-
- d_base_ptr = reinterpret_cast<fec_mtrx*>(this);
} // Constructor
const gsl_matrix*
@@ -410,10 +405,10 @@ namespace gr {
gsl_matrix_free(x);
}
- gr::fec::code::fec_mtrx*
- ldpc_H_matrix_impl::get_base_ptr()
+ gr::fec::code::fec_mtrx_sptr
+ ldpc_H_matrix_impl::get_base_sptr()
{
- return d_base_ptr;
+ return shared_from_this();
}
ldpc_H_matrix_impl::~ldpc_H_matrix_impl()
diff --git a/gr-fec/lib/ldpc_H_matrix_impl.h b/gr-fec/lib/ldpc_H_matrix_impl.h
index 67929a82a3..b4893ced7d 100644
--- a/gr-fec/lib/ldpc_H_matrix_impl.h
+++ b/gr-fec/lib/ldpc_H_matrix_impl.h
@@ -23,7 +23,6 @@
#include "fec_mtrx_impl.h"
#include <gnuradio/fec/ldpc_H_matrix.h>
-#include <gnuradio/fec/ldpc_G_matrix.h>
namespace gr {
namespace fec {
@@ -79,8 +78,6 @@ namespace gr {
*/
const gsl_matrix *phi_inverse() const;
- gr::fec::code::fec_mtrx *d_base_ptr;
-
public:
/*!
* \brief Constructor given alist file and gap
@@ -112,15 +109,16 @@ namespace gr {
//! Redefine these here as part of the public interface
unsigned int k() const { return fec_mtrx_impl::k(); };
+ gr::fec::code::fec_mtrx_sptr get_base_sptr();
+
/*!
* \brief Destructor
* \details
* Calls the gsl_matrix_free function to free memory
*/
virtual ~ldpc_H_matrix_impl();
-
- gr::fec::code::fec_mtrx *get_base_ptr();
};
+
}
}
}
diff --git a/gr-fec/lib/ldpc_bit_flip_decoder_impl.cc b/gr-fec/lib/ldpc_bit_flip_decoder_impl.cc
index 49fd241a06..ed8eb07db4 100644
--- a/gr-fec/lib/ldpc_bit_flip_decoder_impl.cc
+++ b/gr-fec/lib/ldpc_bit_flip_decoder_impl.cc
@@ -35,14 +35,14 @@ namespace gr {
namespace code {
generic_decoder::sptr
- ldpc_bit_flip_decoder::make(const fec_mtrx *mtrx_obj,
+ ldpc_bit_flip_decoder::make(const fec_mtrx_sptr mtrx_obj,
unsigned int max_iter)
{
return generic_decoder::sptr
(new ldpc_bit_flip_decoder_impl(mtrx_obj, max_iter));
}
- ldpc_bit_flip_decoder_impl::ldpc_bit_flip_decoder_impl(const fec_mtrx *mtrx_obj,
+ ldpc_bit_flip_decoder_impl::ldpc_bit_flip_decoder_impl(const fec_mtrx_sptr mtrx_obj,
unsigned int max_iter)
: generic_decoder("ldpc_bit_flip_decoder")
{
diff --git a/gr-fec/lib/ldpc_bit_flip_decoder_impl.h b/gr-fec/lib/ldpc_bit_flip_decoder_impl.h
index b2b1bbf41b..ba331bed62 100644
--- a/gr-fec/lib/ldpc_bit_flip_decoder_impl.h
+++ b/gr-fec/lib/ldpc_bit_flip_decoder_impl.h
@@ -39,13 +39,13 @@ namespace gr {
double d_rate;
// FEC matrix object to use for decoding
- const fec_mtrx *d_mtrx;
+ fec_mtrx_sptr d_mtrx;
// Maximum number of iterations to do in decoding algorithm
unsigned int d_max_iterations;
public:
- ldpc_bit_flip_decoder_impl(const fec_mtrx *mtrx_obj,
+ ldpc_bit_flip_decoder_impl(const fec_mtrx_sptr mtrx_obj,
unsigned int max_iter=100);
~ldpc_bit_flip_decoder_impl();
@@ -53,6 +53,7 @@ namespace gr {
bool set_frame_size(unsigned int frame_size);
double rate();
};
+
} /* namespace code */
} /* namespace fec */
} /* namespace gr */
diff --git a/gr-fec/python/fec/qa_fecapi_ldpc.py b/gr-fec/python/fec/qa_fecapi_ldpc.py
index e5a968b839..52a05dccee 100644
--- a/gr-fec/python/fec/qa_fecapi_ldpc.py
+++ b/gr-fec/python/fec/qa_fecapi_ldpc.py
@@ -48,7 +48,7 @@ class test_fecapi_ldpc(gr_unittest.TestCase):
LDPC_matrix_object = fec.ldpc_H_matrix(filename, gap)
k = LDPC_matrix_object.k()
enc = fec.ldpc_par_mtrx_encoder.make_H(LDPC_matrix_object)
- dec = fec.ldpc_bit_flip_decoder.make(LDPC_matrix_object.get_base_ptr())
+ dec = fec.ldpc_bit_flip_decoder.make(LDPC_matrix_object.get_base_sptr())
threading = None
self.test = _qa_helper(10*k, enc, dec, threading)
self.tb.connect(self.test)
@@ -65,7 +65,7 @@ class test_fecapi_ldpc(gr_unittest.TestCase):
LDPC_matrix_object = fec.ldpc_H_matrix(filename, gap)
k = LDPC_matrix_object.k()
enc = fec.ldpc_par_mtrx_encoder.make_H(LDPC_matrix_object)
- dec = fec.ldpc_bit_flip_decoder.make(LDPC_matrix_object.get_base_ptr())
+ dec = fec.ldpc_bit_flip_decoder.make(LDPC_matrix_object.get_base_sptr())
threading = 'ordinary'
self.test = _qa_helper(10*k, enc, dec, threading)
self.tb.connect(self.test)
@@ -82,7 +82,7 @@ class test_fecapi_ldpc(gr_unittest.TestCase):
LDPC_matrix_object = fec.ldpc_H_matrix(filename, gap)
k = LDPC_matrix_object.k()
enc = fec.ldpc_par_mtrx_encoder.make_H(LDPC_matrix_object)
- dec = fec.ldpc_bit_flip_decoder.make(LDPC_matrix_object.get_base_ptr())
+ dec = fec.ldpc_bit_flip_decoder.make(LDPC_matrix_object.get_base_sptr())
threading = 'capillary'
self.test = _qa_helper(10*k, enc, dec, threading)
self.tb.connect(self.test)
@@ -99,7 +99,7 @@ class test_fecapi_ldpc(gr_unittest.TestCase):
LDPC_matrix_object = fec.ldpc_H_matrix(filename, gap)
k = LDPC_matrix_object.k()
enc = map((lambda a: fec.ldpc_par_mtrx_encoder.make_H(LDPC_matrix_object)), range(0,1))
- dec = map((lambda a: fec.ldpc_bit_flip_decoder.make(LDPC_matrix_object.get_base_ptr())), range(0,1))
+ dec = map((lambda a: fec.ldpc_bit_flip_decoder.make(LDPC_matrix_object.get_base_sptr())), range(0,1))
threading = None
self.test = _qa_helper(10*k, enc, dec, threading)
self.tb.connect(self.test)
@@ -116,7 +116,7 @@ class test_fecapi_ldpc(gr_unittest.TestCase):
LDPC_matrix_object = fec.ldpc_H_matrix(filename, gap)
k = LDPC_matrix_object.k()
enc = map((lambda a: fec.ldpc_par_mtrx_encoder.make_H(LDPC_matrix_object)), range(0,1))
- dec = map((lambda a: fec.ldpc_bit_flip_decoder.make(LDPC_matrix_object.get_base_ptr())), range(0,1))
+ dec = map((lambda a: fec.ldpc_bit_flip_decoder.make(LDPC_matrix_object.get_base_sptr())), range(0,1))
threading = 'ordinary'
self.test = _qa_helper(10*k, enc, dec, threading)
self.tb.connect(self.test)
@@ -133,7 +133,7 @@ class test_fecapi_ldpc(gr_unittest.TestCase):
LDPC_matrix_object = fec.ldpc_H_matrix(filename, gap)
k = LDPC_matrix_object.k()
enc = map((lambda a: fec.ldpc_par_mtrx_encoder.make_H(LDPC_matrix_object)), range(0,1))
- dec = map((lambda a: fec.ldpc_bit_flip_decoder.make(LDPC_matrix_object.get_base_ptr())), range(0,1))
+ dec = map((lambda a: fec.ldpc_bit_flip_decoder.make(LDPC_matrix_object.get_base_sptr())), range(0,1))
threading = 'capillary'
self.test = _qa_helper(10*k, enc, dec, threading)
self.tb.connect(self.test)
@@ -157,7 +157,7 @@ class test_fecapi_ldpc(gr_unittest.TestCase):
dec = []
for n in range(0,dims):
H = fec.ldpc_H_matrix(filename, gap)
- dec.append(fec.ldpc_bit_flip_decoder.make(H.get_base_ptr()))
+ dec.append(fec.ldpc_bit_flip_decoder.make(H.get_base_sptr()))
k = 27
threading = 'ordinary'
@@ -177,7 +177,7 @@ class test_fecapi_ldpc(gr_unittest.TestCase):
# LDPC_matrix_object = fec.ldpc_H_matrix(filename, gap)
# k = LDPC_matrix_object.k()
# enc = map((lambda a: fec.ldpc_par_mtrx_encoder.make_H(LDPC_matrix_object)), range(0,dims))
-# dec = map((lambda a: fec.ldpc_bit_flip_decoder.make(LDPC_matrix_object.get_base_ptr())), range(0,dims))
+# dec = map((lambda a: fec.ldpc_bit_flip_decoder.make(LDPC_matrix_object.get_base_sptr())), range(0,dims))
# threading = 'capillary'
# self.test = _qa_helper(dims*k, enc, dec, threading)
# self.tb.connect(self.test)
@@ -206,7 +206,7 @@ class test_fecapi_ldpc(gr_unittest.TestCase):
# LDPC_matrix_object = fec.ldpc_H_matrix(filename, gap)
# k = LDPC_matrix_object.k()
# # enc = map((lambda a: fec.ldpc_encoder_make(LDPC_matrix_object)), range(0,dims))
-# dec = map((lambda a: fec.ldpc_bit_flip_decoder.make(LDPC_matrix_object.get_base_ptr())), range(0,dims))
+# dec = map((lambda a: fec.ldpc_bit_flip_decoder.make(LDPC_matrix_object.get_base_sptr())), range(0,dims))
# threading = 'capillary'
# self.assertRaises(AttributeError, lambda: extended_decoder(dec, threading=threading, puncpat="11"))
#
@@ -244,7 +244,7 @@ class test_fecapi_ldpc(gr_unittest.TestCase):
# k = LDPC_matrix_object.k()
# dims1 = 16
# dims2 = 16
-# dec = map((lambda b: map((lambda a: fec.ldpc_bit_flip_decoder.make(LDPC_matrix_object.get_base_ptr())), range(0,dims1))), range(0,dims2))
+# dec = map((lambda b: map((lambda a: fec.ldpc_bit_flip_decoder.make(LDPC_matrix_object.get_base_sptr())), range(0,dims1))), range(0,dims2))
# threading = 'capillary'
#
# self.assertRaises(AttributeError, lambda: extended_decoder(dec, threading=threading, puncpat="11"))
diff --git a/gr-fec/swig/ldpc.i b/gr-fec/swig/ldpc.i
index 48f0417467..27ee80d523 100644
--- a/gr-fec/swig/ldpc.i
+++ b/gr-fec/swig/ldpc.i
@@ -21,6 +21,7 @@
*/
%template(matrix_sptr) boost::shared_ptr<gr::fec::code::matrix>;
+%template(fec_mtrx_sptr) boost::shared_ptr<gr::fec::code::fec_mtrx>;
%template(ldpc_H_matrix_sptr) boost::shared_ptr<gr::fec::code::ldpc_H_matrix>;
%pythoncode %{