diff options
author | Michalis Spyrou <michalis.spyrou@arm.com> | 2018-02-06 16:53:47 +0000 |
---|---|---|
committer | Anthony Barbier <anthony.barbier@arm.com> | 2018-11-02 16:46:07 +0000 |
commit | 40df1e9b770393a77afc2ebb94ff7e8f6f8696ed (patch) | |
tree | ef492bb1cd0a14e7cf3315da01e62b2973828b8d /arm_compute | |
parent | f75ab3fb8a1a2a617499c41f8d06e63174165012 (diff) | |
download | ComputeLibrary-40df1e9b770393a77afc2ebb94ff7e8f6f8696ed.tar.gz |
COMPMID-887 Valgrind invalid read in print_measurements
Change-Id: I595d9ac7a616b3ab21ccc889251d0895c9ac9fb0
Reviewed-on: https://eu-gerrit-1.euhpc.arm.com/119099
Tested-by: Jenkins <bsgcomp@arm.com>
Reviewed-by: Georgios Pinitas <georgios.pinitas@arm.com>
Diffstat (limited to 'arm_compute')
-rw-r--r-- | arm_compute/core/utils/misc/utility.h | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/arm_compute/core/utils/misc/utility.h b/arm_compute/core/utils/misc/utility.h index e8d823b5bc..8ba92310da 100644 --- a/arm_compute/core/utils/misc/utility.h +++ b/arm_compute/core/utils/misc/utility.h @@ -24,8 +24,11 @@ #ifndef __ARM_COMPUTE_MISC_UTILITY_H__ #define __ARM_COMPUTE_MISC_UTILITY_H__ +#include <algorithm> #include <array> #include <limits> +#include <numeric> +#include <vector> namespace arm_compute { @@ -140,6 +143,28 @@ T saturate_cast(U val) const auto high = static_cast<U>(std::numeric_limits<T>::max()); return static_cast<T>(clamp(val, low, high)); } + +/** Perform an index sort of a given vector. + * + * @param[in] v Vector to sort + * + * @return Sorted index vector. + */ +template <typename T> +std::vector<size_t> sort_indices(const std::vector<T> &v) +{ + std::vector<size_t> idx(v.size()); + std::iota(idx.begin(), idx.end(), 0); + + std::sort(idx.begin(), idx.end(), + [&v](size_t i1, size_t i2) + { + return v[i1] < v[i2]; + }); + + return idx; +} + } // namespace utility } // namespace arm_compute #endif /* __ARM_COMPUTE_MISC_UTILITY_H__ */ |