diff options
author | Michalis Spyrou <michalis.spyrou@arm.com> | 2019-01-16 14:18:09 +0000 |
---|---|---|
committer | Michalis Spyrou <michalis.spyrou@arm.com> | 2019-01-16 15:33:54 +0000 |
commit | f63885bc445af1329e6a5c44d94b5c5d78146b2c (patch) | |
tree | 3452320b66765b6c5819b31ef2502c87740b4215 /arm_compute/core | |
parent | 1a57ad1edf755bd284c8a387976c292913616081 (diff) | |
download | ComputeLibrary-f63885bc445af1329e6a5c44d94b5c5d78146b2c.tar.gz |
COMPMID-1710 Move some Util functions to core/Utils
Building with exceptions=0 was failing
Change-Id: I6f264dc859dedc66d12d522652134508e18d5740
Reviewed-on: https://review.mlplatform.org/526
Reviewed-by: Isabella Gottardi <isabella.gottardi@arm.com>
Tested-by: Arm Jenkins <bsgcomp@arm.com>
Diffstat (limited to 'arm_compute/core')
-rw-r--r-- | arm_compute/core/Utils.h | 65 |
1 files changed, 64 insertions, 1 deletions
diff --git a/arm_compute/core/Utils.h b/arm_compute/core/Utils.h index 696845d3ff..44974f1ecc 100644 --- a/arm_compute/core/Utils.h +++ b/arm_compute/core/Utils.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, 2017, 2018 ARM Limited. + * Copyright (c) 2016-2019 ARM Limited. * * SPDX-License-Identifier: MIT * @@ -1041,6 +1041,69 @@ inline std::string float_to_string_with_full_precision(float val) return ss.str(); } +/** Returns the number of elements required to go from start to end with the wanted step + * + * @param[in] start start value + * @param[in] end end value + * @param[in] step step value between each number in the wanted sequence + * + * @return number of elements to go from start value to end value using the wanted step + */ +inline size_t num_of_elements_in_range(const float start, const float end, const float step) +{ + ARM_COMPUTE_ERROR_ON_MSG(step == 0, "Range Step cannot be 0"); + return size_t(std::ceil((end - start) / step)); +} + +/** Returns true if the value can be represented by the given data type + * + * @param[in] val value to be checked + * @param[in] dt data type that is checked + * @param[in] quant_info quantization info if the data type is QASYMM8 + * + * @return true if the data type can hold the value. + */ +template <typename T> +bool check_value_range(T val, DataType dt, QuantizationInfo quant_info = QuantizationInfo()) +{ + switch(dt) + { + case DataType::U8: + return ((static_cast<uint8_t>(val) == val) && val >= std::numeric_limits<uint8_t>::lowest() && val <= std::numeric_limits<uint8_t>::max()); + case DataType::QASYMM8: + { + double min = static_cast<double>(quant_info.dequantize(0)); + double max = static_cast<double>(quant_info.dequantize(std::numeric_limits<uint8_t>::max())); + return ((double)val >= min && (double)val <= max); + } + case DataType::S8: + return ((static_cast<int8_t>(val) == val) && val >= std::numeric_limits<int8_t>::lowest() && val <= std::numeric_limits<int8_t>::max()); + case DataType::U16: + return ((static_cast<uint16_t>(val) == val) && val >= std::numeric_limits<uint16_t>::lowest() && val <= std::numeric_limits<uint16_t>::max()); + case DataType::S16: + return ((static_cast<int16_t>(val) == val) && val >= std::numeric_limits<int16_t>::lowest() && val <= std::numeric_limits<int16_t>::max()); + case DataType::U32: + return ((static_cast<uint32_t>(val) == val) && val >= std::numeric_limits<uint32_t>::lowest() && val <= std::numeric_limits<uint32_t>::max()); + case DataType::S32: + return ((static_cast<int32_t>(val) == val) && val >= std::numeric_limits<int32_t>::lowest() && val <= std::numeric_limits<int32_t>::max()); + case DataType::U64: + return (val >= std::numeric_limits<uint64_t>::lowest() && val <= std::numeric_limits<uint64_t>::max()); + case DataType::S64: + return (val >= std::numeric_limits<int64_t>::lowest() && val <= std::numeric_limits<int64_t>::max()); + case DataType::F16: + return (val >= std::numeric_limits<half>::lowest() && val <= std::numeric_limits<half>::max()); + case DataType::F32: + return (val >= std::numeric_limits<float>::lowest() && val <= std::numeric_limits<float>::max()); + case DataType::F64: + return (val >= std::numeric_limits<double>::lowest() && val <= std::numeric_limits<double>::max()); + case DataType::SIZET: + return ((static_cast<size_t>(val) == val) && val >= std::numeric_limits<size_t>::lowest() && val <= std::numeric_limits<size_t>::max()); + default: + ARM_COMPUTE_ERROR("Data type not supported"); + return false; + } +} + #ifdef ARM_COMPUTE_DEBUG_ENABLED /** Print consecutive elements to an output stream. * |