40 void precompute_dx_dy_offsets(ITensor *dx, ITensor *dy, ITensor *offsets,
float wr,
float hr,
SamplingPolicy sampling_policy,
bool align_corners)
43 float sampling_offset = 0.0f;
46 sampling_offset = 0.5f;
50 win.set(
Window::DimX, Window::Dimension(0, offsets->info()->dimension(0), 1));
51 win.set(
Window::DimY, Window::Dimension(0, offsets->info()->dimension(1), 1));
53 if(dx !=
nullptr && dy !=
nullptr)
56 Iterator offsets_it(offsets, win);
57 Iterator dx_it(dx, win);
58 Iterator dy_it(dy, win);
62 const float in_x = (
id.x() + sampling_offset) * wr - sampling_offset;
63 const float in_y = (
id.y() + sampling_offset) * hr - sampling_offset;
64 const int in_xi = std::floor(in_x);
65 const int in_yi = std::floor(in_y);
67 *
reinterpret_cast<int32_t *
>(offsets_it.ptr()) = in_xi;
68 *
reinterpret_cast<float *
>(dx_it.ptr()) = in_x - in_xi;
69 *
reinterpret_cast<float *
>(dy_it.ptr()) = in_y - in_yi;
71 offsets_it, dx_it, dy_it);
76 Iterator offsets_it(offsets, win);
80 const float float_in_xi = (
id.x() + sampling_offset) * wr;
82 *
reinterpret_cast<int32_t *
>(offsets_it.ptr()) = in_xi;
120 auto dx = std::make_unique<TensorInfo>(tensor_info_dxdy);
121 auto dy = std::make_unique<TensorInfo>(tensor_info_dxdy);
122 auto offsets = std::make_unique<TensorInfo>(tensor_info_offsets);
123 auto scale_kernel = std::make_unique<kernels::CpuScaleKernel>();
124 switch(policy_to_use)
128 scale_kernel->configure(src,
nullptr,
nullptr, offsets.get(),
dst,
info);
133 scale_kernel->configure(src, dx.get(), dy.get(), offsets.get(),
dst,
info);
138 scale_kernel->configure(src,
nullptr,
nullptr,
nullptr, dst, info);
144 _kernel = std::move(scale_kernel);
174 switch(policy_to_use)
177 offsets = &tensor_info_offsets;
180 offsets = &tensor_info_offsets;
181 dx = &tensor_info_dx;
182 dy = &tensor_info_dy;
219 switch(policy_to_use)
224 precompute_dx_dy_offsets(
nullptr,
nullptr, offsets, wr, hr, sampling_policy, is_align_corners_used);
230 precompute_dx_dy_offsets(dx, dy, offsets, wr, hr, sampling_policy, is_align_corners_used);
InterpolationPolicy
Interpolation method.
InterpolationPolicy interpolation_policy
Interpolation type to use.
virtual size_t dimension(size_t index) const =0
Return the size of the requested dimension.
bool empty() const
Checks if pack is empty.
#define ARM_COMPUTE_ERROR(msg)
Print the given message then throw an std::runtime_error.
void run(ITensorPack &tensors) override
Run the kernels contained in the function.
#define ARM_COMPUTE_RETURN_ON_ERROR(status)
Checks if a status contains an error and returns it.
virtual void schedule_op(ICPPKernel *kernel, const Hints &hints, const Window &window, ITensorPack &tensors)=0
Runs the kernel in the same thread as the caller synchronously.
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)
void prepare(ITensorPack &tensors) override
Prepare the function for executing.
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.
SimpleTensor< float > src
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.
#define ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(...)
1 channel, 1 S32 per channel
static Status validate(const ITensorInfo *src, const ITensorInfo *dst, const ScaleKernelInfo &info)
Static function to check if given info will lead to a valid configuration.
const ITensor * get_const_tensor(int id) const
Get constant tensor of a given id.
static constexpr size_t DimX
Alias for dimension 0 also known as X dimension.
SamplingPolicy sampling_policy
Sampling policy used by the interpolation.
#define ARM_COMPUTE_ERROR_ON_MSG(cond, msg)
virtual std::unique_ptr< T > clone() const =0
Provide a clone of the current object of class T.
Samples are taken at pixel top left corner.
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)
ITensor * get_tensor(int id)
Get tensor of a given id from the pac.
static Status validate(const ITensorInfo *src, const ITensorInfo *dx, const ITensorInfo *dy, const ITensorInfo *offsets, ITensorInfo *dst, const ScaleKernelInfo &info)
Static function to check if given info will lead to a valid configuration.
void configure(ITensorInfo *src, ITensorInfo *dst, const ScaleKernelInfo &info)
Initialize the function's source, destination, interpolation type and border_mode.
#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.
static IScheduler & get()
Access the scheduler singleton.