Skip to content

Commit

Permalink
[op conformance] Fix threshold bugs in ov::test::utils::compare
Browse files Browse the repository at this point in the history
  • Loading branch information
sbalandi committed Feb 21, 2024
1 parent fd78fb2 commit 828e681
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 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,17 @@ 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) {
if (std::abs(expected_value) >= 1 || std::abs(actual_value) >= 1) {
rel = abs / 100;
} else if (std::abs(expected_value) < 1 || std::abs(actual_value) < 1) {
rel = 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 828e681

Please sign in to comment.