Skip to content

Commit

Permalink
Numerical precision in benchmark
Browse files Browse the repository at this point in the history
So people see numbers that are vaguely correct, without too much overhead
  • Loading branch information
kpu committed Sep 14, 2015
1 parent 0fdb09c commit 638056b
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions lm/kenlm_benchmark_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ template <class Model, class Width> void QueryFromBytes(const Model &model, int
const lm::ngram::State *next_state = begin_state;
Width kEOS = model.GetVocabulary().EndSentence();
Width buf[4096];
float sum = 0.0;
while (true) {
std::size_t got = util::ReadOrEOF(fd_in, buf, sizeof(buf));
if (!got) break;
// Numerical precision: batch sums.
double total = 0.0;
while (std::size_t got = util::ReadOrEOF(fd_in, buf, sizeof(buf))) {
float sum = 0.0;
UTIL_THROW_IF2(got % sizeof(Width), "File size not a multiple of vocab id size " << sizeof(Width));
got /= sizeof(Width);
// Do even stuff first.
Expand All @@ -51,8 +51,9 @@ template <class Model, class Width> void QueryFromBytes(const Model &model, int
sum += model.FullScore(*next_state, *i, state[2]).prob;
next_state = (*i++ == kEOS) ? begin_state : &state[2];
}
total += sum;
}
std::cout << "Sum is " << sum << std::endl;
std::cout << "Sum is " << total << std::endl;
}

template <class Model, class Width> void DispatchFunction(const Model &model, bool query) {
Expand Down

0 comments on commit 638056b

Please sign in to comment.