MCPcopy Create free account
hub / github.com/ARM-software/armnn / StridedSlice

Function StridedSlice

src/backends/reference/workloads/StridedSlice.cpp:86–223  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

84} // Anonymous namespace
85
86void StridedSlice(const TensorInfo& inputInfo,
87 const StridedSliceDescriptor& params,
88 const void* inputData,
89 void* outputData,
90 unsigned int dataTypeSize)
91{
92 if (inputData == nullptr)
93 {
94 throw armnn::InvalidArgumentException("Slice: Null inputData pointer");
95 }
96 if (outputData == nullptr)
97 {
98 throw armnn::InvalidArgumentException("Slice: Null outputData pointer");
99 }
100
101 const unsigned char* input = reinterpret_cast<const unsigned char*>(inputData);
102 unsigned char* output = reinterpret_cast<unsigned char*>(outputData);
103
104 const TensorShape inputShape = ExtendShape(inputInfo.GetShape(), 4);
105
106 StridedSliceDescriptor paddedParams = params;
107
108 // Pad parameters to 4 dimensions
109 PadParams(paddedParams, 4);
110
111 // Arrays containing the start and stop index for each axis (adjusted by set params/flags)
112 int startArray [4] = {0};
113 int stopArray [4] = {0};
114
115 // Getting paddedParams stop and start values for each axis
116 for(unsigned int i = 0; i < 4; ++i)
117 {
118 startArray[i] = paddedParams.GetStartForAxis(inputShape, i);
119 stopArray[i] = paddedParams.GetStopForAxis(inputShape, i, startArray[i]);
120 }
121
122 // Adjusting the EllipsisMask based on the NewAxisMask
123 // (if NewAxisMask extends an axis, the ellipsis flag is extended as well)
124 if(paddedParams.m_NewAxisMask > 0 && paddedParams.m_EllipsisMask > 0)
125 {
126 // Iterate until the current EllipsisMask 1-bit found
127 for(unsigned int i = 0; i < 4; ++i)
128 {
129 // If EllipsisMask bit found, adjust based on NewAxisMask and exit loop
130 if(paddedParams.m_EllipsisMask & (1 << i) && !(paddedParams.m_NewAxisMask & (1 << i)))
131 {
132 // If the previous bit is the NewAxisMask, set the EllipsisMask there
133 // (this condition was determined based on the unit tests expected data)
134 if(paddedParams.m_NewAxisMask & (1 << (i-1)))
135 {
136 paddedParams.m_EllipsisMask |= (1 << (i-1));
137 }
138 // Otherwise, extend the EllipsisMask by one bit
139 else
140 {
141 paddedParams.m_EllipsisMask |= (1 << (i+1));
142 }
143 break;

Callers 1

ExecuteMethod · 0.85

Calls 7

ExtendShapeFunction · 0.85
PadParamsFunction · 0.85
LoopConditionFunction · 0.85
GetStartForAxisMethod · 0.80
GetStopForAxisMethod · 0.80
GetShapeMethod · 0.45

Tested by

no test coverage detected