12 #include <boost/format.hpp> 13 #include <boost/numeric/conversion/cast.hpp> 24 boost::format fmt(
"The number of mappings (%1%) cannot be greater " 25 "than the maximum number of dimensions supported (%2%)");
29 if ((dimMappings ==
nullptr) && (numDimMappings != 0))
34 for (
SizeType i = 0; i < numDimMappings; ++i)
36 const ValueType dstIndex = dimMappings[i];
37 if (dstIndex >= numDimMappings)
39 boost::format fmt(
"Dimension mapping at index %1% is invalid: %2% is outside of the valid range [0,%3%]");
46 std::array<bool, MaxNumOfTensorDimensions> observedDims;
47 observedDims.fill(
false);
49 for (
SizeType i = 0; i < numDimMappings; ++i)
51 const ValueType dstIndex = dimMappings[i];
52 if (observedDims[dstIndex])
55 "to the same output dimension");
57 observedDims[dstIndex] =
true;
62 for (
SizeType i = 0; i < numDimMappings; ++i)
64 m_DimMappings[i] = dimMappings[i];
66 m_NumDimMappings = numDimMappings;
78 , m_ViewOrigins(nullptr)
83 , m_NumViews(numViews)
84 , m_NumDimensions(numDimensions)
85 , m_ViewOrigins(numViews && numDimensions > 0 ? new uint32_t *[numViews]() : nullptr)
87 for (uint32_t i = 0; m_NumDimensions > 0 && i < m_NumViews; ++i)
89 m_ViewOrigins[i] =
new uint32_t[m_NumDimensions]();
94 : m_ConcatAxis(other.m_ConcatAxis)
95 , m_NumViews(other.m_NumViews)
96 , m_NumDimensions(other.m_NumDimensions)
97 , m_ViewOrigins(other.m_NumViews && other.m_NumDimensions > 0 ? new uint32_t *[other.m_NumViews]() : nullptr)
99 for (uint32_t i = 0; m_NumDimensions > 0 && i < m_NumViews; ++i)
101 m_ViewOrigins[i] =
new uint32_t[m_NumDimensions]();
102 memcpy(m_ViewOrigins[i], other.m_ViewOrigins[i], m_NumDimensions *
sizeof(uint32_t));
114 for (uint32_t i = 0; m_NumDimensions > 0 && i < m_NumViews; ++i)
116 delete[] m_ViewOrigins[i];
118 delete[] m_ViewOrigins;
152 m_ConcatAxis = concatAxis;
161 if (view >= m_NumViews)
163 ARMNN_LOG(
error) <<
"OriginsDescriptor::SetViewOriginCoord: view argument:" << view <<
167 if (coord >= m_NumDimensions)
169 ARMNN_LOG(
error) <<
"OriginsDescriptor::SetViewOriginCoord: coord argument:" << coord <<
174 m_ViewOrigins[view][coord] = value;
186 return m_NumDimensions;
191 return m_ViewOrigins ? m_ViewOrigins[idx] :
nullptr;
198 BOOST_ASSERT_MSG(m_NumViews == numNewOrdering,
"number of views must match number of " 199 "elements in the new ordering array");
200 std::vector<uint32_t*> viewOrigins(&m_ViewOrigins[0], &m_ViewOrigins[m_NumViews]);
202 for (
unsigned int i = 0; i < numNewOrdering; ++i)
204 m_ViewOrigins[i] = viewOrigins[newOrdering[i]];
210 , m_ViewSizes(nullptr)
214 : m_Origins(numViews, numDimensions)
215 , m_ViewSizes(numViews > 0 && numDimensions > 0 ?
216 new uint32_t *[numViews]() : nullptr)
228 : m_Origins(other.m_Origins)
237 memcpy(m_ViewSizes[i], other.m_ViewSizes[i],
GetNumDimensions() *
sizeof(uint32_t));
254 delete[] m_ViewSizes[i];
256 delete[] m_ViewSizes;
311 ARMNN_LOG(
error) <<
"ViewsDescriptor::SetViewSize: invalid view sizes";
317 ARMNN_LOG(
error) <<
"ViewsDescriptor::SetViewSize: view argument:" << view <<
323 ARMNN_LOG(
error) <<
"ViewsDescriptor::SetViewSize: coord argument:" << coord <<
328 m_ViewSizes[view][coord] = value;
334 return m_ViewSizes ? m_ViewSizes[idx] :
nullptr;
345 swap(first.m_NumViews, second.m_NumViews);
346 swap(first.m_NumDimensions, second.m_NumDimensions);
347 swap(first.m_ViewOrigins, second.m_ViewOrigins);
348 swap(first.m_ConcatAxis, second.m_ConcatAxis);
354 swap(first.m_Origins, second.m_Origins);
355 swap(first.m_ViewSizes, second.m_ViewSizes);
359 unsigned int axis)
const 361 int start = m_Begin[axis];
363 if (m_BeginMask & (1 << axis))
365 if (m_Stride[axis] > 0)
367 start = std::numeric_limits<int>::min();
371 start = std::numeric_limits<int>::max();
375 const int axisSize = boost::numeric_cast<
int>(inputShape[axis]);
381 return std::max(0, std::min(start, axisSize - 1));
387 int startForAxis)
const 390 if (m_ShrinkAxisMask & (1 << axis))
392 return startForAxis + 1;
395 int stop = m_End[axis];
397 if (m_EndMask & (1 << axis))
399 if (m_Stride[axis] > 0)
401 stop = std::numeric_limits<int>::max();
405 stop = std::numeric_limits<int>::min();
409 const int axisSize = boost::numeric_cast<
int>(inputShape[axis]);
415 return m_Stride[axis] > 0 ? std::max(0, std::min(stop, axisSize)) :
416 std::max(-1, std::min(stop, axisSize - 1));
void SetConcatAxis(unsigned int concatAxis)
Set the concatenation axis value.
friend void swap(OriginsDescriptor &first, OriginsDescriptor &second)
Swap the ViewsDescriptor values first and second.
const OriginsDescriptor & GetOrigins() const
Get the View Origins.
int GetStopForAxis(const TensorShape &inputShape, unsigned int axis, int startForAxis) const
PermutationVector(const ValueType *dimMappings, SizeType numDimMappings)
ViewsDescriptor & operator=(ViewsDescriptor rhs)
ConstIterator begin() const
Status SetViewSize(uint32_t view, uint32_t coord, uint32_t value)
Set the size of the views. The arguments are: view, dimension, value. If the view is greater than or ...
Status SetViewOriginCoord(uint32_t view, uint32_t coord, uint32_t value)
Status SetViewOriginCoord(uint32_t view, uint32_t coord, uint32_t value)
bool operator==(const OriginsDescriptor &rhs) const
A ViewsDescriptor for the SplitterLayer. Descriptor to configure the splitting process. Number of Views must be equal to the number of outputs, and their order must match - e.g. first view corresponds to the first output, second view to the second output, etc.
#define ARMNN_LOG(severity)
uint32_t GetNumDimensions() const
Get the number of dimensions.
const uint32_t * GetViewOrigin(uint32_t idx) const
Return the view origin at the int value idx.
uint32_t GetNumViews() const
Get the number of views.
void swap(ViewsDescriptor &first, ViewsDescriptor &second)
uint32_t GetNumDimensions() const
Get the number of dimensions.
unsigned int GetConcatAxis() const
Get the concatenation axis value.
bool operator==(const ViewsDescriptor &rhs) const
const uint32_t * GetViewSizes(uint32_t idx) const
Get the view sizes at the int value idx.
void ReorderOrigins(unsigned int *newOrdering, unsigned int numNewOrdering)
Reorders the viewOrigins in accordance with the indices presented in newOrdering array. The number of views must match number of elements in the new ordering array.
constexpr unsigned int MaxNumOfTensorDimensions
const uint32_t * GetViewOrigin(uint32_t idx) const
Get the view origin at the int value idx.
int GetStartForAxis(const TensorShape &inputShape, unsigned int axis) const
uint32_t GetNumViews() const
Get the number of views.
An OriginsDescriptor for the ConcatLayer. Descriptor to configure the concatenation process...
friend void swap(ViewsDescriptor &first, ViewsDescriptor &second)
Swap the ViewsDescriptor value first and second.
OriginsDescriptor & operator=(OriginsDescriptor rhs)