From e42f9aa68a53a0a85f7c6ee257c25428c955eea2 Mon Sep 17 00:00:00 2001 From: Rasmus Munk Larsen Date: Fri, 15 Mar 2019 17:15:14 -0700 Subject: Make clipping outside [-18:18] consistent for vectorized and non-vectorized paths of scalar_logistic_. --- Eigen/src/Core/functors/UnaryFunctors.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'Eigen/src/Core/functors') diff --git a/Eigen/src/Core/functors/UnaryFunctors.h b/Eigen/src/Core/functors/UnaryFunctors.h index 1d5eb3678..03f167ac9 100644 --- a/Eigen/src/Core/functors/UnaryFunctors.h +++ b/Eigen/src/Core/functors/UnaryFunctors.h @@ -927,8 +927,9 @@ template <> struct scalar_logistic_op { EIGEN_EMPTY_STRUCT_CTOR(scalar_logistic_op) EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float operator()(const float& x) const { - const float one = 1.0f; - return one / (one + numext::exp(-x)); + if (x < -18.0f) return 0.0f; + else if (x > 18.0f) return 1.0f; + else return 1.0f / (1.0f + numext::exp(-x)); } template EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE -- cgit v1.2.3