From 79aa8729182d7ac2c899346f664771f08b7ce451 Mon Sep 17 00:00:00 2001 From: "Wu, Ke" Date: Thu, 11 Dec 2014 18:51:21 -0500 Subject: Add IgnoredStateSize() to FeatureFunction --- decoder/ffset.cc | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'decoder/ffset.cc') diff --git a/decoder/ffset.cc b/decoder/ffset.cc index 5820f421..8ba70389 100644 --- a/decoder/ffset.cc +++ b/decoder/ffset.cc @@ -14,6 +14,11 @@ ModelSet::ModelSet(const vector& w, const vector for (int i = 0; i < models_.size(); ++i) { model_state_pos_[i] = state_size_; state_size_ += models_[i]->StateSize(); + int num_ignored_bytes = models_[i]->IgnoredStateSize(); + if (num_ignored_bytes > 0) { + ranges_to_erase_.push_back( + {state_size_ - num_ignored_bytes, state_size_}); + } } } @@ -70,3 +75,13 @@ void ModelSet::AddFinalFeatures(const FFState& state, HG::Edge* edge,SentenceMet edge->edge_prob_.logeq(edge->feature_values_.dot(weights_)); } +bool ModelSet::NeedsStateErasure() const { return !ranges_to_erase_.empty(); } + +void ModelSet::EraseIgnoredBytes(FFState* state) const { + // TODO: can we memset? + for (const auto& range : ranges_to_erase_) { + for (int i = range.first; i < range.second; ++i) { + (*state)[i] = 0; + } + } +} -- cgit v1.2.3