Compute Library
 21.05
arm_compute::misc::shape_calculator Namespace Reference

Functions

TensorShape calculate_reduce_mean_shape (ITensorInfo *input, const Coordinates &reduction_axis, bool keep_dims)
 Calculate the output tensor shape for the reduce mean operation. More...
 
TensorShape compute_vector_to_tensor_output_shape (const TensorShape &input, size_t conv_w, size_t conv_h, const DataLayout &data_layout)
 Calculate the output tensor shape of a vector input given the convolution dimensions. More...
 
TensorShape compute_permutation_output_shape (const ITensorInfo &input, const PermutationVector &perm)
 Calculate the permuted shape of an input given a permutation vector. More...
 
TensorShape compute_reorg_output_shape (const ITensorInfo &input, int32_t stride)
 Calculate the output shape of the reorg layer given a stride. More...
 
TensorShape compute_weights_reshaped_shape (const ITensorInfo &weights, bool has_bias=false, unsigned int num_groups=1)
 Calculate the reshaped shape of the weights. More...
 
TensorShape compute_lhs_reshaped_shape (const ITensorInfo &a, const GEMMLHSMatrixInfo &lhs_info, bool reinterpret_input_as_3d=false)
 Calculate the Left Hand Side matrix reshaped shape. More...
 
TensorShape compute_rhs_reshaped_shape (const ITensorInfo &a, const GEMMRHSMatrixInfo &rhs_info)
 Calculate the Right Hand Side matrix reshaped shape. More...
 
TensorShape compute_interleaved_shape (const ITensorInfo &a, int mult_interleave4x4_height=1, bool reinterpret_input_as_3d=false)
 Calculate the interleaved shape of an input tensor. More...
 
TensorShape compute_transpose1xW_shape (const ITensorInfo &b)
 Calculate the transposed 1xW shape. More...
 
TensorShape compute_transpose1xW_with_element_size_shape (const ITensorInfo &b, int mult_transpose1xW_width=1)
 Calculate the transposed 1xW width element shape. More...
 
TensorShape compute_reductionA_shape (const ITensorInfo &b)
 Calculate the reductionA shape used in GEMMLowp. More...
 
TensorShape compute_reductionB_shape (const ITensorInfo &a)
 Calculate the reductionB shape used in GEMMLowp. More...
 
TensorShape compute_col2im_shape (const ITensorInfo &input, const Size2D &convolved_dims, bool batch_size_on_z, unsigned int num_groups=1)
 Calculate the Col2Im shape. More...
 
TensorShape compute_transposed_shape (const ITensorInfo &input)
 Calculate the transposed shape of a tensor. More...
 
TensorShape compute_depthwise_convolution_shape (const ITensorInfo &input, const ITensorInfo &weights, const ConvolutionInfo &info)
 Calculate the depthwise convolution output shape of a tensor. More...
 
TensorShape compute_deconvolution_upsampled_shape (const ITensorInfo &input, const ITensorInfo &weights, unsigned int sx, unsigned int sy, std::pair< unsigned int, unsigned int > &out_dims, uint32_t &padx, uint32_t &pady)
 Calculate the upsampled output shape used for deconvolution. More...
 
TensorShape compute_deconvolution_output_shape (const std::pair< unsigned int, unsigned int > &out_dims, const ITensorInfo &input, const ITensorInfo &weights)
 Calculate the output shape of the deconvolution layer. More...
 
TensorShape compute_im2col_conv_shape (const ITensorInfo *input, const Size2D &kernel_dims, const PadStrideInfo &conv_info, bool has_bias, const Size2D &dilation, bool batch_size_on_z, unsigned int num_groups=1)
 Calculate the im2col output shape of a tensor. More...
 
TensorShape compute_flatten_shape (const ITensorInfo *input)
 Calculate the flattened output shape of a tensor. More...
 
TensorShape compute_softmax_shape (const ITensorInfo *input, size_t axis=1)
 Calculate the softmax output shape of a tensor. More...
 
TensorShape compute_winograd_filter_transform_shape (const ITensorInfo &input, const WinogradInfo &winograd_info)
 Calculate the winograd filter transform shape. More...
 
TensorShape compute_winograd_input_transform_shape (const ITensorInfo &input, const WinogradInfo &winograd_info)
 Calculate the winograd input transform shape. More...
 
TensorShape compute_winograd_output_transform_shape (const ITensorInfo &input, const WinogradInfo &winograd_info)
 Calculate the winograd output transform shape. More...
 
TensorShape compute_deep_convolution_shape (const ITensorInfo &input, const ITensorInfo &weights, PadStrideInfo conv_info)
 Calculate the deep convolution shape output shape of a tensor. More...
 
TensorShape compute_min_max_shape (const ITensorInfo *input)
 Calculate the min/max shape output shape of a tensor. More...
 
TensorShape compute_pool_shape (const ITensorInfo &input, PoolingLayerInfo pool_info)
 Calculate the output pool shape of a tensor. More...
 
TensorShape compute_unpool_shape (const ITensorInfo &input, PoolingLayerInfo pool_info)
 Calculate the output unpool shape of a tensor. More...
 
TensorShape compute_roi_align_shape (const ITensorInfo &input, const ITensorInfo &rois, ROIPoolingLayerInfo pool_info)
 Calculate the output roi align shape of a tensor. More...
 
TensorShape compute_rnn_shape (const ITensorInfo *input, const unsigned int batch_size)
 Calculate the RNN shape of a tensor. More...
 
TensorShape compute_mm_shape (const ITensorInfo &input0, const ITensorInfo &input1, bool is_interleaved_transposed, const GEMMReshapeInfo &reshape_info)
 Calculate the matrix multiplication output shape of two tensors. More...
 
TensorShape compute_mm_shape (const ITensorInfo &input0, const ITensorInfo &input1, const GEMMReshapeInfo &gemm_info)
 Calculate the matrix multiplication output shape of two tensors. More...
 
TensorShape compute_mm_shape (const ITensorInfo &input0, const ITensorInfo &input1, const GEMMKernelInfo &gemm_info)
 Calculate the matrix multiplication output shape of two tensors. More...
 
TensorShape compute_output_stage_shape (const ITensorInfo &input, unsigned int gemm_3d_depth=1, bool batch_size_on_z=false)
 Calculate the matrix multiplication output shape of two tensors. More...
 
TensorShape compute_strided_slice_shape (const ITensorInfo &input, const Coordinates &starts, const Coordinates &ends, const Coordinates &strides, int32_t begin_mask, int32_t end_mask, int32_t shrink_axis_mask)
 Calculate the strided slice output shape of a tensor. More...
 
TensorShape compute_slice_shape (const TensorShape &input_shape, const Coordinates &starts, const Coordinates &ends)
 Calculate the slice output shape of a tensor. More...
 
TensorShape compute_batch_to_space_shape (const ITensorInfo *input, const int block_x, const int block_y)
 Calculate the batch to space output shape of a tensor. More...
 
TensorShape compute_depth_to_space_shape (const TensorShape &input_shape, DataLayout data_layout, int block)
 Calculate the depth to space output shape of a tensor. More...
 
TensorShape compute_split_shape (const ITensorInfo *input, unsigned int axis, unsigned int num_splits)
 Calculate the split output shape of a tensor. More...
 
TensorShape compute_space_to_batch_shape (const ITensorInfo *input, const int block_x, const int block_y, const Size2D &padding_left, const Size2D &padding_right)
 Calculate the space to batch output shape of a tensor. More...
 
TensorShape compute_space_to_depth_shape (const ITensorInfo *input, int32_t block_shape)
 Calculate the space to batch output shape of a tensor. More...
 
TensorShape compute_prior_box_shape (const ITensorInfo &input, const PriorBoxLayerInfo &info)
 Calculate the prior box output shape of a tensor. More...
 
TensorShape compute_padded_shape (const TensorShape &input_shape, const PaddingList &padding)
 Calculate the padded shape of a tensor. More...
 
TensorShape compute_tiled_shape (const TensorShape &input_shape, const Multiples &multiples)
 Calculate the tiled shape of a tensor. More...
 
TensorShape compute_reduced_shape (const TensorShape &input, unsigned int axis, bool keep_dims=true)
 Calculate the reduced shape of a tensor given an axis. More...
 
TensorShape compute_upsample_shape (const ITensorInfo &input, const Size2D &info)
 Calculate the upsampled shape of a tensor. More...
 
template<typename T >
TensorShape extract_shape (T *data)
 Get the tensor shape. More...
 
TensorShape extract_shape (ITensorInfo *data)
 
TensorShape extract_shape (const ITensorInfo *data)
 
TensorShape extract_shape (const TensorShape *data)
 
TensorShape extract_shape (TensorShape *data)
 
TensorShape calculate_unstack_shape (TensorShape input_shape, unsigned int axis)
 Calculate the unstack shape of a tensor. More...
 
template<typename T >
TensorShape calculate_concatenate_shape (const std::vector< T * > &input, size_t axis)
 Calculate the concatenate output shape of the concatenate operation along a single axis. More...
 
TensorShape compute_stack_shape (const ITensorInfo &a, unsigned int axis, unsigned int num_tensors)
 Calculate the stack output shape of a tensor. More...
 
TensorShape compute_gather_shape (const TensorShape &input_shape, const TensorShape &indices_shape, uint32_t actual_axis)
 

Function Documentation

◆ calculate_concatenate_shape()

TensorShape arm_compute::misc::shape_calculator::calculate_concatenate_shape ( const std::vector< T * > &  input,
size_t  axis 
)
inline

Calculate the concatenate output shape of the concatenate operation along a single axis.

Parameters
[in]inputVector containing the shapes of the inputs
[in]axisAxis along which to concatenate the input tensors
Returns
the calculated shape

Definition at line 1320 of file ShapeCalculator.h.

1321 {
1322  TensorShape out_shape = extract_shape(input[0]);
1323 
1324 #if defined(ARM_COMPUTE_ASSERTS_ENABLED)
1325  // All dimensions must match except the axis one
1326  for(unsigned int i = 0; i < MAX_DIMS; ++i)
1327  {
1328  if(i == axis)
1329  {
1330  continue;
1331  }
1332 
1333  for(const auto &tensor : input)
1334  {
1335  ARM_COMPUTE_ERROR_ON(tensor == nullptr);
1336  const TensorShape shape = extract_shape(tensor);
1337  ARM_COMPUTE_ERROR_ON(out_shape[i] != shape[i]);
1338  }
1339  }
1340 #endif // defined(ARM_COMPUTE_ASSERTS_ENABLED)
1341 
1342  // Calculate output shape
1343  size_t new_size = 0;
1344  for(const auto &tensor : input)
1345  {
1346  const TensorShape shape = extract_shape(tensor);
1347  new_size += shape[axis];
1348  }
1349 
1350  out_shape.set(axis, new_size);
1351 
1352  return out_shape;
1353 }
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:466
constexpr size_t MAX_DIMS
Constant value used to indicate maximum dimensions of a Window, TensorShape and Coordinates.
Definition: Dimensions.h:38
TensorShape extract_shape(TensorShape *data)

References ARM_COMPUTE_ERROR_ON, extract_shape(), arm_compute::test::validation::input, arm_compute::MAX_DIMS, TensorShape::set(), and arm_compute::test::validation::shape.

Referenced by ConcatenateLayerNode::compute_output_descriptor(), CpuConcatenate::configure(), ClConcatenate::configure(), CLLSTMLayer::configure(), CpuConcatenate::validate(), ClConcatenate::validate(), NELSTMLayer::validate(), and CLLSTMLayer::validate().

◆ calculate_reduce_mean_shape()

TensorShape arm_compute::misc::shape_calculator::calculate_reduce_mean_shape ( ITensorInfo input,
const Coordinates reduction_axis,
bool  keep_dims 
)
inline

Calculate the output tensor shape for the reduce mean operation.

Parameters
[in]inputInput tensor shape
[in]reduction_axisReduction axis
[in]keep_dimsFlag to indicate if dimensions are kept
Returns
the calculated shape

Definition at line 50 of file ShapeCalculator.h.

51 {
52  const int reduction_ops = reduction_axis.num_dimensions();
53  Coordinates axis_local = reduction_axis;
54  const int input_dims = input->num_dimensions();
55  convert_negative_axis(axis_local, input_dims);
56  TensorShape out_shape = input->tensor_shape();
57  // Configure reshape layer if we want to drop the dimensions
58  if(!keep_dims)
59  {
60  // We have to sort the reduction axis vectors in order for remove_dimension
61  // to work properly
62  std::sort(axis_local.begin(), axis_local.begin() + reduction_ops);
63  for(int i = 0; i < reduction_ops; ++i)
64  {
65  out_shape.remove_dimension(axis_local[i] - i);
66  }
67  return out_shape;
68  }
69  else
70  {
71  for(int i = 0; i < reduction_ops; ++i)
72  {
73  out_shape.set(axis_local[i], 1);
74  }
75  return out_shape;
76  }
77 }
Coordinates & convert_negative_axis(Coordinates &coords, int max_value)
Convert negative coordinates to positive in the range [0, num_dims_input].
Definition: Helpers.h:241

References Dimensions< T >::begin(), arm_compute::convert_negative_axis(), arm_compute::test::validation::input, Dimensions< T >::num_dimensions(), TensorShape::remove_dimension(), and TensorShape::set().

Referenced by NEReduceMean::configure(), and CLReduceMean::configure().

◆ calculate_unstack_shape()

TensorShape arm_compute::misc::shape_calculator::calculate_unstack_shape ( TensorShape  input_shape,
unsigned int  axis 
)
inline

Calculate the unstack shape of a tensor.

Parameters
[in]input_shapeInput tensor shape
[in]axisAxis on which to perform the unstack operation
Returns
the calculated shape

Definition at line 1305 of file ShapeCalculator.h.

1306 {
1309  return input_shape;
1310 }
void remove_dimension(size_t n)
Accessor to remove the dimension n from the tensor shape.
Definition: TensorShape.h:111
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:466
TensorShape input_shape
Validate test suite is to test ARM_COMPUTE_RETURN_ON_* macros we use to check the validity of given a...
unsigned int num_dimensions() const
Returns the effective dimensionality of the tensor.
Definition: Dimensions.h:143

References ARM_COMPUTE_ERROR_ON, arm_compute::test::validation::input_shape, Dimensions< T >::num_dimensions(), and TensorShape::remove_dimension().

◆ compute_batch_to_space_shape()

TensorShape arm_compute::misc::shape_calculator::compute_batch_to_space_shape ( const ITensorInfo input,
const int  block_x,
const int  block_y 
)
inline

Calculate the batch to space output shape of a tensor.

Parameters
[in]inputInput tensor info
[in]block_xBlock shape x value
[in]block_yBlock shape y value
Returns
the calculated shape

Definition at line 1038 of file ShapeCalculator.h.

1039 {
1040  ARM_COMPUTE_ERROR_ON(block_x <= 0 || block_y <= 0);
1041 
1042  const DataLayout data_layout = input->data_layout();
1043  const int idx_width = get_data_layout_dimension_index(data_layout, DataLayoutDimension::WIDTH);
1044  const int idx_height = get_data_layout_dimension_index(data_layout, DataLayoutDimension::HEIGHT);
1045  const int idx_batch = get_data_layout_dimension_index(data_layout, DataLayoutDimension::BATCHES);
1046 
1047  TensorShape output_shape{ input->tensor_shape() };
1048  output_shape.set(idx_width, input->tensor_shape()[idx_width] * block_x);
1049  output_shape.set(idx_height, input->tensor_shape()[idx_height] * block_y);
1050  output_shape.set(idx_batch, input->tensor_shape()[idx_batch] / (block_x * block_y));
1051 
1052  return output_shape;
1053 }
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:466
const DataLayout data_layout
Definition: Im2Col.cpp:151
size_t get_data_layout_dimension_index(const DataLayout data_layout, const DataLayoutDimension data_layout_dimension)
Get the index of the given dimension.
Definition: Helpers.inl:193
DataLayout
[DataLayout enum definition]
Definition: Types.h:114
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.
Definition: TensorShape.h:79

References ARM_COMPUTE_ERROR_ON, arm_compute::BATCHES, arm_compute::test::validation::data_layout, arm_compute::get_data_layout_dimension_index(), arm_compute::HEIGHT, arm_compute::test::validation::idx_height, arm_compute::test::validation::idx_width, arm_compute::test::validation::input, arm_compute::test::validation::output_shape, TensorShape::set(), and arm_compute::WIDTH.

Referenced by NEBatchToSpaceLayerKernel::configure(), and CLBatchToSpaceLayerKernel::configure().

◆ compute_col2im_shape()

TensorShape arm_compute::misc::shape_calculator::compute_col2im_shape ( const ITensorInfo input,
const Size2D convolved_dims,
bool  batch_size_on_z,
unsigned int  num_groups = 1 
)
inline

Calculate the Col2Im shape.

Parameters
[in]inputInput tensor info
[in]convolved_dimsConvolved dimensions
[in]batch_size_on_zTrue if batch size is on z axis
[in]num_groups(Optional) Number of groups when performing a grouped convolution
Returns
the calculated shape

Definition at line 371 of file ShapeCalculator.h.

372 {
374  ARM_COMPUTE_ERROR_ON(input.tensor_shape()[1] != (convolved_dims.area()));
375  ARM_COMPUTE_ERROR_ON((num_groups > 1) && input.tensor_shape()[2] != num_groups);
376 
377  const DataLayout data_layout = input.data_layout();
378  const int width_idx = get_data_layout_dimension_index(data_layout, DataLayoutDimension::WIDTH);
379  const int height_idx = get_data_layout_dimension_index(data_layout, DataLayoutDimension::HEIGHT);
380  const int channel_idx = get_data_layout_dimension_index(data_layout, DataLayoutDimension::CHANNEL);
381 
382  TensorShape col2im_shape{ input.tensor_shape() };
383  // If batches start on 3rd dimension shift dimensions right by 1 to retain upper tensor shape,
384  // as first three will be override by H,W,C data
385  if(batch_size_on_z && num_groups == 1)
386  {
387  col2im_shape.shift_right(1);
388  }
389  col2im_shape.set(width_idx, convolved_dims.width);
390  col2im_shape.set(height_idx, convolved_dims.height);
391  col2im_shape.set(channel_idx, input.tensor_shape()[0] * num_groups);
392 
393  return col2im_shape;
394 }
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:466
const DataLayout data_layout
Definition: Im2Col.cpp:151
const unsigned int num_groups
Definition: Im2Col.cpp:153
size_t get_data_layout_dimension_index(const DataLayout data_layout, const DataLayoutDimension data_layout_dimension)
Get the index of the given dimension.
Definition: Helpers.inl:193
DataLayout
[DataLayout enum definition]
Definition: Types.h:114

References Size2D::area(), ARM_COMPUTE_ERROR_ON, arm_compute::CHANNEL, arm_compute::test::validation::data_layout, arm_compute::get_data_layout_dimension_index(), Size2D::height, arm_compute::HEIGHT, arm_compute::test::validation::input, arm_compute::test::validation::num_groups, Size2D::width, and arm_compute::WIDTH.

◆ compute_deconvolution_output_shape()

TensorShape arm_compute::misc::shape_calculator::compute_deconvolution_output_shape ( const std::pair< unsigned int, unsigned int > &  out_dims,
const ITensorInfo input,
const ITensorInfo weights 
)
inline

Calculate the output shape of the deconvolution layer.

Parameters
[in]out_dimsOutput x and y shape dimensions
[in]inputInput tensor info
[in]weightsWeights tensor shape
Returns
the calculated shape

Definition at line 492 of file ShapeCalculator.h.

493 {
494  const TensorShape input_shape{ input.tensor_shape() };
495  const TensorShape weights_shape{ weights.tensor_shape() };
496 
497  const DataLayout data_layout = input.data_layout();
498  const int width_idx = get_data_layout_dimension_index(data_layout, DataLayoutDimension::WIDTH);
499  const int height_idx = get_data_layout_dimension_index(data_layout, DataLayoutDimension::HEIGHT);
500  const int channel_idx = get_data_layout_dimension_index(data_layout, DataLayoutDimension::CHANNEL);
501  const int batch_idx = get_data_layout_dimension_index(data_layout, DataLayoutDimension::BATCHES);
502 
503  TensorShape out_shape{ input_shape };
504  out_shape.set(width_idx, out_dims.first);
505  out_shape.set(height_idx, out_dims.second);
506  out_shape.set(channel_idx, weights_shape[batch_idx]);
507  return out_shape;
508 }
const DataLayout data_layout
Definition: Im2Col.cpp:151
TensorShape input_shape
Validate test suite is to test ARM_COMPUTE_RETURN_ON_* macros we use to check the validity of given a...
size_t get_data_layout_dimension_index(const DataLayout data_layout, const DataLayoutDimension data_layout_dimension)
Get the index of the given dimension.
Definition: Helpers.inl:193
DataLayout
[DataLayout enum definition]
Definition: Types.h:114
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.
Definition: TensorShape.h:79

References arm_compute::BATCHES, arm_compute::CHANNEL, arm_compute::test::validation::data_layout, arm_compute::get_data_layout_dimension_index(), arm_compute::HEIGHT, arm_compute::test::validation::input, arm_compute::test::validation::input_shape, TensorShape::set(), ITensorInfo::tensor_shape(), and arm_compute::WIDTH.

Referenced by NEDeconvolutionLayer::configure(), CLDirectDeconvolutionLayer::configure(), NEDeconvolutionLayer::validate(), CLGEMMDeconvolutionLayer::validate(), and CLDirectDeconvolutionLayer::validate().

◆ compute_deconvolution_upsampled_shape()

TensorShape arm_compute::misc::shape_calculator::compute_deconvolution_upsampled_shape ( const ITensorInfo input,
const ITensorInfo weights,
unsigned int  sx,
unsigned int  sy,
std::pair< unsigned int, unsigned int > &  out_dims,
uint32_t &  padx,
uint32_t &  pady 
)
inline

Calculate the upsampled output shape used for deconvolution.

Parameters
[in]inputInput tensor info
[in]weightsWeights tensor shape
[in]sxStride on x axis
[in]syStride on y axis
[in]out_dimsOutput shape dimensions
[in]padxPadding on x axis
[in]padyPadding on y axis
Returns
the calculated shape

Definition at line 460 of file ShapeCalculator.h.

462 {
463  const DataLayout data_layout = input.data_layout();
464  const size_t idx_w = get_data_layout_dimension_index(data_layout, DataLayoutDimension::WIDTH);
465  const size_t idx_h = get_data_layout_dimension_index(data_layout, DataLayoutDimension::HEIGHT);
466 
467  // Find the upsampled dimensions
468  unsigned int out_x = (input.dimension(idx_w) - 1) * sx + 1;
469  unsigned int out_y = (input.dimension(idx_h) - 1) * sy + 1;
470 
471  // Find the padding needed for the convolution with stride 1 in order to match output shape
472  padx = out_dims.first - (out_x - weights.dimension(idx_w) + 1);
473  pady = out_dims.second - (out_y - weights.dimension(idx_h) + 1);
474  out_x += padx;
475  out_y += pady;
476 
477  TensorShape scale_out_shape(input.tensor_shape());
478  scale_out_shape.set(idx_w, out_x);
479  scale_out_shape.set(idx_h, out_y);
480 
481  return scale_out_shape;
482 }
const DataLayout data_layout
Definition: Im2Col.cpp:151
size_t get_data_layout_dimension_index(const DataLayout data_layout, const DataLayoutDimension data_layout_dimension)
Get the index of the given dimension.
Definition: Helpers.inl:193
DataLayout
[DataLayout enum definition]
Definition: Types.h:114

References arm_compute::test::validation::data_layout, ITensorInfo::dimension(), arm_compute::get_data_layout_dimension_index(), arm_compute::HEIGHT, arm_compute::test::validation::input, TensorShape::set(), and arm_compute::WIDTH.

Referenced by NEDeconvolutionLayer::configure(), CLDirectDeconvolutionLayer::configure(), NEDeconvolutionLayer::validate(), and CLDirectDeconvolutionLayer::validate().

◆ compute_deep_convolution_shape()

TensorShape arm_compute::misc::shape_calculator::compute_deep_convolution_shape ( const ITensorInfo input,
const ITensorInfo weights,
PadStrideInfo  conv_info 
)
inline

Calculate the deep convolution shape output shape of a tensor.

Parameters
[in]inputInput tensor info
[in]weightsWeights tensor info
[in]conv_infoContains padding and stride information
Returns
the calculated shape

Definition at line 711 of file ShapeCalculator.h.

712 {
713  const TensorShape input_shape{ input.tensor_shape() };
714  const TensorShape weights_shape{ weights.tensor_shape() };
715 
716  const size_t idx_width = get_data_layout_dimension_index(input.data_layout(), DataLayoutDimension::WIDTH);
717  const size_t idx_height = get_data_layout_dimension_index(input.data_layout(), DataLayoutDimension::HEIGHT);
718  const size_t idx_channel = get_data_layout_dimension_index(input.data_layout(), DataLayoutDimension::CHANNEL);
719 
720  const unsigned int input_width = input_shape[idx_width];
721  const unsigned int input_height = input_shape[idx_height];
722  const unsigned int weights_width = weights_shape[idx_width];
723  const unsigned int weights_height = weights_shape[idx_height];
724  const unsigned int weights_out_channel = weights_shape[3];
725  unsigned int output_width = 0;
726  unsigned int output_height = 0;
727  std::tie(output_width, output_height) = scaled_dimensions(input_width, input_height, weights_width, weights_height, conv_info);
728 
729  TensorShape output_shape{ input_shape };
730  output_shape.set(idx_width, output_width);
731  output_shape.set(idx_height, output_height);
732  output_shape.set(idx_channel, weights_out_channel);
733 
734  return output_shape;
735 }
std::pair< unsigned int, unsigned int > scaled_dimensions(int width, int height, int kernel_width, int kernel_height, const PadStrideInfo &pad_stride_info, const Size2D &dilation=Size2D(1U, 1U))
Returns expected width and height of output scaled tensor depending on dimensions rounding mode.
Definition: Utils.cpp:395
TensorShape input_shape
Validate test suite is to test ARM_COMPUTE_RETURN_ON_* macros we use to check the validity of given a...
const size_t input_width
const size_t input_height
const size_t weights_width
const size_t weights_height
size_t get_data_layout_dimension_index(const DataLayout data_layout, const DataLayoutDimension data_layout_dimension)
Get the index of the given dimension.
Definition: Helpers.inl:193
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.
Definition: TensorShape.h:79

References arm_compute::CHANNEL, arm_compute::test::validation::conv_info, arm_compute::get_data_layout_dimension_index(), arm_compute::HEIGHT, arm_compute::test::validation::idx_height, arm_compute::test::validation::idx_width, arm_compute::test::validation::input, input_height, arm_compute::test::validation::input_shape, input_width, arm_compute::test::validation::output_shape, arm_compute::scaled_dimensions(), TensorShape::set(), ITensorInfo::tensor_shape(), weights_height, weights_width, and arm_compute::WIDTH.

Referenced by CpuDirectConvolutionKernel::configure().

◆ compute_depth_to_space_shape()

TensorShape arm_compute::misc::shape_calculator::compute_depth_to_space_shape ( const TensorShape input_shape,
DataLayout  data_layout,
int  block 
)
inline

Calculate the depth to space output shape of a tensor.

Parameters
[in]input_shapeInput tensor shape
[in]data_layoutOperation data layout
[in]blockBlock shape value
Returns
the calculated shape

Definition at line 1063 of file ShapeCalculator.h.

1064 {
1065  ARM_COMPUTE_ERROR_ON(block < 2);
1066 
1067  const int idx_width = get_data_layout_dimension_index(data_layout, DataLayoutDimension::WIDTH);
1068  const int idx_height = get_data_layout_dimension_index(data_layout, DataLayoutDimension::HEIGHT);
1069  const int idx_channel = get_data_layout_dimension_index(data_layout, DataLayoutDimension::CHANNEL);
1070 
1071  TensorShape output_shape{ input_shape };
1074  output_shape.set(idx_channel, input_shape[idx_channel] / (block * block));
1075 
1076  return output_shape;
1077 }
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:466
const DataLayout data_layout
Definition: Im2Col.cpp:151
TensorShape input_shape
Validate test suite is to test ARM_COMPUTE_RETURN_ON_* macros we use to check the validity of given a...
size_t get_data_layout_dimension_index(const DataLayout data_layout, const DataLayoutDimension data_layout_dimension)
Get the index of the given dimension.
Definition: Helpers.inl:193
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.
Definition: TensorShape.h:79

References ARM_COMPUTE_ERROR_ON, arm_compute::CHANNEL, arm_compute::test::validation::data_layout, arm_compute::get_data_layout_dimension_index(), arm_compute::HEIGHT, arm_compute::test::validation::idx_height, arm_compute::test::validation::idx_width, arm_compute::test::validation::input_shape, arm_compute::test::validation::output_shape, TensorShape::set(), and arm_compute::WIDTH.

Referenced by DepthToSpaceLayerNode::compute_output_descriptor(), NEDepthToSpaceLayerKernel::configure(), and CLDepthToSpaceLayerKernel::configure().

◆ compute_depthwise_convolution_shape()

TensorShape arm_compute::misc::shape_calculator::compute_depthwise_convolution_shape ( const ITensorInfo input,
const ITensorInfo weights,
const ConvolutionInfo info 
)
inline

Calculate the depthwise convolution output shape of a tensor.

Parameters
[in]inputInput tensor info
[in]weightsWeights tensor info
[in]infoConvolution info
Returns
the calculated shape

Definition at line 420 of file ShapeCalculator.h.

421 {
422  const TensorShape input_shape{ input.tensor_shape() };
423  const TensorShape weights_shape{ weights.tensor_shape() };
424 
425  const DataLayout data_layout = input.data_layout();
426  const int width_idx = get_data_layout_dimension_index(data_layout, DataLayoutDimension::WIDTH);
427  const int height_idx = get_data_layout_dimension_index(data_layout, DataLayoutDimension::HEIGHT);
428  const int channel_idx = get_data_layout_dimension_index(data_layout, DataLayoutDimension::CHANNEL);
429 
430  const DataLayout weights_data_layout = weights.data_layout();
431  const int weights_width_idx = get_data_layout_dimension_index(weights_data_layout, DataLayoutDimension::WIDTH);
432  const int weights_height_idx = get_data_layout_dimension_index(weights_data_layout, DataLayoutDimension::HEIGHT);
433 
434  unsigned int output_width = 0;
435  unsigned int output_height = 0;
436  std::tie(output_width, output_height) = scaled_dimensions(input_shape[width_idx], input_shape[height_idx],
437  weights_shape[weights_width_idx], weights_shape[weights_height_idx],
438  info.pad_stride_info, info.dilation);
439 
440  TensorShape output_shape{ input_shape };
441  output_shape.set(width_idx, output_width);
442  output_shape.set(height_idx, output_height);
443  output_shape.set(channel_idx, input_shape[channel_idx] * info.depth_multiplier);
444 
445  return output_shape;
446 }
const DataLayout data_layout
Definition: Im2Col.cpp:151
std::pair< unsigned int, unsigned int > scaled_dimensions(int width, int height, int kernel_width, int kernel_height, const PadStrideInfo &pad_stride_info, const Size2D &dilation=Size2D(1U, 1U))
Returns expected width and height of output scaled tensor depending on dimensions rounding mode.
Definition: Utils.cpp:395
TensorShape input_shape
Validate test suite is to test ARM_COMPUTE_RETURN_ON_* macros we use to check the validity of given a...
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)
size_t get_data_layout_dimension_index(const DataLayout data_layout, const DataLayoutDimension data_layout_dimension)
Get the index of the given dimension.
Definition: Helpers.inl:193
DataLayout
[DataLayout enum definition]
Definition: Types.h:114
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.
Definition: TensorShape.h:79

References arm_compute::CHANNEL, arm_compute::test::validation::data_layout, ITensorInfo::data_layout(), arm_compute::get_data_layout_dimension_index(), arm_compute::HEIGHT, arm_compute::test::validation::info, arm_compute::test::validation::input, arm_compute::test::validation::input_shape, arm_compute::test::validation::output_shape, arm_compute::scaled_dimensions(), TensorShape::set(), ITensorInfo::tensor_shape(), and arm_compute::WIDTH.

Referenced by CpuDepthwiseConvolutionAssemblyDispatch::configure(), CpuDepthwiseConvolutionNativeKernel::configure(), CLDepthwiseConvolutionLayerNativeKernel::configure(), and CpuDepthwiseConvolutionAssemblyDispatch::validate().

◆ compute_flatten_shape()

TensorShape arm_compute::misc::shape_calculator::compute_flatten_shape ( const ITensorInfo input)
inline

Calculate the flattened output shape of a tensor.

Parameters
[in]inputInput tensor info
Returns
the calculated shape

Definition at line 560 of file ShapeCalculator.h.

561 {
562  // The output shape will be the flatten version of the input (i.e. [ width * height * channels, num_batches, ... ] ). Used for FlattenLayer and FullyConnectedLayer.
563 
564  TensorShape output_shape{ input->tensor_shape() };
565 
567 
568  return output_shape;
569 }
void collapse(size_t n, size_t first=0)
Collapse the first n dimensions.
Definition: TensorShape.h:133

References TensorShape::collapse(), arm_compute::test::validation::input, and arm_compute::test::validation::output_shape.

Referenced by NEFlattenLayer::configure(), CLFlattenLayer::configure(), NEFlattenLayer::validate(), CLFlattenLayer::validate(), NEFullyConnectedLayer::validate(), and CLFullyConnectedLayer::validate().

◆ compute_gather_shape()

TensorShape arm_compute::misc::shape_calculator::compute_gather_shape ( const TensorShape input_shape,
const TensorShape indices_shape,
uint32_t  actual_axis 
)
inline

Definition at line 1384 of file ShapeCalculator.h.

1385 {
1386  ARM_COMPUTE_ERROR_ON(indices_shape.num_dimensions() > 1);
1389 
1390  TensorShape output_shape = input_shape;
1391  output_shape[actual_axis] = indices_shape[0];
1392 
1393  return output_shape;
1394 }
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:466
TensorShape input_shape
Validate test suite is to test ARM_COMPUTE_RETURN_ON_* macros we use to check the validity of given a...
unsigned int num_dimensions() const
Returns the effective dimensionality of the tensor.
Definition: Dimensions.h:143

References ARM_COMPUTE_ERROR_ON, arm_compute::test::validation::input_shape, Dimensions< T >::num_dimensions(), and arm_compute::test::validation::output_shape.

Referenced by NEGatherKernel::configure(), and arm_compute::test::validation::reference::gather().

◆ compute_im2col_conv_shape()

TensorShape arm_compute::misc::shape_calculator::compute_im2col_conv_shape ( const ITensorInfo input,
const Size2D kernel_dims,
const PadStrideInfo conv_info,
bool  has_bias,
const Size2D dilation,
bool  batch_size_on_z,
unsigned int  num_groups = 1 
)
inline

Calculate the im2col output shape of a tensor.

Parameters
[in]inputInput tensor info
[in]kernel_dimsThe kernel dimensions (width and height).
[in]conv_infoContains padding and stride information
[in]has_biasIn case biases are provided expands the matrix with 1
[in]dilationDilation, in elements, across x and y
[in]batch_size_on_zTrue if batch size is on z axis
[in]num_groups(Optional) Number of groups when performing a grouped convolution
Returns
the calculated shape

Definition at line 522 of file ShapeCalculator.h.

524 {
525  // The output shape will be the 3D shape [ out_channels * kernel_area, num_elems_per_out_channel, batches ] if batch_size_on_z == true
526  // or the 4D shape [ out_channels * kernel_area / num_groups, num_elems_per_out_channel, num_groups, batches ] if batch_size_on_z == false
527 
529  ARM_COMPUTE_ERROR_ON(num_groups > 1 && input->data_layout() != DataLayout::NCHW);
530  ARM_COMPUTE_ERROR_ON(num_groups > 1 && batch_size_on_z);
531 
532  TensorShape output_shape{ input->tensor_shape() };
533 
534  const DataLayout data_layout = input->data_layout();
535  const int width_idx = get_data_layout_dimension_index(data_layout, DataLayoutDimension::WIDTH);
536  const int height_idx = get_data_layout_dimension_index(data_layout, DataLayoutDimension::HEIGHT);
537  const int channel_idx = get_data_layout_dimension_index(data_layout, DataLayoutDimension::CHANNEL);
538 
539  std::pair<unsigned int, unsigned int> out_dims = scaled_dimensions(output_shape[width_idx], output_shape[height_idx], kernel_dims.width, kernel_dims.height, conv_info, dilation);
540  output_shape.set(0, (output_shape[channel_idx] / num_groups * kernel_dims.area() + (has_bias ? 1 : 0))); // NOLINT
541  output_shape.set(1, (out_dims.first * out_dims.second));
542  if(batch_size_on_z && output_shape.num_dimensions() >= 3)
543  {
545  }
546  else
547  {
549  }
550 
551  return output_shape;
552 }
void remove_dimension(size_t n)
Accessor to remove the dimension n from the tensor shape.
Definition: TensorShape.h:111
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:466
const DataLayout data_layout
Definition: Im2Col.cpp:151
std::pair< unsigned int, unsigned int > scaled_dimensions(int width, int height, int kernel_width, int kernel_height, const PadStrideInfo &pad_stride_info, const Size2D &dilation=Size2D(1U, 1U))
Returns expected width and height of output scaled tensor depending on dimensions rounding mode.
Definition: Utils.cpp:395
const unsigned int num_groups
Definition: Im2Col.cpp:153
unsigned int num_dimensions() const
Returns the effective dimensionality of the tensor.
Definition: Dimensions.h:143
size_t get_data_layout_dimension_index(const DataLayout data_layout, const DataLayoutDimension data_layout_dimension)
Get the index of the given dimension.
Definition: Helpers.inl:193
DataLayout
[DataLayout enum definition]
Definition: Types.h:114
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.
Definition: TensorShape.h:79

References Size2D::area(), ARM_COMPUTE_ERROR_ON, arm_compute::CHANNEL, arm_compute::test::validation::conv_info, arm_compute::test::validation::data_layout, arm_compute::get_data_layout_dimension_index(), arm_compute::test::validation::has_bias, Size2D::height, arm_compute::HEIGHT, arm_compute::test::validation::input, arm_compute::NCHW, Dimensions< T >::num_dimensions(), arm_compute::test::validation::num_groups, arm_compute::test::validation::output_shape, TensorShape::remove_dimension(), arm_compute::scaled_dimensions(), TensorShape::set(), Size2D::width, and arm_compute::WIDTH.

Referenced by CLGEMMConvolutionLayer::validate().

◆ compute_interleaved_shape()

TensorShape arm_compute::misc::shape_calculator::compute_interleaved_shape ( const ITensorInfo a,
int  mult_interleave4x4_height = 1,
bool  reinterpret_input_as_3d = false 
)
inline

Calculate the interleaved shape of an input tensor.

Parameters
[in]aInput tensor info
[in]mult_interleave4x4_height(Optional) Interleave4x4 height
[in]reinterpret_input_as_3d(Optional) Set to true if the input need to be interpreted as 3d
Returns
the calculated shape

Definition at line 260 of file ShapeCalculator.h.

261 {
262  // The interleaved output matrix will have the following shape: [ a_height * W, ceil(a_width / W) ] where W = 4 * mult_interleave4x4_height
263  ARM_COMPUTE_ERROR_ON(mult_interleave4x4_height < 1);
264  const int interleave_width = 4 * mult_interleave4x4_height;
265  TensorShape shape_interleaved_a{ a.tensor_shape() };
266  shape_interleaved_a.set(0, a.dimension(0) * interleave_width);
267  if(reinterpret_input_as_3d)
268  {
269  const int M = a.dimension(1) * a.dimension(2);
270  const int height = std::ceil(M / static_cast<float>(interleave_width));
271  shape_interleaved_a.set(1, height);
272 
273  // When the data format is NHWC and the shapes are Nx1x1
274  // the tensor shape num_dimensions is automatically set to 1 instead of 3.
275  // To avoid failures by removing a dimension that doesn't exist
276  // check if the number of dimensions is greater than 2.
277  if(shape_interleaved_a.num_dimensions() > 2)
278  {
279  shape_interleaved_a.remove_dimension(2);
280  }
281  }
282  else
283  {
284  shape_interleaved_a.set(1, std::ceil(a.dimension(1) / static_cast<float>(interleave_width)));
285  }
286 
287  return shape_interleaved_a;
288 }
unsigned int M
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:466

References ARM_COMPUTE_ERROR_ON, ITensorInfo::dimension(), M, TensorShape::set(), and ITensorInfo::tensor_shape().

Referenced by NEGEMMInterleave4x4Kernel::configure(), NEGEMMLowpMatrixMultiplyCore::configure(), and NEGEMM::validate().

◆ compute_lhs_reshaped_shape()

TensorShape arm_compute::misc::shape_calculator::compute_lhs_reshaped_shape ( const ITensorInfo a,
const GEMMLHSMatrixInfo lhs_info,
bool  reinterpret_input_as_3d = false 
)
inline

Calculate the Left Hand Side matrix reshaped shape.

Parameters
[in]aInput tensor info
[in]lhs_infoLeft Hand Side matrix information
[in]reinterpret_input_as_3d(Optional) Set to true if the input need to be interpreted as 3d
Returns
the calculated shape

Definition at line 180 of file ShapeCalculator.h.

181 {
182  ARM_COMPUTE_ERROR_ON(lhs_info.m0 == 0);
183  ARM_COMPUTE_ERROR_ON(lhs_info.k0 == 0);
184  ARM_COMPUTE_ERROR_ON(lhs_info.v0 == 0);
185 
186  // Input width/height
187  const unsigned int input_width = a.dimension(0);
188  const unsigned int input_height = reinterpret_input_as_3d ? a.dimension(1) * a.dimension(2) : a.dimension(1);
189 
190  // Number of horizontal/vertical blocks in the input tensor
191  const unsigned int num_horiz_blocks = std::ceil(input_width / static_cast<float>(lhs_info.k0));
192  const unsigned int num_vert_blocks = std::ceil(input_height / static_cast<float>(lhs_info.m0));
193 
194  // Block size
195  const unsigned int block_size = lhs_info.m0 * lhs_info.k0;
196 
197  // Output width/height
198  const unsigned int output_width = block_size * num_horiz_blocks * lhs_info.v0;
199  const unsigned int output_height = std::ceil(num_vert_blocks / static_cast<float>(lhs_info.v0));
200 
201  TensorShape lhs_shape{ a.tensor_shape() };
202  lhs_shape.set(0, output_width);
203  lhs_shape.set(1, output_height);
204 
205  if((reinterpret_input_as_3d) && (lhs_shape.num_dimensions() > 2))
206  {
207  // When the data format is NHWC and the shapes are Nx1x1
208  // the tensor shape num_dimensions is automatically set to 1 instead of 3.
209  // To avoid failures by removing a dimension that doesn't exist
210  // check if the number of dimensions is greater than 2.
211  lhs_shape.remove_dimension(2);
212  }
213 
214  return lhs_shape;
215 }
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:466
const size_t input_width
const size_t input_height

References ARM_COMPUTE_ERROR_ON, ITensorInfo::dimension(), input_height, input_width, GEMMLHSMatrixInfo::k0, GEMMLHSMatrixInfo::m0, TensorShape::remove_dimension(), TensorShape::set(), ITensorInfo::tensor_shape(), and GEMMLHSMatrixInfo::v0.

◆ compute_min_max_shape()

TensorShape arm_compute::misc::shape_calculator::compute_min_max_shape ( const ITensorInfo input)
inline

Calculate the min/max shape output shape of a tensor.

Parameters
[in]inputInput tensor info
Returns
the calculated shape

Definition at line 743 of file ShapeCalculator.h.

744 {
745  TensorShape output_shape{ input->tensor_shape() };
746  output_shape.set(Window::DimX, 2);
749 
750  return output_shape;
751 }
void remove_dimension(size_t n)
Accessor to remove the dimension n from the tensor shape.
Definition: TensorShape.h:111
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.
Definition: TensorShape.h:79

References Window::DimX, arm_compute::test::validation::input, arm_compute::test::validation::output_shape, TensorShape::remove_dimension(), and TensorShape::set().

◆ compute_mm_shape() [1/3]

TensorShape arm_compute::misc::shape_calculator::compute_mm_shape ( const ITensorInfo input0,
const ITensorInfo input1,
bool  is_interleaved_transposed,
const GEMMReshapeInfo reshape_info 
)
inline

Calculate the matrix multiplication output shape of two tensors.

Parameters
[in]input0First input tensor info
[in]input1Second input tensor info
[in]is_interleaved_transposedTrue if the input is interleaved transposed
[in]reshape_infoGEMM reshape info
Returns
the calculated shape

Definition at line 862 of file ShapeCalculator.h.

863 {
864  ARM_COMPUTE_ERROR_ON_MSG(input0.num_dimensions() > 4, "The number of dimensions for the matrix A must be <= 4");
865  ARM_COMPUTE_ERROR_ON_MSG(is_interleaved_transposed && reshape_info.reinterpret_input_as_3d(), "The first input tensor cannot be reinterpreted as 3D if is_interleaved_transposed is true");
866 
867  const bool reinterpret_input_as_3d = reshape_info.reinterpret_input_as_3d();
868  const bool reinterpret_output_as_3d = reshape_info.depth_output_gemm3d() != 0;
869  const int depth_output_gemm3d = reinterpret_output_as_3d ? reshape_info.depth_output_gemm3d() : 1;
870  const int m = reshape_info.reinterpret_input_as_3d() ? input0.dimension(1) * input0.dimension(2) : input0.dimension(1);
871 
872  // If the output of GEMM has to be reinterpreted as 3D, the number of input0 rows (M) is obtained collapsing the second and third
873  // dimension of the output tensor
874  const int dim0 = is_interleaved_transposed ? reshape_info.n() : input1.dimension(0);
875  const int dim1 = is_interleaved_transposed ? reshape_info.m() / depth_output_gemm3d : m / depth_output_gemm3d;
876  const int dim2 = reinterpret_input_as_3d ? input0.tensor_shape()[3] : input0.tensor_shape()[2];
877  const int dim3 = reinterpret_input_as_3d ? 1 : input0.tensor_shape()[3];
878 
879  TensorShape output_shape{ input0.tensor_shape() };
880 
881  output_shape.set(0, dim0);
882  output_shape.set(1, dim1);
883  output_shape.set(2, reinterpret_output_as_3d ? depth_output_gemm3d : dim2);
884  output_shape.set(3, reinterpret_output_as_3d ? dim2 : dim3);
885  output_shape.set(4, reinterpret_output_as_3d ? dim3 : 1);
886 
887  return output_shape;
888 }
#define ARM_COMPUTE_ERROR_ON_MSG(cond, msg)
Definition: Error.h:456
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.
Definition: TensorShape.h:79

References ARM_COMPUTE_ERROR_ON_MSG, GEMMReshapeInfo::depth_output_gemm3d(), ITensorInfo::dimension(), GEMMReshapeInfo::m(), GEMMReshapeInfo::n(), ITensorInfo::num_dimensions(), arm_compute::test::validation::output_shape, GEMMReshapeInfo::reinterpret_input_as_3d(), TensorShape::set(), and ITensorInfo::tensor_shape().

Referenced by NEGEMM::validate(), and CLGEMMLowpMatrixMultiplyCore::validate().

◆ compute_mm_shape() [2/3]

TensorShape arm_compute::misc::shape_calculator::compute_mm_shape ( const ITensorInfo input0,
const ITensorInfo input1,
const GEMMReshapeInfo gemm_info 
)
inline

Calculate the matrix multiplication output shape of two tensors.

Parameters
[in]input0First input tensor info
[in]input1Second input tensor info
[in]gemm_infoGEMM reshape info
Returns
the calculated shape

Definition at line 898 of file ShapeCalculator.h.

899 {
900  ARM_COMPUTE_UNUSED(input1);
901  ARM_COMPUTE_ERROR_ON_MSG(input0.num_dimensions() > 4, "The number of dimensions for the matrix A must be <= 4");
902 
903  const bool reinterpret_input_as_3d = gemm_info.reinterpret_input_as_3d();
904  const bool reinterpret_output_as_3d = gemm_info.depth_output_gemm3d() != 0;
905  const int depth_output_gemm3d = reinterpret_output_as_3d ? gemm_info.depth_output_gemm3d() : 1;
906 
907  TensorShape output_shape{ input0.tensor_shape() };
908 
909  if(!reinterpret_input_as_3d && !reinterpret_output_as_3d)
910  {
911  output_shape.set(0, gemm_info.n());
912  output_shape.set(1, gemm_info.m());
913  }
914  else
915  {
916  // If the output of GEMM has to be reinterpreted as 3D, the number of input0 rows (M) is obtained collapsing the second and third
917  // dimension of the output tensor
918  const int batch_size = reinterpret_input_as_3d ? input0.tensor_shape()[3] : input0.tensor_shape()[2];
919  output_shape.set(0, gemm_info.n());
920  output_shape.set(1, gemm_info.m() / depth_output_gemm3d);
921  output_shape.set(2, reinterpret_output_as_3d ? depth_output_gemm3d : batch_size);
922  output_shape.set(3, reinterpret_output_as_3d ? batch_size : 1);
923  }
924 
925  return output_shape;
926 }
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
Definition: Error.h:152
#define ARM_COMPUTE_ERROR_ON_MSG(cond, msg)
Definition: Error.h:456
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.
Definition: TensorShape.h:79

References ARM_COMPUTE_ERROR_ON_MSG, ARM_COMPUTE_UNUSED, GEMMReshapeInfo::depth_output_gemm3d(), GEMMReshapeInfo::m(), GEMMReshapeInfo::n(), ITensorInfo::num_dimensions(), arm_compute::test::validation::output_shape, GEMMReshapeInfo::reinterpret_input_as_3d(), TensorShape::set(), and ITensorInfo::tensor_shape().

◆ compute_mm_shape() [3/3]

TensorShape arm_compute::misc::shape_calculator::compute_mm_shape ( const ITensorInfo input0,
const ITensorInfo input1,
const GEMMKernelInfo gemm_info 
)
inline

Calculate the matrix multiplication output shape of two tensors.

Parameters
[in]input0First input tensor info
[in]input1Second input tensor info
[in]gemm_infoGEMM kernel info used to retrieve the original dimensions of the input matrices
Returns
the calculated shape

Definition at line 936 of file ShapeCalculator.h.

937 {
938  ARM_COMPUTE_UNUSED(input1);
939  ARM_COMPUTE_ERROR_ON_MSG(input0.num_dimensions() > 4, "The number of dimensions for the matrix A must be <= 4");
940 
941  const bool reinterpret_input_as_3d = gemm_info.reinterpret_input_as_3d;
942  const bool reinterpret_output_as_3d = gemm_info.depth_output_gemm3d != 0;
943  const unsigned int depth_output_gemm3d = reinterpret_output_as_3d ? gemm_info.depth_output_gemm3d : 1;
944 
945  TensorShape output_shape{ input0.tensor_shape() };
946 
947  if(!reinterpret_input_as_3d && !reinterpret_output_as_3d)
948  {
949  output_shape.set(0, gemm_info.n);
950  output_shape.set(1, gemm_info.m);
951  }
952  else
953  {
954  // If the output of GEMM has to be reinterpreted as 3D, the number of input0 rows (M) is obtained collapsing the second and third
955  // dimension of the output tensor
956  const unsigned int batch_size = reinterpret_input_as_3d ? input0.tensor_shape()[3] : input0.tensor_shape()[2];
957  output_shape.set(0, gemm_info.n);
958  output_shape.set(1, gemm_info.m / depth_output_gemm3d);
959  output_shape.set(2, reinterpret_output_as_3d ? depth_output_gemm3d : batch_size);
960  output_shape.set(3, reinterpret_output_as_3d ? batch_size : 1);
961  }
962 
963  return output_shape;
964 }
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
Definition: Error.h:152
#define ARM_COMPUTE_ERROR_ON_MSG(cond, msg)
Definition: Error.h:456
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.
Definition: TensorShape.h:79

References ARM_COMPUTE_ERROR_ON_MSG, ARM_COMPUTE_UNUSED, GEMMKernelInfo::depth_output_gemm3d, GEMMKernelInfo::m, GEMMKernelInfo::n, ITensorInfo::num_dimensions(), arm_compute::test::validation::output_shape, GEMMKernelInfo::reinterpret_input_as_3d, TensorShape::set(), and ITensorInfo::tensor_shape().

◆ compute_output_stage_shape()

TensorShape arm_compute::misc::shape_calculator::compute_output_stage_shape ( const ITensorInfo input,
unsigned int  gemm_3d_depth = 1,
bool  batch_size_on_z = false 
)
inline

Calculate the matrix multiplication output shape of two tensors.

Parameters
[in]inputInput tensor info
[in]gemm_3d_depth(Optional) GEMM 3d depth
[in]batch_size_on_z(Optional) True if batch size is on z axis
Returns
the calculated shape

Definition at line 974 of file ShapeCalculator.h.

975 {
976  ARM_COMPUTE_ERROR_ON(input.data_layout() != DataLayout::NHWC && gemm_3d_depth > 1);
977 
978  TensorShape output_shape = input.tensor_shape();
979  if(gemm_3d_depth > 1)
980  {
981  if(batch_size_on_z)
982  {
984  }
985  output_shape.set(0, input.tensor_shape().x());
986  output_shape.set(1, input.tensor_shape().y() / gemm_3d_depth);
987  output_shape.set(2, gemm_3d_depth);
988  }
989 
990  return output_shape;
991 }
void shift_right(size_t step)
Shifts right the tensor shape increasing its dimensions.
Definition: TensorShape.h:144
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:466
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.
Definition: TensorShape.h:79

References ARM_COMPUTE_ERROR_ON, arm_compute::test::validation::input, arm_compute::NHWC, arm_compute::test::validation::output_shape, TensorShape::set(), and TensorShape::shift_right().

◆ compute_padded_shape()

TensorShape arm_compute::misc::shape_calculator::compute_padded_shape ( const TensorShape input_shape,
const PaddingList padding 
)
inline

Calculate the padded shape of a tensor.

Parameters
[in]input_shapeInput tensor shape
[in]paddingPaddings list
Returns
the calculated shape

Definition at line 1192 of file ShapeCalculator.h.

1193 {
1194  TensorShape padded_shape = input_shape;
1195  for(size_t dim = 0; dim < padding.size(); ++dim)
1196  {
1197  const auto &padding_pair = padding[dim];
1198  const uint32_t shape_on_index = (padded_shape.num_dimensions() <= dim) ? 1 : input_shape[dim];
1199  padded_shape.set(dim, padding_pair.first + shape_on_index + padding_pair.second);
1200  }
1201  return padded_shape;
1202 }
TensorShape input_shape
Validate test suite is to test ARM_COMPUTE_RETURN_ON_* macros we use to check the validity of given a...
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.
Definition: TensorShape.h:79

References arm_compute::test::validation::input_shape, Dimensions< T >::num_dimensions(), and TensorShape::set().

Referenced by NEPadLayerKernel::configure(), CLPadLayerKernel::configure(), NEPadLayer::configure(), arm_compute::test::validation::reference::pad_layer(), and NEPadLayer::validate().

◆ compute_permutation_output_shape()

TensorShape arm_compute::misc::shape_calculator::compute_permutation_output_shape ( const ITensorInfo input,
const PermutationVector perm 
)
inline

Calculate the permuted shape of an input given a permutation vector.

Parameters
[in]inputInput tensor info
[in]permPermutation vector
Returns
the calculated shape

Definition at line 108 of file ShapeCalculator.h.

109 {
110  TensorShape output_shape = input.tensor_shape();
111  permute(output_shape, perm);
112  return output_shape;
113 }
void permute(Dimensions< T > &dimensions, const PermutationVector &perm)
Permutes given Dimensions according to a permutation vector.
Definition: Helpers.h:125

References arm_compute::test::validation::input, arm_compute::test::validation::output_shape, and arm_compute::permute().

Referenced by CpuPermuteKernel::configure(), CPPPermuteKernel::configure(), ClSoftmax::validate(), and CpuSoftmaxGeneric< IS_LOG >::validate().

◆ compute_pool_shape()

TensorShape arm_compute::misc::shape_calculator::compute_pool_shape ( const ITensorInfo input,
PoolingLayerInfo  pool_info 
)
inline

Calculate the output pool shape of a tensor.

Parameters
[in]inputInput tensor info
[in]pool_infoPooling layer info
Returns
the calculated shape

Definition at line 760 of file ShapeCalculator.h.

761 {
762  unsigned int pooled_w = 0;
763  unsigned int pooled_h = 0;
764 
765  TensorShape output_shape{ input.tensor_shape() };
766 
767  const bool is_global_pooling = pool_info.is_global_pooling;
768  const unsigned int idx_width = get_data_layout_dimension_index(input.data_layout(), DataLayoutDimension::WIDTH);
769  const unsigned int idx_height = get_data_layout_dimension_index(input.data_layout(), DataLayoutDimension::HEIGHT);
770  const unsigned int pool_size_x = is_global_pooling ? output_shape[idx_width] : pool_info.pool_size.width;
771  const unsigned int pool_size_y = is_global_pooling ? output_shape[idx_height] : pool_info.pool_size.height;
772 
773  std::tie(pooled_w, pooled_h) = scaled_dimensions(output_shape[idx_width],
775  pool_size_x,
776  pool_size_y,
777  pool_info.pad_stride_info);
778 
779  output_shape.set(idx_width, pooled_w);
780  output_shape.set(idx_height, pooled_h);
781 
782  return output_shape;
783 }
std::pair< unsigned int, unsigned int > scaled_dimensions(int width, int height, int kernel_width, int kernel_height, const PadStrideInfo &pad_stride_info, const Size2D &dilation=Size2D(1U, 1U))
Returns expected width and height of output scaled tensor depending on dimensions rounding mode.
Definition: Utils.cpp:395
size_t get_data_layout_dimension_index(const DataLayout data_layout, const DataLayoutDimension data_layout_dimension)
Get the index of the given dimension.
Definition: Helpers.inl:193
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.
Definition: TensorShape.h:79

References arm_compute::get_data_layout_dimension_index(), Size2D::height, arm_compute::HEIGHT, arm_compute::test::validation::idx_height, arm_compute::test::validation::idx_width, arm_compute::test::validation::input, PoolingLayerInfo::is_global_pooling, arm_compute::test::validation::output_shape, PoolingLayerInfo::pad_stride_info, PoolingLayerInfo::pool_size, arm_compute::scaled_dimensions(), TensorShape::set(), Size2D::width, and arm_compute::WIDTH.

Referenced by CpuPoolingAssemblyWrapperKernel::configure(), and arm_compute::test::validation::reference::pooling_layer_internal().

◆ compute_prior_box_shape()

TensorShape arm_compute::misc::shape_calculator::compute_prior_box_shape ( const ITensorInfo input,
const PriorBoxLayerInfo info 
)
inline

Calculate the prior box output shape of a tensor.

Parameters
[in]inputInput tensor info
[in]infoPriorBoxLayer info
Returns
the calculated shape

Definition at line 1171 of file ShapeCalculator.h.

1172 {
1173  DataLayout data_layout = input.data_layout();
1174  const size_t idx_w = get_data_layout_dimension_index(data_layout, DataLayoutDimension::WIDTH);
1175  const size_t idx_h = get_data_layout_dimension_index(data_layout, DataLayoutDimension::HEIGHT);
1176  const int num_priors = info.aspect_ratios().size() * info.min_sizes().size() + info.max_sizes().size();
1177 
1178  TensorShape output_shape{};
1179  output_shape.set(0, input.dimension(idx_w) * input.dimension(idx_h) * num_priors * 4);
1180  output_shape.set(1, 2);
1181 
1182  return output_shape;
1183 }
const DataLayout data_layout
Definition: Im2Col.cpp:151
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)
size_t get_data_layout_dimension_index(const DataLayout data_layout, const DataLayoutDimension data_layout_dimension)
Get the index of the given dimension.
Definition: Helpers.inl:193
DataLayout
[DataLayout enum definition]
Definition: Types.h:114
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.
Definition: TensorShape.h:79

References arm_compute::test::validation::data_layout, arm_compute::get_data_layout_dimension_index(), arm_compute::HEIGHT, arm_compute::test::validation::info, arm_compute::test::validation::input, arm_compute::test::validation::output_shape, TensorShape::set(), and arm_compute::WIDTH.

◆ compute_reduced_shape()

TensorShape arm_compute::misc::shape_calculator::compute_reduced_shape ( const TensorShape input,
unsigned int  axis,
bool  keep_dims = true 
)
inline

Calculate the reduced shape of a tensor given an axis.

Parameters
[in]inputInput tensor info
[in]axisAxis on which to perform reduction
[in]keep_dims(Optional) Whether to keep the dimension after reduction operation. Defaults to true.
Returns
the calculated shape

Definition at line 1229 of file ShapeCalculator.h.

1230 {
1231  TensorShape output_shape{ input };
1232 
1233  if(!keep_dims)
1234  {
1236  }
1237  else
1238  {
1239  output_shape.set(axis, 1);
1240  }
1241 
1242  return output_shape;
1243 }
void remove_dimension(size_t n)
Accessor to remove the dimension n from the tensor shape.
Definition: TensorShape.h:111
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.
Definition: TensorShape.h:79

References arm_compute::test::validation::input, arm_compute::test::validation::output_shape, TensorShape::remove_dimension(), and TensorShape::set().

Referenced by NEReductionOperationKernel::configure(), CLReductionOperationKernel::configure(), NEReductionOperation::configure(), CLReductionOperation::configure(), CLArgMinMaxLayer::configure(), ReductionLayerNode::configure_output(), ArgMinMaxLayerNode::configure_output(), NEReductionOperation::validate(), CLArgMinMaxLayer::validate(), and CLReductionOperation::validate().

◆ compute_reductionA_shape()

TensorShape arm_compute::misc::shape_calculator::compute_reductionA_shape ( const ITensorInfo b)
inline

Calculate the reductionA shape used in GEMMLowp.

Parameters
[in]bInput tensor info
Returns
the calculated shape

Definition at line 333 of file ShapeCalculator.h.

334 {
335  TensorShape shape_vector_sum_col{ b.tensor_shape() };
336  if(shape_vector_sum_col.num_dimensions() > 1)
337  {
338  shape_vector_sum_col.remove_dimension(1);
339  }
340 
341  return shape_vector_sum_col;
342 }
SimpleTensor< float > b
Definition: DFT.cpp:157

References arm_compute::test::validation::b.

Referenced by NEGEMMLowpMatrixMultiplyCore::configure(), CLGEMMLowpMatrixMultiplyCore::configure(), NEGEMMLowpMatrixMultiplyCore::validate(), and CLGEMMLowpMatrixMultiplyCore::validate().

◆ compute_reductionB_shape()

TensorShape arm_compute::misc::shape_calculator::compute_reductionB_shape ( const ITensorInfo a)
inline

Calculate the reductionB shape used in GEMMLowp.

Parameters
[in]aInput tensor info
Returns
the calculated shape

Definition at line 350 of file ShapeCalculator.h.

351 {
352  TensorShape shape_vector_sum_row{ a.tensor_shape() };
353  shape_vector_sum_row.set(Window::DimX, a.dimension(1));
354  if(shape_vector_sum_row.num_dimensions() > 1)
355  {
356  shape_vector_sum_row.remove_dimension(1);
357  }
358 
359  return shape_vector_sum_row;
360 }

References ITensorInfo::dimension(), Window::DimX, TensorShape::remove_dimension(), TensorShape::set(), and ITensorInfo::tensor_shape().

Referenced by NEGEMMLowpMatrixMultiplyCore::configure(), CLGEMMLowpMatrixMultiplyCore::configure(), NEGEMMLowpMatrixMultiplyCore::validate(), and CLGEMMLowpMatrixMultiplyCore::validate().

◆ compute_reorg_output_shape()

TensorShape arm_compute::misc::shape_calculator::compute_reorg_output_shape ( const ITensorInfo input,
int32_t  stride 
)
inline

Calculate the output shape of the reorg layer given a stride.

Parameters
[in]inputInput tensor info
[in]strideStride
Returns
the calculated shape

Definition at line 122 of file ShapeCalculator.h.

123 {
124  const size_t idx_width = get_data_layout_dimension_index(input.data_layout(), DataLayoutDimension::WIDTH);
125  const size_t idx_height = get_data_layout_dimension_index(input.data_layout(), DataLayoutDimension::HEIGHT);
126  const size_t idx_channel = get_data_layout_dimension_index(input.data_layout(), DataLayoutDimension::CHANNEL);
127 
128  ARM_COMPUTE_ERROR_ON(stride <= 0);
129  ARM_COMPUTE_ERROR_ON_MSG((input.tensor_shape()[idx_width] % stride != 0), "The width of the input tensor must be a multiple of stride");
130  ARM_COMPUTE_ERROR_ON_MSG((input.tensor_shape()[idx_height] % stride != 0), "The height of the input tensor must be a multiple of stride");
131 
132  TensorShape output_shape{ input.tensor_shape() };
133 
136  output_shape.set(idx_channel, output_shape[idx_channel] * stride * stride);
137 
138  return output_shape;
139 }
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:466
#define ARM_COMPUTE_ERROR_ON_MSG(cond, msg)
Definition: Error.h:456
size_t get_data_layout_dimension_index(const DataLayout data_layout, const DataLayoutDimension data_layout_dimension)
Get the index of the given dimension.
Definition: Helpers.inl:193
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.
Definition: TensorShape.h:79

References ARM_COMPUTE_ERROR_ON, ARM_COMPUTE_ERROR_ON_MSG, arm_compute::CHANNEL, arm_compute::get_data_layout_dimension_index(), arm_compute::HEIGHT, arm_compute::test::validation::idx_height, arm_compute::test::validation::idx_width, arm_compute::test::validation::input, arm_compute::test::validation::output_shape, TensorShape::set(), and arm_compute::WIDTH.

Referenced by NEReorgLayerKernel::configure(), CLReorgLayerKernel::configure(), and arm_compute::test::validation::reference::reorg_layer().

◆ compute_rhs_reshaped_shape()

TensorShape arm_compute::misc::shape_calculator::compute_rhs_reshaped_shape ( const ITensorInfo a,
const GEMMRHSMatrixInfo rhs_info 
)
inline

Calculate the Right Hand Side matrix reshaped shape.

Parameters
[in]aInput tensor info
[in]rhs_infoRight Hand Side matrix information
Returns
the calculated shape

Definition at line 224 of file ShapeCalculator.h.

225 {
226  ARM_COMPUTE_ERROR_ON(rhs_info.n0 == 0);
227  ARM_COMPUTE_ERROR_ON(rhs_info.k0 == 0);
228  ARM_COMPUTE_ERROR_ON(rhs_info.h0 == 0);
229 
230  // Input width/height
231  const unsigned int input_width = a.dimension(0);
232  const unsigned int input_height = a.dimension(1);
233 
234  // Number of horizontal/vertical blocks in the input tensor
235  const unsigned int num_horiz_blocks = std::ceil(input_width / static_cast<float>(rhs_info.n0));
236  const unsigned int num_vert_blocks = std::ceil(input_height / static_cast<float>(rhs_info.k0));
237 
238  // Block size
239  const unsigned int block_size = rhs_info.n0 * rhs_info.k0;
240 
241  // Output width/height
242  const unsigned int output_width = block_size * num_vert_blocks * rhs_info.h0;
243  const unsigned int output_height = std::ceil(num_horiz_blocks / static_cast<float>(rhs_info.h0));
244 
245  TensorShape rhs_shape{ a.tensor_shape() };
246  rhs_shape.set(0, output_width);
247  rhs_shape.set(1, output_height);
248 
249  return rhs_shape;
250 }
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:466
const size_t input_width
const size_t input_height

References ARM_COMPUTE_ERROR_ON, ITensorInfo::dimension(), GEMMRHSMatrixInfo::h0, input_height, input_width, GEMMRHSMatrixInfo::k0, GEMMRHSMatrixInfo::n0, TensorShape::set(), and ITensorInfo::tensor_shape().

Referenced by arm_compute::cl_gemm::select_lhs_rhs_info(), and CLGEMMLowpMatrixMultiplyCore::validate().

◆ compute_rnn_shape()

TensorShape arm_compute::misc::shape_calculator::compute_rnn_shape ( const ITensorInfo input,
const unsigned int  batch_size 
)
inline

Calculate the RNN shape of a tensor.

Parameters
[in]inputInput tensor info
[in]batch_sizeBatch size
Returns
the calculated shape

Definition at line 845 of file ShapeCalculator.h.

846 {
847  TensorShape output_shape{ input->tensor_shape() };
848  output_shape.set(1, batch_size);
849 
850  return output_shape;
851 }
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.
Definition: TensorShape.h:79

References arm_compute::test::validation::input, arm_compute::test::validation::output_shape, and TensorShape::set().

Referenced by NERNNLayer::configure(), CLRNNLayer::configure(), NERNNLayer::validate(), and CLRNNLayer::validate().

◆ compute_roi_align_shape()

TensorShape arm_compute::misc::shape_calculator::compute_roi_align_shape ( const ITensorInfo input,
const ITensorInfo rois,
ROIPoolingLayerInfo  pool_info 
)
inline

Calculate the output roi align shape of a tensor.

Parameters
[in]inputInput tensor info
[in]roisRois tensor info
[in]pool_infoPooling layer info
Returns
the calculated shape

Definition at line 824 of file ShapeCalculator.h.

825 {
826  TensorShape output_shape{ input.tensor_shape() };
827 
828  const unsigned int idx_width = get_data_layout_dimension_index(input.data_layout(), DataLayoutDimension::WIDTH);
829  const unsigned int idx_height = get_data_layout_dimension_index(input.data_layout(), DataLayoutDimension::HEIGHT);
830 
831  output_shape.set(idx_width, pool_info.pooled_width());
832  output_shape.set(idx_height, pool_info.pooled_height());
833  output_shape.set(3, rois.dimension(1));
834 
835  return output_shape;
836 }
size_t get_data_layout_dimension_index(const DataLayout data_layout, const DataLayoutDimension data_layout_dimension)
Get the index of the given dimension.
Definition: Helpers.inl:193
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.
Definition: TensorShape.h:79

References ITensorInfo::dimension(), arm_compute::get_data_layout_dimension_index(), arm_compute::HEIGHT, arm_compute::test::validation::idx_height, arm_compute::test::validation::idx_width, arm_compute::test::validation::input, arm_compute::test::validation::output_shape, ROIPoolingLayerInfo::pooled_height(), ROIPoolingLayerInfo::pooled_width(), TensorShape::set(), and arm_compute::WIDTH.

Referenced by NEROIAlignLayerKernel::configure(), and CLROIAlignLayerKernel::configure().

◆ compute_slice_shape()

TensorShape arm_compute::misc::shape_calculator::compute_slice_shape ( const TensorShape input_shape,
const Coordinates starts,
const Coordinates ends 
)
inline

Calculate the slice output shape of a tensor.

Parameters
[in]input_shapeInput tensor info
[in]startsThe starts of the dimensions of the input tensor to be sliced
[in]endsThe ends of the dimensions of the input tensor to be sliced
Returns
the calculated shape

Definition at line 1021 of file ShapeCalculator.h.

1022 {
1024 
1026  starts, ends, BiStrides(),
1027  0, construct_slice_end_mask(ends), 0);
1028 }
Coordinates BiStrides
Bidirectional strides.
Definition: Types.h:51
int32_t construct_slice_end_mask(Coordinates ends)
Constructs end mask in case we want to perform a slice operation using the strided slice interface.
TensorShape input_shape
Validate test suite is to test ARM_COMPUTE_RETURN_ON_* macros we use to check the validity of given a...
TensorShape compute_strided_slice_output_shape(TensorShape input_shape, Coordinates starts, Coordinates ends, Coordinates strides, int32_t begin_mask=0, int32_t end_mask=0, int32_t shrink_axis_mask=0, bool return_unshrinked=false)
Computes output shape of strided slice.

References arm_compute::helpers::tensor_transform::compute_strided_slice_output_shape(), arm_compute::helpers::tensor_transform::construct_slice_end_mask(), and arm_compute::test::validation::input_shape.

Referenced by SliceLayerNode::compute_output_descriptor(), and arm_compute::test::validation::reference::slice().

◆ compute_softmax_shape()

TensorShape arm_compute::misc::shape_calculator::compute_softmax_shape ( const ITensorInfo input,
size_t  axis = 1 
)
inline

Calculate the softmax output shape of a tensor.

Parameters
[in]inputInput tensor info
[in]axis(Optional) Softmax axis
Returns
the calculated shape

Definition at line 578 of file ShapeCalculator.h.

579 {
580  // The output shape will be a 2D version of the input. For instance:
581  // - [x,y,z] and axis 1 will return [x, y*z]
582  // - [x,y,z,w] and axis 2 will return [x*y, w*z]
583  // - [x,y,z,w] and axis 3 will return [x*y*z, w]
584  TensorShape shape2D = input->tensor_shape();
585 
586  if(axis < input->num_dimensions())
587  {
588  // Collapse from axis onward (this changes the shape)
589  shape2D.collapse_from(axis);
590 
591  // Collapse the rest (collapse is inclusive)
592  shape2D.collapse(shape2D.num_dimensions() - 1);
593  }
594  else
595  {
596  // Collapse everything
597  shape2D.collapse(shape2D.num_dimensions());
598  }
599 
600  if(axis == 0)
601  {
602  // If axis is zero the first dim should be one. Since
603  // collapse is an inclusive operation we need to shift
604  shape2D.shift_right(1);
605  }
606 
607  return shape2D;
608 }

References TensorShape::collapse(), Dimensions< T >::collapse_from(), arm_compute::test::validation::input, Dimensions< T >::num_dimensions(), and TensorShape::shift_right().

◆ compute_space_to_batch_shape()

TensorShape arm_compute::misc::shape_calculator::compute_space_to_batch_shape ( const ITensorInfo input,
const int  block_x,
const int  block_y,
const Size2D padding_left,
const Size2D padding_right 
)
inline

Calculate the space to batch output shape of a tensor.

Parameters
[in]inputInput tensor info
[in]block_xBlock shape x value
[in]block_yBlock shape y value
[in]padding_leftLeft padding values
[in]padding_rightRight padding values
Returns
the calculated shape

Definition at line 1122 of file ShapeCalculator.h.

1123 {
1124  TensorShape output_shape{ input->tensor_shape() };
1125 
1126  const DataLayout data_layout = input->data_layout();
1127  const int idx_width = get_data_layout_dimension_index(data_layout, DataLayoutDimension::WIDTH);
1128  const int idx_height = get_data_layout_dimension_index(data_layout, DataLayoutDimension::HEIGHT);
1129  const int idx_batch = get_data_layout_dimension_index(data_layout, DataLayoutDimension::BATCHES);
1130 
1131  ARM_COMPUTE_ERROR_ON((input->tensor_shape()[idx_width] + padding_left.x() + padding_right.x()) % block_x != 0);
1132  ARM_COMPUTE_ERROR_ON((input->tensor_shape()[idx_height] + padding_left.y() + padding_right.y()) % block_y != 0);
1133 
1134  output_shape.set(idx_width, (input->tensor_shape()[idx_width] + padding_left.x() + padding_right.x()) / block_x);
1135  output_shape.set(idx_height, (input->tensor_shape()[idx_height] + padding_left.y() + padding_right.y()) / block_y);
1136  output_shape.set(idx_batch, input->tensor_shape()[idx_batch] * block_x * block_y);
1137 
1138  return output_shape;
1139 }
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:466
const DataLayout data_layout
Definition: Im2Col.cpp:151
size_t get_data_layout_dimension_index(const DataLayout data_layout, const DataLayoutDimension data_layout_dimension)
Get the index of the given dimension.
Definition: Helpers.inl:193
DataLayout
[DataLayout enum definition]
Definition: Types.h:114
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.
Definition: TensorShape.h:79

References ARM_COMPUTE_ERROR_ON, arm_compute::BATCHES, arm_compute::test::validation::data_layout, arm_compute::get_data_layout_dimension_index(), arm_compute::HEIGHT, arm_compute::test::validation::idx_height, arm_compute::test::validation::idx_width, arm_compute::test::validation::input, arm_compute::test::validation::output_shape, TensorShape::set(), arm_compute::WIDTH, Size2D::x(), and Size2D::y().

Referenced by NESpaceToBatchLayerKernel::configure(), and CLSpaceToBatchLayerKernel::configure().

◆ compute_space_to_depth_shape()

TensorShape arm_compute::misc::shape_calculator::compute_space_to_depth_shape ( const ITensorInfo input,
int32_t  block_shape 
)
inline

Calculate the space to batch output shape of a tensor.

Parameters
[in]inputInput tensor info
[in]block_shapeBlock shape value
Returns
the calculated shape

Definition at line 1148 of file ShapeCalculator.h.

1149 {
1150  TensorShape output_shape{ input->tensor_shape() };
1151 
1152  const DataLayout data_layout = input->data_layout();
1153  const int idx_width = get_data_layout_dimension_index(data_layout, DataLayoutDimension::WIDTH);
1154  const int idx_height = get_data_layout_dimension_index(data_layout, DataLayoutDimension::HEIGHT);
1155  const int idx_depth = get_data_layout_dimension_index(data_layout, DataLayoutDimension::CHANNEL);
1156 
1157  output_shape.set(idx_width, input->tensor_shape()[idx_width] * block_shape);
1158  output_shape.set(idx_height, input->tensor_shape()[idx_height] * block_shape);
1159  output_shape.set(idx_depth, input->tensor_shape()[idx_depth] / (block_shape * block_shape));
1160 
1161  return output_shape;
1162 }
const DataLayout data_layout
Definition: Im2Col.cpp:151
size_t get_data_layout_dimension_index(const DataLayout data_layout, const DataLayoutDimension data_layout_dimension)
Get the index of the given dimension.
Definition: Helpers.inl:193
DataLayout
[DataLayout enum definition]
Definition: Types.h:114
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.
Definition: TensorShape.h:79

References arm_compute::CHANNEL, arm_compute::test::validation::data_layout, arm_compute::get_data_layout_dimension_index(), arm_compute::HEIGHT, arm_compute::test::validation::idx_height, arm_compute::test::validation::idx_width, arm_compute::test::validation::input, arm_compute::test::validation::output_shape, TensorShape::set(), and arm_compute::WIDTH.

Referenced by NESpaceToDepthLayerKernel::configure(), and CLSpaceToDepthLayerKernel::configure().

◆ compute_split_shape()

TensorShape arm_compute::misc::shape_calculator::compute_split_shape ( const ITensorInfo input,
unsigned int  axis,
unsigned int  num_splits 
)
inline

Calculate the split output shape of a tensor.

Parameters
[in]inputInput tensor info
[in]axisAxis on which to split the input
[in]num_splitsNumber of splits
Returns
the calculated shape

Definition at line 1087 of file ShapeCalculator.h.

1088 {
1089  TensorShape empty_shape;
1090  empty_shape.set(0, 0);
1091 
1092  TensorShape out_shape{ input->tensor_shape() };
1093 
1094  // Return empty shape if axis is invalid
1095  if(axis > input->tensor_shape().num_dimensions())
1096  {
1097  return empty_shape;
1098  }
1099 
1100  size_t axis_size = out_shape[axis];
1101 
1102  // Return empty shape if num_split is not valid
1103  if(axis_size % num_splits)
1104  {
1105  return empty_shape;
1106  }
1107 
1108  out_shape[axis] = axis_size / num_splits;
1109  return out_shape;
1110 }

References arm_compute::test::validation::input, and TensorShape::set().

Referenced by CPPSplit< CLSlice, ICLTensor >::configure(), and CPPSplit< CLSlice, ICLTensor >::validate().

◆ compute_stack_shape()

TensorShape arm_compute::misc::shape_calculator::compute_stack_shape ( const ITensorInfo a,
unsigned int  axis,
unsigned int  num_tensors 
)
inline

Calculate the stack output shape of a tensor.

Parameters
[in]aInput tensor info
[in]axisAxis on which to perform the stack operation
[in]num_tensorsNumber of tensors to stack
Returns
the calculated shape

Definition at line 1362 of file ShapeCalculator.h.

1363 {
1364  ARM_COMPUTE_ERROR_ON(axis > a.num_dimensions());
1365  ARM_COMPUTE_ERROR_ON(a.num_dimensions() > 4);
1366 
1367  TensorShape shape_out{ a.tensor_shape() };
1368  shape_out.set(axis, num_tensors);
1369 
1370  unsigned int i_shift = 0;
1371 
1372  for(unsigned int i = 0; i < a.num_dimensions(); ++i)
1373  {
1374  if(i == axis)
1375  {
1376  i_shift++;
1377  }
1378 
1379  shape_out.set(i + i_shift, a.tensor_shape()[i]);
1380  }
1381  return shape_out;
1382 }
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:466

References ARM_COMPUTE_ERROR_ON, ITensorInfo::num_dimensions(), TensorShape::set(), and ITensorInfo::tensor_shape().

Referenced by StackLayerNode::compute_output_descriptor().

◆ compute_strided_slice_shape()

TensorShape arm_compute::misc::shape_calculator::compute_strided_slice_shape ( const ITensorInfo input,
const Coordinates starts,
const Coordinates ends,
const Coordinates strides,
int32_t  begin_mask,
int32_t  end_mask,
int32_t  shrink_axis_mask 
)
inline

Calculate the strided slice output shape of a tensor.

Parameters
[in]inputInput tensor info
[in]startsThe starts of the dimensions of the input tensor to be sliced
[in]endsThe ends of the dimensions of the input tensor to be sliced
[in]stridesThe strides of the dimensions of the input tensor to be sliced
[in]begin_maskIf the ith bit of begin_mask is set, starts[i] is ignored and the fullest possible range in that dimension is used instead.
[in]end_maskIf the ith bit of end_mask is set, ends[i] is ignored and the fullest possible range in that dimension is used instead.
[in]shrink_axis_maskIf the ith bit of shrink_axis_mask is set, it implies that the ith specification shrinks the dimensionality by 1
Returns
the calculated shape

Definition at line 1005 of file ShapeCalculator.h.

1008 {
1010  return compute_strided_slice_output_shape(input.tensor_shape(), starts, ends, strides, begin_mask, end_mask, shrink_axis_mask);
1011 }
TensorShape compute_strided_slice_output_shape(TensorShape input_shape, Coordinates starts, Coordinates ends, Coordinates strides, int32_t begin_mask=0, int32_t end_mask=0, int32_t shrink_axis_mask=0, bool return_unshrinked=false)
Computes output shape of strided slice.

References arm_compute::helpers::tensor_transform::compute_strided_slice_output_shape(), and arm_compute::test::validation::input.

Referenced by CLStridedSliceKernel::configure().

◆ compute_tiled_shape()

TensorShape arm_compute::misc::shape_calculator::compute_tiled_shape ( const TensorShape input_shape,
const Multiples multiples 
)
inline

Calculate the tiled shape of a tensor.

Parameters
[in]input_shapeInput tensor shape
[in]multiplesPaddings list
Returns
the calculated shape

Definition at line 1211 of file ShapeCalculator.h.

1212 {
1213  TensorShape tiled_shape = input_shape;
1214  for(size_t dim = 0; dim < multiples.size(); ++dim)
1215  {
1216  tiled_shape.set(dim, input_shape[dim] * multiples[dim]);
1217  }
1218  return tiled_shape;
1219 }
TensorShape input_shape
Validate test suite is to test ARM_COMPUTE_RETURN_ON_* macros we use to check the validity of given a...
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.
Definition: TensorShape.h:79

References arm_compute::test::validation::input_shape, and TensorShape::set().

Referenced by NETileKernel::configure(), CLTileKernel::configure(), and arm_compute::test::validation::reference::tile().

◆ compute_transpose1xW_shape()

TensorShape arm_compute::misc::shape_calculator::compute_transpose1xW_shape ( const ITensorInfo b)
inline

Calculate the transposed 1xW shape.

Parameters
[in]bInput tensor info
Returns
the calculated shape

Definition at line 296 of file ShapeCalculator.h.

297 {
298  // The transpose1xW output matrix will have the following shape: [ b_height * 16, ceil(b_width / 16.0f) ]
299  TensorShape shape_transposed1xW_b{ b.tensor_shape() };
300  shape_transposed1xW_b.set(0, b.dimension(1) * 16);
301  shape_transposed1xW_b.set(1, std::ceil(b.dimension(0) / 16.f));
302 
303  return shape_transposed1xW_b;
304 }
SimpleTensor< float > b
Definition: DFT.cpp:157

References arm_compute::test::validation::b.

Referenced by NEGEMMLowpMatrixMultiplyCore::configure().

◆ compute_transpose1xW_with_element_size_shape()

TensorShape arm_compute::misc::shape_calculator::compute_transpose1xW_with_element_size_shape ( const ITensorInfo b,
int  mult_transpose1xW_width = 1 
)
inline

Calculate the transposed 1xW width element shape.

Parameters
[in]bInput tensor info
[in]mult_transpose1xW_width(Optional) Transpose1xW width
Returns
the calculated shape

Definition at line 313 of file ShapeCalculator.h.

314 {
315  // Note: mult_transpose1xW_width expresses the number of chunks with size 1x(W) we want to store on the same row
316  // The transpose1xW output matrix will have the following shape:
317  // [ b_height * W, ceil(b_width / W) ] where W = (16 / element size of the tensor) * mult_transpose1xW_width
318  ARM_COMPUTE_ERROR_ON(mult_transpose1xW_width < 1);
319  TensorShape shape_transposed1xW_b{ b.tensor_shape() };
320  const size_t transpose_width = (16 / b.element_size()) * mult_transpose1xW_width;
321  shape_transposed1xW_b.set(0, b.dimension(1) * transpose_width);
322  shape_transposed1xW_b.set(1, static_cast<size_t>(std::ceil(b.dimension(0) / static_cast<float>(transpose_width))));
323 
324  return shape_transposed1xW_b;
325 }
SimpleTensor< float > b
Definition: DFT.cpp:157
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:466

References ARM_COMPUTE_ERROR_ON, and arm_compute::test::validation::b.

Referenced by NEGEMM::validate().

◆ compute_transposed_shape()

TensorShape arm_compute::misc::shape_calculator::compute_transposed_shape ( const ITensorInfo input)
inline

Calculate the transposed shape of a tensor.

Parameters
[in]inputInput tensor info
Returns
the calculated shape

Definition at line 402 of file ShapeCalculator.h.

403 {
404  TensorShape shape_transposed{ input.tensor_shape() };
405 
406  shape_transposed.set(0, input.dimension(1));
407  shape_transposed.set(1, input.dimension(0));
408 
409  return shape_transposed;
410 }

References arm_compute::test::validation::input.

Referenced by CpuTransposeKernel::configure(), ClTransposeKernel::configure(), NELSTMLayer::configure(), CLLSTMLayer::configure(), CpuTransposeKernel::validate(), ClTransposeKernel::validate(), NEFullyConnectedLayer::validate(), NELSTMLayer::validate(), CLFullyConnectedLayer::validate(), and CLLSTMLayer::validate().

◆ compute_unpool_shape()

TensorShape arm_compute::misc::shape_calculator::compute_unpool_shape ( const ITensorInfo input,
PoolingLayerInfo  pool_info 
)
inline

Calculate the output unpool shape of a tensor.

Parameters
[in]inputInput tensor info
[in]pool_infoPooling layer info
Returns
the calculated shape

Definition at line 792 of file ShapeCalculator.h.

793 {
794  const unsigned int idx_width = get_data_layout_dimension_index(input.data_layout(), DataLayoutDimension::WIDTH);
795  const unsigned int idx_height = get_data_layout_dimension_index(input.data_layout(), DataLayoutDimension::HEIGHT);
796  const TensorShape input_shape = input.tensor_shape();
798  const PadStrideInfo pad_stride_info = pool_info.pad_stride_info;
799  const unsigned int stride_x = pad_stride_info.stride().first;
800  const unsigned int stride_y = pad_stride_info.stride().second;
801 
802  const int pad_left = pad_stride_info.pad_left();
803  const int pad_top = pad_stride_info.pad_top();
804  const int pad_right = pad_stride_info.pad_right();
805  const int pad_bottom = pad_stride_info.pad_bottom();
806 
807  TensorShape output_shape = input_shape;
808  const unsigned int out_width = (input_shape[idx_width] - 1) * stride_x - pad_left - pad_right + pool_info.pool_size.width;
809  const unsigned int out_height = (input_shape[idx_height] - 1) * stride_y - pad_top - pad_bottom + pool_info.pool_size.height;
810 
811  output_shape.set(idx_width, out_width);
812  output_shape.set(idx_height, out_height);
813  return output_shape;
814 }
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:466
TensorShape input_shape
Validate test suite is to test ARM_COMPUTE_RETURN_ON_* macros we use to check the validity of given a...
size_t get_data_layout_dimension_index(const DataLayout data_layout, const DataLayoutDimension data_layout_dimension)
Get the index of the given dimension.
Definition: Helpers.inl:193
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.
Definition: TensorShape.h:79

References ARM_COMPUTE_ERROR_ON, arm_compute::get_data_layout_dimension_index(), Size2D::height, arm_compute::HEIGHT, arm_compute::test::validation::idx_height, arm_compute::test::validation::idx_width, arm_compute::test::validation::input, arm_compute::test::validation::input_shape, arm_compute::test::validation::output_shape, PadStrideInfo::pad_bottom(), PadStrideInfo::pad_left(), PadStrideInfo::pad_right(), PoolingLayerInfo::pad_stride_info, PadStrideInfo::pad_top(), PoolingLayerInfo::pool_size, TensorShape::set(), PadStrideInfo::stride(), Size2D::width, and arm_compute::WIDTH.

Referenced by CLMaxUnpoolingLayerKernel::configure(), and NEMaxUnpoolingLayerKernel::configure().

◆ compute_upsample_shape()

TensorShape arm_compute::misc::shape_calculator::compute_upsample_shape ( const ITensorInfo input,
const Size2D info 
)
inline

Calculate the upsampled shape of a tensor.

Parameters
[in]inputInput tensor info
[in]infoContains stride information (x and y)
Returns
the calculated shape

Definition at line 1252 of file ShapeCalculator.h.

1253 {
1254  const DataLayout data_layout = input.data_layout();
1255  const int idx_width = get_data_layout_dimension_index(data_layout, DataLayoutDimension::WIDTH);
1256  const int idx_height = get_data_layout_dimension_index(data_layout, DataLayoutDimension::HEIGHT);
1257 
1258  TensorShape scale_out_shape(input.tensor_shape());
1259  const unsigned int out_x = input.dimension(idx_width) * info.x();
1260  const unsigned int out_y = input.dimension(idx_height) * info.y();
1261  scale_out_shape.set(idx_width, out_x);
1262  scale_out_shape.set(idx_height, out_y);
1263 
1264  return scale_out_shape;
1265 }
const DataLayout data_layout
Definition: Im2Col.cpp:151
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)
size_t get_data_layout_dimension_index(const DataLayout data_layout, const DataLayoutDimension data_layout_dimension)
Get the index of the given dimension.
Definition: Helpers.inl:193
DataLayout
[DataLayout enum definition]
Definition: Types.h:114

References arm_compute::test::validation::data_layout, arm_compute::get_data_layout_dimension_index(), arm_compute::HEIGHT, arm_compute::test::validation::idx_height, arm_compute::test::validation::idx_width, arm_compute::test::validation::info, arm_compute::test::validation::input, and arm_compute::WIDTH.

◆ compute_vector_to_tensor_output_shape()

TensorShape arm_compute::misc::shape_calculator::compute_vector_to_tensor_output_shape ( const TensorShape input,
size_t  conv_w,
size_t  conv_h,
const DataLayout data_layout 
)
inline

Calculate the output tensor shape of a vector input given the convolution dimensions.

Parameters
[in]inputInput tensor shape
[in]conv_wConvolution width
[in]conv_hConvolution height
[in]data_layoutData layout
Returns
the calculated shape

Definition at line 87 of file ShapeCalculator.h.

88 {
89  const size_t idx_w = get_data_layout_dimension_index(data_layout, DataLayoutDimension::WIDTH);
90  const size_t idx_h = get_data_layout_dimension_index(data_layout, DataLayoutDimension::HEIGHT);
91  const size_t idx_c = get_data_layout_dimension_index(data_layout, DataLayoutDimension::CHANNEL);
92 
93  TensorShape output_shape(input);
94  output_shape.set(idx_w, conv_w);
95  output_shape.set(idx_h, conv_h);
96  output_shape.set(idx_c, input.x() / (conv_w * conv_h));
97 
98  return output_shape;
99 }
const DataLayout data_layout
Definition: Im2Col.cpp:151
size_t get_data_layout_dimension_index(const DataLayout data_layout, const DataLayoutDimension data_layout_dimension)
Get the index of the given dimension.
Definition: Helpers.inl:193
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.
Definition: TensorShape.h:79

References arm_compute::CHANNEL, arm_compute::test::validation::data_layout, arm_compute::get_data_layout_dimension_index(), arm_compute::HEIGHT, arm_compute::test::validation::input, arm_compute::test::validation::output_shape, TensorShape::set(), and arm_compute::WIDTH.

◆ compute_weights_reshaped_shape()

TensorShape arm_compute::misc::shape_calculator::compute_weights_reshaped_shape ( const ITensorInfo weights,
bool  has_bias = false,
unsigned int  num_groups = 1 
)
inline

Calculate the reshaped shape of the weights.

Parameters
[in]weightsWeights tensor info
[in]has_bias(Optional) Set to true if there is bias
[in]num_groups(Optional) Number of groups
Returns
the calculated shape of the reshaped weights

Definition at line 149 of file ShapeCalculator.h.

150 {
151  // Number of groups greater than one are only supported for NCHW data layout, and the number of weights must be a multiple of it.
153  ARM_COMPUTE_ERROR_ON(weights.data_layout() == DataLayout::NHWC && num_groups > 1);
154  ARM_COMPUTE_ERROR_ON((weights.dimension(3) % num_groups) != 0);
155 
156  // Calculate output shape
157  TensorShape weights_reshaped{ weights.tensor_shape() };
158  weights_reshaped.set(3, weights_reshaped[3] / num_groups);
159 
160  weights_reshaped.collapse(3);
161  const size_t tmp_dim = weights_reshaped[0];
162  weights_reshaped.set(0, weights_reshaped[1]);
163  weights_reshaped.set(1, tmp_dim + (has_bias ? 1 : 0));
164  if(weights.num_dimensions() < 5)
165  {
166  weights_reshaped.set(2, num_groups);
167  }
168 
169  return weights_reshaped;
170 }
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:466
const unsigned int num_groups
Definition: Im2Col.cpp:153

References ARM_COMPUTE_ERROR_ON, TensorShape::collapse(), ITensorInfo::data_layout(), ITensorInfo::dimension(), arm_compute::test::validation::has_bias, arm_compute::NHWC, ITensorInfo::num_dimensions(), arm_compute::test::validation::num_groups, TensorShape::set(), and ITensorInfo::tensor_shape().

Referenced by CLWeightsReshapeKernel::configure(), NEGEMMConvolutionLayer::validate(), and CLGEMMConvolutionLayer::validate().

◆ compute_winograd_filter_transform_shape()

TensorShape arm_compute::misc::shape_calculator::compute_winograd_filter_transform_shape ( const ITensorInfo input,
const WinogradInfo winograd_info 
)
inline

Calculate the winograd filter transform shape.

Parameters
[in]inputInput tensor info
[in]winograd_infoWinograd information
Returns
the calculated shape

Definition at line 617 of file ShapeCalculator.h.

618 {
619  TensorShape tensor_shape{ input.tensor_shape() };
620 
621  const Size2D kernel_size = winograd_info.kernel_size;
622  const Size2D output_tile_size = winograd_info.output_tile_size;
623  const Size2D input_tile_size = Size2D(output_tile_size.width + kernel_size.width - 1, output_tile_size.height + kernel_size.height - 1);
624 
625  tensor_shape.remove_dimension(get_data_layout_dimension_index(input.data_layout(), DataLayoutDimension::WIDTH));
626  tensor_shape.set(Window::DimX, input.dimension(3));
627  tensor_shape.set(Window::DimY, input.dimension(get_data_layout_dimension_index(input.data_layout(), DataLayoutDimension::CHANNEL)));
628  tensor_shape.set(Window::DimZ, input_tile_size.area());
629 
630  return tensor_shape;
631 }
size_t get_data_layout_dimension_index(const DataLayout data_layout, const DataLayoutDimension data_layout_dimension)
Get the index of the given dimension.
Definition: Helpers.inl:193

References Size2D::area(), arm_compute::CHANNEL, Window::DimX, Window::DimY, Window::DimZ, arm_compute::get_data_layout_dimension_index(), Size2D::height, arm_compute::test::validation::input, Size2D::width, arm_compute::WIDTH, and arm_compute::test::validation::winograd_info.

Referenced by CLWinogradFilterTransformKernel::configure(), NEWinogradConvolutionLayer::validate(), and CLWinogradConvolutionLayer::validate().

◆ compute_winograd_input_transform_shape()

TensorShape arm_compute::misc::shape_calculator::compute_winograd_input_transform_shape ( const ITensorInfo input,
const WinogradInfo winograd_info 
)
inline

Calculate the winograd input transform shape.

Parameters
[in]inputInput tensor info
[in]winograd_infoWinograd information
Returns
the calculated shape

Definition at line 640 of file ShapeCalculator.h.

641 {
642  const PadStrideInfo conv_info = winograd_info.convolution_info;
643  const Size2D kernel_size = winograd_info.kernel_size;
644  const Size2D output_tile_size = winograd_info.output_tile_size;
645  const Size2D input_tile_size = Size2D(output_tile_size.width + kernel_size.width - 1, output_tile_size.height + kernel_size.height - 1);
646 
647  const size_t idx_w = get_data_layout_dimension_index(input.data_layout(), DataLayoutDimension::WIDTH);
648  const size_t idx_h = get_data_layout_dimension_index(input.data_layout(), DataLayoutDimension::HEIGHT);
649  const size_t idx_c = get_data_layout_dimension_index(input.data_layout(), DataLayoutDimension::CHANNEL);
650 
651  // Compute the number of output tiles along the x and y direction of size "output_tile_size"
652  const Size2D num_tiles = compute_winograd_convolution_tiles(Size2D(input.tensor_shape()[idx_w], input.tensor_shape()[idx_h]),
653  kernel_size,
654  output_tile_size,
655  conv_info);
656 
657  const unsigned int width = input.tensor_shape()[idx_c];
658  const unsigned int height = num_tiles.area();
659  const unsigned int depth = input_tile_size.area();
660 
661  TensorShape output_shape{ input.tensor_shape() };
662  output_shape.set(0, width);
663  output_shape.set(1, height);
664  output_shape.set(2, depth);
665 
666  return output_shape;
667 }
Size2D compute_winograd_convolution_tiles(const Size2D &in_dims, const Size2D &kernel_size, const Size2D &output_tile_size, const PadStrideInfo &conv_info)
Calculate the number of output tiles required by Winograd Convolution layer.
Definition: Helpers.h:211
size_t get_data_layout_dimension_index(const DataLayout data_layout, const DataLayoutDimension data_layout_dimension)
Get the index of the given dimension.
Definition: Helpers.inl:193
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.
Definition: TensorShape.h:79

References Size2D::area(), arm_compute::CHANNEL, arm_compute::compute_winograd_convolution_tiles(), arm_compute::test::validation::conv_info, arm_compute::get_data_layout_dimension_index(), Size2D::height, arm_compute::HEIGHT, arm_compute::test::validation::input, arm_compute::test::validation::output_shape, TensorShape::set(), Size2D::width, arm_compute::WIDTH, and arm_compute::test::validation::winograd_info.

Referenced by CLWinogradInputTransformKernel::configure(), NEWinogradConvolutionLayer::validate(), and CLWinogradConvolutionLayer::validate().

◆ compute_winograd_output_transform_shape()

TensorShape arm_compute::misc::shape_calculator::compute_winograd_output_transform_shape ( const ITensorInfo input,
const WinogradInfo winograd_info 
)
inline

Calculate the winograd output transform shape.

Parameters
[in]inputInput tensor info
[in]winograd_infoWinograd information
Returns
the calculated shape

Definition at line 676 of file ShapeCalculator.h.

677 {
678  const PadStrideInfo conv_info = winograd_info.convolution_info;
679  const Size2D kernel_size = winograd_info.kernel_size;
680  const Size2D input_dimensions = winograd_info.input_dimensions;
681  const DataLayout data_layout = winograd_info.output_data_layout;
682 
683  // Compute output shape
684  unsigned int output_width = 0;
685  unsigned int output_height = 0;
686  std::tie(output_width, output_height) = scaled_dimensions(input_dimensions.width, input_dimensions.height,
687  kernel_size.width, kernel_size.height, conv_info);
688 
689  TensorShape tensor_shape{ input.tensor_shape() };
690 
691  // Output dimension
692  const unsigned int out_w = output_width;
693  const unsigned int out_h = output_height;
694  const unsigned int out_c = input.dimension(0);
695 
696  tensor_shape.set(get_data_layout_dimension_index(data_layout, DataLayoutDimension::WIDTH), out_w);
697  tensor_shape.set(get_data_layout_dimension_index(data_layout, DataLayoutDimension::HEIGHT), out_h);
698  tensor_shape.set(get_data_layout_dimension_index(data_layout, DataLayoutDimension::CHANNEL), out_c);
699 
700  return tensor_shape;
701 }
const DataLayout data_layout
Definition: Im2Col.cpp:151
std::pair< unsigned int, unsigned int > scaled_dimensions(int width, int height, int kernel_width, int kernel_height, const PadStrideInfo &pad_stride_info, const Size2D &dilation=Size2D(1U, 1U))
Returns expected width and height of output scaled tensor depending on dimensions rounding mode.
Definition: Utils.cpp:395
size_t get_data_layout_dimension_index(const DataLayout data_layout, const DataLayoutDimension data_layout_dimension)
Get the index of the given dimension.
Definition: Helpers.inl:193
DataLayout
[DataLayout enum definition]
Definition: Types.h:114

References arm_compute::CHANNEL, arm_compute::test::validation::conv_info, arm_compute::test::validation::data_layout, arm_compute::get_data_layout_dimension_index(), Size2D::height, arm_compute::HEIGHT, arm_compute::test::validation::input, arm_compute::scaled_dimensions(), Size2D::width, arm_compute::WIDTH, and arm_compute::test::validation::winograd_info.

Referenced by CLWinogradOutputTransformKernel::configure().

◆ extract_shape() [1/5]

TensorShape arm_compute::misc::shape_calculator::extract_shape ( T *  data)
inline

Get the tensor shape.

Parameters
[in]dataInput data
Returns
the extracted tensor shape

Definition at line 1274 of file ShapeCalculator.h.

1275 {
1276  return data->info()->tensor_shape();
1277 }

Referenced by calculate_concatenate_shape().

◆ extract_shape() [2/5]

TensorShape arm_compute::misc::shape_calculator::extract_shape ( ITensorInfo data)
inline

Definition at line 1279 of file ShapeCalculator.h.

1280 {
1281  return data->tensor_shape();
1282 }

References ITensorInfo::tensor_shape().

◆ extract_shape() [3/5]

TensorShape arm_compute::misc::shape_calculator::extract_shape ( const ITensorInfo data)
inline

Definition at line 1283 of file ShapeCalculator.h.

1284 {
1285  return data->tensor_shape();
1286 }

References ITensorInfo::tensor_shape().

◆ extract_shape() [4/5]

TensorShape arm_compute::misc::shape_calculator::extract_shape ( const TensorShape data)
inline

Definition at line 1288 of file ShapeCalculator.h.

1289 {
1290  return *data;
1291 }

◆ extract_shape() [5/5]

TensorShape arm_compute::misc::shape_calculator::extract_shape ( TensorShape data)
inline

Definition at line 1293 of file ShapeCalculator.h.

1294 {
1295  return *data;
1296 }