45 const size_t round_value = ceil_policy_scale ? 1
U : 0
U;
55 const auto width = static_cast<int>(in.
shape().x());
56 const auto height = static_cast<int>(in.
shape().y());
67 const uint32_t num_elements = out.num_elements();
68 for(uint32_t element_idx = 0, count = 0; element_idx < num_elements; ++element_idx, ++count)
88 x_src = (idx + 0.5f) * wr;
89 y_src = (idy + 0.5f) * hr;
101 out[element_idx] =
tensor_elem_at(in,
id, border_mode, constant_border_value);
114 x_src = (idx + 0.5f) * wr - 0.5f;
115 y_src = (idy + 0.5f) * hr - 0.5f;
121 id.set(0, std::floor(x_src));
122 id.set(1, std::floor(y_src));
125 out[element_idx] =
bilinear_policy(in,
id, x_src, y_src, border_mode, constant_border_value);
131 out[element_idx] = constant_border_value;
135 id.set(0, utility::clamp<int>(x_src, 0, width - 1));
136 id.set(1, utility::clamp<int>(y_src, 0, height - 1));
144 int x_from = std::floor(idx * wr - 0.5f - x_src);
145 int y_from = std::floor(idy * hr - 0.5f - y_src);
146 int x_to = std::ceil((idx + 1) * wr - 0.5f - x_src);
147 int y_to = std::ceil((idy + 1) * hr - 0.5f - y_src);
148 const int xi = std::floor(x_src);
149 const int yi = std::floor(y_src);
152 x_src = std::max(-static_cast<float>(border_size), std::min(x_src, static_cast<float>(width - 1 + border_size)));
153 y_src = std::max(-static_cast<float>(border_size), std::min(y_src, static_cast<float>(height - 1 + border_size)));
156 x_from = ((x_src + x_from) < -border_size) ? -border_size : x_from;
157 y_from = ((y_src + y_from) < -border_size) ? -border_size : y_from;
158 x_to = ((x_src + x_to) >= (width + border_size)) ? (width - 1 + border_size) : x_to;
159 y_to = ((y_src + y_to) >= (height + border_size)) ? (height - 1 + border_size) : y_to;
163 for(
int j = yi + y_from, je = yi + y_to; j <= je; ++j)
165 for(
int i = xi + x_from, ie = xi + x_to; i <= ie; ++i)
167 id.set(0, static_cast<int>(i));
168 id.set(1, static_cast<int>(j));
169 sum +=
tensor_elem_at(in,
id, border_mode, constant_border_value);
172 out[element_idx] = sum / ((x_to - x_from + 1) * (y_to - y_from + 1));
184 template <
typename T>
196 if(
src.quantization_info().uniform().scale != 0.f)
201 dst = convert_to_asymmetric<uint8_t>(dst_tmp,
src.quantization_info());
215 if(
src.quantization_info().uniform().scale != 0.f)
220 dst = convert_to_asymmetric<int8_t>(dst_tmp,
src.quantization_info());
BorderMode
Methods available to handle borders.
InterpolationPolicy
Interpolation method.
T tensor_elem_at(const SimpleTensor< T > &src, Coordinates coord, BorderMode border_mode, T constant_border_value)
float dequantize_qasymm8(uint8_t value, const INFO_TYPE &qinfo)
Dequantize a value given an unsigned 8-bit asymmetric quantization scheme.
TensorShape shape_scaled(shape)
#define ARM_COMPUTE_ERROR(msg)
Print the given message then throw an std::runtime_error.
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.
SimpleTensor< float > convert_from_asymmetric(const SimpleTensor< uint8_t > &src)
TensorShape shape() const override
Shape of the tensor.
T round_half_away_from_zero(T value)
Round floating-point value with half value rounding away from zero.
Output values are defined to match the source pixel whose center is nearest to the sample position.
SimpleTensor< T > scale_core(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, bool align_corners)
bool is_valid_pixel_index(int x, int y, int width, int height, int border_size)
Checks if a pixel has valid coordinates.
SimpleTensor< float > src
Copyright (c) 2017-2021 Arm Limited.
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...
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.
float dequantize_qasymm8_signed(int8_t value, const INFO_TYPE &qinfo)
Dequantize a value given a signed 8-bit asymmetric quantization scheme.
float calculate_resize_ratio(size_t input_size, size_t output_size, bool align_corners=false)
Returns resize ratio between input and output with consideration of aligned corners.
SimpleTensor< T > scale(const SimpleTensor< T > &src, float scale_x, float scale_y, InterpolationPolicy policy, BorderMode border_mode, T constant_border_value, SamplingPolicy sampling_policy, bool ceil_policy_scale, bool align_corners)
TensorShape & set(size_t dimension, size_t value, bool apply_dim_correction=true, bool increase_dim_unit=true)
Accessor to set the value of one of the dimensions.
SamplingPolicy
Available Sampling Policies.