GitHub #577 slice layer does not handle a size of -1

 * Added support for size of -1
   A size of -1 is treated as size = dimension - begin

Signed-off-by: Mike Kelly <mike.kelly@arm.com>
Change-Id: I4e381a3794852ec45be029028e2d29bc87791635
diff --git a/src/armnnTfLiteParser/TfLiteParser.cpp b/src/armnnTfLiteParser/TfLiteParser.cpp
index 8c85d30..0f0e67c 100644
--- a/src/armnnTfLiteParser/TfLiteParser.cpp
+++ b/src/armnnTfLiteParser/TfLiteParser.cpp
@@ -1609,13 +1609,38 @@
     armnn::TensorInfo sizeTensorInfo = ToTensorInfo(inputs[2]);
     BufferRawPtr sizeBufferPtr = GetBuffer(m_Model, inputs[2]->buffer);
 
+    std::vector<int> signedSize(sizeTensorInfo.GetNumElements());
+    ::memcpy(signedSize.data(), sizeBufferPtr->data.data(), sizeTensorInfo.GetNumBytes());
     std::vector<unsigned int> size(sizeTensorInfo.GetNumElements());
-    ::memcpy(size.data(), sizeBufferPtr->data.data(), sizeTensorInfo.GetNumBytes());
+    TensorInfo inputTensorInfo = ToTensorInfo(inputs[0]);
+
+    for (unsigned int i = 0; i < signedSize.size(); ++i)
+    {
+        int signedValue = signedSize[i];
+        
+        if (signedValue < -1 || signedValue > static_cast<int>(inputTensorInfo.GetShape()[i] - begin[i]))
+        {
+            throw ParseException(fmt::format("Invalid value for size {} size must be in range "
+                                             "[-1, inputDimSize - begin] [-1, {}] inclusive {}",
+                                             signedValue,
+                                             inputTensorInfo.GetShape()[i] - begin[i],
+                                             CHECK_LOCATION().AsString()));
+        }
+
+        if (signedValue == -1)
+        {
+            size[i] = inputTensorInfo.GetShape()[i] - begin[i];
+        }
+        else
+        {
+            size[i] = static_cast<unsigned int>(signedValue);
+        }
+    }
+
     desc = SliceDescriptor(begin, size);
 
     auto layerName = fmt::format("Slice:{}:{}", subgraphIndex, operatorIndex);
 
-    TensorInfo inputTensorInfo = ToTensorInfo(inputs[0]);
     TensorInfo outputTensorInfo = ToTensorInfo(outputs[0], true);
     CheckMatchingQuantization(inputTensorInfo, outputTensorInfo, layerName, "Input 0", "Output 0");
 
diff --git a/src/armnnTfLiteParser/test/Slice.cpp b/src/armnnTfLiteParser/test/Slice.cpp
index 2a28c6e..a2a791f 100644
--- a/src/armnnTfLiteParser/test/Slice.cpp
+++ b/src/armnnTfLiteParser/test/Slice.cpp
@@ -176,7 +176,7 @@
     DynamicSliceFixtureD213() : SliceFixture("[ 3, 2, 3 ]",
                                             "[ ]",
                                               "[ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]",
-                                                "[ 2, 0, 0, 0, 1, 0, 0, 0, 3, 0, 0, 0 ]") {}
+                                                "[ 255, 255, 255, 255, 1, 0, 0, 0, 255, 255, 255, 255 ]") {}
 };
 
 TEST_CASE_FIXTURE(DynamicSliceFixtureD213, "DynamicSliceD213")
@@ -187,5 +187,4 @@
         {{"outputTensor", { 3, 3, 3, 5, 5, 5 }}},
         true);
 }
-
 }
\ No newline at end of file