MCPcopy Create free account
hub / github.com/ARM-software/ComputeLibrary / TensorShape

Class TensorShape

arm_compute/core/TensorShape.h:43–277  ·  view source on GitHub ↗

Shape of a tensor */

Source from the content-addressed store, hash-verified

41{
42/** Shape of a tensor */
43class TensorShape : public Dimensions<size_t>
44{
45public:
46 /** Constructor to initialize the tensor shape.
47 *
48 * @param[in] dims Values to initialize the dimensions.
49 */
50 template <typename... Ts>
51 TensorShape(Ts... dims) : Dimensions{dims...}
52 {
53 // Initialize unspecified dimensions to 1
54 if (_num_dimensions > 0)
55 {
56 std::fill(_id.begin() + _num_dimensions, _id.end(), 1);
57 }
58
59 // Correct number dimensions to ignore trailing dimensions of size 1
60 apply_dimension_correction();
61 }
62 /** Allow instances of this class to be copy constructed */
63 TensorShape(const TensorShape &) = default;
64 /** Allow instances of this class to be copied */
65 TensorShape &operator=(const TensorShape &) = default;
66 /** Allow instances of this class to be move constructed */
67 TensorShape(TensorShape &&) = default;
68 /** Allow instances of this class to be moved */
69 TensorShape &operator=(TensorShape &&) = default;
70 /** Default destructor */
71 ~TensorShape() = default;
72
73 /** Accessor to set the value of one of the dimensions.
74 *
75 * @param[in] dimension Dimension for which the value is set.
76 * @param[in] value Value to be set for the dimension.
77 * @param[in] apply_dim_correction (Optional) 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.
78 * @param[in] increase_dim_unit (Optional) Set to true if new unit dimensions increase the number of dimensions of the shape.
79 *
80 * @return *this.
81 */
82 TensorShape &set(size_t dimension, size_t value, bool apply_dim_correction = true, bool increase_dim_unit = true)
83 {
84 // Clear entire shape if one dimension is zero
85 if (value == 0)
86 {
87 _num_dimensions = 0;
88 std::fill(_id.begin(), _id.end(), 0);
89 }
90 else
91 {
92 // Make sure all empty dimensions are filled with 1
93 std::fill(_id.begin() + _num_dimensions, _id.end(), 1);
94 // Set the specified dimension and increase the number of dimensions if
95 // necessary
96 Dimensions::set(dimension, value, increase_dim_unit);
97 // Correct number dimensions to ignore trailing dimensions of size 1
98 if (apply_dim_correction)
99 {
100 apply_dimension_correction();

Callers 1

Calls 3

fillFunction · 0.85
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected