Skip to content

Commit

Permalink
Fixes veeresht#8. Minor changes to ensure Python 3.5 compatibility.
Browse files Browse the repository at this point in the history
  • Loading branch information
veeresht committed Jun 29, 2016
1 parent 55f2489 commit d23f1f8
Show file tree
Hide file tree
Showing 11 changed files with 74 additions and 193 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ language: python
python:
# We don't actually use the Travis Python, but this keeps it organized.
- "2.7"
#- "3.3"
- "3.5"
#- "3.4"
notifications:
email: false
Expand Down
120 changes: 0 additions & 120 deletions README.rst

This file was deleted.

10 changes: 5 additions & 5 deletions commpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
"""
#from channelcoding import *
from filters import *
from modulation import *
from impairments import *
from sequences import *
from channels import *
from commpy.filters import *
from commpy.modulation import *
from commpy.impairments import *
from commpy.sequences import *
from commpy.channels import *

try:
from numpy.testing import Tester
Expand Down
12 changes: 6 additions & 6 deletions commpy/channelcoding/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,12 @@
"""

from convcode import Trellis, conv_encode, viterbi_decode
from interleavers import *
from turbo import turbo_encode, map_decode, turbo_decode
from ldpc import get_ldpc_code_params, ldpc_bp_decode
from gfields import *
from algcode import *
from commpy.channelcoding.convcode import Trellis, conv_encode, viterbi_decode
from commpy.channelcoding.interleavers import *
from commpy.channelcoding.turbo import turbo_encode, map_decode, turbo_decode
from commpy.channelcoding.ldpc import get_ldpc_code_params, ldpc_bp_decode
from commpy.channelcoding.gfields import *
from commpy.channelcoding.algcode import *

try:
from numpy.testing import Tester
Expand Down
8 changes: 4 additions & 4 deletions commpy/channelcoding/algcode.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from fractions import gcd
from numpy import array, arange, concatenate, convolve

from gfields import GF, polymultiply, poly_to_string
from commpy.channelcoding.gfields import GF, polymultiply, poly_to_string
from commpy.utilities import dec2bitarray, bitarray2dec

__all__ = ['cyclic_code_genpoly']
Expand All @@ -32,7 +32,7 @@ def cyclic_code_genpoly(n, k):


if n%2 == 0:
raise ValueError, "n cannot be an even number"
raise ValueError("n cannot be an even number")

for m in arange(1, 18):
if (2**m-1)%n == 0:
Expand All @@ -52,7 +52,7 @@ def cyclic_code_genpoly(n, k):
idx_list = arange(1, len(minpol_list))
poly_list = array([])

for i in xrange(1, 2**len(minpol_list)):
for i in range(1, 2**len(minpol_list)):
i_array = dec2bitarray(i, len(minpol_list))
subset_array = minpol_degrees[i_array == 1]
if int(subset_array.sum()) == (n-k):
Expand All @@ -70,4 +70,4 @@ def cyclic_code_genpoly(n, k):
if __name__ == "__main__":
genpolys = cyclic_code_genpoly(31, 21)
for poly in genpolys:
print poly_to_string(poly)
print(poly_to_string(poly))
46 changes: 23 additions & 23 deletions commpy/channelcoding/convcode.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def __init__(self, memory, g_matrix, feedback = 0, code_type = 'default'):
[self.k, self.n] = g_matrix.shape

if code_type == 'rsc':
for i in xrange(self.k):
for i in range(self.k):
g_matrix[i][i] = feedback

self.total_memory = memory.sum()
Expand All @@ -117,19 +117,19 @@ def __init__(self, memory, g_matrix, feedback = 0, code_type = 'default'):
self.number_inputs], 'int')

# Compute the entries in the next state table and the output table
for current_state in xrange(self.number_states):
for current_state in range(self.number_states):

for current_input in xrange(self.number_inputs):
for current_input in range(self.number_inputs):
outbits = np.zeros(self.n, 'int')

# Compute the values in the output_table
for r in xrange(self.n):
for r in range(self.n):

output_generator_array = np.zeros(self.k, 'int')
shift_register = dec2bitarray(current_state,
self.total_memory)

for l in xrange(self.k):
for l in range(self.k):

# Convert the number representing a polynomial into a
# bit array
Expand All @@ -138,7 +138,7 @@ def __init__(self, memory, g_matrix, feedback = 0, code_type = 'default'):

# Loop over M delay elements of the shift register
# to compute their contribution to the r-th output
for i in xrange(memory[l]):
for i in range(memory[l]):
outbits[r] = (outbits[r] + \
(shift_register[i+l]*generator_array[i+1])) % 2

Expand Down Expand Up @@ -184,7 +184,7 @@ def _generate_states(self, trellis_length, grid, state_order, state_radius, font
""" Private method """
state_patches = []

for state_count in xrange(self.number_states * trellis_length):
for state_count in range(self.number_states * trellis_length):
state_patch = mpatches.Circle(grid[:,state_count], state_radius,
color="#003399", ec="#cccccc")
state_patches.append(state_patch)
Expand All @@ -198,11 +198,11 @@ def _generate_edges(self, trellis_length, grid, state_order, state_radius, edge_
""" Private method """
edge_patches = []

for current_time_index in xrange(trellis_length-1):
for current_time_index in range(trellis_length-1):
grid_subset = grid[:,self.number_states * current_time_index:]
for state_count_1 in xrange(self.number_states):
for state_count_1 in range(self.number_states):
input_count = 0
for state_count_2 in xrange(self.number_states):
for state_count_2 in range(self.number_states):
dx = grid_subset[0, state_count_2+self.number_states] - grid_subset[0,state_count_1] - 2*state_radius
dy = grid_subset[1, state_count_2+self.number_states] - grid_subset[1,state_count_1]
if np.count_nonzero(self.next_state_table[state_order[state_count_1],:] == state_order[state_count_2]):
Expand All @@ -219,8 +219,8 @@ def _generate_edges(self, trellis_length, grid, state_order, state_radius, edge_
def _generate_labels(self, grid, state_order, state_radius, font):
""" Private method """

for state_count in xrange(self.number_states):
for input_count in xrange(self.number_inputs):
for state_count in range(self.number_states):
for input_count in range(self.number_inputs):
edge_label = str(input_count) + "/" + str(
self.output_table[state_order[state_count], input_count])
plt.text(grid[0, state_count]-1.5*state_radius,
Expand Down Expand Up @@ -333,16 +333,16 @@ def conv_encode(message_bits, trellis, code_type = 'default', puncture_matrix=No
number_outbits = int((number_inbits + total_memory)/rate)

outbits = np.zeros(number_outbits, 'int')
p_outbits = np.zeros(number_outbits*
puncture_matrix[0:].sum()/np.size(puncture_matrix, 1), 'int')
p_outbits = np.zeros(int(number_outbits*
puncture_matrix[0:].sum()/np.size(puncture_matrix, 1)), 'int')
next_state_table = trellis.next_state_table
output_table = trellis.output_table

# Encoding process - Each iteration of the loop represents one clock cycle
current_state = 0
j = 0

for i in xrange(number_inbits/k): # Loop through all input bits
for i in range(int(number_inbits/k)): # Loop through all input bits
current_input = bitarray2dec(inbits[i*k:(i+1)*k])
current_output = output_table[current_state][current_input]
outbits[j*n:(j+1)*n] = dec2bitarray(current_output, n)
Expand All @@ -353,15 +353,15 @@ def conv_encode(message_bits, trellis, code_type = 'default', puncture_matrix=No

term_bits = dec2bitarray(current_state, trellis.total_memory)
term_bits = term_bits[::-1]
for i in xrange(trellis.total_memory):
for i in range(trellis.total_memory):
current_input = bitarray2dec(term_bits[i*k:(i+1)*k])
current_output = output_table[current_state][current_input]
outbits[j*n:(j+1)*n] = dec2bitarray(current_output, n)
current_state = next_state_table[current_state][current_input]
j += 1

j = 0
for i in xrange(number_outbits):
for i in range(number_outbits):
if puncture_matrix[0][i % np.size(puncture_matrix, 1)] == 1:
p_outbits[j] = outbits[i]
j = j + 1
Expand All @@ -373,8 +373,8 @@ def _where_c(inarray, rows, cols, search_value, index_array):

#cdef int i, j,
number_found = 0
for i in xrange(rows):
for j in xrange(cols):
for i in range(rows):
for j in range(cols):
if inarray[i, j] == search_value:
index_array[number_found, 0] = i
index_array[number_found, 1] = j
Expand Down Expand Up @@ -407,14 +407,14 @@ def _acs_traceback(r_codeword, trellis, decoding_type,
decoded_bitarray = np.empty(k, 'int')

# Loop over all the current states (Time instant: t)
for state_num in xrange(current_number_states):
for state_num in range(current_number_states):

# Using the next state table find the previous states and inputs
# leading into the current state (Trellis)
number_found = _where_c(next_state_table, number_states, number_inputs, state_num, index_array)

# Loop over all the previous states (Time instant: t-1)
for i in xrange(number_found):
for i in range(number_found):

previous_state = index_array[i, 0]
previous_input = index_array[i, 1]
Expand Down Expand Up @@ -457,7 +457,7 @@ def _acs_traceback(r_codeword, trellis, decoding_type,
current_state = path_metrics[:,1].argmin()

# Traceback Loop
for j in reversed(xrange(1, tb_depth)):
for j in reversed(range(1, tb_depth)):

dec_symbol = decoded_symbols[current_state, j]
previous_state = paths[current_state, j]
Expand Down Expand Up @@ -538,7 +538,7 @@ def viterbi_decode(coded_bits, trellis, tb_depth=None, decoding_type='hard'):
count = 0
current_number_states = number_states

for t in xrange(1, (L+total_memory+total_memory%k)/k + 1):
for t in range(1, int((L+total_memory+total_memory%k)/k) + 1):
# Get the received codeword corresponding to t
if t <= L:
r_codeword = coded_bits[(t-1)*n:t*n]
Expand Down
Loading

0 comments on commit d23f1f8

Please sign in to comment.