aboutsummaryrefslogtreecommitdiff
path: root/tests/Utils.h
diff options
context:
space:
mode:
authorDiego Lopez Recas <Diego.LopezRecas@arm.com>2017-12-18 11:28:27 +0000
committerAnthony Barbier <anthony.barbier@arm.com>2018-11-02 16:43:10 +0000
commitbcbc970f1f5b47f7314a5ad078820bc8a5edca94 (patch)
tree6bca70896b993adc80aea5e652d9e8dcefff3d8d /tests/Utils.h
parent1bfc7849950b67aeee382b08f27fd0b1b5ef0587 (diff)
downloadComputeLibrary-bcbc970f1f5b47f7314a5ad078820bc8a5edca94.tar.gz
IVGCVSW-863 calculate_max_window..() family takes ValidRegion
Change-Id: I91e39713ffa580e9d2213988ad3517a8a41bf4e8 Reviewed-on: https://eu-gerrit-1.euhpc.arm.com/114013 Tested-by: Jenkins <bsgcomp@arm.com> Reviewed-by: Anthony Barbier <anthony.barbier@arm.com>
Diffstat (limited to 'tests/Utils.h')
-rw-r--r--tests/Utils.h52
1 files changed, 28 insertions, 24 deletions
diff --git a/tests/Utils.h b/tests/Utils.h
index 5814965a40..750d907778 100644
--- a/tests/Utils.h
+++ b/tests/Utils.h
@@ -202,17 +202,19 @@ inline I foldl(F &&func, I &&initial, T &&value, Vs &&... values)
/** Create a valid region based on tensor shape, border mode and border size
*
- * @param[in] shape Shape used as size of the valid region.
+ * @param[in] a_shape Shape used as size of the valid region.
* @param[in] border_undefined (Optional) Boolean indicating if the border mode is undefined.
* @param[in] border_size (Optional) Border size used to specify the region to exclude.
*
* @return A valid region starting at (0, 0, ...) with size of @p shape if @p border_undefined is false; otherwise
* return A valid region starting at (@p border_size.left, @p border_size.top, ...) with reduced size of @p shape.
*/
-inline ValidRegion shape_to_valid_region(TensorShape shape, bool border_undefined = false, BorderSize border_size = BorderSize(0))
+inline ValidRegion shape_to_valid_region(const TensorShape &a_shape, bool border_undefined = false, BorderSize border_size = BorderSize(0))
{
- Coordinates anchor;
- anchor.set_num_dimensions(shape.num_dimensions());
+ ValidRegion valid_region{ Coordinates(), a_shape };
+
+ Coordinates &anchor = valid_region.anchor;
+ TensorShape &shape = valid_region.shape;
if(border_undefined)
{
@@ -228,43 +230,45 @@ inline ValidRegion shape_to_valid_region(TensorShape shape, bool border_undefine
shape.set(1, valid_shape_y);
}
- return ValidRegion(std::move(anchor), std::move(shape));
+ return valid_region;
}
/** Create a valid region for Gaussian Pyramid Half based on tensor shape and valid region at level "i - 1" and border mode
*
* @note The border size is 2 in case of Gaussian Pyramid Half
*
- * @param[in] shape Shape used at level "i - 1" of Gaussian Pyramid Half
- * @param[in] valid_region Valid region used at level "i - 1" of Gaussian Pyramid Half
+ * @param[in] a_shape Shape used at level "i - 1" of Gaussian Pyramid Half
+ * @param[in] a_valid_region Valid region used at level "i - 1" of Gaussian Pyramid Half
* @param[in] border_undefined (Optional) Boolean indicating if the border mode is undefined.
*
* return The valid region for the level "i" of Gaussian Pyramid Half
*/
-inline ValidRegion shape_to_valid_region_gaussian_pyramid_half(TensorShape shape, ValidRegion valid_region, bool border_undefined = false)
+inline ValidRegion shape_to_valid_region_gaussian_pyramid_half(const TensorShape &a_shape, const ValidRegion &a_valid_region, bool border_undefined = false)
{
constexpr int border_size = 2;
- Coordinates anchor;
- anchor.set_num_dimensions(shape.num_dimensions());
+
+ ValidRegion valid_region{ Coordinates(), a_shape };
+
+ Coordinates &anchor = valid_region.anchor;
+ TensorShape &shape = valid_region.shape;
// Compute tensor shape for level "i" of Gaussian Pyramid Half
// dst_width = (src_width + 1) * 0.5f
// dst_height = (src_height + 1) * 0.5f
- TensorShape dst_shape = shape;
- dst_shape.set(0, (shape[0] + 1) * 0.5f);
- dst_shape.set(1, (shape[1] + 1) * 0.5f);
+ shape.set(0, (shape[0] + 1) * 0.5f);
+ shape.set(1, (shape[1] + 1) * 0.5f);
if(border_undefined)
{
ARM_COMPUTE_ERROR_ON(shape.num_dimensions() < 2);
// Compute the left and top invalid borders
- float invalid_border_left = static_cast<float>(valid_region.anchor.x() + border_size) / 2.0f;
- float invalid_border_top = static_cast<float>(valid_region.anchor.y() + border_size) / 2.0f;
+ float invalid_border_left = static_cast<float>(a_valid_region.anchor.x() + border_size) / 2.0f;
+ float invalid_border_top = static_cast<float>(a_valid_region.anchor.y() + border_size) / 2.0f;
// For the new anchor point we can have 2 cases:
- // 1) If the width/height of the tensor shape is odd, we have to take the ceil value of (valid_region.anchor.x() + border_size) / 2.0f or (valid_region.anchor.y() + border_size / 2.0f
- // 2) If the width/height of the tensor shape is even, we have to take the floor value of (valid_region.anchor.x() + border_size) / 2.0f or (valid_region.anchor.y() + border_size) / 2.0f
+ // 1) If the width/height of the tensor shape is odd, we have to take the ceil value of (a_valid_region.anchor.x() + border_size) / 2.0f or (a_valid_region.anchor.y() + border_size / 2.0f
+ // 2) If the width/height of the tensor shape is even, we have to take the floor value of (a_valid_region.anchor.x() + border_size) / 2.0f or (a_valid_region.anchor.y() + border_size) / 2.0f
// In this manner we should be able to propagate correctly the valid region along all levels of the pyramid
invalid_border_left = (shape[0] % 2) ? std::ceil(invalid_border_left) : std::floor(invalid_border_left);
invalid_border_top = (shape[1] % 2) ? std::ceil(invalid_border_top) : std::floor(invalid_border_top);
@@ -275,21 +279,21 @@ inline ValidRegion shape_to_valid_region_gaussian_pyramid_half(TensorShape shape
// Compute shape
// Calculate the right and bottom invalid borders at the previous level of the pyramid
- const float prev_invalid_border_right = static_cast<float>(shape[0] - (valid_region.anchor.x() + valid_region.shape[0]));
- const float prev_invalid_border_bottom = static_cast<float>(shape[1] - (valid_region.anchor.y() + valid_region.shape[1]));
+ const float prev_invalid_border_right = static_cast<float>(shape[0] - (a_valid_region.anchor.x() + a_valid_region.shape[0]));
+ const float prev_invalid_border_bottom = static_cast<float>(shape[1] - (a_valid_region.anchor.y() + a_valid_region.shape[1]));
// Calculate the right and bottom invalid borders at the current level of the pyramid
const float invalid_border_right = std::ceil((prev_invalid_border_right + static_cast<float>(border_size)) / 2.0f);
const float invalid_border_bottom = std::ceil((prev_invalid_border_bottom + static_cast<float>(border_size)) / 2.0f);
- const int valid_shape_x = std::max(0, static_cast<int>(dst_shape.x()) - static_cast<int>(invalid_border_left) - static_cast<int>(invalid_border_right));
- const int valid_shape_y = std::max(0, static_cast<int>(dst_shape.y()) - static_cast<int>(invalid_border_top) - static_cast<int>(invalid_border_bottom));
+ const int valid_shape_x = std::max(0, static_cast<int>(shape.x()) - static_cast<int>(invalid_border_left) - static_cast<int>(invalid_border_right));
+ const int valid_shape_y = std::max(0, static_cast<int>(shape.y()) - static_cast<int>(invalid_border_top) - static_cast<int>(invalid_border_bottom));
- dst_shape.set(0, valid_shape_x);
- dst_shape.set(1, valid_shape_y);
+ shape.set(0, valid_shape_x);
+ shape.set(1, valid_shape_y);
}
- return ValidRegion(std::move(anchor), std::move(dst_shape));
+ return valid_region;
}
/** Write the value after casting the pointer according to @p data_type.