15 #include <fmt/format.h>
27 fmt::format(
"The number of mappings ({0}) cannot be greater "
28 "than the maximum number of dimensions supported ({1})",
33 if ((dimMappings ==
nullptr) && (numDimMappings != 0))
38 for (
SizeType i = 0; i < numDimMappings; ++i)
40 const ValueType dstIndex = dimMappings[i];
41 if (dstIndex >= numDimMappings)
44 fmt::format(
"Dimension mapping at index {0} is invalid: "
45 "{1} is outside of the valid range [0,{2}]",
48 (numDimMappings - 1)));
54 std::array<bool, MaxNumOfTensorDimensions> observedDims;
55 observedDims.fill(
false);
57 for (
SizeType i = 0; i < numDimMappings; ++i)
59 const ValueType dstIndex = dimMappings[i];
60 if (observedDims[dstIndex])
63 "to the same output dimension");
65 observedDims[dstIndex] =
true;
70 for (
SizeType i = 0; i < numDimMappings; ++i)
72 m_DimMappings[i] = dimMappings[i];
74 m_NumDimMappings = numDimMappings;
86 , m_ViewOrigins(nullptr)
91 , m_NumViews(numViews)
92 , m_NumDimensions(numDimensions)
93 , m_ViewOrigins(numViews && numDimensions > 0 ? new uint32_t *[numViews]() : nullptr)
95 for (uint32_t i = 0; m_NumDimensions > 0 && i < m_NumViews; ++i)
97 m_ViewOrigins[i] =
new uint32_t[m_NumDimensions]();
102 : m_ConcatAxis(other.m_ConcatAxis)
103 , m_NumViews(other.m_NumViews)
104 , m_NumDimensions(other.m_NumDimensions)
105 , m_ViewOrigins(other.m_NumViews && other.m_NumDimensions > 0 ? new uint32_t *[other.m_NumViews]() : nullptr)
107 for (uint32_t i = 0; m_NumDimensions > 0 && i < m_NumViews; ++i)
109 m_ViewOrigins[i] =
new uint32_t[m_NumDimensions]();
110 memcpy(m_ViewOrigins[i], other.m_ViewOrigins[i], m_NumDimensions *
sizeof(uint32_t));
122 for (uint32_t i = 0; m_NumDimensions > 0 && i < m_NumViews; ++i)
124 delete[] m_ViewOrigins[i];
126 delete[] m_ViewOrigins;
160 m_ConcatAxis = concatAxis;
169 if (view >= m_NumViews)
171 ARMNN_LOG(
error) <<
"OriginsDescriptor::SetViewOriginCoord: view argument:" << view <<
175 if (coord >= m_NumDimensions)
177 ARMNN_LOG(
error) <<
"OriginsDescriptor::SetViewOriginCoord: coord argument:" << coord <<
182 m_ViewOrigins[view][coord] = value;
194 return m_NumDimensions;
199 return m_ViewOrigins ? m_ViewOrigins[idx] :
nullptr;
206 ARMNN_ASSERT_MSG(m_NumViews == numNewOrdering,
"number of views must match number of "
207 "elements in the new ordering array");
208 std::vector<uint32_t*> viewOrigins(&m_ViewOrigins[0], &m_ViewOrigins[m_NumViews]);
210 for (
unsigned int i = 0; i < numNewOrdering; ++i)
212 m_ViewOrigins[i] = viewOrigins[newOrdering[i]];
218 , m_ViewSizes(nullptr)
224 : m_Origins(numViews, numDimensions)
225 , m_ViewSizes(numViews > 0 && numDimensions > 0 ?
226 new uint32_t *[numViews]() : nullptr)
240 : m_Origins(other.m_Origins)
241 , m_ViewSizes(other.GetNumViews() > 0 && other.GetNumDimensions() > 0 ?
242 new uint32_t *[other.GetNumViews()]() : nullptr)
243 , m_IsAxisSet(other.m_IsAxisSet)
244 , m_Axis(other.m_Axis)
251 memcpy(m_ViewSizes[i], other.m_ViewSizes[i],
GetNumDimensions() *
sizeof(uint32_t));
268 delete[] m_ViewSizes[i];
270 delete[] m_ViewSizes;
325 ARMNN_LOG(
error) <<
"ViewsDescriptor::SetViewSize: invalid view sizes";
331 ARMNN_LOG(
error) <<
"ViewsDescriptor::SetViewSize: view argument:" << view <<
337 ARMNN_LOG(
error) <<
"ViewsDescriptor::SetViewSize: coord argument:" << coord <<
342 m_ViewSizes[view][coord] = value;
348 return m_ViewSizes ? m_ViewSizes[idx] :
nullptr;
359 swap(first.m_NumViews, second.m_NumViews);
360 swap(first.m_NumDimensions, second.m_NumDimensions);
361 swap(first.m_ViewOrigins, second.m_ViewOrigins);
362 swap(first.m_ConcatAxis, second.m_ConcatAxis);
368 swap(first.m_Origins, second.m_Origins);
369 swap(first.m_ViewSizes, second.m_ViewSizes);
370 swap(first.m_IsAxisSet, second.m_IsAxisSet);
371 swap(first.m_Axis, second.m_Axis);
393 unsigned int axis)
const
401 start = std::numeric_limits<int>::min();
405 start = std::numeric_limits<int>::max();
409 const int axisSize = armnn::numeric_cast<int>(inputShape[axis]);
415 return std::max(0, std::min(start, axisSize - 1));
421 int startForAxis)
const
426 return startForAxis + 1;
429 int stop =
m_End[axis];
435 stop = std::numeric_limits<int>::max();
439 stop = std::numeric_limits<int>::min();
443 const int axisSize = armnn::numeric_cast<int>(inputShape[axis]);
449 return m_Stride[axis] > 0 ? std::max(0, std::min(stop, axisSize)) :
450 std::max(-1, std::min(stop, axisSize - 1));
456 unsigned int numInputs = 2;
489 std::pair<unsigned int, unsigned int> axes = { numDims-2, numDims-1 };
510 std::vector<unsigned int> axesNotMul;
513 if(i == axesToMul.first || i == axesToMul.second)
517 axesNotMul.push_back(i);
526 std::vector<unsigned int> vec;
530 if(i == axesToMul.first)
534 else if(i == axesToMul.second)
544 static_cast<unsigned int>(vec.size()));