Class TensorShape

Class Documentation

class TensorShape

The TensorShape class represents the shape and layout of a tensor.

Public Types

using DimType = int64_t
using ShapeType = Shape<DimType, (15)>

Public Functions

TensorShape() = default

Default constructor.

inline TensorShape(ShapeType shape, TensorLayout layout)

Constructs a TensorShape with the given shape and layout.

Parameters:
  • shapeShape of the tensor.

  • layout – Layout of the tensor.

inline TensorShape(int size, TensorLayout layout)

Constructs a TensorShape with the given size and layout.

Parameters:
  • size – Size of the tensor.

  • layout – Layout of the tensor.

inline explicit TensorShape(TensorLayout layout)

Constructs a TensorShape with the given layout.

Parameters:

layout – Layout of the tensor.

inline TensorShape(const DimType *data, int32_t size, TensorLayout layout)

Constructs a TensorShape with the given data, size, and layout.

Parameters:
  • data – Pointer to the array of tensor dimensions.

  • size – Size of the tensor.

  • layout – Layout of the tensor.

inline TensorShape(const DimType *data, int32_t size, const char *layout)

Constructs a TensorShape with the given data, size, and layout.

Parameters:
  • data – Pointer to the array of tensor dimensions.

  • size – Size of the tensor.

  • layout – Layout string of the tensor.

inline TensorShape(ShapeType shape, const char *layout)

Constructs a TensorShape with the given shape and layout.

Parameters:
  • shapeShape of the tensor.

  • layout – Layout string of the tensor.

inline const ShapeType &shape() const

Returns the shape of the tensor.

Returns:

The shape of the tensor.

inline const TensorLayout &layout() const

Returns the layout of the tensor.

Returns:

The layout of the tensor.

inline const DimType &operator[](int i) const

Returns the dimension size at the given index.

Parameters:

i – Index of the dimension to return.

Returns:

The dimension size at the given index.

inline int rank() const

Returns the rank (number of dimensions) of the tensor.

Returns:

The rank of the tensor.

inline int size() const

Returns the size (total number of elements) of the tensor.

Returns:

The size of the tensor.

inline bool empty() const

Checks if the tensor is empty.

Returns:

True if the tensor is empty, false otherwise.

inline bool operator==(const TensorShape &that) const

Equality operator.

Parameters:

that – The TensorShape to compare with.

Returns:

True if this TensorShape is equal to that, false otherwise.

inline bool operator!=(const TensorShape &that) const

Inequality operator.

Parameters:

that – The TensorShape to compare with.

Returns:

True if this TensorShape is not equal to that, false otherwise.

inline bool operator<(const TensorShape &that) const

Less than operator.

Parameters:

that – The TensorShape to compare with.

Returns:

True if this TensorShape is less than that, false otherwise.

Public Static Attributes

static constexpr int MAX_RANK = ShapeType::MAX_RANK

Friends

inline friend std::ostream &operator<<(std::ostream &out, const TensorShape &ts)

Overload of the << operator for pretty printing.

Parameters:
  • out – The output stream.

  • ts – The TensorShape to print.

Returns:

The output stream.