From 1fab09f36bdd1e5473bb019cf9639f4a92b4daa1 Mon Sep 17 00:00:00 2001 From: Isabella Gottardi Date: Thu, 13 Jul 2017 15:55:57 +0100 Subject: COMPMID-424 Implemented reference implementation, new output valid region and validation tests (NEON and CL) for Scale Change-Id: I056fa3588b807a97cacf0b8afaec56e37ffc92af Reviewed-on: http://mpd-gerrit.cambridge.arm.com/83872 Tested-by: Kaizen Reviewed-by: Anthony Barbier --- arm_compute/core/Helpers.h | 11 +++++++++++ arm_compute/core/Helpers.inl | 26 ++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) (limited to 'arm_compute') diff --git a/arm_compute/core/Helpers.h b/arm_compute/core/Helpers.h index dfcca96eec..f3702e7c93 100644 --- a/arm_compute/core/Helpers.h +++ b/arm_compute/core/Helpers.h @@ -461,6 +461,17 @@ bool set_data_type_if_unknown(ITensorInfo &info, DataType data_type); * @return True if the fixed point position has been changed. */ bool set_fixed_point_position_if_zero(ITensorInfo &info, int fixed_point_position); +/** Helper function to calculate the Valid Region for Scale. + * + * @param[in] src_info Input tensor info used to check. + * @param[in] dst_shape Shape of the output. + * @param[in] policy Interpolation policy. + * @param[in] border_size Size of the border. + * @param[in] border_undefined True if the border is undefined. + * + * @return The corrispondent valid region + */ +ValidRegion calculate_valid_region_scale(const ITensorInfo &src_info, const TensorShape &dst_shape, InterpolationPolicy policy, BorderSize border_size, bool border_undefined); } // namespace arm_compute #include "arm_compute/core/Helpers.inl" diff --git a/arm_compute/core/Helpers.inl b/arm_compute/core/Helpers.inl index 78e0c70e1b..90a4618fcc 100644 --- a/arm_compute/core/Helpers.inl +++ b/arm_compute/core/Helpers.inl @@ -303,4 +303,30 @@ inline bool set_fixed_point_position_if_zero(ITensorInfo &info, int fixed_point_ return false; } + +inline ValidRegion calculate_valid_region_scale(const ITensorInfo &src_info, const TensorShape &dst_shape, InterpolationPolicy policy, BorderSize border_size, bool border_undefined) +{ + const auto wr = static_cast(dst_shape[0]) / static_cast(src_info.tensor_shape()[0]); + const auto hr = static_cast(dst_shape[1]) / static_cast(src_info.tensor_shape()[1]); + Coordinates anchor; + anchor.set_num_dimensions(src_info.tensor_shape().num_dimensions()); + TensorShape new_dst_shape(dst_shape); + anchor.set(0, (policy == InterpolationPolicy::BILINEAR && border_undefined) ? ((static_cast(src_info.valid_region().anchor[0]) + border_size.left + 0.5f) * wr - 0.5f) : + ((static_cast(src_info.valid_region().anchor[0]) + 0.5f) * wr - 0.5f)); + anchor.set(1, (policy == InterpolationPolicy::BILINEAR && border_undefined) ? ((static_cast(src_info.valid_region().anchor[1]) + border_size.top + 0.5f) * hr - 0.5f) : + ((static_cast(src_info.valid_region().anchor[1]) + 0.5f) * hr - 0.5f)); + float shape_out_x = (policy == InterpolationPolicy::BILINEAR + && border_undefined) ? + ((static_cast(src_info.valid_region().anchor[0]) + static_cast(src_info.valid_region().shape[0]) - 1) - 1 + 0.5f) * wr - 0.5f : + ((static_cast(src_info.valid_region().anchor[0]) + static_cast(src_info.valid_region().shape[0])) + 0.5f) * wr - 0.5f; + float shape_out_y = (policy == InterpolationPolicy::BILINEAR + && border_undefined) ? + ((static_cast(src_info.valid_region().anchor[1]) + static_cast(src_info.valid_region().shape[1]) - 1) - 1 + 0.5f) * hr - 0.5f : + ((static_cast(src_info.valid_region().anchor[1]) + static_cast(src_info.valid_region().shape[1])) + 0.5f) * hr - 0.5f; + + new_dst_shape.set(0, shape_out_x - anchor[0]); + new_dst_shape.set(1, shape_out_y - anchor[1]); + + return ValidRegion(std::move(anchor), std::move(new_dst_shape)); +} } // namespace arm_compute -- cgit v1.2.1