diff options
author | Josh Blum | 2012-11-08 00:10:26 -0800 |
---|---|---|
committer | Josh Blum | 2012-11-08 00:10:26 -0800 |
commit | d1d9b98d31d17b9c7b8b80105de890c287ccf96e (patch) | |
tree | 26944b48f8eb758fe5ecaaa41a5bcb9e7db6d495 /tests/demo_blocks.py | |
parent | 4e6548ed237f3d6eda4383d6a07a4d1e99f404f6 (diff) | |
download | sandhi-d1d9b98d31d17b9c7b8b80105de890c287ccf96e.tar.gz sandhi-d1d9b98d31d17b9c7b8b80105de890c287ccf96e.tar.bz2 sandhi-d1d9b98d31d17b9c7b8b80105de890c287ccf96e.zip |
lot of python locking hell...
Diffstat (limited to 'tests/demo_blocks.py')
-rw-r--r-- | tests/demo_blocks.py | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/tests/demo_blocks.py b/tests/demo_blocks.py new file mode 100644 index 0000000..3a5d5cb --- /dev/null +++ b/tests/demo_blocks.py @@ -0,0 +1,57 @@ +import gras +import numpy + +class add_2x(gras.Block): + def __init__(self, sig): + gras.Block.__init__(self, + name = "add 2x", + in_sig = [sig, sig], + out_sig = [sig], + ) + + def work(self, ins, outs): + nitems = min(*map(len, (ins[0], ins[1], outs[0]))) + outs[0][:nitems] = ins[0][:nitems] + ins[1][:nitems] + self.consume(0, nitems) + self.consume(1, nitems) + self.produce(0, nitems) + +class NullSource(gras.Block): + def __init__(self, out_sig): + gras.Block.__init__(self, 'NullSource', out_sig=[out_sig]) + + def work(self, ins, outs): + outs[0][:] = numpy.zeros(len(outs[0])) + self.produce(0, len(outs[0])) + +class NullSink(gras.Block): + def __init__(self, in_sig): + gras.Block.__init__(self, 'NullSink', in_sig=[in_sig]) + + def work(self, ins, outs): + self.consume(0, len(ins[0])) + +class VectorSource(gras.Block): + def __init__(self, out_sig, vec): + gras.Block.__init__(self, name='VectorSource', out_sig=[out_sig]) + self._vec = vec + + def work(self, ins, outs): + num = min(len(outs[0]), len(self._vec)) + outs[0][:num] = self._vec[:num] + self.produce(0, num) + self._vec = self._vec[num:] + if not self._vec: + self.mark_done() + +class VectorSink(gras.Block): + def __init__(self, in_sig): + gras.Block.__init__(self, name='VectorSink', in_sig=[in_sig]) + self._vec = list() + + def get_vector(self): + return tuple(self._vec) + + def work(self, ins, outs): + self._vec.extend(ins[0].copy()) + self.consume(0, len(ins[0])) |