From 0280785b00cd84f14249d3545a15b93627acf57b Mon Sep 17 00:00:00 2001 From: Narumol Prangnawarat Date: Wed, 11 Sep 2019 16:43:09 +0100 Subject: IVGCVSW-3663 Add utility function to expand tensor dimension Signed-off-by: Narumol Prangnawarat Change-Id: I54d2416be305db7d3fc15fb3123694ad6740b27d --- src/armnnUtils/TensorUtils.cpp | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'src/armnnUtils/TensorUtils.cpp') diff --git a/src/armnnUtils/TensorUtils.cpp b/src/armnnUtils/TensorUtils.cpp index c2fbbe0bcc..8baea78ab5 100644 --- a/src/armnnUtils/TensorUtils.cpp +++ b/src/armnnUtils/TensorUtils.cpp @@ -6,6 +6,10 @@ #include "TensorUtils.hpp" #include +#include +#include +#include + namespace armnnUtils { @@ -75,4 +79,32 @@ std::pair FindMinMax(armnn::ITensorHandle* tensorHandle) return std::make_pair(min, max); } +armnn::TensorShape ExpandDims(const armnn::TensorShape& tensorShape, int axis) +{ + unsigned int outputDim = tensorShape.GetNumDimensions() + 1; + + if (axis < -boost::numeric_cast(outputDim) || axis > boost::numeric_cast(tensorShape.GetNumDimensions())) + { + throw armnn::InvalidArgumentException( + boost::str(boost::format("Invalid expansion axis %1% for %2%D input tensor. %3%") % + axis % + tensorShape.GetNumDimensions() % + CHECK_LOCATION().AsString())); + } + + if (axis < 0) + { + axis = boost::numeric_cast(outputDim) + axis; + } + + std::vector outputShape; + for (unsigned int i = 0; i < tensorShape.GetNumDimensions(); ++i) + { + outputShape.push_back(tensorShape[i]); + } + outputShape.insert(outputShape.begin() + axis, 1); + + return armnn::TensorShape(outputDim, outputShape.data()); +} + } -- cgit v1.2.1