diff options
author | graehl <graehl@ec762483-ff6d-05da-a07a-a48fb63a330f> | 2010-07-16 01:57:08 +0000 |
---|---|---|
committer | graehl <graehl@ec762483-ff6d-05da-a07a-a48fb63a330f> | 2010-07-16 01:57:08 +0000 |
commit | 538bc2149631e989e4806165632c5460c3514670 (patch) | |
tree | 85079e928800058790ec26abbb8a968126256c5d /decoder/sparse_vector.h | |
parent | 1cfa8735f4cd7264e70cc6918bbd58c86a015ee4 (diff) |
oracle refactor, oracle vest directions, sparse_vector
git-svn-id: https://ws10smt.googlecode.com/svn/trunk@280 ec762483-ff6d-05da-a07a-a48fb63a330f
Diffstat (limited to 'decoder/sparse_vector.h')
-rw-r--r-- | decoder/sparse_vector.h | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/decoder/sparse_vector.h b/decoder/sparse_vector.h index 9c7c9c79..43880014 100644 --- a/decoder/sparse_vector.h +++ b/decoder/sparse_vector.h @@ -12,6 +12,13 @@ #include "fdict.h" +template <class T> +inline T & extend_vector(std::vector<T> &v,int i) { + if (i>=v.size()) + v.resize(i+1); + return v[i]; +} + template <typename T> class SparseVector { public: @@ -29,6 +36,17 @@ public: } + void init_vector(std::vector<T> *vp) const { + init_vector(*vp); + } + + void init_vector(std::vector<T> &v) const { + v.clear(); + for (const_iterator i=values_.begin(),e=values_.end();i!=e;++i) + extend_vector(v,i->first)=i->second; + } + + void set_new_value(int index, T const& val) { assert(values_.find(index)==values_.end()); values_[index]=val; @@ -312,7 +330,7 @@ private: typedef SparseVector<double> FeatureVector; typedef SparseVector<double> WeightVector; - +typedef std::vector<double> DenseWeightVector; template <typename T> SparseVector<T> operator+(const SparseVector<T>& a, const SparseVector<T>& b) { SparseVector<T> result = a; |