Skip to content

strata::Constant

Part of Generators.

template <typename T, shape_like S>
class strata::Constant;

The same value at every index: a scalar with a shape.

Read as a scalar is, so dense in every order, and an expression over it and dense views is still walked flat. It answers slice, permute, block and expand itself, giving a Constant of the resulting shape. It holds no memory beyond the value, and assigning it to a tensor fills the tensor. Made by zeros, ones and full.

Template parameters

Name Description
T The type of the value.
S The shape.

Members

Constant

constexpr Constant(const S &shape, T value)

A constant of shape shape with value at every index.

shape

constexpr const S & shape() const noexcept

The shape.

value

constexpr const T & value() const noexcept

The value every element has.

operator[]

template <index_like... Indices>
constexpr T operator[](Indices... indices) const

The element at indices: the value, whatever they are.

Precondition

Each index is within the extent of its axis.

cursor

constexpr detail::ScalarCursor<T> cursor() const

Where a traversal starts: a scalar's cursor, which never moves.

slice

template <std::size_t... Axes>
constexpr auto slice(const Constant &constant, const std::array<std::size_t, sizeof...(Axes)> &)

The slice of the constant: a constant of the shape without Axes.

permute

template <std::size_t... Permutation>
constexpr auto permute(const Constant &constant)

The permutation of the constant: a constant of the shape with its axes reordered.

block

template <Extent... Sizes>
constexpr auto block(const Constant &constant, const Shape<Sizes...> &sizes, const std::array<std::size_t, sizeof...(Sizes)> &)

The block of the constant: a constant of the shape of the block.

expand

template <std::size_t... Inserted, shape_like Space>
constexpr auto expand(const Constant &constant, const Space &space)

The constant in a shape with new axes: a constant of that shape.