Skip to content

Shapes and extents

Static and dynamic extents, and the Shape that holds them.

Concepts

Name Description
matching_shapes Shapes that may describe the same extents: the same rank, and no two different static extents on an axis.
shape_like A Shape<...>, of any extents.

Types

Name Description
dynamic_tag The type of Dyn.
Extent One axis of a Shape, deduced from a template argument.
Extent<dynamic_tag> A dynamic extent: its value is not part of the type, and is not stored here.
Extent<std::size_t> A static extent, fixed by the type.
Shape The extents of a tensor: static ones in the type, dynamic ones at run time.
std::formatter<strata::Shape<Extents...>, char> Formatting of a Shape with std::format.

Functions

is_dynamic

consteval bool is_dynamic(Extent<dynamic_tag>) noexcept

Whether an extent is dynamic: true for Extent<dynamic_tag>.

consteval bool is_dynamic(Extent<std::size_t>) noexcept

Whether an extent is dynamic: false for Extent<std::size_t>.

may_equal

template <typename L, typename R>
consteval bool may_equal(Extent<L> lhs, Extent<R> rhs) noexcept

Whether two extents may describe the same axis.

True when both are static and equal, or when at least one is dynamic.

merge

consteval Extent<dynamic_tag> merge(Extent<dynamic_tag> lhs, Extent<dynamic_tag>) noexcept

The more specific of two extents of the same axis: a static extent wins over a dynamic one.

Two static extents must agree; if they differ, evaluation fails at compile time.

consteval Extent<std::size_t> merge(Extent<std::size_t> lhs, Extent<dynamic_tag>) noexcept

A static extent wins over a dynamic one.

consteval Extent<std::size_t> merge(Extent<dynamic_tag>, Extent<std::size_t> rhs) noexcept

A static extent wins over a dynamic one.

consteval Extent<std::size_t> merge(Extent<std::size_t> lhs, Extent<std::size_t> rhs)

Two static extents must be equal; if they differ, evaluation fails at compile time.

raw_value

consteval std::size_t raw_value(Extent<dynamic_tag>) noexcept

An extent as SemiStaticValues takes it: the sentinel of a dynamic one.

consteval std::size_t raw_value(Extent<std::size_t> extent) noexcept

An extent as SemiStaticValues takes it: its value.

static_value

consteval std::optional<std::size_t> static_value(Extent<dynamic_tag>) noexcept

The value of an extent, or std::nullopt for a dynamic one.

consteval std::optional<std::size_t> static_value(Extent<std::size_t> extent) noexcept

The value of an extent, or std::nullopt for a dynamic one.

permute_shape

template <std::size_t... Permutation, Extent... Extents>
constexpr auto permute_shape(const Shape<Extents...> &shape) noexcept

The shape with its axes reordered: new axis k is old axis Permutation[k].

Template parameters

Name Description
Permutation A permutation of 0 ... rank - 1.

drop_axis

template <std::size_t Axis, Extent... Extents>
constexpr auto drop_axis(const Shape<Extents...> &shape) noexcept

The shape without axis Axis: what slicing at a fixed index along that axis leaves.

The axes after Axis move down by one.

diagonal_shape

template <std::size_t... Axes, Extent... Extents>
constexpr auto diagonal_shape(const Shape<Extents...> &shape) noexcept

The shape of the diagonal over Axes: those axes become one, at the place of the first, and the others are gone.

Precondition

The extents of Axes are equal; the static ones are checked in the type, the rest by the caller.

Variables

Dyn

constexpr dynamic_tag Dyn {}

Marks an axis whose extent is known only at run time.

Shape<3, Dyn, 5> fixes the first and last axis and leaves the middle one to run time.

Aliases

common_shape_t

template <typename... Shapes>
using strata::common_shape_t = detail::common_shape<Shapes...>::type

The shape that all of Shapes describe at once.

Shape<3, Dyn> and Shape<Dyn, 4> give Shape<3, 4>. Ill-formed when they cannot match, which a requires-expression can test.