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()).

This commit is contained in:
Rasmus Munk Larsen 2020-01-08 22:21:37 +00:00
parent 9623c0c4b9
commit 4217a9f090

View File

@ -942,9 +942,9 @@ struct scalar_logistic_op<float> {
// 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<float> {
// Clamp the input to be at most 'cutoff_upper'.
#ifdef EIGEN_VECTORIZE_FMA
const Packet cutoff_upper = pset1<Packet>(16.285715103149414062f);
const Packet cutoff_upper = pset1<Packet>(15.7243833541870117f);
#else
const Packet cutoff_upper = pset1<Packet>(16.619047164916992188f);
const Packet cutoff_upper = pset1<Packet>(15.6437711715698242f);
#endif
const Packet x = pmin(_x, cutoff_upper);