Compute Library
 21.08
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 1322 of file ShapeCalculator.h.

References ARM_COMPUTE_ERROR_ON, extract_shape(), 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().

1323 {
1324  TensorShape out_shape = extract_shape(input[0]);
1325 
1326 #if defined(ARM_COMPUTE_ASSERTS_ENABLED)
1327  // All dimensions must match except the axis one
1328  for(unsigned int i = 0; i < MAX_DIMS; ++i)
1329  {
1330  if(i == axis)
1331  {
1332  continue;
1333  }
1334 
1335  for(const auto &tensor : input)
1336  {
1337  ARM_COMPUTE_ERROR_ON(tensor == nullptr);
1338  const TensorShape shape = extract_shape(tensor);
1339  ARM_COMPUTE_ERROR_ON(out_shape[i] != shape[i]);
1340  }
1341  }
1342 #endif // defined(ARM_COMPUTE_ASSERTS_ENABLED)
1343 
1344  // Calculate output shape
1345  size_t new_size = 0;
1346  for(const auto &tensor : input)
1347  {
1348  const TensorShape shape = extract_shape(tensor);
1349  new_size += shape[axis];
1350  }
1351 
1352  out_shape.set(axis, new_size);
1353 
1354  return out_shape;
1355 }
#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)

◆ 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.

References Dimensions< T >::begin(), arm_compute::convert_negative_axis(), Dimensions< T >::num_dimensions(), ITensorInfo::num_dimensions(), TensorShape::remove_dimension(), TensorShape::set(), and ITensorInfo::tensor_shape().

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

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

◆ 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 1307 of file ShapeCalculator.h.

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

1308 {
1311  return input_shape;
1312 }
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

◆ 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 1040 of file ShapeCalculator.h.

References ARM_COMPUTE_ERROR_ON, arm_compute::BATCHES, arm_compute::test::validation::data_layout, ITensorInfo::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::output_shape, TensorShape::set(), ITensorInfo::tensor_shape(), and arm_compute::WIDTH.

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

1041 {
1042  ARM_COMPUTE_ERROR_ON(block_x <= 0 || block_y <= 0);
1043 
1044  const DataLayout data_layout = input->data_layout();
1045  const int idx_width = get_data_layout_dimension_index(data_layout, DataLayoutDimension::WIDTH);
1046  const int idx_height = get_data_layout_dimension_index(data_layout, DataLayoutDimension::HEIGHT);
1047  const int idx_batch = get_data_layout_dimension_index(data_layout, DataLayoutDimension::BATCHES);
1048 
1049  TensorShape output_shape{ input->tensor_shape() };
1050  output_shape.set(idx_width, input->tensor_shape()[idx_width] * block_x);
1051  output_shape.set(idx_height, input->tensor_shape()[idx_height] * block_y);
1052  output_shape.set(idx_batch, input->tensor_shape()[idx_batch] / (block_x * block_y));
1053 
1054  return output_shape;
1055 }
#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: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

◆ 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.

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

Referenced by CpuCol2ImKernel::configure().

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:111

◆ 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.

References arm_compute::BATCHES, 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::input_shape, TensorShape::set(), ITensorInfo::tensor_shape(), and arm_compute::WIDTH.

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

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: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

◆ 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.

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

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

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:111

◆ 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.

References arm_compute::CHANNEL, ITensorInfo::data_layout(), arm_compute::get_data_layout_dimension_index(), arm_compute::HEIGHT, arm_compute::test::validation::idx_height, arm_compute::test::validation::idx_width, 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 CpuDirectConv2dKernel::configure(), and arm_compute::test::validation::DATA_TEST_CASE().

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 }
const size_t weights_height
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 size_t input_width
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 weights_width
const size_t input_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

◆ 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 1065 of file ShapeCalculator.h.

References ARM_COMPUTE_ERROR_ON, 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::output_shape, TensorShape::set(), and arm_compute::WIDTH.

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

1066 {
1067  ARM_COMPUTE_ERROR_ON(block < 2);
1068 
1069  const int idx_width = get_data_layout_dimension_index(data_layout, DataLayoutDimension::WIDTH);
1070  const int idx_height = get_data_layout_dimension_index(data_layout, DataLayoutDimension::HEIGHT);
1071  const int idx_channel = get_data_layout_dimension_index(data_layout, DataLayoutDimension::CHANNEL);
1072 
1073  TensorShape output_shape{ input_shape };
1074  output_shape.set(idx_width, input_shape[idx_width] * block);
1075  output_shape.set(idx_height, input_shape[idx_height] * block);
1076  output_shape.set(idx_channel, input_shape[idx_channel] / (block * block));
1077 
1078  return output_shape;
1079 }
#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

◆ 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.

References arm_compute::CHANNEL, arm_compute::test::validation::data_layout, ITensorInfo::data_layout(), ConvolutionInfo::depth_multiplier, ConvolutionInfo::dilation, arm_compute::get_data_layout_dimension_index(), arm_compute::HEIGHT, arm_compute::test::validation::input_shape, arm_compute::test::validation::output_shape, ConvolutionInfo::pad_stride_info, arm_compute::scaled_dimensions(), TensorShape::set(), ITensorInfo::tensor_shape(), and arm_compute::WIDTH.

Referenced by CpuDepthwiseConv2dNativeKernel::configure(), CpuDepthwiseConv2dAssemblyWrapperKernel::configure(), CLDepthwiseConvolutionLayerNativeKernel::configure(), CpuDepthwiseConv2dAssemblyWrapperKernel::validate(), and CLDepthwiseConvolutionLayer::validate().

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: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

◆ 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.

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

Referenced by NEFlattenLayer::configure(), CLFlattenLayer::configure(), NEFlattenLayer::validate(), CLFlattenLayer::validate(), ClFullyConnected::validate(), and CpuFullyConnected::validate().

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

◆ 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 1386 of file ShapeCalculator.h.

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().

1387 {
1388  ARM_COMPUTE_ERROR_ON(indices_shape.num_dimensions() > 1);
1391 
1392  TensorShape output_shape = input_shape;
1393  output_shape[actual_axis] = indices_shape[0];
1394 
1395  return output_shape;
1396 }
#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

◆ 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.

References Size2D::area(), ARM_COMPUTE_ERROR_ON, arm_compute::CHANNEL, arm_compute::test::validation::data_layout, ITensorInfo::data_layout(), arm_compute::get_data_layout_dimension_index(), Size2D::height, arm_compute::HEIGHT, 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(), ITensorInfo::tensor_shape(), Size2D::width, and arm_compute::WIDTH.

Referenced by CpuIm2ColKernel::configure(), and ClGemmConvolution::validate().

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: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

◆ 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.

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

Referenced by CpuGemmInterleave4x4Kernel::configure(), CpuGemmLowpMatrixMultiplyCore::configure(), CpuGemmInterleave4x4Kernel::validate(), and CpuGemm::validate().

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 }
#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
unsigned int M

◆ 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.

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.

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

◆ 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.

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

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

◆ 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 864 of file ShapeCalculator.h.

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 ClGemmLowpMatrixMultiplyCore::validate(), and CpuGemm::validate().

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

◆ 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 900 of file ShapeCalculator.h.

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().

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

◆ 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 938 of file ShapeCalculator.h.

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().

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

◆ 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 976 of file ShapeCalculator.h.

References ARM_COMPUTE_ERROR_ON, ITensorInfo::data_layout(), arm_compute::NHWC, arm_compute::test::validation::output_shape, TensorShape::shift_right(), ITensorInfo::tensor_shape(), Dimensions< T >::x(), and Dimensions< T >::y().

977 {
978  ARM_COMPUTE_ERROR_ON(input.data_layout() != DataLayout::NHWC && gemm_3d_depth > 1);
979 
980  TensorShape output_shape = input.tensor_shape();
981  if(gemm_3d_depth > 1)
982  {
983  if(batch_size_on_z)
984  {
985  output_shape.shift_right(1);
986  }
987  output_shape.set(0, input.tensor_shape().x());
988  output_shape.set(1, input.tensor_shape().y() / gemm_3d_depth);
989  output_shape.set(2, gemm_3d_depth);
990  }
991 
992  return output_shape;
993 }
#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

◆ 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 1194 of file ShapeCalculator.h.

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().

1195 {
1196  TensorShape padded_shape = input_shape;
1197  for(size_t dim = 0; dim < padding.size(); ++dim)
1198  {
1199  const auto &padding_pair = padding[dim];
1200  const uint32_t shape_on_index = (padded_shape.num_dimensions() <= dim) ? 1 : input_shape[dim];
1201  padded_shape.set(dim, padding_pair.first + shape_on_index + padding_pair.second);
1202  }
1203  return padded_shape;
1204 }
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

◆ 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.

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

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

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

◆ 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.

References ARM_COMPUTE_ERROR_ON_MSG, ITensorInfo::data_layout(), arm_compute::get_data_layout_dimension_index(), Size2D::height, arm_compute::HEIGHT, arm_compute::test::validation::idx_height, arm_compute::test::validation::idx_width, input_height, input_width, PoolingLayerInfo::is_global_pooling, arm_compute::test::validation::output_shape, PoolingLayerInfo::pad_stride_info, PoolingLayerInfo::pool_size, arm_compute::scaled_dimensions_signed(), TensorShape::set(), ITensorInfo::tensor_shape(), Size2D::width, and arm_compute::WIDTH.

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

761 {
762  int pooled_w = 0;
763  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 int idx_width = get_data_layout_dimension_index(input.data_layout(), DataLayoutDimension::WIDTH);
769  const int idx_height = get_data_layout_dimension_index(input.data_layout(), DataLayoutDimension::HEIGHT);
770  const int input_width = input.tensor_shape()[idx_width];
771  const int input_height = input.tensor_shape()[idx_height];
772  const int pool_size_x = is_global_pooling ? output_shape[idx_width] : pool_info.pool_size.width;
773  const int pool_size_y = is_global_pooling ? output_shape[idx_height] : pool_info.pool_size.height;
774 
775  std::tie(pooled_w, pooled_h) = scaled_dimensions_signed(input_width, input_height,
776  pool_size_x, pool_size_y,
777  pool_info.pad_stride_info);
778 
779  ARM_COMPUTE_ERROR_ON_MSG((pooled_w < 1 || pooled_h < 1), "Calculated output dimension size is invalid");
780 
781  output_shape.set(idx_width, static_cast<size_t>(pooled_w));
782  output_shape.set(idx_height, static_cast<size_t>(pooled_h));
783 
784  return output_shape;
785 }
std::pair< int, int > scaled_dimensions_signed(int width, int height, int kernel_width, int kernel_height, const PadStrideInfo &pad_stride_info)
Returns calculated width and height of output scaled tensor depending on dimensions rounding mode...
Definition: Utils.cpp:429
const size_t input_width
#define ARM_COMPUTE_ERROR_ON_MSG(cond, msg)
Definition: Error.h:456
const size_t input_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

◆ 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 1173 of file ShapeCalculator.h.

References PriorBoxLayerInfo::aspect_ratios(), arm_compute::test::validation::data_layout, ITensorInfo::data_layout(), ITensorInfo::dimension(), arm_compute::get_data_layout_dimension_index(), arm_compute::HEIGHT, PriorBoxLayerInfo::max_sizes(), PriorBoxLayerInfo::min_sizes(), arm_compute::test::validation::output_shape, TensorShape::set(), and arm_compute::WIDTH.

1174 {
1175  DataLayout data_layout = input.data_layout();
1176  const size_t idx_w = get_data_layout_dimension_index(data_layout, DataLayoutDimension::WIDTH);
1177  const size_t idx_h = get_data_layout_dimension_index(data_layout, DataLayoutDimension::HEIGHT);
1178  const int num_priors = info.aspect_ratios().size() * info.min_sizes().size() + info.max_sizes().size();
1179 
1180  TensorShape output_shape{};
1181  output_shape.set(0, input.dimension(idx_w) * input.dimension(idx_h) * num_priors * 4);
1182  output_shape.set(1, 2);
1183 
1184  return output_shape;
1185 }
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: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

◆ 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 1231 of file ShapeCalculator.h.

References 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(), arm_compute::test::validation::DATA_TEST_CASE(), NEReductionOperation::validate(), CLArgMinMaxLayer::validate(), and CLReductionOperation::validate().

1232 {
1233  TensorShape output_shape{ input };
1234 
1235  if(!keep_dims)
1236  {
1238  }
1239  else
1240  {
1241  output_shape.set(axis, 1);
1242  }
1243 
1244  return output_shape;
1245 }
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

◆ 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.

References TensorShape::remove_dimension(), and ITensorInfo::tensor_shape().

Referenced by ClGemmLowpMatrixMultiplyCore::configure(), CpuGemmLowpMatrixMultiplyCore::configure(), ClGemmLowpMatrixMultiplyCore::validate(), and CpuGemmLowpMatrixMultiplyCore::validate().

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

◆ 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.

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

Referenced by ClGemmLowpMatrixMultiplyCore::configure(), CpuGemmLowpMatrixMultiplyCore::configure(), ClGemmLowpMatrixMultiplyCore::validate(), and CpuGemmLowpMatrixMultiplyCore::validate().

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 }

◆ 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.

References ARM_COMPUTE_ERROR_ON, ARM_COMPUTE_ERROR_ON_MSG, arm_compute::CHANNEL, ITensorInfo::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::output_shape, TensorShape::set(), ITensorInfo::tensor_shape(), and arm_compute::WIDTH.

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

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 
134  output_shape.set(idx_width, output_shape[idx_width] / stride);
135  output_shape.set(idx_height, output_shape[idx_height] / stride);
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

◆ 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.

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 ClGemmDefaultConfigReshapedBifrost::configure(), ClGemmDefaultConfigReshapedRhsOnlyBifrost::configure(), arm_compute::test::validation::DATA_TEST_CASE(), arm_compute::opencl::kernels::gemm::select_lhs_rhs_info(), and ClGemmLowpMatrixMultiplyCore::validate().

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

◆ 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 847 of file ShapeCalculator.h.

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

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

848 {
849  TensorShape output_shape{ input->tensor_shape() };
850  output_shape.set(1, batch_size);
851 
852  return output_shape;
853 }
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

◆ 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 826 of file ShapeCalculator.h.

References ITensorInfo::data_layout(), 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::output_shape, ROIPoolingLayerInfo::pooled_height(), ROIPoolingLayerInfo::pooled_width(), TensorShape::set(), ITensorInfo::tensor_shape(), and arm_compute::WIDTH.

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

827 {
828  TensorShape output_shape{ input.tensor_shape() };
829 
830  const unsigned int idx_width = get_data_layout_dimension_index(input.data_layout(), DataLayoutDimension::WIDTH);
831  const unsigned int idx_height = get_data_layout_dimension_index(input.data_layout(), DataLayoutDimension::HEIGHT);
832 
833  output_shape.set(idx_width, pool_info.pooled_width());
834  output_shape.set(idx_height, pool_info.pooled_height());
835  output_shape.set(3, rois.dimension(1));
836 
837  return output_shape;
838 }
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

◆ 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 1023 of file ShapeCalculator.h.

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

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

1024 {
1026 
1028  starts, ends, BiStrides(),
1029  0, construct_slice_end_mask(ends), 0);
1030 }
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.

◆ 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.

References TensorShape::collapse(), Dimensions< T >::collapse_from(), Dimensions< T >::num_dimensions(), TensorShape::shift_right(), and ITensorInfo::tensor_shape().

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 }

◆ 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 1124 of file ShapeCalculator.h.

References ARM_COMPUTE_ERROR_ON, arm_compute::BATCHES, arm_compute::test::validation::data_layout, ITensorInfo::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::output_shape, TensorShape::set(), ITensorInfo::tensor_shape(), arm_compute::WIDTH, Size2D::x(), and Size2D::y().

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

1125 {
1126  TensorShape output_shape{ input->tensor_shape() };
1127 
1128  const DataLayout data_layout = input->data_layout();
1129  const int idx_width = get_data_layout_dimension_index(data_layout, DataLayoutDimension::WIDTH);
1130  const int idx_height = get_data_layout_dimension_index(data_layout, DataLayoutDimension::HEIGHT);
1131  const int idx_batch = get_data_layout_dimension_index(data_layout, DataLayoutDimension::BATCHES);
1132 
1133  ARM_COMPUTE_ERROR_ON((input->tensor_shape()[idx_width] + padding_left.x() + padding_right.x()) % block_x != 0);
1134  ARM_COMPUTE_ERROR_ON((input->tensor_shape()[idx_height] + padding_left.y() + padding_right.y()) % block_y != 0);
1135 
1136  output_shape.set(idx_width, (input->tensor_shape()[idx_width] + padding_left.x() + padding_right.x()) / block_x);
1137  output_shape.set(idx_height, (input->tensor_shape()[idx_height] + padding_left.y() + padding_right.y()) / block_y);
1138  output_shape.set(idx_batch, input->tensor_shape()[idx_batch] * block_x * block_y);
1139 
1140  return output_shape;
1141 }
#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: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

◆ 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 1150 of file ShapeCalculator.h.

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::idx_height, arm_compute::test::validation::idx_width, arm_compute::test::validation::output_shape, TensorShape::set(), ITensorInfo::tensor_shape(), and arm_compute::WIDTH.

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

1151 {
1152  TensorShape output_shape{ input->tensor_shape() };
1153 
1154  const DataLayout data_layout = input->data_layout();
1155  const int idx_width = get_data_layout_dimension_index(data_layout, DataLayoutDimension::WIDTH);
1156  const int idx_height = get_data_layout_dimension_index(data_layout, DataLayoutDimension::HEIGHT);
1157  const int idx_depth = get_data_layout_dimension_index(data_layout, DataLayoutDimension::CHANNEL);
1158 
1159  output_shape.set(idx_width, input->tensor_shape()[idx_width] * block_shape);
1160  output_shape.set(idx_height, input->tensor_shape()[idx_height] * block_shape);
1161  output_shape.set(idx_depth, input->tensor_shape()[idx_depth] / (block_shape * block_shape));
1162 
1163  return output_shape;
1164 }
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: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

◆ 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 1089 of file ShapeCalculator.h.

References Dimensions< T >::num_dimensions(), TensorShape::set(), and ITensorInfo::tensor_shape().

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

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

◆ 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 1364 of file ShapeCalculator.h.

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

Referenced by StackLayerNode::compute_output_descriptor().

1365 {
1366  ARM_COMPUTE_ERROR_ON(axis > a.num_dimensions());
1367  ARM_COMPUTE_ERROR_ON(a.num_dimensions() > 4);
1368 
1369  TensorShape shape_out{ a.tensor_shape() };
1370  shape_out.set(axis, num_tensors);
1371 
1372  unsigned int i_shift = 0;
1373 
1374  for(unsigned int i = 0; i < a.num_dimensions(); ++i)
1375  {
1376  if(i == axis)
1377  {
1378  i_shift++;
1379  }
1380 
1381  shape_out.set(i + i_shift, a.tensor_shape()[i]);
1382  }
1383  return shape_out;
1384 }
#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

◆ 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 1007 of file ShapeCalculator.h.

References arm_compute::helpers::tensor_transform::compute_strided_slice_output_shape(), and ITensorInfo::tensor_shape().

Referenced by CLStridedSliceKernel::configure().

1010 {
1012  return compute_strided_slice_output_shape(input.tensor_shape(), starts, ends, strides, begin_mask, end_mask, shrink_axis_mask);
1013 }
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.

◆ 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 1213 of file ShapeCalculator.h.

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

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

1214 {
1215  TensorShape tiled_shape = input_shape;
1216  for(size_t dim = 0; dim < multiples.size(); ++dim)
1217  {
1218  tiled_shape.set(dim, input_shape[dim] * multiples[dim]);
1219  }
1220  return tiled_shape;
1221 }
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

◆ 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.

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

Referenced by CpuGemmLowpMatrixMultiplyCore::configure().

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

◆ 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.

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

Referenced by CpuGemmTranspose1xWKernel::configure(), CpuGemmTranspose1xWKernel::validate(), and CpuGemm::validate().

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

◆ 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.

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

Referenced by CpuTransposeKernel::configure(), ClTransposeKernel::configure(), NELSTMLayer::configure(), CLLSTMLayer::configure(), CpuTransposeKernel::validate(), ClTransposeKernel::validate(), ClFullyConnected::validate(), CpuFullyConnected::validate(), NELSTMLayer::validate(), and CLLSTMLayer::validate().

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 }

◆ 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 794 of file ShapeCalculator.h.

References ARM_COMPUTE_ERROR_ON, ITensorInfo::data_layout(), 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_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(), ITensorInfo::tensor_shape(), Size2D::width, and arm_compute::WIDTH.

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

795 {
796  const unsigned int idx_width = get_data_layout_dimension_index(input.data_layout(), DataLayoutDimension::WIDTH);
797  const unsigned int idx_height = get_data_layout_dimension_index(input.data_layout(), DataLayoutDimension::HEIGHT);
798  const TensorShape input_shape = input.tensor_shape();
799  ARM_COMPUTE_ERROR_ON(input_shape[idx_height] <= 1 || input_shape[idx_width] <= 1);
800  const PadStrideInfo pad_stride_info = pool_info.pad_stride_info;
801  const unsigned int stride_x = pad_stride_info.stride().first;
802  const unsigned int stride_y = pad_stride_info.stride().second;
803 
804  const int pad_left = pad_stride_info.pad_left();
805  const int pad_top = pad_stride_info.pad_top();
806  const int pad_right = pad_stride_info.pad_right();
807  const int pad_bottom = pad_stride_info.pad_bottom();
808 
809  TensorShape output_shape = input_shape;
810  const unsigned int out_width = (input_shape[idx_width] - 1) * stride_x - pad_left - pad_right + pool_info.pool_size.width;
811  const unsigned int out_height = (input_shape[idx_height] - 1) * stride_y - pad_top - pad_bottom + pool_info.pool_size.height;
812 
813  output_shape.set(idx_width, out_width);
814  output_shape.set(idx_height, out_height);
815  return output_shape;
816 }
#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

◆ 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 1254 of file ShapeCalculator.h.

References arm_compute::test::validation::data_layout, ITensorInfo::data_layout(), ITensorInfo::dimension(), arm_compute::get_data_layout_dimension_index(), arm_compute::HEIGHT, arm_compute::test::validation::idx_height, arm_compute::test::validation::idx_width, ITensorInfo::tensor_shape(), arm_compute::WIDTH, Size2D::x(), and Size2D::y().

1255 {
1256  const DataLayout data_layout = input.data_layout();
1257  const int idx_width = get_data_layout_dimension_index(data_layout, DataLayoutDimension::WIDTH);
1258  const int idx_height = get_data_layout_dimension_index(data_layout, DataLayoutDimension::HEIGHT);
1259 
1260  TensorShape scale_out_shape(input.tensor_shape());
1261  const unsigned int out_x = input.dimension(idx_width) * info.x();
1262  const unsigned int out_y = input.dimension(idx_height) * info.y();
1263  scale_out_shape.set(idx_width, out_x);
1264  scale_out_shape.set(idx_height, out_y);
1265 
1266  return scale_out_shape;
1267 }
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:111

◆ 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.

References arm_compute::CHANNEL, arm_compute::get_data_layout_dimension_index(), arm_compute::HEIGHT, arm_compute::test::validation::output_shape, TensorShape::set(), arm_compute::WIDTH, and Dimensions< T >::x().

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

◆ 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.

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(), ClGemmConvolution::validate(), and CpuGemmConvolution::validate().

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

◆ 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.

References Size2D::area(), arm_compute::CHANNEL, ITensorInfo::data_layout(), ITensorInfo::dimension(), Window::DimX, Window::DimY, Window::DimZ, arm_compute::get_data_layout_dimension_index(), Size2D::height, WinogradInfo::kernel_size, WinogradInfo::output_tile_size, ITensorInfo::tensor_shape(), Size2D::width, and arm_compute::WIDTH.

Referenced by ClWinogradFilterTransformKernel::configure(), and CpuWinogradConv2d::validate().

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

◆ 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.

References Size2D::area(), arm_compute::CHANNEL, arm_compute::compute_winograd_convolution_tiles(), arm_compute::test::validation::conv_info, WinogradInfo::convolution_info, ITensorInfo::data_layout(), arm_compute::get_data_layout_dimension_index(), Size2D::height, arm_compute::HEIGHT, WinogradInfo::kernel_size, arm_compute::test::validation::output_shape, WinogradInfo::output_tile_size, TensorShape::set(), ITensorInfo::tensor_shape(), Size2D::width, and arm_compute::WIDTH.

Referenced by ClWinogradInputTransformKernel::configure(), and CpuWinogradConv2d::validate().

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

◆ 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.

References arm_compute::CHANNEL, arm_compute::test::validation::conv_info, WinogradInfo::convolution_info, arm_compute::test::validation::data_layout, ITensorInfo::dimension(), arm_compute::get_data_layout_dimension_index(), Size2D::height, arm_compute::HEIGHT, WinogradInfo::input_dimensions, WinogradInfo::kernel_size, WinogradInfo::output_data_layout, arm_compute::scaled_dimensions(), ITensorInfo::tensor_shape(), Size2D::width, and arm_compute::WIDTH.

Referenced by ClWinogradOutputTransformKernel::configure().

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:111

◆ 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 1276 of file ShapeCalculator.h.

Referenced by calculate_concatenate_shape().

1277 {
1278  return data->info()->tensor_shape();
1279 }

◆ extract_shape() [2/5]

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

Definition at line 1281 of file ShapeCalculator.h.

References ITensorInfo::tensor_shape().

1282 {
1283  return data->tensor_shape();
1284 }

◆ extract_shape() [3/5]

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

Definition at line 1285 of file ShapeCalculator.h.

References ITensorInfo::tensor_shape().

1286 {
1287  return data->tensor_shape();
1288 }

◆ extract_shape() [4/5]

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

Definition at line 1290 of file ShapeCalculator.h.

1291 {
1292  return *data;
1293 }

◆ extract_shape() [5/5]

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

Definition at line 1295 of file ShapeCalculator.h.

1296 {
1297  return *data;
1298 }