diff options
Diffstat (limited to 'support/Random.h')
-rw-r--r-- | support/Random.h | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/support/Random.h b/support/Random.h index c8b767e505..1a804d3290 100644 --- a/support/Random.h +++ b/support/Random.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019-2020 Arm Limited. + * Copyright (c) 2019-2021 Arm Limited. * * SPDX-License-Identifier: MIT * @@ -26,6 +26,8 @@ #include "arm_compute/core/Error.h" +#include "utils/Utils.h" + #include <random> #include <type_traits> @@ -43,13 +45,16 @@ template <typename T> class RangedUniformDistribution { public: - using DT = typename std::conditional<std::is_integral<T>::value, - std::uniform_int_distribution<T>, - std::uniform_real_distribution<float>>::type; + static constexpr bool is_fp_16bit = std::is_same<T, half>::value || std::is_same<T, bfloat16>::value; + static constexpr bool is_integral = std::is_integral<T>::value && !is_fp_16bit; + + using fp_dist = typename std::conditional<is_fp_16bit, + arm_compute::utils::uniform_real_distribution_16bit<T>, + std::uniform_real_distribution<T>>::type; + using DT = typename std::conditional<is_integral, std::uniform_int_distribution<T>, fp_dist>::type; using result_type = T; using range_pair = std::pair<result_type, result_type>; -public: /** Constructor * * @param[in] low lowest value in the range (inclusive) @@ -60,9 +65,9 @@ public: : _distributions(), _selector() { result_type clow = low; - for(const auto &erange : exclude_ranges) + for (const auto &erange : exclude_ranges) { - result_type epsilon = std::is_integral<result_type>::value ? 1 : static_cast<result_type>(std::numeric_limits<float>::epsilon()); + result_type epsilon = is_integral ? result_type(1) : result_type(std::numeric_limits<T>::epsilon()); ARM_COMPUTE_ERROR_ON(clow > erange.first || clow >= erange.second); |