mirror of
https://github.com/romanz/amodem.git
synced 2026-02-07 09:28:02 +08:00
common: move izip() from recv module and refactor it a bit
This commit is contained in:
@@ -93,6 +93,13 @@ def take(iterable, n):
|
||||
return np.array(list(itertools.islice(iterable, n)))
|
||||
|
||||
|
||||
# "Python 3" zip re-implementation for Python 2
|
||||
def izip(iterables):
|
||||
iterables = [iter(iterable) for iterable in iterables]
|
||||
while True:
|
||||
yield tuple([next(iterable) for iterable in iterables])
|
||||
|
||||
|
||||
class Dummy(object):
|
||||
|
||||
def __getattr__(self, name):
|
||||
|
||||
@@ -195,7 +195,7 @@ class Receiver(object):
|
||||
self.stats['rx_start'] = time.time()
|
||||
|
||||
log.info('Starting demodulation: %s', modem)
|
||||
for i, block in enumerate(izip(streams)): # block per frequency
|
||||
for i, block in enumerate(common.izip(streams)): # block per frequency
|
||||
for bits in block:
|
||||
self.stats['rx_bits'] = self.stats['rx_bits'] + len(bits)
|
||||
yield bits
|
||||
@@ -264,12 +264,6 @@ class Receiver(object):
|
||||
self.plt.title(title)
|
||||
|
||||
|
||||
def izip(streams):
|
||||
iters = [iter(s) for s in streams]
|
||||
while True:
|
||||
yield [next(i) for i in iters]
|
||||
|
||||
|
||||
def main(args):
|
||||
reader = stream.Reader(args.input, data_type=common.loads)
|
||||
signal = itertools.chain.from_iterable(reader)
|
||||
|
||||
@@ -60,3 +60,8 @@ def test_saturation():
|
||||
assert False
|
||||
except common.SaturationError as e:
|
||||
assert e.args == (max(x),)
|
||||
|
||||
def test_izip():
|
||||
x = range(10)
|
||||
y = range(-10, 0)
|
||||
assert list(common.izip([x, y])) == list(zip(x, y))
|
||||
|
||||
Reference in New Issue
Block a user