Skip to content

Commit

Permalink
[op conformance] Fix threshold bugs in ov::test::utils::compare (#22972)
Browse files Browse the repository at this point in the history
### Details:
- *fixed problem, when all actual values are 0 -> rel_error 0, abs_error
more then 0 -> but test is PASS*
- *fixed problem, when one threshold is set by user, another threshold
is set to default values std::numeric_limits<double>::max and some
problem appears in test -> but test is PASS, because one of thresholds
is very big*

### Tickets:
 - *CVS-133173*
  • Loading branch information
sbalandi authored Feb 23, 2024
1 parent 632174b commit 1e5d0e5
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/tests/test_utils/common_test_utils/src/ov_tensor_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -362,8 +362,8 @@ inline double calculate_median(std::vector<double>& abs_values) {
template <typename ExpectedT, typename ActualT>
void compare(const ov::Tensor& expected,
const ov::Tensor& actual,
const double abs_threshold_ = std::numeric_limits<double>::max(),
const double rel_threshold_ = std::numeric_limits<double>::max()) {
const double abs_threshold_ = 0,
const double rel_threshold_ = 0) {
auto expected_shape = expected.get_shape();
auto actual_shape = actual.get_shape();
if (expected_shape != actual_shape) {
Expand All @@ -380,7 +380,7 @@ void compare(const ov::Tensor& expected,
double abs_threshold = abs_threshold_;
double rel_threshold = rel_threshold_;
size_t shape_size_cnt = shape_size(expected_shape);
if (abs_threshold == std::numeric_limits<double>::max() && rel_threshold == std::numeric_limits<double>::max()) {
if (abs_threshold == 0 && rel_threshold == 0) {
if (sizeof(ExpectedT) == 1 || sizeof(ActualT) == 1) {
abs_threshold = 1.;
rel_threshold = 1.;
Expand Down Expand Up @@ -451,8 +451,13 @@ void compare(const ov::Tensor& expected,
}

double abs = std::fabs(expected_value - actual_value);
double rel =
expected_value && actual_value && !std::isinf(expected_value) ? (abs / std::fabs(expected_value)) : 0;
double rel = 0;
if (expected_value == 0 || actual_value == 0) {
rel = (std::abs(expected_value) >= 1 || std::abs(actual_value) >= 1) ? (abs * 1e-2) : abs;
} else if (!std::isinf(expected_value)) {
rel = (abs / std::fabs(expected_value));
}

abs_error.update(abs, i);
rel_error.update(rel, i);
}
Expand Down

0 comments on commit 1e5d0e5

Please sign in to comment.