From b2126fd6b5e232d072ceadb1abb6695ae3352e2e Mon Sep 17 00:00:00 2001 From: Antonio Sanchez Date: Wed, 20 Jan 2021 19:00:09 -0800 Subject: Fix pfrexp/pldexp for half. The recent addition of vectorized pow (!330) relies on `pfrexp` and `pldexp`. This was missing for `Eigen::half` and `Eigen::bfloat16`. Adding tests for these packet ops also exposed an issue with handling negative values in `pfrexp`, returning an incorrect exponent. Added the missing implementations, corrected the exponent in `pfrexp1`, and added `packetmath` tests. --- test/packetmath.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'test/packetmath.cpp') diff --git a/test/packetmath.cpp b/test/packetmath.cpp index ab9bec183..b7562e6a1 100644 --- a/test/packetmath.cpp +++ b/test/packetmath.cpp @@ -46,6 +46,21 @@ inline bool REF_MUL(const bool& a, const bool& b) { return a && b; } +template +inline T REF_FREXP(const T& x, T& exp) { + int iexp; + EIGEN_USING_STD(frexp) + const T out = static_cast(frexp(x, &iexp)); + exp = static_cast(iexp); + return out; +} + +template +inline T REF_LDEXP(const T& x, const T& exp) { + EIGEN_USING_STD(ldexp) + return static_cast(ldexp(x, static_cast(exp))); +} + // Uses pcast to cast from one array to another. template struct pcast_array; @@ -552,6 +567,17 @@ void packetmath_real() { data2[i] = Scalar(internal::random(-87, 88)); } CHECK_CWISE1_IF(PacketTraits::HasExp, std::exp, internal::pexp); + CHECK_CWISE1_BYREF1_IF(PacketTraits::HasExp, REF_FREXP, internal::pfrexp); + for (int i = 0; i < PacketSize; ++i) { + data1[i] = Scalar(internal::random(-1, 1)); + data2[i] = Scalar(internal::random(-1, 1)); + } + for (int i = 0; i < PacketSize; ++i) { + data1[i+PacketSize] = Scalar(internal::random(0, 4)); + data2[i+PacketSize] = Scalar(internal::random(0, 4)); + } + CHECK_CWISE2_IF(PacketTraits::HasExp, REF_LDEXP, internal::pldexp); + for (int i = 0; i < size; ++i) { data1[i] = Scalar(internal::random(-1, 1) * std::pow(10., internal::random(-6, 6))); data2[i] = Scalar(internal::random(-1, 1) * std::pow(10., internal::random(-6, 6))); -- cgit v1.2.3