aboutsummaryrefslogtreecommitdiff
path: root/delegate/common
diff options
context:
space:
mode:
authorMatthew Sloyan <matthew.sloyan@arm.com>2023-04-28 17:27:26 +0100
committerMatthew Sloyan <matthew.sloyan@arm.com>2023-05-02 11:03:23 +0000
commitc49aacc83370e89435129650a30ef1b384712dfe (patch)
tree5d077bcc282505e68953cddbdea47d919be2b67f /delegate/common
parente9b81a4571edc238a582e45d14d29ba346da18a9 (diff)
downloadarmnn-c49aacc83370e89435129650a30ef1b384712dfe.tar.gz
IVGCVSW-7603 Implement Reshape operators for Opaque Delegate
* Moved CreateOutputTensorShape function to common DelegateUtils.hpp Signed-off-by: Matthew Sloyan <matthew.sloyan@arm.com> Change-Id: I3d8a9834ecd6b7cda170cce958677a0dde62824a
Diffstat (limited to 'delegate/common')
-rw-r--r--delegate/common/src/DelegateUtils.hpp31
1 files changed, 31 insertions, 0 deletions
diff --git a/delegate/common/src/DelegateUtils.hpp b/delegate/common/src/DelegateUtils.hpp
index 51c70f9ba1..37fe9b5b84 100644
--- a/delegate/common/src/DelegateUtils.hpp
+++ b/delegate/common/src/DelegateUtils.hpp
@@ -21,6 +21,8 @@
#include <tensorflow/lite/minimal_logging.h>
#include <tensorflow/lite/kernels/kernel_util.h>
+#include <numeric>
+
namespace
{
@@ -138,4 +140,33 @@ void SetupConcatViewOrigin(const armnn::TensorInfo& inputTensorInfo,
}
}
+TfLiteStatus CreateOutputTensorShape(const armnn::TensorInfo& inputTensorInfo,
+ const std::vector<int32_t>& targetShape,
+ armnn::ReshapeDescriptor& reshapeDesc)
+{
+ std::vector<unsigned int> outputDims(targetShape.begin(), targetShape.end());
+ const auto stretchDim = std::find(targetShape.begin(), targetShape.end(), -1);
+
+ if (stretchDim != targetShape.end())
+ {
+ if (std::find(std::next(stretchDim), targetShape.end(), -1) != targetShape.end())
+ {
+ // Return kTfLiteError and log the error after returning
+ return kTfLiteError;
+ }
+
+ auto targetNumElements =
+ armnn::numeric_cast<unsigned int>(
+ std::accumulate(targetShape.begin(), targetShape.end(), -1, std::multiplies<int32_t>()));
+
+ auto stretchIndex = static_cast<size_t>(std::distance(targetShape.begin(), stretchDim));
+ outputDims[stretchIndex] = inputTensorInfo.GetNumElements() / targetNumElements;
+ }
+
+ armnn::TensorShape outputShape = armnn::TensorShape(static_cast<unsigned int>(outputDims.size()),
+ outputDims.data());
+ reshapeDesc.m_TargetShape = outputShape;
+ return kTfLiteOk;
+}
+
} // namespace anonymous