IVGCVSW-7749 DTS: Fix reshape floating point exception

  * Updated Opaque Delegate, TfliteParser, OnnxParser, and Deserializer to handle the Zero In Shape edge case

Signed-off-by: Tianle Cheng <tianle.cheng@arm.com>
Change-Id: I4a0d1e72a66de1fa56de99af9b6730a84e0ff596
diff --git a/src/armnnTfLiteParser/TfLiteParser.cpp b/src/armnnTfLiteParser/TfLiteParser.cpp
index c2be54f..30875d5 100644
--- a/src/armnnTfLiteParser/TfLiteParser.cpp
+++ b/src/armnnTfLiteParser/TfLiteParser.cpp
@@ -3252,6 +3252,7 @@
     auto outputTensorIndexes = AsUnsignedVector(GetOutputTensorIds(m_Model, subgraphIndex, operatorIndex));
     RegisterOutputSlots(subgraphIndex, operatorIndex, layer, {outputTensorIndexes[0]});
 }
+
 armnn::TensorInfo TfLiteParserImpl::OutputShapeOfReshape(const armnn::TensorInfo& inputTensorInfo,
                                                          const std::vector<int32_t>& targetDimsIn)
 {
@@ -3271,7 +3272,24 @@
                 std::accumulate(targetDimsIn.begin(), targetDimsIn.end(), -1, std::multiplies<int32_t>()));
 
         auto stretchIndex = static_cast<size_t>(std::distance(targetDimsIn.begin(), stretchDim));
-        outputDims[stretchIndex] = inputTensorInfo.GetNumElements() / targetNumElements;
+
+        if (targetNumElements == 0)
+        {
+            if (inputTensorInfo.GetNumElements() == 0)
+            {
+                outputDims[stretchIndex] = 0;
+            }
+            else
+            {
+                throw ParseException(
+                        fmt::format("Input to reshape is a tensor with elements, but the requested shape has 0. {}",
+                                    CHECK_LOCATION().AsString()));
+            }
+        }
+        else
+        {
+            outputDims[stretchIndex] = inputTensorInfo.GetNumElements() / targetNumElements;
+        }
     }
 
     TensorShape outputShape = TensorShape(static_cast<unsigned int>(outputDims.size()), outputDims.data());