From 6d7af238fa34d700b93ffe4d63c3f121b2e7825d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonio=20S=C3=A1nchez?= Date: Mon, 7 Oct 2024 23:15:24 +0000 Subject: [PATCH] Adjust array_cwise for 32-bit arm. --- test/array_cwise.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/test/array_cwise.cpp b/test/array_cwise.cpp index 01f5a990f..cc901ff4c 100644 --- a/test/array_cwise.cpp +++ b/test/array_cwise.cpp @@ -48,8 +48,11 @@ std::vector special_values() { const Scalar sqrt2 = Scalar(std::sqrt(2)); const Scalar inf = Eigen::NumTraits::infinity(); const Scalar nan = Eigen::NumTraits::quiet_NaN(); + // For 32-bit arm, working within or near the subnormal range can lead to incorrect results + // due to FTZ. const Scalar denorm_min = EIGEN_ARCH_ARM ? zero : std::numeric_limits::denorm_min(); - const Scalar min = (std::numeric_limits::min)(); + const Scalar min = + EIGEN_ARCH_ARM ? Scalar(1.1) * (std::numeric_limits::min)() : (std::numeric_limits::min)(); const Scalar max = (std::numeric_limits::max)(); const Scalar max_exp = (static_cast(int(Eigen::NumTraits::max_exponent())) * Scalar(EIGEN_LN2)) / eps; std::vector values = {zero, denorm_min, min, eps, sqrt_half, one_half, one, @@ -151,6 +154,14 @@ void unary_op_test(std::string name, Fn fun, RefFn ref) { for (Index i = 0; i < valuesMap.size(); ++i) { Scalar e = static_cast(ref(valuesMap(i))); Scalar a = actual(i); +#if EIGEN_ARCH_ARM + // Work around NEON flush-to-zero mode. + // If ref returns a subnormal value and Eigen returns 0, then skip the test. + if (a == Scalar(0) && (e > -(std::numeric_limits::min)() && e < (std::numeric_limits::min)()) && + (e <= -std::numeric_limits::denorm_min() || e >= std::numeric_limits::denorm_min())) { + continue; + } +#endif bool success = (a == e) || ((numext::isfinite)(e) && internal::isApprox(a, e, tol)) || ((numext::isnan)(a) && (numext::isnan)(e)); if ((a == a) && (e == e)) success &= (bool)numext::signbit(e) == (bool)numext::signbit(a);