diff options
author | steniu01 <steven.niu@arm.com> | 2017-06-15 10:49:37 +0100 |
---|---|---|
committer | Anthony Barbier <anthony.barbier@arm.com> | 2018-09-17 13:03:43 +0100 |
commit | 9746fd824efe1d1d9933c59376e81dcf9c7a0eca (patch) | |
tree | 9279caa933af9fc834e85cc85dfd049cdcbd96ce /tests/validation | |
parent | f795986c8d4594279c277b14a33d29e48b2a4def (diff) | |
download | ComputeLibrary-9746fd824efe1d1d9933c59376e81dcf9c7a0eca.tar.gz |
COMPMID-250 handle validation results comparision correctly
Change-Id: I96b73fb002b74ca397e7beb00dd734d78a5f0fd3
Reviewed-on: http://mpd-gerrit.cambridge.arm.com/77890
Tested-by: Kaizen <jeremy.johnson+kaizengerrit@arm.com>
Reviewed-by: Moritz Pflanzer <moritz.pflanzer@arm.com>
Reviewed-by: Anthony Barbier <anthony.barbier@arm.com>
Diffstat (limited to 'tests/validation')
-rw-r--r-- | tests/validation/UNIT/FixedPoint.cpp | 12 | ||||
-rw-r--r-- | tests/validation/Validation.cpp | 76 |
2 files changed, 63 insertions, 25 deletions
diff --git a/tests/validation/UNIT/FixedPoint.cpp b/tests/validation/UNIT/FixedPoint.cpp index 63d4150318..8042bb6da8 100644 --- a/tests/validation/UNIT/FixedPoint.cpp +++ b/tests/validation/UNIT/FixedPoint.cpp @@ -139,14 +139,14 @@ BOOST_DATA_TEST_CASE(FixedPointQS8Outputs, (boost::unit_test::data::make(func_na out_val = fixed_point_arithmetic::inv_sqrt(in_val); } - BOOST_TEST_INFO("input = " << in_val); - BOOST_TEST_INFO("output = " << out_val); - BOOST_TEST_INFO("reference = " << ref_val); - BOOST_TEST_INFO("tolerance = " << tolerance); - BOOST_TEST_WARN((std::abs(static_cast<float>(out_val) - ref_val) <= tolerance)); - if(std::abs(static_cast<float>(out_val) - ref_val) > tolerance) { + BOOST_TEST_INFO("input = " << in_val); + BOOST_TEST_INFO("output = " << out_val); + BOOST_TEST_INFO("reference = " << ref_val); + BOOST_TEST_INFO("tolerance = " << tolerance); + BOOST_TEST_WARN((std::abs(static_cast<float>(out_val) - ref_val) <= tolerance)); + ++num_mismatches; } diff --git a/tests/validation/Validation.cpp b/tests/validation/Validation.cpp index 335d2644d3..c1c43c05c4 100644 --- a/tests/validation/Validation.cpp +++ b/tests/validation/Validation.cpp @@ -57,6 +57,11 @@ namespace */ double get_double_data(const void *ptr, DataType data_type) { + if(ptr == nullptr) + { + ARM_COMPUTE_ERROR("Can't dereference a null pointer!"); + } + switch(data_type) { case DataType::U8: @@ -92,6 +97,39 @@ double get_double_data(const void *ptr, DataType data_type) } } +bool is_equal(double target, double ref, double max_absolute_error = std::numeric_limits<double>::epsilon(), double max_relative_error = 0.0001f) +{ + if(!std::isfinite(target) || !std::isfinite(ref)) + { + return false; + } + + // No need further check if they are equal + if(ref == target) + { + return true; + } + + // Need this check for the situation when the two values close to zero but have different sign + if(std::abs(std::abs(ref) - std::abs(target)) <= max_absolute_error) + { + return true; + } + + double relative_error = 0; + + if(std::abs(target) > std::abs(ref)) + { + relative_error = std::abs((target - ref) / target); + } + else + { + relative_error = std::abs((ref - target) / ref); + } + + return relative_error <= max_relative_error; +} + void check_border_element(const IAccessor &tensor, const Coordinates &id, const BorderMode &border_mode, const void *border_value, int64_t &num_elements, int64_t &num_mismatches) @@ -112,15 +150,15 @@ void check_border_element(const IAccessor &tensor, const Coordinates &id, const size_t channel_offset = channel * channel_size; const double target = get_double_data(ptr + channel_offset, tensor.data_type()); const double ref = get_double_data(static_cast<const uint8_t *>(border_value) + channel_offset, tensor.data_type()); - const double difference = target - ref; + const bool equal = is_equal(target, ref); BOOST_TEST_INFO("id = " << id); BOOST_TEST_INFO("channel = " << channel); BOOST_TEST_INFO("reference = " << std::setprecision(5) << ref); BOOST_TEST_INFO("target = " << std::setprecision(5) << target); - BOOST_TEST_WARN(difference == 0); + BOOST_TEST_WARN(equal); - if(difference != 0.f) + if(!equal) { ++num_mismatches; } @@ -141,22 +179,22 @@ void check_single_element(const Coordinates &id, const IAccessor &tensor, const const size_t channel_offset = channel * channel_size; const double target = get_double_data(ptr + channel_offset, reference.data_type()); const double ref = get_double_data(ref_ptr + channel_offset, reference.data_type()); - const double difference = target - ref; + bool equal = is_equal(target, ref, tolerance_value); - BOOST_TEST_INFO("id = " << id); - BOOST_TEST_INFO("channel = " << channel); - BOOST_TEST_INFO("reference = " << std::setprecision(5) << ref); - BOOST_TEST_INFO("target = " << std::setprecision(5) << target); - BOOST_TEST_WARN(difference == 0); + if(wrap_range != 0 && !equal) + { + equal = is_equal(target, ref, wrap_range - tolerance_value); + } - if(std::abs(difference) > tolerance_value) + if(!equal) { - // If no special cases for tolerating wrappping cases - // or the special case of wrapping exceeds tolerance_value - if(wrap_range == 0 || (wrap_range - std::abs(difference)) > tolerance_value) - { - ++num_mismatches; - } + BOOST_TEST_INFO("id = " << id); + BOOST_TEST_INFO("channel = " << channel); + BOOST_TEST_INFO("reference = " << std::setprecision(5) << ref); + BOOST_TEST_INFO("target = " << std::setprecision(5) << target); + BOOST_TEST_WARN(equal); + + ++num_mismatches; } ++num_elements; } @@ -247,15 +285,15 @@ void validate(const IAccessor &tensor, const void *reference_value) const size_t channel_offset = channel * channel_size; const double target = get_double_data(ptr + channel_offset, tensor.data_type()); const double ref = get_double_data(reference_value, tensor.data_type()); - const double difference = target - ref; + const bool equal = is_equal(target, ref); BOOST_TEST_INFO("id = " << id); BOOST_TEST_INFO("channel = " << channel); BOOST_TEST_INFO("reference = " << std::setprecision(5) << ref); BOOST_TEST_INFO("target = " << std::setprecision(5) << target); - BOOST_TEST_WARN(difference == 0); + BOOST_TEST_WARN(equal); - if(difference != 0.f) + if(!equal) { ++num_mismatches; } |