19 unsigned int channels,
23 unsigned int channelDimension3D = dataLayout.
GetDataLayout() == DataLayout::NCHW ? 1 : 2;
26 return (batch * shape[dataLayout.
GetHeightIndex()] + height) * shape[channelDimension3D] + channels;
57 if (rank != 3 && rank != 4 )
64 unsigned int channelDimension3D = params.
m_DataLayout == DataLayout::NCHW ? 1 : 2;
69 const unsigned int inputBatchSize = inputShape[0];
70 const unsigned int outputBatchSize = outputShape[0];
72 const unsigned int channels = (rank == 3) ? inputShape[channelDimension3D]
75 const unsigned int inputHeight = inputShape[dataLayout.
GetHeightIndex()];
76 const unsigned int inputWidth = (rank == 3) ? 1 : inputShape[dataLayout.
GetWidthIndex()];
77 const unsigned int outputHeight = outputShape[dataLayout.
GetHeightIndex()];
78 const unsigned int outputWidth = (rank == 3) ? 1 : outputShape[dataLayout.
GetWidthIndex()];
81 const unsigned int blockWidth = (rank == 3) ? 1 : params.
m_BlockShape[1];
83 const unsigned int cropsTop = params.
m_Crops[0].first;
84 const unsigned int cropsLeft = (rank == 3) ? 0 : params.
m_Crops[1].first;
86 for (
unsigned int inBatch = 0; inBatch < inputBatchSize; ++inBatch)
88 const unsigned int outBatch = inBatch % outputBatchSize;
89 const unsigned int spatialOffset = inBatch / outputBatchSize;
91 for (
unsigned int inH = 0; inH < inputHeight; ++inH)
93 const unsigned int outH = inH * blockHeight + spatialOffset / blockWidth - cropsTop;
95 if (outH >= outputHeight)
100 for (
unsigned int inW = 0; inW < inputWidth; ++inW)
102 const unsigned int outW = inW * blockWidth + spatialOffset % blockWidth - cropsLeft;
104 if (outW >= outputWidth)
109 for (
unsigned int c = 0; c < channels; c++)
111 unsigned int outOffset =
Offset(outputShape, outBatch, outH, outW, c, dataLayout);
112 unsigned int inOffset =
Offset(inputShape, inBatch, inH, inW, c, dataLayout);
114 outputData[outOffset];
116 outputData.
Set(inputData.
Get());
virtual IType Get() const =0
virtual void Set(IType right)=0
unsigned int GetNumDimensions() const
const TensorShape & GetShape() const
unsigned int GetNumDimensions() const
Function that returns the tensor rank.
Provides access to the appropriate indexes for Channels, Height and Width based on DataLayout.
unsigned int GetWidthIndex() const
unsigned int GetHeightIndex() const
armnn::DataLayout GetDataLayout() const
unsigned int GetChannelsIndex() const
Copyright (c) 2021 ARM Limited and Contributors.
unsigned int Offset(const TensorShape &shape, unsigned int batch, unsigned int height, unsigned int width, unsigned int channels, const DataLayoutIndexed &dataLayout)
void BatchToSpaceNd(const TensorInfo &inputInfo, const TensorInfo &outputInfo, const BatchToSpaceNdDescriptor ¶ms, Decoder< float > &inputData, Encoder< float > &outputData)
A BatchToSpaceNdDescriptor for the BatchToSpaceNdLayer.
std::vector< unsigned int > m_BlockShape
Block shape values.
std::vector< std::pair< unsigned int, unsigned int > > m_Crops
The values to crop from the input dimension.
DataLayout m_DataLayout
The data layout to be used (NCHW, NHWC).