blob: a4db97adf4751dcdec39548b65f49901cf610a81 [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"
telsoa01c577f2c2018-08-31 09:22:23 +01007#include <armnn/Exceptions.hpp>
8
Colm Donelan5b5c2222020-09-09 12:48:16 +01009#include <fmt/format.h>
10
telsoa01c577f2c2018-08-31 09:22:23 +010011using namespace armnn;
12
13namespace armnnUtils
14{
15
16void CheckValidSize(std::initializer_list<size_t> validInputCounts,
17 size_t actualValue,
18 const char* validExpr,
19 const char* actualExpr,
20 const CheckLocation& location)
21{
22 bool isValid = std::any_of(validInputCounts.begin(),
23 validInputCounts.end(),
24 [&actualValue](size_t x) { return x == actualValue; } );
25 if (!isValid)
26 {
Colm Donelan5b5c2222020-09-09 12:48:16 +010027 throw ParseException(fmt::format("{} = {} is not valid, not in {{}}. {}",
28 actualExpr,
29 actualValue,
30 validExpr,
31 location.AsString()));
telsoa01c577f2c2018-08-31 09:22:23 +010032 }
33}
34
35uint32_t NonNegative(const char* expr,
36 int32_t value,
37 const CheckLocation& location)
38{
39 if (value < 0)
40 {
Colm Donelan5b5c2222020-09-09 12:48:16 +010041 throw ParseException(fmt::format("'{}' must be non-negative, received: {} at {}",
42 expr,
43 value,
44 location.AsString()));
telsoa01c577f2c2018-08-31 09:22:23 +010045 }
46 else
47 {
48 return static_cast<uint32_t>(value);
49 }
50}
51
52int32_t VerifyInt32(const char* expr,
53 int64_t value,
54 const armnn::CheckLocation& location)
55{
56 if (value < std::numeric_limits<int>::min() || value > std::numeric_limits<int>::max())
57 {
Colm Donelan5b5c2222020-09-09 12:48:16 +010058 throw ParseException(fmt::format("'{}' must should fit into a int32 (ArmNN don't support int64),"
59 " received: {} at {}",
60 expr,
61 value,
62 location.AsString()));
telsoa01c577f2c2018-08-31 09:22:23 +010063 }
64 else
65 {
66 return static_cast<int32_t>(value);
67 }
68}
69
70}// armnnUtils