xbroadcast

Defined in xtensor/xbroadcast.hpp

template <class CT, class X>
class xt::xbroadcast

Broadcasted xexpression to a specified shape.

The xbroadcast class implements the broadcasting of an xexpression to a specified shape. xbroadcast is not meant to be used directly, but only with the broadcast helper functions.

See
broadcast
Template Parameters
  • CT: the closure type of the xexpression to broadcast
  • X: the type of the specified shape.

Inherits from xt::xexpression< xbroadcast< CT, X > >, xt::xconst_iterable< xbroadcast< CT, X > >

Constructor

template <class CTA, class S>
xbroadcast(CTA &&e, S &&s)

Constructs an xbroadcast expression broadcasting the specified xexpression to the given shape.

Parameters
  • e: the expression to broadcast
  • s: the shape to apply

Size and shape

auto size() const

Returns the size of the expression.

auto dimension() const

Returns the number of dimensions of the expression.

auto shape() const

Returns the shape of the expression.

layout_type layout() const

Returns the layout_type of the expression.

Data

template <class… Args>
auto operator()(Args... args) const

Returns a constant reference to the element at the specified position in the expression.

Parameters
  • args: a list of indices specifying the position in the function. Indices must be unsigned integers, the number of indices should be equal or greater than the number of dimensions of the expression.

template <class… Args>
auto at(Args... args) const

Returns a constant reference to the element at the specified position in the expression, after dimension and bounds checking.

Parameters
  • args: a list of indices specifying the position in the function. Indices must be unsigned integers, the number of indices should be equal to the number of dimensions of the expression.
Exceptions
  • std::out_of_range: if the number of argument is greater than the number of dimensions or if indices are out of bounds.

template <class S>
auto operator[](const S &index) const

Returns a constant reference to the element at the specified position in the expression.

Parameters
  • index: a sequence of indices specifying the position in the function. Indices must be unsigned integers, the number of indices in the sequence should be equal or greater than the number of dimensions of the container.

template <class It>
auto element(It, It last) const

Returns a constant reference to the element at the specified position in the expression.

Parameters
  • first: iterator starting the sequence of indices
  • last: iterator ending the sequence of indices The number of indices in the sequence should be equal to or greater than the number of dimensions of the function.

Broadcasting

template <class S>
bool broadcast_shape(S &shape) const

Broadcast the shape of the function to the specified parameter.

Return
a boolean indicating whether the broadcasting is trivial
Parameters
  • shape: the result shape

template <class S>
bool is_trivial_broadcast(const S &strides) const

Compares the specified strides with those of the container to see whether the broadcasting is trivial.

Return
a boolean indicating whether the broadcasting is trivial

template <class E, class S>
auto xt::broadcast(E &&e, const S &s)

Returns an xexpression broadcasting the given expression to a specified shape.

The returned expression either hold a const reference to e or a copy depending on whether e is an lvalue or an rvalue.

Template Parameters
  • e: the xexpression to broadcast
  • s: the specified shape to broadcast.