commit-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Commit-gnuradio] [gnuradio] 09/20: python3: update gr-fec for python3 s


From: git
Subject: [Commit-gnuradio] [gnuradio] 09/20: python3: update gr-fec for python3 support
Date: Sun, 25 Dec 2016 03:59:58 +0000 (UTC)

This is an automated email from the git hooks/post-receive script.

jcorgan pushed a commit to branch python3
in repository gnuradio.

commit 33cf1b6994bdd9922280d5d4555dc159b7a90774
Author: Douglas Anderson <address@hidden>
Date:   Thu Dec 22 12:52:49 2016 -0700

    python3: update gr-fec for python3 support
---
 gr-fec/python/fec/LDPC/Generate_LDPC_matrix.py     |  20 +--
 .../fec/LDPC/Generate_LDPC_matrix_functions.py     | 136 +++++++++++----------
 gr-fec/python/fec/_qa_helper.py                    |   6 +-
 gr-fec/python/fec/extended_async_encoder.py        |   2 +
 gr-fec/python/fec/extended_decoder.py              |   8 +-
 gr-fec/python/fec/extended_tagged_decoder.py       |   8 +-
 gr-fec/python/fec/polar/channel_construction.py    |   4 +-
 .../python/fec/polar/channel_construction_awgn.py  |   4 +-
 .../python/fec/polar/channel_construction_bec.py   |   4 +-
 gr-fec/python/fec/polar/common.py                  |   4 +-
 gr-fec/python/fec/polar/decoder.py                 |  30 ++---
 gr-fec/python/fec/polar/encoder.py                 |  10 +-
 gr-fec/python/fec/polar/helper_functions.py        |   8 +-
 gr-fec/python/fec/polar/testbed.py                 |   8 +-
 gr-fec/python/fec/qa_ber_bf.py                     |   6 +-
 gr-fec/python/fec/qa_polar_decoder_sc.py           |   2 +
 gr-fec/python/fec/qa_polar_decoder_sc_list.py      |   6 +-
 17 files changed, 150 insertions(+), 116 deletions(-)

diff --git a/gr-fec/python/fec/LDPC/Generate_LDPC_matrix.py 
b/gr-fec/python/fec/LDPC/Generate_LDPC_matrix.py
index a3862a6..62554dc 100644
--- a/gr-fec/python/fec/LDPC/Generate_LDPC_matrix.py
+++ b/gr-fec/python/fec/LDPC/Generate_LDPC_matrix.py
@@ -20,6 +20,8 @@
 # Boston, MA 02110-1301, USA.
 #
 
+from __future__ import print_function
+
 from Generate_LDPC_matrix_functions import *
 
 # This is an example of how to generate a parity check matrix for
@@ -62,18 +64,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 c42fee6..1fc737c 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,8 @@
 # Boston, MA 02110-1301, USA.
 #
 
+from __future__ import print_function
+
 import string, sys
 from numpy import *
 from numpy.random import shuffle, randint
@@ -46,9 +48,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 +70,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 +81,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 +96,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
@@ -119,8 +121,8 @@ def write_alist_file(filename, H, verbose=0):
 class LDPC_matrix:
   """ 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 +130,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]
@@ -161,8 +163,8 @@ class LDPC_matrix:
     # number of rows in each submatrix must be a whole number.
     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:
@@ -172,7 +174,7 @@ class LDPC_matrix:
       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
@@ -183,7 +185,7 @@ class LDPC_matrix:
 
       for columnNum in arange(n):
         submatrix[:,columnNum] = \
-                      submatrix1[:,newColumnOrder[columnNum]]
+                                 submatrix1[:,newColumnOrder[columnNum]]
 
       H = vstack((H,submatrix))
       submatrixNum = submatrixNum + 1
@@ -197,14 +199,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 +223,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 +255,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 +284,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 +317,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 +329,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 +350,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 +380,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 +389,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 +416,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 +470,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 +522,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 +540,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 +590,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 +606,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 +634,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 +645,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 +684,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 +698,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 +718,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/_qa_helper.py b/gr-fec/python/fec/_qa_helper.py
index 8722453..358671b 100755
--- a/gr-fec/python/fec/_qa_helper.py
+++ b/gr-fec/python/fec/_qa_helper.py
@@ -20,6 +20,8 @@
 # Boston, MA 02110-1301, USA.
 #
 
+from __future__ import print_function
+
 from gnuradio import blocks
 from gnuradio import gr
 import sys, numpy
@@ -85,6 +87,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/extended_async_encoder.py 
b/gr-fec/python/fec/extended_async_encoder.py
index fffe64a..fcd8d0c 100644
--- a/gr-fec/python/fec/extended_async_encoder.py
+++ b/gr-fec/python/fec/extended_async_encoder.py
@@ -20,6 +20,8 @@
 # Boston, MA 02110-1301, USA.
 #
 
+from __future__ import print_function
+
 from gnuradio import gr
 import fec_swig as fec
 from bitflip import read_bitlist
diff --git a/gr-fec/python/fec/extended_decoder.py 
b/gr-fec/python/fec/extended_decoder.py
index 7e6cf45..502fae5 100644
--- a/gr-fec/python/fec/extended_decoder.py
+++ b/gr-fec/python/fec/extended_decoder.py
@@ -20,6 +20,8 @@
 # Boston, MA 02110-1301, USA.
 #
 
+from __future__ import print_function
+
 from gnuradio import gr, blocks
 import fec_swig as fec
 from bitflip import *
@@ -37,7 +39,7 @@ 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,
@@ -132,8 +134,8 @@ class extended_decoder(gr.hier_block2):
             for i in idx_list:
                 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_decoder.py 
b/gr-fec/python/fec/extended_tagged_decoder.py
index 9713907..ee31097 100644
--- a/gr-fec/python/fec/extended_tagged_decoder.py
+++ b/gr-fec/python/fec/extended_tagged_decoder.py
@@ -20,6 +20,8 @@
 # Boston, MA 02110-1301, USA.
 #
 
+from __future__ import print_function
+
 from gnuradio import gr, blocks
 import fec_swig as fec
 from bitflip import *
@@ -34,7 +36,7 @@ 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,
@@ -141,8 +143,8 @@ class extended_tagged_decoder(gr.hier_block2):
             for i in idx_list:
                 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/polar/channel_construction.py 
b/gr-fec/python/fec/polar/channel_construction.py
index a981007..4a4aa57 100644
--- a/gr-fec/python/fec/polar/channel_construction.py
+++ b/gr-fec/python/fec/polar/channel_construction.py
@@ -18,6 +18,8 @@
 # Boston, MA 02110-1301, USA.
 #
 
+from __future__ import print_function
+
 '''
 [0] Erdal Arikan: 'Channel Polarization: A Method for Constructing 
Capacity-Achieving Codes for Symmetric Binary-Input Memoryless Channels', 2009
 foundational paper for polar codes.
@@ -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 7d820b2..5cb2752 100755
--- a/gr-fec/python/fec/polar/channel_construction_awgn.py
+++ b/gr-fec/python/fec/polar/channel_construction_awgn.py
@@ -18,6 +18,8 @@
 # Boston, MA 02110-1301, USA.
 #
 
+from __future__ import print_function
+
 '''
 Based on 2 papers:
 [1] Ido Tal, Alexander Vardy: 'How To Construct Polar Codes', 2013
@@ -249,7 +251,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 4b35602..d6b1636 100644
--- a/gr-fec/python/fec/polar/channel_construction_bec.py
+++ b/gr-fec/python/fec/polar/channel_construction_bec.py
@@ -18,6 +18,8 @@
 # Boston, MA 02110-1301, USA.
 #
 
+from __future__ import print_function
+
 import numpy as np
 import helper_functions as hf
 
@@ -220,7 +222,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 fa5987b..09c9a8a 100644
--- a/gr-fec/python/fec/polar/common.py
+++ b/gr-fec/python/fec/polar/common.py
@@ -18,6 +18,8 @@
 # Boston, MA 02110-1301, USA.
 #
 
+from __future__ import print_function
+
 
 import numpy as np
 from helper_functions import *
@@ -81,4 +83,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 8748d28..2f39779 100644
--- a/gr-fec/python/fec/polar/decoder.py
+++ b/gr-fec/python/fec/polar/decoder.py
@@ -18,6 +18,8 @@
 # Boston, MA 02110-1301, USA.
 #
 
+from __future__ import print_function
+
 import numpy as np
 from common import PolarCommon
 
@@ -239,31 +241,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 +281,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 cc8fda2..73ed2a8 100644
--- a/gr-fec/python/fec/polar/encoder.py
+++ b/gr-fec/python/fec/polar/encoder.py
@@ -18,6 +18,8 @@
 # Boston, MA 02110-1301, USA.
 #
 
+from __future__ import print_function
+
 import numpy as np
 from common import PolarCommon
 import helper_functions as hf
@@ -99,8 +101,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 +116,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 85140c8..8463e35 100644
--- a/gr-fec/python/fec/polar/helper_functions.py
+++ b/gr-fec/python/fec/polar/helper_functions.py
@@ -18,6 +18,8 @@
 # Boston, MA 02110-1301, USA.
 #
 
+from __future__ import print_function
+
 import numpy as np
 import time, sys
 import copy
@@ -33,7 +35,7 @@ def bsc_channel(p):
     p denotes an erroneous transistion
     '''
     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 +101,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 +179,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 3f8e814..15f86c1 100755
--- a/gr-fec/python/fec/polar/testbed.py
+++ b/gr-fec/python/fec/polar/testbed.py
@@ -18,6 +18,8 @@
 # Boston, MA 02110-1301, USA.
 #
 
+from __future__ import print_function
+
 
 from encoder import PolarEncoder
 from decoder import PolarDecoder
@@ -58,7 +60,7 @@ 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
 
@@ -112,7 +114,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 +332,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 5d1734d..74970ea 100644
--- a/gr-fec/python/fec/qa_ber_bf.py
+++ b/gr-fec/python/fec/qa_ber_bf.py
@@ -20,6 +20,8 @@
 # Boston, MA 02110-1301, USA.
 #
 
+from __future__ import print_function
+
 from gnuradio import gr, gr_unittest, blocks
 import fec_swig as fec
 import numpy
@@ -132,8 +134,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_polar_decoder_sc.py 
b/gr-fec/python/fec/qa_polar_decoder_sc.py
index 6dd1e8e..b5ab031 100644
--- a/gr-fec/python/fec/qa_polar_decoder_sc.py
+++ b/gr-fec/python/fec/qa_polar_decoder_sc.py
@@ -20,6 +20,8 @@
 # Boston, MA 02110-1301, USA.
 #
 
+from __future__ import print_function
+
 from gnuradio import gr, gr_unittest, blocks
 import fec_swig as fec
 
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 36819b3..baa5594 100644
--- a/gr-fec/python/fec/qa_polar_decoder_sc_list.py
+++ b/gr-fec/python/fec/qa_polar_decoder_sc_list.py
@@ -20,6 +20,8 @@
 # Boston, MA 02110-1301, USA.
 #
 
+from __future__ import print_function
+
 from gnuradio import gr, gr_unittest, blocks
 import fec_swig as fec
 import numpy as np
@@ -56,7 +58,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 +91,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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]