44 const size_t round_value = ceil_policy_scale ? 1
U : 0
U;
46 shape_scaled.
set(0, (in.
shape()[0] + round_value) * scale_x);
47 shape_scaled.
set(1, (in.
shape()[1] + round_value) * scale_y);
51 const auto wr =
static_cast<float>(in.
shape()[0]) / static_cast<float>(out.shape()[0]);
52 const auto hr =
static_cast<float>(in.
shape()[1]) / static_cast<float>(out.shape()[1]);
54 const auto width =
static_cast<int>(in.
shape().x());
55 const auto height =
static_cast<int>(in.
shape().y());
66 for(
int element_idx = 0, count = 0; element_idx < out.num_elements(); ++element_idx, ++count)
74 switch(sampling_policy)
81 x_src = (idx + 0.5f) * wr - 0.5f;
82 y_src = (idy + 0.5f) * hr - 0.5f;
94 x_src = (idx + 0.5f) * wr;
95 y_src = (idy + 0.5f) * hr;
102 out[element_idx] =
tensor_elem_at(in,
id, border_mode, constant_border_value);
108 id.set(0, std::floor(x_src));
109 id.set(1, std::floor(y_src));
112 out[element_idx] =
bilinear_policy(in,
id, x_src, y_src, border_mode, constant_border_value);
118 out[element_idx] = constant_border_value;
122 id.set(0, utility::clamp<int>(x_src, 0, width - 1));
123 id.set(1, utility::clamp<int>(y_src, 0, height - 1));
131 int x_from = std::floor(idx * wr - 0.5f - x_src);
132 int y_from = std::floor(idy * hr - 0.5f - y_src);
133 int x_to = std::ceil((idx + 1) * wr - 0.5f - x_src);
134 int y_to = std::ceil((idy + 1) * hr - 0.5f - y_src);
135 const int xi = std::floor(x_src);
136 const int yi = std::floor(y_src);
139 x_src =
std::max(-static_cast<float>(border_size),
std::min(x_src, static_cast<float>(width - 1 + border_size)));
140 y_src =
std::max(-static_cast<float>(border_size),
std::min(y_src, static_cast<float>(height - 1 + border_size)));
143 x_from = ((x_src + x_from) < -border_size) ? -border_size : x_from;
144 y_from = ((y_src + y_from) < -border_size) ? -border_size : y_from;
145 x_to = ((x_src + x_to) >= (width + border_size)) ? (width - 1 + border_size) : x_to;
146 y_to = ((y_src + y_to) >= (height + border_size)) ? (height - 1 + border_size) : y_to;
150 for(
int j = yi + y_from, je = yi + y_to; j <= je; ++j)
152 for(
int i = xi + x_from, ie = xi + x_to; i <= ie; ++i)
154 id.set(0, static_cast<int>(i));
155 id.set(1, static_cast<int>(j));
156 sum +=
tensor_elem_at(in,
id, border_mode, constant_border_value);
159 out[element_idx] = sum / ((x_to - x_from + 1) * (y_to - y_from + 1));
BorderMode
Methods available to handle borders.
#define ARM_COMPUTE_ERROR(...)
Print the given message then throw an std::runtime_error.
InterpolationPolicy
Interpolation method.
T tensor_elem_at(const SimpleTensor< T > &src, Coordinates coord, BorderMode border_mode, T constant_border_value)
fixed_point< T > min(fixed_point< T > x, fixed_point< T > y)
DATA_TYPE sum(__global const DATA_TYPE *input)
Calculate sum of a vector.
half_float::half half
16-bit floating point type
DataType data_type() const override
Data type of the tensor.
Output values are defined by bilinear interpolation between the pixels.
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
TensorShape shape() const override
Shape of the tensor.
Output values are defined to match the source pixel whose center is nearest to the sample position...
bool is_valid_pixel_index(int x, int y, int width, int height, int border_size)
Checks if a pixel has valid coordinates.
This file contains all available output stages for GEMMLowp on OpenCL.
int coord2index(const TensorShape &shape, const Coordinates &coord)
Linearise the given coordinate.
Samples are taken at pixel center.
T x() const
Alias to access the size of the first dimension.
T bilinear_policy(const SimpleTensor< T > &in, Coordinates id, float xn, float yn, BorderMode border_mode, T constant_border_value)
Samples are taken at pixel top left corner.
Coordinates index2coord(const TensorShape &shape, int index)
Convert a linear index into n-dimensional coordinates.
Output values are determined by averaging the source pixels whose areas fall under the area of the de...
SimpleTensor< T > scale(const SimpleTensor< T > &in, float scale_x, float scale_y, InterpolationPolicy policy, BorderMode border_mode, T constant_border_value, SamplingPolicy sampling_policy, bool ceil_policy_scale)
Simple tensor object that stores elements in a consecutive chunk of memory.
Borders are left undefined.
Pixels outside the image are assumed to have the same value as the closest image pixel.
Pixels outside the image are assumed to have a constant value.
TensorShape & set(size_t dimension, size_t value, bool apply_dim_correction=true)
Accessor to set the value of one of the dimensions.
fixed_point< T > max(fixed_point< T > x, fixed_point< T > y)
convolution configure & src
SamplingPolicy
Available Sampling Policies.