diff options
author | Chris Dyer <redpony@gmail.com> | 2014-12-17 15:03:48 -0500 |
---|---|---|
committer | Chris Dyer <redpony@gmail.com> | 2014-12-17 15:03:48 -0500 |
commit | 1a79175f9a101d46cf27ca921213d5dd9300518f (patch) | |
tree | 9197105a2f55bc59649c555a1064628c1420bd4d /decoder/ffset.cc | |
parent | 448b451aa481b1509566ddb11abc3476466def6a (diff) | |
parent | d2c51ae79bca9b7c87f87ff458f77a6f07fff9a6 (diff) |
Merge pull request #61 from kho/ignore_state
Add IgnoredStateSize() to FeatureFunction
Diffstat (limited to 'decoder/ffset.cc')
-rw-r--r-- | decoder/ffset.cc | 15 |
1 files changed, 15 insertions, 0 deletions
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<double>& w, const vector<const FeatureFunction*> 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; + } + } +} |