telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2017 Arm Ltd. All rights reserved. |
David Beck | ecb56cd | 2018-09-05 12:52:57 +0100 | [diff] [blame] | 3 | // SPDX-License-Identifier: MIT |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 4 | // |
| 5 | |
| 6 | #include "VerificationHelpers.hpp" |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 7 | #include <armnn/Exceptions.hpp> |
| 8 | |
Colm Donelan | 5b5c222 | 2020-09-09 12:48:16 +0100 | [diff] [blame] | 9 | #include <fmt/format.h> |
| 10 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 11 | using namespace armnn; |
| 12 | |
| 13 | namespace armnnUtils |
| 14 | { |
| 15 | |
| 16 | void 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 Donelan | 5b5c222 | 2020-09-09 12:48:16 +0100 | [diff] [blame] | 27 | throw ParseException(fmt::format("{} = {} is not valid, not in {{}}. {}", |
| 28 | actualExpr, |
| 29 | actualValue, |
| 30 | validExpr, |
| 31 | location.AsString())); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 32 | } |
| 33 | } |
| 34 | |
| 35 | uint32_t NonNegative(const char* expr, |
| 36 | int32_t value, |
| 37 | const CheckLocation& location) |
| 38 | { |
| 39 | if (value < 0) |
| 40 | { |
Colm Donelan | 5b5c222 | 2020-09-09 12:48:16 +0100 | [diff] [blame] | 41 | throw ParseException(fmt::format("'{}' must be non-negative, received: {} at {}", |
| 42 | expr, |
| 43 | value, |
| 44 | location.AsString())); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 45 | } |
| 46 | else |
| 47 | { |
| 48 | return static_cast<uint32_t>(value); |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | int32_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 Donelan | 5b5c222 | 2020-09-09 12:48:16 +0100 | [diff] [blame] | 58 | 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())); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 63 | } |
| 64 | else |
| 65 | { |
| 66 | return static_cast<int32_t>(value); |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | }// armnnUtils |