Compute Library
 21.11
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 TensorShape &input_shape, DataLayout input_data_layout, const TensorShape &weights_shape, const PadStrideInfo &conv_info)
 Calculate the deep convolution shape output shape of a tensor. More...
 
TensorShape compute_deep_convolution_shape (const ITensorInfo &input, const ITensorInfo &weights, const 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_conv3d_shape (const TensorShape &src, const TensorShape &weights, const Conv3dInfo &conv3d_info)
 Calculate the output shape of 3d Convolution. 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 1334 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().

1335 {
1336  TensorShape out_shape = extract_shape(input[0]);
1337 
1338 #if defined(ARM_COMPUTE_ASSERTS_ENABLED)
1339  // All dimensions must match except the axis one
1340  for(unsigned int i = 0; i < MAX_DIMS; ++i)
1341  {
1342  if(i == axis)
1343  {
1344  continue;
1345  }
1346 
1347  for(const auto &tensor : input)
1348  {
1349  ARM_COMPUTE_ERROR_ON(tensor == nullptr);
1350  const TensorShape shape = extract_shape(tensor);
1351  ARM_COMPUTE_ERROR_ON(out_shape[i] != shape[i]);
1352  }
1353  }
1354 #endif // defined(ARM_COMPUTE_ASSERTS_ENABLED)
1355 
1356  // Calculate output shape
1357  size_t new_size = 0;
1358  for(const auto &tensor : input)
1359  {
1360  const TensorShape shape = extract_shape(tensor);
1361  new_size += shape[axis];
1362  }
1363 
1364  out_shape.set(axis, new_size);
1365 
1366  return out_shape;
1367 }
#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 51 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().

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

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

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

1320 {
1321  ARM_COMPUTE_ERROR_ON(axis > input_shape.num_dimensions());
1322  input_shape.remove_dimension(axis);
1323  return input_shape;
1324 }
#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 auto input_shape
Validate test suite is to test ARM_COMPUTE_RETURN_ON_* macros we use to check the validity of given a...

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

References ARM_COMPUTE_ERROR_ON, arm_compute::BATCHES, ITensorInfo::data_layout(), arm_compute::test::validation::data_layout, arm_compute::get_data_layout_dimension_index(), arm_compute::HEIGHT, arm_compute::test::validation::idx_height, arm_compute::test::validation::idx_width, arm_compute::test::validation::output_shape, ITensorInfo::tensor_shape(), and arm_compute::WIDTH.

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

1053 {
1054  ARM_COMPUTE_ERROR_ON(block_x <= 0 || block_y <= 0);
1055 
1056  const DataLayout data_layout = input->data_layout();
1057  const int idx_width = get_data_layout_dimension_index(data_layout, DataLayoutDimension::WIDTH);
1058  const int idx_height = get_data_layout_dimension_index(data_layout, DataLayoutDimension::HEIGHT);
1059  const int idx_batch = get_data_layout_dimension_index(data_layout, DataLayoutDimension::BATCHES);
1060 
1061  TensorShape output_shape{ input->tensor_shape() };
1062  output_shape.set(idx_width, input->tensor_shape()[idx_width] * block_x);
1063  output_shape.set(idx_height, input->tensor_shape()[idx_height] * block_y);
1064  output_shape.set(idx_batch, input->tensor_shape()[idx_batch] / (block_x * block_y));
1065 
1066  return output_shape;
1067 }
#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
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:113

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

References Size2D::area(), ARM_COMPUTE_ERROR_ON, arm_compute::CHANNEL, ITensorInfo::data_layout(), arm_compute::test::validation::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().

373 {
375  ARM_COMPUTE_ERROR_ON(input.tensor_shape()[1] != (convolved_dims.area()));
376  ARM_COMPUTE_ERROR_ON((num_groups > 1) && input.tensor_shape()[2] != num_groups);
377 
378  const DataLayout data_layout = input.data_layout();
379  const int width_idx = get_data_layout_dimension_index(data_layout, DataLayoutDimension::WIDTH);
380  const int height_idx = get_data_layout_dimension_index(data_layout, DataLayoutDimension::HEIGHT);
381  const int channel_idx = get_data_layout_dimension_index(data_layout, DataLayoutDimension::CHANNEL);
382 
383  TensorShape col2im_shape{ input.tensor_shape() };
384  // If batches start on 3rd dimension shift dimensions right by 1 to retain upper tensor shape,
385  // as first three will be override by H,W,C data
386  if(batch_size_on_z && num_groups == 1)
387  {
388  col2im_shape.shift_right(1);
389  }
390  col2im_shape.set(width_idx, convolved_dims.width);
391  col2im_shape.set(height_idx, convolved_dims.height);
392  col2im_shape.set(channel_idx, input.tensor_shape()[0] * num_groups);
393 
394  return col2im_shape;
395 }
#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
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:113

◆ compute_conv3d_shape()

TensorShape arm_compute::misc::shape_calculator::compute_conv3d_shape ( const TensorShape src,
const TensorShape weights,
const Conv3dInfo conv3d_info 
)
inline

Calculate the output shape of 3d Convolution.

Parameters
[in]srcInput tensor shape
[in]weightsWeights tensor shape
[in]conv3d_info3d Convolution Parameters object
Returns
the calculated shape

Definition at line 1406 of file ShapeCalculator.h.

References ARM_COMPUTE_ERROR, Padding3D::back, batch_dim, Padding3D::bottom, arm_compute::CEIL, channel_dim, Size3D::depth, depth_dim, Conv3dInfo::dilation, arm_compute::FLOOR, Padding3D::front, Size3D::height, height_dim, Padding3D::left, arm_compute::test::validation::output_shape, Conv3dInfo::padding, Padding3D::right, Conv3dInfo::round_type, Conv3dInfo::stride, Padding3D::top, weights_CHout_dim, weights_depth_dim, weights_height_dim, weights_width_dim, Size3D::width, width_dim, Size3D::x(), Size3D::y(), and Size3D::z().

Referenced by CpuDirectConv3dKernel::configure(), and arm_compute::test::validation::reference::conv3d().

1407 {
1408  // Weight tensor shape indices (D H W Cin Cout)
1409  constexpr unsigned int weights_depth_dim = 4u;
1410  constexpr unsigned int weights_height_dim = 3u;
1411  constexpr unsigned int weights_width_dim = 2u;
1412  constexpr unsigned int weights_CHout_dim = 0u;
1413 
1414  // Source/Destination Tensor shape indices (N D H W C)
1415  constexpr unsigned int batch_dim = 4u;
1416  constexpr unsigned int depth_dim = 3u;
1417  constexpr unsigned int height_dim = 2u;
1418  constexpr unsigned int width_dim = 1u;
1419  constexpr unsigned int channel_dim = 0u;
1420 
1421  TensorShape output_shape{ src };
1422  const size_t pad_left = conv3d_info.padding.left;
1423  const size_t pad_right = conv3d_info.padding.right;
1424  const size_t pad_top = conv3d_info.padding.top;
1425  const size_t pad_bottom = conv3d_info.padding.bottom;
1426  const size_t pad_front = conv3d_info.padding.front;
1427  const size_t pad_back = conv3d_info.padding.back;
1428  const size_t dilation_x = conv3d_info.dilation.width;
1429  const size_t dilation_y = conv3d_info.dilation.height;
1430  const size_t dilation_z = conv3d_info.dilation.depth;
1431  const size_t stride_x = conv3d_info.stride.x();
1432  const size_t stride_y = conv3d_info.stride.y();
1433  const size_t stride_z = conv3d_info.stride.z();
1434 
1435  int output_width_size = 0;
1436  int output_height_size = 0;
1437  int output_depth_size = 0;
1438 
1439  switch(conv3d_info.round_type)
1440  {
1441  case DimensionRoundingType::FLOOR:
1442  output_width_size = static_cast<int>(std::floor((static_cast<float>(src[width_dim] + pad_left + pad_right - (dilation_x * (weights[weights_width_dim] - 1) + 1)) / stride_x) + 1));
1443  output_height_size = static_cast<int>(std::floor((static_cast<float>(src[height_dim] + pad_top + pad_bottom - (dilation_y * (weights[weights_height_dim] - 1) + 1)) / stride_y) + 1));
1444  output_depth_size = static_cast<int>(std::floor((static_cast<float>(src[depth_dim] + pad_front + pad_back - (dilation_z * (weights[weights_depth_dim] - 1) + 1)) / stride_z) + 1));
1445  break;
1446  case DimensionRoundingType::CEIL:
1447  output_width_size = static_cast<int>(std::ceil((static_cast<float>(src[width_dim] + pad_left + pad_right - (dilation_x * (weights[weights_width_dim] - 1) + 1)) / stride_x) + 1));
1448  output_height_size = static_cast<int>(std::ceil((static_cast<float>(src[height_dim] + pad_top + pad_bottom - (dilation_y * (weights[weights_height_dim] - 1) + 1)) / stride_y) + 1));
1449  output_depth_size = static_cast<int>(std::ceil((static_cast<float>(src[depth_dim] + pad_front + pad_back - (dilation_z * (weights[weights_depth_dim] - 1) + 1)) / stride_z) + 1));
1450  break;
1451  default:
1452  ARM_COMPUTE_ERROR("Unsupported rounding type");
1453  }
1454 
1455  output_shape.set(batch_dim, src[batch_dim]);
1456  output_shape.set(width_dim, output_width_size);
1457  output_shape.set(height_dim, output_height_size);
1458  output_shape.set(depth_dim, output_depth_size);
1459  output_shape.set(channel_dim, weights[weights_CHout_dim]);
1460  return output_shape;
1461 }
constexpr unsigned int channel_dim
Definition: Conv3D.cpp:36
#define ARM_COMPUTE_ERROR(msg)
Print the given message then throw an std::runtime_error.
Definition: Error.h:352
constexpr unsigned int weights_height_dim
Definition: Conv3D.cpp:40
constexpr unsigned int weights_depth_dim
Definition: Conv3D.cpp:39
SimpleTensor< float > src
Definition: DFT.cpp:155
constexpr unsigned int depth_dim
Definition: Conv3D.cpp:33
constexpr unsigned int weights_width_dim
Definition: Conv3D.cpp:41
constexpr unsigned int batch_dim
Definition: Conv3D.cpp:32
constexpr unsigned int weights_CHout_dim
Definition: Conv3D.cpp:43
constexpr unsigned int height_dim
Definition: Conv3D.cpp:34
constexpr unsigned int width_dim
Definition: Conv3D.cpp:35

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

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

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

494 {
495  const TensorShape input_shape{ input.tensor_shape() };
496  const TensorShape weights_shape{ weights.tensor_shape() };
497 
498  const DataLayout data_layout = input.data_layout();
499  const int width_idx = get_data_layout_dimension_index(data_layout, DataLayoutDimension::WIDTH);
500  const int height_idx = get_data_layout_dimension_index(data_layout, DataLayoutDimension::HEIGHT);
501  const int channel_idx = get_data_layout_dimension_index(data_layout, DataLayoutDimension::CHANNEL);
502  const int batch_idx = get_data_layout_dimension_index(data_layout, DataLayoutDimension::BATCHES);
503 
504  TensorShape out_shape{ input_shape };
505  out_shape.set(width_idx, out_dims.first);
506  out_shape.set(height_idx, out_dims.second);
507  out_shape.set(channel_idx, weights_shape[batch_idx]);
508  return out_shape;
509 }
const auto 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:113

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

References ITensorInfo::data_layout(), arm_compute::test::validation::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().

463 {
464  const DataLayout data_layout = input.data_layout();
465  const size_t idx_w = get_data_layout_dimension_index(data_layout, DataLayoutDimension::WIDTH);
466  const size_t idx_h = get_data_layout_dimension_index(data_layout, DataLayoutDimension::HEIGHT);
467 
468  // Find the upsampled dimensions
469  unsigned int out_x = (input.dimension(idx_w) - 1) * sx + 1;
470  unsigned int out_y = (input.dimension(idx_h) - 1) * sy + 1;
471 
472  // Find the padding needed for the convolution with stride 1 in order to match output shape
473  padx = out_dims.first - (out_x - weights.dimension(idx_w) + 1);
474  pady = out_dims.second - (out_y - weights.dimension(idx_h) + 1);
475  out_x += padx;
476  out_y += pady;
477 
478  TensorShape scale_out_shape(input.tensor_shape());
479  scale_out_shape.set(idx_w, out_x);
480  scale_out_shape.set(idx_h, out_y);
481 
482  return scale_out_shape;
483 }
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:113

◆ compute_deep_convolution_shape() [1/2]

TensorShape arm_compute::misc::shape_calculator::compute_deep_convolution_shape ( const TensorShape input_shape,
DataLayout  input_data_layout,
const TensorShape weights_shape,
const PadStrideInfo conv_info 
)
inline

Calculate the deep convolution shape output shape of a tensor.

Parameters
[in]input_shapeInput tensor shape
[in]input_data_layoutInput data layout
[in]weights_shapeWeights tensor shape
[in]conv_infoContains padding and stride information
Returns
the calculated shape

Definition at line 713 of file ShapeCalculator.h.

References 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, input_height, input_width, arm_compute::test::validation::output_shape, arm_compute::scaled_dimensions(), weights_height, weights_width, and arm_compute::WIDTH.

Referenced by compute_deep_convolution_shape(), CpuDirectConv2dKernel::configure(), arm_compute::test::validation::DATA_TEST_CASE(), and arm_compute::test::validation::TEST_CASE().

714 {
715  const size_t idx_width = get_data_layout_dimension_index(input_data_layout, DataLayoutDimension::WIDTH);
716  const size_t idx_height = get_data_layout_dimension_index(input_data_layout, DataLayoutDimension::HEIGHT);
717  const size_t idx_channel = get_data_layout_dimension_index(input_data_layout, DataLayoutDimension::CHANNEL);
718 
719  const unsigned int input_width = input_shape[idx_width];
720  const unsigned int input_height = input_shape[idx_height];
721  const unsigned int weights_width = weights_shape[idx_width];
722  const unsigned int weights_height = weights_shape[idx_height];
723  const unsigned int weights_out_channel = weights_shape[3];
724  unsigned int output_width = 0;
725  unsigned int output_height = 0;
726  std::tie(output_width, output_height) = scaled_dimensions(input_width, input_height, weights_width, weights_height, conv_info);
727 
728  TensorShape output_shape{ input_shape };
729  output_shape.set(idx_width, output_width);
730  output_shape.set(idx_height, output_height);
731  output_shape.set(idx_channel, weights_out_channel);
732 
733  return output_shape;
734 }
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
const auto 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
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
const size_t input_height

◆ compute_deep_convolution_shape() [2/2]

TensorShape arm_compute::misc::shape_calculator::compute_deep_convolution_shape ( const ITensorInfo input,
const ITensorInfo weights,
const 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 744 of file ShapeCalculator.h.

References compute_deep_convolution_shape(), arm_compute::test::validation::conv_info, ITensorInfo::data_layout(), and ITensorInfo::tensor_shape().

745 {
746  return compute_deep_convolution_shape(input.tensor_shape(), input.data_layout(), weights.tensor_shape(), conv_info);
747 }
TensorShape compute_deep_convolution_shape(const ITensorInfo &input, const ITensorInfo &weights, const PadStrideInfo &conv_info)
Calculate the deep convolution shape output shape of a tensor.

◆ 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 1077 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, and arm_compute::WIDTH.

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

1078 {
1079  ARM_COMPUTE_ERROR_ON(block < 2);
1080 
1081  const int idx_width = get_data_layout_dimension_index(data_layout, DataLayoutDimension::WIDTH);
1082  const int idx_height = get_data_layout_dimension_index(data_layout, DataLayoutDimension::HEIGHT);
1083  const int idx_channel = get_data_layout_dimension_index(data_layout, DataLayoutDimension::CHANNEL);
1084 
1085  TensorShape output_shape{ input_shape };
1086  output_shape.set(idx_width, input_shape[idx_width] * block);
1087  output_shape.set(idx_height, input_shape[idx_height] * block);
1088  output_shape.set(idx_channel, input_shape[idx_channel] / (block * block));
1089 
1090  return output_shape;
1091 }
#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 auto 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

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

References arm_compute::CHANNEL, ITensorInfo::data_layout(), arm_compute::test::validation::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(), ITensorInfo::tensor_shape(), arm_compute::test::validation::weights_shape, and arm_compute::WIDTH.

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

422 {
423  const TensorShape input_shape{ input.tensor_shape() };
424  const TensorShape weights_shape{ weights.tensor_shape() };
425 
426  const DataLayout data_layout = input.data_layout();
427  const int width_idx = get_data_layout_dimension_index(data_layout, DataLayoutDimension::WIDTH);
428  const int height_idx = get_data_layout_dimension_index(data_layout, DataLayoutDimension::HEIGHT);
429  const int channel_idx = get_data_layout_dimension_index(data_layout, DataLayoutDimension::CHANNEL);
430 
431  const DataLayout weights_data_layout = weights.data_layout();
432  const int weights_width_idx = get_data_layout_dimension_index(weights_data_layout, DataLayoutDimension::WIDTH);
433  const int weights_height_idx = get_data_layout_dimension_index(weights_data_layout, DataLayoutDimension::HEIGHT);
434 
435  unsigned int output_width = 0;
436  unsigned int output_height = 0;
437  std::tie(output_width, output_height) = scaled_dimensions(input_shape[width_idx], input_shape[height_idx],
438  weights_shape[weights_width_idx], weights_shape[weights_height_idx],
439  info.pad_stride_info, info.dilation);
440 
441  TensorShape output_shape{ input_shape };
442  output_shape.set(width_idx, output_width);
443  output_shape.set(height_idx, output_height);
444  output_shape.set(channel_idx, input_shape[channel_idx] * info.depth_multiplier);
445 
446  return output_shape;
447 }
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 auto 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:113

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

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

562 {
563  // The output shape will be the flatten version of the input (i.e. [ width * height * channels, num_batches, ... ] ). Used for FlattenLayer and FullyConnectedLayer.
564 
565  TensorShape output_shape{ input->tensor_shape() };
566 
567  output_shape.collapse(3);
568 
569  return output_shape;
570 }

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

1464 {
1465  ARM_COMPUTE_ERROR_ON(indices_shape.num_dimensions() > 1);
1466  ARM_COMPUTE_ERROR_ON(input_shape.num_dimensions() > 4);
1467  ARM_COMPUTE_ERROR_ON(actual_axis >= input_shape.num_dimensions());
1468 
1469  TensorShape output_shape = input_shape;
1470  output_shape[actual_axis] = indices_shape[0];
1471 
1472  return output_shape;
1473 }
#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 auto input_shape
Validate test suite is to test ARM_COMPUTE_RETURN_ON_* macros we use to check the validity of given a...

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

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

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

525 {
526  // The output shape will be the 3D shape [ out_channels * kernel_area, num_elems_per_out_channel, batches ] if batch_size_on_z == true
527  // or the 4D shape [ out_channels * kernel_area / num_groups, num_elems_per_out_channel, num_groups, batches ] if batch_size_on_z == false
528 
530  ARM_COMPUTE_ERROR_ON(num_groups > 1 && input->data_layout() != DataLayout::NCHW);
531  ARM_COMPUTE_ERROR_ON(num_groups > 1 && batch_size_on_z);
532 
533  TensorShape output_shape{ input->tensor_shape() };
534 
535  const DataLayout data_layout = input->data_layout();
536  const int width_idx = get_data_layout_dimension_index(data_layout, DataLayoutDimension::WIDTH);
537  const int height_idx = get_data_layout_dimension_index(data_layout, DataLayoutDimension::HEIGHT);
538  const int channel_idx = get_data_layout_dimension_index(data_layout, DataLayoutDimension::CHANNEL);
539 
540  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);
541  output_shape.set(0, (output_shape[channel_idx] / num_groups * kernel_dims.area() + (has_bias ? 1 : 0))); // NOLINT
542  output_shape.set(1, (out_dims.first * out_dims.second));
543  if(batch_size_on_z && output_shape.num_dimensions() >= 3)
544  {
545  output_shape.remove_dimension(2);
546  }
547  else
548  {
549  output_shape.set(2, num_groups);
550  }
551 
552  return output_shape;
553 }
#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
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
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:113

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

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

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

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

756 {
757  TensorShape output_shape{ input->tensor_shape() };
758  output_shape.set(Window::DimX, 2);
759  output_shape.remove_dimension(1);
760  output_shape.remove_dimension(1);
761 
762  return output_shape;
763 }

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

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

Referenced by ClGemmMatrixMultiplyNativeKernel::configure(), ClGemmMatrixMultiplyReshapedOnlyRhsKernel::configure(), ClGemmMatrixMultiplyReshapedKernel::configure(), CpuGemm::validate(), and ClGemmLowpMatrixMultiplyCore::validate().

877 {
878  ARM_COMPUTE_ERROR_ON_MSG(input0.num_dimensions() > 4, "The number of dimensions for the matrix A must be <= 4");
879  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");
880 
881  const bool reinterpret_input_as_3d = reshape_info.reinterpret_input_as_3d();
882  const bool reinterpret_output_as_3d = reshape_info.depth_output_gemm3d() != 0;
883  const int depth_output_gemm3d = reinterpret_output_as_3d ? reshape_info.depth_output_gemm3d() : 1;
884  const int m = reshape_info.reinterpret_input_as_3d() ? input0.dimension(1) * input0.dimension(2) : input0.dimension(1);
885 
886  // If the output of GEMM has to be reinterpreted as 3D, the number of input0 rows (M) is obtained collapsing the second and third
887  // dimension of the output tensor
888  const int dim0 = is_interleaved_transposed ? reshape_info.n() : input1.dimension(0);
889  const int dim1 = is_interleaved_transposed ? reshape_info.m() / depth_output_gemm3d : m / depth_output_gemm3d;
890  const int dim2 = reinterpret_input_as_3d ? input0.tensor_shape()[3] : input0.tensor_shape()[2];
891  const int dim3 = reinterpret_input_as_3d ? 1 : input0.tensor_shape()[3];
892 
893  TensorShape output_shape{ input0.tensor_shape() };
894 
895  output_shape.set(0, dim0);
896  output_shape.set(1, dim1);
897  output_shape.set(2, reinterpret_output_as_3d ? depth_output_gemm3d : dim2);
898  output_shape.set(3, reinterpret_output_as_3d ? dim2 : dim3);
899  output_shape.set(4, reinterpret_output_as_3d ? dim3 : 1);
900 
901  return output_shape;
902 }
#define ARM_COMPUTE_ERROR_ON_MSG(cond, msg)
Definition: Error.h:456

◆ 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 912 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(), and ITensorInfo::tensor_shape().

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

◆ 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 950 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, and ITensorInfo::tensor_shape().

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

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

989 {
990  ARM_COMPUTE_ERROR_ON(input.data_layout() != DataLayout::NHWC && gemm_3d_depth > 1);
991 
992  TensorShape output_shape = input.tensor_shape();
993  if(gemm_3d_depth > 1)
994  {
995  if(batch_size_on_z)
996  {
997  output_shape.shift_right(1);
998  }
999  output_shape.set(0, input.tensor_shape().x());
1000  output_shape.set(1, input.tensor_shape().y() / gemm_3d_depth);
1001  output_shape.set(2, gemm_3d_depth);
1002  }
1003 
1004  return output_shape;
1005 }
#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 1206 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().

1207 {
1208  TensorShape padded_shape = input_shape;
1209  for(size_t dim = 0; dim < padding.size(); ++dim)
1210  {
1211  const auto &padding_pair = padding[dim];
1212  const uint32_t shape_on_index = (padded_shape.num_dimensions() <= dim) ? 1 : input_shape[dim];
1213  padded_shape.set(dim, padding_pair.first + shape_on_index + padding_pair.second);
1214  }
1215  return padded_shape;
1216 }
const auto input_shape
Validate test suite is to test ARM_COMPUTE_RETURN_ON_* macros we use to check the validity of given a...

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

110 {
111  TensorShape output_shape = input.tensor_shape();
112  permute(output_shape, perm);
113  return output_shape;
114 }
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 772 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(), ITensorInfo::tensor_shape(), Size2D::width, and arm_compute::WIDTH.

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

773 {
774  int pooled_w = 0;
775  int pooled_h = 0;
776 
777  TensorShape output_shape{ input.tensor_shape() };
778 
779  const bool is_global_pooling = pool_info.is_global_pooling;
780  const int idx_width = get_data_layout_dimension_index(input.data_layout(), DataLayoutDimension::WIDTH);
781  const int idx_height = get_data_layout_dimension_index(input.data_layout(), DataLayoutDimension::HEIGHT);
782  const int input_width = input.tensor_shape()[idx_width];
783  const int input_height = input.tensor_shape()[idx_height];
784  const int pool_size_x = is_global_pooling ? output_shape[idx_width] : pool_info.pool_size.width;
785  const int pool_size_y = is_global_pooling ? output_shape[idx_height] : pool_info.pool_size.height;
786 
787  std::tie(pooled_w, pooled_h) = scaled_dimensions_signed(input_width, input_height,
788  pool_size_x, pool_size_y,
789  pool_info.pad_stride_info);
790 
791  ARM_COMPUTE_ERROR_ON_MSG((pooled_w < 1 || pooled_h < 1), "Calculated output dimension size is invalid");
792 
793  output_shape.set(idx_width, static_cast<size_t>(pooled_w));
794  output_shape.set(idx_height, static_cast<size_t>(pooled_h));
795 
796  return output_shape;
797 }
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
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
const size_t input_height

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

References PriorBoxLayerInfo::aspect_ratios(), ITensorInfo::data_layout(), arm_compute::test::validation::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, and arm_compute::WIDTH.

1186 {
1187  DataLayout data_layout = input.data_layout();
1188  const size_t idx_w = get_data_layout_dimension_index(data_layout, DataLayoutDimension::WIDTH);
1189  const size_t idx_h = get_data_layout_dimension_index(data_layout, DataLayoutDimension::HEIGHT);
1190  const int num_priors = info.aspect_ratios().size() * info.min_sizes().size() + info.max_sizes().size();
1191 
1192  TensorShape output_shape{};
1193  output_shape.set(0, input.dimension(idx_w) * input.dimension(idx_h) * num_priors * 4);
1194  output_shape.set(1, 2);
1195 
1196  return output_shape;
1197 }
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:113

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

References arm_compute::test::validation::output_shape.

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

1244 {
1245  TensorShape output_shape{ input };
1246 
1247  if(!keep_dims)
1248  {
1249  output_shape.remove_dimension(axis);
1250  }
1251  else
1252  {
1253  output_shape.set(axis, 1);
1254  }
1255 
1256  return output_shape;
1257 }

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

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

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

335 {
336  TensorShape shape_vector_sum_col{ b.tensor_shape() };
337  if(shape_vector_sum_col.num_dimensions() > 1)
338  {
339  shape_vector_sum_col.remove_dimension(1);
340  }
341 
342  return shape_vector_sum_col;
343 }
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 351 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().

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

◆ 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 123 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, ITensorInfo::tensor_shape(), and arm_compute::WIDTH.

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

124 {
125  const size_t idx_width = get_data_layout_dimension_index(input.data_layout(), DataLayoutDimension::WIDTH);
126  const size_t idx_height = get_data_layout_dimension_index(input.data_layout(), DataLayoutDimension::HEIGHT);
127  const size_t idx_channel = get_data_layout_dimension_index(input.data_layout(), DataLayoutDimension::CHANNEL);
128 
129  ARM_COMPUTE_ERROR_ON(stride <= 0);
130  ARM_COMPUTE_ERROR_ON_MSG((input.tensor_shape()[idx_width] % stride != 0), "The width of the input tensor must be a multiple of stride");
131  ARM_COMPUTE_ERROR_ON_MSG((input.tensor_shape()[idx_height] % stride != 0), "The height of the input tensor must be a multiple of stride");
132 
133  TensorShape output_shape{ input.tensor_shape() };
134 
135  output_shape.set(idx_width, output_shape[idx_width] / stride);
136  output_shape.set(idx_height, output_shape[idx_height] / stride);
137  output_shape.set(idx_channel, output_shape[idx_channel] * stride * stride);
138 
139  return output_shape;
140 }
#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

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

226 {
230 
231  // Input width/height
232  const unsigned int input_width = a.dimension(0);
233  const unsigned int input_height = a.dimension(1);
234 
235  // Number of horizontal/vertical blocks in the input tensor
236  const unsigned int num_horiz_blocks = std::ceil(input_width / static_cast<float>(rhs_info.n0));
237  const unsigned int num_vert_blocks = std::ceil(input_height / static_cast<float>(rhs_info.k0));
238 
239  // Block size
240  const unsigned int block_size = rhs_info.n0 * rhs_info.k0;
241 
242  // Output width/height
243  const unsigned int output_width = block_size * num_vert_blocks * rhs_info.h0;
244  const unsigned int output_height = std::ceil(num_horiz_blocks / static_cast<float>(rhs_info.h0));
245 
246  TensorShape rhs_shape{ a.tensor_shape() };
247  rhs_shape.set(0, output_width);
248  rhs_shape.set(1, output_height);
249 
250  return rhs_shape;
251 }
#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 859 of file ShapeCalculator.h.

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

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

860 {
861  TensorShape output_shape{ input->tensor_shape() };
862  output_shape.set(1, batch_size);
863 
864  return output_shape;
865 }

◆ 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 838 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(), ITensorInfo::tensor_shape(), and arm_compute::WIDTH.

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

839 {
840  TensorShape output_shape{ input.tensor_shape() };
841 
842  const unsigned int idx_width = get_data_layout_dimension_index(input.data_layout(), DataLayoutDimension::WIDTH);
843  const unsigned int idx_height = get_data_layout_dimension_index(input.data_layout(), DataLayoutDimension::HEIGHT);
844 
845  output_shape.set(idx_width, pool_info.pooled_width());
846  output_shape.set(idx_height, pool_info.pooled_height());
847  output_shape.set(3, rois.dimension(1));
848 
849  return output_shape;
850 }
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_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 1035 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().

1036 {
1038 
1040  starts, ends, BiStrides(),
1041  0, construct_slice_end_mask(ends), 0);
1042 }
Coordinates BiStrides
Bidirectional strides.
Definition: Types.h:53
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...
const auto 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 579 of file ShapeCalculator.h.

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

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

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

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

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

1137 {
1138  TensorShape output_shape{ input->tensor_shape() };
1139 
1140  const DataLayout data_layout = input->data_layout();
1141  const int idx_width = get_data_layout_dimension_index(data_layout, DataLayoutDimension::WIDTH);
1142  const int idx_height = get_data_layout_dimension_index(data_layout, DataLayoutDimension::HEIGHT);
1143  const int idx_batch = get_data_layout_dimension_index(data_layout, DataLayoutDimension::BATCHES);
1144 
1145  ARM_COMPUTE_ERROR_ON((input->tensor_shape()[idx_width] + padding_left.x() + padding_right.x()) % block_x != 0);
1146  ARM_COMPUTE_ERROR_ON((input->tensor_shape()[idx_height] + padding_left.y() + padding_right.y()) % block_y != 0);
1147 
1148  output_shape.set(idx_width, (input->tensor_shape()[idx_width] + padding_left.x() + padding_right.x()) / block_x);
1149  output_shape.set(idx_height, (input->tensor_shape()[idx_height] + padding_left.y() + padding_right.y()) / block_y);
1150  output_shape.set(idx_batch, input->tensor_shape()[idx_batch] * block_x * block_y);
1151 
1152  return output_shape;
1153 }
#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
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:113

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

References arm_compute::CHANNEL, ITensorInfo::data_layout(), arm_compute::test::validation::data_layout, arm_compute::get_data_layout_dimension_index(), arm_compute::HEIGHT, arm_compute::test::validation::idx_height, arm_compute::test::validation::idx_width, arm_compute::test::validation::output_shape, ITensorInfo::tensor_shape(), and arm_compute::WIDTH.

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

1163 {
1164  TensorShape output_shape{ input->tensor_shape() };
1165 
1166  const DataLayout data_layout = input->data_layout();
1167  const int idx_width = get_data_layout_dimension_index(data_layout, DataLayoutDimension::WIDTH);
1168  const int idx_height = get_data_layout_dimension_index(data_layout, DataLayoutDimension::HEIGHT);
1169  const int idx_depth = get_data_layout_dimension_index(data_layout, DataLayoutDimension::CHANNEL);
1170 
1171  output_shape.set(idx_width, input->tensor_shape()[idx_width] * block_shape);
1172  output_shape.set(idx_height, input->tensor_shape()[idx_height] * block_shape);
1173  output_shape.set(idx_depth, input->tensor_shape()[idx_depth] / (block_shape * block_shape));
1174 
1175  return output_shape;
1176 }
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:113

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

1102 {
1103  TensorShape empty_shape;
1104  empty_shape.set(0, 0);
1105 
1106  TensorShape out_shape{ input->tensor_shape() };
1107 
1108  // Return empty shape if axis is invalid
1109  if(axis > input->tensor_shape().num_dimensions())
1110  {
1111  return empty_shape;
1112  }
1113 
1114  size_t axis_size = out_shape[axis];
1115 
1116  // Return empty shape if num_split is not valid
1117  if(axis_size % num_splits)
1118  {
1119  return empty_shape;
1120  }
1121 
1122  out_shape[axis] = axis_size / num_splits;
1123  return out_shape;
1124 }

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

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

Referenced by StackLayerNode::compute_output_descriptor().

1377 {
1378  ARM_COMPUTE_ERROR_ON(axis > a.num_dimensions());
1379  ARM_COMPUTE_ERROR_ON(a.num_dimensions() > 4);
1380 
1381  TensorShape shape_out{ a.tensor_shape() };
1382  shape_out.set(axis, num_tensors);
1383 
1384  unsigned int i_shift = 0;
1385 
1386  for(unsigned int i = 0; i < a.num_dimensions(); ++i)
1387  {
1388  if(i == axis)
1389  {
1390  i_shift++;
1391  }
1392 
1393  shape_out.set(i + i_shift, a.tensor_shape()[i]);
1394  }
1395  return shape_out;
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

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

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

Referenced by CLStridedSliceKernel::configure().

1022 {
1024  return compute_strided_slice_output_shape(input.tensor_shape(), starts, ends, strides, begin_mask, end_mask, shrink_axis_mask);
1025 }
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 1225 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().

1226 {
1227  TensorShape tiled_shape = input_shape;
1228  for(size_t dim = 0; dim < multiples.size(); ++dim)
1229  {
1230  tiled_shape.set(dim, input_shape[dim] * multiples[dim]);
1231  }
1232  return tiled_shape;
1233 }
const auto input_shape
Validate test suite is to test ARM_COMPUTE_RETURN_ON_* macros we use to check the validity of given a...

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

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

Referenced by CpuGemmLowpMatrixMultiplyCore::configure().

298 {
299  // The transpose1xW output matrix will have the following shape: [ b_height * 16, ceil(b_width / 16.0f) ]
300  TensorShape shape_transposed1xW_b{ b.tensor_shape() };
301  shape_transposed1xW_b.set(0, b.dimension(1) * 16);
302  shape_transposed1xW_b.set(1, std::ceil(b.dimension(0) / 16.f));
303 
304  return shape_transposed1xW_b;
305 }
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 314 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().

315 {
316  // Note: mult_transpose1xW_width expresses the number of chunks with size 1x(W) we want to store on the same row
317  // The transpose1xW output matrix will have the following shape:
318  // [ b_height * W, ceil(b_width / W) ] where W = (16 / element size of the tensor) * mult_transpose1xW_width
319  ARM_COMPUTE_ERROR_ON(mult_transpose1xW_width < 1);
320  TensorShape shape_transposed1xW_b{ b.tensor_shape() };
321  const size_t transpose_width = (16 / b.element_size()) * mult_transpose1xW_width;
322  shape_transposed1xW_b.set(0, b.dimension(1) * transpose_width);
323  shape_transposed1xW_b.set(1, static_cast<size_t>(std::ceil(b.dimension(0) / static_cast<float>(transpose_width))));
324 
325  return shape_transposed1xW_b;
326 }
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 403 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().

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

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

807 {
808  const unsigned int idx_width = get_data_layout_dimension_index(input.data_layout(), DataLayoutDimension::WIDTH);
809  const unsigned int idx_height = get_data_layout_dimension_index(input.data_layout(), DataLayoutDimension::HEIGHT);
810  const TensorShape input_shape = input.tensor_shape();
811  ARM_COMPUTE_ERROR_ON(input_shape[idx_height] <= 1 || input_shape[idx_width] <= 1);
812  const PadStrideInfo pad_stride_info = pool_info.pad_stride_info;
813  const unsigned int stride_x = pad_stride_info.stride().first;
814  const unsigned int stride_y = pad_stride_info.stride().second;
815 
816  const int pad_left = pad_stride_info.pad_left();
817  const int pad_top = pad_stride_info.pad_top();
818  const int pad_right = pad_stride_info.pad_right();
819  const int pad_bottom = pad_stride_info.pad_bottom();
820 
821  TensorShape output_shape = input_shape;
822  const unsigned int out_width = (input_shape[idx_width] - 1) * stride_x - pad_left - pad_right + pool_info.pool_size.width;
823  const unsigned int out_height = (input_shape[idx_height] - 1) * stride_y - pad_top - pad_bottom + pool_info.pool_size.height;
824 
825  output_shape.set(idx_width, out_width);
826  output_shape.set(idx_height, out_height);
827  return output_shape;
828 }
#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 auto 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

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

References ITensorInfo::data_layout(), arm_compute::test::validation::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().

1267 {
1268  const DataLayout data_layout = input.data_layout();
1269  const int idx_width = get_data_layout_dimension_index(data_layout, DataLayoutDimension::WIDTH);
1270  const int idx_height = get_data_layout_dimension_index(data_layout, DataLayoutDimension::HEIGHT);
1271 
1272  TensorShape scale_out_shape(input.tensor_shape());
1273  const unsigned int out_x = input.dimension(idx_width) * info.x();
1274  const unsigned int out_y = input.dimension(idx_height) * info.y();
1275  scale_out_shape.set(idx_width, out_x);
1276  scale_out_shape.set(idx_height, out_y);
1277 
1278  return scale_out_shape;
1279 }
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:113

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

89 {
90  const size_t idx_w = get_data_layout_dimension_index(data_layout, DataLayoutDimension::WIDTH);
91  const size_t idx_h = get_data_layout_dimension_index(data_layout, DataLayoutDimension::HEIGHT);
92  const size_t idx_c = get_data_layout_dimension_index(data_layout, DataLayoutDimension::CHANNEL);
93 
94  TensorShape output_shape(input);
95  output_shape.set(idx_w, conv_w);
96  output_shape.set(idx_h, conv_h);
97  output_shape.set(idx_c, input.x() / (conv_w * conv_h));
98 
99  return output_shape;
100 }
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_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 150 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(), ClGemmConv2d::validate(), and CpuGemmConv2d::validate().

151 {
152  // Number of groups greater than one are only supported for NCHW data layout, and the number of weights must be a multiple of it.
154  ARM_COMPUTE_ERROR_ON(weights.data_layout() == DataLayout::NHWC && num_groups > 1);
155  ARM_COMPUTE_ERROR_ON((weights.dimension(3) % num_groups) != 0);
156 
157  // Calculate output shape
158  TensorShape weights_reshaped{ weights.tensor_shape() };
159  weights_reshaped.set(3, weights_reshaped[3] / num_groups);
160 
161  weights_reshaped.collapse(3);
162  const size_t tmp_dim = weights_reshaped[0];
163  weights_reshaped.set(0, weights_reshaped[1]);
164  weights_reshaped.set(1, tmp_dim + (has_bias ? 1 : 0));
165  if(weights.num_dimensions() < 5)
166  {
167  weights_reshaped.set(2, num_groups);
168  }
169 
170  return weights_reshaped;
171 }
#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 618 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().

619 {
620  TensorShape tensor_shape{ input.tensor_shape() };
621 
622  const Size2D kernel_size = winograd_info.kernel_size;
623  const Size2D output_tile_size = winograd_info.output_tile_size;
624  const Size2D input_tile_size = Size2D(output_tile_size.width + kernel_size.width - 1, output_tile_size.height + kernel_size.height - 1);
625 
626  tensor_shape.remove_dimension(get_data_layout_dimension_index(input.data_layout(), DataLayoutDimension::WIDTH));
627  tensor_shape.set(Window::DimX, input.dimension(3));
628  tensor_shape.set(Window::DimY, input.dimension(get_data_layout_dimension_index(input.data_layout(), DataLayoutDimension::CHANNEL)));
629  tensor_shape.set(Window::DimZ, input_tile_size.area());
630 
631  return tensor_shape;
632 }
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 641 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, ITensorInfo::tensor_shape(), Size2D::width, and arm_compute::WIDTH.

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

642 {
643  const PadStrideInfo conv_info = winograd_info.convolution_info;
644  const Size2D kernel_size = winograd_info.kernel_size;
645  const Size2D output_tile_size = winograd_info.output_tile_size;
646  const Size2D input_tile_size = Size2D(output_tile_size.width + kernel_size.width - 1, output_tile_size.height + kernel_size.height - 1);
647 
648  const size_t idx_w = get_data_layout_dimension_index(input.data_layout(), DataLayoutDimension::WIDTH);
649  const size_t idx_h = get_data_layout_dimension_index(input.data_layout(), DataLayoutDimension::HEIGHT);
650  const size_t idx_c = get_data_layout_dimension_index(input.data_layout(), DataLayoutDimension::CHANNEL);
651 
652  // Compute the number of output tiles along the x and y direction of size "output_tile_size"
653  const Size2D num_tiles = compute_winograd_convolution_tiles(Size2D(input.tensor_shape()[idx_w], input.tensor_shape()[idx_h]),
654  kernel_size,
655  output_tile_size,
656  conv_info);
657 
658  const unsigned int width = input.tensor_shape()[idx_c];
659  const unsigned int height = num_tiles.area();
660  const unsigned int depth = input_tile_size.area();
661 
662  TensorShape output_shape{ input.tensor_shape() };
663  output_shape.set(0, width);
664  output_shape.set(1, height);
665  output_shape.set(2, depth);
666 
667  return output_shape;
668 }
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:227
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_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 677 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().

678 {
679  const PadStrideInfo conv_info = winograd_info.convolution_info;
680  const Size2D kernel_size = winograd_info.kernel_size;
681  const Size2D input_dimensions = winograd_info.input_dimensions;
682  const DataLayout data_layout = winograd_info.output_data_layout;
683 
684  // Compute output shape
685  unsigned int output_width = 0;
686  unsigned int output_height = 0;
687  std::tie(output_width, output_height) = scaled_dimensions(input_dimensions.width, input_dimensions.height,
688  kernel_size.width, kernel_size.height, conv_info);
689 
690  TensorShape tensor_shape{ input.tensor_shape() };
691 
692  // Output dimension
693  const unsigned int out_w = output_width;
694  const unsigned int out_h = output_height;
695  const unsigned int out_c = input.dimension(0);
696 
697  tensor_shape.set(get_data_layout_dimension_index(data_layout, DataLayoutDimension::WIDTH), out_w);
698  tensor_shape.set(get_data_layout_dimension_index(data_layout, DataLayoutDimension::HEIGHT), out_h);
699  tensor_shape.set(get_data_layout_dimension_index(data_layout, DataLayoutDimension::CHANNEL), out_c);
700 
701  return tensor_shape;
702 }
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:113

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

Referenced by calculate_concatenate_shape().

1289 {
1290  return data->info()->tensor_shape();
1291 }

◆ extract_shape() [2/5]

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

Definition at line 1293 of file ShapeCalculator.h.

References ITensorInfo::tensor_shape().

1294 {
1295  return data->tensor_shape();
1296 }

◆ extract_shape() [3/5]

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

Definition at line 1297 of file ShapeCalculator.h.

References ITensorInfo::tensor_shape().

1298 {
1299  return data->tensor_shape();
1300 }

◆ extract_shape() [4/5]

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

Definition at line 1302 of file ShapeCalculator.h.

1303 {
1304  return *data;
1305 }

◆ extract_shape() [5/5]

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

Definition at line 1307 of file ShapeCalculator.h.

1308 {
1309  return *data;
1310 }