diff options
Diffstat (limited to 'utils')
-rw-r--r-- | utils/dict.h | 2 | ||||
-rw-r--r-- | utils/fast_sparse_vector.h | 16 | ||||
-rw-r--r-- | utils/sampler.h | 2 |
3 files changed, 18 insertions, 2 deletions
diff --git a/utils/dict.h b/utils/dict.h index 75ea3def..a3400868 100644 --- a/utils/dict.h +++ b/utils/dict.h @@ -1,7 +1,6 @@ #ifndef DICT_H_ #define DICT_H_ - #include <cassert> #include <cstring> @@ -74,6 +73,7 @@ class Dict { inline const std::string& Convert(const WordID& id) const { if (id == 0) return b0_; assert(id <= (int)words_.size()); + //if (id < 0 || id > (int)words_.size()) return b0_; return words_[id-1]; } diff --git a/utils/fast_sparse_vector.h b/utils/fast_sparse_vector.h index d11be48f..2c49948c 100644 --- a/utils/fast_sparse_vector.h +++ b/utils/fast_sparse_vector.h @@ -196,6 +196,14 @@ class FastSparseVector { else return local_size_; } + size_t size_nonzero() const { + size_t sz = 0; + const_iterator it = this->begin(); + for (; it != this->end(); ++it) { + if (nonzero(it->first)) sz++; + } + return sz; + } inline void clear() { if (is_remote_) delete data_.rbmap; is_remote_ = false; @@ -220,6 +228,14 @@ class FastSparseVector { } return *this; } + template <typename O> + inline FastSparseVector<O>& plus_eq_v_times_s(const FastSparseVector<O>& other, const O scalar) { + const typename FastSparseVector<O>::const_iterator end = other.end(); + for (typename FastSparseVector<O>::const_iterator it = other.begin(); it != end; ++it) { + get_or_create_bin(it->first) += it->second * scalar; + } + return *this; + } inline FastSparseVector& operator-=(const FastSparseVector& other) { const typename FastSparseVector::const_iterator end = other.end(); for (typename FastSparseVector::const_iterator it = other.begin(); it != end; ++it) { diff --git a/utils/sampler.h b/utils/sampler.h index 22c873d4..bdbc01b0 100644 --- a/utils/sampler.h +++ b/utils/sampler.h @@ -32,7 +32,7 @@ struct RandomNumberGenerator { std::cerr << "Warning: could not read from /dev/urandom. Seeding from clock" << std::endl; seed = std::time(NULL); } - std::cerr << "Seeding random number sequence to " << seed << std::endl; + //std::cerr << "Seeding random number sequence to " << seed << std::endl; return seed; } |