Merge pull request #22511 from alalek:dnn_build_warning_gcc12

dnn: eliminate GCC12 warning in total() call
This commit is contained in:
Alexander Smorkalov 2022-09-19 16:22:54 +03:00 committed by GitHub
commit 0ab4872032
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 35 additions and 8 deletions

View File

@ -160,22 +160,49 @@ static inline MatShape shape(int a0, int a1=-1, int a2=-1, int a3=-1)
static inline int total(const MatShape& shape, int start = -1, int end = -1)
{
if (start == -1) start = 0;
if (end == -1) end = (int)shape.size();
if (shape.empty())
return 0;
int dims = (int)shape.size();
if (start == -1) start = 0;
if (end == -1) end = dims;
CV_CheckLE(0, start, "");
CV_CheckLE(start, end, "");
CV_CheckLE(end, dims, "");
int elems = 1;
CV_Assert(start <= (int)shape.size() && end <= (int)shape.size() &&
start <= end);
for(int i = start; i < end; i++)
for (int i = start; i < end; i++)
{
elems *= shape[i];
}
return elems;
}
// TODO: rename to countDimsElements()
static inline int total(const Mat& mat, int start = -1, int end = -1)
{
if (mat.empty())
return 0;
int dims = mat.dims;
if (start == -1) start = 0;
if (end == -1) end = dims;
CV_CheckLE(0, start, "");
CV_CheckLE(start, end, "");
CV_CheckLE(end, dims, "");
int elems = 1;
for (int i = start; i < end; i++)
{
elems *= mat.size[i];
}
return elems;
}
static inline MatShape concat(const MatShape& a, const MatShape& b)
{
MatShape c = a;

View File

@ -208,8 +208,8 @@ public:
const float* inpData = inp0.ptr<float>();
float* outData = outputs[0].ptr<float>();
size_t num = total(shape(inp0.size), 0, startAxis);
size_t numPlanes = total(shape(inp0.size), startAxis, endAxis + 1);
size_t num = total(inp0, 0, startAxis);
size_t numPlanes = total(inp0, startAxis, endAxis + 1);
CV_Assert(num * numPlanes != 0);
size_t planeSize = inp0.total() / (num * numPlanes);
for (size_t n = 0; n < num; ++n)