Skip to content

Commit 8d3f1a8

Browse files
committed
Python 2 compatibility.
1 parent e053068 commit 8d3f1a8

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

commpy/channels.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,16 @@
1818
1919
"""
2020

21+
from __future__ import division, print_function # Python 2 compatibility
22+
2123
from numpy import complex, abs, sqrt, sum, zeros, identity, hstack, einsum, trace, kron, absolute
2224
from numpy.random import randn, random, standard_normal
2325
from scipy.linalg import sqrtm
2426

2527
__all__ = ['SISOFlatChannel', 'MIMOFlatChannel', 'bec', 'bsc', 'awgn']
2628

2729

28-
class _FlatChannel:
30+
class _FlatChannel(object):
2931

3032
def __init__(self):
3133
self.noises = None
@@ -172,7 +174,7 @@ def nb_rx(self):
172174
return 1
173175

174176
def __init__(self, noise_std=None, fading_param=(1, 0)):
175-
super().__init__()
177+
super(SISOFlatChannel, self).__init__()
176178
self.noise_std = noise_std
177179
self.fading_param = fading_param
178180

@@ -317,7 +319,7 @@ class MIMOFlatChannel(_FlatChannel):
317319
"""
318320

319321
def __init__(self, nb_tx, nb_rx, noise_std=None, fading_param=None):
320-
super().__init__()
322+
super(MIMOFlatChannel, self).__init__()
321323
self.nb_tx = nb_tx
322324
self.nb_rx = nb_rx
323325
self.noise_std = noise_std

commpy/tests/test_channels.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Authors: Bastien Trotobas <[email protected]>
22
# License: BSD 3-Clause
33

4+
from __future__ import division, print_function # Python 2 compatibility
5+
46
from numpy import ones, inf, sqrt, array, identity, zeros, dot, trace, einsum, absolute
57
from numpy.random import seed, choice, randn
68
from numpy.testing import run_module_suite, assert_raises, assert_equal, assert_allclose, \
@@ -174,7 +176,7 @@ def test_k_factor(self):
174176
err_msg='Wrong k-factor with rician fading in SISO channels')
175177

176178

177-
class MIMOTestCase:
179+
class MIMOTestCase(object):
178180
msg_length = 100000
179181
real_mods = array((-1, 1)), array((-3, 3))
180182
all_mods = array((-1, 1)), array((-3, 3)), \
@@ -218,6 +220,9 @@ def test_SISO(self):
218220

219221

220222
class TestMIMODefaultArgs(MIMOTestCase):
223+
def __init__(self):
224+
super(TestMIMODefaultArgs, self).__init__()
225+
221226
def do(self, nb_tx, nb_rx):
222227
def check(chan):
223228
assert_equal(chan.noises, None,
@@ -242,6 +247,9 @@ def check(chan):
242247

243248
@dec.slow
244249
class TestMIMOFading(MIMOTestCase):
250+
def __init__(self):
251+
super(TestMIMOFading, self).__init__()
252+
245253
def do(self, nb_tx, nb_rx):
246254
def check_chan_gain(mod, chan):
247255
msg = choice(mod, self.msg_length)
@@ -315,6 +323,9 @@ def check_chan_gain(mod, chan):
315323

316324
@dec.slow
317325
class TestMIMONoiseGeneration(MIMOTestCase):
326+
def __init__(self):
327+
super(TestMIMONoiseGeneration, self).__init__()
328+
318329
def do(self, nb_tx, nb_rx):
319330
def check_noise(mod, chan, corrected_SNR_lin):
320331
msg = choice(mod, self.msg_length)
@@ -348,13 +359,19 @@ def check_noise(mod, chan, corrected_SNR_lin):
348359

349360

350361
class TestMIMOTypeCheck(MIMOTestCase):
362+
def __init__(self):
363+
super(TestMIMOTypeCheck, self).__init__()
364+
351365
def do(self, nb_tx, nb_rx):
352366
chan = MIMOFlatChannel(nb_tx, nb_rx, 0)
353367
with assert_raises(TypeError):
354368
chan.propagate(array((1, 1j)))
355369

356370

357371
class TestMIMOShapes(MIMOTestCase):
372+
def __init__(self):
373+
super(TestMIMOShapes, self).__init__()
374+
358375
def do(self, nb_tx, nb_rx):
359376
# Without padding
360377
chan = MIMOFlatChannel(nb_tx, nb_rx, 0)
@@ -382,6 +399,9 @@ def do(self, nb_tx, nb_rx):
382399

383400

384401
class TestMIMOkFactor(MIMOTestCase):
402+
def __init__(self):
403+
super(TestMIMOkFactor, self).__init__()
404+
385405
def do(self, nb_tx, nb_rx):
386406
prod_nb = nb_tx * nb_rx
387407

0 commit comments

Comments
 (0)