12 #include <boost/numeric/conversion/cast.hpp> 22 void PadParams(StridedSliceDescriptor& p,
unsigned int dimCount)
26 const unsigned int beginIndicesCount =
30 const unsigned int padCount = dimCount - beginIndicesCount;
32 p.m_Begin.resize(dimCount);
33 p.m_End.resize(dimCount);
34 p.m_Stride.resize(dimCount);
36 for (
unsigned int i = beginIndicesCount; i > 0; --i)
38 p.m_Stride[i + padCount - 1] = p.m_Stride[i - 1];
39 p.m_Begin[i + padCount - 1] = p.m_Begin[i - 1];
40 p.m_End[i + padCount - 1] = p.m_End[i - 1];
43 for (
unsigned int i = 0; i < padCount; ++i)
50 p.m_ShrinkAxisMask <<= padCount;
51 p.m_EllipsisMask <<= padCount;
52 p.m_NewAxisMask <<= padCount;
53 p.m_BeginMask <<= padCount;
54 p.m_EndMask <<= padCount;
55 p.m_BeginMask |= (1 << padCount) - 1;
56 p.m_EndMask |= (1 << padCount) - 1;
59 bool LoopCondition(
int index,
int stop,
int stride)
61 return stride > 0 ? index >= stop : index <= stop;
64 TensorShape ExtendShape(
const TensorShape& inputShape,
65 unsigned int newNumDimensions)
67 if (inputShape.GetNumDimensions() >= newNumDimensions)
72 std::vector<unsigned int> newSizes(newNumDimensions, 0);
74 unsigned int diff = newNumDimensions - inputShape.GetNumDimensions();
76 for (
unsigned int i = 0; i < diff; i++)
81 for (
unsigned int i = diff; i < newNumDimensions; i++)
83 newSizes[i] = inputShape[i - diff];
86 return TensorShape(newNumDimensions, newSizes.data());
93 const void* inputData,
95 unsigned int dataTypeSize)
97 const unsigned char* input =
reinterpret_cast<const unsigned char*
>(inputData);
98 unsigned char* output =
reinterpret_cast<unsigned char*
>(outputData);
105 PadParams(paddedParams, 4);
107 const int start0 = paddedParams.GetStartForAxis(inputShape, 0);
108 const int stop0 = paddedParams.GetStopForAxis (inputShape, 0, start0);
110 const int start1 = paddedParams.GetStartForAxis(inputShape, 1);
111 const int stop1 = paddedParams.GetStopForAxis (inputShape, 1, start1);
113 const int start2 = paddedParams.GetStartForAxis(inputShape, 2);
114 const int stop2 = paddedParams.GetStopForAxis (inputShape, 2, start2);
116 const int start3 = paddedParams.GetStartForAxis(inputShape, 3);
117 const int stop3 = paddedParams.GetStopForAxis (inputShape, 3, start3);
121 for (
int in0 = start0;
122 !LoopCondition(in0, stop0, paddedParams.m_Stride[0]);
123 in0 += paddedParams.m_Stride[0])
125 for (
int in1 = start1;
126 !LoopCondition(in1, stop1, paddedParams.m_Stride[1]);
127 in1 += paddedParams.m_Stride[1])
129 for (
int in2 = start2;
130 !LoopCondition(in2, stop2, paddedParams.m_Stride[2]);
131 in2 += paddedParams.m_Stride[2])
133 for (
int in3 = start3;
134 !LoopCondition(in3, stop3, paddedParams.m_Stride[3]);
135 in3 += paddedParams.m_Stride[3])
141 int inputOffset = (((in0 * dim1 + in1) * dim2 + in2) * dim3 + in3) * step;
142 ::memcpy(output, input + inputOffset, dataTypeSize);
const TensorShape & GetShape() const
Copyright (c) 2020 ARM Limited.
#define ARMNN_ASSERT_MSG(COND, MSG)
#define ARMNN_ASSERT(COND)
std::enable_if_t< std::is_unsigned< Source >::value &&std::is_unsigned< Dest >::value, Dest > numeric_cast(Source source)
void StridedSlice(const TensorInfo &inputInfo, const StridedSliceDescriptor ¶ms, const void *inputData, void *outputData, unsigned int dataTypeSize)
A StridedSliceDescriptor for the StridedSliceLayer.