Struct anira::TensorShape#

struct TensorShape#

Defines input and output tensor shapes for neural network models.

The TensorShape struct specifies the dimensional structure of tensors used by neural network models. It supports both universal shapes (backend-agnostic) and backend-specific shapes for models that require different tensor layouts across different inference engines.

Warning

All tensor shapes must have at least one input and one output tensor defined to ensure proper model configuration.

Public Functions

TensorShape() = delete#

Default constructor is deleted to prevent uninitialized instances.

inline TensorShape(TensorShapeList input_shape, TensorShapeList output_shape)#

Constructs a universal TensorShape that works across all backends.

Creates a TensorShape configuration that can be used with any inference backend. This is useful when all backends can use the same tensor layout.

Parameters:
  • input_shape – List of input tensor shapes, where each shape is a vector of dimensions

  • output_shape – List of output tensor shapes, where each shape is a vector of dimensions

inline TensorShape(TensorShapeList input_shape, TensorShapeList output_shape, InferenceBackend backend)#

Constructs a backend-specific TensorShape.

Creates a TensorShape configuration that is optimized for a specific inference backend. This allows different tensor layouts for different backends when models are optimized differently for each inference engine.

Parameters:
  • input_shape – List of input tensor shapes, where each shape is a vector of dimensions

  • output_shape – List of output tensor shapes, where each shape is a vector of dimensions

  • backend – The specific inference backend this shape configuration targets

inline bool is_universal() const#

Checks if this tensor shape configuration is universal.

Returns:

true if the configuration works across all backends, false if backend-specific

inline bool operator==(const TensorShape &other) const#

Equality comparison operator.

Parameters:

other – The TensorShape instance to compare with

Returns:

true if all members are equal, false otherwise

inline bool operator!=(const TensorShape &other) const#

Inequality comparison operator.

Parameters:

other – The TensorShape instance to compare with

Returns:

true if any members are not equal, false otherwise

Public Members

TensorShapeList m_tensor_input_shape#

List of input tensor shapes (each shape is a vector of dimensions)

TensorShapeList m_tensor_output_shape#

List of output tensor shapes (each shape is a vector of dimensions)

InferenceBackend m_backend = InferenceBackend::CUSTOM#

Target backend for backend-specific shapes; the universal constructor leaves the default (reading an uninitialized enum is UB, and universal shapes serve every backend anyway)

bool m_universal = false#

Whether this shape configuration is universal (backend-agnostic)