21 void PadParams(StridedSliceDescriptor& p,
unsigned int dimCount)
25 const unsigned int beginIndicesCount =
26 armnn::numeric_cast<unsigned int>(p.m_Begin.size());
29 const unsigned int padCount = dimCount - beginIndicesCount;
31 p.m_Begin.resize(dimCount);
32 p.m_End.resize(dimCount);
33 p.m_Stride.resize(dimCount);
35 for (
unsigned int i = beginIndicesCount; i > 0; --i)
37 p.m_Stride[i + padCount - 1] = p.m_Stride[i - 1];
38 p.m_Begin[i + padCount - 1] = p.m_Begin[i - 1];
39 p.m_End[i + padCount - 1] = p.m_End[i - 1];
42 for (
unsigned int i = 0; i < padCount; ++i)
49 p.m_ShrinkAxisMask <<= padCount;
50 p.m_EllipsisMask <<= padCount;
51 p.m_NewAxisMask <<= padCount;
52 p.m_BeginMask <<= padCount;
53 p.m_EndMask <<= padCount;
54 p.m_BeginMask |= (1 << padCount) - 1;
55 p.m_EndMask |= (1 << padCount) - 1;
58 bool LoopCondition(
int index,
int stop,
int stride)
60 return stride > 0 ? index >= stop : index <= stop;
63 TensorShape ExtendShape(
const TensorShape& inputShape,
64 unsigned int newNumDimensions)
66 if (inputShape.GetNumDimensions() >= newNumDimensions)
71 std::vector<unsigned int> newSizes(newNumDimensions, 0);
73 unsigned int diff = newNumDimensions - inputShape.GetNumDimensions();
75 for (
unsigned int i = 0; i < diff; i++)
80 for (
unsigned int i = diff; i < newNumDimensions; i++)
82 newSizes[i] = inputShape[i - diff];
85 return TensorShape(newNumDimensions, newSizes.data());
92 const void* inputData,
94 unsigned int dataTypeSize)
96 if (inputData ==
nullptr)
100 if (outputData ==
nullptr)
105 const unsigned char* input =
reinterpret_cast<const unsigned char*
>(inputData);
106 unsigned char* output =
reinterpret_cast<unsigned char*
>(outputData);
113 PadParams(paddedParams, 4);
116 const int stop0 = paddedParams.
GetStopForAxis (inputShape, 0, start0);
119 const int stop1 = paddedParams.
GetStopForAxis (inputShape, 1, start1);
122 const int stop2 = paddedParams.
GetStopForAxis (inputShape, 2, start2);
125 const int stop3 = paddedParams.
GetStopForAxis (inputShape, 3, start3);
127 const int step = armnn::numeric_cast<int>(dataTypeSize);
129 for (
int in0 = start0;
130 !LoopCondition(in0, stop0, paddedParams.
m_Stride[0]);
133 for (
int in1 = start1;
134 !LoopCondition(in1, stop1, paddedParams.
m_Stride[1]);
137 for (
int in2 = start2;
138 !LoopCondition(in2, stop2, paddedParams.
m_Stride[2]);
141 for (
int in3 = start3;
142 !LoopCondition(in3, stop3, paddedParams.
m_Stride[3]);
145 int dim1 = armnn::numeric_cast<int>(inputShape[1]);
146 int dim2 = armnn::numeric_cast<int>(inputShape[2]);
147 int dim3 = armnn::numeric_cast<int>(inputShape[3]);
149 int inputOffset = (((in0 * dim1 + in1) * dim2 + in2) * dim3 + in3) * step;
150 ::memcpy(output, input + inputOffset, dataTypeSize);