aboutsummaryrefslogtreecommitdiff
path: root/src/armnnUtils/VerificationHelpers.cpp
diff options
context:
space:
mode:
authortelsoa01 <telmo.soares@arm.com>2018-08-31 09:22:23 +0100
committertelsoa01 <telmo.soares@arm.com>2018-08-31 09:22:23 +0100
commitc577f2c6a3b4ddb6ba87a882723c53a248afbeba (patch)
treebd7d4c148df27f8be6649d313efb24f536b7cf34 /src/armnnUtils/VerificationHelpers.cpp
parent4c7098bfeab1ffe1cdc77f6c15548d3e73274746 (diff)
downloadarmnn-c577f2c6a3b4ddb6ba87a882723c53a248afbeba.tar.gz
Release 18.08
Diffstat (limited to 'src/armnnUtils/VerificationHelpers.cpp')
-rw-r--r--src/armnnUtils/VerificationHelpers.cpp74
1 files changed, 74 insertions, 0 deletions
diff --git a/src/armnnUtils/VerificationHelpers.cpp b/src/armnnUtils/VerificationHelpers.cpp
new file mode 100644
index 0000000000..301aa4c8c5
--- /dev/null
+++ b/src/armnnUtils/VerificationHelpers.cpp
@@ -0,0 +1,74 @@
+//
+// Copyright © 2017 Arm Ltd. All rights reserved.
+// See LICENSE file in the project root for full license information.
+//
+
+#include "VerificationHelpers.hpp"
+#include <boost/format.hpp>
+#include <armnn/Exceptions.hpp>
+
+using namespace armnn;
+
+namespace armnnUtils
+{
+
+void CheckValidSize(std::initializer_list<size_t> validInputCounts,
+ size_t actualValue,
+ const char* validExpr,
+ const char* actualExpr,
+ const CheckLocation& location)
+{
+ bool isValid = std::any_of(validInputCounts.begin(),
+ validInputCounts.end(),
+ [&actualValue](size_t x) { return x == actualValue; } );
+ if (!isValid)
+ {
+ throw ParseException(
+ boost::str(
+ boost::format("%1% = %2% is not valid, not in {%3%}. %4%") %
+ actualExpr %
+ actualValue %
+ validExpr %
+ location.AsString()));
+ }
+}
+
+uint32_t NonNegative(const char* expr,
+ int32_t value,
+ const CheckLocation& location)
+{
+ if (value < 0)
+ {
+ throw ParseException(
+ boost::str(
+ boost::format("'%1%' must be non-negative, received: %2% at %3%") %
+ expr %
+ value %
+ location.AsString() ));
+ }
+ else
+ {
+ return static_cast<uint32_t>(value);
+ }
+}
+
+int32_t VerifyInt32(const char* expr,
+ int64_t value,
+ const armnn::CheckLocation& location)
+{
+ if (value < std::numeric_limits<int>::min() || value > std::numeric_limits<int>::max())
+ {
+ throw ParseException(
+ boost::str(
+ boost::format("'%1%' must should fit into a int32 (ArmNN don't support int64), received: %2% at %3%") %
+ expr %
+ value %
+ location.AsString() ));
+ }
+ else
+ {
+ return static_cast<int32_t>(value);
+ }
+}
+
+}// armnnUtils