Replace fabs with std::fabs (#1035)

fabs only accept double, there it needs float.
Similar thing for log.
This commit is contained in:
Changming Sun 2019-05-15 10:00:12 -07:00 committed by GitHub
parent 9029c496b0
commit 46bf6fd1ef
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 4 deletions

View file

@ -25,6 +25,7 @@
#pragma warning(disable : 4996)
#endif
#include <algorithm>
#include <cmath>
#ifdef _MSC_VER
#pragma warning(pop)
#endif
@ -79,7 +80,7 @@ common::Status SoftmaxCPU(const int64_t N,
}
} else {
for (int i = 0; i < N; ++i) {
auto log_fmaxf_scale_i = log(fmaxf(scale[i], 1e-20f));
auto log_fmaxf_scale_i = std::log(fmaxf(scale[i], 1e-20f));
for (int j = 0; j < D; ++j) {
Ydata[i * D + j] = Xdata[i * D + j] - rowmax[i] - log_fmaxf_scale_i;
}

View file

@ -39,9 +39,8 @@ template <typename T>
inline T Sigmoid(T x, T alpha RNN_UNUSED_PARAMETER, T beta RNN_UNUSED_PARAMETER) {
if (x >= 0) {
return 1 / (1 + exp(-x));
} else {
return exp(x) / (1 + exp(x));
}
return exp(x) / (1 + exp(x));
}
template <typename T>
@ -69,7 +68,7 @@ inline T Softsign(T x, T alpha, T beta);
template <>
inline float Softsign<float>(float x, float alpha ORT_ATTRIBUTE_UNUSED, float beta ORT_ATTRIBUTE_UNUSED) {
return x / (1 + fabs(x));
return x / (1 + std::fabs(x));
}
template <>