Skip to content

Commit d23f1f8

Browse files
committed
Fixes veeresht#8. Minor changes to ensure Python 3.5 compatibility.
1 parent 55f2489 commit d23f1f8

File tree

11 files changed

+74
-193
lines changed

11 files changed

+74
-193
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ language: python
22
python:
33
# We don't actually use the Travis Python, but this keeps it organized.
44
- "2.7"
5-
#- "3.3"
5+
- "3.5"
66
#- "3.4"
77
notifications:
88
email: false

README.rst

Lines changed: 0 additions & 120 deletions
This file was deleted.

commpy/__init__.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
1414
1515
"""
1616
#from channelcoding import *
17-
from filters import *
18-
from modulation import *
19-
from impairments import *
20-
from sequences import *
21-
from channels import *
17+
from commpy.filters import *
18+
from commpy.modulation import *
19+
from commpy.impairments import *
20+
from commpy.sequences import *
21+
from commpy.channels import *
2222

2323
try:
2424
from numpy.testing import Tester

commpy/channelcoding/__init__.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,12 @@
6262
6363
"""
6464

65-
from convcode import Trellis, conv_encode, viterbi_decode
66-
from interleavers import *
67-
from turbo import turbo_encode, map_decode, turbo_decode
68-
from ldpc import get_ldpc_code_params, ldpc_bp_decode
69-
from gfields import *
70-
from algcode import *
65+
from commpy.channelcoding.convcode import Trellis, conv_encode, viterbi_decode
66+
from commpy.channelcoding.interleavers import *
67+
from commpy.channelcoding.turbo import turbo_encode, map_decode, turbo_decode
68+
from commpy.channelcoding.ldpc import get_ldpc_code_params, ldpc_bp_decode
69+
from commpy.channelcoding.gfields import *
70+
from commpy.channelcoding.algcode import *
7171

7272
try:
7373
from numpy.testing import Tester

commpy/channelcoding/algcode.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from fractions import gcd
77
from numpy import array, arange, concatenate, convolve
88

9-
from gfields import GF, polymultiply, poly_to_string
9+
from commpy.channelcoding.gfields import GF, polymultiply, poly_to_string
1010
from commpy.utilities import dec2bitarray, bitarray2dec
1111

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

3333

3434
if n%2 == 0:
35-
raise ValueError, "n cannot be an even number"
35+
raise ValueError("n cannot be an even number")
3636

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

55-
for i in xrange(1, 2**len(minpol_list)):
55+
for i in range(1, 2**len(minpol_list)):
5656
i_array = dec2bitarray(i, len(minpol_list))
5757
subset_array = minpol_degrees[i_array == 1]
5858
if int(subset_array.sum()) == (n-k):
@@ -70,4 +70,4 @@ def cyclic_code_genpoly(n, k):
7070
if __name__ == "__main__":
7171
genpolys = cyclic_code_genpoly(31, 21)
7272
for poly in genpolys:
73-
print poly_to_string(poly)
73+
print(poly_to_string(poly))

commpy/channelcoding/convcode.py

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ def __init__(self, memory, g_matrix, feedback = 0, code_type = 'default'):
105105
[self.k, self.n] = g_matrix.shape
106106

107107
if code_type == 'rsc':
108-
for i in xrange(self.k):
108+
for i in range(self.k):
109109
g_matrix[i][i] = feedback
110110

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

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

122-
for current_input in xrange(self.number_inputs):
122+
for current_input in range(self.number_inputs):
123123
outbits = np.zeros(self.n, 'int')
124124

125125
# Compute the values in the output_table
126-
for r in xrange(self.n):
126+
for r in range(self.n):
127127

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

132-
for l in xrange(self.k):
132+
for l in range(self.k):
133133

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

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

@@ -184,7 +184,7 @@ def _generate_states(self, trellis_length, grid, state_order, state_radius, font
184184
""" Private method """
185185
state_patches = []
186186

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

201-
for current_time_index in xrange(trellis_length-1):
201+
for current_time_index in range(trellis_length-1):
202202
grid_subset = grid[:,self.number_states * current_time_index:]
203-
for state_count_1 in xrange(self.number_states):
203+
for state_count_1 in range(self.number_states):
204204
input_count = 0
205-
for state_count_2 in xrange(self.number_states):
205+
for state_count_2 in range(self.number_states):
206206
dx = grid_subset[0, state_count_2+self.number_states] - grid_subset[0,state_count_1] - 2*state_radius
207207
dy = grid_subset[1, state_count_2+self.number_states] - grid_subset[1,state_count_1]
208208
if np.count_nonzero(self.next_state_table[state_order[state_count_1],:] == state_order[state_count_2]):
@@ -219,8 +219,8 @@ def _generate_edges(self, trellis_length, grid, state_order, state_radius, edge_
219219
def _generate_labels(self, grid, state_order, state_radius, font):
220220
""" Private method """
221221

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

335335
outbits = np.zeros(number_outbits, 'int')
336-
p_outbits = np.zeros(number_outbits*
337-
puncture_matrix[0:].sum()/np.size(puncture_matrix, 1), 'int')
336+
p_outbits = np.zeros(int(number_outbits*
337+
puncture_matrix[0:].sum()/np.size(puncture_matrix, 1)), 'int')
338338
next_state_table = trellis.next_state_table
339339
output_table = trellis.output_table
340340

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

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

354354
term_bits = dec2bitarray(current_state, trellis.total_memory)
355355
term_bits = term_bits[::-1]
356-
for i in xrange(trellis.total_memory):
356+
for i in range(trellis.total_memory):
357357
current_input = bitarray2dec(term_bits[i*k:(i+1)*k])
358358
current_output = output_table[current_state][current_input]
359359
outbits[j*n:(j+1)*n] = dec2bitarray(current_output, n)
360360
current_state = next_state_table[current_state][current_input]
361361
j += 1
362362

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

374374
#cdef int i, j,
375375
number_found = 0
376-
for i in xrange(rows):
377-
for j in xrange(cols):
376+
for i in range(rows):
377+
for j in range(cols):
378378
if inarray[i, j] == search_value:
379379
index_array[number_found, 0] = i
380380
index_array[number_found, 1] = j
@@ -407,14 +407,14 @@ def _acs_traceback(r_codeword, trellis, decoding_type,
407407
decoded_bitarray = np.empty(k, 'int')
408408

409409
# Loop over all the current states (Time instant: t)
410-
for state_num in xrange(current_number_states):
410+
for state_num in range(current_number_states):
411411

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

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

419419
previous_state = index_array[i, 0]
420420
previous_input = index_array[i, 1]
@@ -457,7 +457,7 @@ def _acs_traceback(r_codeword, trellis, decoding_type,
457457
current_state = path_metrics[:,1].argmin()
458458

459459
# Traceback Loop
460-
for j in reversed(xrange(1, tb_depth)):
460+
for j in reversed(range(1, tb_depth)):
461461

462462
dec_symbol = decoded_symbols[current_state, j]
463463
previous_state = paths[current_state, j]
@@ -538,7 +538,7 @@ def viterbi_decode(coded_bits, trellis, tb_depth=None, decoding_type='hard'):
538538
count = 0
539539
current_number_states = number_states
540540

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

0 commit comments

Comments
 (0)