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¶
Whether an extent is dynamic: true for Extent<dynamic_tag>.
Whether an extent is dynamic: false for Extent<std::size_t>.
may_equal¶
Whether two extents may describe the same axis.
True when both are static and equal, or when at least one is dynamic.
merge¶
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.
A static extent wins over a dynamic one.
A static extent wins over a dynamic one.
Two static extents must be equal; if they differ, evaluation fails at compile time.
raw_value¶
An extent as SemiStaticValues takes it: the sentinel of a dynamic one.
An extent as SemiStaticValues takes it: its value.
static_value¶
The value of an extent, or std::nullopt for a dynamic one.
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¶
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¶
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.