summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJosh Blum2012-11-18 17:33:40 -0800
committerJosh Blum2012-11-18 17:33:40 -0800
commit4f9768f88eeed0c0b7e6ce7335752475d6a20df1 (patch)
tree833f69f1dd86332c7f2ee5e5b3ccd6795da3cba2
parent2918d7145bfc1bed64f1ec4939a9856a8175aba8 (diff)
downloadsandhi-4f9768f88eeed0c0b7e6ce7335752475d6a20df1.tar.gz
sandhi-4f9768f88eeed0c0b7e6ce7335752475d6a20df1.tar.bz2
sandhi-4f9768f88eeed0c0b7e6ce7335752475d6a20df1.zip
propagate_tags director for python
-rw-r--r--include/gras/block.hpp12
-rw-r--r--python/gras/GRAS_Block.i33
2 files changed, 32 insertions, 13 deletions
diff --git a/include/gras/block.hpp b/include/gras/block.hpp
index bddc0f4..70c570c 100644
--- a/include/gras/block.hpp
+++ b/include/gras/block.hpp
@@ -163,14 +163,18 @@ struct GRAS_API Block : Element
void erase_input_tags(const size_t which_input);
/*!
- * Overload me to implement tag propagation logic:
+ * Overload me to implement custom tag propagation logic:
*
* Propagate tags will be given an iterator for all input tags
* whose offset counts is less than the number of items consumed.
- * It is the job of the propagate_tags overload to
+ * It is the job of the propagate_tags overloaded function to
* propagate tags to the downstream and interpolate the offset.
- * By default, the propagate_tags implementation is a NOP.
- * Also, the user may simple propagate tags from within work.
+ *
+ * By default, the propagate_tags implementation is to:
+ * broadcast each consumed input tags to all output ports
+ * using the local input offset as the local output offset.
+ *
+ * Also, the user may simply propagate tags from within work.
*/
virtual void propagate_tags(const size_t which_input, const TagIter &iter);
diff --git a/python/gras/GRAS_Block.i b/python/gras/GRAS_Block.i
index f068b25..2aa1166 100644
--- a/python/gras/GRAS_Block.i
+++ b/python/gras/GRAS_Block.i
@@ -69,7 +69,6 @@ struct PyGILPhondler
%include <std_vector.i>
%template () std::vector<size_t>;
%template () std::vector<void *>;
-%template () std::vector<gras::Tag>;
////////////////////////////////////////////////////////////////////////
// Pull in the implementation goodies
@@ -168,8 +167,11 @@ struct BlockPython : Block
void propagate_tags(const size_t which_input, const TagIter &iter)
{
- //TODO implement _Py_ version of this
+ PyGILPhondler phil;
+ return this->_Py_propagate_tags(which_input, iter);
}
+
+ virtual void _Py_propagate_tags(const size_t which_input, const TagIter &iter) = 0;
};
}
@@ -217,6 +219,14 @@ class Tag(object):
self.value = value
self.srcid = srcid
+def YieldTagIter(iter):
+ for t in iter: yield Tag(
+ offset=t.offset,
+ key=PMC2Py(t.key),
+ value=PMC2Py(t.value),
+ srcid=PMC2Py(t.srcid),
+ )
+
class Block(BlockPython):
def __init__(self, name='Block', in_sig=None, out_sig=None):
BlockPython.__init__(self, name)
@@ -290,12 +300,17 @@ class Block(BlockPython):
BlockPython.post_output_tag(self, which_output, t)
def get_input_tags(self, which_input):
- for t in BlockPython.get_input_tags(self, which_input):
- yield Tag(
- offset=t.offset,
- key=PMC2Py(t.key),
- value=PMC2Py(t.value),
- srcid=PMC2Py(t.srcid),
- )
+ return YieldTagIter(BlockPython.get_input_tags(self, which_input))
+
+ def _Py_propagate_tags(self, which_input, iter):
+ try: return self.propagate_tags(which_input, iter)
+ except: traceback.print_exc(); raise
+
+ def propagate_tags(self, i, iter):
+ for o in self.__out_indexes:
+ for t in YieldTagIter(iter):
+ t.offset -= self.get_consumed(i)
+ t.offset += self.get_produced(o)
+ self.post_output_tag(o, t)
%}