Compute Library
 23.08
arm_compute::scale_utils Namespace Reference

Functions

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. More...
 
bool is_align_corners_allowed_sampling_policy (SamplingPolicy sampling_policy)
 Returns if aligned corners are allowed for the given sampling policy. More...
 
bool is_precomputation_required (DataLayout data_layout, DataType data_type, InterpolationPolicy policy, BorderMode border_mode)
 Returns if precomputation of indices and/or weights is required or/not. More...
 

Function Documentation

◆ calculate_resize_ratio()

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.

Parameters
[in]input_sizeThe input size
[in]output_sizethe output size
[in]align_cornersTrue to align corners of input and output. Defaults to false.
Returns
The ratio between input and output (i.e., the input size divided by the output size)

Definition at line 31 of file ScaleUtils.cpp.

32 {
33  const size_t offset = (align_corners && output_size > 1) ? 1 : 0;
34  const auto in = input_size - offset;
35  const auto out = output_size - offset;
36 
37  ARM_COMPUTE_ERROR_ON((input_size == 0 || output_size == 0) && offset == 1);
38  ARM_COMPUTE_ERROR_ON(out == 0);
39 
40  return static_cast<float>(in) / static_cast<float>(out);
41 }

References ARM_COMPUTE_ERROR_ON, arm_compute::test::validation::input_size, offset(), and arm_compute::test::validation::output_size.

Referenced by arm_compute::cpu::bilinear_neon_scale(), CpuScale::configure(), CpuScaleKernel::configure(), NEScale::configure(), ClTemplateResize::get_tag_lut(), arm_compute::cpu::nearest_neon_scale(), CpuScale::prepare(), arm_compute::test::validation::reference::scale_core(), and CpuScale::validate().

◆ is_align_corners_allowed_sampling_policy()

bool arm_compute::scale_utils::is_align_corners_allowed_sampling_policy ( SamplingPolicy  sampling_policy)
inline

Returns if aligned corners are allowed for the given sampling policy.

Parameters
[in]sampling_policyThe sampling policy to consider
Returns
True if aligned corners are allowed

Definition at line 49 of file ScaleUtils.h.

50 {
51  return sampling_policy != SamplingPolicy::CENTER;
52 }

References arm_compute::CENTER, and arm_compute::test::validation::sampling_policy.

Referenced by CpuScale::configure(), NEScale::configure(), CpuScale::prepare(), CpuScale::validate(), and ClComponentResize::validate().

◆ is_precomputation_required()

bool is_precomputation_required ( DataLayout  data_layout,
DataType  data_type,
InterpolationPolicy  policy,
BorderMode  border_mode 
)

Returns if precomputation of indices and/or weights is required or/not.

Parameters
[in]data_layoutData layout
[in]data_typeData type
[in]policyInterpolation policy
[in]border_modeBorder Mode
Returns
True if precomputation is required

Definition at line 43 of file ScaleUtils.cpp.

45 {
46  // Do not calculate precomputed weights and indices if kernel code doesn't use them
47  if(data_layout == DataLayout::NHWC)
48  {
49  switch(data_type)
50  {
51  case DataType::F32:
52  case DataType::F16:
53  return (CPUInfo::get().get_isa().sve == true && policy == InterpolationPolicy::NEAREST_NEIGHBOR);
54  case DataType::U8:
55  case DataType::S8:
56  case DataType::QASYMM8:
57  case DataType::QASYMM8_SIGNED:
58  return (border_mode != BorderMode::REPLICATE) || (policy == InterpolationPolicy::NEAREST_NEIGHBOR);
59  default:
60  return true;
61  }
62  }
63 
64  return true;
65 }

References arm_compute::test::validation::data_layout, arm_compute::test::validation::data_type, CPUInfo::get(), and arm_compute::test::validation::sve.

Referenced by NEScale::configure(), and CpuScale::prepare().

arm_compute::test::validation::sve
cpu_isa sve
Definition: MaxUnpoolingLayer.cpp:96
arm_compute::test::validation::sampling_policy
sampling_policy
Definition: Scale.cpp:250
arm_compute::CPUInfo::get
static CPUInfo & get()
Access the KernelLibrary singleton.
Definition: CPPTypes.cpp:40
arm_compute::test::validation::data_layout
const auto data_layout
Definition: ConvolutionLayer.cpp:406
ARM_COMPUTE_ERROR_ON
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:467
offset
__global uchar * offset(const Image *img, int x, int y)
Get the pointer position of a Image.
Definition: helpers.h:1112
arm_compute::test::validation::data_type
data_type
Definition: Cast.cpp:223
arm_compute::test::validation::output_size
const int output_size
Definition: LSTMLayerQuantized.cpp:459
arm_compute::test::validation::input_size
const int input_size
Definition: LSTMLayerQuantized.cpp:458