Qualify calls to isnan

The C++ standard library is allowed to only put these into std:: and not in the
global namespace. Some versions of GCC seem to be doing that, breaking the
build. Just use the Eigen numext version consistenly.

PiperOrigin-RevId: 356748330
Change-Id: I38dad1c4cfd0480eed41600a14823ad505318f1d
This commit is contained in:
Benjamin Kramer 2021-02-10 09:11:53 -08:00 committed by TensorFlower Gardener
parent 119ade110d
commit 95efe6e4d0

View File

@ -49,26 +49,28 @@ static ::testing::AssertionResult EqualFailure(const T& x, const T& y) {
}
static ::testing::AssertionResult IsEqual(float x, float y) {
// We consider NaNs equal for testing.
if ((isnan(x) && isnan(y)) ||
if ((Eigen::numext::isnan(x) && Eigen::numext::isnan(y)) ||
::testing::internal::CmpHelperFloatingPointEQ<float>("", "", x, y))
return ::testing::AssertionSuccess();
return EqualFailure(x, y);
}
static ::testing::AssertionResult IsEqual(double x, double y) {
// We consider NaNs equal for testing.
if ((isnan(x) && isnan(y)) ||
if ((Eigen::numext::isnan(x) && Eigen::numext::isnan(y)) ||
::testing::internal::CmpHelperFloatingPointEQ<double>("", "", x, y))
return ::testing::AssertionSuccess();
return EqualFailure(x, y);
}
static ::testing::AssertionResult IsEqual(Eigen::half x, Eigen::half y) {
// We consider NaNs equal for testing.
if (isnan(x) && isnan(y)) return ::testing::AssertionSuccess();
if (Eigen::numext::isnan(x) && Eigen::numext::isnan(y))
return ::testing::AssertionSuccess();
// Below is a reimplementation of CmpHelperFloatingPointEQ<Eigen::half>, which
// we cannot use because Eigen::half is not default-constructible.
if (isnan(x) || isnan(y)) return EqualFailure(x, y);
if (Eigen::numext::isnan(x) || Eigen::numext::isnan(y))
return EqualFailure(x, y);
auto sign_and_magnitude_to_biased = [](uint16_t sam) {
const uint16_t kSignBitMask = 0x8000;
@ -115,7 +117,8 @@ template <typename T>
static ::testing::AssertionResult IsClose(const T& x, const T& y, const T& atol,
const T& rtol) {
// We consider NaNs equal for testing.
if (isnan(x) && isnan(y)) return ::testing::AssertionSuccess();
if (Eigen::numext::isnan(x) && Eigen::numext::isnan(y))
return ::testing::AssertionSuccess();
if (x == y) return ::testing::AssertionSuccess(); // Handle infinity.
auto tolerance = atol + rtol * Eigen::numext::abs(x);
if (Eigen::numext::abs(x - y) <= tolerance)