dnn: return all false in IsInf when both detect flags are 0 (#31171)

Problem
IsInf threw "Unsupported mode" when detect_positive and detect_negative were both 0. ONNX expects an all-false output in that case.

Fix
Fill the output with zeros in that branch instead of calling CV_Error.
This commit is contained in:
Abhishek Gola
2026-11-27 13:22:49 +05:30
committed by GitHub
2 changed files with 21 additions and 1 deletions

View File

@@ -56,7 +56,7 @@ static inline void computeIsInfMask(const T* src, uchar* dst, const size_t count
}
else
{
CV_Error_(Error::StsError, ("IsInf: Unsupported mode"));
std::fill(dst, dst + count, (uchar)0);
}
}

View File

@@ -6224,4 +6224,24 @@ INSTANTIATE_TEST_CASE_P(/**/, Layer_Test_Reduce_Unsigned, Values(
CV_64U
));
TEST(Layer_Test_IsInf, NoDetection)
{
LayerParams lp;
lp.type = "IsInf";
lp.name = "testIsInf";
lp.set("detect_positive", 0);
lp.set("detect_negative", 0);
Ptr<Layer> layer = LayerFactory::createLayerInstance("IsInf", lp);
const float inf = std::numeric_limits<float>::infinity();
float data[] = {1.f, inf, -inf, 0.f};
Mat input(1, 4, CV_32F, data);
std::vector<Mat> inputs = {input}, outputs;
runLayer(layer, inputs, outputs);
ASSERT_EQ(outputs.size(), (size_t)1);
for (int i = 0; i < 4; i++)
EXPECT_EQ(outputs[0].ptr<uchar>()[i], 0) << "index " << i;
}
}} // namespace