summaryrefslogtreecommitdiff
path: root/decoder/indices_after.h
diff options
context:
space:
mode:
authorgraehl <graehl@ec762483-ff6d-05da-a07a-a48fb63a330f>2010-07-25 19:32:34 +0000
committergraehl <graehl@ec762483-ff6d-05da-a07a-a48fb63a330f>2010-07-25 19:32:34 +0000
commitfe91371a77ec43cc08d284ac49f00af8baa1a298 (patch)
tree0cad767686d6522d10c288d274dd358bd054ee65 /decoder/indices_after.h
parent410cc38baef914cdc0841a2e8d5a84098e48be49 (diff)
fixed CreateViterbiHypergraph (old impl did not work), so --show_derivation works
git-svn-id: https://ws10smt.googlecode.com/svn/trunk@408 ec762483-ff6d-05da-a07a-a48fb63a330f
Diffstat (limited to 'decoder/indices_after.h')
-rwxr-xr-xdecoder/indices_after.h19
1 files changed, 18 insertions, 1 deletions
diff --git a/decoder/indices_after.h b/decoder/indices_after.h
index ad94c576..dec94cc0 100755
--- a/decoder/indices_after.h
+++ b/decoder/indices_after.h
@@ -3,6 +3,7 @@
#include <boost/config.hpp> // STATIC_CONSTANT
#include <algorithm> //swap
+#include <iterator>
// iterator wrapper. inverts boolean value.
template <class AB>
@@ -47,7 +48,8 @@ unsigned new_indices(KEEP keep,O out) {
return new_indices(keep.begin(),keep.end(),out);
}
-// given a vector and a parallel sequence of bools where true means keep, keep only the marked elements while maintaining order
+// given a vector and a parallel sequence of bools where true means keep, keep only the marked elements while maintaining order.
+// this is done with a parallel sequence to the input, marked with positions the kept items would map into in a destination array, with removed items marked with the index -1. the reverse would be more compact (parallel to destination array, index of input item that goes into it) but would require the input sequence be random access.
struct indices_after
{
BOOST_STATIC_CONSTANT(unsigned,REMOVED=(unsigned)-1);
@@ -142,6 +144,21 @@ struct indices_after
to[map[i]]=v[i];
}
+ //transform collection of indices into what we're remapping. (input/output iterators)
+ template <class IndexI,class IndexO>
+ void reindex(IndexI i,IndexI const end,IndexO o) const {
+ for(;i<end;++i) {
+ unsigned m=map[*i];
+ if (m!=REMOVED)
+ *o++=m;
+ }
+ }
+
+ template <class VecI,class VecO>
+ void reindex_push_back(VecI const& i,VecO &o) const {
+ reindex(i.begin(),i.end(),std::back_inserter(o));
+ }
+
private:
indices_after(indices_after const& o)
{