ArmNN
 24.02
VerificationHelpers.cpp
Go to the documentation of this file.
1 //
2 // Copyright © 2017 Arm Ltd. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 
7 #include <armnn/Exceptions.hpp>
8 
9 #include <fmt/format.h>
10 
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  {
27  throw ParseException(fmt::format("{} = {} is not valid, not in {{}}. {}",
28  actualExpr,
29  actualValue,
30  validExpr,
31  location.AsString()));
32  }
33 }
34 
35 uint32_t NonNegative(const char* expr,
36  int32_t value,
37  const CheckLocation& location)
38 {
39  if (value < 0)
40  {
41  throw ParseException(fmt::format("'{}' must be non-negative, received: {} at {}",
42  expr,
43  value,
44  location.AsString()));
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  {
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()));
63  }
64  else
65  {
66  return static_cast<int32_t>(value);
67  }
68 }
69 
70 }// armnnUtils
armnnUtils::NonNegative
uint32_t NonNegative(const char *expr, int32_t value, const CheckLocation &location)
Definition: VerificationHelpers.cpp:35
armnn::CheckLocation::AsString
std::string AsString() const
Definition: Exceptions.hpp:29
armnnUtils::CheckValidSize
void CheckValidSize(std::initializer_list< size_t > validInputCounts, size_t actualValue, const char *validExpr, const char *actualExpr, const CheckLocation &location)
Definition: VerificationHelpers.cpp:16
VerificationHelpers.hpp
armnn::CheckLocation
Definition: Exceptions.hpp:14
armnnUtils
Definition: CompatibleTypes.hpp:10
armnnUtils::VerifyInt32
int32_t VerifyInt32(const char *expr, int64_t value, const armnn::CheckLocation &location)
Definition: VerificationHelpers.cpp:52
armnn::ParseException
Definition: Exceptions.hpp:92
Exceptions.hpp
armnn
Copyright (c) 2021 ARM Limited and Contributors.
Definition: 01_00_quick_start.dox:6