49 void precompute_dx_dy_offsets(ITensor *dx, ITensor *dy, ITensor *offsets,
float wr,
float hr,
SamplingPolicy sampling_policy,
bool align_corners)
53 float sampling_offset = 0.0f;
56 sampling_offset = 0.5f;
60 win.set(
Window::DimX, Window::Dimension(0, offsets->info()->dimension(0), 1));
61 win.set(
Window::DimY, Window::Dimension(0, offsets->info()->dimension(1), 1));
63 if(dx !=
nullptr && dy !=
nullptr)
66 Iterator offsets_it(offsets, win);
67 Iterator dx_it(dx, win);
68 Iterator dy_it(dy, win);
72 const float in_x = (
id.x() + sampling_offset) * wr - sampling_offset;
73 const float in_y = (
id.y() + sampling_offset) * hr - sampling_offset;
74 const int in_xi = std::floor(in_x);
75 const int in_yi = std::floor(in_y);
77 *
reinterpret_cast<int32_t *
>(offsets_it.ptr()) = in_xi;
78 *
reinterpret_cast<float *
>(dx_it.ptr()) = in_x - in_xi;
79 *
reinterpret_cast<float *
>(dy_it.ptr()) = in_y - in_yi;
81 offsets_it, dx_it, dy_it);
86 Iterator offsets_it(offsets, win);
90 const float float_in_xi = (
id.x() + sampling_offset) * wr;
92 *
reinterpret_cast<int32_t *
>(offsets_it.ptr()) = in_xi;
100 : _offsets(), _dx(), _dy()
127 auto scale_kernel = std::make_unique<NEScaleKernel>();
128 switch(policy_to_use)
135 scale_kernel->configure(input,
nullptr,
nullptr, &_offsets, output, info);
141 precompute_dx_dy_offsets(
nullptr,
nullptr, &_offsets, wr, hr, info.
sampling_policy, is_align_corners_used);
153 scale_kernel->configure(input, &_dx, &_dy, &_offsets, output, info);
161 precompute_dx_dy_offsets(&_dx, &_dy, &_offsets, wr, hr, info.
sampling_policy, is_align_corners_used);
166 scale_kernel->configure(input,
nullptr,
nullptr,
nullptr, output, info);
172 _kernel = std::move(scale_kernel);
199 offsets = &tensor_info_offsets;
202 offsets = &tensor_info_offsets;
203 dx = &tensor_info_dx;
204 dy = &tensor_info_dy;
InterpolationPolicy interpolation_policy
Interpolation type to use.
void init(const TensorAllocator &allocator, const Coordinates &coords, TensorInfo &sub_info)
Shares the same backing memory with another tensor allocator, while the tensor info might be differen...
virtual size_t dimension(size_t index) const =0
Return the size of the requested dimension.
#define ARM_COMPUTE_ERROR(msg)
Print the given message then throw an std::runtime_error.
#define ARM_COMPUTE_RETURN_ON_ERROR(status)
Checks if a status contains an error and returns it.
1 channel, 1 F32 per channel
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.
const DataLayout data_layout
bool align_corners
Align corners of input and output.
Store the tensor's metadata.
#define ARM_COMPUTE_ERROR_THROW_ON(status)
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...
#define ARM_COMPUTE_RETURN_ERROR_ON(cond)
If the condition is true, an error is returned.
Interface for Neon tensor.
Copyright (c) 2017-2021 Arm Limited.
Samples are taken at pixel center.
bool is_align_corners_allowed_sampling_policy(SamplingPolicy sampling_policy)
Returns if aligned corners are allowed for the given sampling policy.
TensorAllocator * allocator()
Return a pointer to the tensor's allocator.
#define ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(...)
1 channel, 1 S32 per channel
static Status validate(const ITensorInfo *input, const ITensorInfo *dx, const ITensorInfo *dy, const ITensorInfo *offsets, ITensorInfo *output, const ScaleKernelInfo &info)
Static function to check if given info will lead to a valid configuration of NEScaleKernel.
static Status validate(const ITensorInfo *input, const ITensorInfo *output, const ScaleKernelInfo &info)
Static function to check if given info will lead to a valid configuration of NEScale.
static constexpr size_t DimX
Alias for dimension 0 also known as X dimension.
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
SamplingPolicy sampling_policy
Sampling policy used by the interpolation.
void allocate() override
Allocate size specified by TensorInfo of CPU memory.
virtual std::unique_ptr< T > clone() const =0
Provide a clone of the current object of class T.
virtual ITensorInfo * info() const =0
Interface to be implemented by the child class to return the tensor's metadata.
Samples are taken at pixel top left corner.
void configure(ITensor *input, ITensor *output, const ScaleKernelInfo &info)
Initialize the function's source, destination, interpolation type and border_mode.
Output values are determined by averaging the source pixels whose areas fall under the area of the de...
static constexpr size_t DimY
Alias for dimension 1 also known as Y dimension.
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Store the tensor's metadata.
void execute_window_loop(const Window &w, L &&lambda_function, Ts &&... iterators)
Iterate through the passed window, automatically adjusting the iterators and calling the lambda_funct...
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.
size_t get_data_layout_dimension_index(const DataLayout data_layout, const DataLayoutDimension data_layout_dimension)
Get the index of the given dimension.
DataLayout data_layout
Data layout to use.
DataLayout
[DataLayout enum definition]
SamplingPolicy
Available Sampling Policies.
virtual DataLayout data_layout() const =0
Get the data layout of the tensor.