use Vector for scores

This commit is contained in:
Hieu Hoang 2015-12-10 21:21:52 +00:00
parent cd34308236
commit 8d69c1dd38
4 changed files with 36 additions and 1 deletions

View File

@ -95,6 +95,26 @@ void Scores::PlusEquals(const System &system,
}
}
void Scores::PlusEquals(const System &system,
const FeatureFunction &featureFunction,
const Vector<SCORE> &scores)
{
assert(scores.size() == featureFunction.GetNumScores());
const Weights &weights = system.weights;
size_t ffStartInd = featureFunction.GetStartInd();
for (size_t i = 0; i < scores.size(); ++i) {
SCORE incrScore = scores[i];
if (m_scores) {
m_scores[ffStartInd + i] += incrScore;
}
//cerr << "ffStartInd=" << ffStartInd << " " << i << endl;
SCORE weight = weights[ffStartInd + i];
m_total += incrScore * weight;
}
}
void Scores::PlusEquals(const System &system, const Scores &other)
{
size_t numScores = system.featureFunctions.GetNumScores();

View File

@ -10,6 +10,7 @@
#include <string>
#include "TypeDef.h"
#include "MemPool.h"
#include "Vector.h"
namespace Moses2
{
@ -43,6 +44,10 @@ public:
const FeatureFunction &featureFunction,
const std::vector<SCORE> &scores);
void PlusEquals(const System &system,
const FeatureFunction &featureFunction,
const Vector<SCORE> &scores);
void PlusEquals(const System &system,
const Scores &scores);

View File

@ -156,7 +156,7 @@ TargetPhrase *ProbingPT::CreateTargetPhrase(MemPool &pool, const System &system,
}
// score for this phrase table
vector<SCORE> scores = probingTargetPhrase.prob;
Vector<SCORE> scores(pool, probingTargetPhrase.prob);
std::transform(scores.begin(), scores.end(), scores.begin(), TransformScore);
tp->GetScores().PlusEquals(system, *this, scores);

View File

@ -35,6 +35,16 @@ public:
m_arr = pool.Allocate<T>(size);
}
Vector(MemPool &pool, const std::vector<T> &vec)
:m_size(vec.size())
,m_maxSize(vec.size())
{
m_arr = pool.Allocate<T>(m_size);
for (size_t i = 0; i < m_size; ++i) {
m_arr[i] = vec[i];
}
}
virtual ~Vector()
{