Compute Library
18.05
|
Shape of a tensor. More...
#include <TensorShape.h>
Public Member Functions | |
template<typename... Ts> | |
TensorShape (Ts...dims) | |
Constructor to initialize the tensor shape. More... | |
TensorShape (const TensorShape &)=default | |
Allow instances of this class to be copy constructed. More... | |
TensorShape & | operator= (const TensorShape &)=default |
Allow instances of this class to be copied. More... | |
TensorShape (TensorShape &&)=default | |
Allow instances of this class to be move constructed. More... | |
TensorShape & | operator= (TensorShape &&)=default |
Allow instances of this class to be moved. More... | |
~TensorShape ()=default | |
Default destructor. More... | |
TensorShape & | set (size_t dimension, size_t value, bool apply_dim_correction=true) |
Accessor to set the value of one of the dimensions. More... | |
void | remove_dimension (size_t n) |
Accessor to remove the dimension n from the tensor shape. More... | |
void | collapse (size_t n, size_t first=0) |
Collapse the first n dimensions. More... | |
TensorShape | collapsed_from (size_t start) const |
Return a copy with collapsed dimensions starting from a given point. More... | |
size_t | total_size () const |
Collapses all dimensions to a single linear total size. More... | |
size_t | total_size_upper (size_t dimension) const |
Collapses given dimension and above. More... | |
size_t | total_size_lower (size_t dimension) const |
Compute size of dimensions lower than the given one. More... | |
Public Member Functions inherited from Dimensions< size_t > | |
Dimensions (Ts...dims) | |
Constructor to initialize the tensor shape. More... | |
Dimensions (const Dimensions &)=default | |
Allow instances of this class to be copy constructed. More... | |
Dimensions (Dimensions &&)=default | |
Allow instances of this class to be move constructed. More... | |
Dimensions & | operator= (const Dimensions &)=default |
Allow instances of this class to be copied. More... | |
Dimensions & | operator= (Dimensions &&)=default |
Allow instances of this class to be moved. More... | |
void | set (size_t dimension, size_tvalue) |
Accessor to set the value of one of the dimensions. More... | |
size_t | x () const |
Alias to access the size of the first dimension. More... | |
size_t | y () const |
Alias to access the size of the second dimension. More... | |
size_t | z () const |
Alias to access the size of the third dimension. More... | |
const size_t & | operator[] (size_t dimension) const |
Generic accessor to get the size of any dimension. More... | |
size_t & | operator[] (size_t dimension) |
Generic accessor to get the size of any dimension. More... | |
unsigned int | num_dimensions () const |
Returns the effective dimensionality of the tensor. More... | |
void | set_num_dimensions (size_t num_dimensions) |
Set number of dimensions. More... | |
void | collapse (const size_t n, const size_t first=0) |
Collapse dimensions. More... | |
void | collapse_from (size_t start) |
Collapse dimensions starting from a given point. More... | |
std::array< size_t, num_max_dimensions >::iterator | begin () |
Returns a read/write iterator that points to the first element in the dimension array. More... | |
std::array< size_t, num_max_dimensions >::const_iterator | begin () const |
Returns a read-only (constant) iterator that points to the first element in the dimension array. More... | |
std::array< size_t, num_max_dimensions >::const_iterator | cbegin () const |
Returns a read-only (constant) iterator that points to the first element in the dimension array. More... | |
std::array< size_t, num_max_dimensions >::iterator | end () |
Returns a read/write iterator that points one past the last element in the dimension array. More... | |
std::array< size_t, num_max_dimensions >::const_iterator | end () const |
Returns a read-only (constant) iterator that points one past the last element in the dimension array. More... | |
std::array< size_t, num_max_dimensions >::const_iterator | cend () const |
Returns a read-only (constant) iterator that points one past the last element in the dimension array. More... | |
Static Public Member Functions | |
template<typename... Shapes> | |
static TensorShape | broadcast_shape (const Shapes &...shapes) |
If shapes are broadcast compatible, return the broadcasted shape. More... | |
Additional Inherited Members | |
Static Public Attributes inherited from Dimensions< size_t > | |
static constexpr size_t | num_max_dimensions |
Number of dimensions the tensor has. More... | |
Shape of a tensor.
Definition at line 39 of file TensorShape.h.
|
inline |
Constructor to initialize the tensor shape.
[in] | dims | Values to initialize the dimensions. |
Definition at line 47 of file TensorShape.h.
References TensorShape::operator=(), and TensorShape::~TensorShape().
|
default |
Allow instances of this class to be copy constructed.
|
default |
Allow instances of this class to be move constructed.
|
default |
Default destructor.
Referenced by TensorShape::TensorShape().
|
inlinestatic |
If shapes are broadcast compatible, return the broadcasted shape.
Two tensor shapes are broadcast compatible if for each dimension, they're equal or one of them is 1.
If two shapes are compatible, each dimension in the broadcasted shape is the max of the original dimensions.
[in] | shapes | Tensor shapes. |
Definition at line 196 of file TensorShape.h.
References arm_compute::utility::for_each(), arm_compute::test::fixed_point_arithmetic::detail::max(), arm_compute::test::fixed_point_arithmetic::detail::min(), Dimensions< T >::num_dimensions(), Dimensions< size_t >::num_max_dimensions, TensorShape::set(), and arm_compute::U.
Referenced by arm_compute::test::validation::reference::arithmetic_addition(), ITensorInfo::broadcast_shape_and_valid_region(), and arm_compute::test::validation::reference::pixel_wise_multiplication().
|
inline |
Collapse the first n dimensions.
[in] | n | Number of dimensions to collapse into first |
[in] | first | Dimensions into which the following n are collapsed. |
Definition at line 132 of file TensorShape.h.
References Dimensions< T >::collapse().
Referenced by TensorShape::collapsed_from(), and arm_compute::misc::shape_calculator::compute_weights_reshaped_shape().
|
inline |
Return a copy with collapsed dimensions starting from a given point.
[in] | start | Starting point of collapsing dimensions. |
Definition at line 146 of file TensorShape.h.
References TensorShape::collapse(), arm_compute::test::validation::reference::copy(), and Dimensions< size_t >::num_dimensions().
|
default |
Allow instances of this class to be copied.
Referenced by TensorShape::TensorShape().
|
default |
Allow instances of this class to be moved.
|
inline |
Accessor to remove the dimension n from the tensor shape.
[in] | n | Dimension to remove |
Definition at line 110 of file TensorShape.h.
References ARM_COMPUTE_ERROR_ON, and arm_compute::test::validation::reference::copy().
Referenced by arm_compute::misc::shape_calculator::compute_reductionA_shape(), arm_compute::misc::shape_calculator::compute_reductionB_shape(), and arm_compute::test::validation::DATA_TEST_CASE().
|
inline |
Accessor to set the value of one of the dimensions.
[in] | dimension | Dimension for which the value is set. |
[in] | value | Value to be set for the dimension. |
[in] | apply_dim_correction | Flag to state whether apply dimension correction after setting one dimension. E.g. when permuting NCHW -> NHWC, 1x1x2 would become 2x1x1, but _num_dimensions should be 3 rather than 1. |
Definition at line 78 of file TensorShape.h.
References Dimensions< T >::set().
Referenced by arm_compute::adjust_odd_shape(), TensorShape::broadcast_shape(), arm_compute::calculate_depth_concatenate_shape(), arm_compute::calculate_subsampled_shape(), arm_compute::misc::shape_calculator::calculate_width_concatenate_shape(), arm_compute::misc::shape_calculator::compute_col2im_shape(), arm_compute::misc::shape_calculator::compute_interleaved_shape(), arm_compute::misc::shape_calculator::compute_mm_shape(), arm_compute::misc::shape_calculator::compute_reductionB_shape(), arm_compute::misc::shape_calculator::compute_transpose1xW_shape(), arm_compute::misc::shape_calculator::compute_transpose1xW_with_element_size_shape(), arm_compute::misc::shape_calculator::compute_transposed_shape(), arm_compute::test::validation::DATA_TEST_CASE(), arm_compute::test::validation::reference::deconvolution_layer(), arm_compute::test::index2coord(), arm_compute::index2coords(), NPYLoader::init_tensor(), arm_compute::intersect_valid_regions(), arm_compute::permute(), arm_compute::test::validation::reference::scale(), arm_compute::test::shape_to_valid_region(), arm_compute::test::shape_to_valid_region_gaussian_pyramid_half(), and arm_compute::test::validation::transpose().
|
inline |
Collapses all dimensions to a single linear total size.
Definition at line 157 of file TensorShape.h.
References accumulate().
Referenced by arm_compute::auto_init_if_empty(), arm_compute::test::coord2index(), arm_compute::coords2index(), arm_compute::test::validation::DATA_TEST_CASE(), arm_compute::test::validation::reference::depthwise_convolution(), arm_compute::test::index2coord(), arm_compute::index2coords(), GCAccessor::num_elements(), Accessor::num_elements(), CLAccessor::num_elements(), SimpleTensor< T >::num_elements(), arm_compute::test::validation::reference::reshape_layer(), arm_compute::set_shape_if_empty(), and SubTensorInfo::set_valid_region().
|
inline |
Compute size of dimensions lower than the given one.
[in] | dimension | Upper boundary. |
Definition at line 179 of file TensorShape.h.
References accumulate(), ARM_COMPUTE_ERROR_ON, and Dimensions< size_t >::num_max_dimensions.
|
inline |
Collapses given dimension and above.
[in] | dimension | Size of the wanted dimension |
Definition at line 167 of file TensorShape.h.
References accumulate(), ARM_COMPUTE_ERROR_ON, and Dimensions< size_t >::num_max_dimensions.
Referenced by arm_compute::test::validation::reference::fully_connected_layer(), and arm_compute::setup_assembly_kernel().