diff options
author | Andrej Rode <mail@andrejro.de> | 2018-06-23 23:41:42 +0200 |
---|---|---|
committer | Andrej Rode <mail@andrejro.de> | 2018-06-24 00:03:35 +0200 |
commit | 167a6152bad060fc53dd29e0fa79ef83eff1be5b (patch) | |
tree | a01049672d9d7d1bf3d295ed96698a323941f8e8 /gr-fec/python | |
parent | 3c8e6008b092287246234001db7cf1a4038300da (diff) | |
parent | fcd002b6ac82e1e0c1224e24506410ff0833e1aa (diff) |
Merge branch 'python3_fix' into next
Manual merge conflict resolution has been applied to following
conflicts:
* Typos:
* gnuradio-runtime/python/gnuradio/ctrlport/GrDataPlotter.py
* gr-blocks/python/blocks/qa_wavfile.py
* gr-filter/examples/gr_filtdes_api.py
* grc/blocks/parameter.xml
* gr-uhd/python/uhd/__init__.py
* ValueError -> RuntimeError:
* gr-blocks/python/blocks/qa_hier_block2.py
* relative Imports & other Py3k:
* gr-digital/python/digital/psk_constellations.py
* gr-digital/python/digital/qam_constellations.py
* gr-digital/python/digital/test_soft_decisions.py
* gr-digital/python/digital/gfsk.py
* SequenceCompleter:
* gr-utils/python/modtool/modtool_add.py
* gr-utils/python/modtool/modtool_rename.py
* gr-utils/python/modtool/modtool_rm.py
* Updated API on next:
* gr-blocks/grc/blocks_file_source.xml
* gr-blocks/python/blocks/qa_file_source_sink.py
* gr-qtgui/grc/qtgui_time_sink_x.xml
* GRC Py3k Updates:
* grc/core/Block.py
* grc/core/Constants.py
* grc/core/Platform.py
* grc/core/utils/odict.py
* grc/gui/Actions.py
* grc/gui/Block.py
* grc/gui/Executor.py
* grc/gui/Port.py
Diffstat (limited to 'gr-fec/python')
41 files changed, 574 insertions, 432 deletions
diff --git a/gr-fec/python/fec/CMakeLists.txt b/gr-fec/python/fec/CMakeLists.txt index 9d170b0423..013b3521a9 100644 --- a/gr-fec/python/fec/CMakeLists.txt +++ b/gr-fec/python/fec/CMakeLists.txt @@ -67,7 +67,7 @@ endif(NOT GSL_FOUND) foreach(py_qa_test_file ${py_qa_test_files}) get_filename_component(py_qa_test_name ${py_qa_test_file} NAME_WE) - GR_ADD_TEST(${py_qa_test_name} ${QA_PYTHON_EXECUTABLE} ${PYTHON_DASH_B} ${py_qa_test_file}) + GR_ADD_TEST(${py_qa_test_name} ${QA_PYTHON_EXECUTABLE} -B ${py_qa_test_file}) endforeach(py_qa_test_file) endif(ENABLE_TESTING) diff --git a/gr-fec/python/fec/LDPC/Generate_LDPC_matrix.py b/gr-fec/python/fec/LDPC/Generate_LDPC_matrix.py index a3862a6fda..8c5b17bc43 100644 --- a/gr-fec/python/fec/LDPC/Generate_LDPC_matrix.py +++ b/gr-fec/python/fec/LDPC/Generate_LDPC_matrix.py @@ -20,7 +20,12 @@ # Boston, MA 02110-1301, USA. # -from Generate_LDPC_matrix_functions import * +from __future__ import print_function +from __future__ import absolute_import +from __future__ import division +from __future__ import unicode_literals + +from .Generate_LDPC_matrix_functions import * # This is an example of how to generate a parity check matrix for # use with the LDPC Richardson Urbanke encoder. A significant amount @@ -62,18 +67,18 @@ newH = get_full_rank_H_matrix(parity_check_matrix.H) # can take a while... [bestH,g] = get_best_matrix(newH,100) -# Print out some of the resulting properties. +# Print(out some of the resulting properties.) n = bestH.shape[1] k = n - bestH.shape[0] -print "Parity check matrix properties:" -print "\tSize :", bestH.shape -print "\tRank :", linalg.matrix_rank(bestH) -print "\tRate : %.3f" % ((k*1.0)/n) -print "\tn :", n, " (codeword length)" -print "\tk :", k, " (info word length)" -print "\tgap : %i" % g +print("Parity check matrix properties:") +print("\tSize :", bestH.shape) +print("\tRank :", linalg.matrix_rank(bestH)) +print("\tRate : %.3f" % ((k*1.0) / n)) +print("\tn :", n, " (codeword length)") +print("\tk :", k, " (info word length)") +print("\tgap : %i" % g) # Save the matrix to an alist file for future use: alist_filename = "n_%04i_k_%04i_gap_%02i.alist" % (n,k,g) write_alist_file(alist_filename,bestH) -print '\nMatrix saved to alist file:', alist_filename, "\n" +print('\nMatrix saved to alist file:', alist_filename, "\n") diff --git a/gr-fec/python/fec/LDPC/Generate_LDPC_matrix_functions.py b/gr-fec/python/fec/LDPC/Generate_LDPC_matrix_functions.py index 589595bbd5..6cf0dee09e 100644 --- a/gr-fec/python/fec/LDPC/Generate_LDPC_matrix_functions.py +++ b/gr-fec/python/fec/LDPC/Generate_LDPC_matrix_functions.py @@ -20,6 +20,10 @@ # Boston, MA 02110-1301, USA. # +from __future__ import print_function +from __future__ import division +from __future__ import unicode_literals + import string, sys from numpy import * from numpy.random import shuffle, randint @@ -46,9 +50,9 @@ def read_alist_file(filename): indices = string.split(data[lineNumber]) for index in indices: H[int(index)-1,lineNumber-4] = 1 - # The subsequent lines in the file list the indices for where - # the 1s are in the rows, but this is redundant - # information. + # The subsequent lines in the file list the indices for where + # the 1s are in the rows, but this is redundant + # information. return H @@ -68,7 +72,7 @@ def write_alist_file(filename, H, verbose=0): numRows = H.shape[0] numCols = H.shape[1] - tempstring = `numCols` + ' ' + `numRows` + '\n' + tempstring = repr(numCols) + ' ' + repr(numRows) + '\n' myfile.write(tempstring) tempstring1 = '' @@ -79,12 +83,12 @@ def write_alist_file(filename, H, verbose=0): rowWeight = nonzeros.shape[1] if rowWeight > maxRowWeight: maxRowWeight = rowWeight - tempstring1 = tempstring1 + `rowWeight` + ' ' + tempstring1 = tempstring1 + repr(rowWeight) + ' ' for tempArray in nonzeros: for index in tempArray: - tempstring2 = tempstring2 + `index+1` + ' ' - tempstring2 = tempstring2 + '\n' - tempstring1 = tempstring1 + '\n' + tempstring2 = tempstring2 + repr(index+1) + ' ' + tempstring2 = tempstring2 + '\n' + tempstring1 = tempstring1 + '\n' tempstring3 = '' tempstring4 = '' @@ -94,14 +98,14 @@ def write_alist_file(filename, H, verbose=0): colWeight = nonzeros.shape[1] if colWeight > maxColWeight: maxColWeight = colWeight - tempstring3 = tempstring3 + `colWeight` + ' ' + tempstring3 = tempstring3 + repr(colWeight) + ' ' for tempArray in nonzeros: for index in tempArray: - tempstring4 = tempstring4 + `index+1` + ' ' - tempstring4 = tempstring4 + '\n' - tempstring3 = tempstring3 + '\n' + tempstring4 = tempstring4 + repr(index+1) + ' ' + tempstring4 = tempstring4 + '\n' + tempstring3 = tempstring3 + '\n' - tempstring = `maxColWeight` + ' ' + `maxRowWeight` + '\n' + tempstring = repr(maxColWeight) + ' ' + repr(maxRowWeight) + '\n' # write out max column and row weights myfile.write(tempstring) # write out all of the column weights @@ -116,11 +120,11 @@ def write_alist_file(filename, H, verbose=0): myfile.close() -class LDPC_matrix: +class LDPC_matrix(object): """ Class for a LDPC parity check matrix """ def __init__(self, alist_filename = None, - n_p_q = None, - H_matrix = None): + n_p_q = None, + H_matrix = None): if (alist_filename != None): self.H = self.read_alist_file(alist_filename) elif (n_p_q != None): @@ -128,9 +132,9 @@ class LDPC_matrix: elif (H_matrix != None): self.H = H_matrix else: - print 'Error: provide either an alist filename,', - print 'parameters for constructing regular LDPC parity', - print 'check matrix, or a numpy array.' + print('Error: provide either an alist filename, ', end='') + print('parameters for constructing regular LDPC parity, ', end='') + print('check matrix, or a numpy array.') self.rank = linalg.matrix_rank(self.H) self.numRows = self.H.shape[0] @@ -159,31 +163,31 @@ class LDPC_matrix: # For this algorithm, n/p must be an integer, because the # number of rows in each submatrix must be a whole number. - ratioTest = (n*1.0)/q + ratioTest = (n*1.0) / q if ratioTest%1 != 0: - print '\nError in regular_LDPC_code_contructor: The' - print 'ratio of inputs n/q must be a whole number.\n' + print('\nError in regular_LDPC_code_contructor: The ', end='') + print('ratio of inputs n/q must be a whole number.\n') return # First submatrix first: - m = (n*p)/q # number of rows in H matrix - submatrix1 = zeros((m/p,n)) - for row in arange(m/p): + m = (n*p) / q # number of rows in H matrix + submatrix1 = zeros((m / p,n)) + for row in arange(m / p): range1 = row*q range2 = (row+1)*q submatrix1[row,range1:range2] = 1 - H = submatrix1 + H = submatrix1 # Create the other submatrices and vertically stack them on. submatrixNum = 2 newColumnOrder = arange(n) while submatrixNum <= p: - submatrix = zeros((m/p,n)) + submatrix = zeros((m / p,n)) shuffle(newColumnOrder) for columnNum in arange(n): submatrix[:,columnNum] = \ - submatrix1[:,newColumnOrder[columnNum]] + submatrix1[:,newColumnOrder[columnNum]] H = vstack((H,submatrix)) submatrixNum = submatrixNum + 1 @@ -197,14 +201,14 @@ class LDPC_matrix: for rowNum in arange(rows): nonzeros = array(H[rowNum,:].nonzero()) if nonzeros.shape[1] != q: - print 'Row', rowNum, 'has incorrect weight!' + print('Row', rowNum, 'has incorrect weight!') return # Check the column weights for columnNum in arange(cols): nonzeros = array(H[:,columnNum].nonzero()) if nonzeros.shape[1] != p: - print 'Row', columnNum, 'has incorrect weight!' + print('Row', columnNum, 'has incorrect weight!') return return H @@ -221,10 +225,10 @@ def greedy_upper_triangulation(H, verbose=0): # Per email from Dr. Urbanke, author of this textbook, this # algorithm requires H to be full rank if linalg.matrix_rank(H_t) != H_t.shape[0]: - print 'Rank of H:', linalg.matrix_rank(tempArray) - print 'H has', H_t.shape[0], 'rows' - print 'Error: H must be full rank.' - return + print('Rank of H:', linalg.matrix_rank(tempArray)) + print('H has', H_t.shape[0], 'rows') + print('Error: H must be full rank.') + return size = H_t.shape n = size[1] @@ -253,7 +257,7 @@ def greedy_upper_triangulation(H, verbose=0): # equal to the min positive residual degree, then pick a # random column c. indices = (minResidualDegrees == minimumResidualDegree)\ - .nonzero()[1] + .nonzero()[1] indices = indices + t if indices.shape[0] == 1: columnC = indices[0] @@ -282,7 +286,7 @@ def greedy_upper_triangulation(H, verbose=0): else: # This is the 'choose' case. rowsThatContainNonZeros = H_residual[:,columnC-t]\ - .nonzero()[0] + .nonzero()[0] # Swap column c with column t. (Book says t+1 but we # index from 0, not 1.) @@ -315,8 +319,8 @@ def greedy_upper_triangulation(H, verbose=0): while sub_index < (m - rowInH_t): Htemp[m-sub_index-1,:] = H_t[m-sub_index,:] sub_index = sub_index+1 - H_t = Htemp.copy() - Htemp = H_t.copy() + H_t = Htemp.copy() + Htemp = H_t.copy() # Save temp H as new H_t. H_t = Htemp.copy() @@ -327,7 +331,7 @@ def greedy_upper_triangulation(H, verbose=0): if g == 0: if verbose: - print 'Error: gap is 0.' + print('Error: gap is 0.') return # We need to ensure phi is nonsingular. @@ -348,22 +352,22 @@ def greedy_upper_triangulation(H, verbose=0): except linalg.linalg.LinAlgError: # Phi is singular if verbose > 1: - print 'Initial phi is singular' + print('Initial phi is singular') else: # Phi is nonsingular, so we need to use this version of H. if verbose > 1: - print 'Initial phi is nonsingular' + print('Initial phi is nonsingular') return [H_t, g, t] else: if verbose: - print 'Initial phi is all zeros:\n', phi + print('Initial phi is all zeros:\n', phi) # If the C and D submatrices are all zeros, there is no point in # shuffling them around in an attempt to find a good phi. if not (C.any() or D.any()): if verbose: - print 'C and D are all zeros. There is no hope in', - print 'finding a nonsingular phi matrix. ' + print('C and D are all zeros. There is no hope in',) + print('finding a nonsingular phi matrix. ') return # We can't look at every row/column permutation possibility @@ -378,8 +382,8 @@ def greedy_upper_triangulation(H, verbose=0): while iterationCount < maxIterations: if verbose > 1: - print 'iterationCount:', iterationCount - tempH = H_t.copy() + print('iterationCount:', iterationCount) + tempH = H_t.copy() shuffle(columnsToShuffle) shuffle(rowsToShuffle) @@ -387,7 +391,7 @@ def greedy_upper_triangulation(H, verbose=0): for newDestinationColumnNumber in arange(t,n): oldColumnNumber = columnsToShuffle[index] tempH[:,newDestinationColumnNumber] = \ - H_t[:,oldColumnNumber] + H_t[:,oldColumnNumber] index +=1 tempH2 = tempH.copy() @@ -414,23 +418,23 @@ def greedy_upper_triangulation(H, verbose=0): except linalg.linalg.LinAlgError: # Phi is singular if verbose > 1: - print 'Phi is still singular' + print('Phi is still singular') else: # Phi is nonsingular, so we're done. if verbose: - print 'Found a nonsingular phi on', - print 'iterationCount = ', iterationCount + print('Found a nonsingular phi on',) + print('iterationCount = ', iterationCount) return [H_t, g, t] else: if verbose > 1: - print 'phi is all zeros' + print('phi is all zeros') iterationCount +=1 # If we've reached this point, then we haven't found a # version of H that has a nonsingular phi. if verbose: - print '--- Error: nonsingular phi matrix not found.' + print('--- Error: nonsingular phi matrix not found.') def inv_mod2(squareMatrix, verbose=0): """ @@ -468,16 +472,16 @@ def inv_mod2(squareMatrix, verbose=0): tempTest[rowNum,colNum] = 0 else: if verbose > 1: - print 'In inv_mod2. Rounding error on this', - print 'value? Mod 2 has already been done.', - print 'value:', value + print('In inv_mod2. Rounding error on this',) + print('value? Mod 2 has already been done.',) + print('value:', value) test = tempTest.copy() if (test - eye(t,t) % 2).any(): if verbose: - print 'Error in inv_mod2: did not find inverse.' - # TODO is this the most appropriate error to raise? + print('Error in inv_mod2: did not find inverse.') + # TODO is this the most appropriate error to raise? raise linalg.linalg.LinAlgError else: return C @@ -520,7 +524,7 @@ def get_full_rank_H_matrix(H, verbose=False): tempArray = H.copy() if linalg.matrix_rank(tempArray) == tempArray.shape[0]: if verbose: - print 'Returning H; it is already full rank.' + print('Returning H; it is already full rank.') return tempArray numRows = tempArray.shape[0] @@ -538,8 +542,8 @@ def get_full_rank_H_matrix(H, verbose=False): while i < limit: if verbose: - print 'In get_full_rank_H_matrix; i:', i - # Flag indicating that the row contains a non-zero entry + print('In get_full_rank_H_matrix; i:', i) + # Flag indicating that the row contains a non-zero entry found = False for j in arange(i, numColumns): if tempArray[i, j] == 1: @@ -588,8 +592,8 @@ def get_full_rank_H_matrix(H, verbose=False): newH[:,index] = tempHarray[:,columnOrder[0,index]] if verbose: - print 'original H.shape:', H.shape - print 'newH.shape:', newH.shape + print('original H.shape:', H.shape) + print('newH.shape:', newH.shape) return newH @@ -604,13 +608,13 @@ def get_best_matrix(H, numIterations=100, verbose=False): index = 1 while index <= numIterations: if verbose: - print '--- In get_best_matrix, iteration:', index - index += 1 + print('--- In get_best_matrix, iteration:', index) + index += 1 try: ret = greedy_upper_triangulation(H, verbose) - except ValueError, e: + except ValueError as e: if verbose > 1: - print 'greedy_upper_triangulation error: ', e + print('greedy_upper_triangulation error: ', e) else: if ret: [betterH, gap, t] = ret @@ -632,8 +636,8 @@ def get_best_matrix(H, numIterations=100, verbose=False): return [bestH, bestGap] else: if verbose: - print 'Error: Could not find appropriate H form', - print 'for encoding.' + print('Error: Could not find appropriate H form',) + print('for encoding.') return def getSystematicGmatrix(GenMatrix): @@ -643,7 +647,7 @@ def getSystematicGmatrix(GenMatrix): matrix and P is the parity submatrix. If the GenMatrix matrix provided is not full rank, then dependent rows will be deleted. - This function does not convert parity check (H) matrices to the + This function does not convert parity check (H) matrices to the generator matrix format. Use the function getSystematicGmatrixFromH for that purpose. """ @@ -682,7 +686,7 @@ def getSystematicGmatrix(GenMatrix): tempArray = move_row_to_bottom(i,tempArray) # decrease limit since we just found a row of 0s limit -= 1 - # the rows below i are the dependent rows, which we discard + # the rows below i are the dependent rows, which we discard G = tempArray[0:i,:] return G @@ -696,7 +700,7 @@ def getSystematicGmatrixFromH(H, verbose=False): will be deleted first. """ if verbose: - print 'received H with size: ', H.shape + print('received H with size: ', H.shape) # First, put the H matrix into the form H = [I|m] where: # I is (n-k) x (n-k) identity matrix @@ -716,5 +720,5 @@ def getSystematicGmatrixFromH(H, verbose=False): k = m.shape[1] G = concatenate((identity(k),m.T),axis=1) if verbose: - print 'returning G with size: ', G.shape - return G
\ No newline at end of file + print('returning G with size: ', G.shape) + return G diff --git a/gr-fec/python/fec/LDPC/__init__.py b/gr-fec/python/fec/LDPC/__init__.py index 173171a24f..7ee9196d12 100644 --- a/gr-fec/python/fec/LDPC/__init__.py +++ b/gr-fec/python/fec/LDPC/__init__.py @@ -1,3 +1,5 @@ +from __future__ import absolute_import +from __future__ import unicode_literals # # Copyright 2015 Free Software Foundation, Inc. # @@ -19,4 +21,4 @@ # Boston, MA 02110-1301, USA. # -from Generate_LDPC_matrix_functions import * +from .Generate_LDPC_matrix_functions import * diff --git a/gr-fec/python/fec/__init__.py b/gr-fec/python/fec/__init__.py index 6c82232d4f..e5458686dc 100644 --- a/gr-fec/python/fec/__init__.py +++ b/gr-fec/python/fec/__init__.py @@ -23,25 +23,28 @@ Blocks for forward error correction. ''' +from __future__ import absolute_import +from __future__ import unicode_literals + try: - from fec_swig import * + from .fec_swig import * except ImportError: import os dirname, filename = os.path.split(os.path.abspath(__file__)) __path__.append(os.path.join(dirname, "..", "..", "swig")) - from fec_swig import * + from .fec_swig import * -from bitflip import * -from extended_encoder import extended_encoder -from extended_decoder import extended_decoder -from threaded_encoder import threaded_encoder -from threaded_decoder import threaded_decoder -from capillary_threaded_decoder import capillary_threaded_decoder -from capillary_threaded_encoder import capillary_threaded_encoder -from extended_async_encoder import extended_async_encoder -from extended_tagged_encoder import extended_tagged_encoder -from extended_tagged_decoder import extended_tagged_decoder +from .bitflip import * +from .extended_encoder import extended_encoder +from .extended_decoder import extended_decoder +from .threaded_encoder import threaded_encoder +from .threaded_decoder import threaded_decoder +from .capillary_threaded_decoder import capillary_threaded_decoder +from .capillary_threaded_encoder import capillary_threaded_encoder +from .extended_async_encoder import extended_async_encoder +from .extended_tagged_encoder import extended_tagged_encoder +from .extended_tagged_decoder import extended_tagged_decoder -from fec_test import fec_test -from bercurve_generator import bercurve_generator +from .fec_test import fec_test +from .bercurve_generator import bercurve_generator diff --git a/gr-fec/python/fec/_qa_helper.py b/gr-fec/python/fec/_qa_helper.py index 8722453441..85a19ed7c5 100755..100644 --- a/gr-fec/python/fec/_qa_helper.py +++ b/gr-fec/python/fec/_qa_helper.py @@ -20,12 +20,19 @@ # Boston, MA 02110-1301, USA. # -from gnuradio import blocks -from gnuradio import gr -import sys, numpy +from __future__ import print_function +from __future__ import absolute_import +from __future__ import unicode_literals + + +import numpy + +from gnuradio import gr, blocks +# Must use absolute import here because this file is not installed as part +# of the module +from gnuradio.fec import extended_encoder +from gnuradio.fec import extended_decoder -from extended_encoder import extended_encoder -from extended_decoder import extended_decoder class map_bb(gr.sync_block): def __init__(self, bitmap): @@ -37,7 +44,7 @@ class map_bb(gr.sync_block): self.bitmap = bitmap def work(self, input_items, output_items): - output_items[0][:] = map(lambda x: self.bitmap[x], input_items[0]) + output_items[0][:] = [self.bitmap[x] for x in input_items[0]] return len(output_items[0]) @@ -85,6 +92,6 @@ if __name__ == '__main__': errs += 1 if errs == 0: - print "Decoded properly" + print("Decoded properly") else: - print "Problem Decoding" + print("Problem Decoding") diff --git a/gr-fec/python/fec/bercurve_generator.py b/gr-fec/python/fec/bercurve_generator.py index 3221a683ce..29a02c135a 100644 --- a/gr-fec/python/fec/bercurve_generator.py +++ b/gr-fec/python/fec/bercurve_generator.py @@ -20,10 +20,12 @@ # Boston, MA 02110-1301, USA. # +from __future__ import absolute_import +from __future__ import unicode_literals from gnuradio import gr, blocks import numpy -from fec_test import fec_test +from .fec_test import fec_test class bercurve_generator(gr.hier_block2): @@ -40,7 +42,7 @@ class bercurve_generator(gr.hier_block2): self.decoder_list = decoder_list self.puncpat = puncpat - self.random_gen_b_0 = blocks.vector_source_b(map(int, numpy.random.randint(0, 256, 100000)), True) + self.random_gen_b_0 = blocks.vector_source_b(list(map(int, numpy.random.randint(0, 256, 100000))), True) self.deinterleave = blocks.deinterleave(gr.sizeof_char*1) self.connect(self.random_gen_b_0, self.deinterleave) self.ber_generators = [] diff --git a/gr-fec/python/fec/bitflip.py b/gr-fec/python/fec/bitflip.py index 235dc19a05..332a288e7e 100644 --- a/gr-fec/python/fec/bitflip.py +++ b/gr-fec/python/fec/bitflip.py @@ -20,6 +20,11 @@ # Boston, MA 02110-1301, USA. # +from __future__ import division +from __future__ import unicode_literals + + + def bitreverse(mint): res = 0; while mint != 0: @@ -51,7 +56,7 @@ def read_bitlist(bitlist): def read_big_bitlist(bitlist): ret = [] - for j in range(0, len(bitlist)/64): + for j in range(0, len(bitlist) / 64): res = 0; for i in range(0, 64): if int(bitlist[j*64+i]) == 1: @@ -72,9 +77,9 @@ def generate_symmetries(symlist): for i in range(len(symlist[0])): retlist.append(symlist[0][i:] + symlist[0][0:i]); invlist = symlist[0]; - for i in range(1, len(symlist[0])/2): - invlist[i] = symlist[0][i + len(symlist[0])/2]; - invlist[i + len(symlist[0])/2] = symlist[0][i]; + for i in range(1, len(symlist[0]) / 2): + invlist[i] = symlist[0][i + len(symlist[0]) / 2]; + invlist[i + len(symlist[0]) / 2] = symlist[0][i]; for i in range(len(symlist[0])): retlist.append(symlist[0][i:] + symlist[0][0:i]); return retlist; diff --git a/gr-fec/python/fec/capillary_threaded_decoder.py b/gr-fec/python/fec/capillary_threaded_decoder.py index 9a00cde192..821e3cf92a 100644 --- a/gr-fec/python/fec/capillary_threaded_decoder.py +++ b/gr-fec/python/fec/capillary_threaded_decoder.py @@ -20,10 +20,15 @@ # Boston, MA 02110-1301, USA. # -from gnuradio import gr, blocks -import fec_swig as fec +from __future__ import division +from __future__ import unicode_literals + import math +from gnuradio import gr, blocks +from . import fec_swig as fec + + class capillary_threaded_decoder(gr.hier_block2): def __init__(self, decoder_list_0, input_size, output_size): gr.hier_block2.__init__( @@ -64,7 +69,7 @@ class capillary_threaded_decoder(gr.hier_block2): branchcount += 2 codercount = 0 - for i in range(len(decoder_list_0)/2): + for i in range(len(decoder_list_0) // 2): self.connect((self.deinterleaves_0[rootcount], 0), (self.generic_decoders_0[codercount], 0)) self.connect((self.deinterleaves_0[rootcount], 1), (self.generic_decoders_0[codercount + 1], 0)) rootcount += 1 @@ -80,7 +85,7 @@ class capillary_threaded_decoder(gr.hier_block2): branchcount += 2 codercount = 0 - for i in range(len(decoder_list_0)/2): + for i in range(len(decoder_list_0) // 2): self.connect((self.generic_decoders_0[codercount], 0), (self.interleaves_0[rootcount], 0)) self.connect((self.generic_decoders_0[codercount + 1], 0), (self.interleaves_0[rootcount], 1)) rootcount += 1 diff --git a/gr-fec/python/fec/capillary_threaded_encoder.py b/gr-fec/python/fec/capillary_threaded_encoder.py index 21d4af62ca..899d10c3b7 100644 --- a/gr-fec/python/fec/capillary_threaded_encoder.py +++ b/gr-fec/python/fec/capillary_threaded_encoder.py @@ -20,10 +20,15 @@ # Boston, MA 02110-1301, USA. # -from gnuradio import gr, blocks -import fec_swig as fec +from __future__ import division +from __future__ import unicode_literals + import math +from gnuradio import gr, blocks +from . import fec_swig as fec + + class capillary_threaded_encoder(gr.hier_block2): def __init__(self, encoder_list_0, input_size=gr.sizeof_char, output_size=gr.sizeof_char): gr.hier_block2.__init__(self, "Capillary Threaded Encoder", @@ -43,7 +48,7 @@ class capillary_threaded_encoder(gr.hier_block2): self.deinterleaves_0.append(blocks.deinterleave(input_size, fec.get_encoder_input_size(encoder_list_0[0]))) - self.generic_encoders_0 = []; + self.generic_encoders_0 = []; for i in range(len(encoder_list_0)): self.generic_encoders_0.append(fec.encoder(encoder_list_0[i], input_size, output_size)) @@ -64,7 +69,7 @@ class capillary_threaded_encoder(gr.hier_block2): branchcount += 2; codercount = 0; - for i in range(len(encoder_list_0)/2): + for i in range(len(encoder_list_0) // 2): self.connect((self.deinterleaves_0[rootcount], 0), (self.generic_encoders_0[codercount], 0)) self.connect((self.deinterleaves_0[rootcount], 1), (self.generic_encoders_0[codercount + 1], 0)) rootcount += 1; @@ -82,13 +87,13 @@ class capillary_threaded_encoder(gr.hier_block2): codercount = 0; - for i in range(len(encoder_list_0)/2): + for i in range(len(encoder_list_0) // 2): self.connect((self.generic_encoders_0[codercount], 0), (self.interleaves_0[rootcount], 0)) self.connect((self.generic_encoders_0[codercount + 1], 0), (self.interleaves_0[rootcount], 1)) rootcount += 1; codercount += 2; - if((len(self.encoder_list_0)) > 1): + if((len(self.encoder_list_0)) > 1): self.connect((self, 0), (self.deinterleaves_0[0], 0)) self.connect((self.interleaves_0[0], 0), (self, 0)) else: diff --git a/gr-fec/python/fec/extended_async_encoder.py b/gr-fec/python/fec/extended_async_encoder.py index fffe64aeb8..cebd5c652b 100644 --- a/gr-fec/python/fec/extended_async_encoder.py +++ b/gr-fec/python/fec/extended_async_encoder.py @@ -20,11 +20,18 @@ # Boston, MA 02110-1301, USA. # -from gnuradio import gr -import fec_swig as fec -from bitflip import read_bitlist +from __future__ import print_function +from __future__ import absolute_import +from __future__ import unicode_literals + import weakref +from gnuradio import gr + +from . import fec_swig as fec +from .bitflip import read_bitlist + + class extended_async_encoder(gr.hier_block2): def __init__(self, encoder_obj_list, puncpat=None): gr.hier_block2.__init__(self, "extended_async_encoder", diff --git a/gr-fec/python/fec/extended_decoder.py b/gr-fec/python/fec/extended_decoder.py index 7e6cf452f9..3c7ebefb49 100644 --- a/gr-fec/python/fec/extended_decoder.py +++ b/gr-fec/python/fec/extended_decoder.py @@ -20,24 +20,25 @@ # Boston, MA 02110-1301, USA. # -from gnuradio import gr, blocks -import fec_swig as fec -from bitflip import * -import sys +from __future__ import print_function +from __future__ import absolute_import +from __future__ import division +from __future__ import unicode_literals -if sys.modules.has_key("gnuradio.digital"): - digital = sys.modules["gnuradio.digital"] -else: - from gnuradio import digital +from gnuradio import gr, blocks, digital + +from . import fec_swig as fec + +from .bitflip import * +from .threaded_decoder import threaded_decoder +from .capillary_threaded_decoder import capillary_threaded_decoder -from threaded_decoder import threaded_decoder -from capillary_threaded_decoder import capillary_threaded_decoder class extended_decoder(gr.hier_block2): #solution to log_(1-2*t)(1-2*.0335) = 1/taps where t is thresh (syndrome density) #for i in numpy.arange(.1, .499, .01): - #print str(log((1-(2 * .035)), (1-(2 * i)))) + ':' + str(i); + #print(str(log((1-(2 * .035)), (1-(2 * i)))) + ':' + str(i);) garbletable = { 0.310786835319:0.1, 0.279118162802:0.11, @@ -127,13 +128,13 @@ class extended_decoder(gr.hier_block2): cat.append(i); synd_garble = .49 - idx_list = self.garbletable.keys() + idx_list = list(self.garbletable.keys()) idx_list.sort() for i in idx_list: - if 1.0/self.ann.count('1') >= i: + if 1.0 / self.ann.count('1') >= i: synd_garble = self.garbletable[i] - print 'using syndrom garble threshold ' + str(synd_garble) + 'for conv_bit_corr_bb' - print 'ceiling: .0335 data garble rate' + print('using syndrom garble threshold ' + str(synd_garble) + 'for conv_bit_corr_bb') + print('ceiling: .0335 data garble rate') self.blocks.append(fec.conv_bit_corr_bb(cat, len(puncpat) - puncpat.count('0'), len(ann), integration_period, flush, synd_garble)) diff --git a/gr-fec/python/fec/extended_encoder.py b/gr-fec/python/fec/extended_encoder.py index 1c6da0ecb1..992c2bdad4 100644 --- a/gr-fec/python/fec/extended_encoder.py +++ b/gr-fec/python/fec/extended_encoder.py @@ -20,12 +20,16 @@ # Boston, MA 02110-1301, USA. # +from __future__ import absolute_import +from __future__ import unicode_literals + from gnuradio import gr, blocks -import fec_swig as fec -from threaded_encoder import threaded_encoder -from capillary_threaded_encoder import capillary_threaded_encoder -from bitflip import read_bitlist +from . import fec_swig as fec +from .threaded_encoder import threaded_encoder +from .capillary_threaded_encoder import capillary_threaded_encoder +from .bitflip import read_bitlist + class extended_encoder(gr.hier_block2): def __init__(self, encoder_obj_list, threading, puncpat=None): diff --git a/gr-fec/python/fec/extended_tagged_decoder.py b/gr-fec/python/fec/extended_tagged_decoder.py index 9713907712..c119bf9938 100644 --- a/gr-fec/python/fec/extended_tagged_decoder.py +++ b/gr-fec/python/fec/extended_tagged_decoder.py @@ -20,21 +20,23 @@ # Boston, MA 02110-1301, USA. # -from gnuradio import gr, blocks -import fec_swig as fec -from bitflip import * -import sys +from __future__ import print_function +from __future__ import absolute_import +from __future__ import division +from __future__ import unicode_literals + +from gnuradio import gr, blocks, digital + +from . import fec_swig as fec + +from .bitflip import * -if sys.modules.has_key("gnuradio.digital"): - digital = sys.modules["gnuradio.digital"] -else: - from gnuradio import digital class extended_tagged_decoder(gr.hier_block2): #solution to log_(1-2*t)(1-2*.0335) = 1/taps where t is thresh (syndrome density) #for i in numpy.arange(.1, .499, .01): - #print str(log((1-(2 * .035)), (1-(2 * i)))) + ':' + str(i); + #print(str(log((1-(2 * .035)), (1-(2 * i)))) + ':' + str(i);) garbletable = { 0.310786835319:0.1, 0.279118162802:0.11, @@ -136,13 +138,13 @@ class extended_tagged_decoder(gr.hier_block2): cat.append(i); synd_garble = .49 - idx_list = self.garbletable.keys() + idx_list = list(self.garbletable.keys()) idx_list.sort() for i in idx_list: - if 1.0/self.ann.count('1') >= i: + if 1.0 / self.ann.count('1') >= i: synd_garble = self.garbletable[i] - print 'using syndrom garble threshold ' + str(synd_garble) + 'for conv_bit_corr_bb' - print 'ceiling: .0335 data garble rate' + print('using syndrom garble threshold ' + str(synd_garble) + 'for conv_bit_corr_bb') + print('ceiling: .0335 data garble rate') self.blocks.append(fec.conv_bit_corr_bb(cat, len(puncpat) - puncpat.count('0'), len(ann), integration_period, flush, synd_garble)) diff --git a/gr-fec/python/fec/extended_tagged_encoder.py b/gr-fec/python/fec/extended_tagged_encoder.py index d3cf1d80d2..9f4a684c4a 100644 --- a/gr-fec/python/fec/extended_tagged_encoder.py +++ b/gr-fec/python/fec/extended_tagged_encoder.py @@ -20,10 +20,16 @@ # Boston, MA 02110-1301, USA. # +from __future__ import absolute_import +from __future__ import unicode_literals + + from gnuradio import gr, blocks -import fec_swig as fec -from bitflip import read_bitlist +from . import fec_swig as fec + +from .bitflip import read_bitlist + class extended_tagged_encoder(gr.hier_block2): def __init__(self, encoder_obj_list, puncpat=None, lentagname=None, mtu=1500): diff --git a/gr-fec/python/fec/fec_test.py b/gr-fec/python/fec/fec_test.py index 6466a0bcb4..dfb5b1b28e 100644 --- a/gr-fec/python/fec/fec_test.py +++ b/gr-fec/python/fec/fec_test.py @@ -20,18 +20,21 @@ # Boston, MA 02110-1301, USA. # +from __future__ import absolute_import +from __future__ import division +from __future__ import unicode_literals from gnuradio.fec.bitflip import read_bitlist from gnuradio import gr, blocks, analog import math import sys -if sys.modules.has_key("gnuradio.digital"): +if "gnuradio.digital" in sys.modules: digital = sys.modules["gnuradio.digital"] else: from gnuradio import digital -from extended_encoder import extended_encoder -from extended_decoder import extended_decoder +from .extended_encoder import extended_encoder +from .extended_decoder import extended_decoder class fec_test(gr.hier_block2): @@ -64,7 +67,7 @@ class fec_test(gr.hier_block2): ann=None, puncpat=puncpat, integration_period=10000, rotator=None) - noise = math.sqrt((10.0**(-esno/10.0))/2.0) + noise = math.sqrt((10.0**(old_div(-esno / 10.0)),2.0)) #self.fastnoise = analog.fastnoise_source_f(analog.GR_GAUSSIAN, noise, seed, 8192) self.fastnoise = analog.noise_source_f(analog.GR_GAUSSIAN, noise, seed) self.addnoise = blocks.add_ff(1) diff --git a/gr-fec/python/fec/polar/CMakeLists.txt b/gr-fec/python/fec/polar/CMakeLists.txt index 1efed062ff..2c126746e7 100644 --- a/gr-fec/python/fec/polar/CMakeLists.txt +++ b/gr-fec/python/fec/polar/CMakeLists.txt @@ -27,6 +27,9 @@ GR_PYTHON_INSTALL( channel_construction_awgn.py channel_construction_bec.py helper_functions.py + encoder.py + decoder.py + common.py DESTINATION ${GR_PYTHON_DIR}/gnuradio/fec/polar ) diff --git a/gr-fec/python/fec/polar/__init__.py b/gr-fec/python/fec/polar/__init__.py index ce1b1459fb..e06020b886 100644 --- a/gr-fec/python/fec/polar/__init__.py +++ b/gr-fec/python/fec/polar/__init__.py @@ -21,9 +21,12 @@ # turn this folder into a Python module -import channel_construction as cc -from channel_construction_bec import bhattacharyya_bounds -from helper_functions import is_power_of_two +from __future__ import print_function +from __future__ import absolute_import +from __future__ import unicode_literals +from . import channel_construction as cc +from .channel_construction_bec import bhattacharyya_bounds +from .helper_functions import is_power_of_two CHANNEL_TYPE_AWGN = 'AWGN' diff --git a/gr-fec/python/fec/polar/channel_construction.py b/gr-fec/python/fec/polar/channel_construction.py index b7a3dee3bd..d3b33fe3ac 100644 --- a/gr-fec/python/fec/polar/channel_construction.py +++ b/gr-fec/python/fec/polar/channel_construction.py @@ -23,12 +23,14 @@ foundational paper for polar codes. ''' +from __future__ import print_function +from __future__ import absolute_import -from channel_construction_bec import calculate_bec_channel_capacities -from channel_construction_bec import design_snr_to_bec_eta -from channel_construction_bec import bhattacharyya_bounds -from channel_construction_awgn import tal_vardy_tpm_algorithm -from helper_functions import * +from .channel_construction_bec import calculate_bec_channel_capacities +from .channel_construction_bec import design_snr_to_bec_eta +from .channel_construction_bec import bhattacharyya_bounds +from .channel_construction_awgn import tal_vardy_tpm_algorithm +from .helper_functions import * Z_PARAM_FIRST_HEADER_LINE = "Bhattacharyya parameters (Z-parameters) for a polar code" @@ -117,7 +119,7 @@ def load_z_parameters(block_size, design_snr, mu): def main(): np.set_printoptions(precision=3, linewidth=150) - print 'channel construction Bhattacharyya bounds by Arikan' + print('channel construction Bhattacharyya bounds by Arikan') n = 10 m = 2 ** n k = m // 2 diff --git a/gr-fec/python/fec/polar/channel_construction_awgn.py b/gr-fec/python/fec/polar/channel_construction_awgn.py index 7d820b2883..c75f3d1c44 100755..100644 --- a/gr-fec/python/fec/polar/channel_construction_awgn.py +++ b/gr-fec/python/fec/polar/channel_construction_awgn.py @@ -18,6 +18,11 @@ # Boston, MA 02110-1301, USA. # +from __future__ import print_function +from __future__ import absolute_import +from __future__ import division +from __future__ import unicode_literals + ''' Based on 2 papers: [1] Ido Tal, Alexander Vardy: 'How To Construct Polar Codes', 2013 @@ -27,11 +32,10 @@ for an in-depth description of a widely used algorithm for channel construction. for an overview of different approaches ''' - from scipy.optimize import fsolve from scipy.special import erfc -from helper_functions import * -from channel_construction_bec import bhattacharyya_bounds +from .helper_functions import * +from .channel_construction_bec import bhattacharyya_bounds def solver_equation(val, s): @@ -190,7 +194,7 @@ def upper_convolve(tpm, mu): idx = -1 for i in range(mu): idx += 1 - q[0, idx] = (tpm[0, i] ** 2 + tpm[1, i] ** 2) / 2 + q[0, idx] = (tpm[0 / i] ** 2 + tpm[1, i] ** 2, 2) q[1, idx] = tpm[0, i] * tpm[1, i] for j in range(i + 1, mu): idx += 1 @@ -211,8 +215,8 @@ def lower_convolve(tpm, mu): idx = -1 for i in range(0, mu): idx += 1 - q[0, idx] = (tpm[0, i] ** 2) / 2 - q[1, idx] = (tpm[1, i] ** 2) / 2 + q[0, idx] = (tpm[0 / i] ** 2, 2) + q[1, idx] = (tpm[1 / i] ** 2, 2) if q[0, idx] < q[1, idx]: q[0, idx], q[1, idx] = swap_values(q[0, idx], q[1, idx]) idx += 1 @@ -249,7 +253,7 @@ def normalize_q(q, tpm): def main(): - print 'channel construction AWGN main' + print('channel construction AWGN main') n = 8 m = 2 ** n design_snr = 0.0 diff --git a/gr-fec/python/fec/polar/channel_construction_bec.py b/gr-fec/python/fec/polar/channel_construction_bec.py index acad720036..d0ca4f84ed 100644 --- a/gr-fec/python/fec/polar/channel_construction_bec.py +++ b/gr-fec/python/fec/polar/channel_construction_bec.py @@ -18,8 +18,13 @@ # Boston, MA 02110-1301, USA. # +from __future__ import print_function +from __future__ import absolute_import +from __future__ import division +from __future__ import unicode_literals + import numpy as np -import helper_functions as hf +from . import helper_functions as hf def bec_channel(eta): @@ -220,7 +225,7 @@ def plot_capacity_histogram(design_snr, save_file=None): def main(): - print 'channel construction main' + print('channel construction main') n = 11 block_size = int(2 ** n) design_snr = -1.59 diff --git a/gr-fec/python/fec/polar/common.py b/gr-fec/python/fec/polar/common.py index fa5987b6d2..8604f05ba1 100644 --- a/gr-fec/python/fec/polar/common.py +++ b/gr-fec/python/fec/polar/common.py @@ -18,16 +18,20 @@ # Boston, MA 02110-1301, USA. # +from __future__ import print_function +from __future__ import absolute_import +from __future__ import unicode_literals + import numpy as np -from helper_functions import * +from .helper_functions import * ''' PolarCommon holds value checks and common initializer code for both Encoder and Decoder. ''' -class PolarCommon: +class PolarCommon(object): def __init__(self, n, k, frozen_bit_position, frozenbits=None): if not is_power_of_two(n): raise ValueError("n={0} is not a power of 2!".format(n)) @@ -81,4 +85,4 @@ class PolarCommon: return self._encode_efficient(vec) def info_print(self): - print "POLAR code ({0}, {1})".format(self.N, self.K) + print("POLAR code ({0}, {1})".format(self.N, self.K)) diff --git a/gr-fec/python/fec/polar/decoder.py b/gr-fec/python/fec/polar/decoder.py index 8748d284f7..5acd04aa72 100644 --- a/gr-fec/python/fec/polar/decoder.py +++ b/gr-fec/python/fec/polar/decoder.py @@ -18,11 +18,16 @@ # Boston, MA 02110-1301, USA. # +from __future__ import print_function +from __future__ import absolute_import +from __future__ import division +from __future__ import unicode_literals + import numpy as np -from common import PolarCommon +from .common import PolarCommon # for dev -from encoder import PolarEncoder +from .encoder import PolarEncoder from matplotlib import pyplot as plt @@ -239,31 +244,31 @@ def test_reverse_enc_dec(): encoder = PolarEncoder(n, k, frozenbitposition, frozenbits) decoder = PolarDecoder(n, k, frozenbitposition, frozenbits) encoded = encoder.encode(bits) - print 'encoded:', encoded + print('encoded:', encoded) rx = decoder.decode(encoded) - print 'bits:', bits - print 'rx :', rx - print (bits == rx).all() + print('bits:', bits) + print('rx :', rx) + print((bits == rx).all()) def compare_decoder_impls(): - print '\nthis is decoder test' + print('\nthis is decoder test') n = 8 k = 4 frozenbits = np.zeros(n - k) # frozenbitposition16 = np.array((0, 1, 2, 3, 4, 5, 8, 9), dtype=int) frozenbitposition = np.array((0, 1, 2, 4), dtype=int) bits = np.random.randint(2, size=k) - print 'bits:', bits + print('bits:', bits) encoder = PolarEncoder(n, k, frozenbitposition, frozenbits) decoder = PolarDecoder(n, k, frozenbitposition, frozenbits) encoded = encoder.encode(bits) - print 'encoded:', encoded + print('encoded:', encoded) rx_st = decoder._lr_sc_decoder(encoded) rx_eff = decoder._lr_sc_decoder_efficient(encoded) - print 'standard :', rx_st - print 'efficient:', rx_eff - print (rx_st == rx_eff).all() + print('standard :', rx_st) + print('efficient:', rx_eff) + print((rx_st == rx_eff).all()) def main(): @@ -279,14 +284,14 @@ def main(): # decoder = PolarDecoder(n, k, frozenbitposition, frozenbits) # # bits = np.ones(k, dtype=int) - # print "bits: ", bits + # print("bits: ", bits) # evec = encoder.encode(bits) - # print "froz: ", encoder._insert_frozen_bits(bits) - # print "evec: ", evec + # print("froz: ", encoder._insert_frozen_bits(bits)) + # print("evec: ", evec) # # evec[1] = 0 # deced = decoder._lr_sc_decoder(evec) - # print 'SC decoded:', deced + # print('SC decoded:', deced) # # test_reverse_enc_dec() # compare_decoder_impls() diff --git a/gr-fec/python/fec/polar/encoder.py b/gr-fec/python/fec/polar/encoder.py index cc8fda2d1b..c5c7c05d5b 100644 --- a/gr-fec/python/fec/polar/encoder.py +++ b/gr-fec/python/fec/polar/encoder.py @@ -18,9 +18,13 @@ # Boston, MA 02110-1301, USA. # +from __future__ import print_function +from __future__ import absolute_import +from __future__ import unicode_literals + import numpy as np -from common import PolarCommon -import helper_functions as hf +from .common import PolarCommon +from . import helper_functions as hf class PolarEncoder(PolarCommon): @@ -99,8 +103,8 @@ def test_pseudo_rate_1_encoder(encoder, ntests, k): u_hat = encoder._encode_efficient(fenc) if not (u_hat == u).all(): print('rate-1 encoder/decoder failed') - print u - print u_hat + print(u) + print(u_hat) return False return True @@ -114,11 +118,11 @@ def test_encoder_impls(): # frozenbitposition8 = np.array((0, 1, 2, 4), dtype=int) # keep it! frozenbitposition = np.array((0, 1, 2, 3, 4, 5, 8, 9), dtype=int) encoder = PolarEncoder(n, k, frozenbitposition) #, frozenbits) - print 'result:', compare_results(encoder, ntests, k) + print('result:', compare_results(encoder, ntests, k)) print('Test rate-1 encoder/decoder chain results') r1_test = test_pseudo_rate_1_encoder(encoder, ntests, k) - print 'Test rate-1 encoder/decoder:', r1_test + print('Test rate-1 encoder/decoder:', r1_test) test_systematic_encoder(encoder, ntests, k) diff --git a/gr-fec/python/fec/polar/helper_functions.py b/gr-fec/python/fec/polar/helper_functions.py index a4ecb1f0ff..147023a593 100644 --- a/gr-fec/python/fec/polar/helper_functions.py +++ b/gr-fec/python/fec/polar/helper_functions.py @@ -18,6 +18,10 @@ # Boston, MA 02110-1301, USA. # +from __future__ import print_function +from __future__ import division +from __future__ import unicode_literals + import numpy as np import time, sys import copy @@ -33,7 +37,7 @@ def bsc_channel(p): p denotes an erroneous transition ''' if not (p >= 0.0 and p <= 1.0): - print "given p is out of range!" + print("given p is out of range!") return np.array([], dtype=float) # 0 -> 0, 0 -> 1, 1 -> 0, 1 -> 1 @@ -99,7 +103,7 @@ def get_Fn(n): def get_Gn(n): # this matrix is called generator matrix if not is_power_of_two(n): - print "invalid input" + print("invalid input") return None if n == 1: return np.array([1, ]) @@ -177,7 +181,7 @@ def bhattacharyya_parameter(w): def main(): - print 'helper functions' + print('helper functions') for i in range(9): print(i, 'is power of 2: ', is_power_of_two(i)) diff --git a/gr-fec/python/fec/polar/testbed.py b/gr-fec/python/fec/polar/testbed.py index 3f8e814e4f..08ef0de558 100755..100644 --- a/gr-fec/python/fec/polar/testbed.py +++ b/gr-fec/python/fec/polar/testbed.py @@ -18,11 +18,16 @@ # Boston, MA 02110-1301, USA. # +from __future__ import print_function +from __future__ import absolute_import +from __future__ import division +from __future__ import unicode_literals -from encoder import PolarEncoder -from decoder import PolarDecoder -import channel_construction as cc -from helper_functions import * + +from .encoder import PolarEncoder +from .decoder import PolarDecoder +from . import channel_construction as cc +from .helper_functions import * import matplotlib.pyplot as plt @@ -58,13 +63,13 @@ def is_equal(first, second): if not (first == second).all(): result = first == second for i in range(len(result)): - print '{0:4}: {1:2} == {2:1} = {3}'.format(i, first[i], second[i], result[i]) + print('{0:4}: {1:2} == {2:1} = {3}'.format(i, first[i], second[i], result[i])) return False return True def exact_value(la, lb): - return np.log((np.exp(la + lb) + 1) / (np.exp(la) + np.exp(lb))) + return np.log((np.exp(la + lb) + 1) / (np.exp(la + np.exp(lb)))) def approx_value(la, lb): @@ -112,7 +117,7 @@ def test_1024_rate_1_code(): recv = decoder.decode(rx) channel_counter += (bits == recv) - print channel_counter + print(channel_counter) print(np.min(channel_counter), np.max(channel_counter)) np.save('channel_counter_' + str(ntests) + '.npy', channel_counter) @@ -330,7 +335,7 @@ def main(): # frozenbits = np.zeros(n - k) # frozenbitposition8 = np.array((0, 1, 2, 4), dtype=int) # frozenbitposition = np.array((0, 1, 2, 3, 4, 5, 8, 9), dtype=int) - # print frozenbitposition + # print(frozenbitposition) # test_enc_dec_chain() # test_1024_rate_1_code() diff --git a/gr-fec/python/fec/qa_ber_bf.py b/gr-fec/python/fec/qa_ber_bf.py index 5d1734de0c..0d720988cb 100644 --- a/gr-fec/python/fec/qa_ber_bf.py +++ b/gr-fec/python/fec/qa_ber_bf.py @@ -20,11 +20,15 @@ # Boston, MA 02110-1301, USA. # -from gnuradio import gr, gr_unittest, blocks -import fec_swig as fec +from __future__ import print_function + + import numpy import copy +from gnuradio import gr, gr_unittest, blocks +from gnuradio import fec + class test_ber_bf(gr_unittest.TestCase): def setUp(self): @@ -132,8 +136,8 @@ class test_ber_bf(gr_unittest.TestCase): data = dst.data() expected_result = [-2.0, ] - print data - print expected_result + print(data) + print(expected_result) self.assertFloatTuplesAlmostEqual(expected_result, data, 5) diff --git a/gr-fec/python/fec/qa_depuncture.py b/gr-fec/python/fec/qa_depuncture.py index 5566e83a25..9ec57bfc41 100644 --- a/gr-fec/python/fec/qa_depuncture.py +++ b/gr-fec/python/fec/qa_depuncture.py @@ -20,11 +20,14 @@ # Boston, MA 02110-1301, USA. # -from gnuradio import gr, gr_unittest -import fec_swig as fec -import blocks_swig as blocks +from __future__ import division + from collections import deque +from gnuradio import gr, gr_unittest, blocks +from gnuradio import fec + + class test_depuncture (gr_unittest.TestCase): def depuncture_setup(self): @@ -37,7 +40,7 @@ class test_depuncture (gr_unittest.TestCase): k = 0 self.expected = [] - for n in range(len(self.src_data)/(self.puncsize - self.puncholes)): + for n in range(len(self.src_data) // (self.puncsize - self.puncholes)): for i in range(self.puncsize): if _puncpat[i] == 1: self.expected.append(self.src_data[k]); @@ -46,7 +49,7 @@ class test_depuncture (gr_unittest.TestCase): self.expected.append(self.sym) def setUp(self): - self.src_data = 2000*range(64) + self.src_data = 2000*list(range(64)) self.tb = gr.top_block () def tearDown(self): @@ -64,15 +67,15 @@ class test_depuncture (gr_unittest.TestCase): self.depuncture_setup() src = blocks.vector_source_b(self.src_data) - op = fec.depuncture_bb(self.puncsize, self.puncpat, + op = fec.depuncture_bb(self.puncsize, self.puncpat, self.delay, self.sym) - dst = blocks.vector_sink_b() + dst = blocks.vector_sink_b() - self.tb.connect(src, op, dst) - self.tb.run() + self.tb.connect(src, op, dst) + self.tb.run() - dst_data = list(dst.data()) - for i in xrange(len(dst_data)): + dst_data = list(dst.data()) + for i in range(len(dst_data)): dst_data[i] = int(dst_data[i]) self.assertEqual(self.expected, dst_data) @@ -89,15 +92,15 @@ class test_depuncture (gr_unittest.TestCase): self.depuncture_setup() src = blocks.vector_source_b(self.src_data) - op = fec.depuncture_bb(self.puncsize, self.puncpat, + op = fec.depuncture_bb(self.puncsize, self.puncpat, self.delay, self.sym) - dst = blocks.vector_sink_b() + dst = blocks.vector_sink_b() - self.tb.connect(src, op, dst) - self.tb.run() + self.tb.connect(src, op, dst) + self.tb.run() - dst_data = list(dst.data()) - for i in xrange(len(dst_data)): + dst_data = list(dst.data()) + for i in range(len(dst_data)): dst_data[i] = int(dst_data[i]) self.assertEqual(self.expected, dst_data) @@ -115,15 +118,15 @@ class test_depuncture (gr_unittest.TestCase): self.depuncture_setup() src = blocks.vector_source_b(self.src_data) - op = fec.depuncture_bb(self.puncsize, self.puncpat, + op = fec.depuncture_bb(self.puncsize, self.puncpat, self.delay, self.sym) - dst = blocks.vector_sink_b() + dst = blocks.vector_sink_b() - self.tb.connect(src, op, dst) - self.tb.run() + self.tb.connect(src, op, dst) + self.tb.run() - dst_data = list(dst.data()) - for i in xrange(len(dst_data)): + dst_data = list(dst.data()) + for i in range(len(dst_data)): dst_data[i] = int(dst_data[i]) self.assertEqual(self.expected, dst_data) @@ -141,23 +144,23 @@ class test_depuncture (gr_unittest.TestCase): self.sym = 0 src = blocks.vector_source_b(self.src_data) - op0 = fec.depuncture_bb(self.puncsize, self.puncpat0, + op0 = fec.depuncture_bb(self.puncsize, self.puncpat0, self.delay, self.sym) - op1 = fec.depuncture_bb(self.puncsize, self.puncpat1, + op1 = fec.depuncture_bb(self.puncsize, self.puncpat1, self.delay, self.sym) - dst0 = blocks.vector_sink_b() - dst1 = blocks.vector_sink_b() + dst0 = blocks.vector_sink_b() + dst1 = blocks.vector_sink_b() - self.tb.connect(src, op0, dst0) - self.tb.connect(src, op1, dst1) - self.tb.run() + self.tb.connect(src, op0, dst0) + self.tb.connect(src, op1, dst1) + self.tb.run() - dst_data0 = list(dst0.data()) - for i in xrange(len(dst_data0)): + dst_data0 = list(dst0.data()) + for i in range(len(dst_data0)): dst_data0[i] = int(dst_data0[i]) - dst_data1 = list(dst1.data()) - for i in xrange(len(dst_data1)): + dst_data1 = list(dst1.data()) + for i in range(len(dst_data1)): dst_data1[i] = int(dst_data1[i]) self.assertEqual(dst_data1, dst_data0) @@ -175,15 +178,15 @@ class test_depuncture (gr_unittest.TestCase): self.depuncture_setup() src = blocks.vector_source_b(self.src_data) - op = fec.depuncture_bb(self.puncsize, self.puncpat, + op = fec.depuncture_bb(self.puncsize, self.puncpat, self.delay) - dst = blocks.vector_sink_b() + dst = blocks.vector_sink_b() - self.tb.connect(src, op, dst) - self.tb.run() + self.tb.connect(src, op, dst) + self.tb.run() - dst_data = list(dst.data()) - for i in xrange(len(dst_data)): + dst_data = list(dst.data()) + for i in range(len(dst_data)): dst_data[i] = int(dst_data[i]) self.assertEqual(self.expected, dst_data) diff --git a/gr-fec/python/fec/qa_ecc_ccsds_27.py b/gr-fec/python/fec/qa_ecc_ccsds_27.py index 895e683345..6656c9d3ac 100755..100644 --- a/gr-fec/python/fec/qa_ecc_ccsds_27.py +++ b/gr-fec/python/fec/qa_ecc_ccsds_27.py @@ -20,9 +20,10 @@ # Boston, MA 02110-1301, USA. # -from gnuradio import gr, gr_unittest -import fec_swig as fec -import blocks_swig as blocks + +from gnuradio import gr, gr_unittest, blocks +from gnuradio import fec + class test_ccsds_27 (gr_unittest.TestCase): @@ -34,17 +35,17 @@ class test_ccsds_27 (gr_unittest.TestCase): def xtest_ccsds_27 (self): src_data = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10) - expected = (0, 0, 0, 0, 1, 2, 3, 4, 5, 6) + expected = (0, 0, 0, 0, 1, 2, 3, 4, 5, 6) src = blocks.vector_source_b(src_data) - enc = fec.encode_ccsds_27_bb() - b2f = blocks.char_to_float() - add = blocks.add_const_ff(-0.5) - mul = blocks.multiply_const_ff(2.0) - dec = fec.decode_ccsds_27_fb() - dst = blocks.vector_sink_b() - self.tb.connect(src, enc, b2f, add, mul, dec, dst) - self.tb.run() - dst_data = dst.data() + enc = fec.encode_ccsds_27_bb() + b2f = blocks.char_to_float() + add = blocks.add_const_ff(-0.5) + mul = blocks.multiply_const_ff(2.0) + dec = fec.decode_ccsds_27_fb() + dst = blocks.vector_sink_b() + self.tb.connect(src, enc, b2f, add, mul, dec, dst) + self.tb.run() + dst_data = dst.data() self.assertEqual(expected, dst_data) diff --git a/gr-fec/python/fec/qa_fecapi_cc.py b/gr-fec/python/fec/qa_fecapi_cc.py index bbd500161e..053f671a0e 100644 --- a/gr-fec/python/fec/qa_fecapi_cc.py +++ b/gr-fec/python/fec/qa_fecapi_cc.py @@ -20,12 +20,14 @@ # Boston, MA 02110-1301, USA. # +from __future__ import absolute_import + + from gnuradio import gr, gr_unittest -import fec_swig as fec +from gnuradio import fec + from _qa_helper import _qa_helper -from extended_encoder import extended_encoder -from extended_decoder import extended_decoder class test_fecapi_cc(gr_unittest.TestCase): @@ -91,8 +93,8 @@ class test_fecapi_cc(gr_unittest.TestCase): k = 7 rate = 2 polys = [109,79] - enc = map((lambda a: fec.cc_encoder_make(frame_size*8, k, rate, polys)), range(0,1)) - dec = map((lambda a: fec.cc_decoder.make(frame_size*8, k, rate, polys)), range(0,1)) + enc = list(map((lambda a: fec.cc_encoder_make(frame_size*8, k, rate, polys)), list(range(0,1)))) + dec = list(map((lambda a: fec.cc_decoder.make(frame_size*8, k, rate, polys)), list(range(0,1)))) threading = None self.test = _qa_helper(5*frame_size, enc, dec, threading) self.tb.connect(self.test) @@ -108,8 +110,8 @@ class test_fecapi_cc(gr_unittest.TestCase): k = 7 rate = 2 polys = [109,79] - enc = map((lambda a: fec.cc_encoder_make(frame_size*8, k, rate, polys)), range(0,1)) - dec = map((lambda a: fec.cc_decoder.make(frame_size*8, k, rate, polys)), range(0,1)) + enc = list(map((lambda a: fec.cc_encoder_make(frame_size*8, k, rate, polys)), list(range(0,1)))) + dec = list(map((lambda a: fec.cc_decoder.make(frame_size*8, k, rate, polys)), list(range(0,1)))) threading = 'ordinary' self.test = _qa_helper(5*frame_size, enc, dec, threading) self.tb.connect(self.test) @@ -125,8 +127,8 @@ class test_fecapi_cc(gr_unittest.TestCase): k = 7 rate = 2 polys = [109,79] - enc = map((lambda a: fec.cc_encoder_make(frame_size*8, k, rate, polys)), range(0,1)) - dec = map((lambda a: fec.cc_decoder.make(frame_size*8, k, rate, polys)), range(0,1)) + enc = list(map((lambda a: fec.cc_encoder_make(frame_size*8, k, rate, polys)), list(range(0,1)))) + dec = list(map((lambda a: fec.cc_decoder.make(frame_size*8, k, rate, polys)), list(range(0,1)))) threading = 'capillary' self.test = _qa_helper(5*frame_size, enc, dec, threading) self.tb.connect(self.test) @@ -143,8 +145,8 @@ class test_fecapi_cc(gr_unittest.TestCase): rate = 2 polys = [109,79] mode = fec.CC_TERMINATED - enc = map((lambda a: fec.cc_encoder_make(frame_size*8, k, rate, polys, mode=mode)), range(0,4)) - dec = map((lambda a: fec.cc_decoder.make(frame_size*8, k, rate, polys, mode=mode)), range(0,4)) + enc = list(map((lambda a: fec.cc_encoder_make(frame_size*8, k, rate, polys, mode=mode)), list(range(0,4)))) + dec = list(map((lambda a: fec.cc_decoder.make(frame_size*8, k, rate, polys, mode=mode)), list(range(0,4)))) threading = 'capillary' self.test = _qa_helper(4*frame_size, enc, dec, threading) self.tb.connect(self.test) @@ -161,8 +163,8 @@ class test_fecapi_cc(gr_unittest.TestCase): rate = 2 polys = [109,79] mode = fec.CC_TRUNCATED - enc = map((lambda a: fec.cc_encoder_make(frame_size*8, k, rate, polys, mode=mode)), range(0,4)) - dec = map((lambda a: fec.cc_decoder.make(frame_size*8, k, rate, polys, mode=mode)), range(0,4)) + enc = list(map((lambda a: fec.cc_encoder_make(frame_size*8, k, rate, polys, mode=mode)), list(range(0,4)))) + dec = list(map((lambda a: fec.cc_decoder.make(frame_size*8, k, rate, polys, mode=mode)), list(range(0,4)))) threading = 'capillary' self.test = _qa_helper(4*frame_size, enc, dec, threading) self.tb.connect(self.test) @@ -179,8 +181,8 @@ class test_fecapi_cc(gr_unittest.TestCase): rate = 2 polys = [109,79] mode = fec.CC_TAILBITING - enc = map((lambda a: fec.cc_encoder_make(frame_size*8, k, rate, polys, mode=mode)), range(0,4)) - dec = map((lambda a: fec.cc_decoder.make(frame_size*8, k, rate, polys, mode=mode)), range(0,4)) + enc = list(map((lambda a: fec.cc_encoder_make(frame_size*8, k, rate, polys, mode=mode)), list(range(0,4)))) + dec = list(map((lambda a: fec.cc_decoder.make(frame_size*8, k, rate, polys, mode=mode)), list(range(0,4)))) threading = 'capillary' self.test = _qa_helper(4*frame_size, enc, dec, threading) self.tb.connect(self.test) diff --git a/gr-fec/python/fec/qa_fecapi_dummy.py b/gr-fec/python/fec/qa_fecapi_dummy.py index 9471c71d74..368014d890 100644 --- a/gr-fec/python/fec/qa_fecapi_dummy.py +++ b/gr-fec/python/fec/qa_fecapi_dummy.py @@ -20,13 +20,17 @@ # Boston, MA 02110-1301, USA. # +from __future__ import absolute_import + +import numpy as np + from gnuradio import gr, gr_unittest, blocks -import fec_swig as fec +from gnuradio import fec +from fec import extended_encoder +from fec import extended_decoder + from _qa_helper import _qa_helper -import numpy as np -from extended_encoder import extended_encoder -from extended_decoder import extended_decoder class test_fecapi_dummy(gr_unittest.TestCase): @@ -80,8 +84,8 @@ class test_fecapi_dummy(gr_unittest.TestCase): def test_parallelism1_00(self): frame_size = 30 - enc = map((lambda a: fec.dummy_encoder_make(frame_size*8)), range(0,1)) - dec = map((lambda a: fec.dummy_decoder.make(frame_size*8)), range(0,1)) + enc = list(map((lambda a: fec.dummy_encoder_make(frame_size*8)), list(range(0,1)))) + dec = list(map((lambda a: fec.dummy_decoder.make(frame_size*8)), list(range(0,1)))) threading = None self.test = _qa_helper(10*frame_size, enc, dec, threading) self.tb.connect(self.test) @@ -94,8 +98,8 @@ class test_fecapi_dummy(gr_unittest.TestCase): def test_parallelism1_01(self): frame_size = 30 - enc = map((lambda a: fec.dummy_encoder_make(frame_size*8)), range(0,1)) - dec = map((lambda a: fec.dummy_decoder.make(frame_size*8)), range(0,1)) + enc = list(map((lambda a: fec.dummy_encoder_make(frame_size*8)), list(range(0,1)))) + dec = list(map((lambda a: fec.dummy_decoder.make(frame_size*8)), list(range(0,1)))) threading = 'ordinary' self.test = _qa_helper(10*frame_size, enc, dec, threading) self.tb.connect(self.test) @@ -108,8 +112,8 @@ class test_fecapi_dummy(gr_unittest.TestCase): def test_parallelism1_02(self): frame_size = 300 - enc = map((lambda a: fec.dummy_encoder_make(frame_size*8)), range(0,1)) - dec = map((lambda a: fec.dummy_decoder.make(frame_size*8)), range(0,1)) + enc = list(map((lambda a: fec.dummy_encoder_make(frame_size*8)), list(range(0,1)))) + dec = list(map((lambda a: fec.dummy_decoder.make(frame_size*8)), list(range(0,1)))) threading = 'capillary' self.test = _qa_helper(10*frame_size, enc, dec, threading) self.tb.connect(self.test) @@ -123,8 +127,8 @@ class test_fecapi_dummy(gr_unittest.TestCase): def test_parallelism1_03(self): frame_size = 30 dims = 10 - enc = map((lambda a: fec.dummy_encoder_make(frame_size*8)), range(0,dims)) - dec = map((lambda a: fec.dummy_decoder.make(frame_size*8)), range(0,dims)) + enc = list(map((lambda a: fec.dummy_encoder_make(frame_size*8)), list(range(0,dims)))) + dec = list(map((lambda a: fec.dummy_decoder.make(frame_size*8)), list(range(0,dims)))) threading = 'ordinary' self.test = _qa_helper(dims*frame_size, enc, dec, threading) self.tb.connect(self.test) @@ -138,8 +142,8 @@ class test_fecapi_dummy(gr_unittest.TestCase): def test_parallelism1_04(self): frame_size = 30 dims = 16 - enc = map((lambda a: fec.dummy_encoder_make(frame_size*8)), range(0,dims)) - dec = map((lambda a: fec.dummy_decoder.make(frame_size*8)), range(0,dims)) + enc = list(map((lambda a: fec.dummy_encoder_make(frame_size*8)), list(range(0,dims)))) + dec = list(map((lambda a: fec.dummy_decoder.make(frame_size*8)), list(range(0,dims)))) threading = 'capillary' self.test = _qa_helper(dims*frame_size, enc, dec, threading) self.tb.connect(self.test) @@ -153,7 +157,7 @@ class test_fecapi_dummy(gr_unittest.TestCase): def test_parallelism1_05(self): frame_size = 30 dims = 5 - enc = map((lambda a: fec.dummy_encoder_make(frame_size*8)), range(0,dims)) + enc = list(map((lambda a: fec.dummy_encoder_make(frame_size*8)), list(range(0,dims)))) #dec = map((lambda a: fec.dummy_decoder.make(frame_size*8)), range(0,dims)) threading = 'capillary' @@ -163,7 +167,7 @@ class test_fecapi_dummy(gr_unittest.TestCase): frame_size = 30 dims = 5 #enc = map((lambda a: fec.dummy_encoder_make(frame_size*8)), range(0,dims)) - dec = map((lambda a: fec.dummy_decoder.make(frame_size*8)), range(0,dims)) + dec = list(map((lambda a: fec.dummy_decoder.make(frame_size*8)), list(range(0,dims)))) threading = 'capillary' self.assertRaises(AttributeError, lambda: extended_decoder(dec, threading=threading, puncpat="11")) @@ -172,7 +176,7 @@ class test_fecapi_dummy(gr_unittest.TestCase): frame_size = 30 dims1 = 16 dims2 = 16 - enc = map((lambda b: map((lambda a: fec.dummy_encoder_make(frame_size*8)), range(0,dims1))), range(0,dims2)) + enc = list(map((lambda b: list(map((lambda a: fec.dummy_encoder_make(frame_size*8)), list(range(0,dims1))))), list(range(0,dims2)))) #dec = map((lambda b: map((lambda a: fec.dummy_decoder_make(frame_size*8)), range(0,dims1))), range(0,dims2)) threading = 'capillary' @@ -182,7 +186,7 @@ class test_fecapi_dummy(gr_unittest.TestCase): frame_size = 30 dims1 = 16 dims2 = 16 - dec = map((lambda b: map((lambda a: fec.dummy_decoder_make(frame_size*8)), range(0,dims1))), range(0,dims2)) + dec = list(map((lambda b: list(map((lambda a: fec.dummy_decoder_make(frame_size*8)), list(range(0,dims1))))), list(range(0,dims2)))) threading = 'capillary' self.assertRaises(AttributeError, lambda: extended_decoder(dec, threading=threading, puncpat="11")) @@ -193,6 +197,7 @@ class test_fecapi_dummy(gr_unittest.TestCase): frame_size = 32 data = np.random.randint(0, 2, n_frames * frame_size) + data.dtype = np.uint8 packed_data = np.packbits(data) tb = gr.top_block() diff --git a/gr-fec/python/fec/qa_fecapi_ldpc.py b/gr-fec/python/fec/qa_fecapi_ldpc.py index b45ce0ee19..758a26469e 100644 --- a/gr-fec/python/fec/qa_fecapi_ldpc.py +++ b/gr-fec/python/fec/qa_fecapi_ldpc.py @@ -20,15 +20,19 @@ # Boston, MA 02110-1301, USA. # -from gnuradio import gr, gr_unittest -import fec_swig as fec -from _qa_helper import _qa_helper +from __future__ import absolute_import -from extended_encoder import extended_encoder -from extended_decoder import extended_decoder import os +from gnuradio import gr, gr_unittest +from gnuradio import fec +from fec import extended_encoder +from fec import extended_decoder + +from _qa_helper import _qa_helper + + # Get location of the alist files. If run in 'ctest' or 'make test', # the shell script sets srcdir. Otherwise, we assume we're running # from the current directory and know where to go. @@ -131,8 +135,8 @@ class test_fecapi_ldpc(gr_unittest.TestCase): gap = 4 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_sptr())), range(0,1)) + enc = list(map((lambda a: fec.ldpc_par_mtrx_encoder.make_H(LDPC_matrix_object)), list(range(0,1)))) + dec = list(map((lambda a: fec.ldpc_bit_flip_decoder.make(LDPC_matrix_object.get_base_sptr())), list(range(0,1)))) threading = None self.test = _qa_helper(10*k, enc, dec, threading) self.tb.connect(self.test) @@ -148,8 +152,8 @@ class test_fecapi_ldpc(gr_unittest.TestCase): gap = 4 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_sptr())), range(0,1)) + enc = list(map((lambda a: fec.ldpc_par_mtrx_encoder.make_H(LDPC_matrix_object)), list(range(0,1)))) + dec = list(map((lambda a: fec.ldpc_bit_flip_decoder.make(LDPC_matrix_object.get_base_sptr())), list(range(0,1)))) threading = 'ordinary' self.test = _qa_helper(10*k, enc, dec, threading) self.tb.connect(self.test) @@ -165,8 +169,8 @@ class test_fecapi_ldpc(gr_unittest.TestCase): gap = 4 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_sptr())), range(0,1)) + enc = list(map((lambda a: fec.ldpc_par_mtrx_encoder.make_H(LDPC_matrix_object)), list(range(0,1)))) + dec = list(map((lambda a: fec.ldpc_bit_flip_decoder.make(LDPC_matrix_object.get_base_sptr())), list(range(0,1)))) threading = 'capillary' self.test = _qa_helper(10*k, enc, dec, threading) self.tb.connect(self.test) @@ -255,7 +259,7 @@ class test_fecapi_ldpc(gr_unittest.TestCase): dims = 5 LDPC_matrix_object = fec.ldpc_H_matrix(filename, gap) k = LDPC_matrix_object.k() - dec = map((lambda a: fec.ldpc_bit_flip_decoder.make(LDPC_matrix_object.get_base_sptr())), range(0,dims)) + dec = list(map((lambda a: fec.ldpc_bit_flip_decoder.make(LDPC_matrix_object.get_base_sptr())), list(range(0,dims)))) threading = 'capillary' self.assertRaises(AttributeError, lambda: extended_decoder(dec, threading=threading, puncpat="11")) @@ -267,8 +271,8 @@ class test_fecapi_ldpc(gr_unittest.TestCase): k = LDPC_matrix_object.k() dims1 = 16 dims2 = 16 - enc = map((lambda b: map((lambda a: fec.ldpc_par_mtrx_encoder.make_H(LDPC_matrix_object)), - range(0,dims1))), range(0,dims2)) + enc = list(map((lambda b: list(map((lambda a: fec.ldpc_par_mtrx_encoder.make_H(LDPC_matrix_object)), + list(range(0,dims1))))), list(range(0,dims2)))) threading = 'capillary' self.assertRaises(AttributeError, lambda: extended_encoder(enc, threading=threading, puncpat="11")) @@ -281,8 +285,8 @@ class test_fecapi_ldpc(gr_unittest.TestCase): k = LDPC_matrix_object.k() dims1 = 16 dims2 = 16 - enc = map((lambda b: map((lambda a: fec.ldpc_par_mtrx_encoder.make_H(LDPC_matrix_object)), - range(0,dims1))), range(0,dims2)) + enc = list(map((lambda b: list(map((lambda a: fec.ldpc_par_mtrx_encoder.make_H(LDPC_matrix_object)), + list(range(0,dims1))))), list(range(0,dims2)))) threading = 'capillary' self.assertRaises(AttributeError, lambda: extended_encoder(enc, threading=threading, puncpat="11")) @@ -295,8 +299,8 @@ 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_sptr())), - range(0,dims1))), range(0,dims2)) + dec = list(map((lambda b: list(map((lambda a: fec.ldpc_bit_flip_decoder.make(LDPC_matrix_object.get_base_sptr())), + list(range(0,dims1))))), list(range(0,dims2)))) threading = 'capillary' self.assertRaises(AttributeError, lambda: extended_decoder(dec, threading=threading, puncpat="11")) diff --git a/gr-fec/python/fec/qa_fecapi_repetition.py b/gr-fec/python/fec/qa_fecapi_repetition.py index 7998d61bd1..650aab7010 100644 --- a/gr-fec/python/fec/qa_fecapi_repetition.py +++ b/gr-fec/python/fec/qa_fecapi_repetition.py @@ -20,12 +20,15 @@ # Boston, MA 02110-1301, USA. # +from __future__ import absolute_import + + + from gnuradio import gr, gr_unittest -import fec_swig as fec +from gnuradio import fec + from _qa_helper import _qa_helper -from extended_encoder import extended_encoder -from extended_decoder import extended_decoder class test_fecapi_repetition(gr_unittest.TestCase): @@ -83,8 +86,8 @@ class test_fecapi_repetition(gr_unittest.TestCase): def test_parallelism1_00(self): frame_size = 30 rep = 3 - enc = map((lambda a: fec.repetition_encoder_make(frame_size*8, rep)), range(0,1)) - dec = map((lambda a: fec.repetition_decoder.make(frame_size*8, rep)), range(0,1)) + enc = list(map((lambda a: fec.repetition_encoder_make(frame_size*8, rep)), list(range(0,1)))) + dec = list(map((lambda a: fec.repetition_decoder.make(frame_size*8, rep)), list(range(0,1)))) threading = None self.test = _qa_helper(10*frame_size, enc, dec, threading) self.tb.connect(self.test) @@ -98,8 +101,8 @@ class test_fecapi_repetition(gr_unittest.TestCase): def test_parallelism1_01(self): frame_size = 30 rep = 3 - enc = map((lambda a: fec.repetition_encoder_make(frame_size*8, rep)), range(0,1)) - dec = map((lambda a: fec.repetition_decoder.make(frame_size*8, rep)), range(0,1)) + enc = list(map((lambda a: fec.repetition_encoder_make(frame_size*8, rep)), list(range(0,1)))) + dec = list(map((lambda a: fec.repetition_decoder.make(frame_size*8, rep)), list(range(0,1)))) threading = 'ordinary' self.test = _qa_helper(10*frame_size, enc, dec, threading) self.tb.connect(self.test) @@ -113,8 +116,8 @@ class test_fecapi_repetition(gr_unittest.TestCase): def test_parallelism1_02(self): frame_size = 300 rep = 3 - enc = map((lambda a: fec.repetition_encoder_make(frame_size*8, rep)), range(0,1)) - dec = map((lambda a: fec.repetition_decoder.make(frame_size*8, rep)), range(0,1)) + enc = list(map((lambda a: fec.repetition_encoder_make(frame_size*8, rep)), list(range(0,1)))) + dec = list(map((lambda a: fec.repetition_decoder.make(frame_size*8, rep)), list(range(0,1)))) threading = 'capillary' self.test = _qa_helper(10*frame_size, enc, dec, threading) self.tb.connect(self.test) @@ -129,8 +132,8 @@ class test_fecapi_repetition(gr_unittest.TestCase): frame_size = 30 rep = 3 dims = 10 - enc = map((lambda a: fec.repetition_encoder_make(frame_size*8, rep)), range(0,dims)) - dec = map((lambda a: fec.repetition_decoder.make(frame_size*8, rep)), range(0,dims)) + enc = list(map((lambda a: fec.repetition_encoder_make(frame_size*8, rep)), list(range(0,dims)))) + dec = list(map((lambda a: fec.repetition_decoder.make(frame_size*8, rep)), list(range(0,dims)))) threading = 'ordinary' self.test = _qa_helper(dims*frame_size, enc, dec, threading) self.tb.connect(self.test) @@ -145,8 +148,8 @@ class test_fecapi_repetition(gr_unittest.TestCase): frame_size = 30 rep = 3 dims = 16 - enc = map((lambda a: fec.repetition_encoder_make(frame_size*8, rep)), range(0,dims)) - dec = map((lambda a: fec.repetition_decoder.make(frame_size*8, rep)), range(0,dims)) + enc = list(map((lambda a: fec.repetition_encoder_make(frame_size*8, rep)), list(range(0,dims)))) + dec = list(map((lambda a: fec.repetition_decoder.make(frame_size*8, rep)), list(range(0,dims)))) threading = 'capillary' self.test = _qa_helper(dims*frame_size, enc, dec, threading) self.tb.connect(self.test) diff --git a/gr-fec/python/fec/qa_polar_decoder_sc.py b/gr-fec/python/fec/qa_polar_decoder_sc.py index 6dd1e8e481..c8d956328e 100644 --- a/gr-fec/python/fec/qa_polar_decoder_sc.py +++ b/gr-fec/python/fec/qa_polar_decoder_sc.py @@ -20,13 +20,18 @@ # Boston, MA 02110-1301, USA. # -from gnuradio import gr, gr_unittest, blocks -import fec_swig as fec +from __future__ import print_function +from __future__ import absolute_import +from __future__ import division + import numpy as np -from extended_decoder import extended_decoder -from polar.encoder import PolarEncoder -import polar.channel_construction as cc + +from gnuradio import gr, gr_unittest, blocks +from gnuradio import fec +from fec import extended_decoder +from fec.polar.encoder import PolarEncoder +from fec.polar import channel_construction as cc # import os # print('PID:', os.getpid()) diff --git a/gr-fec/python/fec/qa_polar_decoder_sc_list.py b/gr-fec/python/fec/qa_polar_decoder_sc_list.py index 36819b396f..13a8e9bc32 100644 --- a/gr-fec/python/fec/qa_polar_decoder_sc_list.py +++ b/gr-fec/python/fec/qa_polar_decoder_sc_list.py @@ -20,13 +20,17 @@ # Boston, MA 02110-1301, USA. # -from gnuradio import gr, gr_unittest, blocks -import fec_swig as fec +from __future__ import print_function +from __future__ import absolute_import +from __future__ import division + + import numpy as np -from extended_decoder import extended_decoder -from polar.encoder import PolarEncoder -import polar.channel_construction as cc +from gnuradio import gr, gr_unittest, blocks, fec +from gnuradio.fec import extended_decoder +from gnuradio.fec.polar.encoder import PolarEncoder +from gnuradio.fec.polar import channel_construction as cc # import os # print('PID:', os.getpid()) @@ -56,7 +60,7 @@ class test_polar_decoder_sc_list(gr_unittest.TestCase): self.assertFalse(polar_decoder.set_frame_size(10)) def test_002_one_vector(self): - print "test_002_one_vector" + print("test_002_one_vector") expo = 6 block_size = 2 ** expo num_info_bits = 2 ** (expo - 1) @@ -89,7 +93,7 @@ class test_polar_decoder_sc_list(gr_unittest.TestCase): self.assertTupleEqual(tuple(res), tuple(bits)) def test_003_stream(self): - print "test_003_stream" + print("test_003_stream") nframes = 5 expo = 8 block_size = 2 ** expo diff --git a/gr-fec/python/fec/qa_polar_decoder_sc_systematic.py b/gr-fec/python/fec/qa_polar_decoder_sc_systematic.py index fb2381e069..525ebbc76c 100644 --- a/gr-fec/python/fec/qa_polar_decoder_sc_systematic.py +++ b/gr-fec/python/fec/qa_polar_decoder_sc_systematic.py @@ -20,13 +20,16 @@ # Boston, MA 02110-1301, USA. # -from gnuradio import gr, gr_unittest, blocks -import fec_swig as fec +from __future__ import absolute_import +from __future__ import division import numpy as np -from extended_decoder import extended_decoder -from polar.encoder import PolarEncoder -import polar.channel_construction as cc + +from gnuradio import gr, gr_unittest, blocks, fec + +from gnuradio.fec.extended_decoder import extended_decoder +from gnuradio.fec.polar.encoder import PolarEncoder +from gnuradio.fec.polar import channel_construction as cc # import os # print('PID:', os.getpid()) @@ -113,5 +116,3 @@ class test_polar_decoder_sc_systematic(gr_unittest.TestCase): if __name__ == '__main__': gr_unittest.run(test_polar_decoder_sc_systematic) - - diff --git a/gr-fec/python/fec/qa_polar_encoder.py b/gr-fec/python/fec/qa_polar_encoder.py index d7362b6dc4..ba003d9070 100644 --- a/gr-fec/python/fec/qa_polar_encoder.py +++ b/gr-fec/python/fec/qa_polar_encoder.py @@ -20,13 +20,16 @@ # Boston, MA 02110-1301, USA. # -from gnuradio import gr, gr_unittest, blocks -import fec_swig as fec +from __future__ import absolute_import +from __future__ import division + + import numpy as np -from extended_encoder import extended_encoder -from polar.encoder import PolarEncoder -import polar.channel_construction as cc +from gnuradio import gr, gr_unittest, blocks, fec +from gnuradio.fec.extended_encoder import extended_encoder +from gnuradio.fec.polar.encoder import PolarEncoder +from gnuradio.fec.polar import channel_construction as cc # import os # print('PID:', os.getpid()) diff --git a/gr-fec/python/fec/qa_polar_encoder_systematic.py b/gr-fec/python/fec/qa_polar_encoder_systematic.py index 015a31b3cb..18b918ddab 100644 --- a/gr-fec/python/fec/qa_polar_encoder_systematic.py +++ b/gr-fec/python/fec/qa_polar_encoder_systematic.py @@ -20,13 +20,15 @@ # Boston, MA 02110-1301, USA. # -from gnuradio import gr, gr_unittest, blocks -import fec_swig as fec +from __future__ import absolute_import +from __future__ import division + import numpy as np -from extended_encoder import extended_encoder -from polar.encoder import PolarEncoder -import polar.channel_construction as cc +from gnuradio import gr, gr_unittest, blocks, fec +from gnuradio.fec.extended_encoder import extended_encoder +from gnuradio.fec.polar.encoder import PolarEncoder +from gnuradio.fec.polar import channel_construction as cc # import os # print('PID:', os.getpid()) @@ -103,5 +105,3 @@ class test_polar_encoder_systematic(gr_unittest.TestCase): if __name__ == '__main__': gr_unittest.run(test_polar_encoder_systematic) - - diff --git a/gr-fec/python/fec/qa_puncture.py b/gr-fec/python/fec/qa_puncture.py index fdd15c9a08..f4e0ba8556 100644 --- a/gr-fec/python/fec/qa_puncture.py +++ b/gr-fec/python/fec/qa_puncture.py @@ -20,11 +20,13 @@ # Boston, MA 02110-1301, USA. # -from gnuradio import gr, gr_unittest -import fec_swig as fec -import blocks_swig as blocks +from __future__ import division + from collections import deque +from gnuradio import gr, gr_unittest, blocks, fec + + class test_puncture (gr_unittest.TestCase): def puncture_setup(self): @@ -36,13 +38,13 @@ class test_puncture (gr_unittest.TestCase): _puncpat = list(d) self.expected = [] - for n in range(len(self.src_data)/self.puncsize): + for n in range(len(self.src_data) // self.puncsize): for i in range(self.puncsize): if _puncpat[i] == 1: self.expected.append(self.src_data[n*self.puncsize+i]); def setUp(self): - self.src_data = 10000*range(64) + self.src_data = 10000*list(range(64)) self.tb = gr.top_block() def tearDown(self): @@ -58,14 +60,14 @@ class test_puncture (gr_unittest.TestCase): self.puncture_setup() src = blocks.vector_source_b(self.src_data) - op = fec.puncture_bb(self.puncsize, self.puncpat, self.delay) - dst = blocks.vector_sink_b() + op = fec.puncture_bb(self.puncsize, self.puncpat, self.delay) + dst = blocks.vector_sink_b() - self.tb.connect(src, op, dst) - self.tb.run() + self.tb.connect(src, op, dst) + self.tb.run() - dst_data = list(dst.data()) - for i in xrange(len(dst_data)): + dst_data = list(dst.data()) + for i in range(len(dst_data)): dst_data[i] = int(dst_data[i]) self.assertEqual(self.expected, dst_data) @@ -78,19 +80,19 @@ class test_puncture (gr_unittest.TestCase): self.puncpat = 0xEE self.delay = 1 - self.src_data = range(16) + self.src_data = list(range(16)) self.puncture_setup() src = blocks.vector_source_b(self.src_data) - op = fec.puncture_bb(self.puncsize, self.puncpat, self.delay) - dst = blocks.vector_sink_b() + op = fec.puncture_bb(self.puncsize, self.puncpat, self.delay) + dst = blocks.vector_sink_b() - self.tb.connect(src, op, dst) - self.tb.run() + self.tb.connect(src, op, dst) + self.tb.run() - dst_data = list(dst.data()) - for i in xrange(len(dst_data)): + dst_data = list(dst.data()) + for i in range(len(dst_data)): dst_data[i] = int(dst_data[i]) self.assertEqual(self.expected, dst_data) @@ -107,14 +109,14 @@ class test_puncture (gr_unittest.TestCase): self.puncture_setup() src = blocks.vector_source_b(self.src_data) - op = fec.puncture_bb(self.puncsize, self.puncpat, self.delay) - dst = blocks.vector_sink_b() + op = fec.puncture_bb(self.puncsize, self.puncpat, self.delay) + dst = blocks.vector_sink_b() - self.tb.connect(src, op, dst) - self.tb.run() + self.tb.connect(src, op, dst) + self.tb.run() - dst_data = list(dst.data()) - for i in xrange(len(dst_data)): + dst_data = list(dst.data()) + for i in range(len(dst_data)): dst_data[i] = int(dst_data[i]) self.assertEqual(self.expected, dst_data) @@ -131,21 +133,21 @@ class test_puncture (gr_unittest.TestCase): self.delay = 1 src = blocks.vector_source_b(self.src_data) - op0 = fec.puncture_bb(self.puncsize, self.puncpat0, self.delay) - op1 = fec.puncture_bb(self.puncsize, self.puncpat1, self.delay) - dst0 = blocks.vector_sink_b() - dst1 = blocks.vector_sink_b() + op0 = fec.puncture_bb(self.puncsize, self.puncpat0, self.delay) + op1 = fec.puncture_bb(self.puncsize, self.puncpat1, self.delay) + dst0 = blocks.vector_sink_b() + dst1 = blocks.vector_sink_b() - self.tb.connect(src, op0, dst0) - self.tb.connect(src, op1, dst1) - self.tb.run() + self.tb.connect(src, op0, dst0) + self.tb.connect(src, op1, dst1) + self.tb.run() - dst_data0 = list(dst0.data()) - for i in xrange(len(dst_data0)): + dst_data0 = list(dst0.data()) + for i in range(len(dst_data0)): dst_data0[i] = int(dst_data0[i]) - dst_data1 = list(dst1.data()) - for i in xrange(len(dst_data1)): + dst_data1 = list(dst1.data()) + for i in range(len(dst_data1)): dst_data1[i] = int(dst_data1[i]) self.assertEqual(dst_data1, dst_data0) @@ -162,13 +164,13 @@ class test_puncture (gr_unittest.TestCase): self.puncture_setup() src = blocks.vector_source_f(self.src_data) - op = fec.puncture_ff(self.puncsize, self.puncpat, self.delay) - dst = blocks.vector_sink_f() + op = fec.puncture_ff(self.puncsize, self.puncpat, self.delay) + dst = blocks.vector_sink_f() - self.tb.connect(src, op, dst) - self.tb.run() + self.tb.connect(src, op, dst) + self.tb.run() - dst_data = list(dst.data()) + dst_data = list(dst.data()) self.assertEqual(self.expected, dst_data) @@ -179,18 +181,18 @@ class test_puncture (gr_unittest.TestCase): self.puncpat = 0xEE self.delay = 1 - self.src_data = range(16) + self.src_data = list(range(16)) self.puncture_setup() src = blocks.vector_source_f(self.src_data) - op = fec.puncture_ff(self.puncsize, self.puncpat, self.delay) - dst = blocks.vector_sink_f() + op = fec.puncture_ff(self.puncsize, self.puncpat, self.delay) + dst = blocks.vector_sink_f() - self.tb.connect(src, op, dst) - self.tb.run() + self.tb.connect(src, op, dst) + self.tb.run() - dst_data = list(dst.data()) + dst_data = list(dst.data()) self.assertEqual(self.expected, dst_data) @@ -205,13 +207,13 @@ class test_puncture (gr_unittest.TestCase): self.puncture_setup() src = blocks.vector_source_f(self.src_data) - op = fec.puncture_ff(self.puncsize, self.puncpat, self.delay) - dst = blocks.vector_sink_f() + op = fec.puncture_ff(self.puncsize, self.puncpat, self.delay) + dst = blocks.vector_sink_f() - self.tb.connect(src, op, dst) - self.tb.run() + self.tb.connect(src, op, dst) + self.tb.run() - dst_data = list(dst.data()) + dst_data = list(dst.data()) self.assertEqual(self.expected, dst_data) def test_f_003(self): @@ -226,17 +228,17 @@ class test_puncture (gr_unittest.TestCase): self.delay = 1 src = blocks.vector_source_f(self.src_data) - op0 = fec.puncture_ff(self.puncsize, self.puncpat0, self.delay) - op1 = fec.puncture_ff(self.puncsize, self.puncpat1, self.delay) - dst0 = blocks.vector_sink_f() - dst1 = blocks.vector_sink_f() + op0 = fec.puncture_ff(self.puncsize, self.puncpat0, self.delay) + op1 = fec.puncture_ff(self.puncsize, self.puncpat1, self.delay) + dst0 = blocks.vector_sink_f() + dst1 = blocks.vector_sink_f() - self.tb.connect(src, op0, dst0) - self.tb.connect(src, op1, dst1) - self.tb.run() + self.tb.connect(src, op0, dst0) + self.tb.connect(src, op1, dst1) + self.tb.run() - dst_data0 = list(dst0.data()) - dst_data1 = list(dst1.data()) + dst_data0 = list(dst0.data()) + dst_data1 = list(dst1.data()) self.assertEqual(dst_data1, dst_data0) diff --git a/gr-fec/python/fec/threaded_decoder.py b/gr-fec/python/fec/threaded_decoder.py index 115ad7b5d3..adf4abfe22 100644 --- a/gr-fec/python/fec/threaded_decoder.py +++ b/gr-fec/python/fec/threaded_decoder.py @@ -20,8 +20,10 @@ # Boston, MA 02110-1301, USA. # +from __future__ import unicode_literals from gnuradio import gr, blocks -import fec_swig as fec +from . import fec_swig as fec + class threaded_decoder(gr.hier_block2): def __init__(self, decoder_list_0, input_size, output_size): diff --git a/gr-fec/python/fec/threaded_encoder.py b/gr-fec/python/fec/threaded_encoder.py index 391baa5442..254b4d39d8 100644 --- a/gr-fec/python/fec/threaded_encoder.py +++ b/gr-fec/python/fec/threaded_encoder.py @@ -20,8 +20,11 @@ # Boston, MA 02110-1301, USA. # +from __future__ import unicode_literals from gnuradio import gr, blocks -import fec_swig as fec + +from . import fec_swig as fec + class threaded_encoder(gr.hier_block2): def __init__(self, encoder_list_0, input_size, output_size): |