blob: 243d22e4449d5599fb9dc161c6ceed9c30174f73 [file] [log] [blame]
telsoa01c577f2c2018-08-31 09:22:23 +01001//
2// Copyright © 2017 Arm Ltd. All rights reserved.
David Beckecb56cd2018-09-05 12:52:57 +01003// SPDX-License-Identifier: MIT
telsoa01c577f2c2018-08-31 09:22:23 +01004//
5
6#include "VerificationHelpers.hpp"
7#include <boost/format.hpp>
8#include <armnn/Exceptions.hpp>
9
10using namespace armnn;
11
12namespace armnnUtils
13{
14
15void CheckValidSize(std::initializer_list<size_t> validInputCounts,
16 size_t actualValue,
17 const char* validExpr,
18 const char* actualExpr,
19 const CheckLocation& location)
20{
21 bool isValid = std::any_of(validInputCounts.begin(),
22 validInputCounts.end(),
23 [&actualValue](size_t x) { return x == actualValue; } );
24 if (!isValid)
25 {
26 throw ParseException(
27 boost::str(
28 boost::format("%1% = %2% is not valid, not in {%3%}. %4%") %
29 actualExpr %
30 actualValue %
31 validExpr %
32 location.AsString()));
33 }
34}
35
36uint32_t NonNegative(const char* expr,
37 int32_t value,
38 const CheckLocation& location)
39{
40 if (value < 0)
41 {
42 throw ParseException(
43 boost::str(
44 boost::format("'%1%' must be non-negative, received: %2% at %3%") %
45 expr %
46 value %
47 location.AsString() ));
48 }
49 else
50 {
51 return static_cast<uint32_t>(value);
52 }
53}
54
55int32_t VerifyInt32(const char* expr,
56 int64_t value,
57 const armnn::CheckLocation& location)
58{
59 if (value < std::numeric_limits<int>::min() || value > std::numeric_limits<int>::max())
60 {
61 throw ParseException(
62 boost::str(
63 boost::format("'%1%' must should fit into a int32 (ArmNN don't support int64), received: %2% at %3%") %
64 expr %
65 value %
66 location.AsString() ));
67 }
68 else
69 {
70 return static_cast<int32_t>(value);
71 }
72}
73
74}// armnnUtils