Skip to content

strata::Shape

Part of Shapes and extents.

template <Extent... Extents>
class strata::Shape;

The extents of a tensor: static ones in the type, dynamic ones at run time.

Shape<3, Dyn, 5> has three axes, the first and the last of fixed extent and the middle one known only at run time. The product of the static extents must stay below the maximum of std::size_t, or the shape does not compile.

Template parameters

Name Description
Extents One per axis: a number for a static extent, Dyn for a dynamic one.

Members

rank

static constexpr std::size_t rank() noexcept

The number of axes.

dyn_rank

static constexpr std::size_t dyn_rank() noexcept

The number of dynamic axes.

from_extents

static constexpr Shape from_extents(const std::array<std::size_t, rank_> &extents) noexcept

A shape from every extent, static ones included: from_extents({3, 4, 5}).

Parameters

Name Description
extents One per axis. Those of static axes must match the type.

Precondition

The size of the shape does not overflow std::size_t.

static_extent

static constexpr std::optional<std::size_t> static_extent(std::size_t axis) noexcept

The extent the type fixes for axis, if any.

is_dynamic

static constexpr bool is_dynamic(std::size_t axis) noexcept

Whether the extent of axis is dynamic, that is, not fixed by the type.

Shape

constexpr Shape() noexcept=default

Dynamic extents start at 0, as in std::extents.

template <index_like... DynExtents>
explicit constexpr Shape(DynExtents... extents) noexcept

The dynamic extents, in axis order: Shape<3, Dyn, 5, Dyn>{4, 6}.

Parameters

Name Description
extents One per dynamic axis, of any integer type.

Precondition

Each extent is non-negative, and the size of the shape does not overflow std::size_t.

template <Extent... Others>
constexpr Shape(const Shape<Others...> &other) noexcept

Converts from a shape that fixes at least as much: every static extent here is static and equal there.

Shape<3, 4> converts to Shape<Dyn, 4> and Shape<Dyn, Dyn>, never the other way.

extent

constexpr std::size_t extent(std::size_t axis) const noexcept

The extent of axis, static or dynamic.

size

constexpr std::size_t size() const noexcept

The number of elements: the product of all extents.

operator==

constexpr bool operator==(const Shape &, const Shape &) noexcept=default

Two shapes are equal when every extent is.