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;
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)