Skip to content

Commit

Permalink
EXPECT_NEAR -> ASSERT_NEAR
Browse files Browse the repository at this point in the history
This should speed up failing tests.

PiperOrigin-RevId: 716670004
  • Loading branch information
dsharletg authored and xnnpack-bot committed Jan 17, 2025
1 parent a207ba5 commit b60e73f
Show file tree
Hide file tree
Showing 23 changed files with 86 additions and 86 deletions.
18 changes: 9 additions & 9 deletions test/average-pooling-operator-tester.h
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@ class AveragePoolingOperatorTester {
for (size_t c = 0; c < channels(); c++) {
EXPECT_LE(output[((i * output_height() + y) * output_width() + x) * output_pixel_stride() + c], output_max);
EXPECT_GE(output[((i * output_height() + y) * output_width() + x) * output_pixel_stride() + c], output_min);
EXPECT_NEAR(
ASSERT_NEAR(
output[((i * output_height() + y) * output_width() + x) * output_pixel_stride() + c],
output_ref[((i * output_height() + y) * output_width() + x) * channels() + c],
std::max(1.0e-3f, std::abs(output_ref[((i * output_height() + y) * output_width() + x) * channels() + c]) * 1.0e-2f)) <<
Expand Down Expand Up @@ -722,7 +722,7 @@ class AveragePoolingOperatorTester {
for (size_t c = 0; c < channels(); c++) {
EXPECT_LE(output[((i * output_height() + y) * output_width() + x) * output_pixel_stride() + c], output_max);
EXPECT_GE(output[((i * output_height() + y) * output_width() + x) * output_pixel_stride() + c], output_min);
EXPECT_NEAR(output[((i * output_height() + y) * output_width() + x) * output_pixel_stride() + c],
ASSERT_NEAR(output[((i * output_height() + y) * output_width() + x) * output_pixel_stride() + c],
output_ref[((i * output_height() + y) * output_width() + x) * channels() + c],
std::abs(output_ref[((i * output_height() + y) * output_width() + x) * channels() + c]) * 1.0e-6f) <<
"in batch index " << i << ", pixel (" << y << ", " << x << "), channel " << c;
Expand Down Expand Up @@ -829,7 +829,7 @@ class AveragePoolingOperatorTester {
for (size_t c = 0; c < channels(); c++) {
EXPECT_LE(uint32_t(output[((i * output_height() + y) * output_width() + x) * output_pixel_stride() + c]), uint32_t(qmax()));
EXPECT_GE(uint32_t(output[((i * output_height() + y) * output_width() + x) * output_pixel_stride() + c]), uint32_t(qmin()));
EXPECT_NEAR(float(int32_t(output[((i * output_height() + y) * output_width() + x) * output_pixel_stride() + c])),
ASSERT_NEAR(float(int32_t(output[((i * output_height() + y) * output_width() + x) * output_pixel_stride() + c])),
output_ref[((i * output_height() + y) * output_width() + x) * channels() + c], 0.80f) <<
"in batch index " << i << ", pixel (" << y << ", " << x << "), channel " << c;
}
Expand Down Expand Up @@ -958,7 +958,7 @@ class AveragePoolingOperatorTester {
for (size_t c = 0; c < channels(); c++) {
EXPECT_LE(output[((i * output_height() + y) * output_width() + x) * output_pixel_stride() + c], output_max);
EXPECT_GE(output[((i * output_height() + y) * output_width() + x) * output_pixel_stride() + c], output_min);
EXPECT_NEAR(
ASSERT_NEAR(
output[((i * output_height() + y) * output_width() + x) * output_pixel_stride() + c],
output_ref[((i * output_height() + y) * output_width() + x) * channels() + c],
std::max(1.0e-3f, std::abs(output_ref[((i * output_height() + y) * output_width() + x) * channels() + c]) * 1.0e-2f)) <<
Expand Down Expand Up @@ -1032,7 +1032,7 @@ class AveragePoolingOperatorTester {
for (size_t c = 0; c < next_channels(); c++) {
EXPECT_LE(output[((i * next_output_height() + y) * next_output_width() + x) * next_output_pixel_stride() + c], output_max);
EXPECT_GE(output[((i * next_output_height() + y) * next_output_width() + x) * next_output_pixel_stride() + c], output_min);
EXPECT_NEAR(
ASSERT_NEAR(
output[((i * next_output_height() + y) * next_output_width() + x) * next_output_pixel_stride() + c],
next_output_ref[((i * next_output_height() + y) * next_output_width() + x) * next_channels() + c],
std::max(1.0e-3f, std::abs(next_output_ref[((i * next_output_height() + y) * next_output_width() + x) * next_channels() + c]) * 1.0e-2f)) <<
Expand Down Expand Up @@ -1152,7 +1152,7 @@ class AveragePoolingOperatorTester {
for (size_t c = 0; c < channels(); c++) {
EXPECT_LE(output[((i * output_height() + y) * output_width() + x) * output_pixel_stride() + c], output_max);
EXPECT_GE(output[((i * output_height() + y) * output_width() + x) * output_pixel_stride() + c], output_min);
EXPECT_NEAR(output[((i * output_height() + y) * output_width() + x) * output_pixel_stride() + c],
ASSERT_NEAR(output[((i * output_height() + y) * output_width() + x) * output_pixel_stride() + c],
output_ref[((i * output_height() + y) * output_width() + x) * channels() + c],
std::abs(output_ref[((i * output_height() + y) * output_width() + x) * channels() + c]) * 1.0e-6f) <<
"in batch index " << i << ", pixel (" << y << ", " << x << "), channel " << c;
Expand Down Expand Up @@ -1223,7 +1223,7 @@ class AveragePoolingOperatorTester {
for (size_t c = 0; c < next_channels(); c++) {
EXPECT_LE(output[((i * next_output_height() + y) * next_output_width() + x) * next_output_pixel_stride() + c], output_max);
EXPECT_GE(output[((i * next_output_height() + y) * next_output_width() + x) * next_output_pixel_stride() + c], output_min);
EXPECT_NEAR(output[((i * next_output_height() + y) * next_output_width() + x) * next_output_pixel_stride() + c],
ASSERT_NEAR(output[((i * next_output_height() + y) * next_output_width() + x) * next_output_pixel_stride() + c],
next_output_ref[((i * next_output_height() + y) * next_output_width() + x) * next_channels() + c],
std::abs(next_output_ref[((i * next_output_height() + y) * next_output_width() + x) * next_channels() + c]) * 1.0e-6f) <<
"in batch index " << i << ", pixel (" << y << ", " << x << "), channel " << c;
Expand Down Expand Up @@ -1332,7 +1332,7 @@ class AveragePoolingOperatorTester {
for (size_t c = 0; c < channels(); c++) {
EXPECT_LE(uint32_t(output[((i * output_height() + y) * output_width() + x) * output_pixel_stride() + c]), uint32_t(qmax()));
EXPECT_GE(uint32_t(output[((i * output_height() + y) * output_width() + x) * output_pixel_stride() + c]), uint32_t(qmin()));
EXPECT_NEAR(float(int32_t(output[((i * output_height() + y) * output_width() + x) * output_pixel_stride() + c])),
ASSERT_NEAR(float(int32_t(output[((i * output_height() + y) * output_width() + x) * output_pixel_stride() + c])),
output_ref[((i * output_height() + y) * output_width() + x) * channels() + c], 0.80f) <<
"in batch index " << i << ", pixel (" << y << ", " << x << "), channel " << c;
}
Expand Down Expand Up @@ -1405,7 +1405,7 @@ class AveragePoolingOperatorTester {
for (size_t c = 0; c < next_channels(); c++) {
EXPECT_LE(uint32_t(output[((i * next_output_height() + y) * next_output_width() + x) * next_output_pixel_stride() + c]), uint32_t(qmax()));
EXPECT_GE(uint32_t(output[((i * next_output_height() + y) * next_output_width() + x) * next_output_pixel_stride() + c]), uint32_t(qmin()));
EXPECT_NEAR(float(int32_t(output[((i * next_output_height() + y) * next_output_width() + x) * next_output_pixel_stride() + c])),
ASSERT_NEAR(float(int32_t(output[((i * next_output_height() + y) * next_output_width() + x) * next_output_pixel_stride() + c])),
next_output_ref[((i * next_output_height() + y) * next_output_width() + x) * next_channels() + c], 0.80f) <<
"in batch index " << i << ", pixel (" << y << ", " << x << "), channel " << c;
}
Expand Down
20 changes: 10 additions & 10 deletions test/avgpool-microkernel-tester.h
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ class AvgPoolMicrokernelTester {
<< "at pixel " << x << " / " << output_pixels() << ", channel " << c << " / " << channels()
<< ", pooling elements = " << pooling_elements() << ", step = " << step()
<< ", input offset = " << input_offset();
EXPECT_NEAR(
ASSERT_NEAR(
output[x * output_stride() + c],
output_ref[x * channels() + c],
std::max(1.0e-4f, std::abs(output_ref[x * channels() + c]) * 3.0e-3f))
Expand Down Expand Up @@ -379,7 +379,7 @@ class AvgPoolMicrokernelTester {
<< "at pixel " << x << " / " << output_pixels() << ", channel " << c << " / " << channels()
<< ", pooling elements = " << pooling_elements() << ", step = " << step()
<< ", input offset = " << input_offset();
EXPECT_NEAR(
ASSERT_NEAR(
output[x * output_stride() + c],
output_ref[x * channels() + c],
std::max(1.0e-4f, std::abs(output_ref[x * channels() + c]) * 3.0e-3f))
Expand Down Expand Up @@ -466,7 +466,7 @@ class AvgPoolMicrokernelTester {
<< "at pixel " << x << " / " << output_pixels() << ", channel " << c << " / " << channels()
<< ", pooling elements = " << pooling_elements() << ", step = " << step()
<< ", input offset = " << input_offset();
EXPECT_NEAR(
ASSERT_NEAR(
output[x * output_stride() + c],
output_ref[x * channels() + c],
std::abs(output_ref[x * channels() + c]) * 1.0e-6f)
Expand Down Expand Up @@ -555,7 +555,7 @@ class AvgPoolMicrokernelTester {
<< "at pixel " << x << " / " << output_pixels() << ", channel " << c << " / " << channels()
<< ", pooling elements = " << pooling_elements() << ", step = " << step()
<< ", input offset = " << input_offset();
EXPECT_NEAR(
ASSERT_NEAR(
output[x * output_stride() + c],
output_ref[x * channels() + c],
std::abs(output_ref[x * channels() + c]) * 1.0e-6f)
Expand Down Expand Up @@ -649,7 +649,7 @@ class AvgPoolMicrokernelTester {
<< "at pixel " << x << " / " << output_pixels() << ", channel " << c << " / " << channels()
<< ", pooling elements = " << pooling_elements() << ", step = " << step()
<< ", input offset = " << input_offset();
EXPECT_NEAR(float(int32_t(output[x * output_stride() + c])), output_real[x * channels() + c], 0.5f)
ASSERT_NEAR(float(int32_t(output[x * output_stride() + c])), output_real[x * channels() + c], 0.5f)
<< "at pixel " << x << " / " << output_pixels() << ", channel " << c << " / " << channels()
<< ", pooling elements = " << pooling_elements() << ", step = " << step()
<< ", input offset = " << input_offset() << ", accumulator = " << accumulator[x * channels() + c];
Expand Down Expand Up @@ -746,7 +746,7 @@ class AvgPoolMicrokernelTester {
<< "at pixel " << x << " / " << output_pixels() << ", channel " << c << " / " << channels()
<< ", pooling elements = " << pooling_elements() << ", step = " << step()
<< ", input offset = " << input_offset();
EXPECT_NEAR(float(int32_t(output[x * output_stride() + c])), output_real[x * channels() + c], 0.5f)
ASSERT_NEAR(float(int32_t(output[x * output_stride() + c])), output_real[x * channels() + c], 0.5f)
<< "at pixel " << x << " / " << output_pixels() << ", channel " << c << " / " << channels()
<< ", pooling elements = " << pooling_elements() << ", step = " << step()
<< ", input offset = " << input_offset() << ", accumulator = " << accumulator[x * channels() + c];
Expand Down Expand Up @@ -841,7 +841,7 @@ class AvgPoolMicrokernelTester {
<< "at pixel " << x << " / " << output_pixels() << ", channel " << c << " / " << channels()
<< ", pooling elements = " << pooling_elements() << ", step = " << step()
<< ", input offset = " << input_offset();
EXPECT_NEAR(
ASSERT_NEAR(
output[x * output_stride() + c],
output_ref[x * channels() + c],
std::max(1.0e-4f, std::abs(output_ref[x * channels() + c]) * 3.0e-3f))
Expand Down Expand Up @@ -937,7 +937,7 @@ class AvgPoolMicrokernelTester {
<< "at pixel " << x << " / " << output_pixels() << ", channel " << c << " / " << channels()
<< ", pooling elements = " << pooling_elements() << ", step = " << step()
<< ", input offset = " << input_offset();
EXPECT_NEAR(
ASSERT_NEAR(
output[x * output_stride() + c],
output_ref[x * channels() + c],
std::max(1.0e-4f, std::abs(output_ref[x * channels() + c]) * 3.0e-3f))
Expand Down Expand Up @@ -1027,7 +1027,7 @@ class AvgPoolMicrokernelTester {
<< "at pixel " << x << " / " << output_pixels() << ", channel " << c << " / " << channels()
<< ", pooling elements = " << pooling_elements() << ", step = " << step()
<< ", input offset = " << input_offset();
EXPECT_NEAR(
ASSERT_NEAR(
output[x * output_stride() + c],
output_ref[x * channels() + c],
std::abs(output_ref[x * channels() + c]) * 1.0e-6f)
Expand Down Expand Up @@ -1119,7 +1119,7 @@ class AvgPoolMicrokernelTester {
<< "at pixel " << x << " / " << output_pixels() << ", channel " << c << " / " << channels()
<< ", pooling elements = " << pooling_elements() << ", step = " << step()
<< ", input offset = " << input_offset();
EXPECT_NEAR(
ASSERT_NEAR(
output[x * output_stride() + c],
output_ref[x * channels() + c],
std::abs(output_ref[x * channels() + c]) * 1.0e-6f)
Expand Down
2 changes: 1 addition & 1 deletion test/conv-hwc-microkernel-tester.h
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ class ConvHWCMicrokernelTester {
<< "(x, y) = (" << x << ", " << y << "), channel = " << c;
EXPECT_LE(output[((i * output_height() + y) * output_width() + x) * output_pixel_stride() + c], output_max)
<< "(x, y) = (" << x << ", " << y << "), channel = " << c;
EXPECT_NEAR(
ASSERT_NEAR(
output_ref[((i * output_height() + y) * output_width() + x) * output_channels() + c],
output[((i * output_height() + y) * output_width() + x) * output_pixel_stride() + c],
1.0e-4 * std::abs(output_ref[((i * output_height() + y) * output_width() + x) * output_channels() + c]))
Expand Down
4 changes: 2 additions & 2 deletions test/conv-hwc2chw-microkernel-tester.h
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ class ConvHWC2CHWMicrokernelTester {
<< "(x, y) = (" << x << ", " << y << "), channel = " << c;
EXPECT_LE(output[((i * output_channels() + c) * output_height() + y) * output_width() + x], output_max)
<< "(x, y) = (" << x << ", " << y << "), channel = " << c;
EXPECT_NEAR(
ASSERT_NEAR(
output_ref[((i * output_channels() + c) * output_height() + y) * output_width() + x],
output[((i * output_channels() + c) * output_height() + y) * output_width() + x],
1.0e-4 * std::abs(output_ref[((i * output_channels() + c) * output_height() + y) * output_width() + x]))
Expand Down Expand Up @@ -486,7 +486,7 @@ class ConvHWC2CHWMicrokernelTester {
<< "(x, y) = (" << x << ", " << y << "), channel = " << c;
EXPECT_LE(output[((i * output_channels() + c) * output_height() + y) * output_width() + x], output_max)
<< "(x, y) = (" << x << ", " << y << "), channel = " << c;
EXPECT_NEAR(
ASSERT_NEAR(
output_ref[((i * output_channels() + c) * output_height() + y) * output_width() + x],
output[((i * output_channels() + c) * output_height() + y) * output_width() + x],
std::max(1.0e-4f, 1.0e-2f * std::abs(output_ref[((i * output_channels() + c) * output_height() + y) * output_width() + x])))
Expand Down
4 changes: 2 additions & 2 deletions test/convert-nc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ class ConvertOperatorTester {
static_cast<float>(static_cast<int>(quantized_val) -
quantization_params[i].zero_point) *
quantization_params[i].scale;
EXPECT_NEAR(expected, dequantized_val, max_acceptable_error)
ASSERT_NEAR(expected, dequantized_val, max_acceptable_error)
<< "at batch " << i << " / " << batch_size() << ", channel " << c
<< " / " << channels() << " scale "
<< quantization_params[i].scale << " zp "
Expand Down Expand Up @@ -305,7 +305,7 @@ class ConvertOperatorTester {
static_cast<float>(quantized_val -
quantization_params[i].zero_point) *
quantization_params[i].scale;
EXPECT_NEAR(expected, dequantized_val, max_acceptable_error)
ASSERT_NEAR(expected, dequantized_val, max_acceptable_error)
<< "at batch " << i << " / " << batch_size() << ", channel " << c
<< " / " << channels();
}
Expand Down
Loading

0 comments on commit b60e73f

Please sign in to comment.