diff options
Diffstat (limited to 'tests/validation')
-rw-r--r-- | tests/validation/CL/Scale.cpp | 8 | ||||
-rw-r--r-- | tests/validation/CPP/Scale.cpp | 32 | ||||
-rw-r--r-- | tests/validation/CPP/Utils.h | 15 |
3 files changed, 31 insertions, 24 deletions
diff --git a/tests/validation/CL/Scale.cpp b/tests/validation/CL/Scale.cpp index f43f2aeeb9..1ddf03a74c 100644 --- a/tests/validation/CL/Scale.cpp +++ b/tests/validation/CL/Scale.cpp @@ -92,16 +92,18 @@ DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(combine(combi CLScale clscale; clscale.configure(&src, &dst, policy, border_mode, constant_border_value); - // Validate valid region - const ValidRegion dst_valid_region = calculate_valid_region_scale(*(src.info()), shape_scaled, policy, BorderSize(1), (border_mode == BorderMode::UNDEFINED)); + // Get border size depending on border mode + const BorderSize border_size(border_mode == BorderMode::UNDEFINED ? 0 : 1); + // Validate valid region + const ValidRegion dst_valid_region = calculate_valid_region_scale(*(src.info()), shape_scaled, policy, border_size, (border_mode == BorderMode::UNDEFINED)); validate(dst.info()->valid_region(), dst_valid_region); // Validate padding PaddingCalculator calculator(shape_scaled.x(), 4); calculator.set_border_mode(border_mode); - const PaddingSize read_padding(1); + const PaddingSize read_padding(border_size); const PaddingSize write_padding = calculator.required_padding(PaddingCalculator::Option::EXCLUDE_BORDER); validate(src.info()->padding(), read_padding); validate(dst.info()->padding(), write_padding); 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) |