From cb86956e1972be4b2ddbaacaa23a0d21185f8ccb Mon Sep 17 00:00:00 2001 From: SiCongLi Date: Wed, 22 Dec 2021 15:37:20 +0000 Subject: Fix test validation method * Allow non-finite values to be equal (inf == inf, -inf == -inf) in validate * Fix SpecialPoolingLayerValidationFixture Partially resolves COMPMID-4998 Change-Id: I3fba1ccee74c1af419a3b6088ddac68c79aa243a Signed-off-by: SiCongLi Reviewed-on: https://review.mlplatform.org/c/ml/ComputeLibrary/+/6856 Reviewed-by: Gunes Bayir Comments-Addressed: Arm Jenkins Tested-by: Arm Jenkins --- tests/validation/Validation.h | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) (limited to 'tests/validation/Validation.h') diff --git a/tests/validation/Validation.h b/tests/validation/Validation.h index 638a1c20ee..4f3f92da24 100644 --- a/tests/validation/Validation.h +++ b/tests/validation/Validation.h @@ -45,6 +45,17 @@ namespace test { namespace validation { +namespace +{ +// Compare if 2 values are both infinities and if they are "equal" (has the same sign) +template +bool are_equal_infs(T val0, T val1) +{ + const auto same_sign = std::signbit(val0) == std::signbit(val1); + return (!support::cpp11::isfinite(val0)) && (!support::cpp11::isfinite(val1)) && same_sign; +} +} // namespace + /** Class reprensenting an absolute tolerance value. */ template class AbsoluteTolerance @@ -296,9 +307,9 @@ struct compare> : public compare_base> /** Perform comparison */ operator bool() const { - if(!support::cpp11::isfinite(this->_target) || !support::cpp11::isfinite(this->_reference)) + if(are_equal_infs(this->_target, this->_reference)) { - return false; + return true; } else if(this->_target == this->_reference) { @@ -322,9 +333,9 @@ struct compare> : public compare_base> /** Perform comparison */ operator bool() const { - if(!support::cpp11::isfinite(this->_target) || !support::cpp11::isfinite(this->_reference)) + if(are_equal_infs(this->_target, this->_reference)) { - return false; + return true; } else if(this->_target == this->_reference) { @@ -494,9 +505,9 @@ void validate_wrap(const IAccessor &tensor, const SimpleTensor &reference, co // check for wrapping if(!equal) { - if(!support::cpp11::isfinite(target_value) || !support::cpp11::isfinite(reference_value)) + if(are_equal_infs(target_value, reference_value)) { - equal = false; + equal = true; } else { -- cgit v1.2.1