18 void PadParams(StridedSliceDescriptor& p,
unsigned int dimCount)
22 const unsigned int beginIndicesCount =
23 armnn::numeric_cast<unsigned int>(p.m_Begin.size());
25 const unsigned int padCount = dimCount - beginIndicesCount;
27 p.m_Begin.resize(dimCount);
28 p.m_End.resize(dimCount);
29 p.m_Stride.resize(dimCount);
31 for (
unsigned int i = beginIndicesCount; i > 0; --i)
33 p.m_Stride[i + padCount - 1] = p.m_Stride[i - 1];
34 p.m_Begin[i + padCount - 1] = p.m_Begin[i - 1];
35 p.m_End[i + padCount - 1] = p.m_End[i - 1];
38 for (
unsigned int i = 0; i < padCount; ++i)
45 p.m_ShrinkAxisMask <<= padCount;
46 p.m_EllipsisMask <<= padCount;
47 p.m_NewAxisMask <<= padCount;
48 p.m_BeginMask <<= padCount;
49 p.m_EndMask <<= padCount;
50 p.m_BeginMask |= (1 << padCount) - 1;
51 p.m_EndMask |= (1 << padCount) - 1;
54 bool LoopCondition(
int index,
int stop,
int stride)
56 return stride > 0 ? index >= stop : index <= stop;
59 TensorShape ExtendShape(
const TensorShape& inputShape,
60 unsigned int newNumDimensions)
62 if (inputShape.GetNumDimensions() >= newNumDimensions)
67 std::vector<unsigned int> newSizes(newNumDimensions, 0);
69 unsigned int diff = newNumDimensions - inputShape.GetNumDimensions();
71 for (
unsigned int i = 0; i < diff; i++)
76 for (
unsigned int i = diff; i < newNumDimensions; i++)
78 newSizes[i] = inputShape[i - diff];
81 return TensorShape(newNumDimensions, newSizes.data());
88 const void* inputData,
90 unsigned int dataTypeSize)
92 if (inputData ==
nullptr)
96 if (outputData ==
nullptr)
101 const unsigned char* input =
reinterpret_cast<const unsigned char*
>(inputData);
102 unsigned char* output =
reinterpret_cast<unsigned char*
>(outputData);
109 PadParams(paddedParams, 4);
112 const int stop0 = paddedParams.
GetStopForAxis (inputShape, 0, start0);
115 const int stop1 = paddedParams.
GetStopForAxis (inputShape, 1, start1);
118 const int stop2 = paddedParams.
GetStopForAxis (inputShape, 2, start2);
121 const int stop3 = paddedParams.
GetStopForAxis (inputShape, 3, start3);
123 const int step = armnn::numeric_cast<int>(dataTypeSize);
125 for (
int in0 = start0;
126 !LoopCondition(in0, stop0, paddedParams.
m_Stride[0]);
129 for (
int in1 = start1;
130 !LoopCondition(in1, stop1, paddedParams.
m_Stride[1]);
133 for (
int in2 = start2;
134 !LoopCondition(in2, stop2, paddedParams.
m_Stride[2]);
137 for (
int in3 = start3;
138 !LoopCondition(in3, stop3, paddedParams.
m_Stride[3]);
141 int dim1 = armnn::numeric_cast<int>(inputShape[1]);
142 int dim2 = armnn::numeric_cast<int>(inputShape[2]);
143 int dim3 = armnn::numeric_cast<int>(inputShape[3]);
145 int inputOffset = (((in0 * dim1 + in1) * dim2 + in2) * dim3 + in3) * step;
146 ::memcpy(output, input + inputOffset, dataTypeSize);