diff options
author | Matthew Sloyan <matthew.sloyan@arm.com> | 2023-04-28 17:27:26 +0100 |
---|---|---|
committer | Matthew Sloyan <matthew.sloyan@arm.com> | 2023-05-02 11:03:23 +0000 |
commit | c49aacc83370e89435129650a30ef1b384712dfe (patch) | |
tree | 5d077bcc282505e68953cddbdea47d919be2b67f /delegate/common | |
parent | e9b81a4571edc238a582e45d14d29ba346da18a9 (diff) | |
download | armnn-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.hpp | 31 |
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 |