Skip to content

Commit

Permalink
Merge pull request PaddlePaddle#41 from lifeiteng/master
Browse files Browse the repository at this point in the history
avoid repeated exp() calculation
  • Loading branch information
ekelsen authored Jul 1, 2016
2 parents e80803b + bf78d35 commit 19547b5
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions include/detail/cpu_ctc.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,13 @@ CpuCTC<ProbT>::softmax(const ProbT* const activations, ProbT* probs,
max_activation = std::max(max_activation, activations[r + col_offset]);

ProbT denom = ProbT(0.);
for(int r = 0; r < alphabet_size_; ++r)
denom += std::exp(activations[r + col_offset] - max_activation);
for(int r = 0; r < alphabet_size_; ++r) {
probs[r + col_offset] = std::exp(activations[r + col_offset] - max_activation);
denom += probs[r + col_offset];
}

for(int r = 0; r < alphabet_size_; ++r) {
probs[r + col_offset] = std::exp(activations[r + col_offset] - max_activation) / denom;
probs[r + col_offset] /= denom;
}
}
}
Expand Down

0 comments on commit 19547b5

Please sign in to comment.