diff options
author | Hieu Hoang <hieuhoang@gmail.com> | 2013-11-21 21:51:01 +0400 |
---|---|---|
committer | Hieu Hoang <hieuhoang@gmail.com> | 2013-11-21 21:51:01 +0400 |
commit | 819c006253ef358e92fb3b6723bc49bbd42c0147 (patch) | |
tree | 5d0a1027feaa7a3dfbf77ff9606433f8620d6907 /moses/ScoreComponentCollection.h | |
parent | 3c0eaac9a39a1b4395176799c7619ad1e9e95e6c (diff) |
replace CHECK with UTIL_THROW_IF in Moses
Diffstat (limited to 'moses/ScoreComponentCollection.h')
-rw-r--r-- | moses/ScoreComponentCollection.h | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/moses/ScoreComponentCollection.h b/moses/ScoreComponentCollection.h index 31b28d1c7..984f681dc 100644 --- a/moses/ScoreComponentCollection.h +++ b/moses/ScoreComponentCollection.h @@ -60,7 +60,7 @@ struct ScorePair { void PlusEquals(const StringPiece &key, float value); void PlusEquals(const std::vector<float> &other) { - CHECK(denseScores.size() == other.size()); + UTIL_THROW_IF2(denseScores.size() != other.size(), "Number of scores incorrect"); std::transform(denseScores.begin(), denseScores.end(), other.begin(), @@ -233,7 +233,8 @@ public: //! produced by sp void PlusEquals(const FeatureFunction* sp, const std::vector<float>& scores) { IndexPair indexes = GetIndexes(sp); - CHECK(scores.size() == indexes.second - indexes.first); + UTIL_THROW_IF2(scores.size() != indexes.second - indexes.first, + "Number of scores is incorrect"); for (size_t i = 0; i < scores.size(); ++i) { m_scores[i + indexes.first] += scores[i]; } @@ -244,7 +245,8 @@ public: //! a single value void PlusEquals(const FeatureFunction* sp, float score) { IndexPair indexes = GetIndexes(sp); - CHECK(1 == indexes.second - indexes.first); + UTIL_THROW_IF2(1 != indexes.second - indexes.first, + "Number of scores is incorrect"); m_scores[indexes.first] += score; } @@ -269,7 +271,8 @@ public: //! a single value void Assign(const FeatureFunction* sp, float score) { IndexPair indexes = GetIndexes(sp); - CHECK(1 == indexes.second - indexes.first); + UTIL_THROW_IF2(1 != indexes.second - indexes.first, + "Feature function must must only contain 1 score"); m_scores[indexes.first] = score; } @@ -299,7 +302,8 @@ public: float PartialInnerProduct(const FeatureFunction* sp, const std::vector<float>& rhs) const { std::vector<float> lhs = GetScoresForProducer(sp); - CHECK(lhs.size() == rhs.size()); + UTIL_THROW_IF2(lhs.size() != rhs.size(), + "Number of weights must match number of scores"); return std::inner_product(lhs.begin(), lhs.end(), rhs.begin(), 0.0f); } @@ -347,7 +351,8 @@ public: //! this will return it. If not, this method will throw float GetScoreForProducer(const FeatureFunction* sp) const { IndexPair indexes = GetIndexes(sp); - CHECK(indexes.second - indexes.first == 1); + UTIL_THROW_IF2(indexes.second - indexes.first != 1, + "Feature function must must only contain 1 score"); return m_scores[indexes.first]; } |