Template Class Shape

Class Documentation

template<class T, int N>
class Shape

Template class representing an N-dimensional shape.

This class is designed to encapsulate the shape of an N-dimensional tensor, where the size in each dimension is of type T.

Template Parameters:
  • T – The type of the size in each dimension (e.g., int, size_t).

  • N – The maximum number of dimensions this shape can represent.

Public Types

using value_type = typename Data::value_type
using size_type = int
using reference = typename Data::reference
using const_reference = typename Data::const_reference
using iterator = typename Data::iterator
using const_iterator = typename Data::const_iterator

Public Functions

Shape()
Shape(const Shape &that)
explicit Shape(size_type size)

Construct with a given rank, sizes default to 0.

Parameters:

size – The rank of the shape.

Shape(const T *data, size_t n)

Constructor using a buffer.

Constructs a shape by copying ‘n’ elements from the buffer pointed by ‘data’.

Parameters:
  • data – Pointer to the buffer.

  • n – Number of elements to copy from the buffer.

Shape(std::initializer_list<value_type> shape)
reference operator[](int i)

Access the i-th dimension.

const_reference operator[](int i) const
size_type rank() const

Get the rank (number of dimensions) of the shape.

size_type size() const

Get the total size represented by the shape.

bool empty() const

Check if the shape is empty.

iterator begin()
iterator end()
const_iterator begin() const
const_iterator end() const
const_iterator cbegin() const
const_iterator cend() const
bool operator==(const Shape &that) const
bool operator!=(const Shape &that) const
bool operator<(const Shape &that) const

Public Static Attributes

static constexpr int MAX_RANK = N