From cc7ee5e3f6ac08750b80e468b77e8ad732e48b77 Mon Sep 17 00:00:00 2001 From: graehl Date: Tue, 27 Jul 2010 04:59:37 +0000 Subject: fsa feature templated Accum interface, phrase interface allows exceeding markov order e.g. unigram state, 3gram lm. use Accum,set_value rather than clear,add_value. warning: 3gram fsa lm disagrees with bottom-up in 4th decimal place git-svn-id: https://ws10smt.googlecode.com/svn/trunk@431 ec762483-ff6d-05da-a07a-a48fb63a330f --- decoder/sparse_vector.h | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'decoder/sparse_vector.h') diff --git a/decoder/sparse_vector.h b/decoder/sparse_vector.h index 8fc0f520..207489c5 100644 --- a/decoder/sparse_vector.h +++ b/decoder/sparse_vector.h @@ -60,6 +60,11 @@ class SparseVector { SPARSE_VECTOR_MAP_RESERVED(values_,-1,-2); } public: + T const& get_singleton() const { + assert(values_.size()==1); + return values_.begin()->second; + } + typedef SparseVector Self; typedef SPARSE_VECTOR_MAP MapType; typedef typename MapType::const_iterator const_iterator; @@ -113,7 +118,7 @@ public: return values_[index]; } - void set_value(int index, const T &value) { + inline void set_value(int index, const T &value) { values_[index] = value; } @@ -236,6 +241,15 @@ public: values_.erase(found);*/ } + template + void set_from(SparseVector const& other) { + for (typename MapType::const_iterator + it = other.values_.begin(); it != other.values_.end(); ++it) + { + values_[it->first]=it->second; + } + } + SparseVector &operator+=(const SparseVector &other) { for (typename MapType::const_iterator it = other.values_.begin(); it != other.values_.end(); ++it) -- cgit v1.2.3