17 inline std::vector<unsigned int> IndexToCoord(
const armnn::TensorShape& shape,
unsigned int index)
27 numOfElements /= shape[i];
28 coord[i] = index / numOfElements;
29 index %= numOfElements;
37 inline unsigned int CoordToIndex(
const armnn::TensorShape& shape,
const std::vector<unsigned int>& coord)
42 unsigned int index = 0;
43 unsigned int dimSize = 1;
47 index += coord[i - 1] * dimSize;
48 dimSize *= shape[i - 1];
78 for(
unsigned int i = 0; i < padList.size(); ++i)
80 if(padList.at(i).first > (inputShape[i] - isReflect) ||
81 padList.at(i).second > (inputShape[i] - isReflect))
84 "equal (Symmetric) to the dimension size.");
88 auto inputData = MakeDecoder<float>(inputInfo, inputHandle->
Map());
89 auto outData = MakeEncoder<float>(outputInfo, outputHandle->
Map());
94 for(
unsigned int idx = 0; idx < numOutputElements; ++idx)
97 const std::vector<unsigned int> coord = IndexToCoord(outputShape, idx);
99 std::vector<unsigned int> dimensions;
100 std::vector<unsigned int> coords;
102 for(
unsigned int i = 0; i < numInputDimensions; ++i)
104 dimensions.emplace_back(i);
105 coords.emplace_back(coord[i]);
108 auto isInPadding = [&](
unsigned int i)
110 return (coords[i] < padList[i].first || coords[i] > inputShape[i] + padList[i].first - 1);
113 auto getReflectIndex = [&](
unsigned int i) ->
unsigned int
117 if(coords[i] < padList[i].first)
119 return padList[i].first - coords[i];
123 return 2 * inputShape[i] + padList[i].first - 2 - coords[i];
126 return coords[i] - padList[i].first;
129 auto getSymmetricIndex = [&](
unsigned int i) ->
unsigned int
133 if(coords[i] < padList[i].first)
135 return padList[i].first - coords[i] - 1;
139 return 2 * inputShape[i] + padList[i].first - 1 - coords[i];
142 return coords[i] - padList[i].first;
146 std::vector<unsigned int> coordOfInput;
155 if(std::any_of(dimensions.begin(), dimensions.end(), isInPadding))
161 for(
unsigned int i = 0; i < numInputDimensions; ++i)
163 coordOfInput.emplace_back(getReflectIndex(i));
169 for(
unsigned int i = 0; i < numInputDimensions; ++i)
171 coordOfInput.emplace_back(getSymmetricIndex(i));
182 for(
unsigned int i = 0; i < numInputDimensions; ++i)
184 coordOfInput.emplace_back(coord[i] - padList[i].first);
189 const unsigned int indexOfInput = CoordToIndex(inputShape, coordOfInput);
192 auto inputValue = input.
Get();
195 output.
Set(inputValue);
#define ARMNN_THROW_INVALIDARG_MSG_IF_FALSE(_cond, _str)
virtual IType Get() const =0
virtual void Set(IType right)=0
virtual const void * Map(bool blocking=true) const =0
Map the tensor data for access.
unsigned int GetNumElements() const
const TensorShape & GetShape() const
unsigned int GetNumDimensions() const
Function that returns the tensor rank.
unsigned int GetNumElements() const
Function that calculates the tensor elements by multiplying all dimension size which are Specified.
Copyright (c) 2021 ARM Limited and Contributors.
PaddingMode
The padding mode controls whether the padding should be filled with constant values (Constant),...
void MirrorPad(const TensorInfo &inputInfo, const TensorInfo &outputInfo, const ITensorHandle *inputHandle, ITensorHandle *outputHandle, const PadQueueDescriptor &data)
PaddingMode m_PaddingMode
Specifies the Padding mode (Constant, Reflect or Symmetric)
std::vector< std::pair< unsigned int, unsigned int > > m_PadList
Specifies the padding for input dimension.
LayerDescriptor m_Parameters