xrepeat

Defined in xtensor/xrepeat.hpp

template<class CT, class R>
class xrepeat : public xt::xconst_iterable<xrepeat<CT, R>>, public xt::xconst_accessible<xrepeat<CT, R>>, public xt::xsharable_expression<xrepeat<CT, R>>, public extension::xrepeat_base_t<CT, R>

Expression with repeated values along an axis.

The xrepeat class implements the repetition of the elements of an xexpression along a given axis. xrepeat is not meant to be used directly, but only with the repeat helper functions.

See

repeat

Size and shape

auto shape() const

Returns the shape of the expression.

auto layout() const

Returns the layout_type of the expression.

Data

auto expression() const

Returns a constant reference to the underlying expression of the broadcast expression.

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 unchecked(Args... args) const

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

Warning

This method is meant for performance, for expressions with a dynamic number of dimensions (i.e. not known at compile time). Since it may have undefined behavior (see parameters), operator() should be prefered whenever it is possible.

Warning

This method is NOT compatible with broadcasting, meaning the following code has undefined behavior:

xt::xarray<double> a = {{0, 1}, {2, 3}};
xt::xarray<double> b = {0, 1};
auto fd = a + b;
double res = fd.uncheked(0, 1);

Parameters
  • args: a list of indices specifying the position in the expression. Indices must be unsigned integers, the number of indices must be equal to the number of dimensions of the expression, else the behavior is undefined.

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

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

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 the number of dimensions of the view..

Broadcasting

template<class S>
bool broadcast_shape(S &shape, bool reuse_cache = false) 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

  • reuse_cache: parameter for internal optimization

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

Checks whether the xbroadcast can be linearly assigned to an expression with the specified strides.

Return

a boolean indicating whether a linear assign is possible

Public Functions

template<class CTA>
xrepeat(CTA &&e, R &&repeats, size_type axis)

Constructs an xrepeat expression repeating the element of the specified xexpression.

Parameters
  • e: the input expression

  • repeats: The number of repetitions for each elements

  • axis: The axis along which to repeat the value