12 #include <boost/assert.hpp> 19 inline unsigned int Offset(
const TensorShape& shape,
unsigned int batch,
unsigned int height,
unsigned int width,
38 const std::vector<unsigned int>& blockShape,
39 const std::vector<std::pair<unsigned int, unsigned int>>& cropsData,
45 BOOST_ASSERT_MSG(inputShape.
GetNumDimensions() == 4,
"Expected Input with 4 Dimensions");
49 BOOST_ASSERT_MSG(outputShape.GetNumDimensions() == 4,
"Expected Output with 4 Dimensions");
51 const unsigned int inputBatchSize = inputShape[0];
54 const unsigned int outputBatchSize = outputShape[0];
55 const unsigned int outputHeight = outputShape[dataLayout.
GetHeightIndex()];
56 const unsigned int outputWidth = outputShape[dataLayout.
GetWidthIndex()];
58 BOOST_ASSERT_MSG(blockShape.size() > 0,
"BlockShape must contain 1 or more entries");
60 const unsigned int blockShapeHeight = blockShape[0];
61 const unsigned int blockShapeWidth = blockShape[1];
63 BOOST_ASSERT_MSG(cropsData.size() > 0,
"Crops must contain 1 or more entries");
65 const unsigned int cropsTop = cropsData[0].first;
66 const unsigned int cropsLeft = cropsData[1].first;
68 for (
unsigned int inBatch = 0; inBatch < inputBatchSize; ++inBatch)
70 const unsigned int outBatch = inBatch % outputBatchSize;
71 const unsigned int spatialOffset = inBatch / outputBatchSize;
74 const unsigned int outH = inH * blockShapeHeight + spatialOffset / blockShapeWidth - cropsTop;
76 if (outH >= outputHeight)
82 const unsigned int outW = inW * blockShapeWidth + spatialOffset % blockShapeWidth - cropsLeft;
84 if (outW >= outputWidth)
89 for (
unsigned int c = 0; c < channels; c++)
91 unsigned int outOffset =
Offset(outputShape, outBatch, outH, outW, c, dataLayout);
92 unsigned int inOffset =
Offset(inputShape, inBatch, inH, inW, c, dataLayout);
94 outputEncoder[outOffset];
95 inputDecoder[inOffset];
96 outputEncoder.
Set(inputDecoder.
Get());
void BatchToSpaceNd(const DataLayoutIndexed &dataLayout, const TensorInfo &inputTensorInfo, const TensorInfo &outputTensorInfo, const std::vector< unsigned int > &blockShape, const std::vector< std::pair< unsigned int, unsigned int >> &cropsData, Decoder< float > &inputDecoder, Encoder< float > &outputEncoder)
unsigned int Offset(const TensorShape &shape, unsigned int batch, unsigned int height, unsigned int width, unsigned int channels, const DataLayoutIndexed &dataLayout)
unsigned int GetNumDimensions() const
armnn::DataLayout GetDataLayout() const
unsigned int GetHeightIndex() const
unsigned int GetWidthIndex() const
unsigned int GetChannelsIndex() const
virtual IType Get() const =0
const TensorShape & GetShape() const
virtual void Set(IType right)=0