summaryrefslogtreecommitdiff
path: root/decoder/sparse_vector.h
diff options
context:
space:
mode:
authorgraehl <graehl@ec762483-ff6d-05da-a07a-a48fb63a330f>2010-07-27 04:59:37 +0000
committergraehl <graehl@ec762483-ff6d-05da-a07a-a48fb63a330f>2010-07-27 04:59:37 +0000
commit9f34384f610e512488df4bb0f08e962ad95d6d13 (patch)
tree6a91597be780d1460dc2f92e58452a56e745dd18 /decoder/sparse_vector.h
parentcd24c0b69bbfe3218fc8ad50f0729f388b23cc2a (diff)
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
Diffstat (limited to 'decoder/sparse_vector.h')
-rw-r--r--decoder/sparse_vector.h16
1 files changed, 15 insertions, 1 deletions
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<T> Self;
typedef SPARSE_VECTOR_MAP<int, T> 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 <class T2>
+ void set_from(SparseVector<T2> const& other) {
+ for (typename MapType::const_iterator
+ it = other.values_.begin(); it != other.values_.end(); ++it)
+ {
+ values_[it->first]=it->second;
+ }
+ }
+
SparseVector<T> &operator+=(const SparseVector<T> &other) {
for (typename MapType::const_iterator
it = other.values_.begin(); it != other.values_.end(); ++it)