From bf78d3580df68853755e64232e6c9ddd6625a451 Mon Sep 17 00:00:00 2001 From: Feiteng Date: Tue, 21 Jun 2016 09:10:37 +0800 Subject: [PATCH] avoid repeated exp() calculation --- include/detail/cpu_ctc.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/include/detail/cpu_ctc.h b/include/detail/cpu_ctc.h index c272f24b658791..3f46a6c9f09a55 100644 --- a/include/detail/cpu_ctc.h +++ b/include/detail/cpu_ctc.h @@ -168,11 +168,13 @@ CpuCTC::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; } } }