MCPcopy Create free account
hub / github.com/ARM-software/ComputeLibrary / equal_values_relative

Function equal_values_relative

tests/validation/CPP/LUT.cpp:51–84  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

49// Check if difference in values is within tolerance range
50template <typename U>
51bool equal_values_relative(const U target, const U reference, const float tolerance)
52{
53 if (are_equal_infs(target, reference))
54 {
55 return true;
56 }
57 else if (target == reference)
58 {
59 return true;
60 }
61 else if (half_float::detail::builtin_isnan(target) &&
62 half_float::detail::builtin_isnan(reference)) // determine if nan values using existing function
63 {
64 return true;
65 }
66
67 const U epsilon = (std::is_same<half, typename std::remove_cv<U>::type>::value || (reference == 0))
68 ? static_cast<U>(0.01)
69 : static_cast<U>(1e-05);
70 if (std::abs(static_cast<double>(reference) - static_cast<double>(target)) <= epsilon)
71 {
72 return true;
73 }
74 else
75 {
76 if (static_cast<double>(reference) == 0.0f)
77 {
78 return false; // We have checked whether _reference and _target is close. If _reference is 0 but not close to _target, it should return false
79 }
80 const double relative_change =
81 std::abs((static_cast<double>(target) - static_cast<double>(reference)) / reference);
82 return relative_change <= static_cast<U>(tolerance);
83 }
84}
85} // namespace
86
87TEST_SUITE(CPP)

Callers 1

TEST_CASEFunction · 0.85

Calls 3

are_equal_infsFunction · 0.85
builtin_isnanFunction · 0.85
absFunction · 0.85

Tested by

no test coverage detected