aboutsummaryrefslogtreecommitdiff
path: root/tests/validation/CPP
diff options
context:
space:
mode:
authorDaniil Efremov <daniil.efremov@xored.com>2017-11-14 21:25:34 +0700
committerAnthony Barbier <anthony.barbier@arm.com>2018-11-02 16:35:24 +0000
commit7a49c7993a8b2c670f7caa90e3fbe8a5f1c03078 (patch)
treee043cff3fe7d9f9d014ecc5c2c2348d03f9dcaa4 /tests/validation/CPP
parent50fbc6f0a1e781d4f9f83d1e4ea2588390facea2 (diff)
downloadComputeLibrary-7a49c7993a8b2c670f7caa90e3fbe8a5f1c03078.tar.gz
COMPMID-661: issue# 23 Scale border fix (#26)
Changes in CL and reference in terms of border handling. Change-Id: I5bed95b1f4c308629d7113455dc8a55d74500bcd Reviewed-on: http://mpd-gerrit.cambridge.arm.com/95742 Reviewed-by: Anthony Barbier <anthony.barbier@arm.com> Tested-by: Kaizen <jeremy.johnson+kaizengerrit@arm.com>
Diffstat (limited to 'tests/validation/CPP')
-rw-r--r--tests/validation/CPP/Scale.cpp32
-rw-r--r--tests/validation/CPP/Utils.h15
2 files changed, 26 insertions, 21 deletions
diff --git a/tests/validation/CPP/Scale.cpp b/tests/validation/CPP/Scale.cpp
index 74489aaa96..0da7497277 100644
--- a/tests/validation/CPP/Scale.cpp
+++ b/tests/validation/CPP/Scale.cpp
@@ -50,6 +50,9 @@ SimpleTensor<T> scale(const SimpleTensor<T> &in, float scale_x, float scale_y, I
const auto width = static_cast<int>(in.shape().x());
const auto height = static_cast<int>(in.shape().y());
+ // Determine border size
+ const int border_size = (border_mode == BorderMode::UNDEFINED) ? 0 : 1;
+
// Area interpolation behaves as Nearest Neighbour in case of up-sampling
if(policy == InterpolationPolicy::AREA && wr <= 1.f && hr <= 1.f)
{
@@ -75,30 +78,17 @@ SimpleTensor<T> scale(const SimpleTensor<T> &in, float scale_x, float scale_y, I
id.set(1, y_src);
// If coordinates in range of tensor's width or height
- if(x_src >= -1 || y_src >= -1 || x_src <= width || y_src <= height)
+ if(is_valid_pixel_index(x_src, y_src, width, height, border_size))
{
out[element_idx] = tensor_elem_at(in, id, border_mode, constant_border_value);
}
- else
- {
- if(border_mode == BorderMode::CONSTANT)
- {
- out[element_idx] = constant_border_value;
- }
- else if(border_mode == BorderMode::REPLICATE)
- {
- id.set(0, clamp(static_cast<int>(x_src), 0, width - 1));
- id.set(1, clamp(static_cast<int>(y_src), 0, height - 1));
- out[element_idx] = in[coord2index(in.shape(), id)];
- }
- }
break;
}
case InterpolationPolicy::BILINEAR:
{
id.set(0, std::floor(x_src));
id.set(1, std::floor(y_src));
- if(x_src >= -1 || y_src >= -1 || x_src <= width || y_src <= height)
+ if(is_valid_pixel_index(x_src, y_src, width, height, border_size))
{
out[element_idx] = bilinear_policy(in, id, x_src, y_src, border_mode, constant_border_value);
}
@@ -127,14 +117,14 @@ SimpleTensor<T> scale(const SimpleTensor<T> &in, float scale_x, float scale_y, I
const int yi = std::floor(y_src);
// Clamp position to borders
- x_src = std::max(-1.f, std::min(x_src, static_cast<float>(width)));
- y_src = std::max(-1.f, std::min(y_src, static_cast<float>(height)));
+ x_src = std::max(-static_cast<float>(border_size), std::min(x_src, static_cast<float>(width - 1 + border_size)));
+ y_src = std::max(-static_cast<float>(border_size), std::min(y_src, static_cast<float>(height - 1 + border_size)));
// Clamp bounding box offsets to borders
- x_from = ((x_src + x_from) < -1) ? -1 : x_from;
- y_from = ((y_src + y_from) < -1) ? -1 : y_from;
- x_to = ((x_src + x_to) > width) ? (width - x_src) : x_to;
- y_to = ((y_src + y_to) > height) ? (height - y_src) : y_to;
+ x_from = ((x_src + x_from) < -border_size) ? -border_size : x_from;
+ y_from = ((y_src + y_from) < -border_size) ? -border_size : y_from;
+ x_to = ((x_src + x_to) >= (width + border_size)) ? (width - 1 + border_size) : x_to;
+ y_to = ((y_src + y_to) >= (height + border_size)) ? (height - 1 + border_size) : y_to;
ARM_COMPUTE_ERROR_ON((x_to - x_from + 1) == 0 || (y_to - y_from + 1) == 0);
float sum = 0;
diff --git a/tests/validation/CPP/Utils.h b/tests/validation/CPP/Utils.h
index 0733411462..2aa77c6ff7 100644
--- a/tests/validation/CPP/Utils.h
+++ b/tests/validation/CPP/Utils.h
@@ -41,6 +41,21 @@ namespace test
{
namespace validation
{
+/** Checks if a pixel has valid coordinates
+ *
+ * @param x X coordinate
+ * @param y Y coordinate
+ * @param width Width of the image
+ * @param height Height of the image
+ * @param border_size Border size
+ *
+ * @return True if pixel is valid else false
+ */
+inline bool is_valid_pixel_index(int x, int y, int width, int height, int border_size)
+{
+ return ((x >= -border_size) && (y >= -border_size) && (x < (width + border_size)) && (y < height + border_size));
+}
+
// Return a tensor element at a specified coordinate with different border modes
template <typename T>
T tensor_elem_at(const SimpleTensor<T> &src, Coordinates coord, BorderMode border_mode, T constant_border_value)