From 5dec2fff48855084245b7ea5e6943552347522de Mon Sep 17 00:00:00 2001 From: Olivier Guilyardi Date: Fri, 19 Feb 2010 13:49:48 +0000 Subject: [PATCH] restore input adapter nframes() suppressed in r123 --- core.py | 13 +++++++++++++ tests/testinputadapter.py | 10 ++++++++++ 2 files changed, 23 insertions(+) diff --git a/core.py b/core.py index b4c3153..f5b3c31 100644 --- a/core.py +++ b/core.py @@ -106,6 +106,19 @@ class FixedSizeInputAdapter(object): self.len = 0 self.pad = pad + def nframes(self, input_nframes): + """Return the total number of frames that this adapter will output according to the + input_nframes argument""" + + nframes = input_nframes + if self.pad: + mod = input_nframes % self.buffer_size + if mod: + nframes += self.buffer_size - mod + + return nframes + + def process(self, frames, eod): """Returns an iterator over tuples of the form (buffer, eod) where buffer is a fixed-sized block of data, and eod indicates whether this is the last block. diff --git a/tests/testinputadapter.py b/tests/testinputadapter.py index 0c051c7..28550e1 100644 --- a/tests/testinputadapter.py +++ b/tests/testinputadapter.py @@ -23,6 +23,11 @@ data = numpy.arange(44).reshape(2,22).transpose() adapter = FixedSizeInputAdapter(4, 2) stdout.write("%s simple test" % adapter.__class__.__name__) +expected = len(data) +actual = adapter.nframes(len(data)) +if actual != expected: + raise Exception("%d != %d nframes", (actual, expected)) + test(adapter, data[0:1], False, []) test(adapter, data[1:5], False, [data[0:4]], False) test(adapter, data[5:12], False, [data[4:8], data[8:12]], False) @@ -37,6 +42,11 @@ stdout.write(" OK\n") adapter = FixedSizeInputAdapter(4, 2, pad=True) stdout.write("%s padding test" % adapter.__class__.__name__) +expected = len(data) + 2 +actual = adapter.nframes(len(data)) +if actual != expected: + raise Exception("%d != %d nframes", (actual, expected)) + test(adapter, data[0:21], False, [data[0:4], data[4:8], data[8:12], data[12:16], data[16:20]], False) test(adapter, data[21:22], True, [[ [20, 42], -- 2.39.5