Skip to content

strata::Ewise

Part of Element-wise expressions.

template <typename Fn, typename... Args>
class strata::Ewise;

An element-wise expression: fn(operands[i...]...) for every index, computed when assigned, not before.

Operands are tensors, other expressions and scalars, each held as capture_t says: a view or an expression by value, which is cheap, an lvalue owner borrowed, a temporary owner moved in and owned, which makes the expression moved and never copied. Chains of one left-foldable operation are kept flat: a + b + c is one Ewise<Plus> over three operands, computed as (a + b) + c all the same. Expressions are usually made by the operators and by map, not spelled out.

A slice, a permutation or a block of an expression is the expression over the same operation of each operand, which keeps the views views, and the expression walkable as they are. That is so for an expression that can be copied; one that holds a temporary owner is cut by the nodes of slice, permute and block, which move it in.

Template parameters

Name Description
Fn The function object applied to the operand values at each index.
Args The operands as they are held, each a tensor or a Scalar.

Precondition

Every tensor operand has the same extents (checked on construction).

Members

shape_type

using strata::Ewise< Fn, Args >::shape_type = operand_shape_t<Args...>

The common shape of the tensor operands.

value_type

using strata::Ewise< Fn, Args >::value_type = std::remove_cvref_t<std::invoke_result_t<const Fn&, value_t<Args>...>>

What fn gives for the operand values, without const and references.

nothrow_make

static constexpr bool nothrow_make = std::is_nothrow_move_constructible_v<Fn> &&
 (std::is_nothrow_move_constructible_v<Args> && ...) && shapes_nothrow

Whether making the expression from its function and operands does not throw.

Ewise

constexpr Ewise(Fn fn, Args... operands)

The expression of fn over operands.

Precondition

The tensor operands have equal extents on every axis.

fn

constexpr decltype(auto) fn() const noexcept

The function applied at each index.

operands

constexpr const std::tuple<Args...> & operands() const &noexcept

The operands, in order.

constexpr std::tuple<Args...> && operands() &&noexcept

The operands of an expression that is no longer used, to be moved on.

shape

constexpr shape_type shape() const

The shape of the expression: the extents of the tensor operands, static wherever any fixes them.

cursor

constexpr auto cursor() const

Where a traversal starts: every operand's cursor, and the functor.

operator[]

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

The value at the index, computed from the operands there.

Parameters

Name Description
indices One per axis.

slice

template <std::size_t... Axes>
constexpr auto slice(const Ewise &expression, const std::array<std::size_t, sizeof...(Axes)> &indices)

The slice of the expression: the expression over the slice of each tensor operand.

permute

template <std::size_t... Permutation>
constexpr auto permute(const Ewise &expression)

The permutation of the expression: the expression over the permutation of each tensor operand.

block

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

The block of the expression: the expression over the block of each tensor operand.