aboutsummaryrefslogtreecommitdiff
path: root/arm_compute/core
diff options
context:
space:
mode:
authorDiego Lopez Recas <Diego.LopezRecas@arm.com>2017-12-19 15:42:25 +0000
committerAnthony Barbier <anthony.barbier@arm.com>2018-11-02 16:42:33 +0000
commit490b3d839808cbd088ab567dec991dcefb08f718 (patch)
tree72ddb43ddef562ffb3008d9e421b08c7ecab0c3a /arm_compute/core
parent53a6ec5944132000e2c6779c04d722b3b2d2501c (diff)
downloadComputeLibrary-490b3d839808cbd088ab567dec991dcefb08f718.tar.gz
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 <anthony.barbier@arm.com> Reviewed-by: Georgios Pinitas <georgios.pinitas@arm.com> Tested-by: Jenkins <bsgcomp@arm.com>
Diffstat (limited to 'arm_compute/core')
-rw-r--r--arm_compute/core/Helpers.h74
-rw-r--r--arm_compute/core/Helpers.inl15
-rw-r--r--arm_compute/core/utils/misc/utility.h58
3 files changed, 66 insertions, 81 deletions
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 <typename T>
-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 <typename F>
-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 <typename F, typename T, typename... Ts>
-inline void for_each(F &&func, T &&arg, Ts &&... args)
-{
- func(arg);
- for_each(func, args...);
-}
-
-/** Base case of foldl.
- *
- * @return value.
- */
-template <typename F, typename T>
-inline T foldl(F &&, const T &value)
-{
- return value;
-}
-
-/** Base case of foldl.
- *
- * @return Function evaluation for value1 and value2
- */
-template <typename F, typename T, typename U>
-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 <typename F, typename I, typename T, typename... Vs>
-inline I foldl(F &&func, I &&initial, T &&value, Vs &&... values)
-{
- return foldl(std::forward<F>(func), func(std::forward<I>(initial), std::forward<T>(value)), std::forward<Vs>(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 <typename... Ts>
-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<Ts>(regions)...);
+ return utility::foldl(intersect, regions...);
}
/** Create a strides object based on the provided strides and the tensor dimensions.
diff --git a/arm_compute/core/Helpers.inl b/arm_compute/core/Helpers.inl
index 3672692814..4121fb1e8d 100644
--- a/arm_compute/core/Helpers.inl
+++ b/arm_compute/core/Helpers.inl
@@ -80,17 +80,12 @@ struct IncrementIterators
template <typename T, typename... Ts>
static void unroll(T &&it, Ts &&... iterators)
{
- it.increment(dimension);
- IncrementIterators<dimension>::unroll<Ts...>(std::forward<Ts>(iterators)...);
- }
-
- template <typename T>
- static void unroll(T &&it)
- {
- it.increment(dimension);
- // End of recursion
+ auto increment = [](T && it)
+ {
+ it.increment(dimension);
+ };
+ utility::for_each(increment, std::forward<T>(it), std::forward<Ts>(iterators)...);
}
-
static void unroll()
{
// End of recursion
diff --git a/arm_compute/core/utils/misc/utility.h b/arm_compute/core/utils/misc/utility.h
index 898d0cdea8..45b3b5268e 100644
--- a/arm_compute/core/utils/misc/utility.h
+++ b/arm_compute/core/utils/misc/utility.h
@@ -67,6 +67,62 @@ std::array<typename std::iterator_traits<Iterator>::value_type, N> make_array(It
{
return detail::make_array(first, index_sequence_t<N> {});
}
-} // namespace misc
+
+/** 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 <typename T>
+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 <typename F>
+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 <typename F, typename T, typename... Ts>
+inline void for_each(F &&func, T &&arg, Ts &&... args)
+{
+ func(std::forward<T>(arg));
+ for_each(std::forward<F>(func), std::forward<Ts>(args)...);
+}
+
+/** Base case of foldl.
+ *
+ * @return value.
+ */
+template <typename F, typename T>
+inline T &&foldl(F &&, T &&value)
+{
+ return std::forward<T>(value);
+}
+
+/** 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 <typename F, typename T, typename U, typename... Us>
+inline auto foldl(F &&func, T &&initial, U &&value, Us &&... values) -> decltype(func(std::forward<T>(initial), std::forward<U>(value)))
+{
+ return foldl(std::forward<F>(func), func(std::forward<T>(initial), std::forward<U>(value)), std::forward<Us>(values)...);
+}
+} // namespace utility
} // namespace arm_compute
#endif /* __ARM_COMPUTE_MISC_UTILITY_H__ */