From f216419b6a6eb1afa1c5d1c62d69ea07a67b87b6 Mon Sep 17 00:00:00 2001 From: graehl Date: Sat, 24 Jul 2010 21:24:59 +0000 Subject: compile git-svn-id: https://ws10smt.googlecode.com/svn/trunk@400 ec762483-ff6d-05da-a07a-a48fb63a330f --- decoder/ff_fsa.h | 4 ++-- decoder/sparse_vector.h | 10 +++++++--- 2 files changed, 9 insertions(+), 5 deletions(-) (limited to 'decoder') diff --git a/decoder/ff_fsa.h b/decoder/ff_fsa.h index 0a7aebde..e199ec04 100755 --- a/decoder/ff_fsa.h +++ b/decoder/ff_fsa.h @@ -136,7 +136,7 @@ public: // NOTE: if you want to e.g. track statistics, cache, whatever, cast const away or use mutable members inline void Scan(SentenceMetadata const& smeta,const Hypergraph::Edge& edge,WordID w,void const* state,void *next_state,FeatureVector *features) const { - features->add_value(fid_,Scan1(w,state,next_state)); + features->maybe_add(fid_,Scan1(w,state,next_state)); } // don't set state-bytes etc. in ctor because it may depend on parsing param string @@ -244,7 +244,7 @@ public: int markov_order() const { return 1; } Featval ScanT1(WordID w,int prevlen,int &len) const { return 0; } inline void ScanT(SentenceMetadata const& smeta,const Hypergraph::Edge& edge,WordID w,int prevlen,int &len,FeatureVector *features) const { - features->add_value(d().fid_,d().ScanT1(w,prevlen,len)); + features->maybe_add(d().fid_,d().ScanT1(w,prevlen,len)); } inline void Scan(SentenceMetadata const& smeta,const Hypergraph::Edge& edge,WordID w,void const* st,void *next_state,FeatureVector *features) const { diff --git a/decoder/sparse_vector.h b/decoder/sparse_vector.h index ec623c6e..0325c1ee 100644 --- a/decoder/sparse_vector.h +++ b/decoder/sparse_vector.h @@ -115,15 +115,19 @@ public: values_[index] = value; } - void add_value(int index, const T &value) { - if (!value) return; + inline void maybe_add(int index, const T& value) { + if (value) add_value(index,value); + } + + T& add_value(int index, const T &value) { #if 1 - values_[index]+=value; + return values_[index]+=value; #else // this is not really going to be any faster, and we already rely on default init = 0 init std::pair art=values_.insert(std::make_pair(index,value)); T &val=art.first->second; if (!art.second) val += value; // already existed + return val; #endif } -- cgit v1.2.3