Skip to content

Commit f250ffc

Browse files
authored
Fix a test failure in mlas (microsoft#24930)
The original code has a divided-by-zero error.
1 parent 24e0b07 commit f250ffc

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

onnxruntime/test/mlas/unittest/test_scaleoutput.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class MlasScaleOutputTest : public MlasTestBase {
2222
std::numeric_limits<int16_t>::max());
2323

2424
for (size_t s = 0; s < M * N; s++) {
25-
Input[s] = int_distribution(generator);
25+
Input[s] = int_distribution(generator); // It could be zero
2626
Output[s] = OutputRef[s] = real_distribution(generator);
2727
}
2828

@@ -52,10 +52,14 @@ class MlasScaleOutputTest : public MlasTestBase {
5252
constexpr float epsilon = 1e-6f;
5353

5454
for (size_t n = 0; n < M * N; n++) {
55-
float diff = std::fabs((Output[n] - OutputRef[n]) / OutputRef[n]);
55+
float outvalue = OutputRef[n]; // When `AccumulateMode` is false, there is a high chance that this value could be zero
56+
float diff = std::fabs(Output[n] - outvalue);
57+
if (outvalue != 0) {
58+
diff /= outvalue;
59+
}
5660
ASSERT_LE(diff, epsilon)
5761
<< " @[" << n / N << "," << n % N << "], total:[" << M << "," << N << "], got:"
58-
<< Output[n] << ", expecting:" << OutputRef[n];
62+
<< Output[n] << ", expecting:" << outvalue;
5963
}
6064
}
6165

0 commit comments

Comments
 (0)