Mila 0.13.48
Deep Neural Network Library
Loading...
Searching...
No Matches
Mila::Dnn::TensorShape Struct Referenceexport

Fixed-capacity inline shape descriptor for N-dimensional tensors. More...

Public Member Functions

 TensorShape ()=default
 TensorShape (const dim_t *first, const dim_t *last)
 Constructs from a contiguous pointer range of dimension sizes.
 TensorShape (std::initializer_list< dim_t > il)
 Constructs from a brace-enclosed list of dimension sizes.
dim_tback ()
dim_t back () const
dim_tbegin ()
const dim_tbegin () const
dim_tdata ()
const dim_tdata () const
bool empty () const
dim_tend ()
const dim_tend () const
bool operator== (const TensorShape &other) const noexcept
 Equality compares only the active ndim dimensions.
dim_toperator[] (size_t i)
dim_t operator[] (size_t i) const
size_t size () const

Public Attributes

std::array< dim_t, MaxRankdims {}
uint8_t ndim { 0 }

Static Public Attributes

static constexpr uint8_t MaxRank = 6

Detailed Description

Fixed-capacity inline shape descriptor for N-dimensional tensors.

Stores up to MaxRank dimension sizes inline with no heap allocation. The active rank is tracked by ndim; unused slots are zero-initialized and ignored by all operations. An empty shape (ndim == 0) represents a scalar tensor.

MaxRank = 6 covers all current Mila architectures (2-4D) and common research extensions including video and spatiotemporal models (5D) with one dimension of safety margin. shape_t, stride_t, and index_t are all aliases of TensorShape since all three are structurally identical fixed-capacity int64 sequences.

Example
shape_t s{ 2, 1024, 768 }; // [B, T, C]
s[0] == 2; s.size() == 3;
for (auto d : s) { ... }
TensorShape shape_t
Row-major shape descriptor for tensor dimensional sizes.
Definition Tensor.Types.ixx:143
size_t size() const
Definition Tensor.Types.ixx:109

Constructor & Destructor Documentation

◆ TensorShape() [1/3]

Mila::Dnn::TensorShape::TensorShape ( )
default
Here is the caller graph for this function:

◆ TensorShape() [2/3]

Mila::Dnn::TensorShape::TensorShape ( std::initializer_list< dim_t > il)
inline

Constructs from a brace-enclosed list of dimension sizes.

Parameters
ilDimension sizes in row-major order.
Exceptions
std::invalid_argumentif il.size() > MaxRank.

◆ TensorShape() [3/3]

Mila::Dnn::TensorShape::TensorShape ( const dim_t * first,
const dim_t * last )
inline

Constructs from a contiguous pointer range of dimension sizes.

Covers serialization boundaries where shapes arrive as contiguous storage (e.g. std::vector<int64_t>::data()). The range [first, last) must not exceed MaxRank elements.

Parameters
firstPointer to the first dimension size.
lastOne-past-end pointer.
Exceptions
std::invalid_argumentif the range length exceeds MaxRank.

Member Function Documentation

◆ back() [1/2]

dim_t & Mila::Dnn::TensorShape::back ( )
inline

◆ back() [2/2]

dim_t Mila::Dnn::TensorShape::back ( ) const
inline
Here is the caller graph for this function:

◆ begin() [1/2]

dim_t * Mila::Dnn::TensorShape::begin ( )
inline

◆ begin() [2/2]

const dim_t * Mila::Dnn::TensorShape::begin ( ) const
inline
Here is the caller graph for this function:

◆ data() [1/2]

dim_t * Mila::Dnn::TensorShape::data ( )
inline

◆ data() [2/2]

const dim_t * Mila::Dnn::TensorShape::data ( ) const
inline
Here is the caller graph for this function:

◆ empty()

bool Mila::Dnn::TensorShape::empty ( ) const
inline
Examples
/__w/Mila/Mila/Mila/Src/Dnn/Components/Normalization/Softmax.ixx.
Here is the caller graph for this function:

◆ end() [1/2]

dim_t * Mila::Dnn::TensorShape::end ( )
inline

◆ end() [2/2]

const dim_t * Mila::Dnn::TensorShape::end ( ) const
inline
Here is the caller graph for this function:

◆ operator==()

bool Mila::Dnn::TensorShape::operator== ( const TensorShape & other) const
inlinenoexcept

Equality compares only the active ndim dimensions.

Unused slots (indices >= ndim) are ignored regardless of their values.

Here is the call graph for this function:

◆ operator[]() [1/2]

dim_t & Mila::Dnn::TensorShape::operator[] ( size_t i)
inline

◆ operator[]() [2/2]

dim_t Mila::Dnn::TensorShape::operator[] ( size_t i) const
inline

◆ size()

size_t Mila::Dnn::TensorShape::size ( ) const
inline
Examples
/__w/Mila/Mila/Mila/Src/Dnn/Components/Normalization/Softmax.ixx.
Here is the caller graph for this function:

Member Data Documentation

◆ dims

std::array<dim_t, MaxRank> Mila::Dnn::TensorShape::dims {}

◆ MaxRank

uint8_t Mila::Dnn::TensorShape::MaxRank = 6
staticconstexpr

◆ ndim

uint8_t Mila::Dnn::TensorShape::ndim { 0 }

The documentation for this struct was generated from the following file: