From 490b3d839808cbd088ab567dec991dcefb08f718 Mon Sep 17 00:00:00 2001 From: Diego Lopez Recas Date: Tue, 19 Dec 2017 15:42:25 +0000 Subject: IVGCVSW-863 Move clamp, for_each, foldl to misc/utility.h Also, improve for_each, foldl, and related changes. Change-Id: I0cf0c7dbf88f26bb70cc734ba9fb5725d405585f Reviewed-on: https://eu-gerrit-1.euhpc.arm.com/114014 Reviewed-by: Anthony Barbier Reviewed-by: Georgios Pinitas Tested-by: Jenkins --- arm_compute/core/Helpers.h | 74 +++------------------------------------------- 1 file changed, 4 insertions(+), 70 deletions(-) (limited to 'arm_compute/core/Helpers.h') diff --git a/arm_compute/core/Helpers.h b/arm_compute/core/Helpers.h index c02f14aecc..3575fcf1b9 100644 --- a/arm_compute/core/Helpers.h +++ b/arm_compute/core/Helpers.h @@ -253,72 +253,6 @@ inline uint8_t pixel_bilinear_c1_clamp(const T *first_pixel_ptr, size_t stride, */ inline uint8_t pixel_area_c1u8_clamp(const uint8_t *first_pixel_ptr, size_t stride, size_t width, size_t height, float wr, float hr, int x, int y); -/** Performs clamping among a lower and upper value. - * - * @param[in] n Value to clamp. - * @param[in] lower Lower threshold. - * @param[in] upper Upper threshold. - * - * @return Clamped value. - */ -template -inline T clamp(const T &n, const T &lower, const T &upper) -{ - return std::max(lower, std::min(n, upper)); -} - -/** Base case of for_each. Does nothing. */ -template -inline void for_each(F &&) -{ -} - -/** Call the function for each of the arguments - * - * @param[in] func Function to be called - * @param[in] arg Argument passed to the function - * @param[in] args Remaining arguments - */ -template -inline void for_each(F &&func, T &&arg, Ts &&... args) -{ - func(arg); - for_each(func, args...); -} - -/** Base case of foldl. - * - * @return value. - */ -template -inline T foldl(F &&, const T &value) -{ - return value; -} - -/** Base case of foldl. - * - * @return Function evaluation for value1 and value2 - */ -template -inline auto foldl(F &&func, T &&value1, U &&value2) -> decltype(func(value1, value2)) -{ - return func(value1, value2); -} - -/** Fold left. - * - * @param[in] func Function to be called - * @param[in] initial Initial value - * @param[in] value Argument passed to the function - * @param[in] values Remaining arguments - */ -template -inline I foldl(F &&func, I &&initial, T &&value, Vs &&... values) -{ - return foldl(std::forward(func), func(std::forward(initial), std::forward(value)), std::forward(values)...); -} - /** Iterator updated by @ref execute_window_loop for each window element */ class Iterator { @@ -408,7 +342,7 @@ bool update_window_and_padding(Window &win, Ts &&... patterns) { bool window_changed = false; - for_each([&](const IAccessWindow & w) + utility::for_each([&](const IAccessWindow & w) { window_changed |= w.update_window_if_needed(win); }, @@ -416,7 +350,7 @@ bool update_window_and_padding(Window &win, Ts &&... patterns) bool padding_changed = false; - for_each([&](const IAccessWindow & w) + utility::for_each([&](const IAccessWindow & w) { padding_changed |= w.update_padding_if_needed(win); }, @@ -464,7 +398,7 @@ Window calculate_max_enlarged_window(const ITensorInfo &info, const Steps &steps * @return Intersection of all regions. */ template -ValidRegion intersect_valid_regions(Ts &&... regions) +ValidRegion intersect_valid_regions(const Ts &... regions) { auto intersect = [](const ValidRegion & r1, const ValidRegion & r2) -> ValidRegion { @@ -483,7 +417,7 @@ ValidRegion intersect_valid_regions(Ts &&... regions) return region; }; - return foldl(intersect, std::forward(regions)...); + return utility::foldl(intersect, regions...); } /** Create a strides object based on the provided strides and the tensor dimensions. -- cgit v1.2.1