IVGCVSW-7855 removed ASSERTs from armnnUtils code

Signed-off-by: Jim Flynn <jim.flynn@arm.com>
Change-Id: Ie26ea2ac4a82d7460ae719fc3154c6a88b079606
diff --git a/src/armnnUtils/FloatingPointConverter.cpp b/src/armnnUtils/FloatingPointConverter.cpp
index 024b74e..102ad09 100644
--- a/src/armnnUtils/FloatingPointConverter.cpp
+++ b/src/armnnUtils/FloatingPointConverter.cpp
@@ -8,6 +8,7 @@
 #include "BFloat16.hpp"
 #include "Half.hpp"
 
+#include <armnn/Exceptions.hpp>
 #include <armnn/utility/Assert.hpp>
 
 namespace armnnUtils
@@ -17,8 +18,14 @@
                                                 size_t numElements,
                                                 void* dstFloat16Buffer)
 {
-    ARMNN_ASSERT(srcFloat32Buffer != nullptr);
-    ARMNN_ASSERT(dstFloat16Buffer != nullptr);
+    if (srcFloat32Buffer == nullptr)
+    {
+        throw armnn::InvalidArgumentException("ConvertFloat32To16: source float32 buffer pointer is null");
+    }
+    if (dstFloat16Buffer == nullptr)
+    {
+        throw armnn::InvalidArgumentException("ConvertFloat32To16: destination float16 buffer pointer is null");
+    }
 
     armnn::Half* pHalf = static_cast<armnn::Half*>(dstFloat16Buffer);
 
@@ -37,8 +44,14 @@
                                                 size_t numElements,
                                                 float* dstFloat32Buffer)
 {
-    ARMNN_ASSERT(srcFloat16Buffer != nullptr);
-    ARMNN_ASSERT(dstFloat32Buffer != nullptr);
+    if (srcFloat16Buffer == nullptr)
+    {
+        throw armnn::InvalidArgumentException("ConvertFloat16To32: source float16 buffer pointer is null");
+    }
+    if (dstFloat32Buffer == nullptr)
+    {
+        throw armnn::InvalidArgumentException("ConvertFloat16To32: destination float32 buffer pointer is null");
+    }
 
     const armnn::Half* pHalf = static_cast<const armnn::Half*>(srcFloat16Buffer);
 
diff --git a/src/armnnUtils/ModelAccuracyChecker.cpp b/src/armnnUtils/ModelAccuracyChecker.cpp
index 418737c..83cd0cb 100644
--- a/src/armnnUtils/ModelAccuracyChecker.cpp
+++ b/src/armnnUtils/ModelAccuracyChecker.cpp
@@ -5,6 +5,7 @@
 
 #include "ModelAccuracyChecker.hpp"
 
+#include <armnn/Exceptions.hpp>
 #include <armnn/Logging.hpp>
 
 #include <map>
@@ -63,7 +64,10 @@
 // Remove any preceding and trailing character specified in the characterSet.
 std::string Strip(const std::string& originalString, const std::string& characterSet)
 {
-    ARMNN_ASSERT(!characterSet.empty());
+    if (characterSet.empty())
+    {
+        throw armnn::InvalidArgumentException("Strip: string of characters to strip is empty");
+    }
     const std::size_t firstFound = originalString.find_first_not_of(characterSet);
     const std::size_t lastFound  = originalString.find_last_not_of(characterSet);
     // Return empty if the originalString is empty or the originalString contains only to-be-striped characters
@@ -73,4 +77,4 @@
     }
     return originalString.substr(firstFound, lastFound + 1 - firstFound);
 }
-}    // namespace armnnUtils
\ No newline at end of file
+}    // namespace armnnUtils
diff --git a/src/armnnUtils/TensorUtils.cpp b/src/armnnUtils/TensorUtils.cpp
index cb73d92..3e703a5 100644
--- a/src/armnnUtils/TensorUtils.cpp
+++ b/src/armnnUtils/TensorUtils.cpp
@@ -5,6 +5,8 @@
 
 #include <armnnUtils/TensorUtils.hpp>
 
+#include <armnn/Exceptions.hpp>
+
 #include <armnn/backends/ITensorHandle.hpp>
 #include <armnn/utility/Assert.hpp>
 #include <armnn/utility/NumericCast.hpp>
@@ -208,8 +210,21 @@
                                    const unsigned int firstAxisInclusive,
                                    const unsigned int lastAxisExclusive)
 {
-    ARMNN_ASSERT(firstAxisInclusive <= lastAxisExclusive);
-    ARMNN_ASSERT(lastAxisExclusive <= shape.GetNumDimensions());
+    if (firstAxisInclusive > lastAxisExclusive)
+    {
+        throw armnn::InvalidArgumentException(fmt::format(
+            "GetNumElementsBetween: firstAxisInclusive [{}D] is greater than lastAxisExclusive [{}D]",
+            firstAxisInclusive,
+            lastAxisExclusive));
+    }
+    if (lastAxisExclusive > shape.GetNumDimensions())
+    {
+        throw armnn::InvalidArgumentException(fmt::format(
+            "{}: lastAxisExclusive [{}D] is greater than the number of dimensions of the tensor shape [{}D]"
+            "GetNumElementsBetween",
+            lastAxisExclusive,
+            shape.GetNumDimensions()));
+    }
     unsigned int count = 1;
     for (unsigned int i = firstAxisInclusive; i < lastAxisExclusive; i++)
     {
@@ -220,10 +235,22 @@
 
 unsigned int GetUnsignedAxis(const unsigned int inputDimension, const int axis)
 {
-    ARMNN_ASSERT_MSG(axis < armnn::numeric_cast<int>(inputDimension),
-                     "Required axis index greater than number of dimensions.");
-    ARMNN_ASSERT_MSG(axis >= -armnn::numeric_cast<int>(inputDimension),
-                     "Required axis index lower than negative of the number of dimensions");
+    if (axis >= armnn::numeric_cast<int>(inputDimension))
+    {
+        throw armnn::InvalidArgumentException(fmt::format(
+            "{}: axis index [{}] is not less than the number of dimensions [{}D]",
+            "GetUnsignedAxis",
+            axis,
+            inputDimension));
+    }
+    if (axis < -armnn::numeric_cast<int>(inputDimension))
+    {
+        throw armnn::InvalidArgumentException(fmt::format(
+            "{}: axis index [{}] lower than the negative of the number of dimensions [{}]",
+            "GetUnsignedAxis",
+            axis,
+            -armnn::numeric_cast<int>(inputDimension)));
+    }
 
     unsigned int uAxis = axis < 0  ?
                          inputDimension - armnn::numeric_cast<unsigned int>(abs(axis))
@@ -234,7 +261,14 @@
 unsigned int GetNumElementsAfter(const armnn::TensorShape& shape, unsigned int axis)
 {
     unsigned int numDim = shape.GetNumDimensions();
-    ARMNN_ASSERT(axis <= numDim - 1);
+    if (axis >= numDim)
+    {
+        throw armnn::InvalidArgumentException(fmt::format(
+            "{}: axis index [{}D] indexes beyond the number of dimesions of the tensor shape [{}D]",
+            "GetNumElementsAfter",
+            axis,
+            numDim));
+    }
     unsigned int count = 1;
     for (unsigned int i = axis+1; i < numDim; i++)
     {