From 3b445d9bf2df77e7742f808125e826c7955e0b8b Mon Sep 17 00:00:00 2001 From: Rasmus Munk Larsen Date: Thu, 1 Oct 2020 16:54:31 +0000 Subject: Add a generic packet ops corresponding to {std}::fmin and {std}::fmax. The non-sensical NaN-propagation rules for std::min std::max implemented by pmin and pmax in Eigen is a longstanding source og confusion and bug report. This change is a first step towards addressing it, as discussing in issue #564. --- test/packetmath.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'test/packetmath.cpp') diff --git a/test/packetmath.cpp b/test/packetmath.cpp index 3d8fbafc7..dd3e5b41e 100644 --- a/test/packetmath.cpp +++ b/test/packetmath.cpp @@ -783,6 +783,15 @@ void packetmath_notcomplex() { CHECK_CWISE2_IF(PacketTraits::HasMin, (std::min), internal::pmin); CHECK_CWISE2_IF(PacketTraits::HasMax, (std::max), internal::pmax); +#if EIGEN_HAS_CXX11_MATH + using std::fmin; + using std::fmax; +#else + using ::fmin; + using ::fmax; +#endif + CHECK_CWISE2_IF(PacketTraits::HasMin, fmin, internal::pfmin); + CHECK_CWISE2_IF(PacketTraits::HasMax, fmax, internal::pfmax); CHECK_CWISE1(numext::abs, internal::pabs); CHECK_CWISE2_IF(PacketTraits::HasAbsDiff, REF_ABS_DIFF, internal::pabsdiff); @@ -815,6 +824,17 @@ void packetmath_notcomplex() { for (unsigned int i = 0; i < sizeof(Scalar); ++i) data1_bits[k * sizeof(Scalar) + i] = 0x00; } } + + for (int i = 0; i < PacketSize; ++i) { + data1[i] = internal::random() ? std::numeric_limits::quiet_NaN() : Scalar(0); + data1[i + PacketSize] = internal::random() ? std::numeric_limits::quiet_NaN() : Scalar(0); + } + // Test NaN propagation for pmin and pmax. It should be equivalent to std::min. + CHECK_CWISE2_IF(PacketTraits::HasMin, (std::min), internal::pmin); + CHECK_CWISE2_IF(PacketTraits::HasMax, (std::max), internal::pmax); + // Test NaN propagation for pfmin and pfmax. It should be equivalent to std::fmin. + CHECK_CWISE2_IF(PacketTraits::HasMin, fmin, internal::pfmin); + CHECK_CWISE2_IF(PacketTraits::HasMax, fmax, internal::pfmax); } template <> -- cgit v1.2.3