aboutsummaryrefslogtreecommitdiff
path: root/arm_compute
diff options
context:
space:
mode:
Diffstat (limited to 'arm_compute')
-rw-r--r--arm_compute/core/Utils.h14
-rw-r--r--arm_compute/core/utils/misc/ShapeCalculator.h30
2 files changed, 30 insertions, 14 deletions
diff --git a/arm_compute/core/Utils.h b/arm_compute/core/Utils.h
index d5c365e6ab..af9a777a0c 100644
--- a/arm_compute/core/Utils.h
+++ b/arm_compute/core/Utils.h
@@ -779,6 +779,20 @@ std::pair<unsigned int, unsigned int> scaled_dimensions(int width, int height,
const PadStrideInfo &pad_stride_info,
const Size2D &dilation = Size2D(1U, 1U));
+/** Returns calculated width and height of output scaled tensor depending on dimensions rounding mode.
+ *
+ * @param[in] width Width of input tensor (Number of columns)
+ * @param[in] height Height of input tensor (Number of rows)
+ * @param[in] kernel_width Kernel width.
+ * @param[in] kernel_height Kernel height.
+ * @param[in] pad_stride_info Pad and stride information.
+ *
+ * @return A pair with the new width in the first position and the new height in the second, returned values can be < 1
+ */
+std::pair<int, int> scaled_dimensions_signed(int width, int height,
+ int kernel_width, int kernel_height,
+ const PadStrideInfo &pad_stride_info);
+
/** Check if the given reduction operation should be handled in a serial way.
*
* @param[in] op Reduction operation to perform
diff --git a/arm_compute/core/utils/misc/ShapeCalculator.h b/arm_compute/core/utils/misc/ShapeCalculator.h
index 8e49c068af..d0dc202f91 100644
--- a/arm_compute/core/utils/misc/ShapeCalculator.h
+++ b/arm_compute/core/utils/misc/ShapeCalculator.h
@@ -759,25 +759,27 @@ inline TensorShape compute_min_max_shape(const ITensorInfo *input)
*/
inline TensorShape compute_pool_shape(const ITensorInfo &input, PoolingLayerInfo pool_info)
{
- unsigned int pooled_w = 0;
- unsigned int pooled_h = 0;
+ int pooled_w = 0;
+ int pooled_h = 0;
TensorShape output_shape{ input.tensor_shape() };
- const bool is_global_pooling = pool_info.is_global_pooling;
- const unsigned int idx_width = get_data_layout_dimension_index(input.data_layout(), DataLayoutDimension::WIDTH);
- const unsigned int idx_height = get_data_layout_dimension_index(input.data_layout(), DataLayoutDimension::HEIGHT);
- const unsigned int pool_size_x = is_global_pooling ? output_shape[idx_width] : pool_info.pool_size.width;
- const unsigned int pool_size_y = is_global_pooling ? output_shape[idx_height] : pool_info.pool_size.height;
+ const bool is_global_pooling = pool_info.is_global_pooling;
+ const int idx_width = get_data_layout_dimension_index(input.data_layout(), DataLayoutDimension::WIDTH);
+ const int idx_height = get_data_layout_dimension_index(input.data_layout(), DataLayoutDimension::HEIGHT);
+ const int input_width = input.tensor_shape()[idx_width];
+ const int input_height = input.tensor_shape()[idx_height];
+ const int pool_size_x = is_global_pooling ? output_shape[idx_width] : pool_info.pool_size.width;
+ const int pool_size_y = is_global_pooling ? output_shape[idx_height] : pool_info.pool_size.height;
- std::tie(pooled_w, pooled_h) = scaled_dimensions(output_shape[idx_width],
- output_shape[idx_height],
- pool_size_x,
- pool_size_y,
- pool_info.pad_stride_info);
+ std::tie(pooled_w, pooled_h) = scaled_dimensions_signed(input_width, input_height,
+ pool_size_x, pool_size_y,
+ pool_info.pad_stride_info);
- output_shape.set(idx_width, pooled_w);
- output_shape.set(idx_height, pooled_h);
+ ARM_COMPUTE_ERROR_ON_MSG((pooled_w < 1 || pooled_h < 1), "Calculated output dimension size is invalid");
+
+ output_shape.set(idx_width, static_cast<size_t>(pooled_w));
+ output_shape.set(idx_height, static_cast<size_t>(pooled_h));
return output_shape;
}