operator[]

Function Usage

Obtains the dimension value of a specified index axis.

Prototype

1
2
const int64_t &operator[](const size_t idx) const
int64_t &operator[](const size_t idx)

Parameters

Parameter

Input/Output

Description

idx

Input

Index of dim. You must ensure that the index is valid.

Returns

  • const int64_t &operator[](const size_t idx) const: dimension value. When idx is greater than or equal to kMaxDimNum, the behavior is not defined.
  • int64_t &operator[](const size_t idx): dimension value. When idx is greater than or equal to kMaxDimNum, the behavior is not defined.

Constraints

You must ensure that the index is valid, that is, idx must be less than kMaxDimNum.

Examples

1
2
3
4
Shape shape0({3, 256, 256});
auto dim0 = shape0[0]; // 3
auto dim5 = shape0[5]; // 0
auto invalid_dim = shape0[kMaxDimNum]; // The behavior is not defined.