aboutsummaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
authorVidhya Sudhan Loganathan <vidhyasudhan.loganathan@arm.com>2018-12-18 14:17:00 +0000
committerGeorgios Pinitas <georgios.pinitas@arm.com>2018-12-18 17:40:19 +0000
commit5e96be7707a571b136dc64256af399dbbb0fdfe0 (patch)
tree92229d9824f3089814ed2af56c5f76a474366954 /utils
parent52ebf4219385efe54463dc794ba806b82a6137b3 (diff)
downloadComputeLibrary-5e96be7707a571b136dc64256af399dbbb0fdfe0.tar.gz
COMPMID-1722 : CL: Implement Range
Change-Id: I88da6eb5289c303b1dc91606c1560ce629746058 Reviewed-on: https://review.mlplatform.org/381 Reviewed-by: Gian Marco Iodice <gianmarco.iodice@arm.com> Tested-by: Arm Jenkins <bsgcomp@arm.com> Reviewed-by: Georgios Pinitas <georgios.pinitas@arm.com>
Diffstat (limited to 'utils')
-rw-r--r--utils/Utils.h49
1 files changed, 49 insertions, 0 deletions
diff --git a/utils/Utils.h b/utils/Utils.h
index 8cac857178..031a3726a1 100644
--- a/utils/Utils.h
+++ b/utils/Utils.h
@@ -194,6 +194,55 @@ inline std::string get_typestring(DataType data_type)
}
}
+/** 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;
+ }
+}
+
/** Maps a tensor if needed
*
* @param[in] tensor Tensor to be mapped