diff options
author | wangershi <zhangdao@buaa.edu.cn> | 2018-07-16 21:52:17 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-07-16 21:52:17 +0800 |
commit | 7dc3233bdf9cb3f03807b2c892d965b37e3de105 (patch) | |
tree | 5ba9833f6424d5c4bab3a64fe69b6cb914560c04 | |
parent | 5c6d6eb67c76c33022908c447033c5e7f9b4f10e (diff) |
Omit some operations if only one para is kLogZero
If log_prob_1 is kLogZero and log_prob_2 is not kLogZero or log_prob_2 is kLogZero and log_prob_1 is not kLogZero, just return another parameters, this judge can omit some operations(log1pf() and expf()).
The mathematical equation is:
ln(e^(-inf)+e^(x))=ln(0+e^(x))=x
-rw-r--r-- | tensorflow/core/util/ctc/ctc_loss_util.h | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/tensorflow/core/util/ctc/ctc_loss_util.h b/tensorflow/core/util/ctc/ctc_loss_util.h index 9c71f58e23..3c77396881 100644 --- a/tensorflow/core/util/ctc/ctc_loss_util.h +++ b/tensorflow/core/util/ctc/ctc_loss_util.h @@ -31,8 +31,10 @@ const float kLogZero = -std::numeric_limits<float>::infinity(); inline float LogSumExp(float log_prob_1, float log_prob_2) { // Always have 'b' be the smaller number to avoid the exponential from // blowing up. - if (log_prob_1 == kLogZero && log_prob_2 == kLogZero) { - return kLogZero; + if (log_prob_1 == kLogZero) { + return log_prob_2; + } else if (log_prob_2 == kLogZero){ + return log_prob_1; } else { return (log_prob_1 > log_prob_2) ? log_prob_1 + log1pf(expf(log_prob_2 - log_prob_1)) |