From 4217a9f09018b1eb3ce800919a69c7c3df47f9cb Mon Sep 17 00:00:00 2001 From: Rasmus Munk Larsen Date: Wed, 8 Jan 2020 22:21:37 +0000 Subject: [PATCH] The upper limits for where to use the rational approximation to the logistic function were not set carefully enough in the original commit, and some arguments would cause the function to return values greater than 1. This change set the versions found by scanning all floating point numbers (using std::nextafterf()). --- Eigen/src/Core/functors/UnaryFunctors.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Eigen/src/Core/functors/UnaryFunctors.h b/Eigen/src/Core/functors/UnaryFunctors.h index 6d1b6ba51..410cc6f58 100644 --- a/Eigen/src/Core/functors/UnaryFunctors.h +++ b/Eigen/src/Core/functors/UnaryFunctors.h @@ -942,9 +942,9 @@ struct scalar_logistic_op { // The upper cut-off is the smallest x for which the rational approximation evaluates to 1. // Choosing this value saves us a few instructions clamping the results at the end. #ifdef EIGEN_VECTORIZE_FMA - const float cutoff_upper = 16.285715103149414062f; + const float cutoff_upper = 15.7243833541870117f; #else - const float cutoff_upper = 16.619047164916992188f; + const float cutoff_upper = 15.6437711715698242f; #endif const float cutoff_lower = -9.f; if (x > cutoff_upper) return 1.0f; @@ -960,9 +960,9 @@ struct scalar_logistic_op { // Clamp the input to be at most 'cutoff_upper'. #ifdef EIGEN_VECTORIZE_FMA - const Packet cutoff_upper = pset1(16.285715103149414062f); + const Packet cutoff_upper = pset1(15.7243833541870117f); #else - const Packet cutoff_upper = pset1(16.619047164916992188f); + const Packet cutoff_upper = pset1(15.6437711715698242f); #endif const Packet x = pmin(_x, cutoff_upper);